main.c 153 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876
  1. /*
  2. Broadcom B43 wireless driver
  3. Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
  4. Copyright (c) 2005 Stefano Brivio <stefano.brivio@polimi.it>
  5. Copyright (c) 2005-2009 Michael Buesch <m@bues.ch>
  6. Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
  7. Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  8. Copyright (c) 2010-2011 Rafał Miłecki <zajec5@gmail.com>
  9. SDIO support
  10. Copyright (c) 2009 Albert Herranz <albert_herranz@yahoo.es>
  11. Some parts of the code in this file are derived from the ipw2200
  12. driver Copyright(c) 2003 - 2004 Intel Corporation.
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. You should have received a copy of the GNU General Public License
  22. along with this program; see the file COPYING. If not, write to
  23. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  24. Boston, MA 02110-1301, USA.
  25. */
  26. #include <linux/delay.h>
  27. #include <linux/init.h>
  28. #include <linux/module.h>
  29. #include <linux/if_arp.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/firmware.h>
  32. #include <linux/workqueue.h>
  33. #include <linux/skbuff.h>
  34. #include <linux/io.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/slab.h>
  37. #include <asm/unaligned.h>
  38. #include "b43.h"
  39. #include "main.h"
  40. #include "debugfs.h"
  41. #include "phy_common.h"
  42. #include "phy_g.h"
  43. #include "phy_n.h"
  44. #include "dma.h"
  45. #include "pio.h"
  46. #include "sysfs.h"
  47. #include "xmit.h"
  48. #include "lo.h"
  49. #include "sdio.h"
  50. #include <linux/mmc/sdio_func.h>
  51. MODULE_DESCRIPTION("Broadcom B43 wireless driver");
  52. MODULE_AUTHOR("Martin Langer");
  53. MODULE_AUTHOR("Stefano Brivio");
  54. MODULE_AUTHOR("Michael Buesch");
  55. MODULE_AUTHOR("Gábor Stefanik");
  56. MODULE_AUTHOR("Rafał Miłecki");
  57. MODULE_LICENSE("GPL");
  58. MODULE_FIRMWARE("b43/ucode11.fw");
  59. MODULE_FIRMWARE("b43/ucode13.fw");
  60. MODULE_FIRMWARE("b43/ucode14.fw");
  61. MODULE_FIRMWARE("b43/ucode15.fw");
  62. MODULE_FIRMWARE("b43/ucode16_lp.fw");
  63. MODULE_FIRMWARE("b43/ucode16_mimo.fw");
  64. MODULE_FIRMWARE("b43/ucode24_lcn.fw");
  65. MODULE_FIRMWARE("b43/ucode25_lcn.fw");
  66. MODULE_FIRMWARE("b43/ucode25_mimo.fw");
  67. MODULE_FIRMWARE("b43/ucode26_mimo.fw");
  68. MODULE_FIRMWARE("b43/ucode29_mimo.fw");
  69. MODULE_FIRMWARE("b43/ucode33_lcn40.fw");
  70. MODULE_FIRMWARE("b43/ucode30_mimo.fw");
  71. MODULE_FIRMWARE("b43/ucode5.fw");
  72. MODULE_FIRMWARE("b43/ucode40.fw");
  73. MODULE_FIRMWARE("b43/ucode42.fw");
  74. MODULE_FIRMWARE("b43/ucode9.fw");
  75. static int modparam_bad_frames_preempt;
  76. module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
  77. MODULE_PARM_DESC(bad_frames_preempt,
  78. "enable(1) / disable(0) Bad Frames Preemption");
  79. static char modparam_fwpostfix[16];
  80. module_param_string(fwpostfix, modparam_fwpostfix, 16, 0444);
  81. MODULE_PARM_DESC(fwpostfix, "Postfix for the .fw files to load.");
  82. static int modparam_hwpctl;
  83. module_param_named(hwpctl, modparam_hwpctl, int, 0444);
  84. MODULE_PARM_DESC(hwpctl, "Enable hardware-side power control (default off)");
  85. static int modparam_nohwcrypt;
  86. module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
  87. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  88. static int modparam_hwtkip;
  89. module_param_named(hwtkip, modparam_hwtkip, int, 0444);
  90. MODULE_PARM_DESC(hwtkip, "Enable hardware tkip.");
  91. static int modparam_qos = 1;
  92. module_param_named(qos, modparam_qos, int, 0444);
  93. MODULE_PARM_DESC(qos, "Enable QOS support (default on)");
  94. static int modparam_btcoex = 1;
  95. module_param_named(btcoex, modparam_btcoex, int, 0444);
  96. MODULE_PARM_DESC(btcoex, "Enable Bluetooth coexistence (default on)");
  97. int b43_modparam_verbose = B43_VERBOSITY_DEFAULT;
  98. module_param_named(verbose, b43_modparam_verbose, int, 0644);
  99. MODULE_PARM_DESC(verbose, "Log message verbosity: 0=error, 1=warn, 2=info(default), 3=debug");
  100. static int b43_modparam_pio = 0;
  101. module_param_named(pio, b43_modparam_pio, int, 0644);
  102. MODULE_PARM_DESC(pio, "Use PIO accesses by default: 0=DMA, 1=PIO");
  103. static int modparam_allhwsupport = !IS_ENABLED(CONFIG_BRCMSMAC);
  104. module_param_named(allhwsupport, modparam_allhwsupport, int, 0444);
  105. MODULE_PARM_DESC(allhwsupport, "Enable support for all hardware (even it if overlaps with the brcmsmac driver)");
  106. #ifdef CONFIG_B43_BCMA
  107. static const struct bcma_device_id b43_bcma_tbl[] = {
  108. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x11, BCMA_ANY_CLASS),
  109. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x15, BCMA_ANY_CLASS),
  110. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x17, BCMA_ANY_CLASS),
  111. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x18, BCMA_ANY_CLASS),
  112. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x1C, BCMA_ANY_CLASS),
  113. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x1D, BCMA_ANY_CLASS),
  114. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x1E, BCMA_ANY_CLASS),
  115. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x28, BCMA_ANY_CLASS),
  116. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x2A, BCMA_ANY_CLASS),
  117. {},
  118. };
  119. MODULE_DEVICE_TABLE(bcma, b43_bcma_tbl);
  120. #endif
  121. #ifdef CONFIG_B43_SSB
  122. static const struct ssb_device_id b43_ssb_tbl[] = {
  123. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 5),
  124. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 6),
  125. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 7),
  126. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 9),
  127. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 10),
  128. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 11),
  129. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 12),
  130. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 13),
  131. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 15),
  132. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 16),
  133. {},
  134. };
  135. MODULE_DEVICE_TABLE(ssb, b43_ssb_tbl);
  136. #endif
  137. /* Channel and ratetables are shared for all devices.
  138. * They can't be const, because ieee80211 puts some precalculated
  139. * data in there. This data is the same for all devices, so we don't
  140. * get concurrency issues */
  141. #define RATETAB_ENT(_rateid, _flags) \
  142. { \
  143. .bitrate = B43_RATE_TO_BASE100KBPS(_rateid), \
  144. .hw_value = (_rateid), \
  145. .flags = (_flags), \
  146. }
  147. /*
  148. * NOTE: When changing this, sync with xmit.c's
  149. * b43_plcp_get_bitrate_idx_* functions!
  150. */
  151. static struct ieee80211_rate __b43_ratetable[] = {
  152. RATETAB_ENT(B43_CCK_RATE_1MB, 0),
  153. RATETAB_ENT(B43_CCK_RATE_2MB, IEEE80211_RATE_SHORT_PREAMBLE),
  154. RATETAB_ENT(B43_CCK_RATE_5MB, IEEE80211_RATE_SHORT_PREAMBLE),
  155. RATETAB_ENT(B43_CCK_RATE_11MB, IEEE80211_RATE_SHORT_PREAMBLE),
  156. RATETAB_ENT(B43_OFDM_RATE_6MB, 0),
  157. RATETAB_ENT(B43_OFDM_RATE_9MB, 0),
  158. RATETAB_ENT(B43_OFDM_RATE_12MB, 0),
  159. RATETAB_ENT(B43_OFDM_RATE_18MB, 0),
  160. RATETAB_ENT(B43_OFDM_RATE_24MB, 0),
  161. RATETAB_ENT(B43_OFDM_RATE_36MB, 0),
  162. RATETAB_ENT(B43_OFDM_RATE_48MB, 0),
  163. RATETAB_ENT(B43_OFDM_RATE_54MB, 0),
  164. };
  165. #define b43_a_ratetable (__b43_ratetable + 4)
  166. #define b43_a_ratetable_size 8
  167. #define b43_b_ratetable (__b43_ratetable + 0)
  168. #define b43_b_ratetable_size 4
  169. #define b43_g_ratetable (__b43_ratetable + 0)
  170. #define b43_g_ratetable_size 12
  171. #define CHAN2G(_channel, _freq, _flags) { \
  172. .band = NL80211_BAND_2GHZ, \
  173. .center_freq = (_freq), \
  174. .hw_value = (_channel), \
  175. .flags = (_flags), \
  176. .max_antenna_gain = 0, \
  177. .max_power = 30, \
  178. }
  179. static struct ieee80211_channel b43_2ghz_chantable[] = {
  180. CHAN2G(1, 2412, 0),
  181. CHAN2G(2, 2417, 0),
  182. CHAN2G(3, 2422, 0),
  183. CHAN2G(4, 2427, 0),
  184. CHAN2G(5, 2432, 0),
  185. CHAN2G(6, 2437, 0),
  186. CHAN2G(7, 2442, 0),
  187. CHAN2G(8, 2447, 0),
  188. CHAN2G(9, 2452, 0),
  189. CHAN2G(10, 2457, 0),
  190. CHAN2G(11, 2462, 0),
  191. CHAN2G(12, 2467, 0),
  192. CHAN2G(13, 2472, 0),
  193. CHAN2G(14, 2484, 0),
  194. };
  195. /* No support for the last 3 channels (12, 13, 14) */
  196. #define b43_2ghz_chantable_limited_size 11
  197. #undef CHAN2G
  198. #define CHAN4G(_channel, _flags) { \
  199. .band = NL80211_BAND_5GHZ, \
  200. .center_freq = 4000 + (5 * (_channel)), \
  201. .hw_value = (_channel), \
  202. .flags = (_flags), \
  203. .max_antenna_gain = 0, \
  204. .max_power = 30, \
  205. }
  206. #define CHAN5G(_channel, _flags) { \
  207. .band = NL80211_BAND_5GHZ, \
  208. .center_freq = 5000 + (5 * (_channel)), \
  209. .hw_value = (_channel), \
  210. .flags = (_flags), \
  211. .max_antenna_gain = 0, \
  212. .max_power = 30, \
  213. }
  214. static struct ieee80211_channel b43_5ghz_nphy_chantable[] = {
  215. CHAN4G(184, 0), CHAN4G(186, 0),
  216. CHAN4G(188, 0), CHAN4G(190, 0),
  217. CHAN4G(192, 0), CHAN4G(194, 0),
  218. CHAN4G(196, 0), CHAN4G(198, 0),
  219. CHAN4G(200, 0), CHAN4G(202, 0),
  220. CHAN4G(204, 0), CHAN4G(206, 0),
  221. CHAN4G(208, 0), CHAN4G(210, 0),
  222. CHAN4G(212, 0), CHAN4G(214, 0),
  223. CHAN4G(216, 0), CHAN4G(218, 0),
  224. CHAN4G(220, 0), CHAN4G(222, 0),
  225. CHAN4G(224, 0), CHAN4G(226, 0),
  226. CHAN4G(228, 0),
  227. CHAN5G(32, 0), CHAN5G(34, 0),
  228. CHAN5G(36, 0), CHAN5G(38, 0),
  229. CHAN5G(40, 0), CHAN5G(42, 0),
  230. CHAN5G(44, 0), CHAN5G(46, 0),
  231. CHAN5G(48, 0), CHAN5G(50, 0),
  232. CHAN5G(52, 0), CHAN5G(54, 0),
  233. CHAN5G(56, 0), CHAN5G(58, 0),
  234. CHAN5G(60, 0), CHAN5G(62, 0),
  235. CHAN5G(64, 0), CHAN5G(66, 0),
  236. CHAN5G(68, 0), CHAN5G(70, 0),
  237. CHAN5G(72, 0), CHAN5G(74, 0),
  238. CHAN5G(76, 0), CHAN5G(78, 0),
  239. CHAN5G(80, 0), CHAN5G(82, 0),
  240. CHAN5G(84, 0), CHAN5G(86, 0),
  241. CHAN5G(88, 0), CHAN5G(90, 0),
  242. CHAN5G(92, 0), CHAN5G(94, 0),
  243. CHAN5G(96, 0), CHAN5G(98, 0),
  244. CHAN5G(100, 0), CHAN5G(102, 0),
  245. CHAN5G(104, 0), CHAN5G(106, 0),
  246. CHAN5G(108, 0), CHAN5G(110, 0),
  247. CHAN5G(112, 0), CHAN5G(114, 0),
  248. CHAN5G(116, 0), CHAN5G(118, 0),
  249. CHAN5G(120, 0), CHAN5G(122, 0),
  250. CHAN5G(124, 0), CHAN5G(126, 0),
  251. CHAN5G(128, 0), CHAN5G(130, 0),
  252. CHAN5G(132, 0), CHAN5G(134, 0),
  253. CHAN5G(136, 0), CHAN5G(138, 0),
  254. CHAN5G(140, 0), CHAN5G(142, 0),
  255. CHAN5G(144, 0), CHAN5G(145, 0),
  256. CHAN5G(146, 0), CHAN5G(147, 0),
  257. CHAN5G(148, 0), CHAN5G(149, 0),
  258. CHAN5G(150, 0), CHAN5G(151, 0),
  259. CHAN5G(152, 0), CHAN5G(153, 0),
  260. CHAN5G(154, 0), CHAN5G(155, 0),
  261. CHAN5G(156, 0), CHAN5G(157, 0),
  262. CHAN5G(158, 0), CHAN5G(159, 0),
  263. CHAN5G(160, 0), CHAN5G(161, 0),
  264. CHAN5G(162, 0), CHAN5G(163, 0),
  265. CHAN5G(164, 0), CHAN5G(165, 0),
  266. CHAN5G(166, 0), CHAN5G(168, 0),
  267. CHAN5G(170, 0), CHAN5G(172, 0),
  268. CHAN5G(174, 0), CHAN5G(176, 0),
  269. CHAN5G(178, 0), CHAN5G(180, 0),
  270. CHAN5G(182, 0),
  271. };
  272. static struct ieee80211_channel b43_5ghz_nphy_chantable_limited[] = {
  273. CHAN5G(36, 0), CHAN5G(40, 0),
  274. CHAN5G(44, 0), CHAN5G(48, 0),
  275. CHAN5G(149, 0), CHAN5G(153, 0),
  276. CHAN5G(157, 0), CHAN5G(161, 0),
  277. CHAN5G(165, 0),
  278. };
  279. static struct ieee80211_channel b43_5ghz_aphy_chantable[] = {
  280. CHAN5G(34, 0), CHAN5G(36, 0),
  281. CHAN5G(38, 0), CHAN5G(40, 0),
  282. CHAN5G(42, 0), CHAN5G(44, 0),
  283. CHAN5G(46, 0), CHAN5G(48, 0),
  284. CHAN5G(52, 0), CHAN5G(56, 0),
  285. CHAN5G(60, 0), CHAN5G(64, 0),
  286. CHAN5G(100, 0), CHAN5G(104, 0),
  287. CHAN5G(108, 0), CHAN5G(112, 0),
  288. CHAN5G(116, 0), CHAN5G(120, 0),
  289. CHAN5G(124, 0), CHAN5G(128, 0),
  290. CHAN5G(132, 0), CHAN5G(136, 0),
  291. CHAN5G(140, 0), CHAN5G(149, 0),
  292. CHAN5G(153, 0), CHAN5G(157, 0),
  293. CHAN5G(161, 0), CHAN5G(165, 0),
  294. CHAN5G(184, 0), CHAN5G(188, 0),
  295. CHAN5G(192, 0), CHAN5G(196, 0),
  296. CHAN5G(200, 0), CHAN5G(204, 0),
  297. CHAN5G(208, 0), CHAN5G(212, 0),
  298. CHAN5G(216, 0),
  299. };
  300. #undef CHAN4G
  301. #undef CHAN5G
  302. static struct ieee80211_supported_band b43_band_5GHz_nphy = {
  303. .band = NL80211_BAND_5GHZ,
  304. .channels = b43_5ghz_nphy_chantable,
  305. .n_channels = ARRAY_SIZE(b43_5ghz_nphy_chantable),
  306. .bitrates = b43_a_ratetable,
  307. .n_bitrates = b43_a_ratetable_size,
  308. };
  309. static struct ieee80211_supported_band b43_band_5GHz_nphy_limited = {
  310. .band = NL80211_BAND_5GHZ,
  311. .channels = b43_5ghz_nphy_chantable_limited,
  312. .n_channels = ARRAY_SIZE(b43_5ghz_nphy_chantable_limited),
  313. .bitrates = b43_a_ratetable,
  314. .n_bitrates = b43_a_ratetable_size,
  315. };
  316. static struct ieee80211_supported_band b43_band_5GHz_aphy = {
  317. .band = NL80211_BAND_5GHZ,
  318. .channels = b43_5ghz_aphy_chantable,
  319. .n_channels = ARRAY_SIZE(b43_5ghz_aphy_chantable),
  320. .bitrates = b43_a_ratetable,
  321. .n_bitrates = b43_a_ratetable_size,
  322. };
  323. static struct ieee80211_supported_band b43_band_2GHz = {
  324. .band = NL80211_BAND_2GHZ,
  325. .channels = b43_2ghz_chantable,
  326. .n_channels = ARRAY_SIZE(b43_2ghz_chantable),
  327. .bitrates = b43_g_ratetable,
  328. .n_bitrates = b43_g_ratetable_size,
  329. };
  330. static struct ieee80211_supported_band b43_band_2ghz_limited = {
  331. .band = NL80211_BAND_2GHZ,
  332. .channels = b43_2ghz_chantable,
  333. .n_channels = b43_2ghz_chantable_limited_size,
  334. .bitrates = b43_g_ratetable,
  335. .n_bitrates = b43_g_ratetable_size,
  336. };
  337. static void b43_wireless_core_exit(struct b43_wldev *dev);
  338. static int b43_wireless_core_init(struct b43_wldev *dev);
  339. static struct b43_wldev * b43_wireless_core_stop(struct b43_wldev *dev);
  340. static int b43_wireless_core_start(struct b43_wldev *dev);
  341. static void b43_op_bss_info_changed(struct ieee80211_hw *hw,
  342. struct ieee80211_vif *vif,
  343. struct ieee80211_bss_conf *conf,
  344. u32 changed);
  345. static int b43_ratelimit(struct b43_wl *wl)
  346. {
  347. if (!wl || !wl->current_dev)
  348. return 1;
  349. if (b43_status(wl->current_dev) < B43_STAT_STARTED)
  350. return 1;
  351. /* We are up and running.
  352. * Ratelimit the messages to avoid DoS over the net. */
  353. return net_ratelimit();
  354. }
  355. void b43info(struct b43_wl *wl, const char *fmt, ...)
  356. {
  357. struct va_format vaf;
  358. va_list args;
  359. if (b43_modparam_verbose < B43_VERBOSITY_INFO)
  360. return;
  361. if (!b43_ratelimit(wl))
  362. return;
  363. va_start(args, fmt);
  364. vaf.fmt = fmt;
  365. vaf.va = &args;
  366. printk(KERN_INFO "b43-%s: %pV",
  367. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan", &vaf);
  368. va_end(args);
  369. }
  370. void b43err(struct b43_wl *wl, const char *fmt, ...)
  371. {
  372. struct va_format vaf;
  373. va_list args;
  374. if (b43_modparam_verbose < B43_VERBOSITY_ERROR)
  375. return;
  376. if (!b43_ratelimit(wl))
  377. return;
  378. va_start(args, fmt);
  379. vaf.fmt = fmt;
  380. vaf.va = &args;
  381. printk(KERN_ERR "b43-%s ERROR: %pV",
  382. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan", &vaf);
  383. va_end(args);
  384. }
  385. void b43warn(struct b43_wl *wl, const char *fmt, ...)
  386. {
  387. struct va_format vaf;
  388. va_list args;
  389. if (b43_modparam_verbose < B43_VERBOSITY_WARN)
  390. return;
  391. if (!b43_ratelimit(wl))
  392. return;
  393. va_start(args, fmt);
  394. vaf.fmt = fmt;
  395. vaf.va = &args;
  396. printk(KERN_WARNING "b43-%s warning: %pV",
  397. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan", &vaf);
  398. va_end(args);
  399. }
  400. void b43dbg(struct b43_wl *wl, const char *fmt, ...)
  401. {
  402. struct va_format vaf;
  403. va_list args;
  404. if (b43_modparam_verbose < B43_VERBOSITY_DEBUG)
  405. return;
  406. va_start(args, fmt);
  407. vaf.fmt = fmt;
  408. vaf.va = &args;
  409. printk(KERN_DEBUG "b43-%s debug: %pV",
  410. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan", &vaf);
  411. va_end(args);
  412. }
  413. static void b43_ram_write(struct b43_wldev *dev, u16 offset, u32 val)
  414. {
  415. u32 macctl;
  416. B43_WARN_ON(offset % 4 != 0);
  417. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  418. if (macctl & B43_MACCTL_BE)
  419. val = swab32(val);
  420. b43_write32(dev, B43_MMIO_RAM_CONTROL, offset);
  421. mmiowb();
  422. b43_write32(dev, B43_MMIO_RAM_DATA, val);
  423. }
  424. static inline void b43_shm_control_word(struct b43_wldev *dev,
  425. u16 routing, u16 offset)
  426. {
  427. u32 control;
  428. /* "offset" is the WORD offset. */
  429. control = routing;
  430. control <<= 16;
  431. control |= offset;
  432. b43_write32(dev, B43_MMIO_SHM_CONTROL, control);
  433. }
  434. u32 b43_shm_read32(struct b43_wldev *dev, u16 routing, u16 offset)
  435. {
  436. u32 ret;
  437. if (routing == B43_SHM_SHARED) {
  438. B43_WARN_ON(offset & 0x0001);
  439. if (offset & 0x0003) {
  440. /* Unaligned access */
  441. b43_shm_control_word(dev, routing, offset >> 2);
  442. ret = b43_read16(dev, B43_MMIO_SHM_DATA_UNALIGNED);
  443. b43_shm_control_word(dev, routing, (offset >> 2) + 1);
  444. ret |= ((u32)b43_read16(dev, B43_MMIO_SHM_DATA)) << 16;
  445. goto out;
  446. }
  447. offset >>= 2;
  448. }
  449. b43_shm_control_word(dev, routing, offset);
  450. ret = b43_read32(dev, B43_MMIO_SHM_DATA);
  451. out:
  452. return ret;
  453. }
  454. u16 b43_shm_read16(struct b43_wldev *dev, u16 routing, u16 offset)
  455. {
  456. u16 ret;
  457. if (routing == B43_SHM_SHARED) {
  458. B43_WARN_ON(offset & 0x0001);
  459. if (offset & 0x0003) {
  460. /* Unaligned access */
  461. b43_shm_control_word(dev, routing, offset >> 2);
  462. ret = b43_read16(dev, B43_MMIO_SHM_DATA_UNALIGNED);
  463. goto out;
  464. }
  465. offset >>= 2;
  466. }
  467. b43_shm_control_word(dev, routing, offset);
  468. ret = b43_read16(dev, B43_MMIO_SHM_DATA);
  469. out:
  470. return ret;
  471. }
  472. void b43_shm_write32(struct b43_wldev *dev, u16 routing, u16 offset, u32 value)
  473. {
  474. if (routing == B43_SHM_SHARED) {
  475. B43_WARN_ON(offset & 0x0001);
  476. if (offset & 0x0003) {
  477. /* Unaligned access */
  478. b43_shm_control_word(dev, routing, offset >> 2);
  479. b43_write16(dev, B43_MMIO_SHM_DATA_UNALIGNED,
  480. value & 0xFFFF);
  481. b43_shm_control_word(dev, routing, (offset >> 2) + 1);
  482. b43_write16(dev, B43_MMIO_SHM_DATA,
  483. (value >> 16) & 0xFFFF);
  484. return;
  485. }
  486. offset >>= 2;
  487. }
  488. b43_shm_control_word(dev, routing, offset);
  489. b43_write32(dev, B43_MMIO_SHM_DATA, value);
  490. }
  491. void b43_shm_write16(struct b43_wldev *dev, u16 routing, u16 offset, u16 value)
  492. {
  493. if (routing == B43_SHM_SHARED) {
  494. B43_WARN_ON(offset & 0x0001);
  495. if (offset & 0x0003) {
  496. /* Unaligned access */
  497. b43_shm_control_word(dev, routing, offset >> 2);
  498. b43_write16(dev, B43_MMIO_SHM_DATA_UNALIGNED, value);
  499. return;
  500. }
  501. offset >>= 2;
  502. }
  503. b43_shm_control_word(dev, routing, offset);
  504. b43_write16(dev, B43_MMIO_SHM_DATA, value);
  505. }
  506. /* Read HostFlags */
  507. u64 b43_hf_read(struct b43_wldev *dev)
  508. {
  509. u64 ret;
  510. ret = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTF3);
  511. ret <<= 16;
  512. ret |= b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTF2);
  513. ret <<= 16;
  514. ret |= b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTF1);
  515. return ret;
  516. }
  517. /* Write HostFlags */
  518. void b43_hf_write(struct b43_wldev *dev, u64 value)
  519. {
  520. u16 lo, mi, hi;
  521. lo = (value & 0x00000000FFFFULL);
  522. mi = (value & 0x0000FFFF0000ULL) >> 16;
  523. hi = (value & 0xFFFF00000000ULL) >> 32;
  524. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTF1, lo);
  525. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTF2, mi);
  526. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTF3, hi);
  527. }
  528. /* Read the firmware capabilities bitmask (Opensource firmware only) */
  529. static u16 b43_fwcapa_read(struct b43_wldev *dev)
  530. {
  531. B43_WARN_ON(!dev->fw.opensource);
  532. return b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_FWCAPA);
  533. }
  534. void b43_tsf_read(struct b43_wldev *dev, u64 *tsf)
  535. {
  536. u32 low, high;
  537. B43_WARN_ON(dev->dev->core_rev < 3);
  538. /* The hardware guarantees us an atomic read, if we
  539. * read the low register first. */
  540. low = b43_read32(dev, B43_MMIO_REV3PLUS_TSF_LOW);
  541. high = b43_read32(dev, B43_MMIO_REV3PLUS_TSF_HIGH);
  542. *tsf = high;
  543. *tsf <<= 32;
  544. *tsf |= low;
  545. }
  546. static void b43_time_lock(struct b43_wldev *dev)
  547. {
  548. b43_maskset32(dev, B43_MMIO_MACCTL, ~0, B43_MACCTL_TBTTHOLD);
  549. /* Commit the write */
  550. b43_read32(dev, B43_MMIO_MACCTL);
  551. }
  552. static void b43_time_unlock(struct b43_wldev *dev)
  553. {
  554. b43_maskset32(dev, B43_MMIO_MACCTL, ~B43_MACCTL_TBTTHOLD, 0);
  555. /* Commit the write */
  556. b43_read32(dev, B43_MMIO_MACCTL);
  557. }
  558. static void b43_tsf_write_locked(struct b43_wldev *dev, u64 tsf)
  559. {
  560. u32 low, high;
  561. B43_WARN_ON(dev->dev->core_rev < 3);
  562. low = tsf;
  563. high = (tsf >> 32);
  564. /* The hardware guarantees us an atomic write, if we
  565. * write the low register first. */
  566. b43_write32(dev, B43_MMIO_REV3PLUS_TSF_LOW, low);
  567. mmiowb();
  568. b43_write32(dev, B43_MMIO_REV3PLUS_TSF_HIGH, high);
  569. mmiowb();
  570. }
  571. void b43_tsf_write(struct b43_wldev *dev, u64 tsf)
  572. {
  573. b43_time_lock(dev);
  574. b43_tsf_write_locked(dev, tsf);
  575. b43_time_unlock(dev);
  576. }
  577. static
  578. void b43_macfilter_set(struct b43_wldev *dev, u16 offset, const u8 *mac)
  579. {
  580. static const u8 zero_addr[ETH_ALEN] = { 0 };
  581. u16 data;
  582. if (!mac)
  583. mac = zero_addr;
  584. offset |= 0x0020;
  585. b43_write16(dev, B43_MMIO_MACFILTER_CONTROL, offset);
  586. data = mac[0];
  587. data |= mac[1] << 8;
  588. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  589. data = mac[2];
  590. data |= mac[3] << 8;
  591. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  592. data = mac[4];
  593. data |= mac[5] << 8;
  594. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  595. }
  596. static void b43_write_mac_bssid_templates(struct b43_wldev *dev)
  597. {
  598. const u8 *mac;
  599. const u8 *bssid;
  600. u8 mac_bssid[ETH_ALEN * 2];
  601. int i;
  602. u32 tmp;
  603. bssid = dev->wl->bssid;
  604. mac = dev->wl->mac_addr;
  605. b43_macfilter_set(dev, B43_MACFILTER_BSSID, bssid);
  606. memcpy(mac_bssid, mac, ETH_ALEN);
  607. memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
  608. /* Write our MAC address and BSSID to template ram */
  609. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32)) {
  610. tmp = (u32) (mac_bssid[i + 0]);
  611. tmp |= (u32) (mac_bssid[i + 1]) << 8;
  612. tmp |= (u32) (mac_bssid[i + 2]) << 16;
  613. tmp |= (u32) (mac_bssid[i + 3]) << 24;
  614. b43_ram_write(dev, 0x20 + i, tmp);
  615. }
  616. }
  617. static void b43_upload_card_macaddress(struct b43_wldev *dev)
  618. {
  619. b43_write_mac_bssid_templates(dev);
  620. b43_macfilter_set(dev, B43_MACFILTER_SELF, dev->wl->mac_addr);
  621. }
  622. static void b43_set_slot_time(struct b43_wldev *dev, u16 slot_time)
  623. {
  624. /* slot_time is in usec. */
  625. /* This test used to exit for all but a G PHY. */
  626. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ)
  627. return;
  628. b43_write16(dev, B43_MMIO_IFSSLOT, 510 + slot_time);
  629. /* Shared memory location 0x0010 is the slot time and should be
  630. * set to slot_time; however, this register is initially 0 and changing
  631. * the value adversely affects the transmit rate for BCM4311
  632. * devices. Until this behavior is unterstood, delete this step
  633. *
  634. * b43_shm_write16(dev, B43_SHM_SHARED, 0x0010, slot_time);
  635. */
  636. }
  637. static void b43_short_slot_timing_enable(struct b43_wldev *dev)
  638. {
  639. b43_set_slot_time(dev, 9);
  640. }
  641. static void b43_short_slot_timing_disable(struct b43_wldev *dev)
  642. {
  643. b43_set_slot_time(dev, 20);
  644. }
  645. /* DummyTransmission function, as documented on
  646. * http://bcm-v4.sipsolutions.net/802.11/DummyTransmission
  647. */
  648. void b43_dummy_transmission(struct b43_wldev *dev, bool ofdm, bool pa_on)
  649. {
  650. struct b43_phy *phy = &dev->phy;
  651. unsigned int i, max_loop;
  652. u16 value;
  653. u32 buffer[5] = {
  654. 0x00000000,
  655. 0x00D40000,
  656. 0x00000000,
  657. 0x01000000,
  658. 0x00000000,
  659. };
  660. if (ofdm) {
  661. max_loop = 0x1E;
  662. buffer[0] = 0x000201CC;
  663. } else {
  664. max_loop = 0xFA;
  665. buffer[0] = 0x000B846E;
  666. }
  667. for (i = 0; i < 5; i++)
  668. b43_ram_write(dev, i * 4, buffer[i]);
  669. b43_write16(dev, B43_MMIO_XMTSEL, 0x0000);
  670. if (dev->dev->core_rev < 11)
  671. b43_write16(dev, B43_MMIO_WEPCTL, 0x0000);
  672. else
  673. b43_write16(dev, B43_MMIO_WEPCTL, 0x0100);
  674. value = (ofdm ? 0x41 : 0x40);
  675. b43_write16(dev, B43_MMIO_TXE0_PHYCTL, value);
  676. if (phy->type == B43_PHYTYPE_N || phy->type == B43_PHYTYPE_LP ||
  677. phy->type == B43_PHYTYPE_LCN)
  678. b43_write16(dev, B43_MMIO_TXE0_PHYCTL1, 0x1A02);
  679. b43_write16(dev, B43_MMIO_TXE0_WM_0, 0x0000);
  680. b43_write16(dev, B43_MMIO_TXE0_WM_1, 0x0000);
  681. b43_write16(dev, B43_MMIO_XMTTPLATETXPTR, 0x0000);
  682. b43_write16(dev, B43_MMIO_XMTTXCNT, 0x0014);
  683. b43_write16(dev, B43_MMIO_XMTSEL, 0x0826);
  684. b43_write16(dev, B43_MMIO_TXE0_CTL, 0x0000);
  685. if (!pa_on && phy->type == B43_PHYTYPE_N)
  686. ; /*b43_nphy_pa_override(dev, false) */
  687. switch (phy->type) {
  688. case B43_PHYTYPE_N:
  689. case B43_PHYTYPE_LCN:
  690. b43_write16(dev, B43_MMIO_TXE0_AUX, 0x00D0);
  691. break;
  692. case B43_PHYTYPE_LP:
  693. b43_write16(dev, B43_MMIO_TXE0_AUX, 0x0050);
  694. break;
  695. default:
  696. b43_write16(dev, B43_MMIO_TXE0_AUX, 0x0030);
  697. }
  698. b43_read16(dev, B43_MMIO_TXE0_AUX);
  699. if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
  700. b43_radio_write16(dev, 0x0051, 0x0017);
  701. for (i = 0x00; i < max_loop; i++) {
  702. value = b43_read16(dev, B43_MMIO_TXE0_STATUS);
  703. if (value & 0x0080)
  704. break;
  705. udelay(10);
  706. }
  707. for (i = 0x00; i < 0x0A; i++) {
  708. value = b43_read16(dev, B43_MMIO_TXE0_STATUS);
  709. if (value & 0x0400)
  710. break;
  711. udelay(10);
  712. }
  713. for (i = 0x00; i < 0x19; i++) {
  714. value = b43_read16(dev, B43_MMIO_IFSSTAT);
  715. if (!(value & 0x0100))
  716. break;
  717. udelay(10);
  718. }
  719. if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
  720. b43_radio_write16(dev, 0x0051, 0x0037);
  721. }
  722. static void key_write(struct b43_wldev *dev,
  723. u8 index, u8 algorithm, const u8 *key)
  724. {
  725. unsigned int i;
  726. u32 offset;
  727. u16 value;
  728. u16 kidx;
  729. /* Key index/algo block */
  730. kidx = b43_kidx_to_fw(dev, index);
  731. value = ((kidx << 4) | algorithm);
  732. b43_shm_write16(dev, B43_SHM_SHARED,
  733. B43_SHM_SH_KEYIDXBLOCK + (kidx * 2), value);
  734. /* Write the key to the Key Table Pointer offset */
  735. offset = dev->ktp + (index * B43_SEC_KEYSIZE);
  736. for (i = 0; i < B43_SEC_KEYSIZE; i += 2) {
  737. value = key[i];
  738. value |= (u16) (key[i + 1]) << 8;
  739. b43_shm_write16(dev, B43_SHM_SHARED, offset + i, value);
  740. }
  741. }
  742. static void keymac_write(struct b43_wldev *dev, u8 index, const u8 *addr)
  743. {
  744. u32 addrtmp[2] = { 0, 0, };
  745. u8 pairwise_keys_start = B43_NR_GROUP_KEYS * 2;
  746. if (b43_new_kidx_api(dev))
  747. pairwise_keys_start = B43_NR_GROUP_KEYS;
  748. B43_WARN_ON(index < pairwise_keys_start);
  749. /* We have four default TX keys and possibly four default RX keys.
  750. * Physical mac 0 is mapped to physical key 4 or 8, depending
  751. * on the firmware version.
  752. * So we must adjust the index here.
  753. */
  754. index -= pairwise_keys_start;
  755. B43_WARN_ON(index >= B43_NR_PAIRWISE_KEYS);
  756. if (addr) {
  757. addrtmp[0] = addr[0];
  758. addrtmp[0] |= ((u32) (addr[1]) << 8);
  759. addrtmp[0] |= ((u32) (addr[2]) << 16);
  760. addrtmp[0] |= ((u32) (addr[3]) << 24);
  761. addrtmp[1] = addr[4];
  762. addrtmp[1] |= ((u32) (addr[5]) << 8);
  763. }
  764. /* Receive match transmitter address (RCMTA) mechanism */
  765. b43_shm_write32(dev, B43_SHM_RCMTA,
  766. (index * 2) + 0, addrtmp[0]);
  767. b43_shm_write16(dev, B43_SHM_RCMTA,
  768. (index * 2) + 1, addrtmp[1]);
  769. }
  770. /* The ucode will use phase1 key with TEK key to decrypt rx packets.
  771. * When a packet is received, the iv32 is checked.
  772. * - if it doesn't the packet is returned without modification (and software
  773. * decryption can be done). That's what happen when iv16 wrap.
  774. * - if it does, the rc4 key is computed, and decryption is tried.
  775. * Either it will success and B43_RX_MAC_DEC is returned,
  776. * either it fails and B43_RX_MAC_DEC|B43_RX_MAC_DECERR is returned
  777. * and the packet is not usable (it got modified by the ucode).
  778. * So in order to never have B43_RX_MAC_DECERR, we should provide
  779. * a iv32 and phase1key that match. Because we drop packets in case of
  780. * B43_RX_MAC_DECERR, if we have a correct iv32 but a wrong phase1key, all
  781. * packets will be lost without higher layer knowing (ie no resync possible
  782. * until next wrap).
  783. *
  784. * NOTE : this should support 50 key like RCMTA because
  785. * (B43_SHM_SH_KEYIDXBLOCK - B43_SHM_SH_TKIPTSCTTAK)/14 = 50
  786. */
  787. static void rx_tkip_phase1_write(struct b43_wldev *dev, u8 index, u32 iv32,
  788. u16 *phase1key)
  789. {
  790. unsigned int i;
  791. u32 offset;
  792. u8 pairwise_keys_start = B43_NR_GROUP_KEYS * 2;
  793. if (!modparam_hwtkip)
  794. return;
  795. if (b43_new_kidx_api(dev))
  796. pairwise_keys_start = B43_NR_GROUP_KEYS;
  797. B43_WARN_ON(index < pairwise_keys_start);
  798. /* We have four default TX keys and possibly four default RX keys.
  799. * Physical mac 0 is mapped to physical key 4 or 8, depending
  800. * on the firmware version.
  801. * So we must adjust the index here.
  802. */
  803. index -= pairwise_keys_start;
  804. B43_WARN_ON(index >= B43_NR_PAIRWISE_KEYS);
  805. if (b43_debug(dev, B43_DBG_KEYS)) {
  806. b43dbg(dev->wl, "rx_tkip_phase1_write : idx 0x%x, iv32 0x%x\n",
  807. index, iv32);
  808. }
  809. /* Write the key to the RX tkip shared mem */
  810. offset = B43_SHM_SH_TKIPTSCTTAK + index * (10 + 4);
  811. for (i = 0; i < 10; i += 2) {
  812. b43_shm_write16(dev, B43_SHM_SHARED, offset + i,
  813. phase1key ? phase1key[i / 2] : 0);
  814. }
  815. b43_shm_write16(dev, B43_SHM_SHARED, offset + i, iv32);
  816. b43_shm_write16(dev, B43_SHM_SHARED, offset + i + 2, iv32 >> 16);
  817. }
  818. static void b43_op_update_tkip_key(struct ieee80211_hw *hw,
  819. struct ieee80211_vif *vif,
  820. struct ieee80211_key_conf *keyconf,
  821. struct ieee80211_sta *sta,
  822. u32 iv32, u16 *phase1key)
  823. {
  824. struct b43_wl *wl = hw_to_b43_wl(hw);
  825. struct b43_wldev *dev;
  826. int index = keyconf->hw_key_idx;
  827. if (B43_WARN_ON(!modparam_hwtkip))
  828. return;
  829. /* This is only called from the RX path through mac80211, where
  830. * our mutex is already locked. */
  831. B43_WARN_ON(!mutex_is_locked(&wl->mutex));
  832. dev = wl->current_dev;
  833. B43_WARN_ON(!dev || b43_status(dev) < B43_STAT_INITIALIZED);
  834. keymac_write(dev, index, NULL); /* First zero out mac to avoid race */
  835. rx_tkip_phase1_write(dev, index, iv32, phase1key);
  836. /* only pairwise TKIP keys are supported right now */
  837. if (WARN_ON(!sta))
  838. return;
  839. keymac_write(dev, index, sta->addr);
  840. }
  841. static void do_key_write(struct b43_wldev *dev,
  842. u8 index, u8 algorithm,
  843. const u8 *key, size_t key_len, const u8 *mac_addr)
  844. {
  845. u8 buf[B43_SEC_KEYSIZE] = { 0, };
  846. u8 pairwise_keys_start = B43_NR_GROUP_KEYS * 2;
  847. if (b43_new_kidx_api(dev))
  848. pairwise_keys_start = B43_NR_GROUP_KEYS;
  849. B43_WARN_ON(index >= ARRAY_SIZE(dev->key));
  850. B43_WARN_ON(key_len > B43_SEC_KEYSIZE);
  851. if (index >= pairwise_keys_start)
  852. keymac_write(dev, index, NULL); /* First zero out mac. */
  853. if (algorithm == B43_SEC_ALGO_TKIP) {
  854. /*
  855. * We should provide an initial iv32, phase1key pair.
  856. * We could start with iv32=0 and compute the corresponding
  857. * phase1key, but this means calling ieee80211_get_tkip_key
  858. * with a fake skb (or export other tkip function).
  859. * Because we are lazy we hope iv32 won't start with
  860. * 0xffffffff and let's b43_op_update_tkip_key provide a
  861. * correct pair.
  862. */
  863. rx_tkip_phase1_write(dev, index, 0xffffffff, (u16*)buf);
  864. } else if (index >= pairwise_keys_start) /* clear it */
  865. rx_tkip_phase1_write(dev, index, 0, NULL);
  866. if (key)
  867. memcpy(buf, key, key_len);
  868. key_write(dev, index, algorithm, buf);
  869. if (index >= pairwise_keys_start)
  870. keymac_write(dev, index, mac_addr);
  871. dev->key[index].algorithm = algorithm;
  872. }
  873. static int b43_key_write(struct b43_wldev *dev,
  874. int index, u8 algorithm,
  875. const u8 *key, size_t key_len,
  876. const u8 *mac_addr,
  877. struct ieee80211_key_conf *keyconf)
  878. {
  879. int i;
  880. int pairwise_keys_start;
  881. /* For ALG_TKIP the key is encoded as a 256-bit (32 byte) data block:
  882. * - Temporal Encryption Key (128 bits)
  883. * - Temporal Authenticator Tx MIC Key (64 bits)
  884. * - Temporal Authenticator Rx MIC Key (64 bits)
  885. *
  886. * Hardware only store TEK
  887. */
  888. if (algorithm == B43_SEC_ALGO_TKIP && key_len == 32)
  889. key_len = 16;
  890. if (key_len > B43_SEC_KEYSIZE)
  891. return -EINVAL;
  892. for (i = 0; i < ARRAY_SIZE(dev->key); i++) {
  893. /* Check that we don't already have this key. */
  894. B43_WARN_ON(dev->key[i].keyconf == keyconf);
  895. }
  896. if (index < 0) {
  897. /* Pairwise key. Get an empty slot for the key. */
  898. if (b43_new_kidx_api(dev))
  899. pairwise_keys_start = B43_NR_GROUP_KEYS;
  900. else
  901. pairwise_keys_start = B43_NR_GROUP_KEYS * 2;
  902. for (i = pairwise_keys_start;
  903. i < pairwise_keys_start + B43_NR_PAIRWISE_KEYS;
  904. i++) {
  905. B43_WARN_ON(i >= ARRAY_SIZE(dev->key));
  906. if (!dev->key[i].keyconf) {
  907. /* found empty */
  908. index = i;
  909. break;
  910. }
  911. }
  912. if (index < 0) {
  913. b43warn(dev->wl, "Out of hardware key memory\n");
  914. return -ENOSPC;
  915. }
  916. } else
  917. B43_WARN_ON(index > 3);
  918. do_key_write(dev, index, algorithm, key, key_len, mac_addr);
  919. if ((index <= 3) && !b43_new_kidx_api(dev)) {
  920. /* Default RX key */
  921. B43_WARN_ON(mac_addr);
  922. do_key_write(dev, index + 4, algorithm, key, key_len, NULL);
  923. }
  924. keyconf->hw_key_idx = index;
  925. dev->key[index].keyconf = keyconf;
  926. return 0;
  927. }
  928. static int b43_key_clear(struct b43_wldev *dev, int index)
  929. {
  930. if (B43_WARN_ON((index < 0) || (index >= ARRAY_SIZE(dev->key))))
  931. return -EINVAL;
  932. do_key_write(dev, index, B43_SEC_ALGO_NONE,
  933. NULL, B43_SEC_KEYSIZE, NULL);
  934. if ((index <= 3) && !b43_new_kidx_api(dev)) {
  935. do_key_write(dev, index + 4, B43_SEC_ALGO_NONE,
  936. NULL, B43_SEC_KEYSIZE, NULL);
  937. }
  938. dev->key[index].keyconf = NULL;
  939. return 0;
  940. }
  941. static void b43_clear_keys(struct b43_wldev *dev)
  942. {
  943. int i, count;
  944. if (b43_new_kidx_api(dev))
  945. count = B43_NR_GROUP_KEYS + B43_NR_PAIRWISE_KEYS;
  946. else
  947. count = B43_NR_GROUP_KEYS * 2 + B43_NR_PAIRWISE_KEYS;
  948. for (i = 0; i < count; i++)
  949. b43_key_clear(dev, i);
  950. }
  951. static void b43_dump_keymemory(struct b43_wldev *dev)
  952. {
  953. unsigned int i, index, count, offset, pairwise_keys_start;
  954. u8 mac[ETH_ALEN];
  955. u16 algo;
  956. u32 rcmta0;
  957. u16 rcmta1;
  958. u64 hf;
  959. struct b43_key *key;
  960. if (!b43_debug(dev, B43_DBG_KEYS))
  961. return;
  962. hf = b43_hf_read(dev);
  963. b43dbg(dev->wl, "Hardware key memory dump: USEDEFKEYS=%u\n",
  964. !!(hf & B43_HF_USEDEFKEYS));
  965. if (b43_new_kidx_api(dev)) {
  966. pairwise_keys_start = B43_NR_GROUP_KEYS;
  967. count = B43_NR_GROUP_KEYS + B43_NR_PAIRWISE_KEYS;
  968. } else {
  969. pairwise_keys_start = B43_NR_GROUP_KEYS * 2;
  970. count = B43_NR_GROUP_KEYS * 2 + B43_NR_PAIRWISE_KEYS;
  971. }
  972. for (index = 0; index < count; index++) {
  973. key = &(dev->key[index]);
  974. printk(KERN_DEBUG "Key slot %02u: %s",
  975. index, (key->keyconf == NULL) ? " " : "*");
  976. offset = dev->ktp + (index * B43_SEC_KEYSIZE);
  977. for (i = 0; i < B43_SEC_KEYSIZE; i += 2) {
  978. u16 tmp = b43_shm_read16(dev, B43_SHM_SHARED, offset + i);
  979. printk("%02X%02X", (tmp & 0xFF), ((tmp >> 8) & 0xFF));
  980. }
  981. algo = b43_shm_read16(dev, B43_SHM_SHARED,
  982. B43_SHM_SH_KEYIDXBLOCK + (index * 2));
  983. printk(" Algo: %04X/%02X", algo, key->algorithm);
  984. if (index >= pairwise_keys_start) {
  985. if (key->algorithm == B43_SEC_ALGO_TKIP) {
  986. printk(" TKIP: ");
  987. offset = B43_SHM_SH_TKIPTSCTTAK + (index - 4) * (10 + 4);
  988. for (i = 0; i < 14; i += 2) {
  989. u16 tmp = b43_shm_read16(dev, B43_SHM_SHARED, offset + i);
  990. printk("%02X%02X", (tmp & 0xFF), ((tmp >> 8) & 0xFF));
  991. }
  992. }
  993. rcmta0 = b43_shm_read32(dev, B43_SHM_RCMTA,
  994. ((index - pairwise_keys_start) * 2) + 0);
  995. rcmta1 = b43_shm_read16(dev, B43_SHM_RCMTA,
  996. ((index - pairwise_keys_start) * 2) + 1);
  997. *((__le32 *)(&mac[0])) = cpu_to_le32(rcmta0);
  998. *((__le16 *)(&mac[4])) = cpu_to_le16(rcmta1);
  999. printk(" MAC: %pM", mac);
  1000. } else
  1001. printk(" DEFAULT KEY");
  1002. printk("\n");
  1003. }
  1004. }
  1005. void b43_power_saving_ctl_bits(struct b43_wldev *dev, unsigned int ps_flags)
  1006. {
  1007. u32 macctl;
  1008. u16 ucstat;
  1009. bool hwps;
  1010. bool awake;
  1011. int i;
  1012. B43_WARN_ON((ps_flags & B43_PS_ENABLED) &&
  1013. (ps_flags & B43_PS_DISABLED));
  1014. B43_WARN_ON((ps_flags & B43_PS_AWAKE) && (ps_flags & B43_PS_ASLEEP));
  1015. if (ps_flags & B43_PS_ENABLED) {
  1016. hwps = true;
  1017. } else if (ps_flags & B43_PS_DISABLED) {
  1018. hwps = false;
  1019. } else {
  1020. //TODO: If powersave is not off and FIXME is not set and we are not in adhoc
  1021. // and thus is not an AP and we are associated, set bit 25
  1022. }
  1023. if (ps_flags & B43_PS_AWAKE) {
  1024. awake = true;
  1025. } else if (ps_flags & B43_PS_ASLEEP) {
  1026. awake = false;
  1027. } else {
  1028. //TODO: If the device is awake or this is an AP, or we are scanning, or FIXME,
  1029. // or we are associated, or FIXME, or the latest PS-Poll packet sent was
  1030. // successful, set bit26
  1031. }
  1032. /* FIXME: For now we force awake-on and hwps-off */
  1033. hwps = false;
  1034. awake = true;
  1035. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  1036. if (hwps)
  1037. macctl |= B43_MACCTL_HWPS;
  1038. else
  1039. macctl &= ~B43_MACCTL_HWPS;
  1040. if (awake)
  1041. macctl |= B43_MACCTL_AWAKE;
  1042. else
  1043. macctl &= ~B43_MACCTL_AWAKE;
  1044. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  1045. /* Commit write */
  1046. b43_read32(dev, B43_MMIO_MACCTL);
  1047. if (awake && dev->dev->core_rev >= 5) {
  1048. /* Wait for the microcode to wake up. */
  1049. for (i = 0; i < 100; i++) {
  1050. ucstat = b43_shm_read16(dev, B43_SHM_SHARED,
  1051. B43_SHM_SH_UCODESTAT);
  1052. if (ucstat != B43_SHM_SH_UCODESTAT_SLEEP)
  1053. break;
  1054. udelay(10);
  1055. }
  1056. }
  1057. }
  1058. /* http://bcm-v4.sipsolutions.net/802.11/PHY/BmacCorePllReset */
  1059. void b43_wireless_core_phy_pll_reset(struct b43_wldev *dev)
  1060. {
  1061. struct bcma_drv_cc *bcma_cc __maybe_unused;
  1062. struct ssb_chipcommon *ssb_cc __maybe_unused;
  1063. switch (dev->dev->bus_type) {
  1064. #ifdef CONFIG_B43_BCMA
  1065. case B43_BUS_BCMA:
  1066. bcma_cc = &dev->dev->bdev->bus->drv_cc;
  1067. bcma_cc_write32(bcma_cc, BCMA_CC_PMU_CHIPCTL_ADDR, 0);
  1068. bcma_cc_mask32(bcma_cc, BCMA_CC_PMU_CHIPCTL_DATA, ~0x4);
  1069. bcma_cc_set32(bcma_cc, BCMA_CC_PMU_CHIPCTL_DATA, 0x4);
  1070. bcma_cc_mask32(bcma_cc, BCMA_CC_PMU_CHIPCTL_DATA, ~0x4);
  1071. break;
  1072. #endif
  1073. #ifdef CONFIG_B43_SSB
  1074. case B43_BUS_SSB:
  1075. ssb_cc = &dev->dev->sdev->bus->chipco;
  1076. chipco_write32(ssb_cc, SSB_CHIPCO_CHIPCTL_ADDR, 0);
  1077. chipco_mask32(ssb_cc, SSB_CHIPCO_CHIPCTL_DATA, ~0x4);
  1078. chipco_set32(ssb_cc, SSB_CHIPCO_CHIPCTL_DATA, 0x4);
  1079. chipco_mask32(ssb_cc, SSB_CHIPCO_CHIPCTL_DATA, ~0x4);
  1080. break;
  1081. #endif
  1082. }
  1083. }
  1084. #ifdef CONFIG_B43_BCMA
  1085. static void b43_bcma_phy_reset(struct b43_wldev *dev)
  1086. {
  1087. u32 flags;
  1088. /* Put PHY into reset */
  1089. flags = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  1090. flags |= B43_BCMA_IOCTL_PHY_RESET;
  1091. flags |= B43_BCMA_IOCTL_PHY_BW_20MHZ; /* Make 20 MHz def */
  1092. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, flags);
  1093. udelay(2);
  1094. b43_phy_take_out_of_reset(dev);
  1095. }
  1096. static void b43_bcma_wireless_core_reset(struct b43_wldev *dev, bool gmode)
  1097. {
  1098. u32 req = B43_BCMA_CLKCTLST_80211_PLL_REQ |
  1099. B43_BCMA_CLKCTLST_PHY_PLL_REQ;
  1100. u32 status = B43_BCMA_CLKCTLST_80211_PLL_ST |
  1101. B43_BCMA_CLKCTLST_PHY_PLL_ST;
  1102. u32 flags;
  1103. flags = B43_BCMA_IOCTL_PHY_CLKEN;
  1104. if (gmode)
  1105. flags |= B43_BCMA_IOCTL_GMODE;
  1106. b43_device_enable(dev, flags);
  1107. if (dev->phy.type == B43_PHYTYPE_AC) {
  1108. u16 tmp;
  1109. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  1110. tmp &= ~B43_BCMA_IOCTL_DAC;
  1111. tmp |= 0x100;
  1112. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  1113. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  1114. tmp &= ~B43_BCMA_IOCTL_PHY_CLKEN;
  1115. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  1116. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  1117. tmp |= B43_BCMA_IOCTL_PHY_CLKEN;
  1118. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  1119. }
  1120. bcma_core_set_clockmode(dev->dev->bdev, BCMA_CLKMODE_FAST);
  1121. b43_bcma_phy_reset(dev);
  1122. bcma_core_pll_ctl(dev->dev->bdev, req, status, true);
  1123. }
  1124. #endif
  1125. #ifdef CONFIG_B43_SSB
  1126. static void b43_ssb_wireless_core_reset(struct b43_wldev *dev, bool gmode)
  1127. {
  1128. u32 flags = 0;
  1129. if (gmode)
  1130. flags |= B43_TMSLOW_GMODE;
  1131. flags |= B43_TMSLOW_PHYCLKEN;
  1132. flags |= B43_TMSLOW_PHYRESET;
  1133. if (dev->phy.type == B43_PHYTYPE_N)
  1134. flags |= B43_TMSLOW_PHY_BANDWIDTH_20MHZ; /* Make 20 MHz def */
  1135. b43_device_enable(dev, flags);
  1136. msleep(2); /* Wait for the PLL to turn on. */
  1137. b43_phy_take_out_of_reset(dev);
  1138. }
  1139. #endif
  1140. void b43_wireless_core_reset(struct b43_wldev *dev, bool gmode)
  1141. {
  1142. u32 macctl;
  1143. switch (dev->dev->bus_type) {
  1144. #ifdef CONFIG_B43_BCMA
  1145. case B43_BUS_BCMA:
  1146. b43_bcma_wireless_core_reset(dev, gmode);
  1147. break;
  1148. #endif
  1149. #ifdef CONFIG_B43_SSB
  1150. case B43_BUS_SSB:
  1151. b43_ssb_wireless_core_reset(dev, gmode);
  1152. break;
  1153. #endif
  1154. }
  1155. /* Turn Analog ON, but only if we already know the PHY-type.
  1156. * This protects against very early setup where we don't know the
  1157. * PHY-type, yet. wireless_core_reset will be called once again later,
  1158. * when we know the PHY-type. */
  1159. if (dev->phy.ops)
  1160. dev->phy.ops->switch_analog(dev, 1);
  1161. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  1162. macctl &= ~B43_MACCTL_GMODE;
  1163. if (gmode)
  1164. macctl |= B43_MACCTL_GMODE;
  1165. macctl |= B43_MACCTL_IHR_ENABLED;
  1166. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  1167. }
  1168. static void handle_irq_transmit_status(struct b43_wldev *dev)
  1169. {
  1170. u32 v0, v1;
  1171. u16 tmp;
  1172. struct b43_txstatus stat;
  1173. while (1) {
  1174. v0 = b43_read32(dev, B43_MMIO_XMITSTAT_0);
  1175. if (!(v0 & 0x00000001))
  1176. break;
  1177. v1 = b43_read32(dev, B43_MMIO_XMITSTAT_1);
  1178. stat.cookie = (v0 >> 16);
  1179. stat.seq = (v1 & 0x0000FFFF);
  1180. stat.phy_stat = ((v1 & 0x00FF0000) >> 16);
  1181. tmp = (v0 & 0x0000FFFF);
  1182. stat.frame_count = ((tmp & 0xF000) >> 12);
  1183. stat.rts_count = ((tmp & 0x0F00) >> 8);
  1184. stat.supp_reason = ((tmp & 0x001C) >> 2);
  1185. stat.pm_indicated = !!(tmp & 0x0080);
  1186. stat.intermediate = !!(tmp & 0x0040);
  1187. stat.for_ampdu = !!(tmp & 0x0020);
  1188. stat.acked = !!(tmp & 0x0002);
  1189. b43_handle_txstatus(dev, &stat);
  1190. }
  1191. }
  1192. static void drain_txstatus_queue(struct b43_wldev *dev)
  1193. {
  1194. u32 dummy;
  1195. if (dev->dev->core_rev < 5)
  1196. return;
  1197. /* Read all entries from the microcode TXstatus FIFO
  1198. * and throw them away.
  1199. */
  1200. while (1) {
  1201. dummy = b43_read32(dev, B43_MMIO_XMITSTAT_0);
  1202. if (!(dummy & 0x00000001))
  1203. break;
  1204. dummy = b43_read32(dev, B43_MMIO_XMITSTAT_1);
  1205. }
  1206. }
  1207. static u32 b43_jssi_read(struct b43_wldev *dev)
  1208. {
  1209. u32 val = 0;
  1210. val = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_JSSI1);
  1211. val <<= 16;
  1212. val |= b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_JSSI0);
  1213. return val;
  1214. }
  1215. static void b43_jssi_write(struct b43_wldev *dev, u32 jssi)
  1216. {
  1217. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_JSSI0,
  1218. (jssi & 0x0000FFFF));
  1219. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_JSSI1,
  1220. (jssi & 0xFFFF0000) >> 16);
  1221. }
  1222. static void b43_generate_noise_sample(struct b43_wldev *dev)
  1223. {
  1224. b43_jssi_write(dev, 0x7F7F7F7F);
  1225. b43_write32(dev, B43_MMIO_MACCMD,
  1226. b43_read32(dev, B43_MMIO_MACCMD) | B43_MACCMD_BGNOISE);
  1227. }
  1228. static void b43_calculate_link_quality(struct b43_wldev *dev)
  1229. {
  1230. /* Top half of Link Quality calculation. */
  1231. if (dev->phy.type != B43_PHYTYPE_G)
  1232. return;
  1233. if (dev->noisecalc.calculation_running)
  1234. return;
  1235. dev->noisecalc.calculation_running = true;
  1236. dev->noisecalc.nr_samples = 0;
  1237. b43_generate_noise_sample(dev);
  1238. }
  1239. static void handle_irq_noise(struct b43_wldev *dev)
  1240. {
  1241. struct b43_phy_g *phy = dev->phy.g;
  1242. u16 tmp;
  1243. u8 noise[4];
  1244. u8 i, j;
  1245. s32 average;
  1246. /* Bottom half of Link Quality calculation. */
  1247. if (dev->phy.type != B43_PHYTYPE_G)
  1248. return;
  1249. /* Possible race condition: It might be possible that the user
  1250. * changed to a different channel in the meantime since we
  1251. * started the calculation. We ignore that fact, since it's
  1252. * not really that much of a problem. The background noise is
  1253. * an estimation only anyway. Slightly wrong results will get damped
  1254. * by the averaging of the 8 sample rounds. Additionally the
  1255. * value is shortlived. So it will be replaced by the next noise
  1256. * calculation round soon. */
  1257. B43_WARN_ON(!dev->noisecalc.calculation_running);
  1258. *((__le32 *)noise) = cpu_to_le32(b43_jssi_read(dev));
  1259. if (noise[0] == 0x7F || noise[1] == 0x7F ||
  1260. noise[2] == 0x7F || noise[3] == 0x7F)
  1261. goto generate_new;
  1262. /* Get the noise samples. */
  1263. B43_WARN_ON(dev->noisecalc.nr_samples >= 8);
  1264. i = dev->noisecalc.nr_samples;
  1265. noise[0] = clamp_val(noise[0], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1266. noise[1] = clamp_val(noise[1], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1267. noise[2] = clamp_val(noise[2], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1268. noise[3] = clamp_val(noise[3], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1269. dev->noisecalc.samples[i][0] = phy->nrssi_lt[noise[0]];
  1270. dev->noisecalc.samples[i][1] = phy->nrssi_lt[noise[1]];
  1271. dev->noisecalc.samples[i][2] = phy->nrssi_lt[noise[2]];
  1272. dev->noisecalc.samples[i][3] = phy->nrssi_lt[noise[3]];
  1273. dev->noisecalc.nr_samples++;
  1274. if (dev->noisecalc.nr_samples == 8) {
  1275. /* Calculate the Link Quality by the noise samples. */
  1276. average = 0;
  1277. for (i = 0; i < 8; i++) {
  1278. for (j = 0; j < 4; j++)
  1279. average += dev->noisecalc.samples[i][j];
  1280. }
  1281. average /= (8 * 4);
  1282. average *= 125;
  1283. average += 64;
  1284. average /= 128;
  1285. tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x40C);
  1286. tmp = (tmp / 128) & 0x1F;
  1287. if (tmp >= 8)
  1288. average += 2;
  1289. else
  1290. average -= 25;
  1291. if (tmp == 8)
  1292. average -= 72;
  1293. else
  1294. average -= 48;
  1295. dev->stats.link_noise = average;
  1296. dev->noisecalc.calculation_running = false;
  1297. return;
  1298. }
  1299. generate_new:
  1300. b43_generate_noise_sample(dev);
  1301. }
  1302. static void handle_irq_tbtt_indication(struct b43_wldev *dev)
  1303. {
  1304. if (b43_is_mode(dev->wl, NL80211_IFTYPE_AP)) {
  1305. ///TODO: PS TBTT
  1306. } else {
  1307. if (1 /*FIXME: the last PSpoll frame was sent successfully */ )
  1308. b43_power_saving_ctl_bits(dev, 0);
  1309. }
  1310. if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC))
  1311. dev->dfq_valid = true;
  1312. }
  1313. static void handle_irq_atim_end(struct b43_wldev *dev)
  1314. {
  1315. if (dev->dfq_valid) {
  1316. b43_write32(dev, B43_MMIO_MACCMD,
  1317. b43_read32(dev, B43_MMIO_MACCMD)
  1318. | B43_MACCMD_DFQ_VALID);
  1319. dev->dfq_valid = false;
  1320. }
  1321. }
  1322. static void handle_irq_pmq(struct b43_wldev *dev)
  1323. {
  1324. u32 tmp;
  1325. //TODO: AP mode.
  1326. while (1) {
  1327. tmp = b43_read32(dev, B43_MMIO_PS_STATUS);
  1328. if (!(tmp & 0x00000008))
  1329. break;
  1330. }
  1331. /* 16bit write is odd, but correct. */
  1332. b43_write16(dev, B43_MMIO_PS_STATUS, 0x0002);
  1333. }
  1334. static void b43_write_template_common(struct b43_wldev *dev,
  1335. const u8 *data, u16 size,
  1336. u16 ram_offset,
  1337. u16 shm_size_offset, u8 rate)
  1338. {
  1339. u32 i, tmp;
  1340. struct b43_plcp_hdr4 plcp;
  1341. plcp.data = 0;
  1342. b43_generate_plcp_hdr(&plcp, size + FCS_LEN, rate);
  1343. b43_ram_write(dev, ram_offset, le32_to_cpu(plcp.data));
  1344. ram_offset += sizeof(u32);
  1345. /* The PLCP is 6 bytes long, but we only wrote 4 bytes, yet.
  1346. * So leave the first two bytes of the next write blank.
  1347. */
  1348. tmp = (u32) (data[0]) << 16;
  1349. tmp |= (u32) (data[1]) << 24;
  1350. b43_ram_write(dev, ram_offset, tmp);
  1351. ram_offset += sizeof(u32);
  1352. for (i = 2; i < size; i += sizeof(u32)) {
  1353. tmp = (u32) (data[i + 0]);
  1354. if (i + 1 < size)
  1355. tmp |= (u32) (data[i + 1]) << 8;
  1356. if (i + 2 < size)
  1357. tmp |= (u32) (data[i + 2]) << 16;
  1358. if (i + 3 < size)
  1359. tmp |= (u32) (data[i + 3]) << 24;
  1360. b43_ram_write(dev, ram_offset + i - 2, tmp);
  1361. }
  1362. b43_shm_write16(dev, B43_SHM_SHARED, shm_size_offset,
  1363. size + sizeof(struct b43_plcp_hdr6));
  1364. }
  1365. /* Check if the use of the antenna that ieee80211 told us to
  1366. * use is possible. This will fall back to DEFAULT.
  1367. * "antenna_nr" is the antenna identifier we got from ieee80211. */
  1368. u8 b43_ieee80211_antenna_sanitize(struct b43_wldev *dev,
  1369. u8 antenna_nr)
  1370. {
  1371. u8 antenna_mask;
  1372. if (antenna_nr == 0) {
  1373. /* Zero means "use default antenna". That's always OK. */
  1374. return 0;
  1375. }
  1376. /* Get the mask of available antennas. */
  1377. if (dev->phy.gmode)
  1378. antenna_mask = dev->dev->bus_sprom->ant_available_bg;
  1379. else
  1380. antenna_mask = dev->dev->bus_sprom->ant_available_a;
  1381. if (!(antenna_mask & (1 << (antenna_nr - 1)))) {
  1382. /* This antenna is not available. Fall back to default. */
  1383. return 0;
  1384. }
  1385. return antenna_nr;
  1386. }
  1387. /* Convert a b43 antenna number value to the PHY TX control value. */
  1388. static u16 b43_antenna_to_phyctl(int antenna)
  1389. {
  1390. switch (antenna) {
  1391. case B43_ANTENNA0:
  1392. return B43_TXH_PHY_ANT0;
  1393. case B43_ANTENNA1:
  1394. return B43_TXH_PHY_ANT1;
  1395. case B43_ANTENNA2:
  1396. return B43_TXH_PHY_ANT2;
  1397. case B43_ANTENNA3:
  1398. return B43_TXH_PHY_ANT3;
  1399. case B43_ANTENNA_AUTO0:
  1400. case B43_ANTENNA_AUTO1:
  1401. return B43_TXH_PHY_ANT01AUTO;
  1402. }
  1403. B43_WARN_ON(1);
  1404. return 0;
  1405. }
  1406. static void b43_write_beacon_template(struct b43_wldev *dev,
  1407. u16 ram_offset,
  1408. u16 shm_size_offset)
  1409. {
  1410. unsigned int i, len, variable_len;
  1411. const struct ieee80211_mgmt *bcn;
  1412. const u8 *ie;
  1413. bool tim_found = false;
  1414. unsigned int rate;
  1415. u16 ctl;
  1416. int antenna;
  1417. struct ieee80211_tx_info *info;
  1418. unsigned long flags;
  1419. struct sk_buff *beacon_skb;
  1420. spin_lock_irqsave(&dev->wl->beacon_lock, flags);
  1421. info = IEEE80211_SKB_CB(dev->wl->current_beacon);
  1422. rate = ieee80211_get_tx_rate(dev->wl->hw, info)->hw_value;
  1423. /* Clone the beacon, so it cannot go away, while we write it to hw. */
  1424. beacon_skb = skb_clone(dev->wl->current_beacon, GFP_ATOMIC);
  1425. spin_unlock_irqrestore(&dev->wl->beacon_lock, flags);
  1426. if (!beacon_skb) {
  1427. b43dbg(dev->wl, "Could not upload beacon. "
  1428. "Failed to clone beacon skb.");
  1429. return;
  1430. }
  1431. bcn = (const struct ieee80211_mgmt *)(beacon_skb->data);
  1432. len = min_t(size_t, beacon_skb->len,
  1433. 0x200 - sizeof(struct b43_plcp_hdr6));
  1434. b43_write_template_common(dev, (const u8 *)bcn,
  1435. len, ram_offset, shm_size_offset, rate);
  1436. /* Write the PHY TX control parameters. */
  1437. antenna = B43_ANTENNA_DEFAULT;
  1438. antenna = b43_antenna_to_phyctl(antenna);
  1439. ctl = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL);
  1440. /* We can't send beacons with short preamble. Would get PHY errors. */
  1441. ctl &= ~B43_TXH_PHY_SHORTPRMBL;
  1442. ctl &= ~B43_TXH_PHY_ANT;
  1443. ctl &= ~B43_TXH_PHY_ENC;
  1444. ctl |= antenna;
  1445. if (b43_is_cck_rate(rate))
  1446. ctl |= B43_TXH_PHY_ENC_CCK;
  1447. else
  1448. ctl |= B43_TXH_PHY_ENC_OFDM;
  1449. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL, ctl);
  1450. /* Find the position of the TIM and the DTIM_period value
  1451. * and write them to SHM. */
  1452. ie = bcn->u.beacon.variable;
  1453. variable_len = len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
  1454. for (i = 0; i < variable_len - 2; ) {
  1455. uint8_t ie_id, ie_len;
  1456. ie_id = ie[i];
  1457. ie_len = ie[i + 1];
  1458. if (ie_id == 5) {
  1459. u16 tim_position;
  1460. u16 dtim_period;
  1461. /* This is the TIM Information Element */
  1462. /* Check whether the ie_len is in the beacon data range. */
  1463. if (variable_len < ie_len + 2 + i)
  1464. break;
  1465. /* A valid TIM is at least 4 bytes long. */
  1466. if (ie_len < 4)
  1467. break;
  1468. tim_found = true;
  1469. tim_position = sizeof(struct b43_plcp_hdr6);
  1470. tim_position += offsetof(struct ieee80211_mgmt, u.beacon.variable);
  1471. tim_position += i;
  1472. dtim_period = ie[i + 3];
  1473. b43_shm_write16(dev, B43_SHM_SHARED,
  1474. B43_SHM_SH_TIMBPOS, tim_position);
  1475. b43_shm_write16(dev, B43_SHM_SHARED,
  1476. B43_SHM_SH_DTIMPER, dtim_period);
  1477. break;
  1478. }
  1479. i += ie_len + 2;
  1480. }
  1481. if (!tim_found) {
  1482. /*
  1483. * If ucode wants to modify TIM do it behind the beacon, this
  1484. * will happen, for example, when doing mesh networking.
  1485. */
  1486. b43_shm_write16(dev, B43_SHM_SHARED,
  1487. B43_SHM_SH_TIMBPOS,
  1488. len + sizeof(struct b43_plcp_hdr6));
  1489. b43_shm_write16(dev, B43_SHM_SHARED,
  1490. B43_SHM_SH_DTIMPER, 0);
  1491. }
  1492. b43dbg(dev->wl, "Updated beacon template at 0x%x\n", ram_offset);
  1493. dev_kfree_skb_any(beacon_skb);
  1494. }
  1495. static void b43_upload_beacon0(struct b43_wldev *dev)
  1496. {
  1497. struct b43_wl *wl = dev->wl;
  1498. if (wl->beacon0_uploaded)
  1499. return;
  1500. b43_write_beacon_template(dev, B43_SHM_SH_BT_BASE0, B43_SHM_SH_BTL0);
  1501. wl->beacon0_uploaded = true;
  1502. }
  1503. static void b43_upload_beacon1(struct b43_wldev *dev)
  1504. {
  1505. struct b43_wl *wl = dev->wl;
  1506. if (wl->beacon1_uploaded)
  1507. return;
  1508. b43_write_beacon_template(dev, B43_SHM_SH_BT_BASE1, B43_SHM_SH_BTL1);
  1509. wl->beacon1_uploaded = true;
  1510. }
  1511. static void handle_irq_beacon(struct b43_wldev *dev)
  1512. {
  1513. struct b43_wl *wl = dev->wl;
  1514. u32 cmd, beacon0_valid, beacon1_valid;
  1515. if (!b43_is_mode(wl, NL80211_IFTYPE_AP) &&
  1516. !b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT) &&
  1517. !b43_is_mode(wl, NL80211_IFTYPE_ADHOC))
  1518. return;
  1519. /* This is the bottom half of the asynchronous beacon update. */
  1520. /* Ignore interrupt in the future. */
  1521. dev->irq_mask &= ~B43_IRQ_BEACON;
  1522. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1523. beacon0_valid = (cmd & B43_MACCMD_BEACON0_VALID);
  1524. beacon1_valid = (cmd & B43_MACCMD_BEACON1_VALID);
  1525. /* Schedule interrupt manually, if busy. */
  1526. if (beacon0_valid && beacon1_valid) {
  1527. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, B43_IRQ_BEACON);
  1528. dev->irq_mask |= B43_IRQ_BEACON;
  1529. return;
  1530. }
  1531. if (unlikely(wl->beacon_templates_virgin)) {
  1532. /* We never uploaded a beacon before.
  1533. * Upload both templates now, but only mark one valid. */
  1534. wl->beacon_templates_virgin = false;
  1535. b43_upload_beacon0(dev);
  1536. b43_upload_beacon1(dev);
  1537. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1538. cmd |= B43_MACCMD_BEACON0_VALID;
  1539. b43_write32(dev, B43_MMIO_MACCMD, cmd);
  1540. } else {
  1541. if (!beacon0_valid) {
  1542. b43_upload_beacon0(dev);
  1543. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1544. cmd |= B43_MACCMD_BEACON0_VALID;
  1545. b43_write32(dev, B43_MMIO_MACCMD, cmd);
  1546. } else if (!beacon1_valid) {
  1547. b43_upload_beacon1(dev);
  1548. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1549. cmd |= B43_MACCMD_BEACON1_VALID;
  1550. b43_write32(dev, B43_MMIO_MACCMD, cmd);
  1551. }
  1552. }
  1553. }
  1554. static void b43_do_beacon_update_trigger_work(struct b43_wldev *dev)
  1555. {
  1556. u32 old_irq_mask = dev->irq_mask;
  1557. /* update beacon right away or defer to irq */
  1558. handle_irq_beacon(dev);
  1559. if (old_irq_mask != dev->irq_mask) {
  1560. /* The handler updated the IRQ mask. */
  1561. B43_WARN_ON(!dev->irq_mask);
  1562. if (b43_read32(dev, B43_MMIO_GEN_IRQ_MASK)) {
  1563. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
  1564. } else {
  1565. /* Device interrupts are currently disabled. That means
  1566. * we just ran the hardirq handler and scheduled the
  1567. * IRQ thread. The thread will write the IRQ mask when
  1568. * it finished, so there's nothing to do here. Writing
  1569. * the mask _here_ would incorrectly re-enable IRQs. */
  1570. }
  1571. }
  1572. }
  1573. static void b43_beacon_update_trigger_work(struct work_struct *work)
  1574. {
  1575. struct b43_wl *wl = container_of(work, struct b43_wl,
  1576. beacon_update_trigger);
  1577. struct b43_wldev *dev;
  1578. mutex_lock(&wl->mutex);
  1579. dev = wl->current_dev;
  1580. if (likely(dev && (b43_status(dev) >= B43_STAT_INITIALIZED))) {
  1581. if (b43_bus_host_is_sdio(dev->dev)) {
  1582. /* wl->mutex is enough. */
  1583. b43_do_beacon_update_trigger_work(dev);
  1584. mmiowb();
  1585. } else {
  1586. spin_lock_irq(&wl->hardirq_lock);
  1587. b43_do_beacon_update_trigger_work(dev);
  1588. mmiowb();
  1589. spin_unlock_irq(&wl->hardirq_lock);
  1590. }
  1591. }
  1592. mutex_unlock(&wl->mutex);
  1593. }
  1594. /* Asynchronously update the packet templates in template RAM. */
  1595. static void b43_update_templates(struct b43_wl *wl)
  1596. {
  1597. struct sk_buff *beacon, *old_beacon;
  1598. unsigned long flags;
  1599. /* This is the top half of the asynchronous beacon update.
  1600. * The bottom half is the beacon IRQ.
  1601. * Beacon update must be asynchronous to avoid sending an
  1602. * invalid beacon. This can happen for example, if the firmware
  1603. * transmits a beacon while we are updating it. */
  1604. /* We could modify the existing beacon and set the aid bit in
  1605. * the TIM field, but that would probably require resizing and
  1606. * moving of data within the beacon template.
  1607. * Simply request a new beacon and let mac80211 do the hard work. */
  1608. beacon = ieee80211_beacon_get(wl->hw, wl->vif);
  1609. if (unlikely(!beacon))
  1610. return;
  1611. spin_lock_irqsave(&wl->beacon_lock, flags);
  1612. old_beacon = wl->current_beacon;
  1613. wl->current_beacon = beacon;
  1614. wl->beacon0_uploaded = false;
  1615. wl->beacon1_uploaded = false;
  1616. spin_unlock_irqrestore(&wl->beacon_lock, flags);
  1617. ieee80211_queue_work(wl->hw, &wl->beacon_update_trigger);
  1618. if (old_beacon)
  1619. dev_kfree_skb_any(old_beacon);
  1620. }
  1621. static void b43_set_beacon_int(struct b43_wldev *dev, u16 beacon_int)
  1622. {
  1623. b43_time_lock(dev);
  1624. if (dev->dev->core_rev >= 3) {
  1625. b43_write32(dev, B43_MMIO_TSF_CFP_REP, (beacon_int << 16));
  1626. b43_write32(dev, B43_MMIO_TSF_CFP_START, (beacon_int << 10));
  1627. } else {
  1628. b43_write16(dev, 0x606, (beacon_int >> 6));
  1629. b43_write16(dev, 0x610, beacon_int);
  1630. }
  1631. b43_time_unlock(dev);
  1632. b43dbg(dev->wl, "Set beacon interval to %u\n", beacon_int);
  1633. }
  1634. static void b43_handle_firmware_panic(struct b43_wldev *dev)
  1635. {
  1636. u16 reason;
  1637. /* Read the register that contains the reason code for the panic. */
  1638. reason = b43_shm_read16(dev, B43_SHM_SCRATCH, B43_FWPANIC_REASON_REG);
  1639. b43err(dev->wl, "Whoopsy, firmware panic! Reason: %u\n", reason);
  1640. switch (reason) {
  1641. default:
  1642. b43dbg(dev->wl, "The panic reason is unknown.\n");
  1643. /* fallthrough */
  1644. case B43_FWPANIC_DIE:
  1645. /* Do not restart the controller or firmware.
  1646. * The device is nonfunctional from now on.
  1647. * Restarting would result in this panic to trigger again,
  1648. * so we avoid that recursion. */
  1649. break;
  1650. case B43_FWPANIC_RESTART:
  1651. b43_controller_restart(dev, "Microcode panic");
  1652. break;
  1653. }
  1654. }
  1655. static void handle_irq_ucode_debug(struct b43_wldev *dev)
  1656. {
  1657. unsigned int i, cnt;
  1658. u16 reason, marker_id, marker_line;
  1659. __le16 *buf;
  1660. /* The proprietary firmware doesn't have this IRQ. */
  1661. if (!dev->fw.opensource)
  1662. return;
  1663. /* Read the register that contains the reason code for this IRQ. */
  1664. reason = b43_shm_read16(dev, B43_SHM_SCRATCH, B43_DEBUGIRQ_REASON_REG);
  1665. switch (reason) {
  1666. case B43_DEBUGIRQ_PANIC:
  1667. b43_handle_firmware_panic(dev);
  1668. break;
  1669. case B43_DEBUGIRQ_DUMP_SHM:
  1670. if (!B43_DEBUG)
  1671. break; /* Only with driver debugging enabled. */
  1672. buf = kmalloc(4096, GFP_ATOMIC);
  1673. if (!buf) {
  1674. b43dbg(dev->wl, "SHM-dump: Failed to allocate memory\n");
  1675. goto out;
  1676. }
  1677. for (i = 0; i < 4096; i += 2) {
  1678. u16 tmp = b43_shm_read16(dev, B43_SHM_SHARED, i);
  1679. buf[i / 2] = cpu_to_le16(tmp);
  1680. }
  1681. b43info(dev->wl, "Shared memory dump:\n");
  1682. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET,
  1683. 16, 2, buf, 4096, 1);
  1684. kfree(buf);
  1685. break;
  1686. case B43_DEBUGIRQ_DUMP_REGS:
  1687. if (!B43_DEBUG)
  1688. break; /* Only with driver debugging enabled. */
  1689. b43info(dev->wl, "Microcode register dump:\n");
  1690. for (i = 0, cnt = 0; i < 64; i++) {
  1691. u16 tmp = b43_shm_read16(dev, B43_SHM_SCRATCH, i);
  1692. if (cnt == 0)
  1693. printk(KERN_INFO);
  1694. printk("r%02u: 0x%04X ", i, tmp);
  1695. cnt++;
  1696. if (cnt == 6) {
  1697. printk("\n");
  1698. cnt = 0;
  1699. }
  1700. }
  1701. printk("\n");
  1702. break;
  1703. case B43_DEBUGIRQ_MARKER:
  1704. if (!B43_DEBUG)
  1705. break; /* Only with driver debugging enabled. */
  1706. marker_id = b43_shm_read16(dev, B43_SHM_SCRATCH,
  1707. B43_MARKER_ID_REG);
  1708. marker_line = b43_shm_read16(dev, B43_SHM_SCRATCH,
  1709. B43_MARKER_LINE_REG);
  1710. b43info(dev->wl, "The firmware just executed the MARKER(%u) "
  1711. "at line number %u\n",
  1712. marker_id, marker_line);
  1713. break;
  1714. default:
  1715. b43dbg(dev->wl, "Debug-IRQ triggered for unknown reason: %u\n",
  1716. reason);
  1717. }
  1718. out:
  1719. /* Acknowledge the debug-IRQ, so the firmware can continue. */
  1720. b43_shm_write16(dev, B43_SHM_SCRATCH,
  1721. B43_DEBUGIRQ_REASON_REG, B43_DEBUGIRQ_ACK);
  1722. }
  1723. static void b43_do_interrupt_thread(struct b43_wldev *dev)
  1724. {
  1725. u32 reason;
  1726. u32 dma_reason[ARRAY_SIZE(dev->dma_reason)];
  1727. u32 merged_dma_reason = 0;
  1728. int i;
  1729. if (unlikely(b43_status(dev) != B43_STAT_STARTED))
  1730. return;
  1731. reason = dev->irq_reason;
  1732. for (i = 0; i < ARRAY_SIZE(dma_reason); i++) {
  1733. dma_reason[i] = dev->dma_reason[i];
  1734. merged_dma_reason |= dma_reason[i];
  1735. }
  1736. if (unlikely(reason & B43_IRQ_MAC_TXERR))
  1737. b43err(dev->wl, "MAC transmission error\n");
  1738. if (unlikely(reason & B43_IRQ_PHY_TXERR)) {
  1739. b43err(dev->wl, "PHY transmission error\n");
  1740. rmb();
  1741. if (unlikely(atomic_dec_and_test(&dev->phy.txerr_cnt))) {
  1742. atomic_set(&dev->phy.txerr_cnt,
  1743. B43_PHY_TX_BADNESS_LIMIT);
  1744. b43err(dev->wl, "Too many PHY TX errors, "
  1745. "restarting the controller\n");
  1746. b43_controller_restart(dev, "PHY TX errors");
  1747. }
  1748. }
  1749. if (unlikely(merged_dma_reason & (B43_DMAIRQ_FATALMASK))) {
  1750. b43err(dev->wl,
  1751. "Fatal DMA error: 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
  1752. dma_reason[0], dma_reason[1],
  1753. dma_reason[2], dma_reason[3],
  1754. dma_reason[4], dma_reason[5]);
  1755. b43err(dev->wl, "This device does not support DMA "
  1756. "on your system. It will now be switched to PIO.\n");
  1757. /* Fall back to PIO transfers if we get fatal DMA errors! */
  1758. dev->use_pio = true;
  1759. b43_controller_restart(dev, "DMA error");
  1760. return;
  1761. }
  1762. if (unlikely(reason & B43_IRQ_UCODE_DEBUG))
  1763. handle_irq_ucode_debug(dev);
  1764. if (reason & B43_IRQ_TBTT_INDI)
  1765. handle_irq_tbtt_indication(dev);
  1766. if (reason & B43_IRQ_ATIM_END)
  1767. handle_irq_atim_end(dev);
  1768. if (reason & B43_IRQ_BEACON)
  1769. handle_irq_beacon(dev);
  1770. if (reason & B43_IRQ_PMQ)
  1771. handle_irq_pmq(dev);
  1772. if (reason & B43_IRQ_TXFIFO_FLUSH_OK)
  1773. ;/* TODO */
  1774. if (reason & B43_IRQ_NOISESAMPLE_OK)
  1775. handle_irq_noise(dev);
  1776. /* Check the DMA reason registers for received data. */
  1777. if (dma_reason[0] & B43_DMAIRQ_RDESC_UFLOW) {
  1778. if (B43_DEBUG)
  1779. b43warn(dev->wl, "RX descriptor underrun\n");
  1780. b43_dma_handle_rx_overflow(dev->dma.rx_ring);
  1781. }
  1782. if (dma_reason[0] & B43_DMAIRQ_RX_DONE) {
  1783. if (b43_using_pio_transfers(dev))
  1784. b43_pio_rx(dev->pio.rx_queue);
  1785. else
  1786. b43_dma_rx(dev->dma.rx_ring);
  1787. }
  1788. B43_WARN_ON(dma_reason[1] & B43_DMAIRQ_RX_DONE);
  1789. B43_WARN_ON(dma_reason[2] & B43_DMAIRQ_RX_DONE);
  1790. B43_WARN_ON(dma_reason[3] & B43_DMAIRQ_RX_DONE);
  1791. B43_WARN_ON(dma_reason[4] & B43_DMAIRQ_RX_DONE);
  1792. B43_WARN_ON(dma_reason[5] & B43_DMAIRQ_RX_DONE);
  1793. if (reason & B43_IRQ_TX_OK)
  1794. handle_irq_transmit_status(dev);
  1795. /* Re-enable interrupts on the device by restoring the current interrupt mask. */
  1796. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
  1797. #if B43_DEBUG
  1798. if (b43_debug(dev, B43_DBG_VERBOSESTATS)) {
  1799. dev->irq_count++;
  1800. for (i = 0; i < ARRAY_SIZE(dev->irq_bit_count); i++) {
  1801. if (reason & (1 << i))
  1802. dev->irq_bit_count[i]++;
  1803. }
  1804. }
  1805. #endif
  1806. }
  1807. /* Interrupt thread handler. Handles device interrupts in thread context. */
  1808. static irqreturn_t b43_interrupt_thread_handler(int irq, void *dev_id)
  1809. {
  1810. struct b43_wldev *dev = dev_id;
  1811. mutex_lock(&dev->wl->mutex);
  1812. b43_do_interrupt_thread(dev);
  1813. mmiowb();
  1814. mutex_unlock(&dev->wl->mutex);
  1815. return IRQ_HANDLED;
  1816. }
  1817. static irqreturn_t b43_do_interrupt(struct b43_wldev *dev)
  1818. {
  1819. u32 reason;
  1820. /* This code runs under wl->hardirq_lock, but _only_ on non-SDIO busses.
  1821. * On SDIO, this runs under wl->mutex. */
  1822. reason = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  1823. if (reason == 0xffffffff) /* shared IRQ */
  1824. return IRQ_NONE;
  1825. reason &= dev->irq_mask;
  1826. if (!reason)
  1827. return IRQ_NONE;
  1828. dev->dma_reason[0] = b43_read32(dev, B43_MMIO_DMA0_REASON)
  1829. & 0x0001FC00;
  1830. dev->dma_reason[1] = b43_read32(dev, B43_MMIO_DMA1_REASON)
  1831. & 0x0000DC00;
  1832. dev->dma_reason[2] = b43_read32(dev, B43_MMIO_DMA2_REASON)
  1833. & 0x0000DC00;
  1834. dev->dma_reason[3] = b43_read32(dev, B43_MMIO_DMA3_REASON)
  1835. & 0x0001DC00;
  1836. dev->dma_reason[4] = b43_read32(dev, B43_MMIO_DMA4_REASON)
  1837. & 0x0000DC00;
  1838. /* Unused ring
  1839. dev->dma_reason[5] = b43_read32(dev, B43_MMIO_DMA5_REASON)
  1840. & 0x0000DC00;
  1841. */
  1842. /* ACK the interrupt. */
  1843. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, reason);
  1844. b43_write32(dev, B43_MMIO_DMA0_REASON, dev->dma_reason[0]);
  1845. b43_write32(dev, B43_MMIO_DMA1_REASON, dev->dma_reason[1]);
  1846. b43_write32(dev, B43_MMIO_DMA2_REASON, dev->dma_reason[2]);
  1847. b43_write32(dev, B43_MMIO_DMA3_REASON, dev->dma_reason[3]);
  1848. b43_write32(dev, B43_MMIO_DMA4_REASON, dev->dma_reason[4]);
  1849. /* Unused ring
  1850. b43_write32(dev, B43_MMIO_DMA5_REASON, dev->dma_reason[5]);
  1851. */
  1852. /* Disable IRQs on the device. The IRQ thread handler will re-enable them. */
  1853. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, 0);
  1854. /* Save the reason bitmasks for the IRQ thread handler. */
  1855. dev->irq_reason = reason;
  1856. return IRQ_WAKE_THREAD;
  1857. }
  1858. /* Interrupt handler top-half. This runs with interrupts disabled. */
  1859. static irqreturn_t b43_interrupt_handler(int irq, void *dev_id)
  1860. {
  1861. struct b43_wldev *dev = dev_id;
  1862. irqreturn_t ret;
  1863. if (unlikely(b43_status(dev) < B43_STAT_STARTED))
  1864. return IRQ_NONE;
  1865. spin_lock(&dev->wl->hardirq_lock);
  1866. ret = b43_do_interrupt(dev);
  1867. mmiowb();
  1868. spin_unlock(&dev->wl->hardirq_lock);
  1869. return ret;
  1870. }
  1871. /* SDIO interrupt handler. This runs in process context. */
  1872. static void b43_sdio_interrupt_handler(struct b43_wldev *dev)
  1873. {
  1874. struct b43_wl *wl = dev->wl;
  1875. irqreturn_t ret;
  1876. mutex_lock(&wl->mutex);
  1877. ret = b43_do_interrupt(dev);
  1878. if (ret == IRQ_WAKE_THREAD)
  1879. b43_do_interrupt_thread(dev);
  1880. mutex_unlock(&wl->mutex);
  1881. }
  1882. void b43_do_release_fw(struct b43_firmware_file *fw)
  1883. {
  1884. release_firmware(fw->data);
  1885. fw->data = NULL;
  1886. fw->filename = NULL;
  1887. }
  1888. static void b43_release_firmware(struct b43_wldev *dev)
  1889. {
  1890. complete(&dev->fw_load_complete);
  1891. b43_do_release_fw(&dev->fw.ucode);
  1892. b43_do_release_fw(&dev->fw.pcm);
  1893. b43_do_release_fw(&dev->fw.initvals);
  1894. b43_do_release_fw(&dev->fw.initvals_band);
  1895. }
  1896. static void b43_print_fw_helptext(struct b43_wl *wl, bool error)
  1897. {
  1898. const char text[] =
  1899. "You must go to " \
  1900. "http://wireless.kernel.org/en/users/Drivers/b43#devicefirmware " \
  1901. "and download the correct firmware for this driver version. " \
  1902. "Please carefully read all instructions on this website.\n";
  1903. if (error)
  1904. b43err(wl, text);
  1905. else
  1906. b43warn(wl, text);
  1907. }
  1908. static void b43_fw_cb(const struct firmware *firmware, void *context)
  1909. {
  1910. struct b43_request_fw_context *ctx = context;
  1911. ctx->blob = firmware;
  1912. complete(&ctx->dev->fw_load_complete);
  1913. }
  1914. int b43_do_request_fw(struct b43_request_fw_context *ctx,
  1915. const char *name,
  1916. struct b43_firmware_file *fw, bool async)
  1917. {
  1918. struct b43_fw_header *hdr;
  1919. u32 size;
  1920. int err;
  1921. if (!name) {
  1922. /* Don't fetch anything. Free possibly cached firmware. */
  1923. /* FIXME: We should probably keep it anyway, to save some headache
  1924. * on suspend/resume with multiband devices. */
  1925. b43_do_release_fw(fw);
  1926. return 0;
  1927. }
  1928. if (fw->filename) {
  1929. if ((fw->type == ctx->req_type) &&
  1930. (strcmp(fw->filename, name) == 0))
  1931. return 0; /* Already have this fw. */
  1932. /* Free the cached firmware first. */
  1933. /* FIXME: We should probably do this later after we successfully
  1934. * got the new fw. This could reduce headache with multiband devices.
  1935. * We could also redesign this to cache the firmware for all possible
  1936. * bands all the time. */
  1937. b43_do_release_fw(fw);
  1938. }
  1939. switch (ctx->req_type) {
  1940. case B43_FWTYPE_PROPRIETARY:
  1941. snprintf(ctx->fwname, sizeof(ctx->fwname),
  1942. "b43%s/%s.fw",
  1943. modparam_fwpostfix, name);
  1944. break;
  1945. case B43_FWTYPE_OPENSOURCE:
  1946. snprintf(ctx->fwname, sizeof(ctx->fwname),
  1947. "b43-open%s/%s.fw",
  1948. modparam_fwpostfix, name);
  1949. break;
  1950. default:
  1951. B43_WARN_ON(1);
  1952. return -ENOSYS;
  1953. }
  1954. if (async) {
  1955. /* do this part asynchronously */
  1956. init_completion(&ctx->dev->fw_load_complete);
  1957. err = request_firmware_nowait(THIS_MODULE, 1, ctx->fwname,
  1958. ctx->dev->dev->dev, GFP_KERNEL,
  1959. ctx, b43_fw_cb);
  1960. if (err < 0) {
  1961. pr_err("Unable to load firmware\n");
  1962. return err;
  1963. }
  1964. wait_for_completion(&ctx->dev->fw_load_complete);
  1965. if (ctx->blob)
  1966. goto fw_ready;
  1967. /* On some ARM systems, the async request will fail, but the next sync
  1968. * request works. For this reason, we fall through here
  1969. */
  1970. }
  1971. err = request_firmware(&ctx->blob, ctx->fwname,
  1972. ctx->dev->dev->dev);
  1973. if (err)
  1974. return err;
  1975. fw_ready:
  1976. if (ctx->blob->size < sizeof(struct b43_fw_header))
  1977. goto err_format;
  1978. hdr = (struct b43_fw_header *)(ctx->blob->data);
  1979. switch (hdr->type) {
  1980. case B43_FW_TYPE_UCODE:
  1981. case B43_FW_TYPE_PCM:
  1982. size = be32_to_cpu(hdr->size);
  1983. if (size != ctx->blob->size - sizeof(struct b43_fw_header))
  1984. goto err_format;
  1985. /* fallthrough */
  1986. case B43_FW_TYPE_IV:
  1987. if (hdr->ver != 1)
  1988. goto err_format;
  1989. break;
  1990. default:
  1991. goto err_format;
  1992. }
  1993. fw->data = ctx->blob;
  1994. fw->filename = name;
  1995. fw->type = ctx->req_type;
  1996. return 0;
  1997. err_format:
  1998. snprintf(ctx->errors[ctx->req_type],
  1999. sizeof(ctx->errors[ctx->req_type]),
  2000. "Firmware file \"%s\" format error.\n", ctx->fwname);
  2001. release_firmware(ctx->blob);
  2002. return -EPROTO;
  2003. }
  2004. /* http://bcm-v4.sipsolutions.net/802.11/Init/Firmware */
  2005. static int b43_try_request_fw(struct b43_request_fw_context *ctx)
  2006. {
  2007. struct b43_wldev *dev = ctx->dev;
  2008. struct b43_firmware *fw = &ctx->dev->fw;
  2009. struct b43_phy *phy = &dev->phy;
  2010. const u8 rev = ctx->dev->dev->core_rev;
  2011. const char *filename;
  2012. int err;
  2013. /* Get microcode */
  2014. filename = NULL;
  2015. switch (rev) {
  2016. case 42:
  2017. if (phy->type == B43_PHYTYPE_AC)
  2018. filename = "ucode42";
  2019. break;
  2020. case 40:
  2021. if (phy->type == B43_PHYTYPE_AC)
  2022. filename = "ucode40";
  2023. break;
  2024. case 33:
  2025. if (phy->type == B43_PHYTYPE_LCN40)
  2026. filename = "ucode33_lcn40";
  2027. break;
  2028. case 30:
  2029. if (phy->type == B43_PHYTYPE_N)
  2030. filename = "ucode30_mimo";
  2031. break;
  2032. case 29:
  2033. if (phy->type == B43_PHYTYPE_HT)
  2034. filename = "ucode29_mimo";
  2035. break;
  2036. case 26:
  2037. if (phy->type == B43_PHYTYPE_HT)
  2038. filename = "ucode26_mimo";
  2039. break;
  2040. case 28:
  2041. case 25:
  2042. if (phy->type == B43_PHYTYPE_N)
  2043. filename = "ucode25_mimo";
  2044. else if (phy->type == B43_PHYTYPE_LCN)
  2045. filename = "ucode25_lcn";
  2046. break;
  2047. case 24:
  2048. if (phy->type == B43_PHYTYPE_LCN)
  2049. filename = "ucode24_lcn";
  2050. break;
  2051. case 23:
  2052. if (phy->type == B43_PHYTYPE_N)
  2053. filename = "ucode16_mimo";
  2054. break;
  2055. case 16 ... 19:
  2056. if (phy->type == B43_PHYTYPE_N)
  2057. filename = "ucode16_mimo";
  2058. else if (phy->type == B43_PHYTYPE_LP)
  2059. filename = "ucode16_lp";
  2060. break;
  2061. case 15:
  2062. filename = "ucode15";
  2063. break;
  2064. case 14:
  2065. filename = "ucode14";
  2066. break;
  2067. case 13:
  2068. filename = "ucode13";
  2069. break;
  2070. case 11 ... 12:
  2071. filename = "ucode11";
  2072. break;
  2073. case 5 ... 10:
  2074. filename = "ucode5";
  2075. break;
  2076. }
  2077. if (!filename)
  2078. goto err_no_ucode;
  2079. err = b43_do_request_fw(ctx, filename, &fw->ucode, true);
  2080. if (err)
  2081. goto err_load;
  2082. /* Get PCM code */
  2083. if ((rev >= 5) && (rev <= 10))
  2084. filename = "pcm5";
  2085. else if (rev >= 11)
  2086. filename = NULL;
  2087. else
  2088. goto err_no_pcm;
  2089. fw->pcm_request_failed = false;
  2090. err = b43_do_request_fw(ctx, filename, &fw->pcm, false);
  2091. if (err == -ENOENT) {
  2092. /* We did not find a PCM file? Not fatal, but
  2093. * core rev <= 10 must do without hwcrypto then. */
  2094. fw->pcm_request_failed = true;
  2095. } else if (err)
  2096. goto err_load;
  2097. /* Get initvals */
  2098. filename = NULL;
  2099. switch (dev->phy.type) {
  2100. case B43_PHYTYPE_G:
  2101. if (rev == 13)
  2102. filename = "b0g0initvals13";
  2103. else if (rev >= 5 && rev <= 10)
  2104. filename = "b0g0initvals5";
  2105. break;
  2106. case B43_PHYTYPE_N:
  2107. if (rev == 30)
  2108. filename = "n16initvals30";
  2109. else if (rev == 28 || rev == 25)
  2110. filename = "n0initvals25";
  2111. else if (rev == 24)
  2112. filename = "n0initvals24";
  2113. else if (rev == 23)
  2114. filename = "n0initvals16"; /* What about n0initvals22? */
  2115. else if (rev >= 16 && rev <= 18)
  2116. filename = "n0initvals16";
  2117. else if (rev >= 11 && rev <= 12)
  2118. filename = "n0initvals11";
  2119. break;
  2120. case B43_PHYTYPE_LP:
  2121. if (rev >= 16 && rev <= 18)
  2122. filename = "lp0initvals16";
  2123. else if (rev == 15)
  2124. filename = "lp0initvals15";
  2125. else if (rev == 14)
  2126. filename = "lp0initvals14";
  2127. else if (rev == 13)
  2128. filename = "lp0initvals13";
  2129. break;
  2130. case B43_PHYTYPE_HT:
  2131. if (rev == 29)
  2132. filename = "ht0initvals29";
  2133. else if (rev == 26)
  2134. filename = "ht0initvals26";
  2135. break;
  2136. case B43_PHYTYPE_LCN:
  2137. if (rev == 24)
  2138. filename = "lcn0initvals24";
  2139. break;
  2140. case B43_PHYTYPE_LCN40:
  2141. if (rev == 33)
  2142. filename = "lcn400initvals33";
  2143. break;
  2144. case B43_PHYTYPE_AC:
  2145. if (rev == 42)
  2146. filename = "ac1initvals42";
  2147. else if (rev == 40)
  2148. filename = "ac0initvals40";
  2149. break;
  2150. }
  2151. if (!filename)
  2152. goto err_no_initvals;
  2153. err = b43_do_request_fw(ctx, filename, &fw->initvals, false);
  2154. if (err)
  2155. goto err_load;
  2156. /* Get bandswitch initvals */
  2157. filename = NULL;
  2158. switch (dev->phy.type) {
  2159. case B43_PHYTYPE_G:
  2160. if (rev == 13)
  2161. filename = "b0g0bsinitvals13";
  2162. else if (rev >= 5 && rev <= 10)
  2163. filename = "b0g0bsinitvals5";
  2164. break;
  2165. case B43_PHYTYPE_N:
  2166. if (rev == 30)
  2167. filename = "n16bsinitvals30";
  2168. else if (rev == 28 || rev == 25)
  2169. filename = "n0bsinitvals25";
  2170. else if (rev == 24)
  2171. filename = "n0bsinitvals24";
  2172. else if (rev == 23)
  2173. filename = "n0bsinitvals16"; /* What about n0bsinitvals22? */
  2174. else if (rev >= 16 && rev <= 18)
  2175. filename = "n0bsinitvals16";
  2176. else if (rev >= 11 && rev <= 12)
  2177. filename = "n0bsinitvals11";
  2178. break;
  2179. case B43_PHYTYPE_LP:
  2180. if (rev >= 16 && rev <= 18)
  2181. filename = "lp0bsinitvals16";
  2182. else if (rev == 15)
  2183. filename = "lp0bsinitvals15";
  2184. else if (rev == 14)
  2185. filename = "lp0bsinitvals14";
  2186. else if (rev == 13)
  2187. filename = "lp0bsinitvals13";
  2188. break;
  2189. case B43_PHYTYPE_HT:
  2190. if (rev == 29)
  2191. filename = "ht0bsinitvals29";
  2192. else if (rev == 26)
  2193. filename = "ht0bsinitvals26";
  2194. break;
  2195. case B43_PHYTYPE_LCN:
  2196. if (rev == 24)
  2197. filename = "lcn0bsinitvals24";
  2198. break;
  2199. case B43_PHYTYPE_LCN40:
  2200. if (rev == 33)
  2201. filename = "lcn400bsinitvals33";
  2202. break;
  2203. case B43_PHYTYPE_AC:
  2204. if (rev == 42)
  2205. filename = "ac1bsinitvals42";
  2206. else if (rev == 40)
  2207. filename = "ac0bsinitvals40";
  2208. break;
  2209. }
  2210. if (!filename)
  2211. goto err_no_initvals;
  2212. err = b43_do_request_fw(ctx, filename, &fw->initvals_band, false);
  2213. if (err)
  2214. goto err_load;
  2215. fw->opensource = (ctx->req_type == B43_FWTYPE_OPENSOURCE);
  2216. return 0;
  2217. err_no_ucode:
  2218. err = ctx->fatal_failure = -EOPNOTSUPP;
  2219. b43err(dev->wl, "The driver does not know which firmware (ucode) "
  2220. "is required for your device (wl-core rev %u)\n", rev);
  2221. goto error;
  2222. err_no_pcm:
  2223. err = ctx->fatal_failure = -EOPNOTSUPP;
  2224. b43err(dev->wl, "The driver does not know which firmware (PCM) "
  2225. "is required for your device (wl-core rev %u)\n", rev);
  2226. goto error;
  2227. err_no_initvals:
  2228. err = ctx->fatal_failure = -EOPNOTSUPP;
  2229. b43err(dev->wl, "The driver does not know which firmware (initvals) "
  2230. "is required for your device (wl-core rev %u)\n", rev);
  2231. goto error;
  2232. err_load:
  2233. /* We failed to load this firmware image. The error message
  2234. * already is in ctx->errors. Return and let our caller decide
  2235. * what to do. */
  2236. goto error;
  2237. error:
  2238. b43_release_firmware(dev);
  2239. return err;
  2240. }
  2241. static int b43_one_core_attach(struct b43_bus_dev *dev, struct b43_wl *wl);
  2242. static void b43_one_core_detach(struct b43_bus_dev *dev);
  2243. static int b43_rng_init(struct b43_wl *wl);
  2244. static void b43_request_firmware(struct work_struct *work)
  2245. {
  2246. struct b43_wl *wl = container_of(work,
  2247. struct b43_wl, firmware_load);
  2248. struct b43_wldev *dev = wl->current_dev;
  2249. struct b43_request_fw_context *ctx;
  2250. unsigned int i;
  2251. int err;
  2252. const char *errmsg;
  2253. ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
  2254. if (!ctx)
  2255. return;
  2256. ctx->dev = dev;
  2257. ctx->req_type = B43_FWTYPE_PROPRIETARY;
  2258. err = b43_try_request_fw(ctx);
  2259. if (!err)
  2260. goto start_ieee80211; /* Successfully loaded it. */
  2261. /* Was fw version known? */
  2262. if (ctx->fatal_failure)
  2263. goto out;
  2264. /* proprietary fw not found, try open source */
  2265. ctx->req_type = B43_FWTYPE_OPENSOURCE;
  2266. err = b43_try_request_fw(ctx);
  2267. if (!err)
  2268. goto start_ieee80211; /* Successfully loaded it. */
  2269. if(ctx->fatal_failure)
  2270. goto out;
  2271. /* Could not find a usable firmware. Print the errors. */
  2272. for (i = 0; i < B43_NR_FWTYPES; i++) {
  2273. errmsg = ctx->errors[i];
  2274. if (strlen(errmsg))
  2275. b43err(dev->wl, "%s", errmsg);
  2276. }
  2277. b43_print_fw_helptext(dev->wl, 1);
  2278. goto out;
  2279. start_ieee80211:
  2280. wl->hw->queues = B43_QOS_QUEUE_NUM;
  2281. if (!modparam_qos || dev->fw.opensource)
  2282. wl->hw->queues = 1;
  2283. err = ieee80211_register_hw(wl->hw);
  2284. if (err)
  2285. goto err_one_core_detach;
  2286. wl->hw_registred = true;
  2287. b43_leds_register(wl->current_dev);
  2288. /* Register HW RNG driver */
  2289. b43_rng_init(wl);
  2290. goto out;
  2291. err_one_core_detach:
  2292. b43_one_core_detach(dev->dev);
  2293. out:
  2294. kfree(ctx);
  2295. }
  2296. static int b43_upload_microcode(struct b43_wldev *dev)
  2297. {
  2298. struct wiphy *wiphy = dev->wl->hw->wiphy;
  2299. const size_t hdr_len = sizeof(struct b43_fw_header);
  2300. const __be32 *data;
  2301. unsigned int i, len;
  2302. u16 fwrev, fwpatch, fwdate, fwtime;
  2303. u32 tmp, macctl;
  2304. int err = 0;
  2305. /* Jump the microcode PSM to offset 0 */
  2306. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  2307. B43_WARN_ON(macctl & B43_MACCTL_PSM_RUN);
  2308. macctl |= B43_MACCTL_PSM_JMP0;
  2309. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  2310. /* Zero out all microcode PSM registers and shared memory. */
  2311. for (i = 0; i < 64; i++)
  2312. b43_shm_write16(dev, B43_SHM_SCRATCH, i, 0);
  2313. for (i = 0; i < 4096; i += 2)
  2314. b43_shm_write16(dev, B43_SHM_SHARED, i, 0);
  2315. /* Upload Microcode. */
  2316. data = (__be32 *) (dev->fw.ucode.data->data + hdr_len);
  2317. len = (dev->fw.ucode.data->size - hdr_len) / sizeof(__be32);
  2318. b43_shm_control_word(dev, B43_SHM_UCODE | B43_SHM_AUTOINC_W, 0x0000);
  2319. for (i = 0; i < len; i++) {
  2320. b43_write32(dev, B43_MMIO_SHM_DATA, be32_to_cpu(data[i]));
  2321. udelay(10);
  2322. }
  2323. if (dev->fw.pcm.data) {
  2324. /* Upload PCM data. */
  2325. data = (__be32 *) (dev->fw.pcm.data->data + hdr_len);
  2326. len = (dev->fw.pcm.data->size - hdr_len) / sizeof(__be32);
  2327. b43_shm_control_word(dev, B43_SHM_HW, 0x01EA);
  2328. b43_write32(dev, B43_MMIO_SHM_DATA, 0x00004000);
  2329. /* No need for autoinc bit in SHM_HW */
  2330. b43_shm_control_word(dev, B43_SHM_HW, 0x01EB);
  2331. for (i = 0; i < len; i++) {
  2332. b43_write32(dev, B43_MMIO_SHM_DATA, be32_to_cpu(data[i]));
  2333. udelay(10);
  2334. }
  2335. }
  2336. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, B43_IRQ_ALL);
  2337. /* Start the microcode PSM */
  2338. b43_maskset32(dev, B43_MMIO_MACCTL, ~B43_MACCTL_PSM_JMP0,
  2339. B43_MACCTL_PSM_RUN);
  2340. /* Wait for the microcode to load and respond */
  2341. i = 0;
  2342. while (1) {
  2343. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2344. if (tmp == B43_IRQ_MAC_SUSPENDED)
  2345. break;
  2346. i++;
  2347. if (i >= 20) {
  2348. b43err(dev->wl, "Microcode not responding\n");
  2349. b43_print_fw_helptext(dev->wl, 1);
  2350. err = -ENODEV;
  2351. goto error;
  2352. }
  2353. msleep(50);
  2354. }
  2355. b43_read32(dev, B43_MMIO_GEN_IRQ_REASON); /* dummy read */
  2356. /* Get and check the revisions. */
  2357. fwrev = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEREV);
  2358. fwpatch = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEPATCH);
  2359. fwdate = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEDATE);
  2360. fwtime = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODETIME);
  2361. if (fwrev <= 0x128) {
  2362. b43err(dev->wl, "YOUR FIRMWARE IS TOO OLD. Firmware from "
  2363. "binary drivers older than version 4.x is unsupported. "
  2364. "You must upgrade your firmware files.\n");
  2365. b43_print_fw_helptext(dev->wl, 1);
  2366. err = -EOPNOTSUPP;
  2367. goto error;
  2368. }
  2369. dev->fw.rev = fwrev;
  2370. dev->fw.patch = fwpatch;
  2371. if (dev->fw.rev >= 598)
  2372. dev->fw.hdr_format = B43_FW_HDR_598;
  2373. else if (dev->fw.rev >= 410)
  2374. dev->fw.hdr_format = B43_FW_HDR_410;
  2375. else
  2376. dev->fw.hdr_format = B43_FW_HDR_351;
  2377. WARN_ON(dev->fw.opensource != (fwdate == 0xFFFF));
  2378. dev->qos_enabled = dev->wl->hw->queues > 1;
  2379. /* Default to firmware/hardware crypto acceleration. */
  2380. dev->hwcrypto_enabled = true;
  2381. if (dev->fw.opensource) {
  2382. u16 fwcapa;
  2383. /* Patchlevel info is encoded in the "time" field. */
  2384. dev->fw.patch = fwtime;
  2385. b43info(dev->wl, "Loading OpenSource firmware version %u.%u\n",
  2386. dev->fw.rev, dev->fw.patch);
  2387. fwcapa = b43_fwcapa_read(dev);
  2388. if (!(fwcapa & B43_FWCAPA_HWCRYPTO) || dev->fw.pcm_request_failed) {
  2389. b43info(dev->wl, "Hardware crypto acceleration not supported by firmware\n");
  2390. /* Disable hardware crypto and fall back to software crypto. */
  2391. dev->hwcrypto_enabled = false;
  2392. }
  2393. /* adding QoS support should use an offline discovery mechanism */
  2394. WARN(fwcapa & B43_FWCAPA_QOS, "QoS in OpenFW not supported\n");
  2395. } else {
  2396. b43info(dev->wl, "Loading firmware version %u.%u "
  2397. "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n",
  2398. fwrev, fwpatch,
  2399. (fwdate >> 12) & 0xF, (fwdate >> 8) & 0xF, fwdate & 0xFF,
  2400. (fwtime >> 11) & 0x1F, (fwtime >> 5) & 0x3F, fwtime & 0x1F);
  2401. if (dev->fw.pcm_request_failed) {
  2402. b43warn(dev->wl, "No \"pcm5.fw\" firmware file found. "
  2403. "Hardware accelerated cryptography is disabled.\n");
  2404. b43_print_fw_helptext(dev->wl, 0);
  2405. }
  2406. }
  2407. snprintf(wiphy->fw_version, sizeof(wiphy->fw_version), "%u.%u",
  2408. dev->fw.rev, dev->fw.patch);
  2409. wiphy->hw_version = dev->dev->core_id;
  2410. if (dev->fw.hdr_format == B43_FW_HDR_351) {
  2411. /* We're over the deadline, but we keep support for old fw
  2412. * until it turns out to be in major conflict with something new. */
  2413. b43warn(dev->wl, "You are using an old firmware image. "
  2414. "Support for old firmware will be removed soon "
  2415. "(official deadline was July 2008).\n");
  2416. b43_print_fw_helptext(dev->wl, 0);
  2417. }
  2418. return 0;
  2419. error:
  2420. /* Stop the microcode PSM. */
  2421. b43_maskset32(dev, B43_MMIO_MACCTL, ~B43_MACCTL_PSM_RUN,
  2422. B43_MACCTL_PSM_JMP0);
  2423. return err;
  2424. }
  2425. static int b43_write_initvals(struct b43_wldev *dev,
  2426. const struct b43_iv *ivals,
  2427. size_t count,
  2428. size_t array_size)
  2429. {
  2430. const struct b43_iv *iv;
  2431. u16 offset;
  2432. size_t i;
  2433. bool bit32;
  2434. BUILD_BUG_ON(sizeof(struct b43_iv) != 6);
  2435. iv = ivals;
  2436. for (i = 0; i < count; i++) {
  2437. if (array_size < sizeof(iv->offset_size))
  2438. goto err_format;
  2439. array_size -= sizeof(iv->offset_size);
  2440. offset = be16_to_cpu(iv->offset_size);
  2441. bit32 = !!(offset & B43_IV_32BIT);
  2442. offset &= B43_IV_OFFSET_MASK;
  2443. if (offset >= 0x1000)
  2444. goto err_format;
  2445. if (bit32) {
  2446. u32 value;
  2447. if (array_size < sizeof(iv->data.d32))
  2448. goto err_format;
  2449. array_size -= sizeof(iv->data.d32);
  2450. value = get_unaligned_be32(&iv->data.d32);
  2451. b43_write32(dev, offset, value);
  2452. iv = (const struct b43_iv *)((const uint8_t *)iv +
  2453. sizeof(__be16) +
  2454. sizeof(__be32));
  2455. } else {
  2456. u16 value;
  2457. if (array_size < sizeof(iv->data.d16))
  2458. goto err_format;
  2459. array_size -= sizeof(iv->data.d16);
  2460. value = be16_to_cpu(iv->data.d16);
  2461. b43_write16(dev, offset, value);
  2462. iv = (const struct b43_iv *)((const uint8_t *)iv +
  2463. sizeof(__be16) +
  2464. sizeof(__be16));
  2465. }
  2466. }
  2467. if (array_size)
  2468. goto err_format;
  2469. return 0;
  2470. err_format:
  2471. b43err(dev->wl, "Initial Values Firmware file-format error.\n");
  2472. b43_print_fw_helptext(dev->wl, 1);
  2473. return -EPROTO;
  2474. }
  2475. static int b43_upload_initvals(struct b43_wldev *dev)
  2476. {
  2477. const size_t hdr_len = sizeof(struct b43_fw_header);
  2478. const struct b43_fw_header *hdr;
  2479. struct b43_firmware *fw = &dev->fw;
  2480. const struct b43_iv *ivals;
  2481. size_t count;
  2482. hdr = (const struct b43_fw_header *)(fw->initvals.data->data);
  2483. ivals = (const struct b43_iv *)(fw->initvals.data->data + hdr_len);
  2484. count = be32_to_cpu(hdr->size);
  2485. return b43_write_initvals(dev, ivals, count,
  2486. fw->initvals.data->size - hdr_len);
  2487. }
  2488. static int b43_upload_initvals_band(struct b43_wldev *dev)
  2489. {
  2490. const size_t hdr_len = sizeof(struct b43_fw_header);
  2491. const struct b43_fw_header *hdr;
  2492. struct b43_firmware *fw = &dev->fw;
  2493. const struct b43_iv *ivals;
  2494. size_t count;
  2495. if (!fw->initvals_band.data)
  2496. return 0;
  2497. hdr = (const struct b43_fw_header *)(fw->initvals_band.data->data);
  2498. ivals = (const struct b43_iv *)(fw->initvals_band.data->data + hdr_len);
  2499. count = be32_to_cpu(hdr->size);
  2500. return b43_write_initvals(dev, ivals, count,
  2501. fw->initvals_band.data->size - hdr_len);
  2502. }
  2503. /* Initialize the GPIOs
  2504. * http://bcm-specs.sipsolutions.net/GPIO
  2505. */
  2506. #ifdef CONFIG_B43_SSB
  2507. static struct ssb_device *b43_ssb_gpio_dev(struct b43_wldev *dev)
  2508. {
  2509. struct ssb_bus *bus = dev->dev->sdev->bus;
  2510. #ifdef CONFIG_SSB_DRIVER_PCICORE
  2511. return (bus->chipco.dev ? bus->chipco.dev : bus->pcicore.dev);
  2512. #else
  2513. return bus->chipco.dev;
  2514. #endif
  2515. }
  2516. #endif
  2517. static int b43_gpio_init(struct b43_wldev *dev)
  2518. {
  2519. #ifdef CONFIG_B43_SSB
  2520. struct ssb_device *gpiodev;
  2521. #endif
  2522. u32 mask, set;
  2523. b43_maskset32(dev, B43_MMIO_MACCTL, ~B43_MACCTL_GPOUTSMSK, 0);
  2524. b43_maskset16(dev, B43_MMIO_GPIO_MASK, ~0, 0xF);
  2525. mask = 0x0000001F;
  2526. set = 0x0000000F;
  2527. if (dev->dev->chip_id == 0x4301) {
  2528. mask |= 0x0060;
  2529. set |= 0x0060;
  2530. } else if (dev->dev->chip_id == 0x5354) {
  2531. /* Don't allow overtaking buttons GPIOs */
  2532. set &= 0x2; /* 0x2 is LED GPIO on BCM5354 */
  2533. }
  2534. if (0 /* FIXME: conditional unknown */ ) {
  2535. b43_write16(dev, B43_MMIO_GPIO_MASK,
  2536. b43_read16(dev, B43_MMIO_GPIO_MASK)
  2537. | 0x0100);
  2538. /* BT Coexistance Input */
  2539. mask |= 0x0080;
  2540. set |= 0x0080;
  2541. /* BT Coexistance Out */
  2542. mask |= 0x0100;
  2543. set |= 0x0100;
  2544. }
  2545. if (dev->dev->bus_sprom->boardflags_lo & B43_BFL_PACTRL) {
  2546. /* PA is controlled by gpio 9, let ucode handle it */
  2547. b43_write16(dev, B43_MMIO_GPIO_MASK,
  2548. b43_read16(dev, B43_MMIO_GPIO_MASK)
  2549. | 0x0200);
  2550. mask |= 0x0200;
  2551. set |= 0x0200;
  2552. }
  2553. switch (dev->dev->bus_type) {
  2554. #ifdef CONFIG_B43_BCMA
  2555. case B43_BUS_BCMA:
  2556. bcma_chipco_gpio_control(&dev->dev->bdev->bus->drv_cc, mask, set);
  2557. break;
  2558. #endif
  2559. #ifdef CONFIG_B43_SSB
  2560. case B43_BUS_SSB:
  2561. gpiodev = b43_ssb_gpio_dev(dev);
  2562. if (gpiodev)
  2563. ssb_write32(gpiodev, B43_GPIO_CONTROL,
  2564. (ssb_read32(gpiodev, B43_GPIO_CONTROL)
  2565. & ~mask) | set);
  2566. break;
  2567. #endif
  2568. }
  2569. return 0;
  2570. }
  2571. /* Turn off all GPIO stuff. Call this on module unload, for example. */
  2572. static void b43_gpio_cleanup(struct b43_wldev *dev)
  2573. {
  2574. #ifdef CONFIG_B43_SSB
  2575. struct ssb_device *gpiodev;
  2576. #endif
  2577. switch (dev->dev->bus_type) {
  2578. #ifdef CONFIG_B43_BCMA
  2579. case B43_BUS_BCMA:
  2580. bcma_chipco_gpio_control(&dev->dev->bdev->bus->drv_cc, ~0, 0);
  2581. break;
  2582. #endif
  2583. #ifdef CONFIG_B43_SSB
  2584. case B43_BUS_SSB:
  2585. gpiodev = b43_ssb_gpio_dev(dev);
  2586. if (gpiodev)
  2587. ssb_write32(gpiodev, B43_GPIO_CONTROL, 0);
  2588. break;
  2589. #endif
  2590. }
  2591. }
  2592. /* http://bcm-specs.sipsolutions.net/EnableMac */
  2593. void b43_mac_enable(struct b43_wldev *dev)
  2594. {
  2595. if (b43_debug(dev, B43_DBG_FIRMWARE)) {
  2596. u16 fwstate;
  2597. fwstate = b43_shm_read16(dev, B43_SHM_SHARED,
  2598. B43_SHM_SH_UCODESTAT);
  2599. if ((fwstate != B43_SHM_SH_UCODESTAT_SUSP) &&
  2600. (fwstate != B43_SHM_SH_UCODESTAT_SLEEP)) {
  2601. b43err(dev->wl, "b43_mac_enable(): The firmware "
  2602. "should be suspended, but current state is %u\n",
  2603. fwstate);
  2604. }
  2605. }
  2606. dev->mac_suspended--;
  2607. B43_WARN_ON(dev->mac_suspended < 0);
  2608. if (dev->mac_suspended == 0) {
  2609. b43_maskset32(dev, B43_MMIO_MACCTL, ~0, B43_MACCTL_ENABLED);
  2610. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON,
  2611. B43_IRQ_MAC_SUSPENDED);
  2612. /* Commit writes */
  2613. b43_read32(dev, B43_MMIO_MACCTL);
  2614. b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2615. b43_power_saving_ctl_bits(dev, 0);
  2616. }
  2617. }
  2618. /* http://bcm-specs.sipsolutions.net/SuspendMAC */
  2619. void b43_mac_suspend(struct b43_wldev *dev)
  2620. {
  2621. int i;
  2622. u32 tmp;
  2623. might_sleep();
  2624. B43_WARN_ON(dev->mac_suspended < 0);
  2625. if (dev->mac_suspended == 0) {
  2626. b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
  2627. b43_maskset32(dev, B43_MMIO_MACCTL, ~B43_MACCTL_ENABLED, 0);
  2628. /* force pci to flush the write */
  2629. b43_read32(dev, B43_MMIO_MACCTL);
  2630. for (i = 35; i; i--) {
  2631. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2632. if (tmp & B43_IRQ_MAC_SUSPENDED)
  2633. goto out;
  2634. udelay(10);
  2635. }
  2636. /* Hm, it seems this will take some time. Use msleep(). */
  2637. for (i = 40; i; i--) {
  2638. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2639. if (tmp & B43_IRQ_MAC_SUSPENDED)
  2640. goto out;
  2641. msleep(1);
  2642. }
  2643. b43err(dev->wl, "MAC suspend failed\n");
  2644. }
  2645. out:
  2646. dev->mac_suspended++;
  2647. }
  2648. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/MacPhyClkSet */
  2649. void b43_mac_phy_clock_set(struct b43_wldev *dev, bool on)
  2650. {
  2651. u32 tmp;
  2652. switch (dev->dev->bus_type) {
  2653. #ifdef CONFIG_B43_BCMA
  2654. case B43_BUS_BCMA:
  2655. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  2656. if (on)
  2657. tmp |= B43_BCMA_IOCTL_MACPHYCLKEN;
  2658. else
  2659. tmp &= ~B43_BCMA_IOCTL_MACPHYCLKEN;
  2660. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  2661. break;
  2662. #endif
  2663. #ifdef CONFIG_B43_SSB
  2664. case B43_BUS_SSB:
  2665. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  2666. if (on)
  2667. tmp |= B43_TMSLOW_MACPHYCLKEN;
  2668. else
  2669. tmp &= ~B43_TMSLOW_MACPHYCLKEN;
  2670. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  2671. break;
  2672. #endif
  2673. }
  2674. }
  2675. /* brcms_b_switch_macfreq */
  2676. void b43_mac_switch_freq(struct b43_wldev *dev, u8 spurmode)
  2677. {
  2678. u16 chip_id = dev->dev->chip_id;
  2679. if (chip_id == BCMA_CHIP_ID_BCM4331) {
  2680. switch (spurmode) {
  2681. case 2: /* 168 Mhz: 2^26/168 = 0x61862 */
  2682. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_LOW, 0x1862);
  2683. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_HIGH, 0x6);
  2684. break;
  2685. case 1: /* 164 Mhz: 2^26/164 = 0x63e70 */
  2686. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_LOW, 0x3e70);
  2687. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_HIGH, 0x6);
  2688. break;
  2689. default: /* 160 Mhz: 2^26/160 = 0x66666 */
  2690. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_LOW, 0x6666);
  2691. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_HIGH, 0x6);
  2692. break;
  2693. }
  2694. } else if (chip_id == BCMA_CHIP_ID_BCM43131 ||
  2695. chip_id == BCMA_CHIP_ID_BCM43217 ||
  2696. chip_id == BCMA_CHIP_ID_BCM43222 ||
  2697. chip_id == BCMA_CHIP_ID_BCM43224 ||
  2698. chip_id == BCMA_CHIP_ID_BCM43225 ||
  2699. chip_id == BCMA_CHIP_ID_BCM43227 ||
  2700. chip_id == BCMA_CHIP_ID_BCM43228) {
  2701. switch (spurmode) {
  2702. case 2: /* 126 Mhz */
  2703. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_LOW, 0x2082);
  2704. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_HIGH, 0x8);
  2705. break;
  2706. case 1: /* 123 Mhz */
  2707. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_LOW, 0x5341);
  2708. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_HIGH, 0x8);
  2709. break;
  2710. default: /* 120 Mhz */
  2711. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_LOW, 0x8889);
  2712. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_HIGH, 0x8);
  2713. break;
  2714. }
  2715. } else if (dev->phy.type == B43_PHYTYPE_LCN) {
  2716. switch (spurmode) {
  2717. case 1: /* 82 Mhz */
  2718. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_LOW, 0x7CE0);
  2719. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_HIGH, 0xC);
  2720. break;
  2721. default: /* 80 Mhz */
  2722. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_LOW, 0xCCCD);
  2723. b43_write16(dev, B43_MMIO_TSF_CLK_FRAC_HIGH, 0xC);
  2724. break;
  2725. }
  2726. }
  2727. }
  2728. static void b43_adjust_opmode(struct b43_wldev *dev)
  2729. {
  2730. struct b43_wl *wl = dev->wl;
  2731. u32 ctl;
  2732. u16 cfp_pretbtt;
  2733. ctl = b43_read32(dev, B43_MMIO_MACCTL);
  2734. /* Reset status to STA infrastructure mode. */
  2735. ctl &= ~B43_MACCTL_AP;
  2736. ctl &= ~B43_MACCTL_KEEP_CTL;
  2737. ctl &= ~B43_MACCTL_KEEP_BADPLCP;
  2738. ctl &= ~B43_MACCTL_KEEP_BAD;
  2739. ctl &= ~B43_MACCTL_PROMISC;
  2740. ctl &= ~B43_MACCTL_BEACPROMISC;
  2741. ctl |= B43_MACCTL_INFRA;
  2742. if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
  2743. b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT))
  2744. ctl |= B43_MACCTL_AP;
  2745. else if (b43_is_mode(wl, NL80211_IFTYPE_ADHOC))
  2746. ctl &= ~B43_MACCTL_INFRA;
  2747. if (wl->filter_flags & FIF_CONTROL)
  2748. ctl |= B43_MACCTL_KEEP_CTL;
  2749. if (wl->filter_flags & FIF_FCSFAIL)
  2750. ctl |= B43_MACCTL_KEEP_BAD;
  2751. if (wl->filter_flags & FIF_PLCPFAIL)
  2752. ctl |= B43_MACCTL_KEEP_BADPLCP;
  2753. if (wl->filter_flags & FIF_BCN_PRBRESP_PROMISC)
  2754. ctl |= B43_MACCTL_BEACPROMISC;
  2755. /* Workaround: On old hardware the HW-MAC-address-filter
  2756. * doesn't work properly, so always run promisc in filter
  2757. * it in software. */
  2758. if (dev->dev->core_rev <= 4)
  2759. ctl |= B43_MACCTL_PROMISC;
  2760. b43_write32(dev, B43_MMIO_MACCTL, ctl);
  2761. cfp_pretbtt = 2;
  2762. if ((ctl & B43_MACCTL_INFRA) && !(ctl & B43_MACCTL_AP)) {
  2763. if (dev->dev->chip_id == 0x4306 &&
  2764. dev->dev->chip_rev == 3)
  2765. cfp_pretbtt = 100;
  2766. else
  2767. cfp_pretbtt = 50;
  2768. }
  2769. b43_write16(dev, 0x612, cfp_pretbtt);
  2770. /* FIXME: We don't currently implement the PMQ mechanism,
  2771. * so always disable it. If we want to implement PMQ,
  2772. * we need to enable it here (clear DISCPMQ) in AP mode.
  2773. */
  2774. if (0 /* ctl & B43_MACCTL_AP */)
  2775. b43_maskset32(dev, B43_MMIO_MACCTL, ~B43_MACCTL_DISCPMQ, 0);
  2776. else
  2777. b43_maskset32(dev, B43_MMIO_MACCTL, ~0, B43_MACCTL_DISCPMQ);
  2778. }
  2779. static void b43_rate_memory_write(struct b43_wldev *dev, u16 rate, int is_ofdm)
  2780. {
  2781. u16 offset;
  2782. if (is_ofdm) {
  2783. offset = 0x480;
  2784. offset += (b43_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
  2785. } else {
  2786. offset = 0x4C0;
  2787. offset += (b43_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
  2788. }
  2789. b43_shm_write16(dev, B43_SHM_SHARED, offset + 0x20,
  2790. b43_shm_read16(dev, B43_SHM_SHARED, offset));
  2791. }
  2792. static void b43_rate_memory_init(struct b43_wldev *dev)
  2793. {
  2794. switch (dev->phy.type) {
  2795. case B43_PHYTYPE_G:
  2796. case B43_PHYTYPE_N:
  2797. case B43_PHYTYPE_LP:
  2798. case B43_PHYTYPE_HT:
  2799. case B43_PHYTYPE_LCN:
  2800. b43_rate_memory_write(dev, B43_OFDM_RATE_6MB, 1);
  2801. b43_rate_memory_write(dev, B43_OFDM_RATE_9MB, 1);
  2802. b43_rate_memory_write(dev, B43_OFDM_RATE_12MB, 1);
  2803. b43_rate_memory_write(dev, B43_OFDM_RATE_18MB, 1);
  2804. b43_rate_memory_write(dev, B43_OFDM_RATE_24MB, 1);
  2805. b43_rate_memory_write(dev, B43_OFDM_RATE_36MB, 1);
  2806. b43_rate_memory_write(dev, B43_OFDM_RATE_48MB, 1);
  2807. b43_rate_memory_write(dev, B43_OFDM_RATE_54MB, 1);
  2808. /* fallthrough */
  2809. case B43_PHYTYPE_B:
  2810. b43_rate_memory_write(dev, B43_CCK_RATE_1MB, 0);
  2811. b43_rate_memory_write(dev, B43_CCK_RATE_2MB, 0);
  2812. b43_rate_memory_write(dev, B43_CCK_RATE_5MB, 0);
  2813. b43_rate_memory_write(dev, B43_CCK_RATE_11MB, 0);
  2814. break;
  2815. default:
  2816. B43_WARN_ON(1);
  2817. }
  2818. }
  2819. /* Set the default values for the PHY TX Control Words. */
  2820. static void b43_set_phytxctl_defaults(struct b43_wldev *dev)
  2821. {
  2822. u16 ctl = 0;
  2823. ctl |= B43_TXH_PHY_ENC_CCK;
  2824. ctl |= B43_TXH_PHY_ANT01AUTO;
  2825. ctl |= B43_TXH_PHY_TXPWR;
  2826. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL, ctl);
  2827. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL, ctl);
  2828. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL, ctl);
  2829. }
  2830. /* Set the TX-Antenna for management frames sent by firmware. */
  2831. static void b43_mgmtframe_txantenna(struct b43_wldev *dev, int antenna)
  2832. {
  2833. u16 ant;
  2834. u16 tmp;
  2835. ant = b43_antenna_to_phyctl(antenna);
  2836. /* For ACK/CTS */
  2837. tmp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL);
  2838. tmp = (tmp & ~B43_TXH_PHY_ANT) | ant;
  2839. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL, tmp);
  2840. /* For Probe Resposes */
  2841. tmp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL);
  2842. tmp = (tmp & ~B43_TXH_PHY_ANT) | ant;
  2843. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL, tmp);
  2844. }
  2845. /* This is the opposite of b43_chip_init() */
  2846. static void b43_chip_exit(struct b43_wldev *dev)
  2847. {
  2848. b43_phy_exit(dev);
  2849. b43_gpio_cleanup(dev);
  2850. /* firmware is released later */
  2851. }
  2852. /* Initialize the chip
  2853. * http://bcm-specs.sipsolutions.net/ChipInit
  2854. */
  2855. static int b43_chip_init(struct b43_wldev *dev)
  2856. {
  2857. struct b43_phy *phy = &dev->phy;
  2858. int err;
  2859. u32 macctl;
  2860. u16 value16;
  2861. /* Initialize the MAC control */
  2862. macctl = B43_MACCTL_IHR_ENABLED | B43_MACCTL_SHM_ENABLED;
  2863. if (dev->phy.gmode)
  2864. macctl |= B43_MACCTL_GMODE;
  2865. macctl |= B43_MACCTL_INFRA;
  2866. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  2867. err = b43_upload_microcode(dev);
  2868. if (err)
  2869. goto out; /* firmware is released later */
  2870. err = b43_gpio_init(dev);
  2871. if (err)
  2872. goto out; /* firmware is released later */
  2873. err = b43_upload_initvals(dev);
  2874. if (err)
  2875. goto err_gpio_clean;
  2876. err = b43_upload_initvals_band(dev);
  2877. if (err)
  2878. goto err_gpio_clean;
  2879. /* Turn the Analog on and initialize the PHY. */
  2880. phy->ops->switch_analog(dev, 1);
  2881. err = b43_phy_init(dev);
  2882. if (err)
  2883. goto err_gpio_clean;
  2884. /* Disable Interference Mitigation. */
  2885. if (phy->ops->interf_mitigation)
  2886. phy->ops->interf_mitigation(dev, B43_INTERFMODE_NONE);
  2887. /* Select the antennae */
  2888. if (phy->ops->set_rx_antenna)
  2889. phy->ops->set_rx_antenna(dev, B43_ANTENNA_DEFAULT);
  2890. b43_mgmtframe_txantenna(dev, B43_ANTENNA_DEFAULT);
  2891. if (phy->type == B43_PHYTYPE_B) {
  2892. value16 = b43_read16(dev, 0x005E);
  2893. value16 |= 0x0004;
  2894. b43_write16(dev, 0x005E, value16);
  2895. }
  2896. b43_write32(dev, 0x0100, 0x01000000);
  2897. if (dev->dev->core_rev < 5)
  2898. b43_write32(dev, 0x010C, 0x01000000);
  2899. b43_maskset32(dev, B43_MMIO_MACCTL, ~B43_MACCTL_INFRA, 0);
  2900. b43_maskset32(dev, B43_MMIO_MACCTL, ~0, B43_MACCTL_INFRA);
  2901. /* Probe Response Timeout value */
  2902. /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
  2903. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRMAXTIME, 0);
  2904. /* Initially set the wireless operation mode. */
  2905. b43_adjust_opmode(dev);
  2906. if (dev->dev->core_rev < 3) {
  2907. b43_write16(dev, 0x060E, 0x0000);
  2908. b43_write16(dev, 0x0610, 0x8000);
  2909. b43_write16(dev, 0x0604, 0x0000);
  2910. b43_write16(dev, 0x0606, 0x0200);
  2911. } else {
  2912. b43_write32(dev, 0x0188, 0x80000000);
  2913. b43_write32(dev, 0x018C, 0x02000000);
  2914. }
  2915. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, 0x00004000);
  2916. b43_write32(dev, B43_MMIO_DMA0_IRQ_MASK, 0x0001FC00);
  2917. b43_write32(dev, B43_MMIO_DMA1_IRQ_MASK, 0x0000DC00);
  2918. b43_write32(dev, B43_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
  2919. b43_write32(dev, B43_MMIO_DMA3_IRQ_MASK, 0x0001DC00);
  2920. b43_write32(dev, B43_MMIO_DMA4_IRQ_MASK, 0x0000DC00);
  2921. b43_write32(dev, B43_MMIO_DMA5_IRQ_MASK, 0x0000DC00);
  2922. b43_mac_phy_clock_set(dev, true);
  2923. switch (dev->dev->bus_type) {
  2924. #ifdef CONFIG_B43_BCMA
  2925. case B43_BUS_BCMA:
  2926. /* FIXME: 0xE74 is quite common, but should be read from CC */
  2927. b43_write16(dev, B43_MMIO_POWERUP_DELAY, 0xE74);
  2928. break;
  2929. #endif
  2930. #ifdef CONFIG_B43_SSB
  2931. case B43_BUS_SSB:
  2932. b43_write16(dev, B43_MMIO_POWERUP_DELAY,
  2933. dev->dev->sdev->bus->chipco.fast_pwrup_delay);
  2934. break;
  2935. #endif
  2936. }
  2937. err = 0;
  2938. b43dbg(dev->wl, "Chip initialized\n");
  2939. out:
  2940. return err;
  2941. err_gpio_clean:
  2942. b43_gpio_cleanup(dev);
  2943. return err;
  2944. }
  2945. static void b43_periodic_every60sec(struct b43_wldev *dev)
  2946. {
  2947. const struct b43_phy_operations *ops = dev->phy.ops;
  2948. if (ops->pwork_60sec)
  2949. ops->pwork_60sec(dev);
  2950. /* Force check the TX power emission now. */
  2951. b43_phy_txpower_check(dev, B43_TXPWR_IGNORE_TIME);
  2952. }
  2953. static void b43_periodic_every30sec(struct b43_wldev *dev)
  2954. {
  2955. /* Update device statistics. */
  2956. b43_calculate_link_quality(dev);
  2957. }
  2958. static void b43_periodic_every15sec(struct b43_wldev *dev)
  2959. {
  2960. struct b43_phy *phy = &dev->phy;
  2961. u16 wdr;
  2962. if (dev->fw.opensource) {
  2963. /* Check if the firmware is still alive.
  2964. * It will reset the watchdog counter to 0 in its idle loop. */
  2965. wdr = b43_shm_read16(dev, B43_SHM_SCRATCH, B43_WATCHDOG_REG);
  2966. if (unlikely(wdr)) {
  2967. b43err(dev->wl, "Firmware watchdog: The firmware died!\n");
  2968. b43_controller_restart(dev, "Firmware watchdog");
  2969. return;
  2970. } else {
  2971. b43_shm_write16(dev, B43_SHM_SCRATCH,
  2972. B43_WATCHDOG_REG, 1);
  2973. }
  2974. }
  2975. if (phy->ops->pwork_15sec)
  2976. phy->ops->pwork_15sec(dev);
  2977. atomic_set(&phy->txerr_cnt, B43_PHY_TX_BADNESS_LIMIT);
  2978. wmb();
  2979. #if B43_DEBUG
  2980. if (b43_debug(dev, B43_DBG_VERBOSESTATS)) {
  2981. unsigned int i;
  2982. b43dbg(dev->wl, "Stats: %7u IRQs/sec, %7u TX/sec, %7u RX/sec\n",
  2983. dev->irq_count / 15,
  2984. dev->tx_count / 15,
  2985. dev->rx_count / 15);
  2986. dev->irq_count = 0;
  2987. dev->tx_count = 0;
  2988. dev->rx_count = 0;
  2989. for (i = 0; i < ARRAY_SIZE(dev->irq_bit_count); i++) {
  2990. if (dev->irq_bit_count[i]) {
  2991. b43dbg(dev->wl, "Stats: %7u IRQ-%02u/sec (0x%08X)\n",
  2992. dev->irq_bit_count[i] / 15, i, (1 << i));
  2993. dev->irq_bit_count[i] = 0;
  2994. }
  2995. }
  2996. }
  2997. #endif
  2998. }
  2999. static void do_periodic_work(struct b43_wldev *dev)
  3000. {
  3001. unsigned int state;
  3002. state = dev->periodic_state;
  3003. if (state % 4 == 0)
  3004. b43_periodic_every60sec(dev);
  3005. if (state % 2 == 0)
  3006. b43_periodic_every30sec(dev);
  3007. b43_periodic_every15sec(dev);
  3008. }
  3009. /* Periodic work locking policy:
  3010. * The whole periodic work handler is protected by
  3011. * wl->mutex. If another lock is needed somewhere in the
  3012. * pwork callchain, it's acquired in-place, where it's needed.
  3013. */
  3014. static void b43_periodic_work_handler(struct work_struct *work)
  3015. {
  3016. struct b43_wldev *dev = container_of(work, struct b43_wldev,
  3017. periodic_work.work);
  3018. struct b43_wl *wl = dev->wl;
  3019. unsigned long delay;
  3020. mutex_lock(&wl->mutex);
  3021. if (unlikely(b43_status(dev) != B43_STAT_STARTED))
  3022. goto out;
  3023. if (b43_debug(dev, B43_DBG_PWORK_STOP))
  3024. goto out_requeue;
  3025. do_periodic_work(dev);
  3026. dev->periodic_state++;
  3027. out_requeue:
  3028. if (b43_debug(dev, B43_DBG_PWORK_FAST))
  3029. delay = msecs_to_jiffies(50);
  3030. else
  3031. delay = round_jiffies_relative(HZ * 15);
  3032. ieee80211_queue_delayed_work(wl->hw, &dev->periodic_work, delay);
  3033. out:
  3034. mutex_unlock(&wl->mutex);
  3035. }
  3036. static void b43_periodic_tasks_setup(struct b43_wldev *dev)
  3037. {
  3038. struct delayed_work *work = &dev->periodic_work;
  3039. dev->periodic_state = 0;
  3040. INIT_DELAYED_WORK(work, b43_periodic_work_handler);
  3041. ieee80211_queue_delayed_work(dev->wl->hw, work, 0);
  3042. }
  3043. /* Check if communication with the device works correctly. */
  3044. static int b43_validate_chipaccess(struct b43_wldev *dev)
  3045. {
  3046. u32 v, backup0, backup4;
  3047. backup0 = b43_shm_read32(dev, B43_SHM_SHARED, 0);
  3048. backup4 = b43_shm_read32(dev, B43_SHM_SHARED, 4);
  3049. /* Check for read/write and endianness problems. */
  3050. b43_shm_write32(dev, B43_SHM_SHARED, 0, 0x55AAAA55);
  3051. if (b43_shm_read32(dev, B43_SHM_SHARED, 0) != 0x55AAAA55)
  3052. goto error;
  3053. b43_shm_write32(dev, B43_SHM_SHARED, 0, 0xAA5555AA);
  3054. if (b43_shm_read32(dev, B43_SHM_SHARED, 0) != 0xAA5555AA)
  3055. goto error;
  3056. /* Check if unaligned 32bit SHM_SHARED access works properly.
  3057. * However, don't bail out on failure, because it's noncritical. */
  3058. b43_shm_write16(dev, B43_SHM_SHARED, 0, 0x1122);
  3059. b43_shm_write16(dev, B43_SHM_SHARED, 2, 0x3344);
  3060. b43_shm_write16(dev, B43_SHM_SHARED, 4, 0x5566);
  3061. b43_shm_write16(dev, B43_SHM_SHARED, 6, 0x7788);
  3062. if (b43_shm_read32(dev, B43_SHM_SHARED, 2) != 0x55663344)
  3063. b43warn(dev->wl, "Unaligned 32bit SHM read access is broken\n");
  3064. b43_shm_write32(dev, B43_SHM_SHARED, 2, 0xAABBCCDD);
  3065. if (b43_shm_read16(dev, B43_SHM_SHARED, 0) != 0x1122 ||
  3066. b43_shm_read16(dev, B43_SHM_SHARED, 2) != 0xCCDD ||
  3067. b43_shm_read16(dev, B43_SHM_SHARED, 4) != 0xAABB ||
  3068. b43_shm_read16(dev, B43_SHM_SHARED, 6) != 0x7788)
  3069. b43warn(dev->wl, "Unaligned 32bit SHM write access is broken\n");
  3070. b43_shm_write32(dev, B43_SHM_SHARED, 0, backup0);
  3071. b43_shm_write32(dev, B43_SHM_SHARED, 4, backup4);
  3072. if ((dev->dev->core_rev >= 3) && (dev->dev->core_rev <= 10)) {
  3073. /* The 32bit register shadows the two 16bit registers
  3074. * with update sideeffects. Validate this. */
  3075. b43_write16(dev, B43_MMIO_TSF_CFP_START, 0xAAAA);
  3076. b43_write32(dev, B43_MMIO_TSF_CFP_START, 0xCCCCBBBB);
  3077. if (b43_read16(dev, B43_MMIO_TSF_CFP_START_LOW) != 0xBBBB)
  3078. goto error;
  3079. if (b43_read16(dev, B43_MMIO_TSF_CFP_START_HIGH) != 0xCCCC)
  3080. goto error;
  3081. }
  3082. b43_write32(dev, B43_MMIO_TSF_CFP_START, 0);
  3083. v = b43_read32(dev, B43_MMIO_MACCTL);
  3084. v |= B43_MACCTL_GMODE;
  3085. if (v != (B43_MACCTL_GMODE | B43_MACCTL_IHR_ENABLED))
  3086. goto error;
  3087. return 0;
  3088. error:
  3089. b43err(dev->wl, "Failed to validate the chipaccess\n");
  3090. return -ENODEV;
  3091. }
  3092. static void b43_security_init(struct b43_wldev *dev)
  3093. {
  3094. dev->ktp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_KTP);
  3095. /* KTP is a word address, but we address SHM bytewise.
  3096. * So multiply by two.
  3097. */
  3098. dev->ktp *= 2;
  3099. /* Number of RCMTA address slots */
  3100. b43_write16(dev, B43_MMIO_RCMTA_COUNT, B43_NR_PAIRWISE_KEYS);
  3101. /* Clear the key memory. */
  3102. b43_clear_keys(dev);
  3103. }
  3104. #ifdef CONFIG_B43_HWRNG
  3105. static int b43_rng_read(struct hwrng *rng, u32 *data)
  3106. {
  3107. struct b43_wl *wl = (struct b43_wl *)rng->priv;
  3108. struct b43_wldev *dev;
  3109. int count = -ENODEV;
  3110. mutex_lock(&wl->mutex);
  3111. dev = wl->current_dev;
  3112. if (likely(dev && b43_status(dev) >= B43_STAT_INITIALIZED)) {
  3113. *data = b43_read16(dev, B43_MMIO_RNG);
  3114. count = sizeof(u16);
  3115. }
  3116. mutex_unlock(&wl->mutex);
  3117. return count;
  3118. }
  3119. #endif /* CONFIG_B43_HWRNG */
  3120. static void b43_rng_exit(struct b43_wl *wl)
  3121. {
  3122. #ifdef CONFIG_B43_HWRNG
  3123. if (wl->rng_initialized)
  3124. hwrng_unregister(&wl->rng);
  3125. #endif /* CONFIG_B43_HWRNG */
  3126. }
  3127. static int b43_rng_init(struct b43_wl *wl)
  3128. {
  3129. int err = 0;
  3130. #ifdef CONFIG_B43_HWRNG
  3131. snprintf(wl->rng_name, ARRAY_SIZE(wl->rng_name),
  3132. "%s_%s", KBUILD_MODNAME, wiphy_name(wl->hw->wiphy));
  3133. wl->rng.name = wl->rng_name;
  3134. wl->rng.data_read = b43_rng_read;
  3135. wl->rng.priv = (unsigned long)wl;
  3136. wl->rng_initialized = true;
  3137. err = hwrng_register(&wl->rng);
  3138. if (err) {
  3139. wl->rng_initialized = false;
  3140. b43err(wl, "Failed to register the random "
  3141. "number generator (%d)\n", err);
  3142. }
  3143. #endif /* CONFIG_B43_HWRNG */
  3144. return err;
  3145. }
  3146. static void b43_tx_work(struct work_struct *work)
  3147. {
  3148. struct b43_wl *wl = container_of(work, struct b43_wl, tx_work);
  3149. struct b43_wldev *dev;
  3150. struct sk_buff *skb;
  3151. int queue_num;
  3152. int err = 0;
  3153. mutex_lock(&wl->mutex);
  3154. dev = wl->current_dev;
  3155. if (unlikely(!dev || b43_status(dev) < B43_STAT_STARTED)) {
  3156. mutex_unlock(&wl->mutex);
  3157. return;
  3158. }
  3159. for (queue_num = 0; queue_num < B43_QOS_QUEUE_NUM; queue_num++) {
  3160. while (skb_queue_len(&wl->tx_queue[queue_num])) {
  3161. skb = skb_dequeue(&wl->tx_queue[queue_num]);
  3162. if (b43_using_pio_transfers(dev))
  3163. err = b43_pio_tx(dev, skb);
  3164. else
  3165. err = b43_dma_tx(dev, skb);
  3166. if (err == -ENOSPC) {
  3167. wl->tx_queue_stopped[queue_num] = 1;
  3168. ieee80211_stop_queue(wl->hw, queue_num);
  3169. skb_queue_head(&wl->tx_queue[queue_num], skb);
  3170. break;
  3171. }
  3172. if (unlikely(err))
  3173. ieee80211_free_txskb(wl->hw, skb);
  3174. err = 0;
  3175. }
  3176. if (!err)
  3177. wl->tx_queue_stopped[queue_num] = 0;
  3178. }
  3179. #if B43_DEBUG
  3180. dev->tx_count++;
  3181. #endif
  3182. mutex_unlock(&wl->mutex);
  3183. }
  3184. static void b43_op_tx(struct ieee80211_hw *hw,
  3185. struct ieee80211_tx_control *control,
  3186. struct sk_buff *skb)
  3187. {
  3188. struct b43_wl *wl = hw_to_b43_wl(hw);
  3189. if (unlikely(skb->len < 2 + 2 + 6)) {
  3190. /* Too short, this can't be a valid frame. */
  3191. ieee80211_free_txskb(hw, skb);
  3192. return;
  3193. }
  3194. B43_WARN_ON(skb_shinfo(skb)->nr_frags);
  3195. skb_queue_tail(&wl->tx_queue[skb->queue_mapping], skb);
  3196. if (!wl->tx_queue_stopped[skb->queue_mapping]) {
  3197. ieee80211_queue_work(wl->hw, &wl->tx_work);
  3198. } else {
  3199. ieee80211_stop_queue(wl->hw, skb->queue_mapping);
  3200. }
  3201. }
  3202. static void b43_qos_params_upload(struct b43_wldev *dev,
  3203. const struct ieee80211_tx_queue_params *p,
  3204. u16 shm_offset)
  3205. {
  3206. u16 params[B43_NR_QOSPARAMS];
  3207. int bslots, tmp;
  3208. unsigned int i;
  3209. if (!dev->qos_enabled)
  3210. return;
  3211. bslots = b43_read16(dev, B43_MMIO_RNG) & p->cw_min;
  3212. memset(&params, 0, sizeof(params));
  3213. params[B43_QOSPARAM_TXOP] = p->txop * 32;
  3214. params[B43_QOSPARAM_CWMIN] = p->cw_min;
  3215. params[B43_QOSPARAM_CWMAX] = p->cw_max;
  3216. params[B43_QOSPARAM_CWCUR] = p->cw_min;
  3217. params[B43_QOSPARAM_AIFS] = p->aifs;
  3218. params[B43_QOSPARAM_BSLOTS] = bslots;
  3219. params[B43_QOSPARAM_REGGAP] = bslots + p->aifs;
  3220. for (i = 0; i < ARRAY_SIZE(params); i++) {
  3221. if (i == B43_QOSPARAM_STATUS) {
  3222. tmp = b43_shm_read16(dev, B43_SHM_SHARED,
  3223. shm_offset + (i * 2));
  3224. /* Mark the parameters as updated. */
  3225. tmp |= 0x100;
  3226. b43_shm_write16(dev, B43_SHM_SHARED,
  3227. shm_offset + (i * 2),
  3228. tmp);
  3229. } else {
  3230. b43_shm_write16(dev, B43_SHM_SHARED,
  3231. shm_offset + (i * 2),
  3232. params[i]);
  3233. }
  3234. }
  3235. }
  3236. /* Mapping of mac80211 queue numbers to b43 QoS SHM offsets. */
  3237. static const u16 b43_qos_shm_offsets[] = {
  3238. /* [mac80211-queue-nr] = SHM_OFFSET, */
  3239. [0] = B43_QOS_VOICE,
  3240. [1] = B43_QOS_VIDEO,
  3241. [2] = B43_QOS_BESTEFFORT,
  3242. [3] = B43_QOS_BACKGROUND,
  3243. };
  3244. /* Update all QOS parameters in hardware. */
  3245. static void b43_qos_upload_all(struct b43_wldev *dev)
  3246. {
  3247. struct b43_wl *wl = dev->wl;
  3248. struct b43_qos_params *params;
  3249. unsigned int i;
  3250. if (!dev->qos_enabled)
  3251. return;
  3252. BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
  3253. ARRAY_SIZE(wl->qos_params));
  3254. b43_mac_suspend(dev);
  3255. for (i = 0; i < ARRAY_SIZE(wl->qos_params); i++) {
  3256. params = &(wl->qos_params[i]);
  3257. b43_qos_params_upload(dev, &(params->p),
  3258. b43_qos_shm_offsets[i]);
  3259. }
  3260. b43_mac_enable(dev);
  3261. }
  3262. static void b43_qos_clear(struct b43_wl *wl)
  3263. {
  3264. struct b43_qos_params *params;
  3265. unsigned int i;
  3266. /* Initialize QoS parameters to sane defaults. */
  3267. BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
  3268. ARRAY_SIZE(wl->qos_params));
  3269. for (i = 0; i < ARRAY_SIZE(wl->qos_params); i++) {
  3270. params = &(wl->qos_params[i]);
  3271. switch (b43_qos_shm_offsets[i]) {
  3272. case B43_QOS_VOICE:
  3273. params->p.txop = 0;
  3274. params->p.aifs = 2;
  3275. params->p.cw_min = 0x0001;
  3276. params->p.cw_max = 0x0001;
  3277. break;
  3278. case B43_QOS_VIDEO:
  3279. params->p.txop = 0;
  3280. params->p.aifs = 2;
  3281. params->p.cw_min = 0x0001;
  3282. params->p.cw_max = 0x0001;
  3283. break;
  3284. case B43_QOS_BESTEFFORT:
  3285. params->p.txop = 0;
  3286. params->p.aifs = 3;
  3287. params->p.cw_min = 0x0001;
  3288. params->p.cw_max = 0x03FF;
  3289. break;
  3290. case B43_QOS_BACKGROUND:
  3291. params->p.txop = 0;
  3292. params->p.aifs = 7;
  3293. params->p.cw_min = 0x0001;
  3294. params->p.cw_max = 0x03FF;
  3295. break;
  3296. default:
  3297. B43_WARN_ON(1);
  3298. }
  3299. }
  3300. }
  3301. /* Initialize the core's QOS capabilities */
  3302. static void b43_qos_init(struct b43_wldev *dev)
  3303. {
  3304. if (!dev->qos_enabled) {
  3305. /* Disable QOS support. */
  3306. b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_EDCF);
  3307. b43_write16(dev, B43_MMIO_IFSCTL,
  3308. b43_read16(dev, B43_MMIO_IFSCTL)
  3309. & ~B43_MMIO_IFSCTL_USE_EDCF);
  3310. b43dbg(dev->wl, "QoS disabled\n");
  3311. return;
  3312. }
  3313. /* Upload the current QOS parameters. */
  3314. b43_qos_upload_all(dev);
  3315. /* Enable QOS support. */
  3316. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF);
  3317. b43_write16(dev, B43_MMIO_IFSCTL,
  3318. b43_read16(dev, B43_MMIO_IFSCTL)
  3319. | B43_MMIO_IFSCTL_USE_EDCF);
  3320. b43dbg(dev->wl, "QoS enabled\n");
  3321. }
  3322. static int b43_op_conf_tx(struct ieee80211_hw *hw,
  3323. struct ieee80211_vif *vif, u16 _queue,
  3324. const struct ieee80211_tx_queue_params *params)
  3325. {
  3326. struct b43_wl *wl = hw_to_b43_wl(hw);
  3327. struct b43_wldev *dev;
  3328. unsigned int queue = (unsigned int)_queue;
  3329. int err = -ENODEV;
  3330. if (queue >= ARRAY_SIZE(wl->qos_params)) {
  3331. /* Queue not available or don't support setting
  3332. * params on this queue. Return success to not
  3333. * confuse mac80211. */
  3334. return 0;
  3335. }
  3336. BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
  3337. ARRAY_SIZE(wl->qos_params));
  3338. mutex_lock(&wl->mutex);
  3339. dev = wl->current_dev;
  3340. if (unlikely(!dev || (b43_status(dev) < B43_STAT_INITIALIZED)))
  3341. goto out_unlock;
  3342. memcpy(&(wl->qos_params[queue].p), params, sizeof(*params));
  3343. b43_mac_suspend(dev);
  3344. b43_qos_params_upload(dev, &(wl->qos_params[queue].p),
  3345. b43_qos_shm_offsets[queue]);
  3346. b43_mac_enable(dev);
  3347. err = 0;
  3348. out_unlock:
  3349. mutex_unlock(&wl->mutex);
  3350. return err;
  3351. }
  3352. static int b43_op_get_stats(struct ieee80211_hw *hw,
  3353. struct ieee80211_low_level_stats *stats)
  3354. {
  3355. struct b43_wl *wl = hw_to_b43_wl(hw);
  3356. mutex_lock(&wl->mutex);
  3357. memcpy(stats, &wl->ieee_stats, sizeof(*stats));
  3358. mutex_unlock(&wl->mutex);
  3359. return 0;
  3360. }
  3361. static u64 b43_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  3362. {
  3363. struct b43_wl *wl = hw_to_b43_wl(hw);
  3364. struct b43_wldev *dev;
  3365. u64 tsf;
  3366. mutex_lock(&wl->mutex);
  3367. dev = wl->current_dev;
  3368. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED))
  3369. b43_tsf_read(dev, &tsf);
  3370. else
  3371. tsf = 0;
  3372. mutex_unlock(&wl->mutex);
  3373. return tsf;
  3374. }
  3375. static void b43_op_set_tsf(struct ieee80211_hw *hw,
  3376. struct ieee80211_vif *vif, u64 tsf)
  3377. {
  3378. struct b43_wl *wl = hw_to_b43_wl(hw);
  3379. struct b43_wldev *dev;
  3380. mutex_lock(&wl->mutex);
  3381. dev = wl->current_dev;
  3382. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED))
  3383. b43_tsf_write(dev, tsf);
  3384. mutex_unlock(&wl->mutex);
  3385. }
  3386. static const char *band_to_string(enum nl80211_band band)
  3387. {
  3388. switch (band) {
  3389. case NL80211_BAND_5GHZ:
  3390. return "5";
  3391. case NL80211_BAND_2GHZ:
  3392. return "2.4";
  3393. default:
  3394. break;
  3395. }
  3396. B43_WARN_ON(1);
  3397. return "";
  3398. }
  3399. /* Expects wl->mutex locked */
  3400. static int b43_switch_band(struct b43_wldev *dev,
  3401. struct ieee80211_channel *chan)
  3402. {
  3403. struct b43_phy *phy = &dev->phy;
  3404. bool gmode;
  3405. u32 tmp;
  3406. switch (chan->band) {
  3407. case NL80211_BAND_5GHZ:
  3408. gmode = false;
  3409. break;
  3410. case NL80211_BAND_2GHZ:
  3411. gmode = true;
  3412. break;
  3413. default:
  3414. B43_WARN_ON(1);
  3415. return -EINVAL;
  3416. }
  3417. if (!((gmode && phy->supports_2ghz) ||
  3418. (!gmode && phy->supports_5ghz))) {
  3419. b43err(dev->wl, "This device doesn't support %s-GHz band\n",
  3420. band_to_string(chan->band));
  3421. return -ENODEV;
  3422. }
  3423. if (!!phy->gmode == !!gmode) {
  3424. /* This device is already running. */
  3425. return 0;
  3426. }
  3427. b43dbg(dev->wl, "Switching to %s GHz band\n",
  3428. band_to_string(chan->band));
  3429. /* Some new devices don't need disabling radio for band switching */
  3430. if (!(phy->type == B43_PHYTYPE_N && phy->rev >= 3))
  3431. b43_software_rfkill(dev, true);
  3432. phy->gmode = gmode;
  3433. b43_phy_put_into_reset(dev);
  3434. switch (dev->dev->bus_type) {
  3435. #ifdef CONFIG_B43_BCMA
  3436. case B43_BUS_BCMA:
  3437. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
  3438. if (gmode)
  3439. tmp |= B43_BCMA_IOCTL_GMODE;
  3440. else
  3441. tmp &= ~B43_BCMA_IOCTL_GMODE;
  3442. bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
  3443. break;
  3444. #endif
  3445. #ifdef CONFIG_B43_SSB
  3446. case B43_BUS_SSB:
  3447. tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
  3448. if (gmode)
  3449. tmp |= B43_TMSLOW_GMODE;
  3450. else
  3451. tmp &= ~B43_TMSLOW_GMODE;
  3452. ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
  3453. break;
  3454. #endif
  3455. }
  3456. b43_phy_take_out_of_reset(dev);
  3457. b43_upload_initvals_band(dev);
  3458. b43_phy_init(dev);
  3459. return 0;
  3460. }
  3461. static void b43_set_beacon_listen_interval(struct b43_wldev *dev, u16 interval)
  3462. {
  3463. interval = min_t(u16, interval, (u16)0xFF);
  3464. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_BCN_LI, interval);
  3465. }
  3466. /* Write the short and long frame retry limit values. */
  3467. static void b43_set_retry_limits(struct b43_wldev *dev,
  3468. unsigned int short_retry,
  3469. unsigned int long_retry)
  3470. {
  3471. /* The retry limit is a 4-bit counter. Enforce this to avoid overflowing
  3472. * the chip-internal counter. */
  3473. short_retry = min(short_retry, (unsigned int)0xF);
  3474. long_retry = min(long_retry, (unsigned int)0xF);
  3475. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_SRLIMIT,
  3476. short_retry);
  3477. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_LRLIMIT,
  3478. long_retry);
  3479. }
  3480. static int b43_op_config(struct ieee80211_hw *hw, u32 changed)
  3481. {
  3482. struct b43_wl *wl = hw_to_b43_wl(hw);
  3483. struct b43_wldev *dev = wl->current_dev;
  3484. struct b43_phy *phy = &dev->phy;
  3485. struct ieee80211_conf *conf = &hw->conf;
  3486. int antenna;
  3487. int err = 0;
  3488. mutex_lock(&wl->mutex);
  3489. b43_mac_suspend(dev);
  3490. if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL)
  3491. b43_set_beacon_listen_interval(dev, conf->listen_interval);
  3492. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  3493. phy->chandef = &conf->chandef;
  3494. phy->channel = conf->chandef.chan->hw_value;
  3495. /* Switch the band (if necessary). */
  3496. err = b43_switch_band(dev, conf->chandef.chan);
  3497. if (err)
  3498. goto out_mac_enable;
  3499. /* Switch to the requested channel.
  3500. * The firmware takes care of races with the TX handler.
  3501. */
  3502. b43_switch_channel(dev, phy->channel);
  3503. }
  3504. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  3505. b43_set_retry_limits(dev, conf->short_frame_max_tx_count,
  3506. conf->long_frame_max_tx_count);
  3507. changed &= ~IEEE80211_CONF_CHANGE_RETRY_LIMITS;
  3508. if (!changed)
  3509. goto out_mac_enable;
  3510. dev->wl->radiotap_enabled = !!(conf->flags & IEEE80211_CONF_MONITOR);
  3511. /* Adjust the desired TX power level. */
  3512. if (conf->power_level != 0) {
  3513. if (conf->power_level != phy->desired_txpower) {
  3514. phy->desired_txpower = conf->power_level;
  3515. b43_phy_txpower_check(dev, B43_TXPWR_IGNORE_TIME |
  3516. B43_TXPWR_IGNORE_TSSI);
  3517. }
  3518. }
  3519. /* Antennas for RX and management frame TX. */
  3520. antenna = B43_ANTENNA_DEFAULT;
  3521. b43_mgmtframe_txantenna(dev, antenna);
  3522. antenna = B43_ANTENNA_DEFAULT;
  3523. if (phy->ops->set_rx_antenna)
  3524. phy->ops->set_rx_antenna(dev, antenna);
  3525. if (wl->radio_enabled != phy->radio_on) {
  3526. if (wl->radio_enabled) {
  3527. b43_software_rfkill(dev, false);
  3528. b43info(dev->wl, "Radio turned on by software\n");
  3529. if (!dev->radio_hw_enable) {
  3530. b43info(dev->wl, "The hardware RF-kill button "
  3531. "still turns the radio physically off. "
  3532. "Press the button to turn it on.\n");
  3533. }
  3534. } else {
  3535. b43_software_rfkill(dev, true);
  3536. b43info(dev->wl, "Radio turned off by software\n");
  3537. }
  3538. }
  3539. out_mac_enable:
  3540. b43_mac_enable(dev);
  3541. mutex_unlock(&wl->mutex);
  3542. return err;
  3543. }
  3544. static void b43_update_basic_rates(struct b43_wldev *dev, u32 brates)
  3545. {
  3546. struct ieee80211_supported_band *sband =
  3547. dev->wl->hw->wiphy->bands[b43_current_band(dev->wl)];
  3548. struct ieee80211_rate *rate;
  3549. int i;
  3550. u16 basic, direct, offset, basic_offset, rateptr;
  3551. for (i = 0; i < sband->n_bitrates; i++) {
  3552. rate = &sband->bitrates[i];
  3553. if (b43_is_cck_rate(rate->hw_value)) {
  3554. direct = B43_SHM_SH_CCKDIRECT;
  3555. basic = B43_SHM_SH_CCKBASIC;
  3556. offset = b43_plcp_get_ratecode_cck(rate->hw_value);
  3557. offset &= 0xF;
  3558. } else {
  3559. direct = B43_SHM_SH_OFDMDIRECT;
  3560. basic = B43_SHM_SH_OFDMBASIC;
  3561. offset = b43_plcp_get_ratecode_ofdm(rate->hw_value);
  3562. offset &= 0xF;
  3563. }
  3564. rate = ieee80211_get_response_rate(sband, brates, rate->bitrate);
  3565. if (b43_is_cck_rate(rate->hw_value)) {
  3566. basic_offset = b43_plcp_get_ratecode_cck(rate->hw_value);
  3567. basic_offset &= 0xF;
  3568. } else {
  3569. basic_offset = b43_plcp_get_ratecode_ofdm(rate->hw_value);
  3570. basic_offset &= 0xF;
  3571. }
  3572. /*
  3573. * Get the pointer that we need to point to
  3574. * from the direct map
  3575. */
  3576. rateptr = b43_shm_read16(dev, B43_SHM_SHARED,
  3577. direct + 2 * basic_offset);
  3578. /* and write it to the basic map */
  3579. b43_shm_write16(dev, B43_SHM_SHARED, basic + 2 * offset,
  3580. rateptr);
  3581. }
  3582. }
  3583. static void b43_op_bss_info_changed(struct ieee80211_hw *hw,
  3584. struct ieee80211_vif *vif,
  3585. struct ieee80211_bss_conf *conf,
  3586. u32 changed)
  3587. {
  3588. struct b43_wl *wl = hw_to_b43_wl(hw);
  3589. struct b43_wldev *dev;
  3590. mutex_lock(&wl->mutex);
  3591. dev = wl->current_dev;
  3592. if (!dev || b43_status(dev) < B43_STAT_STARTED)
  3593. goto out_unlock_mutex;
  3594. B43_WARN_ON(wl->vif != vif);
  3595. if (changed & BSS_CHANGED_BSSID) {
  3596. if (conf->bssid)
  3597. memcpy(wl->bssid, conf->bssid, ETH_ALEN);
  3598. else
  3599. eth_zero_addr(wl->bssid);
  3600. }
  3601. if (b43_status(dev) >= B43_STAT_INITIALIZED) {
  3602. if (changed & BSS_CHANGED_BEACON &&
  3603. (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
  3604. b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT) ||
  3605. b43_is_mode(wl, NL80211_IFTYPE_ADHOC)))
  3606. b43_update_templates(wl);
  3607. if (changed & BSS_CHANGED_BSSID)
  3608. b43_write_mac_bssid_templates(dev);
  3609. }
  3610. b43_mac_suspend(dev);
  3611. /* Update templates for AP/mesh mode. */
  3612. if (changed & BSS_CHANGED_BEACON_INT &&
  3613. (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
  3614. b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT) ||
  3615. b43_is_mode(wl, NL80211_IFTYPE_ADHOC)) &&
  3616. conf->beacon_int)
  3617. b43_set_beacon_int(dev, conf->beacon_int);
  3618. if (changed & BSS_CHANGED_BASIC_RATES)
  3619. b43_update_basic_rates(dev, conf->basic_rates);
  3620. if (changed & BSS_CHANGED_ERP_SLOT) {
  3621. if (conf->use_short_slot)
  3622. b43_short_slot_timing_enable(dev);
  3623. else
  3624. b43_short_slot_timing_disable(dev);
  3625. }
  3626. b43_mac_enable(dev);
  3627. out_unlock_mutex:
  3628. mutex_unlock(&wl->mutex);
  3629. }
  3630. static int b43_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  3631. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  3632. struct ieee80211_key_conf *key)
  3633. {
  3634. struct b43_wl *wl = hw_to_b43_wl(hw);
  3635. struct b43_wldev *dev;
  3636. u8 algorithm;
  3637. u8 index;
  3638. int err;
  3639. static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  3640. if (modparam_nohwcrypt)
  3641. return -ENOSPC; /* User disabled HW-crypto */
  3642. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  3643. vif->type == NL80211_IFTYPE_MESH_POINT) &&
  3644. (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
  3645. key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
  3646. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  3647. /*
  3648. * For now, disable hw crypto for the RSN IBSS group keys. This
  3649. * could be optimized in the future, but until that gets
  3650. * implemented, use of software crypto for group addressed
  3651. * frames is a acceptable to allow RSN IBSS to be used.
  3652. */
  3653. return -EOPNOTSUPP;
  3654. }
  3655. mutex_lock(&wl->mutex);
  3656. dev = wl->current_dev;
  3657. err = -ENODEV;
  3658. if (!dev || b43_status(dev) < B43_STAT_INITIALIZED)
  3659. goto out_unlock;
  3660. if (dev->fw.pcm_request_failed || !dev->hwcrypto_enabled) {
  3661. /* We don't have firmware for the crypto engine.
  3662. * Must use software-crypto. */
  3663. err = -EOPNOTSUPP;
  3664. goto out_unlock;
  3665. }
  3666. err = -EINVAL;
  3667. switch (key->cipher) {
  3668. case WLAN_CIPHER_SUITE_WEP40:
  3669. algorithm = B43_SEC_ALGO_WEP40;
  3670. break;
  3671. case WLAN_CIPHER_SUITE_WEP104:
  3672. algorithm = B43_SEC_ALGO_WEP104;
  3673. break;
  3674. case WLAN_CIPHER_SUITE_TKIP:
  3675. algorithm = B43_SEC_ALGO_TKIP;
  3676. break;
  3677. case WLAN_CIPHER_SUITE_CCMP:
  3678. algorithm = B43_SEC_ALGO_AES;
  3679. break;
  3680. default:
  3681. B43_WARN_ON(1);
  3682. goto out_unlock;
  3683. }
  3684. index = (u8) (key->keyidx);
  3685. if (index > 3)
  3686. goto out_unlock;
  3687. switch (cmd) {
  3688. case SET_KEY:
  3689. if (algorithm == B43_SEC_ALGO_TKIP &&
  3690. (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
  3691. !modparam_hwtkip)) {
  3692. /* We support only pairwise key */
  3693. err = -EOPNOTSUPP;
  3694. goto out_unlock;
  3695. }
  3696. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
  3697. if (WARN_ON(!sta)) {
  3698. err = -EOPNOTSUPP;
  3699. goto out_unlock;
  3700. }
  3701. /* Pairwise key with an assigned MAC address. */
  3702. err = b43_key_write(dev, -1, algorithm,
  3703. key->key, key->keylen,
  3704. sta->addr, key);
  3705. } else {
  3706. /* Group key */
  3707. err = b43_key_write(dev, index, algorithm,
  3708. key->key, key->keylen, NULL, key);
  3709. }
  3710. if (err)
  3711. goto out_unlock;
  3712. if (algorithm == B43_SEC_ALGO_WEP40 ||
  3713. algorithm == B43_SEC_ALGO_WEP104) {
  3714. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_USEDEFKEYS);
  3715. } else {
  3716. b43_hf_write(dev,
  3717. b43_hf_read(dev) & ~B43_HF_USEDEFKEYS);
  3718. }
  3719. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  3720. if (algorithm == B43_SEC_ALGO_TKIP)
  3721. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  3722. break;
  3723. case DISABLE_KEY: {
  3724. err = b43_key_clear(dev, key->hw_key_idx);
  3725. if (err)
  3726. goto out_unlock;
  3727. break;
  3728. }
  3729. default:
  3730. B43_WARN_ON(1);
  3731. }
  3732. out_unlock:
  3733. if (!err) {
  3734. b43dbg(wl, "%s hardware based encryption for keyidx: %d, "
  3735. "mac: %pM\n",
  3736. cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
  3737. sta ? sta->addr : bcast_addr);
  3738. b43_dump_keymemory(dev);
  3739. }
  3740. mutex_unlock(&wl->mutex);
  3741. return err;
  3742. }
  3743. static void b43_op_configure_filter(struct ieee80211_hw *hw,
  3744. unsigned int changed, unsigned int *fflags,
  3745. u64 multicast)
  3746. {
  3747. struct b43_wl *wl = hw_to_b43_wl(hw);
  3748. struct b43_wldev *dev;
  3749. mutex_lock(&wl->mutex);
  3750. dev = wl->current_dev;
  3751. if (!dev) {
  3752. *fflags = 0;
  3753. goto out_unlock;
  3754. }
  3755. *fflags &= FIF_ALLMULTI |
  3756. FIF_FCSFAIL |
  3757. FIF_PLCPFAIL |
  3758. FIF_CONTROL |
  3759. FIF_OTHER_BSS |
  3760. FIF_BCN_PRBRESP_PROMISC;
  3761. changed &= FIF_ALLMULTI |
  3762. FIF_FCSFAIL |
  3763. FIF_PLCPFAIL |
  3764. FIF_CONTROL |
  3765. FIF_OTHER_BSS |
  3766. FIF_BCN_PRBRESP_PROMISC;
  3767. wl->filter_flags = *fflags;
  3768. if (changed && b43_status(dev) >= B43_STAT_INITIALIZED)
  3769. b43_adjust_opmode(dev);
  3770. out_unlock:
  3771. mutex_unlock(&wl->mutex);
  3772. }
  3773. /* Locking: wl->mutex
  3774. * Returns the current dev. This might be different from the passed in dev,
  3775. * because the core might be gone away while we unlocked the mutex. */
  3776. static struct b43_wldev * b43_wireless_core_stop(struct b43_wldev *dev)
  3777. {
  3778. struct b43_wl *wl;
  3779. struct b43_wldev *orig_dev;
  3780. u32 mask;
  3781. int queue_num;
  3782. if (!dev)
  3783. return NULL;
  3784. wl = dev->wl;
  3785. redo:
  3786. if (!dev || b43_status(dev) < B43_STAT_STARTED)
  3787. return dev;
  3788. /* Cancel work. Unlock to avoid deadlocks. */
  3789. mutex_unlock(&wl->mutex);
  3790. cancel_delayed_work_sync(&dev->periodic_work);
  3791. cancel_work_sync(&wl->tx_work);
  3792. b43_leds_stop(dev);
  3793. mutex_lock(&wl->mutex);
  3794. dev = wl->current_dev;
  3795. if (!dev || b43_status(dev) < B43_STAT_STARTED) {
  3796. /* Whoops, aliens ate up the device while we were unlocked. */
  3797. return dev;
  3798. }
  3799. /* Disable interrupts on the device. */
  3800. b43_set_status(dev, B43_STAT_INITIALIZED);
  3801. if (b43_bus_host_is_sdio(dev->dev)) {
  3802. /* wl->mutex is locked. That is enough. */
  3803. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, 0);
  3804. b43_read32(dev, B43_MMIO_GEN_IRQ_MASK); /* Flush */
  3805. } else {
  3806. spin_lock_irq(&wl->hardirq_lock);
  3807. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, 0);
  3808. b43_read32(dev, B43_MMIO_GEN_IRQ_MASK); /* Flush */
  3809. spin_unlock_irq(&wl->hardirq_lock);
  3810. }
  3811. /* Synchronize and free the interrupt handlers. Unlock to avoid deadlocks. */
  3812. orig_dev = dev;
  3813. mutex_unlock(&wl->mutex);
  3814. if (b43_bus_host_is_sdio(dev->dev))
  3815. b43_sdio_free_irq(dev);
  3816. else
  3817. free_irq(dev->dev->irq, dev);
  3818. mutex_lock(&wl->mutex);
  3819. dev = wl->current_dev;
  3820. if (!dev)
  3821. return dev;
  3822. if (dev != orig_dev) {
  3823. if (b43_status(dev) >= B43_STAT_STARTED)
  3824. goto redo;
  3825. return dev;
  3826. }
  3827. mask = b43_read32(dev, B43_MMIO_GEN_IRQ_MASK);
  3828. B43_WARN_ON(mask != 0xFFFFFFFF && mask);
  3829. /* Drain all TX queues. */
  3830. for (queue_num = 0; queue_num < B43_QOS_QUEUE_NUM; queue_num++) {
  3831. while (skb_queue_len(&wl->tx_queue[queue_num])) {
  3832. struct sk_buff *skb;
  3833. skb = skb_dequeue(&wl->tx_queue[queue_num]);
  3834. ieee80211_free_txskb(wl->hw, skb);
  3835. }
  3836. }
  3837. b43_mac_suspend(dev);
  3838. b43_leds_exit(dev);
  3839. b43dbg(wl, "Wireless interface stopped\n");
  3840. return dev;
  3841. }
  3842. /* Locking: wl->mutex */
  3843. static int b43_wireless_core_start(struct b43_wldev *dev)
  3844. {
  3845. int err;
  3846. B43_WARN_ON(b43_status(dev) != B43_STAT_INITIALIZED);
  3847. drain_txstatus_queue(dev);
  3848. if (b43_bus_host_is_sdio(dev->dev)) {
  3849. err = b43_sdio_request_irq(dev, b43_sdio_interrupt_handler);
  3850. if (err) {
  3851. b43err(dev->wl, "Cannot request SDIO IRQ\n");
  3852. goto out;
  3853. }
  3854. } else {
  3855. err = request_threaded_irq(dev->dev->irq, b43_interrupt_handler,
  3856. b43_interrupt_thread_handler,
  3857. IRQF_SHARED, KBUILD_MODNAME, dev);
  3858. if (err) {
  3859. b43err(dev->wl, "Cannot request IRQ-%d\n",
  3860. dev->dev->irq);
  3861. goto out;
  3862. }
  3863. }
  3864. /* We are ready to run. */
  3865. ieee80211_wake_queues(dev->wl->hw);
  3866. b43_set_status(dev, B43_STAT_STARTED);
  3867. /* Start data flow (TX/RX). */
  3868. b43_mac_enable(dev);
  3869. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
  3870. /* Start maintenance work */
  3871. b43_periodic_tasks_setup(dev);
  3872. b43_leds_init(dev);
  3873. b43dbg(dev->wl, "Wireless interface started\n");
  3874. out:
  3875. return err;
  3876. }
  3877. static char *b43_phy_name(struct b43_wldev *dev, u8 phy_type)
  3878. {
  3879. switch (phy_type) {
  3880. case B43_PHYTYPE_A:
  3881. return "A";
  3882. case B43_PHYTYPE_B:
  3883. return "B";
  3884. case B43_PHYTYPE_G:
  3885. return "G";
  3886. case B43_PHYTYPE_N:
  3887. return "N";
  3888. case B43_PHYTYPE_LP:
  3889. return "LP";
  3890. case B43_PHYTYPE_SSLPN:
  3891. return "SSLPN";
  3892. case B43_PHYTYPE_HT:
  3893. return "HT";
  3894. case B43_PHYTYPE_LCN:
  3895. return "LCN";
  3896. case B43_PHYTYPE_LCNXN:
  3897. return "LCNXN";
  3898. case B43_PHYTYPE_LCN40:
  3899. return "LCN40";
  3900. case B43_PHYTYPE_AC:
  3901. return "AC";
  3902. }
  3903. return "UNKNOWN";
  3904. }
  3905. /* Get PHY and RADIO versioning numbers */
  3906. static int b43_phy_versioning(struct b43_wldev *dev)
  3907. {
  3908. struct b43_phy *phy = &dev->phy;
  3909. const u8 core_rev = dev->dev->core_rev;
  3910. u32 tmp;
  3911. u8 analog_type;
  3912. u8 phy_type;
  3913. u8 phy_rev;
  3914. u16 radio_manuf;
  3915. u16 radio_id;
  3916. u16 radio_rev;
  3917. u8 radio_ver;
  3918. int unsupported = 0;
  3919. /* Get PHY versioning */
  3920. tmp = b43_read16(dev, B43_MMIO_PHY_VER);
  3921. analog_type = (tmp & B43_PHYVER_ANALOG) >> B43_PHYVER_ANALOG_SHIFT;
  3922. phy_type = (tmp & B43_PHYVER_TYPE) >> B43_PHYVER_TYPE_SHIFT;
  3923. phy_rev = (tmp & B43_PHYVER_VERSION);
  3924. /* LCNXN is continuation of N which run out of revisions */
  3925. if (phy_type == B43_PHYTYPE_LCNXN) {
  3926. phy_type = B43_PHYTYPE_N;
  3927. phy_rev += 16;
  3928. }
  3929. switch (phy_type) {
  3930. #ifdef CONFIG_B43_PHY_G
  3931. case B43_PHYTYPE_G:
  3932. if (phy_rev > 9)
  3933. unsupported = 1;
  3934. break;
  3935. #endif
  3936. #ifdef CONFIG_B43_PHY_N
  3937. case B43_PHYTYPE_N:
  3938. if (phy_rev >= 19)
  3939. unsupported = 1;
  3940. break;
  3941. #endif
  3942. #ifdef CONFIG_B43_PHY_LP
  3943. case B43_PHYTYPE_LP:
  3944. if (phy_rev > 2)
  3945. unsupported = 1;
  3946. break;
  3947. #endif
  3948. #ifdef CONFIG_B43_PHY_HT
  3949. case B43_PHYTYPE_HT:
  3950. if (phy_rev > 1)
  3951. unsupported = 1;
  3952. break;
  3953. #endif
  3954. #ifdef CONFIG_B43_PHY_LCN
  3955. case B43_PHYTYPE_LCN:
  3956. if (phy_rev > 1)
  3957. unsupported = 1;
  3958. break;
  3959. #endif
  3960. #ifdef CONFIG_B43_PHY_AC
  3961. case B43_PHYTYPE_AC:
  3962. if (phy_rev > 1)
  3963. unsupported = 1;
  3964. break;
  3965. #endif
  3966. default:
  3967. unsupported = 1;
  3968. }
  3969. if (unsupported) {
  3970. b43err(dev->wl, "FOUND UNSUPPORTED PHY (Analog %u, Type %d (%s), Revision %u)\n",
  3971. analog_type, phy_type, b43_phy_name(dev, phy_type),
  3972. phy_rev);
  3973. return -EOPNOTSUPP;
  3974. }
  3975. b43info(dev->wl, "Found PHY: Analog %u, Type %d (%s), Revision %u\n",
  3976. analog_type, phy_type, b43_phy_name(dev, phy_type), phy_rev);
  3977. /* Get RADIO versioning */
  3978. if (core_rev == 40 || core_rev == 42) {
  3979. radio_manuf = 0x17F;
  3980. b43_write16f(dev, B43_MMIO_RADIO24_CONTROL, 0);
  3981. radio_rev = b43_read16(dev, B43_MMIO_RADIO24_DATA);
  3982. b43_write16f(dev, B43_MMIO_RADIO24_CONTROL, 1);
  3983. radio_id = b43_read16(dev, B43_MMIO_RADIO24_DATA);
  3984. radio_ver = 0; /* Is there version somewhere? */
  3985. } else if (core_rev >= 24) {
  3986. u16 radio24[3];
  3987. for (tmp = 0; tmp < 3; tmp++) {
  3988. b43_write16f(dev, B43_MMIO_RADIO24_CONTROL, tmp);
  3989. radio24[tmp] = b43_read16(dev, B43_MMIO_RADIO24_DATA);
  3990. }
  3991. radio_manuf = 0x17F;
  3992. radio_id = (radio24[2] << 8) | radio24[1];
  3993. radio_rev = (radio24[0] & 0xF);
  3994. radio_ver = (radio24[0] & 0xF0) >> 4;
  3995. } else {
  3996. if (dev->dev->chip_id == 0x4317) {
  3997. if (dev->dev->chip_rev == 0)
  3998. tmp = 0x3205017F;
  3999. else if (dev->dev->chip_rev == 1)
  4000. tmp = 0x4205017F;
  4001. else
  4002. tmp = 0x5205017F;
  4003. } else {
  4004. b43_write16f(dev, B43_MMIO_RADIO_CONTROL,
  4005. B43_RADIOCTL_ID);
  4006. tmp = b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
  4007. b43_write16f(dev, B43_MMIO_RADIO_CONTROL,
  4008. B43_RADIOCTL_ID);
  4009. tmp |= b43_read16(dev, B43_MMIO_RADIO_DATA_HIGH) << 16;
  4010. }
  4011. radio_manuf = (tmp & 0x00000FFF);
  4012. radio_id = (tmp & 0x0FFFF000) >> 12;
  4013. radio_rev = (tmp & 0xF0000000) >> 28;
  4014. radio_ver = 0; /* Probably not available on old hw */
  4015. }
  4016. if (radio_manuf != 0x17F /* Broadcom */)
  4017. unsupported = 1;
  4018. switch (phy_type) {
  4019. case B43_PHYTYPE_B:
  4020. if ((radio_id & 0xFFF0) != 0x2050)
  4021. unsupported = 1;
  4022. break;
  4023. case B43_PHYTYPE_G:
  4024. if (radio_id != 0x2050)
  4025. unsupported = 1;
  4026. break;
  4027. case B43_PHYTYPE_N:
  4028. if (radio_id != 0x2055 && radio_id != 0x2056 &&
  4029. radio_id != 0x2057)
  4030. unsupported = 1;
  4031. if (radio_id == 0x2057 &&
  4032. !(radio_rev == 9 || radio_rev == 14))
  4033. unsupported = 1;
  4034. break;
  4035. case B43_PHYTYPE_LP:
  4036. if (radio_id != 0x2062 && radio_id != 0x2063)
  4037. unsupported = 1;
  4038. break;
  4039. case B43_PHYTYPE_HT:
  4040. if (radio_id != 0x2059)
  4041. unsupported = 1;
  4042. break;
  4043. case B43_PHYTYPE_LCN:
  4044. if (radio_id != 0x2064)
  4045. unsupported = 1;
  4046. break;
  4047. case B43_PHYTYPE_AC:
  4048. if (radio_id != 0x2069)
  4049. unsupported = 1;
  4050. break;
  4051. default:
  4052. B43_WARN_ON(1);
  4053. }
  4054. if (unsupported) {
  4055. b43err(dev->wl,
  4056. "FOUND UNSUPPORTED RADIO (Manuf 0x%X, ID 0x%X, Revision %u, Version %u)\n",
  4057. radio_manuf, radio_id, radio_rev, radio_ver);
  4058. return -EOPNOTSUPP;
  4059. }
  4060. b43info(dev->wl,
  4061. "Found Radio: Manuf 0x%X, ID 0x%X, Revision %u, Version %u\n",
  4062. radio_manuf, radio_id, radio_rev, radio_ver);
  4063. /* FIXME: b43 treats "id" as "ver" and ignores the real "ver" */
  4064. phy->radio_manuf = radio_manuf;
  4065. phy->radio_ver = radio_id;
  4066. phy->radio_rev = radio_rev;
  4067. phy->analog = analog_type;
  4068. phy->type = phy_type;
  4069. phy->rev = phy_rev;
  4070. return 0;
  4071. }
  4072. static void setup_struct_phy_for_init(struct b43_wldev *dev,
  4073. struct b43_phy *phy)
  4074. {
  4075. phy->hardware_power_control = !!modparam_hwpctl;
  4076. phy->next_txpwr_check_time = jiffies;
  4077. /* PHY TX errors counter. */
  4078. atomic_set(&phy->txerr_cnt, B43_PHY_TX_BADNESS_LIMIT);
  4079. #if B43_DEBUG
  4080. phy->phy_locked = false;
  4081. phy->radio_locked = false;
  4082. #endif
  4083. }
  4084. static void setup_struct_wldev_for_init(struct b43_wldev *dev)
  4085. {
  4086. dev->dfq_valid = false;
  4087. /* Assume the radio is enabled. If it's not enabled, the state will
  4088. * immediately get fixed on the first periodic work run. */
  4089. dev->radio_hw_enable = true;
  4090. /* Stats */
  4091. memset(&dev->stats, 0, sizeof(dev->stats));
  4092. setup_struct_phy_for_init(dev, &dev->phy);
  4093. /* IRQ related flags */
  4094. dev->irq_reason = 0;
  4095. memset(dev->dma_reason, 0, sizeof(dev->dma_reason));
  4096. dev->irq_mask = B43_IRQ_MASKTEMPLATE;
  4097. if (b43_modparam_verbose < B43_VERBOSITY_DEBUG)
  4098. dev->irq_mask &= ~B43_IRQ_PHY_TXERR;
  4099. dev->mac_suspended = 1;
  4100. /* Noise calculation context */
  4101. memset(&dev->noisecalc, 0, sizeof(dev->noisecalc));
  4102. }
  4103. static void b43_bluetooth_coext_enable(struct b43_wldev *dev)
  4104. {
  4105. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  4106. u64 hf;
  4107. if (!modparam_btcoex)
  4108. return;
  4109. if (!(sprom->boardflags_lo & B43_BFL_BTCOEXIST))
  4110. return;
  4111. if (dev->phy.type != B43_PHYTYPE_B && !dev->phy.gmode)
  4112. return;
  4113. hf = b43_hf_read(dev);
  4114. if (sprom->boardflags_lo & B43_BFL_BTCMOD)
  4115. hf |= B43_HF_BTCOEXALT;
  4116. else
  4117. hf |= B43_HF_BTCOEX;
  4118. b43_hf_write(dev, hf);
  4119. }
  4120. static void b43_bluetooth_coext_disable(struct b43_wldev *dev)
  4121. {
  4122. if (!modparam_btcoex)
  4123. return;
  4124. //TODO
  4125. }
  4126. static void b43_imcfglo_timeouts_workaround(struct b43_wldev *dev)
  4127. {
  4128. struct ssb_bus *bus;
  4129. u32 tmp;
  4130. #ifdef CONFIG_B43_SSB
  4131. if (dev->dev->bus_type != B43_BUS_SSB)
  4132. return;
  4133. #else
  4134. return;
  4135. #endif
  4136. bus = dev->dev->sdev->bus;
  4137. if ((bus->chip_id == 0x4311 && bus->chip_rev == 2) ||
  4138. (bus->chip_id == 0x4312)) {
  4139. tmp = ssb_read32(dev->dev->sdev, SSB_IMCFGLO);
  4140. tmp &= ~SSB_IMCFGLO_REQTO;
  4141. tmp &= ~SSB_IMCFGLO_SERTO;
  4142. tmp |= 0x3;
  4143. ssb_write32(dev->dev->sdev, SSB_IMCFGLO, tmp);
  4144. ssb_commit_settings(bus);
  4145. }
  4146. }
  4147. static void b43_set_synth_pu_delay(struct b43_wldev *dev, bool idle)
  4148. {
  4149. u16 pu_delay;
  4150. /* The time value is in microseconds. */
  4151. pu_delay = 1050;
  4152. if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC) || idle)
  4153. pu_delay = 500;
  4154. if ((dev->phy.radio_ver == 0x2050) && (dev->phy.radio_rev == 8))
  4155. pu_delay = max(pu_delay, (u16)2400);
  4156. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_SPUWKUP, pu_delay);
  4157. }
  4158. /* Set the TSF CFP pre-TargetBeaconTransmissionTime. */
  4159. static void b43_set_pretbtt(struct b43_wldev *dev)
  4160. {
  4161. u16 pretbtt;
  4162. /* The time value is in microseconds. */
  4163. if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC))
  4164. pretbtt = 2;
  4165. else
  4166. pretbtt = 250;
  4167. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRETBTT, pretbtt);
  4168. b43_write16(dev, B43_MMIO_TSF_CFP_PRETBTT, pretbtt);
  4169. }
  4170. /* Shutdown a wireless core */
  4171. /* Locking: wl->mutex */
  4172. static void b43_wireless_core_exit(struct b43_wldev *dev)
  4173. {
  4174. B43_WARN_ON(dev && b43_status(dev) > B43_STAT_INITIALIZED);
  4175. if (!dev || b43_status(dev) != B43_STAT_INITIALIZED)
  4176. return;
  4177. b43_set_status(dev, B43_STAT_UNINIT);
  4178. /* Stop the microcode PSM. */
  4179. b43_maskset32(dev, B43_MMIO_MACCTL, ~B43_MACCTL_PSM_RUN,
  4180. B43_MACCTL_PSM_JMP0);
  4181. switch (dev->dev->bus_type) {
  4182. #ifdef CONFIG_B43_BCMA
  4183. case B43_BUS_BCMA:
  4184. bcma_host_pci_down(dev->dev->bdev->bus);
  4185. break;
  4186. #endif
  4187. #ifdef CONFIG_B43_SSB
  4188. case B43_BUS_SSB:
  4189. /* TODO */
  4190. break;
  4191. #endif
  4192. }
  4193. b43_dma_free(dev);
  4194. b43_pio_free(dev);
  4195. b43_chip_exit(dev);
  4196. dev->phy.ops->switch_analog(dev, 0);
  4197. if (dev->wl->current_beacon) {
  4198. dev_kfree_skb_any(dev->wl->current_beacon);
  4199. dev->wl->current_beacon = NULL;
  4200. }
  4201. b43_device_disable(dev, 0);
  4202. b43_bus_may_powerdown(dev);
  4203. }
  4204. /* Initialize a wireless core */
  4205. static int b43_wireless_core_init(struct b43_wldev *dev)
  4206. {
  4207. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  4208. struct b43_phy *phy = &dev->phy;
  4209. int err;
  4210. u64 hf;
  4211. B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
  4212. err = b43_bus_powerup(dev, 0);
  4213. if (err)
  4214. goto out;
  4215. if (!b43_device_is_enabled(dev))
  4216. b43_wireless_core_reset(dev, phy->gmode);
  4217. /* Reset all data structures. */
  4218. setup_struct_wldev_for_init(dev);
  4219. phy->ops->prepare_structs(dev);
  4220. /* Enable IRQ routing to this device. */
  4221. switch (dev->dev->bus_type) {
  4222. #ifdef CONFIG_B43_BCMA
  4223. case B43_BUS_BCMA:
  4224. bcma_host_pci_irq_ctl(dev->dev->bdev->bus,
  4225. dev->dev->bdev, true);
  4226. bcma_host_pci_up(dev->dev->bdev->bus);
  4227. break;
  4228. #endif
  4229. #ifdef CONFIG_B43_SSB
  4230. case B43_BUS_SSB:
  4231. ssb_pcicore_dev_irqvecs_enable(&dev->dev->sdev->bus->pcicore,
  4232. dev->dev->sdev);
  4233. break;
  4234. #endif
  4235. }
  4236. b43_imcfglo_timeouts_workaround(dev);
  4237. b43_bluetooth_coext_disable(dev);
  4238. if (phy->ops->prepare_hardware) {
  4239. err = phy->ops->prepare_hardware(dev);
  4240. if (err)
  4241. goto err_busdown;
  4242. }
  4243. err = b43_chip_init(dev);
  4244. if (err)
  4245. goto err_busdown;
  4246. b43_shm_write16(dev, B43_SHM_SHARED,
  4247. B43_SHM_SH_WLCOREREV, dev->dev->core_rev);
  4248. hf = b43_hf_read(dev);
  4249. if (phy->type == B43_PHYTYPE_G) {
  4250. hf |= B43_HF_SYMW;
  4251. if (phy->rev == 1)
  4252. hf |= B43_HF_GDCW;
  4253. if (sprom->boardflags_lo & B43_BFL_PACTRL)
  4254. hf |= B43_HF_OFDMPABOOST;
  4255. }
  4256. if (phy->radio_ver == 0x2050) {
  4257. if (phy->radio_rev == 6)
  4258. hf |= B43_HF_4318TSSI;
  4259. if (phy->radio_rev < 6)
  4260. hf |= B43_HF_VCORECALC;
  4261. }
  4262. if (sprom->boardflags_lo & B43_BFL_XTAL_NOSLOW)
  4263. hf |= B43_HF_DSCRQ; /* Disable slowclock requests from ucode. */
  4264. #if defined(CONFIG_B43_SSB) && defined(CONFIG_SSB_DRIVER_PCICORE)
  4265. if (dev->dev->bus_type == B43_BUS_SSB &&
  4266. dev->dev->sdev->bus->bustype == SSB_BUSTYPE_PCI &&
  4267. dev->dev->sdev->bus->pcicore.dev->id.revision <= 10)
  4268. hf |= B43_HF_PCISCW; /* PCI slow clock workaround. */
  4269. #endif
  4270. hf &= ~B43_HF_SKCFPUP;
  4271. b43_hf_write(dev, hf);
  4272. /* tell the ucode MAC capabilities */
  4273. if (dev->dev->core_rev >= 13) {
  4274. u32 mac_hw_cap = b43_read32(dev, B43_MMIO_MAC_HW_CAP);
  4275. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_MACHW_L,
  4276. mac_hw_cap & 0xffff);
  4277. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_MACHW_H,
  4278. (mac_hw_cap >> 16) & 0xffff);
  4279. }
  4280. b43_set_retry_limits(dev, B43_DEFAULT_SHORT_RETRY_LIMIT,
  4281. B43_DEFAULT_LONG_RETRY_LIMIT);
  4282. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_SFFBLIM, 3);
  4283. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_LFFBLIM, 2);
  4284. /* Disable sending probe responses from firmware.
  4285. * Setting the MaxTime to one usec will always trigger
  4286. * a timeout, so we never send any probe resp.
  4287. * A timeout of zero is infinite. */
  4288. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRMAXTIME, 1);
  4289. b43_rate_memory_init(dev);
  4290. b43_set_phytxctl_defaults(dev);
  4291. /* Minimum Contention Window */
  4292. if (phy->type == B43_PHYTYPE_B)
  4293. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MINCONT, 0x1F);
  4294. else
  4295. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MINCONT, 0xF);
  4296. /* Maximum Contention Window */
  4297. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MAXCONT, 0x3FF);
  4298. /* write phytype and phyvers */
  4299. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PHYTYPE, phy->type);
  4300. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PHYVER, phy->rev);
  4301. if (b43_bus_host_is_pcmcia(dev->dev) ||
  4302. b43_bus_host_is_sdio(dev->dev)) {
  4303. dev->__using_pio_transfers = true;
  4304. err = b43_pio_init(dev);
  4305. } else if (dev->use_pio) {
  4306. b43warn(dev->wl, "Forced PIO by use_pio module parameter. "
  4307. "This should not be needed and will result in lower "
  4308. "performance.\n");
  4309. dev->__using_pio_transfers = true;
  4310. err = b43_pio_init(dev);
  4311. } else {
  4312. dev->__using_pio_transfers = false;
  4313. err = b43_dma_init(dev);
  4314. }
  4315. if (err)
  4316. goto err_chip_exit;
  4317. b43_qos_init(dev);
  4318. b43_set_synth_pu_delay(dev, 1);
  4319. b43_bluetooth_coext_enable(dev);
  4320. b43_bus_powerup(dev, !(sprom->boardflags_lo & B43_BFL_XTAL_NOSLOW));
  4321. b43_upload_card_macaddress(dev);
  4322. b43_security_init(dev);
  4323. ieee80211_wake_queues(dev->wl->hw);
  4324. b43_set_status(dev, B43_STAT_INITIALIZED);
  4325. out:
  4326. return err;
  4327. err_chip_exit:
  4328. b43_chip_exit(dev);
  4329. err_busdown:
  4330. b43_bus_may_powerdown(dev);
  4331. B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
  4332. return err;
  4333. }
  4334. static int b43_op_add_interface(struct ieee80211_hw *hw,
  4335. struct ieee80211_vif *vif)
  4336. {
  4337. struct b43_wl *wl = hw_to_b43_wl(hw);
  4338. struct b43_wldev *dev;
  4339. int err = -EOPNOTSUPP;
  4340. /* TODO: allow WDS/AP devices to coexist */
  4341. if (vif->type != NL80211_IFTYPE_AP &&
  4342. vif->type != NL80211_IFTYPE_MESH_POINT &&
  4343. vif->type != NL80211_IFTYPE_STATION &&
  4344. vif->type != NL80211_IFTYPE_WDS &&
  4345. vif->type != NL80211_IFTYPE_ADHOC)
  4346. return -EOPNOTSUPP;
  4347. mutex_lock(&wl->mutex);
  4348. if (wl->operating)
  4349. goto out_mutex_unlock;
  4350. b43dbg(wl, "Adding Interface type %d\n", vif->type);
  4351. dev = wl->current_dev;
  4352. wl->operating = true;
  4353. wl->vif = vif;
  4354. wl->if_type = vif->type;
  4355. memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
  4356. b43_adjust_opmode(dev);
  4357. b43_set_pretbtt(dev);
  4358. b43_set_synth_pu_delay(dev, 0);
  4359. b43_upload_card_macaddress(dev);
  4360. err = 0;
  4361. out_mutex_unlock:
  4362. mutex_unlock(&wl->mutex);
  4363. if (err == 0)
  4364. b43_op_bss_info_changed(hw, vif, &vif->bss_conf, ~0);
  4365. return err;
  4366. }
  4367. static void b43_op_remove_interface(struct ieee80211_hw *hw,
  4368. struct ieee80211_vif *vif)
  4369. {
  4370. struct b43_wl *wl = hw_to_b43_wl(hw);
  4371. struct b43_wldev *dev = wl->current_dev;
  4372. b43dbg(wl, "Removing Interface type %d\n", vif->type);
  4373. mutex_lock(&wl->mutex);
  4374. B43_WARN_ON(!wl->operating);
  4375. B43_WARN_ON(wl->vif != vif);
  4376. wl->vif = NULL;
  4377. wl->operating = false;
  4378. b43_adjust_opmode(dev);
  4379. eth_zero_addr(wl->mac_addr);
  4380. b43_upload_card_macaddress(dev);
  4381. mutex_unlock(&wl->mutex);
  4382. }
  4383. static int b43_op_start(struct ieee80211_hw *hw)
  4384. {
  4385. struct b43_wl *wl = hw_to_b43_wl(hw);
  4386. struct b43_wldev *dev = wl->current_dev;
  4387. int did_init = 0;
  4388. int err = 0;
  4389. /* Kill all old instance specific information to make sure
  4390. * the card won't use it in the short timeframe between start
  4391. * and mac80211 reconfiguring it. */
  4392. eth_zero_addr(wl->bssid);
  4393. eth_zero_addr(wl->mac_addr);
  4394. wl->filter_flags = 0;
  4395. wl->radiotap_enabled = false;
  4396. b43_qos_clear(wl);
  4397. wl->beacon0_uploaded = false;
  4398. wl->beacon1_uploaded = false;
  4399. wl->beacon_templates_virgin = true;
  4400. wl->radio_enabled = true;
  4401. mutex_lock(&wl->mutex);
  4402. if (b43_status(dev) < B43_STAT_INITIALIZED) {
  4403. err = b43_wireless_core_init(dev);
  4404. if (err)
  4405. goto out_mutex_unlock;
  4406. did_init = 1;
  4407. }
  4408. if (b43_status(dev) < B43_STAT_STARTED) {
  4409. err = b43_wireless_core_start(dev);
  4410. if (err) {
  4411. if (did_init)
  4412. b43_wireless_core_exit(dev);
  4413. goto out_mutex_unlock;
  4414. }
  4415. }
  4416. /* XXX: only do if device doesn't support rfkill irq */
  4417. wiphy_rfkill_start_polling(hw->wiphy);
  4418. out_mutex_unlock:
  4419. mutex_unlock(&wl->mutex);
  4420. /*
  4421. * Configuration may have been overwritten during initialization.
  4422. * Reload the configuration, but only if initialization was
  4423. * successful. Reloading the configuration after a failed init
  4424. * may hang the system.
  4425. */
  4426. if (!err)
  4427. b43_op_config(hw, ~0);
  4428. return err;
  4429. }
  4430. static void b43_op_stop(struct ieee80211_hw *hw)
  4431. {
  4432. struct b43_wl *wl = hw_to_b43_wl(hw);
  4433. struct b43_wldev *dev = wl->current_dev;
  4434. cancel_work_sync(&(wl->beacon_update_trigger));
  4435. if (!dev)
  4436. goto out;
  4437. mutex_lock(&wl->mutex);
  4438. if (b43_status(dev) >= B43_STAT_STARTED) {
  4439. dev = b43_wireless_core_stop(dev);
  4440. if (!dev)
  4441. goto out_unlock;
  4442. }
  4443. b43_wireless_core_exit(dev);
  4444. wl->radio_enabled = false;
  4445. out_unlock:
  4446. mutex_unlock(&wl->mutex);
  4447. out:
  4448. cancel_work_sync(&(wl->txpower_adjust_work));
  4449. }
  4450. static int b43_op_beacon_set_tim(struct ieee80211_hw *hw,
  4451. struct ieee80211_sta *sta, bool set)
  4452. {
  4453. struct b43_wl *wl = hw_to_b43_wl(hw);
  4454. b43_update_templates(wl);
  4455. return 0;
  4456. }
  4457. static void b43_op_sta_notify(struct ieee80211_hw *hw,
  4458. struct ieee80211_vif *vif,
  4459. enum sta_notify_cmd notify_cmd,
  4460. struct ieee80211_sta *sta)
  4461. {
  4462. struct b43_wl *wl = hw_to_b43_wl(hw);
  4463. B43_WARN_ON(!vif || wl->vif != vif);
  4464. }
  4465. static void b43_op_sw_scan_start_notifier(struct ieee80211_hw *hw,
  4466. struct ieee80211_vif *vif,
  4467. const u8 *mac_addr)
  4468. {
  4469. struct b43_wl *wl = hw_to_b43_wl(hw);
  4470. struct b43_wldev *dev;
  4471. mutex_lock(&wl->mutex);
  4472. dev = wl->current_dev;
  4473. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED)) {
  4474. /* Disable CFP update during scan on other channels. */
  4475. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_SKCFPUP);
  4476. }
  4477. mutex_unlock(&wl->mutex);
  4478. }
  4479. static void b43_op_sw_scan_complete_notifier(struct ieee80211_hw *hw,
  4480. struct ieee80211_vif *vif)
  4481. {
  4482. struct b43_wl *wl = hw_to_b43_wl(hw);
  4483. struct b43_wldev *dev;
  4484. mutex_lock(&wl->mutex);
  4485. dev = wl->current_dev;
  4486. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED)) {
  4487. /* Re-enable CFP update. */
  4488. b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_SKCFPUP);
  4489. }
  4490. mutex_unlock(&wl->mutex);
  4491. }
  4492. static int b43_op_get_survey(struct ieee80211_hw *hw, int idx,
  4493. struct survey_info *survey)
  4494. {
  4495. struct b43_wl *wl = hw_to_b43_wl(hw);
  4496. struct b43_wldev *dev = wl->current_dev;
  4497. struct ieee80211_conf *conf = &hw->conf;
  4498. if (idx != 0)
  4499. return -ENOENT;
  4500. survey->channel = conf->chandef.chan;
  4501. survey->filled = SURVEY_INFO_NOISE_DBM;
  4502. survey->noise = dev->stats.link_noise;
  4503. return 0;
  4504. }
  4505. static const struct ieee80211_ops b43_hw_ops = {
  4506. .tx = b43_op_tx,
  4507. .conf_tx = b43_op_conf_tx,
  4508. .add_interface = b43_op_add_interface,
  4509. .remove_interface = b43_op_remove_interface,
  4510. .config = b43_op_config,
  4511. .bss_info_changed = b43_op_bss_info_changed,
  4512. .configure_filter = b43_op_configure_filter,
  4513. .set_key = b43_op_set_key,
  4514. .update_tkip_key = b43_op_update_tkip_key,
  4515. .get_stats = b43_op_get_stats,
  4516. .get_tsf = b43_op_get_tsf,
  4517. .set_tsf = b43_op_set_tsf,
  4518. .start = b43_op_start,
  4519. .stop = b43_op_stop,
  4520. .set_tim = b43_op_beacon_set_tim,
  4521. .sta_notify = b43_op_sta_notify,
  4522. .sw_scan_start = b43_op_sw_scan_start_notifier,
  4523. .sw_scan_complete = b43_op_sw_scan_complete_notifier,
  4524. .get_survey = b43_op_get_survey,
  4525. .rfkill_poll = b43_rfkill_poll,
  4526. };
  4527. /* Hard-reset the chip. Do not call this directly.
  4528. * Use b43_controller_restart()
  4529. */
  4530. static void b43_chip_reset(struct work_struct *work)
  4531. {
  4532. struct b43_wldev *dev =
  4533. container_of(work, struct b43_wldev, restart_work);
  4534. struct b43_wl *wl = dev->wl;
  4535. int err = 0;
  4536. int prev_status;
  4537. mutex_lock(&wl->mutex);
  4538. prev_status = b43_status(dev);
  4539. /* Bring the device down... */
  4540. if (prev_status >= B43_STAT_STARTED) {
  4541. dev = b43_wireless_core_stop(dev);
  4542. if (!dev) {
  4543. err = -ENODEV;
  4544. goto out;
  4545. }
  4546. }
  4547. if (prev_status >= B43_STAT_INITIALIZED)
  4548. b43_wireless_core_exit(dev);
  4549. /* ...and up again. */
  4550. if (prev_status >= B43_STAT_INITIALIZED) {
  4551. err = b43_wireless_core_init(dev);
  4552. if (err)
  4553. goto out;
  4554. }
  4555. if (prev_status >= B43_STAT_STARTED) {
  4556. err = b43_wireless_core_start(dev);
  4557. if (err) {
  4558. b43_wireless_core_exit(dev);
  4559. goto out;
  4560. }
  4561. }
  4562. out:
  4563. if (err)
  4564. wl->current_dev = NULL; /* Failed to init the dev. */
  4565. mutex_unlock(&wl->mutex);
  4566. if (err) {
  4567. b43err(wl, "Controller restart FAILED\n");
  4568. return;
  4569. }
  4570. /* reload configuration */
  4571. b43_op_config(wl->hw, ~0);
  4572. if (wl->vif)
  4573. b43_op_bss_info_changed(wl->hw, wl->vif, &wl->vif->bss_conf, ~0);
  4574. b43info(wl, "Controller restarted\n");
  4575. }
  4576. static int b43_setup_bands(struct b43_wldev *dev,
  4577. bool have_2ghz_phy, bool have_5ghz_phy)
  4578. {
  4579. struct ieee80211_hw *hw = dev->wl->hw;
  4580. struct b43_phy *phy = &dev->phy;
  4581. bool limited_2g;
  4582. bool limited_5g;
  4583. /* We don't support all 2 GHz channels on some devices */
  4584. limited_2g = phy->radio_ver == 0x2057 &&
  4585. (phy->radio_rev == 9 || phy->radio_rev == 14);
  4586. limited_5g = phy->radio_ver == 0x2057 &&
  4587. phy->radio_rev == 9;
  4588. if (have_2ghz_phy)
  4589. hw->wiphy->bands[NL80211_BAND_2GHZ] = limited_2g ?
  4590. &b43_band_2ghz_limited : &b43_band_2GHz;
  4591. if (dev->phy.type == B43_PHYTYPE_N) {
  4592. if (have_5ghz_phy)
  4593. hw->wiphy->bands[NL80211_BAND_5GHZ] = limited_5g ?
  4594. &b43_band_5GHz_nphy_limited :
  4595. &b43_band_5GHz_nphy;
  4596. } else {
  4597. if (have_5ghz_phy)
  4598. hw->wiphy->bands[NL80211_BAND_5GHZ] = &b43_band_5GHz_aphy;
  4599. }
  4600. dev->phy.supports_2ghz = have_2ghz_phy;
  4601. dev->phy.supports_5ghz = have_5ghz_phy;
  4602. return 0;
  4603. }
  4604. static void b43_wireless_core_detach(struct b43_wldev *dev)
  4605. {
  4606. /* We release firmware that late to not be required to re-request
  4607. * is all the time when we reinit the core. */
  4608. b43_release_firmware(dev);
  4609. b43_phy_free(dev);
  4610. }
  4611. static void b43_supported_bands(struct b43_wldev *dev, bool *have_2ghz_phy,
  4612. bool *have_5ghz_phy)
  4613. {
  4614. u16 dev_id = 0;
  4615. #ifdef CONFIG_B43_BCMA
  4616. if (dev->dev->bus_type == B43_BUS_BCMA &&
  4617. dev->dev->bdev->bus->hosttype == BCMA_HOSTTYPE_PCI)
  4618. dev_id = dev->dev->bdev->bus->host_pci->device;
  4619. #endif
  4620. #ifdef CONFIG_B43_SSB
  4621. if (dev->dev->bus_type == B43_BUS_SSB &&
  4622. dev->dev->sdev->bus->bustype == SSB_BUSTYPE_PCI)
  4623. dev_id = dev->dev->sdev->bus->host_pci->device;
  4624. #endif
  4625. /* Override with SPROM value if available */
  4626. if (dev->dev->bus_sprom->dev_id)
  4627. dev_id = dev->dev->bus_sprom->dev_id;
  4628. /* Note: below IDs can be "virtual" (not maching e.g. real PCI ID) */
  4629. switch (dev_id) {
  4630. case 0x4324: /* BCM4306 */
  4631. case 0x4312: /* BCM4311 */
  4632. case 0x4319: /* BCM4318 */
  4633. case 0x4328: /* BCM4321 */
  4634. case 0x432b: /* BCM4322 */
  4635. case 0x4350: /* BCM43222 */
  4636. case 0x4353: /* BCM43224 */
  4637. case 0x0576: /* BCM43224 */
  4638. case 0x435f: /* BCM6362 */
  4639. case 0x4331: /* BCM4331 */
  4640. case 0x4359: /* BCM43228 */
  4641. case 0x43a0: /* BCM4360 */
  4642. case 0x43b1: /* BCM4352 */
  4643. /* Dual band devices */
  4644. *have_2ghz_phy = true;
  4645. *have_5ghz_phy = true;
  4646. return;
  4647. case 0x4321: /* BCM4306 */
  4648. /* There are 14e4:4321 PCI devs with 2.4 GHz BCM4321 (N-PHY) */
  4649. if (dev->phy.type != B43_PHYTYPE_G)
  4650. break;
  4651. /* fall through */
  4652. case 0x4313: /* BCM4311 */
  4653. case 0x431a: /* BCM4318 */
  4654. case 0x432a: /* BCM4321 */
  4655. case 0x432d: /* BCM4322 */
  4656. case 0x4352: /* BCM43222 */
  4657. case 0x435a: /* BCM43228 */
  4658. case 0x4333: /* BCM4331 */
  4659. case 0x43a2: /* BCM4360 */
  4660. case 0x43b3: /* BCM4352 */
  4661. /* 5 GHz only devices */
  4662. *have_2ghz_phy = false;
  4663. *have_5ghz_phy = true;
  4664. return;
  4665. }
  4666. /* As a fallback, try to guess using PHY type */
  4667. switch (dev->phy.type) {
  4668. case B43_PHYTYPE_G:
  4669. case B43_PHYTYPE_N:
  4670. case B43_PHYTYPE_LP:
  4671. case B43_PHYTYPE_HT:
  4672. case B43_PHYTYPE_LCN:
  4673. *have_2ghz_phy = true;
  4674. *have_5ghz_phy = false;
  4675. return;
  4676. }
  4677. B43_WARN_ON(1);
  4678. }
  4679. static int b43_wireless_core_attach(struct b43_wldev *dev)
  4680. {
  4681. struct b43_wl *wl = dev->wl;
  4682. struct b43_phy *phy = &dev->phy;
  4683. int err;
  4684. u32 tmp;
  4685. bool have_2ghz_phy = false, have_5ghz_phy = false;
  4686. /* Do NOT do any device initialization here.
  4687. * Do it in wireless_core_init() instead.
  4688. * This function is for gathering basic information about the HW, only.
  4689. * Also some structs may be set up here. But most likely you want to have
  4690. * that in core_init(), too.
  4691. */
  4692. err = b43_bus_powerup(dev, 0);
  4693. if (err) {
  4694. b43err(wl, "Bus powerup failed\n");
  4695. goto out;
  4696. }
  4697. phy->do_full_init = true;
  4698. /* Try to guess supported bands for the first init needs */
  4699. switch (dev->dev->bus_type) {
  4700. #ifdef CONFIG_B43_BCMA
  4701. case B43_BUS_BCMA:
  4702. tmp = bcma_aread32(dev->dev->bdev, BCMA_IOST);
  4703. have_2ghz_phy = !!(tmp & B43_BCMA_IOST_2G_PHY);
  4704. have_5ghz_phy = !!(tmp & B43_BCMA_IOST_5G_PHY);
  4705. break;
  4706. #endif
  4707. #ifdef CONFIG_B43_SSB
  4708. case B43_BUS_SSB:
  4709. if (dev->dev->core_rev >= 5) {
  4710. tmp = ssb_read32(dev->dev->sdev, SSB_TMSHIGH);
  4711. have_2ghz_phy = !!(tmp & B43_TMSHIGH_HAVE_2GHZ_PHY);
  4712. have_5ghz_phy = !!(tmp & B43_TMSHIGH_HAVE_5GHZ_PHY);
  4713. } else
  4714. B43_WARN_ON(1);
  4715. break;
  4716. #endif
  4717. }
  4718. dev->phy.gmode = have_2ghz_phy;
  4719. b43_wireless_core_reset(dev, dev->phy.gmode);
  4720. /* Get the PHY type. */
  4721. err = b43_phy_versioning(dev);
  4722. if (err)
  4723. goto err_powerdown;
  4724. /* Get real info about supported bands */
  4725. b43_supported_bands(dev, &have_2ghz_phy, &have_5ghz_phy);
  4726. /* We don't support 5 GHz on some PHYs yet */
  4727. if (have_5ghz_phy) {
  4728. switch (dev->phy.type) {
  4729. case B43_PHYTYPE_G:
  4730. case B43_PHYTYPE_LP:
  4731. case B43_PHYTYPE_HT:
  4732. b43warn(wl, "5 GHz band is unsupported on this PHY\n");
  4733. have_5ghz_phy = false;
  4734. }
  4735. }
  4736. if (!have_2ghz_phy && !have_5ghz_phy) {
  4737. b43err(wl, "b43 can't support any band on this device\n");
  4738. err = -EOPNOTSUPP;
  4739. goto err_powerdown;
  4740. }
  4741. err = b43_phy_allocate(dev);
  4742. if (err)
  4743. goto err_powerdown;
  4744. dev->phy.gmode = have_2ghz_phy;
  4745. b43_wireless_core_reset(dev, dev->phy.gmode);
  4746. err = b43_validate_chipaccess(dev);
  4747. if (err)
  4748. goto err_phy_free;
  4749. err = b43_setup_bands(dev, have_2ghz_phy, have_5ghz_phy);
  4750. if (err)
  4751. goto err_phy_free;
  4752. /* Now set some default "current_dev" */
  4753. if (!wl->current_dev)
  4754. wl->current_dev = dev;
  4755. INIT_WORK(&dev->restart_work, b43_chip_reset);
  4756. dev->phy.ops->switch_analog(dev, 0);
  4757. b43_device_disable(dev, 0);
  4758. b43_bus_may_powerdown(dev);
  4759. out:
  4760. return err;
  4761. err_phy_free:
  4762. b43_phy_free(dev);
  4763. err_powerdown:
  4764. b43_bus_may_powerdown(dev);
  4765. return err;
  4766. }
  4767. static void b43_one_core_detach(struct b43_bus_dev *dev)
  4768. {
  4769. struct b43_wldev *wldev;
  4770. struct b43_wl *wl;
  4771. /* Do not cancel ieee80211-workqueue based work here.
  4772. * See comment in b43_remove(). */
  4773. wldev = b43_bus_get_wldev(dev);
  4774. wl = wldev->wl;
  4775. b43_debugfs_remove_device(wldev);
  4776. b43_wireless_core_detach(wldev);
  4777. list_del(&wldev->list);
  4778. b43_bus_set_wldev(dev, NULL);
  4779. kfree(wldev);
  4780. }
  4781. static int b43_one_core_attach(struct b43_bus_dev *dev, struct b43_wl *wl)
  4782. {
  4783. struct b43_wldev *wldev;
  4784. int err = -ENOMEM;
  4785. wldev = kzalloc(sizeof(*wldev), GFP_KERNEL);
  4786. if (!wldev)
  4787. goto out;
  4788. wldev->use_pio = b43_modparam_pio;
  4789. wldev->dev = dev;
  4790. wldev->wl = wl;
  4791. b43_set_status(wldev, B43_STAT_UNINIT);
  4792. wldev->bad_frames_preempt = modparam_bad_frames_preempt;
  4793. INIT_LIST_HEAD(&wldev->list);
  4794. err = b43_wireless_core_attach(wldev);
  4795. if (err)
  4796. goto err_kfree_wldev;
  4797. b43_bus_set_wldev(dev, wldev);
  4798. b43_debugfs_add_device(wldev);
  4799. out:
  4800. return err;
  4801. err_kfree_wldev:
  4802. kfree(wldev);
  4803. return err;
  4804. }
  4805. #define IS_PDEV(pdev, _vendor, _device, _subvendor, _subdevice) ( \
  4806. (pdev->vendor == PCI_VENDOR_ID_##_vendor) && \
  4807. (pdev->device == _device) && \
  4808. (pdev->subsystem_vendor == PCI_VENDOR_ID_##_subvendor) && \
  4809. (pdev->subsystem_device == _subdevice) )
  4810. #ifdef CONFIG_B43_SSB
  4811. static void b43_sprom_fixup(struct ssb_bus *bus)
  4812. {
  4813. struct pci_dev *pdev;
  4814. /* boardflags workarounds */
  4815. if (bus->boardinfo.vendor == SSB_BOARDVENDOR_DELL &&
  4816. bus->chip_id == 0x4301 && bus->sprom.board_rev == 0x74)
  4817. bus->sprom.boardflags_lo |= B43_BFL_BTCOEXIST;
  4818. if (bus->boardinfo.vendor == PCI_VENDOR_ID_APPLE &&
  4819. bus->boardinfo.type == 0x4E && bus->sprom.board_rev > 0x40)
  4820. bus->sprom.boardflags_lo |= B43_BFL_PACTRL;
  4821. if (bus->bustype == SSB_BUSTYPE_PCI) {
  4822. pdev = bus->host_pci;
  4823. if (IS_PDEV(pdev, BROADCOM, 0x4318, ASUSTEK, 0x100F) ||
  4824. IS_PDEV(pdev, BROADCOM, 0x4320, DELL, 0x0003) ||
  4825. IS_PDEV(pdev, BROADCOM, 0x4320, HP, 0x12f8) ||
  4826. IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0015) ||
  4827. IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0014) ||
  4828. IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0013) ||
  4829. IS_PDEV(pdev, BROADCOM, 0x4320, MOTOROLA, 0x7010))
  4830. bus->sprom.boardflags_lo &= ~B43_BFL_BTCOEXIST;
  4831. }
  4832. }
  4833. static void b43_wireless_exit(struct b43_bus_dev *dev, struct b43_wl *wl)
  4834. {
  4835. struct ieee80211_hw *hw = wl->hw;
  4836. ssb_set_devtypedata(dev->sdev, NULL);
  4837. ieee80211_free_hw(hw);
  4838. }
  4839. #endif
  4840. static struct b43_wl *b43_wireless_init(struct b43_bus_dev *dev)
  4841. {
  4842. struct ssb_sprom *sprom = dev->bus_sprom;
  4843. struct ieee80211_hw *hw;
  4844. struct b43_wl *wl;
  4845. char chip_name[6];
  4846. int queue_num;
  4847. hw = ieee80211_alloc_hw(sizeof(*wl), &b43_hw_ops);
  4848. if (!hw) {
  4849. b43err(NULL, "Could not allocate ieee80211 device\n");
  4850. return ERR_PTR(-ENOMEM);
  4851. }
  4852. wl = hw_to_b43_wl(hw);
  4853. /* fill hw info */
  4854. ieee80211_hw_set(hw, RX_INCLUDES_FCS);
  4855. ieee80211_hw_set(hw, SIGNAL_DBM);
  4856. hw->wiphy->interface_modes =
  4857. BIT(NL80211_IFTYPE_AP) |
  4858. BIT(NL80211_IFTYPE_MESH_POINT) |
  4859. BIT(NL80211_IFTYPE_STATION) |
  4860. #ifdef CONFIG_WIRELESS_WDS
  4861. BIT(NL80211_IFTYPE_WDS) |
  4862. #endif
  4863. BIT(NL80211_IFTYPE_ADHOC);
  4864. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  4865. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
  4866. wl->hw_registred = false;
  4867. hw->max_rates = 2;
  4868. SET_IEEE80211_DEV(hw, dev->dev);
  4869. if (is_valid_ether_addr(sprom->et1mac))
  4870. SET_IEEE80211_PERM_ADDR(hw, sprom->et1mac);
  4871. else
  4872. SET_IEEE80211_PERM_ADDR(hw, sprom->il0mac);
  4873. /* Initialize struct b43_wl */
  4874. wl->hw = hw;
  4875. mutex_init(&wl->mutex);
  4876. spin_lock_init(&wl->hardirq_lock);
  4877. spin_lock_init(&wl->beacon_lock);
  4878. INIT_WORK(&wl->beacon_update_trigger, b43_beacon_update_trigger_work);
  4879. INIT_WORK(&wl->txpower_adjust_work, b43_phy_txpower_adjust_work);
  4880. INIT_WORK(&wl->tx_work, b43_tx_work);
  4881. /* Initialize queues and flags. */
  4882. for (queue_num = 0; queue_num < B43_QOS_QUEUE_NUM; queue_num++) {
  4883. skb_queue_head_init(&wl->tx_queue[queue_num]);
  4884. wl->tx_queue_stopped[queue_num] = 0;
  4885. }
  4886. snprintf(chip_name, ARRAY_SIZE(chip_name),
  4887. (dev->chip_id > 0x9999) ? "%d" : "%04X", dev->chip_id);
  4888. b43info(wl, "Broadcom %s WLAN found (core revision %u)\n", chip_name,
  4889. dev->core_rev);
  4890. return wl;
  4891. }
  4892. #ifdef CONFIG_B43_BCMA
  4893. static int b43_bcma_probe(struct bcma_device *core)
  4894. {
  4895. struct b43_bus_dev *dev;
  4896. struct b43_wl *wl;
  4897. int err;
  4898. if (!modparam_allhwsupport &&
  4899. (core->id.rev == 0x17 || core->id.rev == 0x18)) {
  4900. pr_err("Support for cores revisions 0x17 and 0x18 disabled by module param allhwsupport=0. Try b43.allhwsupport=1\n");
  4901. return -ENOTSUPP;
  4902. }
  4903. dev = b43_bus_dev_bcma_init(core);
  4904. if (!dev)
  4905. return -ENODEV;
  4906. wl = b43_wireless_init(dev);
  4907. if (IS_ERR(wl)) {
  4908. err = PTR_ERR(wl);
  4909. goto bcma_out;
  4910. }
  4911. err = b43_one_core_attach(dev, wl);
  4912. if (err)
  4913. goto bcma_err_wireless_exit;
  4914. /* setup and start work to load firmware */
  4915. INIT_WORK(&wl->firmware_load, b43_request_firmware);
  4916. schedule_work(&wl->firmware_load);
  4917. return err;
  4918. bcma_err_wireless_exit:
  4919. ieee80211_free_hw(wl->hw);
  4920. bcma_out:
  4921. kfree(dev);
  4922. return err;
  4923. }
  4924. static void b43_bcma_remove(struct bcma_device *core)
  4925. {
  4926. struct b43_wldev *wldev = bcma_get_drvdata(core);
  4927. struct b43_wl *wl = wldev->wl;
  4928. /* We must cancel any work here before unregistering from ieee80211,
  4929. * as the ieee80211 unreg will destroy the workqueue. */
  4930. cancel_work_sync(&wldev->restart_work);
  4931. cancel_work_sync(&wl->firmware_load);
  4932. B43_WARN_ON(!wl);
  4933. if (!wldev->fw.ucode.data)
  4934. return; /* NULL if firmware never loaded */
  4935. if (wl->current_dev == wldev && wl->hw_registred) {
  4936. b43_leds_stop(wldev);
  4937. ieee80211_unregister_hw(wl->hw);
  4938. }
  4939. b43_one_core_detach(wldev->dev);
  4940. /* Unregister HW RNG driver */
  4941. b43_rng_exit(wl);
  4942. b43_leds_unregister(wl);
  4943. ieee80211_free_hw(wl->hw);
  4944. kfree(wldev->dev);
  4945. }
  4946. static struct bcma_driver b43_bcma_driver = {
  4947. .name = KBUILD_MODNAME,
  4948. .id_table = b43_bcma_tbl,
  4949. .probe = b43_bcma_probe,
  4950. .remove = b43_bcma_remove,
  4951. };
  4952. #endif
  4953. #ifdef CONFIG_B43_SSB
  4954. static
  4955. int b43_ssb_probe(struct ssb_device *sdev, const struct ssb_device_id *id)
  4956. {
  4957. struct b43_bus_dev *dev;
  4958. struct b43_wl *wl;
  4959. int err;
  4960. dev = b43_bus_dev_ssb_init(sdev);
  4961. if (!dev)
  4962. return -ENOMEM;
  4963. wl = ssb_get_devtypedata(sdev);
  4964. if (wl) {
  4965. b43err(NULL, "Dual-core devices are not supported\n");
  4966. err = -ENOTSUPP;
  4967. goto err_ssb_kfree_dev;
  4968. }
  4969. b43_sprom_fixup(sdev->bus);
  4970. wl = b43_wireless_init(dev);
  4971. if (IS_ERR(wl)) {
  4972. err = PTR_ERR(wl);
  4973. goto err_ssb_kfree_dev;
  4974. }
  4975. ssb_set_devtypedata(sdev, wl);
  4976. B43_WARN_ON(ssb_get_devtypedata(sdev) != wl);
  4977. err = b43_one_core_attach(dev, wl);
  4978. if (err)
  4979. goto err_ssb_wireless_exit;
  4980. /* setup and start work to load firmware */
  4981. INIT_WORK(&wl->firmware_load, b43_request_firmware);
  4982. schedule_work(&wl->firmware_load);
  4983. return err;
  4984. err_ssb_wireless_exit:
  4985. b43_wireless_exit(dev, wl);
  4986. err_ssb_kfree_dev:
  4987. kfree(dev);
  4988. return err;
  4989. }
  4990. static void b43_ssb_remove(struct ssb_device *sdev)
  4991. {
  4992. struct b43_wl *wl = ssb_get_devtypedata(sdev);
  4993. struct b43_wldev *wldev = ssb_get_drvdata(sdev);
  4994. struct b43_bus_dev *dev = wldev->dev;
  4995. /* We must cancel any work here before unregistering from ieee80211,
  4996. * as the ieee80211 unreg will destroy the workqueue. */
  4997. cancel_work_sync(&wldev->restart_work);
  4998. cancel_work_sync(&wl->firmware_load);
  4999. B43_WARN_ON(!wl);
  5000. if (!wldev->fw.ucode.data)
  5001. return; /* NULL if firmware never loaded */
  5002. if (wl->current_dev == wldev && wl->hw_registred) {
  5003. b43_leds_stop(wldev);
  5004. ieee80211_unregister_hw(wl->hw);
  5005. }
  5006. b43_one_core_detach(dev);
  5007. /* Unregister HW RNG driver */
  5008. b43_rng_exit(wl);
  5009. b43_leds_unregister(wl);
  5010. b43_wireless_exit(dev, wl);
  5011. kfree(dev);
  5012. }
  5013. static struct ssb_driver b43_ssb_driver = {
  5014. .name = KBUILD_MODNAME,
  5015. .id_table = b43_ssb_tbl,
  5016. .probe = b43_ssb_probe,
  5017. .remove = b43_ssb_remove,
  5018. };
  5019. #endif /* CONFIG_B43_SSB */
  5020. /* Perform a hardware reset. This can be called from any context. */
  5021. void b43_controller_restart(struct b43_wldev *dev, const char *reason)
  5022. {
  5023. /* Must avoid requeueing, if we are in shutdown. */
  5024. if (b43_status(dev) < B43_STAT_INITIALIZED)
  5025. return;
  5026. b43info(dev->wl, "Controller RESET (%s) ...\n", reason);
  5027. ieee80211_queue_work(dev->wl->hw, &dev->restart_work);
  5028. }
  5029. static void b43_print_driverinfo(void)
  5030. {
  5031. const char *feat_pci = "", *feat_pcmcia = "", *feat_nphy = "",
  5032. *feat_leds = "", *feat_sdio = "";
  5033. #ifdef CONFIG_B43_PCI_AUTOSELECT
  5034. feat_pci = "P";
  5035. #endif
  5036. #ifdef CONFIG_B43_PCMCIA
  5037. feat_pcmcia = "M";
  5038. #endif
  5039. #ifdef CONFIG_B43_PHY_N
  5040. feat_nphy = "N";
  5041. #endif
  5042. #ifdef CONFIG_B43_LEDS
  5043. feat_leds = "L";
  5044. #endif
  5045. #ifdef CONFIG_B43_SDIO
  5046. feat_sdio = "S";
  5047. #endif
  5048. printk(KERN_INFO "Broadcom 43xx driver loaded "
  5049. "[ Features: %s%s%s%s%s ]\n",
  5050. feat_pci, feat_pcmcia, feat_nphy,
  5051. feat_leds, feat_sdio);
  5052. }
  5053. static int __init b43_init(void)
  5054. {
  5055. int err;
  5056. b43_debugfs_init();
  5057. err = b43_sdio_init();
  5058. if (err)
  5059. goto err_dfs_exit;
  5060. #ifdef CONFIG_B43_BCMA
  5061. err = bcma_driver_register(&b43_bcma_driver);
  5062. if (err)
  5063. goto err_sdio_exit;
  5064. #endif
  5065. #ifdef CONFIG_B43_SSB
  5066. err = ssb_driver_register(&b43_ssb_driver);
  5067. if (err)
  5068. goto err_bcma_driver_exit;
  5069. #endif
  5070. b43_print_driverinfo();
  5071. return err;
  5072. #ifdef CONFIG_B43_SSB
  5073. err_bcma_driver_exit:
  5074. #endif
  5075. #ifdef CONFIG_B43_BCMA
  5076. bcma_driver_unregister(&b43_bcma_driver);
  5077. err_sdio_exit:
  5078. #endif
  5079. b43_sdio_exit();
  5080. err_dfs_exit:
  5081. b43_debugfs_exit();
  5082. return err;
  5083. }
  5084. static void __exit b43_exit(void)
  5085. {
  5086. #ifdef CONFIG_B43_SSB
  5087. ssb_driver_unregister(&b43_ssb_driver);
  5088. #endif
  5089. #ifdef CONFIG_B43_BCMA
  5090. bcma_driver_unregister(&b43_bcma_driver);
  5091. #endif
  5092. b43_sdio_exit();
  5093. b43_debugfs_exit();
  5094. }
  5095. module_init(b43_init)
  5096. module_exit(b43_exit)