mwl8k.c 149 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165
  1. /*
  2. * drivers/net/wireless/mwl8k.c
  3. * Driver for Marvell TOPDOG 802.11 Wireless cards
  4. *
  5. * Copyright (C) 2008, 2009, 2010 Marvell Semiconductor Inc.
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #include <linux/interrupt.h>
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/sched.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/list.h>
  17. #include <linux/pci.h>
  18. #include <linux/delay.h>
  19. #include <linux/completion.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/slab.h>
  22. #include <net/mac80211.h>
  23. #include <linux/moduleparam.h>
  24. #include <linux/firmware.h>
  25. #include <linux/workqueue.h>
  26. #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
  27. #define MWL8K_NAME KBUILD_MODNAME
  28. #define MWL8K_VERSION "0.13"
  29. /* Module parameters */
  30. static bool ap_mode_default;
  31. module_param(ap_mode_default, bool, 0);
  32. MODULE_PARM_DESC(ap_mode_default,
  33. "Set to 1 to make ap mode the default instead of sta mode");
  34. /* Register definitions */
  35. #define MWL8K_HIU_GEN_PTR 0x00000c10
  36. #define MWL8K_MODE_STA 0x0000005a
  37. #define MWL8K_MODE_AP 0x000000a5
  38. #define MWL8K_HIU_INT_CODE 0x00000c14
  39. #define MWL8K_FWSTA_READY 0xf0f1f2f4
  40. #define MWL8K_FWAP_READY 0xf1f2f4a5
  41. #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
  42. #define MWL8K_HIU_SCRATCH 0x00000c40
  43. /* Host->device communications */
  44. #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
  45. #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
  46. #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
  47. #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
  48. #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
  49. #define MWL8K_H2A_INT_DUMMY (1 << 20)
  50. #define MWL8K_H2A_INT_RESET (1 << 15)
  51. #define MWL8K_H2A_INT_DOORBELL (1 << 1)
  52. #define MWL8K_H2A_INT_PPA_READY (1 << 0)
  53. /* Device->host communications */
  54. #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
  55. #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
  56. #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
  57. #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
  58. #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
  59. #define MWL8K_A2H_INT_DUMMY (1 << 20)
  60. #define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14)
  61. #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
  62. #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
  63. #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
  64. #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
  65. #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
  66. #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
  67. #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
  68. #define MWL8K_A2H_INT_RX_READY (1 << 1)
  69. #define MWL8K_A2H_INT_TX_DONE (1 << 0)
  70. /* HW micro second timer register
  71. * located at offset 0xA600. This
  72. * will be used to timestamp tx
  73. * packets.
  74. */
  75. #define MWL8K_HW_TIMER_REGISTER 0x0000a600
  76. #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
  77. MWL8K_A2H_INT_CHNL_SWITCHED | \
  78. MWL8K_A2H_INT_QUEUE_EMPTY | \
  79. MWL8K_A2H_INT_RADAR_DETECT | \
  80. MWL8K_A2H_INT_RADIO_ON | \
  81. MWL8K_A2H_INT_RADIO_OFF | \
  82. MWL8K_A2H_INT_MAC_EVENT | \
  83. MWL8K_A2H_INT_OPC_DONE | \
  84. MWL8K_A2H_INT_RX_READY | \
  85. MWL8K_A2H_INT_TX_DONE | \
  86. MWL8K_A2H_INT_BA_WATCHDOG)
  87. #define MWL8K_RX_QUEUES 1
  88. #define MWL8K_TX_WMM_QUEUES 4
  89. #define MWL8K_MAX_AMPDU_QUEUES 8
  90. #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES)
  91. #define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues)
  92. /* txpriorities are mapped with hw queues.
  93. * Each hw queue has a txpriority.
  94. */
  95. #define TOTAL_HW_TX_QUEUES 8
  96. /* Each HW queue can have one AMPDU stream.
  97. * But, because one of the hw queue is reserved,
  98. * maximum AMPDU queues that can be created are
  99. * one short of total tx queues.
  100. */
  101. #define MWL8K_NUM_AMPDU_STREAMS (TOTAL_HW_TX_QUEUES - 1)
  102. struct rxd_ops {
  103. int rxd_size;
  104. void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
  105. void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
  106. int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
  107. __le16 *qos, s8 *noise);
  108. };
  109. struct mwl8k_device_info {
  110. char *part_name;
  111. char *helper_image;
  112. char *fw_image_sta;
  113. char *fw_image_ap;
  114. struct rxd_ops *ap_rxd_ops;
  115. u32 fw_api_ap;
  116. };
  117. struct mwl8k_rx_queue {
  118. int rxd_count;
  119. /* hw receives here */
  120. int head;
  121. /* refill descs here */
  122. int tail;
  123. void *rxd;
  124. dma_addr_t rxd_dma;
  125. struct {
  126. struct sk_buff *skb;
  127. DEFINE_DMA_UNMAP_ADDR(dma);
  128. } *buf;
  129. };
  130. struct mwl8k_tx_queue {
  131. /* hw transmits here */
  132. int head;
  133. /* sw appends here */
  134. int tail;
  135. unsigned int len;
  136. struct mwl8k_tx_desc *txd;
  137. dma_addr_t txd_dma;
  138. struct sk_buff **skb;
  139. };
  140. enum {
  141. AMPDU_NO_STREAM,
  142. AMPDU_STREAM_NEW,
  143. AMPDU_STREAM_IN_PROGRESS,
  144. AMPDU_STREAM_ACTIVE,
  145. };
  146. struct mwl8k_ampdu_stream {
  147. struct ieee80211_sta *sta;
  148. u8 tid;
  149. u8 state;
  150. u8 idx;
  151. };
  152. struct mwl8k_priv {
  153. struct ieee80211_hw *hw;
  154. struct pci_dev *pdev;
  155. int irq;
  156. struct mwl8k_device_info *device_info;
  157. void __iomem *sram;
  158. void __iomem *regs;
  159. /* firmware */
  160. const struct firmware *fw_helper;
  161. const struct firmware *fw_ucode;
  162. /* hardware/firmware parameters */
  163. bool ap_fw;
  164. struct rxd_ops *rxd_ops;
  165. struct ieee80211_supported_band band_24;
  166. struct ieee80211_channel channels_24[14];
  167. struct ieee80211_rate rates_24[13];
  168. struct ieee80211_supported_band band_50;
  169. struct ieee80211_channel channels_50[4];
  170. struct ieee80211_rate rates_50[8];
  171. u32 ap_macids_supported;
  172. u32 sta_macids_supported;
  173. /* Ampdu stream information */
  174. u8 num_ampdu_queues;
  175. spinlock_t stream_lock;
  176. struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES];
  177. struct work_struct watchdog_ba_handle;
  178. /* firmware access */
  179. struct mutex fw_mutex;
  180. struct task_struct *fw_mutex_owner;
  181. struct task_struct *hw_restart_owner;
  182. int fw_mutex_depth;
  183. struct completion *hostcmd_wait;
  184. atomic_t watchdog_event_pending;
  185. /* lock held over TX and TX reap */
  186. spinlock_t tx_lock;
  187. /* TX quiesce completion, protected by fw_mutex and tx_lock */
  188. struct completion *tx_wait;
  189. /* List of interfaces. */
  190. u32 macids_used;
  191. struct list_head vif_list;
  192. /* power management status cookie from firmware */
  193. u32 *cookie;
  194. dma_addr_t cookie_dma;
  195. u16 num_mcaddrs;
  196. u8 hw_rev;
  197. u32 fw_rev;
  198. u32 caps;
  199. /*
  200. * Running count of TX packets in flight, to avoid
  201. * iterating over the transmit rings each time.
  202. */
  203. int pending_tx_pkts;
  204. struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
  205. struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES];
  206. u32 txq_offset[MWL8K_MAX_TX_QUEUES];
  207. bool radio_on;
  208. bool radio_short_preamble;
  209. bool sniffer_enabled;
  210. bool wmm_enabled;
  211. /* XXX need to convert this to handle multiple interfaces */
  212. bool capture_beacon;
  213. u8 capture_bssid[ETH_ALEN];
  214. struct sk_buff *beacon_skb;
  215. /*
  216. * This FJ worker has to be global as it is scheduled from the
  217. * RX handler. At this point we don't know which interface it
  218. * belongs to until the list of bssids waiting to complete join
  219. * is checked.
  220. */
  221. struct work_struct finalize_join_worker;
  222. /* Tasklet to perform TX reclaim. */
  223. struct tasklet_struct poll_tx_task;
  224. /* Tasklet to perform RX. */
  225. struct tasklet_struct poll_rx_task;
  226. /* Most recently reported noise in dBm */
  227. s8 noise;
  228. /*
  229. * preserve the queue configurations so they can be restored if/when
  230. * the firmware image is swapped.
  231. */
  232. struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES];
  233. /* To perform the task of reloading the firmware */
  234. struct work_struct fw_reload;
  235. bool hw_restart_in_progress;
  236. /* async firmware loading state */
  237. unsigned fw_state;
  238. char *fw_pref;
  239. char *fw_alt;
  240. bool is_8764;
  241. struct completion firmware_loading_complete;
  242. /* bitmap of running BSSes */
  243. u32 running_bsses;
  244. };
  245. #define MAX_WEP_KEY_LEN 13
  246. #define NUM_WEP_KEYS 4
  247. /* Per interface specific private data */
  248. struct mwl8k_vif {
  249. struct list_head list;
  250. struct ieee80211_vif *vif;
  251. /* Firmware macid for this vif. */
  252. int macid;
  253. /* Non AMPDU sequence number assigned by driver. */
  254. u16 seqno;
  255. /* Saved WEP keys */
  256. struct {
  257. u8 enabled;
  258. u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
  259. } wep_key_conf[NUM_WEP_KEYS];
  260. /* BSSID */
  261. u8 bssid[ETH_ALEN];
  262. /* A flag to indicate is HW crypto is enabled for this bssid */
  263. bool is_hw_crypto_enabled;
  264. };
  265. #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
  266. #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
  267. struct tx_traffic_info {
  268. u32 start_time;
  269. u32 pkts;
  270. };
  271. #define MWL8K_MAX_TID 8
  272. struct mwl8k_sta {
  273. /* Index into station database. Returned by UPDATE_STADB. */
  274. u8 peer_id;
  275. u8 is_ampdu_allowed;
  276. struct tx_traffic_info tx_stats[MWL8K_MAX_TID];
  277. };
  278. #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
  279. static const struct ieee80211_channel mwl8k_channels_24[] = {
  280. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2412, .hw_value = 1, },
  281. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2417, .hw_value = 2, },
  282. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2422, .hw_value = 3, },
  283. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2427, .hw_value = 4, },
  284. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2432, .hw_value = 5, },
  285. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2437, .hw_value = 6, },
  286. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2442, .hw_value = 7, },
  287. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2447, .hw_value = 8, },
  288. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2452, .hw_value = 9, },
  289. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2457, .hw_value = 10, },
  290. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2462, .hw_value = 11, },
  291. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2467, .hw_value = 12, },
  292. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2472, .hw_value = 13, },
  293. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2484, .hw_value = 14, },
  294. };
  295. static const struct ieee80211_rate mwl8k_rates_24[] = {
  296. { .bitrate = 10, .hw_value = 2, },
  297. { .bitrate = 20, .hw_value = 4, },
  298. { .bitrate = 55, .hw_value = 11, },
  299. { .bitrate = 110, .hw_value = 22, },
  300. { .bitrate = 220, .hw_value = 44, },
  301. { .bitrate = 60, .hw_value = 12, },
  302. { .bitrate = 90, .hw_value = 18, },
  303. { .bitrate = 120, .hw_value = 24, },
  304. { .bitrate = 180, .hw_value = 36, },
  305. { .bitrate = 240, .hw_value = 48, },
  306. { .bitrate = 360, .hw_value = 72, },
  307. { .bitrate = 480, .hw_value = 96, },
  308. { .bitrate = 540, .hw_value = 108, },
  309. };
  310. static const struct ieee80211_channel mwl8k_channels_50[] = {
  311. { .band = IEEE80211_BAND_5GHZ, .center_freq = 5180, .hw_value = 36, },
  312. { .band = IEEE80211_BAND_5GHZ, .center_freq = 5200, .hw_value = 40, },
  313. { .band = IEEE80211_BAND_5GHZ, .center_freq = 5220, .hw_value = 44, },
  314. { .band = IEEE80211_BAND_5GHZ, .center_freq = 5240, .hw_value = 48, },
  315. };
  316. static const struct ieee80211_rate mwl8k_rates_50[] = {
  317. { .bitrate = 60, .hw_value = 12, },
  318. { .bitrate = 90, .hw_value = 18, },
  319. { .bitrate = 120, .hw_value = 24, },
  320. { .bitrate = 180, .hw_value = 36, },
  321. { .bitrate = 240, .hw_value = 48, },
  322. { .bitrate = 360, .hw_value = 72, },
  323. { .bitrate = 480, .hw_value = 96, },
  324. { .bitrate = 540, .hw_value = 108, },
  325. };
  326. /* Set or get info from Firmware */
  327. #define MWL8K_CMD_GET 0x0000
  328. #define MWL8K_CMD_SET 0x0001
  329. #define MWL8K_CMD_SET_LIST 0x0002
  330. /* Firmware command codes */
  331. #define MWL8K_CMD_CODE_DNLD 0x0001
  332. #define MWL8K_CMD_GET_HW_SPEC 0x0003
  333. #define MWL8K_CMD_SET_HW_SPEC 0x0004
  334. #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
  335. #define MWL8K_CMD_GET_STAT 0x0014
  336. #define MWL8K_CMD_RADIO_CONTROL 0x001c
  337. #define MWL8K_CMD_RF_TX_POWER 0x001e
  338. #define MWL8K_CMD_TX_POWER 0x001f
  339. #define MWL8K_CMD_RF_ANTENNA 0x0020
  340. #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
  341. #define MWL8K_CMD_SET_PRE_SCAN 0x0107
  342. #define MWL8K_CMD_SET_POST_SCAN 0x0108
  343. #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
  344. #define MWL8K_CMD_SET_AID 0x010d
  345. #define MWL8K_CMD_SET_RATE 0x0110
  346. #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
  347. #define MWL8K_CMD_RTS_THRESHOLD 0x0113
  348. #define MWL8K_CMD_SET_SLOT 0x0114
  349. #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
  350. #define MWL8K_CMD_SET_WMM_MODE 0x0123
  351. #define MWL8K_CMD_MIMO_CONFIG 0x0125
  352. #define MWL8K_CMD_USE_FIXED_RATE 0x0126
  353. #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
  354. #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
  355. #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
  356. #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
  357. #define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */
  358. #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
  359. #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
  360. #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
  361. #define MWL8K_CMD_UPDATE_STADB 0x1123
  362. #define MWL8K_CMD_BASTREAM 0x1125
  363. static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
  364. {
  365. u16 command = le16_to_cpu(cmd);
  366. #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
  367. snprintf(buf, bufsize, "%s", #x);\
  368. return buf;\
  369. } while (0)
  370. switch (command & ~0x8000) {
  371. MWL8K_CMDNAME(CODE_DNLD);
  372. MWL8K_CMDNAME(GET_HW_SPEC);
  373. MWL8K_CMDNAME(SET_HW_SPEC);
  374. MWL8K_CMDNAME(MAC_MULTICAST_ADR);
  375. MWL8K_CMDNAME(GET_STAT);
  376. MWL8K_CMDNAME(RADIO_CONTROL);
  377. MWL8K_CMDNAME(RF_TX_POWER);
  378. MWL8K_CMDNAME(TX_POWER);
  379. MWL8K_CMDNAME(RF_ANTENNA);
  380. MWL8K_CMDNAME(SET_BEACON);
  381. MWL8K_CMDNAME(SET_PRE_SCAN);
  382. MWL8K_CMDNAME(SET_POST_SCAN);
  383. MWL8K_CMDNAME(SET_RF_CHANNEL);
  384. MWL8K_CMDNAME(SET_AID);
  385. MWL8K_CMDNAME(SET_RATE);
  386. MWL8K_CMDNAME(SET_FINALIZE_JOIN);
  387. MWL8K_CMDNAME(RTS_THRESHOLD);
  388. MWL8K_CMDNAME(SET_SLOT);
  389. MWL8K_CMDNAME(SET_EDCA_PARAMS);
  390. MWL8K_CMDNAME(SET_WMM_MODE);
  391. MWL8K_CMDNAME(MIMO_CONFIG);
  392. MWL8K_CMDNAME(USE_FIXED_RATE);
  393. MWL8K_CMDNAME(ENABLE_SNIFFER);
  394. MWL8K_CMDNAME(SET_MAC_ADDR);
  395. MWL8K_CMDNAME(SET_RATEADAPT_MODE);
  396. MWL8K_CMDNAME(BSS_START);
  397. MWL8K_CMDNAME(SET_NEW_STN);
  398. MWL8K_CMDNAME(UPDATE_ENCRYPTION);
  399. MWL8K_CMDNAME(UPDATE_STADB);
  400. MWL8K_CMDNAME(BASTREAM);
  401. MWL8K_CMDNAME(GET_WATCHDOG_BITMAP);
  402. default:
  403. snprintf(buf, bufsize, "0x%x", cmd);
  404. }
  405. #undef MWL8K_CMDNAME
  406. return buf;
  407. }
  408. /* Hardware and firmware reset */
  409. static void mwl8k_hw_reset(struct mwl8k_priv *priv)
  410. {
  411. iowrite32(MWL8K_H2A_INT_RESET,
  412. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  413. iowrite32(MWL8K_H2A_INT_RESET,
  414. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  415. msleep(20);
  416. }
  417. /* Release fw image */
  418. static void mwl8k_release_fw(const struct firmware **fw)
  419. {
  420. if (*fw == NULL)
  421. return;
  422. release_firmware(*fw);
  423. *fw = NULL;
  424. }
  425. static void mwl8k_release_firmware(struct mwl8k_priv *priv)
  426. {
  427. mwl8k_release_fw(&priv->fw_ucode);
  428. mwl8k_release_fw(&priv->fw_helper);
  429. }
  430. /* states for asynchronous f/w loading */
  431. static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
  432. enum {
  433. FW_STATE_INIT = 0,
  434. FW_STATE_LOADING_PREF,
  435. FW_STATE_LOADING_ALT,
  436. FW_STATE_ERROR,
  437. };
  438. /* Request fw image */
  439. static int mwl8k_request_fw(struct mwl8k_priv *priv,
  440. const char *fname, const struct firmware **fw,
  441. bool nowait)
  442. {
  443. /* release current image */
  444. if (*fw != NULL)
  445. mwl8k_release_fw(fw);
  446. if (nowait)
  447. return request_firmware_nowait(THIS_MODULE, 1, fname,
  448. &priv->pdev->dev, GFP_KERNEL,
  449. priv, mwl8k_fw_state_machine);
  450. else
  451. return request_firmware(fw, fname, &priv->pdev->dev);
  452. }
  453. static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
  454. bool nowait)
  455. {
  456. struct mwl8k_device_info *di = priv->device_info;
  457. int rc;
  458. if (di->helper_image != NULL) {
  459. if (nowait)
  460. rc = mwl8k_request_fw(priv, di->helper_image,
  461. &priv->fw_helper, true);
  462. else
  463. rc = mwl8k_request_fw(priv, di->helper_image,
  464. &priv->fw_helper, false);
  465. if (rc)
  466. printk(KERN_ERR "%s: Error requesting helper fw %s\n",
  467. pci_name(priv->pdev), di->helper_image);
  468. if (rc || nowait)
  469. return rc;
  470. }
  471. if (nowait) {
  472. /*
  473. * if we get here, no helper image is needed. Skip the
  474. * FW_STATE_INIT state.
  475. */
  476. priv->fw_state = FW_STATE_LOADING_PREF;
  477. rc = mwl8k_request_fw(priv, fw_image,
  478. &priv->fw_ucode,
  479. true);
  480. } else
  481. rc = mwl8k_request_fw(priv, fw_image,
  482. &priv->fw_ucode, false);
  483. if (rc) {
  484. printk(KERN_ERR "%s: Error requesting firmware file %s\n",
  485. pci_name(priv->pdev), fw_image);
  486. mwl8k_release_fw(&priv->fw_helper);
  487. return rc;
  488. }
  489. return 0;
  490. }
  491. struct mwl8k_cmd_pkt {
  492. __le16 code;
  493. __le16 length;
  494. __u8 seq_num;
  495. __u8 macid;
  496. __le16 result;
  497. char payload[0];
  498. } __packed;
  499. /*
  500. * Firmware loading.
  501. */
  502. static int
  503. mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
  504. {
  505. void __iomem *regs = priv->regs;
  506. dma_addr_t dma_addr;
  507. int loops;
  508. dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
  509. if (pci_dma_mapping_error(priv->pdev, dma_addr))
  510. return -ENOMEM;
  511. iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
  512. iowrite32(0, regs + MWL8K_HIU_INT_CODE);
  513. iowrite32(MWL8K_H2A_INT_DOORBELL,
  514. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  515. iowrite32(MWL8K_H2A_INT_DUMMY,
  516. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  517. loops = 1000;
  518. do {
  519. u32 int_code;
  520. if (priv->is_8764) {
  521. int_code = ioread32(regs +
  522. MWL8K_HIU_H2A_INTERRUPT_STATUS);
  523. if (int_code == 0)
  524. break;
  525. } else {
  526. int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
  527. if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
  528. iowrite32(0, regs + MWL8K_HIU_INT_CODE);
  529. break;
  530. }
  531. }
  532. cond_resched();
  533. udelay(1);
  534. } while (--loops);
  535. pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
  536. return loops ? 0 : -ETIMEDOUT;
  537. }
  538. static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
  539. const u8 *data, size_t length)
  540. {
  541. struct mwl8k_cmd_pkt *cmd;
  542. int done;
  543. int rc = 0;
  544. cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
  545. if (cmd == NULL)
  546. return -ENOMEM;
  547. cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
  548. cmd->seq_num = 0;
  549. cmd->macid = 0;
  550. cmd->result = 0;
  551. done = 0;
  552. while (length) {
  553. int block_size = length > 256 ? 256 : length;
  554. memcpy(cmd->payload, data + done, block_size);
  555. cmd->length = cpu_to_le16(block_size);
  556. rc = mwl8k_send_fw_load_cmd(priv, cmd,
  557. sizeof(*cmd) + block_size);
  558. if (rc)
  559. break;
  560. done += block_size;
  561. length -= block_size;
  562. }
  563. if (!rc) {
  564. cmd->length = 0;
  565. rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
  566. }
  567. kfree(cmd);
  568. return rc;
  569. }
  570. static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
  571. const u8 *data, size_t length)
  572. {
  573. unsigned char *buffer;
  574. int may_continue, rc = 0;
  575. u32 done, prev_block_size;
  576. buffer = kmalloc(1024, GFP_KERNEL);
  577. if (buffer == NULL)
  578. return -ENOMEM;
  579. done = 0;
  580. prev_block_size = 0;
  581. may_continue = 1000;
  582. while (may_continue > 0) {
  583. u32 block_size;
  584. block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
  585. if (block_size & 1) {
  586. block_size &= ~1;
  587. may_continue--;
  588. } else {
  589. done += prev_block_size;
  590. length -= prev_block_size;
  591. }
  592. if (block_size > 1024 || block_size > length) {
  593. rc = -EOVERFLOW;
  594. break;
  595. }
  596. if (length == 0) {
  597. rc = 0;
  598. break;
  599. }
  600. if (block_size == 0) {
  601. rc = -EPROTO;
  602. may_continue--;
  603. udelay(1);
  604. continue;
  605. }
  606. prev_block_size = block_size;
  607. memcpy(buffer, data + done, block_size);
  608. rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
  609. if (rc)
  610. break;
  611. }
  612. if (!rc && length != 0)
  613. rc = -EREMOTEIO;
  614. kfree(buffer);
  615. return rc;
  616. }
  617. static int mwl8k_load_firmware(struct ieee80211_hw *hw)
  618. {
  619. struct mwl8k_priv *priv = hw->priv;
  620. const struct firmware *fw = priv->fw_ucode;
  621. int rc;
  622. int loops;
  623. if (!memcmp(fw->data, "\x01\x00\x00\x00", 4) && !priv->is_8764) {
  624. const struct firmware *helper = priv->fw_helper;
  625. if (helper == NULL) {
  626. printk(KERN_ERR "%s: helper image needed but none "
  627. "given\n", pci_name(priv->pdev));
  628. return -EINVAL;
  629. }
  630. rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
  631. if (rc) {
  632. printk(KERN_ERR "%s: unable to load firmware "
  633. "helper image\n", pci_name(priv->pdev));
  634. return rc;
  635. }
  636. msleep(20);
  637. rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
  638. } else {
  639. if (priv->is_8764)
  640. rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
  641. else
  642. rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
  643. }
  644. if (rc) {
  645. printk(KERN_ERR "%s: unable to load firmware image\n",
  646. pci_name(priv->pdev));
  647. return rc;
  648. }
  649. iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
  650. loops = 500000;
  651. do {
  652. u32 ready_code;
  653. ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
  654. if (ready_code == MWL8K_FWAP_READY) {
  655. priv->ap_fw = true;
  656. break;
  657. } else if (ready_code == MWL8K_FWSTA_READY) {
  658. priv->ap_fw = false;
  659. break;
  660. }
  661. cond_resched();
  662. udelay(1);
  663. } while (--loops);
  664. return loops ? 0 : -ETIMEDOUT;
  665. }
  666. /* DMA header used by firmware and hardware. */
  667. struct mwl8k_dma_data {
  668. __le16 fwlen;
  669. struct ieee80211_hdr wh;
  670. char data[0];
  671. } __packed;
  672. /* Routines to add/remove DMA header from skb. */
  673. static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
  674. {
  675. struct mwl8k_dma_data *tr;
  676. int hdrlen;
  677. tr = (struct mwl8k_dma_data *)skb->data;
  678. hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
  679. if (hdrlen != sizeof(tr->wh)) {
  680. if (ieee80211_is_data_qos(tr->wh.frame_control)) {
  681. memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
  682. *((__le16 *)(tr->data - 2)) = qos;
  683. } else {
  684. memmove(tr->data - hdrlen, &tr->wh, hdrlen);
  685. }
  686. }
  687. if (hdrlen != sizeof(*tr))
  688. skb_pull(skb, sizeof(*tr) - hdrlen);
  689. }
  690. #define REDUCED_TX_HEADROOM 8
  691. static void
  692. mwl8k_add_dma_header(struct mwl8k_priv *priv, struct sk_buff *skb,
  693. int head_pad, int tail_pad)
  694. {
  695. struct ieee80211_hdr *wh;
  696. int hdrlen;
  697. int reqd_hdrlen;
  698. struct mwl8k_dma_data *tr;
  699. /*
  700. * Add a firmware DMA header; the firmware requires that we
  701. * present a 2-byte payload length followed by a 4-address
  702. * header (without QoS field), followed (optionally) by any
  703. * WEP/ExtIV header (but only filled in for CCMP).
  704. */
  705. wh = (struct ieee80211_hdr *)skb->data;
  706. hdrlen = ieee80211_hdrlen(wh->frame_control);
  707. /*
  708. * Check if skb_resize is required because of
  709. * tx_headroom adjustment.
  710. */
  711. if (priv->ap_fw && (hdrlen < (sizeof(struct ieee80211_cts)
  712. + REDUCED_TX_HEADROOM))) {
  713. if (pskb_expand_head(skb, REDUCED_TX_HEADROOM, 0, GFP_ATOMIC)) {
  714. wiphy_err(priv->hw->wiphy,
  715. "Failed to reallocate TX buffer\n");
  716. return;
  717. }
  718. skb->truesize += REDUCED_TX_HEADROOM;
  719. }
  720. reqd_hdrlen = sizeof(*tr) + head_pad;
  721. if (hdrlen != reqd_hdrlen)
  722. skb_push(skb, reqd_hdrlen - hdrlen);
  723. if (ieee80211_is_data_qos(wh->frame_control))
  724. hdrlen -= IEEE80211_QOS_CTL_LEN;
  725. tr = (struct mwl8k_dma_data *)skb->data;
  726. if (wh != &tr->wh)
  727. memmove(&tr->wh, wh, hdrlen);
  728. if (hdrlen != sizeof(tr->wh))
  729. memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
  730. /*
  731. * Firmware length is the length of the fully formed "802.11
  732. * payload". That is, everything except for the 802.11 header.
  733. * This includes all crypto material including the MIC.
  734. */
  735. tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
  736. }
  737. static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv *priv,
  738. struct sk_buff *skb)
  739. {
  740. struct ieee80211_hdr *wh;
  741. struct ieee80211_tx_info *tx_info;
  742. struct ieee80211_key_conf *key_conf;
  743. int data_pad;
  744. int head_pad = 0;
  745. wh = (struct ieee80211_hdr *)skb->data;
  746. tx_info = IEEE80211_SKB_CB(skb);
  747. key_conf = NULL;
  748. if (ieee80211_is_data(wh->frame_control))
  749. key_conf = tx_info->control.hw_key;
  750. /*
  751. * Make sure the packet header is in the DMA header format (4-address
  752. * without QoS), and add head & tail padding when HW crypto is enabled.
  753. *
  754. * We have the following trailer padding requirements:
  755. * - WEP: 4 trailer bytes (ICV)
  756. * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
  757. * - CCMP: 8 trailer bytes (MIC)
  758. */
  759. data_pad = 0;
  760. if (key_conf != NULL) {
  761. head_pad = key_conf->iv_len;
  762. switch (key_conf->cipher) {
  763. case WLAN_CIPHER_SUITE_WEP40:
  764. case WLAN_CIPHER_SUITE_WEP104:
  765. data_pad = 4;
  766. break;
  767. case WLAN_CIPHER_SUITE_TKIP:
  768. data_pad = 12;
  769. break;
  770. case WLAN_CIPHER_SUITE_CCMP:
  771. data_pad = 8;
  772. break;
  773. }
  774. }
  775. mwl8k_add_dma_header(priv, skb, head_pad, data_pad);
  776. }
  777. /*
  778. * Packet reception for 88w8366/88w8764 AP firmware.
  779. */
  780. struct mwl8k_rxd_ap {
  781. __le16 pkt_len;
  782. __u8 sq2;
  783. __u8 rate;
  784. __le32 pkt_phys_addr;
  785. __le32 next_rxd_phys_addr;
  786. __le16 qos_control;
  787. __le16 htsig2;
  788. __le32 hw_rssi_info;
  789. __le32 hw_noise_floor_info;
  790. __u8 noise_floor;
  791. __u8 pad0[3];
  792. __u8 rssi;
  793. __u8 rx_status;
  794. __u8 channel;
  795. __u8 rx_ctrl;
  796. } __packed;
  797. #define MWL8K_AP_RATE_INFO_MCS_FORMAT 0x80
  798. #define MWL8K_AP_RATE_INFO_40MHZ 0x40
  799. #define MWL8K_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
  800. #define MWL8K_AP_RX_CTRL_OWNED_BY_HOST 0x80
  801. /* 8366/8764 AP rx_status bits */
  802. #define MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
  803. #define MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
  804. #define MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
  805. #define MWL8K_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
  806. #define MWL8K_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
  807. static void mwl8k_rxd_ap_init(void *_rxd, dma_addr_t next_dma_addr)
  808. {
  809. struct mwl8k_rxd_ap *rxd = _rxd;
  810. rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
  811. rxd->rx_ctrl = MWL8K_AP_RX_CTRL_OWNED_BY_HOST;
  812. }
  813. static void mwl8k_rxd_ap_refill(void *_rxd, dma_addr_t addr, int len)
  814. {
  815. struct mwl8k_rxd_ap *rxd = _rxd;
  816. rxd->pkt_len = cpu_to_le16(len);
  817. rxd->pkt_phys_addr = cpu_to_le32(addr);
  818. wmb();
  819. rxd->rx_ctrl = 0;
  820. }
  821. static int
  822. mwl8k_rxd_ap_process(void *_rxd, struct ieee80211_rx_status *status,
  823. __le16 *qos, s8 *noise)
  824. {
  825. struct mwl8k_rxd_ap *rxd = _rxd;
  826. if (!(rxd->rx_ctrl & MWL8K_AP_RX_CTRL_OWNED_BY_HOST))
  827. return -1;
  828. rmb();
  829. memset(status, 0, sizeof(*status));
  830. status->signal = -rxd->rssi;
  831. *noise = -rxd->noise_floor;
  832. if (rxd->rate & MWL8K_AP_RATE_INFO_MCS_FORMAT) {
  833. status->flag |= RX_FLAG_HT;
  834. if (rxd->rate & MWL8K_AP_RATE_INFO_40MHZ)
  835. status->flag |= RX_FLAG_40MHZ;
  836. status->rate_idx = MWL8K_AP_RATE_INFO_RATEID(rxd->rate);
  837. } else {
  838. int i;
  839. for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
  840. if (mwl8k_rates_24[i].hw_value == rxd->rate) {
  841. status->rate_idx = i;
  842. break;
  843. }
  844. }
  845. }
  846. if (rxd->channel > 14) {
  847. status->band = IEEE80211_BAND_5GHZ;
  848. if (!(status->flag & RX_FLAG_HT))
  849. status->rate_idx -= 5;
  850. } else {
  851. status->band = IEEE80211_BAND_2GHZ;
  852. }
  853. status->freq = ieee80211_channel_to_frequency(rxd->channel,
  854. status->band);
  855. *qos = rxd->qos_control;
  856. if ((rxd->rx_status != MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
  857. (rxd->rx_status & MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK) &&
  858. (rxd->rx_status & MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
  859. status->flag |= RX_FLAG_MMIC_ERROR;
  860. return le16_to_cpu(rxd->pkt_len);
  861. }
  862. static struct rxd_ops rxd_ap_ops = {
  863. .rxd_size = sizeof(struct mwl8k_rxd_ap),
  864. .rxd_init = mwl8k_rxd_ap_init,
  865. .rxd_refill = mwl8k_rxd_ap_refill,
  866. .rxd_process = mwl8k_rxd_ap_process,
  867. };
  868. /*
  869. * Packet reception for STA firmware.
  870. */
  871. struct mwl8k_rxd_sta {
  872. __le16 pkt_len;
  873. __u8 link_quality;
  874. __u8 noise_level;
  875. __le32 pkt_phys_addr;
  876. __le32 next_rxd_phys_addr;
  877. __le16 qos_control;
  878. __le16 rate_info;
  879. __le32 pad0[4];
  880. __u8 rssi;
  881. __u8 channel;
  882. __le16 pad1;
  883. __u8 rx_ctrl;
  884. __u8 rx_status;
  885. __u8 pad2[2];
  886. } __packed;
  887. #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
  888. #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
  889. #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
  890. #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
  891. #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
  892. #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
  893. #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
  894. #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
  895. /* ICV=0 or MIC=1 */
  896. #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
  897. /* Key is uploaded only in failure case */
  898. #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
  899. static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
  900. {
  901. struct mwl8k_rxd_sta *rxd = _rxd;
  902. rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
  903. rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
  904. }
  905. static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
  906. {
  907. struct mwl8k_rxd_sta *rxd = _rxd;
  908. rxd->pkt_len = cpu_to_le16(len);
  909. rxd->pkt_phys_addr = cpu_to_le32(addr);
  910. wmb();
  911. rxd->rx_ctrl = 0;
  912. }
  913. static int
  914. mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
  915. __le16 *qos, s8 *noise)
  916. {
  917. struct mwl8k_rxd_sta *rxd = _rxd;
  918. u16 rate_info;
  919. if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
  920. return -1;
  921. rmb();
  922. rate_info = le16_to_cpu(rxd->rate_info);
  923. memset(status, 0, sizeof(*status));
  924. status->signal = -rxd->rssi;
  925. *noise = -rxd->noise_level;
  926. status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
  927. status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
  928. if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
  929. status->flag |= RX_FLAG_SHORTPRE;
  930. if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
  931. status->flag |= RX_FLAG_40MHZ;
  932. if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
  933. status->flag |= RX_FLAG_SHORT_GI;
  934. if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
  935. status->flag |= RX_FLAG_HT;
  936. if (rxd->channel > 14) {
  937. status->band = IEEE80211_BAND_5GHZ;
  938. if (!(status->flag & RX_FLAG_HT))
  939. status->rate_idx -= 5;
  940. } else {
  941. status->band = IEEE80211_BAND_2GHZ;
  942. }
  943. status->freq = ieee80211_channel_to_frequency(rxd->channel,
  944. status->band);
  945. *qos = rxd->qos_control;
  946. if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
  947. (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
  948. status->flag |= RX_FLAG_MMIC_ERROR;
  949. return le16_to_cpu(rxd->pkt_len);
  950. }
  951. static struct rxd_ops rxd_sta_ops = {
  952. .rxd_size = sizeof(struct mwl8k_rxd_sta),
  953. .rxd_init = mwl8k_rxd_sta_init,
  954. .rxd_refill = mwl8k_rxd_sta_refill,
  955. .rxd_process = mwl8k_rxd_sta_process,
  956. };
  957. #define MWL8K_RX_DESCS 256
  958. #define MWL8K_RX_MAXSZ 3800
  959. static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
  960. {
  961. struct mwl8k_priv *priv = hw->priv;
  962. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  963. int size;
  964. int i;
  965. rxq->rxd_count = 0;
  966. rxq->head = 0;
  967. rxq->tail = 0;
  968. size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
  969. rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
  970. if (rxq->rxd == NULL) {
  971. wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
  972. return -ENOMEM;
  973. }
  974. memset(rxq->rxd, 0, size);
  975. rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
  976. if (rxq->buf == NULL) {
  977. pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
  978. return -ENOMEM;
  979. }
  980. for (i = 0; i < MWL8K_RX_DESCS; i++) {
  981. int desc_size;
  982. void *rxd;
  983. int nexti;
  984. dma_addr_t next_dma_addr;
  985. desc_size = priv->rxd_ops->rxd_size;
  986. rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
  987. nexti = i + 1;
  988. if (nexti == MWL8K_RX_DESCS)
  989. nexti = 0;
  990. next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
  991. priv->rxd_ops->rxd_init(rxd, next_dma_addr);
  992. }
  993. return 0;
  994. }
  995. static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
  996. {
  997. struct mwl8k_priv *priv = hw->priv;
  998. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  999. int refilled;
  1000. refilled = 0;
  1001. while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
  1002. struct sk_buff *skb;
  1003. dma_addr_t addr;
  1004. int rx;
  1005. void *rxd;
  1006. skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
  1007. if (skb == NULL)
  1008. break;
  1009. addr = pci_map_single(priv->pdev, skb->data,
  1010. MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
  1011. rxq->rxd_count++;
  1012. rx = rxq->tail++;
  1013. if (rxq->tail == MWL8K_RX_DESCS)
  1014. rxq->tail = 0;
  1015. rxq->buf[rx].skb = skb;
  1016. dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
  1017. rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
  1018. priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
  1019. refilled++;
  1020. }
  1021. return refilled;
  1022. }
  1023. /* Must be called only when the card's reception is completely halted */
  1024. static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
  1025. {
  1026. struct mwl8k_priv *priv = hw->priv;
  1027. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  1028. int i;
  1029. if (rxq->rxd == NULL)
  1030. return;
  1031. for (i = 0; i < MWL8K_RX_DESCS; i++) {
  1032. if (rxq->buf[i].skb != NULL) {
  1033. pci_unmap_single(priv->pdev,
  1034. dma_unmap_addr(&rxq->buf[i], dma),
  1035. MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
  1036. dma_unmap_addr_set(&rxq->buf[i], dma, 0);
  1037. kfree_skb(rxq->buf[i].skb);
  1038. rxq->buf[i].skb = NULL;
  1039. }
  1040. }
  1041. kfree(rxq->buf);
  1042. rxq->buf = NULL;
  1043. pci_free_consistent(priv->pdev,
  1044. MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
  1045. rxq->rxd, rxq->rxd_dma);
  1046. rxq->rxd = NULL;
  1047. }
  1048. /*
  1049. * Scan a list of BSSIDs to process for finalize join.
  1050. * Allows for extension to process multiple BSSIDs.
  1051. */
  1052. static inline int
  1053. mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
  1054. {
  1055. return priv->capture_beacon &&
  1056. ieee80211_is_beacon(wh->frame_control) &&
  1057. ether_addr_equal_64bits(wh->addr3, priv->capture_bssid);
  1058. }
  1059. static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
  1060. struct sk_buff *skb)
  1061. {
  1062. struct mwl8k_priv *priv = hw->priv;
  1063. priv->capture_beacon = false;
  1064. memset(priv->capture_bssid, 0, ETH_ALEN);
  1065. /*
  1066. * Use GFP_ATOMIC as rxq_process is called from
  1067. * the primary interrupt handler, memory allocation call
  1068. * must not sleep.
  1069. */
  1070. priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
  1071. if (priv->beacon_skb != NULL)
  1072. ieee80211_queue_work(hw, &priv->finalize_join_worker);
  1073. }
  1074. static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
  1075. u8 *bssid)
  1076. {
  1077. struct mwl8k_vif *mwl8k_vif;
  1078. list_for_each_entry(mwl8k_vif,
  1079. vif_list, list) {
  1080. if (memcmp(bssid, mwl8k_vif->bssid,
  1081. ETH_ALEN) == 0)
  1082. return mwl8k_vif;
  1083. }
  1084. return NULL;
  1085. }
  1086. static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
  1087. {
  1088. struct mwl8k_priv *priv = hw->priv;
  1089. struct mwl8k_vif *mwl8k_vif = NULL;
  1090. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  1091. int processed;
  1092. processed = 0;
  1093. while (rxq->rxd_count && limit--) {
  1094. struct sk_buff *skb;
  1095. void *rxd;
  1096. int pkt_len;
  1097. struct ieee80211_rx_status status;
  1098. struct ieee80211_hdr *wh;
  1099. __le16 qos;
  1100. skb = rxq->buf[rxq->head].skb;
  1101. if (skb == NULL)
  1102. break;
  1103. rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
  1104. pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
  1105. &priv->noise);
  1106. if (pkt_len < 0)
  1107. break;
  1108. rxq->buf[rxq->head].skb = NULL;
  1109. pci_unmap_single(priv->pdev,
  1110. dma_unmap_addr(&rxq->buf[rxq->head], dma),
  1111. MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
  1112. dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
  1113. rxq->head++;
  1114. if (rxq->head == MWL8K_RX_DESCS)
  1115. rxq->head = 0;
  1116. rxq->rxd_count--;
  1117. wh = &((struct mwl8k_dma_data *)skb->data)->wh;
  1118. /*
  1119. * Check for a pending join operation. Save a
  1120. * copy of the beacon and schedule a tasklet to
  1121. * send a FINALIZE_JOIN command to the firmware.
  1122. */
  1123. if (mwl8k_capture_bssid(priv, (void *)skb->data))
  1124. mwl8k_save_beacon(hw, skb);
  1125. if (ieee80211_has_protected(wh->frame_control)) {
  1126. /* Check if hw crypto has been enabled for
  1127. * this bss. If yes, set the status flags
  1128. * accordingly
  1129. */
  1130. mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
  1131. wh->addr1);
  1132. if (mwl8k_vif != NULL &&
  1133. mwl8k_vif->is_hw_crypto_enabled) {
  1134. /*
  1135. * When MMIC ERROR is encountered
  1136. * by the firmware, payload is
  1137. * dropped and only 32 bytes of
  1138. * mwl8k Firmware header is sent
  1139. * to the host.
  1140. *
  1141. * We need to add four bytes of
  1142. * key information. In it
  1143. * MAC80211 expects keyidx set to
  1144. * 0 for triggering Counter
  1145. * Measure of MMIC failure.
  1146. */
  1147. if (status.flag & RX_FLAG_MMIC_ERROR) {
  1148. struct mwl8k_dma_data *tr;
  1149. tr = (struct mwl8k_dma_data *)skb->data;
  1150. memset((void *)&(tr->data), 0, 4);
  1151. pkt_len += 4;
  1152. }
  1153. if (!ieee80211_is_auth(wh->frame_control))
  1154. status.flag |= RX_FLAG_IV_STRIPPED |
  1155. RX_FLAG_DECRYPTED |
  1156. RX_FLAG_MMIC_STRIPPED;
  1157. }
  1158. }
  1159. skb_put(skb, pkt_len);
  1160. mwl8k_remove_dma_header(skb, qos);
  1161. memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
  1162. ieee80211_rx_irqsafe(hw, skb);
  1163. processed++;
  1164. }
  1165. return processed;
  1166. }
  1167. /*
  1168. * Packet transmission.
  1169. */
  1170. #define MWL8K_TXD_STATUS_OK 0x00000001
  1171. #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
  1172. #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
  1173. #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
  1174. #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
  1175. #define MWL8K_QOS_QLEN_UNSPEC 0xff00
  1176. #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
  1177. #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
  1178. #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
  1179. #define MWL8K_QOS_EOSP 0x0010
  1180. struct mwl8k_tx_desc {
  1181. __le32 status;
  1182. __u8 data_rate;
  1183. __u8 tx_priority;
  1184. __le16 qos_control;
  1185. __le32 pkt_phys_addr;
  1186. __le16 pkt_len;
  1187. __u8 dest_MAC_addr[ETH_ALEN];
  1188. __le32 next_txd_phys_addr;
  1189. __le32 timestamp;
  1190. __le16 rate_info;
  1191. __u8 peer_id;
  1192. __u8 tx_frag_cnt;
  1193. } __packed;
  1194. #define MWL8K_TX_DESCS 128
  1195. static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
  1196. {
  1197. struct mwl8k_priv *priv = hw->priv;
  1198. struct mwl8k_tx_queue *txq = priv->txq + index;
  1199. int size;
  1200. int i;
  1201. txq->len = 0;
  1202. txq->head = 0;
  1203. txq->tail = 0;
  1204. size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
  1205. txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
  1206. if (txq->txd == NULL) {
  1207. wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
  1208. return -ENOMEM;
  1209. }
  1210. memset(txq->txd, 0, size);
  1211. txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
  1212. if (txq->skb == NULL) {
  1213. pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
  1214. return -ENOMEM;
  1215. }
  1216. for (i = 0; i < MWL8K_TX_DESCS; i++) {
  1217. struct mwl8k_tx_desc *tx_desc;
  1218. int nexti;
  1219. tx_desc = txq->txd + i;
  1220. nexti = (i + 1) % MWL8K_TX_DESCS;
  1221. tx_desc->status = 0;
  1222. tx_desc->next_txd_phys_addr =
  1223. cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
  1224. }
  1225. return 0;
  1226. }
  1227. static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
  1228. {
  1229. iowrite32(MWL8K_H2A_INT_PPA_READY,
  1230. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1231. iowrite32(MWL8K_H2A_INT_DUMMY,
  1232. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1233. ioread32(priv->regs + MWL8K_HIU_INT_CODE);
  1234. }
  1235. static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
  1236. {
  1237. struct mwl8k_priv *priv = hw->priv;
  1238. int i;
  1239. for (i = 0; i < mwl8k_tx_queues(priv); i++) {
  1240. struct mwl8k_tx_queue *txq = priv->txq + i;
  1241. int fw_owned = 0;
  1242. int drv_owned = 0;
  1243. int unused = 0;
  1244. int desc;
  1245. for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
  1246. struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
  1247. u32 status;
  1248. status = le32_to_cpu(tx_desc->status);
  1249. if (status & MWL8K_TXD_STATUS_FW_OWNED)
  1250. fw_owned++;
  1251. else
  1252. drv_owned++;
  1253. if (tx_desc->pkt_len == 0)
  1254. unused++;
  1255. }
  1256. wiphy_err(hw->wiphy,
  1257. "txq[%d] len=%d head=%d tail=%d "
  1258. "fw_owned=%d drv_owned=%d unused=%d\n",
  1259. i,
  1260. txq->len, txq->head, txq->tail,
  1261. fw_owned, drv_owned, unused);
  1262. }
  1263. }
  1264. /*
  1265. * Must be called with priv->fw_mutex held and tx queues stopped.
  1266. */
  1267. #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
  1268. static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
  1269. {
  1270. struct mwl8k_priv *priv = hw->priv;
  1271. DECLARE_COMPLETION_ONSTACK(tx_wait);
  1272. int retry;
  1273. int rc;
  1274. might_sleep();
  1275. /* Since fw restart is in progress, allow only the firmware
  1276. * commands from the restart code and block the other
  1277. * commands since they are going to fail in any case since
  1278. * the firmware has crashed
  1279. */
  1280. if (priv->hw_restart_in_progress) {
  1281. if (priv->hw_restart_owner == current)
  1282. return 0;
  1283. else
  1284. return -EBUSY;
  1285. }
  1286. if (atomic_read(&priv->watchdog_event_pending))
  1287. return 0;
  1288. /*
  1289. * The TX queues are stopped at this point, so this test
  1290. * doesn't need to take ->tx_lock.
  1291. */
  1292. if (!priv->pending_tx_pkts)
  1293. return 0;
  1294. retry = 1;
  1295. rc = 0;
  1296. spin_lock_bh(&priv->tx_lock);
  1297. priv->tx_wait = &tx_wait;
  1298. while (!rc) {
  1299. int oldcount;
  1300. unsigned long timeout;
  1301. oldcount = priv->pending_tx_pkts;
  1302. spin_unlock_bh(&priv->tx_lock);
  1303. timeout = wait_for_completion_timeout(&tx_wait,
  1304. msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
  1305. if (atomic_read(&priv->watchdog_event_pending)) {
  1306. spin_lock_bh(&priv->tx_lock);
  1307. priv->tx_wait = NULL;
  1308. spin_unlock_bh(&priv->tx_lock);
  1309. return 0;
  1310. }
  1311. spin_lock_bh(&priv->tx_lock);
  1312. if (timeout || !priv->pending_tx_pkts) {
  1313. WARN_ON(priv->pending_tx_pkts);
  1314. if (retry)
  1315. wiphy_notice(hw->wiphy, "tx rings drained\n");
  1316. break;
  1317. }
  1318. if (retry) {
  1319. mwl8k_tx_start(priv);
  1320. retry = 0;
  1321. continue;
  1322. }
  1323. if (priv->pending_tx_pkts < oldcount) {
  1324. wiphy_notice(hw->wiphy,
  1325. "waiting for tx rings to drain (%d -> %d pkts)\n",
  1326. oldcount, priv->pending_tx_pkts);
  1327. retry = 1;
  1328. continue;
  1329. }
  1330. priv->tx_wait = NULL;
  1331. wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
  1332. MWL8K_TX_WAIT_TIMEOUT_MS);
  1333. mwl8k_dump_tx_rings(hw);
  1334. priv->hw_restart_in_progress = true;
  1335. ieee80211_queue_work(hw, &priv->fw_reload);
  1336. rc = -ETIMEDOUT;
  1337. }
  1338. priv->tx_wait = NULL;
  1339. spin_unlock_bh(&priv->tx_lock);
  1340. return rc;
  1341. }
  1342. #define MWL8K_TXD_SUCCESS(status) \
  1343. ((status) & (MWL8K_TXD_STATUS_OK | \
  1344. MWL8K_TXD_STATUS_OK_RETRY | \
  1345. MWL8K_TXD_STATUS_OK_MORE_RETRY))
  1346. static int mwl8k_tid_queue_mapping(u8 tid)
  1347. {
  1348. BUG_ON(tid > 7);
  1349. switch (tid) {
  1350. case 0:
  1351. case 3:
  1352. return IEEE80211_AC_BE;
  1353. break;
  1354. case 1:
  1355. case 2:
  1356. return IEEE80211_AC_BK;
  1357. break;
  1358. case 4:
  1359. case 5:
  1360. return IEEE80211_AC_VI;
  1361. break;
  1362. case 6:
  1363. case 7:
  1364. return IEEE80211_AC_VO;
  1365. break;
  1366. default:
  1367. return -1;
  1368. break;
  1369. }
  1370. }
  1371. /* The firmware will fill in the rate information
  1372. * for each packet that gets queued in the hardware
  1373. * and these macros will interpret that info.
  1374. */
  1375. #define RI_FORMAT(a) (a & 0x0001)
  1376. #define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3)
  1377. static int
  1378. mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
  1379. {
  1380. struct mwl8k_priv *priv = hw->priv;
  1381. struct mwl8k_tx_queue *txq = priv->txq + index;
  1382. int processed;
  1383. processed = 0;
  1384. while (txq->len > 0 && limit--) {
  1385. int tx;
  1386. struct mwl8k_tx_desc *tx_desc;
  1387. unsigned long addr;
  1388. int size;
  1389. struct sk_buff *skb;
  1390. struct ieee80211_tx_info *info;
  1391. u32 status;
  1392. struct ieee80211_sta *sta;
  1393. struct mwl8k_sta *sta_info = NULL;
  1394. u16 rate_info;
  1395. struct ieee80211_hdr *wh;
  1396. tx = txq->head;
  1397. tx_desc = txq->txd + tx;
  1398. status = le32_to_cpu(tx_desc->status);
  1399. if (status & MWL8K_TXD_STATUS_FW_OWNED) {
  1400. if (!force)
  1401. break;
  1402. tx_desc->status &=
  1403. ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
  1404. }
  1405. txq->head = (tx + 1) % MWL8K_TX_DESCS;
  1406. BUG_ON(txq->len == 0);
  1407. txq->len--;
  1408. priv->pending_tx_pkts--;
  1409. addr = le32_to_cpu(tx_desc->pkt_phys_addr);
  1410. size = le16_to_cpu(tx_desc->pkt_len);
  1411. skb = txq->skb[tx];
  1412. txq->skb[tx] = NULL;
  1413. BUG_ON(skb == NULL);
  1414. pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
  1415. mwl8k_remove_dma_header(skb, tx_desc->qos_control);
  1416. wh = (struct ieee80211_hdr *) skb->data;
  1417. /* Mark descriptor as unused */
  1418. tx_desc->pkt_phys_addr = 0;
  1419. tx_desc->pkt_len = 0;
  1420. info = IEEE80211_SKB_CB(skb);
  1421. if (ieee80211_is_data(wh->frame_control)) {
  1422. rcu_read_lock();
  1423. sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1,
  1424. wh->addr2);
  1425. if (sta) {
  1426. sta_info = MWL8K_STA(sta);
  1427. BUG_ON(sta_info == NULL);
  1428. rate_info = le16_to_cpu(tx_desc->rate_info);
  1429. /* If rate is < 6.5 Mpbs for an ht station
  1430. * do not form an ampdu. If the station is a
  1431. * legacy station (format = 0), do not form an
  1432. * ampdu
  1433. */
  1434. if (RI_RATE_ID_MCS(rate_info) < 1 ||
  1435. RI_FORMAT(rate_info) == 0) {
  1436. sta_info->is_ampdu_allowed = false;
  1437. } else {
  1438. sta_info->is_ampdu_allowed = true;
  1439. }
  1440. }
  1441. rcu_read_unlock();
  1442. }
  1443. ieee80211_tx_info_clear_status(info);
  1444. /* Rate control is happening in the firmware.
  1445. * Ensure no tx rate is being reported.
  1446. */
  1447. info->status.rates[0].idx = -1;
  1448. info->status.rates[0].count = 1;
  1449. if (MWL8K_TXD_SUCCESS(status))
  1450. info->flags |= IEEE80211_TX_STAT_ACK;
  1451. ieee80211_tx_status_irqsafe(hw, skb);
  1452. processed++;
  1453. }
  1454. return processed;
  1455. }
  1456. /* must be called only when the card's transmit is completely halted */
  1457. static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
  1458. {
  1459. struct mwl8k_priv *priv = hw->priv;
  1460. struct mwl8k_tx_queue *txq = priv->txq + index;
  1461. if (txq->txd == NULL)
  1462. return;
  1463. mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
  1464. kfree(txq->skb);
  1465. txq->skb = NULL;
  1466. pci_free_consistent(priv->pdev,
  1467. MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
  1468. txq->txd, txq->txd_dma);
  1469. txq->txd = NULL;
  1470. }
  1471. /* caller must hold priv->stream_lock when calling the stream functions */
  1472. static struct mwl8k_ampdu_stream *
  1473. mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
  1474. {
  1475. struct mwl8k_ampdu_stream *stream;
  1476. struct mwl8k_priv *priv = hw->priv;
  1477. int i;
  1478. for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
  1479. stream = &priv->ampdu[i];
  1480. if (stream->state == AMPDU_NO_STREAM) {
  1481. stream->sta = sta;
  1482. stream->state = AMPDU_STREAM_NEW;
  1483. stream->tid = tid;
  1484. stream->idx = i;
  1485. wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
  1486. sta->addr, tid);
  1487. return stream;
  1488. }
  1489. }
  1490. return NULL;
  1491. }
  1492. static int
  1493. mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
  1494. {
  1495. int ret;
  1496. /* if the stream has already been started, don't start it again */
  1497. if (stream->state != AMPDU_STREAM_NEW)
  1498. return 0;
  1499. ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
  1500. if (ret)
  1501. wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
  1502. "%d\n", stream->sta->addr, stream->tid, ret);
  1503. else
  1504. wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
  1505. stream->sta->addr, stream->tid);
  1506. return ret;
  1507. }
  1508. static void
  1509. mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
  1510. {
  1511. wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
  1512. stream->tid);
  1513. memset(stream, 0, sizeof(*stream));
  1514. }
  1515. static struct mwl8k_ampdu_stream *
  1516. mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
  1517. {
  1518. struct mwl8k_priv *priv = hw->priv;
  1519. int i;
  1520. for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
  1521. struct mwl8k_ampdu_stream *stream;
  1522. stream = &priv->ampdu[i];
  1523. if (stream->state == AMPDU_NO_STREAM)
  1524. continue;
  1525. if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
  1526. stream->tid == tid)
  1527. return stream;
  1528. }
  1529. return NULL;
  1530. }
  1531. #define MWL8K_AMPDU_PACKET_THRESHOLD 64
  1532. static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid)
  1533. {
  1534. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  1535. struct tx_traffic_info *tx_stats;
  1536. BUG_ON(tid >= MWL8K_MAX_TID);
  1537. tx_stats = &sta_info->tx_stats[tid];
  1538. return sta_info->is_ampdu_allowed &&
  1539. tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD;
  1540. }
  1541. static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid)
  1542. {
  1543. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  1544. struct tx_traffic_info *tx_stats;
  1545. BUG_ON(tid >= MWL8K_MAX_TID);
  1546. tx_stats = &sta_info->tx_stats[tid];
  1547. if (tx_stats->start_time == 0)
  1548. tx_stats->start_time = jiffies;
  1549. /* reset the packet count after each second elapses. If the number of
  1550. * packets ever exceeds the ampdu_min_traffic threshold, we will allow
  1551. * an ampdu stream to be started.
  1552. */
  1553. if (jiffies - tx_stats->start_time > HZ) {
  1554. tx_stats->pkts = 0;
  1555. tx_stats->start_time = 0;
  1556. } else
  1557. tx_stats->pkts++;
  1558. }
  1559. /* The hardware ampdu queues start from 5.
  1560. * txpriorities for ampdu queues are
  1561. * 5 6 7 0 1 2 3 4 ie., queue 5 is highest
  1562. * and queue 3 is lowest (queue 4 is reserved)
  1563. */
  1564. #define BA_QUEUE 5
  1565. static void
  1566. mwl8k_txq_xmit(struct ieee80211_hw *hw,
  1567. int index,
  1568. struct ieee80211_sta *sta,
  1569. struct sk_buff *skb)
  1570. {
  1571. struct mwl8k_priv *priv = hw->priv;
  1572. struct ieee80211_tx_info *tx_info;
  1573. struct mwl8k_vif *mwl8k_vif;
  1574. struct ieee80211_hdr *wh;
  1575. struct mwl8k_tx_queue *txq;
  1576. struct mwl8k_tx_desc *tx;
  1577. dma_addr_t dma;
  1578. u32 txstatus;
  1579. u8 txdatarate;
  1580. u16 qos;
  1581. int txpriority;
  1582. u8 tid = 0;
  1583. struct mwl8k_ampdu_stream *stream = NULL;
  1584. bool start_ba_session = false;
  1585. bool mgmtframe = false;
  1586. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
  1587. bool eapol_frame = false;
  1588. wh = (struct ieee80211_hdr *)skb->data;
  1589. if (ieee80211_is_data_qos(wh->frame_control))
  1590. qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
  1591. else
  1592. qos = 0;
  1593. if (skb->protocol == cpu_to_be16(ETH_P_PAE))
  1594. eapol_frame = true;
  1595. if (ieee80211_is_mgmt(wh->frame_control))
  1596. mgmtframe = true;
  1597. if (priv->ap_fw)
  1598. mwl8k_encapsulate_tx_frame(priv, skb);
  1599. else
  1600. mwl8k_add_dma_header(priv, skb, 0, 0);
  1601. wh = &((struct mwl8k_dma_data *)skb->data)->wh;
  1602. tx_info = IEEE80211_SKB_CB(skb);
  1603. mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
  1604. if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1605. wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1606. wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
  1607. mwl8k_vif->seqno += 0x10;
  1608. }
  1609. /* Setup firmware control bit fields for each frame type. */
  1610. txstatus = 0;
  1611. txdatarate = 0;
  1612. if (ieee80211_is_mgmt(wh->frame_control) ||
  1613. ieee80211_is_ctl(wh->frame_control)) {
  1614. txdatarate = 0;
  1615. qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
  1616. } else if (ieee80211_is_data(wh->frame_control)) {
  1617. txdatarate = 1;
  1618. if (is_multicast_ether_addr(wh->addr1))
  1619. txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
  1620. qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
  1621. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
  1622. qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
  1623. else
  1624. qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
  1625. }
  1626. /* Queue ADDBA request in the respective data queue. While setting up
  1627. * the ampdu stream, mac80211 queues further packets for that
  1628. * particular ra/tid pair. However, packets piled up in the hardware
  1629. * for that ra/tid pair will still go out. ADDBA request and the
  1630. * related data packets going out from different queues asynchronously
  1631. * will cause a shift in the receiver window which might result in
  1632. * ampdu packets getting dropped at the receiver after the stream has
  1633. * been setup.
  1634. */
  1635. if (unlikely(ieee80211_is_action(wh->frame_control) &&
  1636. mgmt->u.action.category == WLAN_CATEGORY_BACK &&
  1637. mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
  1638. priv->ap_fw)) {
  1639. u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
  1640. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  1641. index = mwl8k_tid_queue_mapping(tid);
  1642. }
  1643. txpriority = index;
  1644. if (priv->ap_fw && sta && sta->ht_cap.ht_supported && !eapol_frame &&
  1645. ieee80211_is_data_qos(wh->frame_control)) {
  1646. tid = qos & 0xf;
  1647. mwl8k_tx_count_packet(sta, tid);
  1648. spin_lock(&priv->stream_lock);
  1649. stream = mwl8k_lookup_stream(hw, sta->addr, tid);
  1650. if (stream != NULL) {
  1651. if (stream->state == AMPDU_STREAM_ACTIVE) {
  1652. WARN_ON(!(qos & MWL8K_QOS_ACK_POLICY_BLOCKACK));
  1653. txpriority = (BA_QUEUE + stream->idx) %
  1654. TOTAL_HW_TX_QUEUES;
  1655. if (stream->idx <= 1)
  1656. index = stream->idx +
  1657. MWL8K_TX_WMM_QUEUES;
  1658. } else if (stream->state == AMPDU_STREAM_NEW) {
  1659. /* We get here if the driver sends us packets
  1660. * after we've initiated a stream, but before
  1661. * our ampdu_action routine has been called
  1662. * with IEEE80211_AMPDU_TX_START to get the SSN
  1663. * for the ADDBA request. So this packet can
  1664. * go out with no risk of sequence number
  1665. * mismatch. No special handling is required.
  1666. */
  1667. } else {
  1668. /* Drop packets that would go out after the
  1669. * ADDBA request was sent but before the ADDBA
  1670. * response is received. If we don't do this,
  1671. * the recipient would probably receive it
  1672. * after the ADDBA request with SSN 0. This
  1673. * will cause the recipient's BA receive window
  1674. * to shift, which would cause the subsequent
  1675. * packets in the BA stream to be discarded.
  1676. * mac80211 queues our packets for us in this
  1677. * case, so this is really just a safety check.
  1678. */
  1679. wiphy_warn(hw->wiphy,
  1680. "Cannot send packet while ADDBA "
  1681. "dialog is underway.\n");
  1682. spin_unlock(&priv->stream_lock);
  1683. dev_kfree_skb(skb);
  1684. return;
  1685. }
  1686. } else {
  1687. /* Defer calling mwl8k_start_stream so that the current
  1688. * skb can go out before the ADDBA request. This
  1689. * prevents sequence number mismatch at the recepient
  1690. * as described above.
  1691. */
  1692. if (mwl8k_ampdu_allowed(sta, tid)) {
  1693. stream = mwl8k_add_stream(hw, sta, tid);
  1694. if (stream != NULL)
  1695. start_ba_session = true;
  1696. }
  1697. }
  1698. spin_unlock(&priv->stream_lock);
  1699. } else {
  1700. qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
  1701. qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
  1702. }
  1703. dma = pci_map_single(priv->pdev, skb->data,
  1704. skb->len, PCI_DMA_TODEVICE);
  1705. if (pci_dma_mapping_error(priv->pdev, dma)) {
  1706. wiphy_debug(hw->wiphy,
  1707. "failed to dma map skb, dropping TX frame.\n");
  1708. if (start_ba_session) {
  1709. spin_lock(&priv->stream_lock);
  1710. mwl8k_remove_stream(hw, stream);
  1711. spin_unlock(&priv->stream_lock);
  1712. }
  1713. dev_kfree_skb(skb);
  1714. return;
  1715. }
  1716. spin_lock_bh(&priv->tx_lock);
  1717. txq = priv->txq + index;
  1718. /* Mgmt frames that go out frequently are probe
  1719. * responses. Other mgmt frames got out relatively
  1720. * infrequently. Hence reserve 2 buffers so that
  1721. * other mgmt frames do not get dropped due to an
  1722. * already queued probe response in one of the
  1723. * reserved buffers.
  1724. */
  1725. if (txq->len >= MWL8K_TX_DESCS - 2) {
  1726. if (!mgmtframe || txq->len == MWL8K_TX_DESCS) {
  1727. if (start_ba_session) {
  1728. spin_lock(&priv->stream_lock);
  1729. mwl8k_remove_stream(hw, stream);
  1730. spin_unlock(&priv->stream_lock);
  1731. }
  1732. mwl8k_tx_start(priv);
  1733. spin_unlock_bh(&priv->tx_lock);
  1734. pci_unmap_single(priv->pdev, dma, skb->len,
  1735. PCI_DMA_TODEVICE);
  1736. dev_kfree_skb(skb);
  1737. return;
  1738. }
  1739. }
  1740. BUG_ON(txq->skb[txq->tail] != NULL);
  1741. txq->skb[txq->tail] = skb;
  1742. tx = txq->txd + txq->tail;
  1743. tx->data_rate = txdatarate;
  1744. tx->tx_priority = txpriority;
  1745. tx->qos_control = cpu_to_le16(qos);
  1746. tx->pkt_phys_addr = cpu_to_le32(dma);
  1747. tx->pkt_len = cpu_to_le16(skb->len);
  1748. tx->rate_info = 0;
  1749. if (!priv->ap_fw && sta != NULL)
  1750. tx->peer_id = MWL8K_STA(sta)->peer_id;
  1751. else
  1752. tx->peer_id = 0;
  1753. if (priv->ap_fw && ieee80211_is_data(wh->frame_control) && !eapol_frame)
  1754. tx->timestamp = cpu_to_le32(ioread32(priv->regs +
  1755. MWL8K_HW_TIMER_REGISTER));
  1756. else
  1757. tx->timestamp = 0;
  1758. wmb();
  1759. tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
  1760. txq->len++;
  1761. priv->pending_tx_pkts++;
  1762. txq->tail++;
  1763. if (txq->tail == MWL8K_TX_DESCS)
  1764. txq->tail = 0;
  1765. mwl8k_tx_start(priv);
  1766. spin_unlock_bh(&priv->tx_lock);
  1767. /* Initiate the ampdu session here */
  1768. if (start_ba_session) {
  1769. spin_lock(&priv->stream_lock);
  1770. if (mwl8k_start_stream(hw, stream))
  1771. mwl8k_remove_stream(hw, stream);
  1772. spin_unlock(&priv->stream_lock);
  1773. }
  1774. }
  1775. /*
  1776. * Firmware access.
  1777. *
  1778. * We have the following requirements for issuing firmware commands:
  1779. * - Some commands require that the packet transmit path is idle when
  1780. * the command is issued. (For simplicity, we'll just quiesce the
  1781. * transmit path for every command.)
  1782. * - There are certain sequences of commands that need to be issued to
  1783. * the hardware sequentially, with no other intervening commands.
  1784. *
  1785. * This leads to an implementation of a "firmware lock" as a mutex that
  1786. * can be taken recursively, and which is taken by both the low-level
  1787. * command submission function (mwl8k_post_cmd) as well as any users of
  1788. * that function that require issuing of an atomic sequence of commands,
  1789. * and quiesces the transmit path whenever it's taken.
  1790. */
  1791. static int mwl8k_fw_lock(struct ieee80211_hw *hw)
  1792. {
  1793. struct mwl8k_priv *priv = hw->priv;
  1794. if (priv->fw_mutex_owner != current) {
  1795. int rc;
  1796. mutex_lock(&priv->fw_mutex);
  1797. ieee80211_stop_queues(hw);
  1798. rc = mwl8k_tx_wait_empty(hw);
  1799. if (rc) {
  1800. if (!priv->hw_restart_in_progress)
  1801. ieee80211_wake_queues(hw);
  1802. mutex_unlock(&priv->fw_mutex);
  1803. return rc;
  1804. }
  1805. priv->fw_mutex_owner = current;
  1806. }
  1807. priv->fw_mutex_depth++;
  1808. return 0;
  1809. }
  1810. static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
  1811. {
  1812. struct mwl8k_priv *priv = hw->priv;
  1813. if (!--priv->fw_mutex_depth) {
  1814. if (!priv->hw_restart_in_progress)
  1815. ieee80211_wake_queues(hw);
  1816. priv->fw_mutex_owner = NULL;
  1817. mutex_unlock(&priv->fw_mutex);
  1818. }
  1819. }
  1820. static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable,
  1821. u32 bitmap);
  1822. /*
  1823. * Command processing.
  1824. */
  1825. /* Timeout firmware commands after 10s */
  1826. #define MWL8K_CMD_TIMEOUT_MS 10000
  1827. static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
  1828. {
  1829. DECLARE_COMPLETION_ONSTACK(cmd_wait);
  1830. struct mwl8k_priv *priv = hw->priv;
  1831. void __iomem *regs = priv->regs;
  1832. dma_addr_t dma_addr;
  1833. unsigned int dma_size;
  1834. int rc;
  1835. unsigned long timeout = 0;
  1836. u8 buf[32];
  1837. u32 bitmap = 0;
  1838. wiphy_dbg(hw->wiphy, "Posting %s [%d]\n",
  1839. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), cmd->macid);
  1840. /* Before posting firmware commands that could change the hardware
  1841. * characteristics, make sure that all BSSes are stopped temporary.
  1842. * Enable these stopped BSSes after completion of the commands
  1843. */
  1844. rc = mwl8k_fw_lock(hw);
  1845. if (rc)
  1846. return rc;
  1847. if (priv->ap_fw && priv->running_bsses) {
  1848. switch (le16_to_cpu(cmd->code)) {
  1849. case MWL8K_CMD_SET_RF_CHANNEL:
  1850. case MWL8K_CMD_RADIO_CONTROL:
  1851. case MWL8K_CMD_RF_TX_POWER:
  1852. case MWL8K_CMD_TX_POWER:
  1853. case MWL8K_CMD_RF_ANTENNA:
  1854. case MWL8K_CMD_RTS_THRESHOLD:
  1855. case MWL8K_CMD_MIMO_CONFIG:
  1856. bitmap = priv->running_bsses;
  1857. mwl8k_enable_bsses(hw, false, bitmap);
  1858. break;
  1859. }
  1860. }
  1861. cmd->result = (__force __le16) 0xffff;
  1862. dma_size = le16_to_cpu(cmd->length);
  1863. dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
  1864. PCI_DMA_BIDIRECTIONAL);
  1865. if (pci_dma_mapping_error(priv->pdev, dma_addr))
  1866. return -ENOMEM;
  1867. priv->hostcmd_wait = &cmd_wait;
  1868. iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
  1869. iowrite32(MWL8K_H2A_INT_DOORBELL,
  1870. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1871. iowrite32(MWL8K_H2A_INT_DUMMY,
  1872. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1873. timeout = wait_for_completion_timeout(&cmd_wait,
  1874. msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
  1875. priv->hostcmd_wait = NULL;
  1876. pci_unmap_single(priv->pdev, dma_addr, dma_size,
  1877. PCI_DMA_BIDIRECTIONAL);
  1878. if (!timeout) {
  1879. wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
  1880. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1881. MWL8K_CMD_TIMEOUT_MS);
  1882. rc = -ETIMEDOUT;
  1883. } else {
  1884. int ms;
  1885. ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
  1886. rc = cmd->result ? -EINVAL : 0;
  1887. if (rc)
  1888. wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
  1889. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1890. le16_to_cpu(cmd->result));
  1891. else if (ms > 2000)
  1892. wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
  1893. mwl8k_cmd_name(cmd->code,
  1894. buf, sizeof(buf)),
  1895. ms);
  1896. }
  1897. if (bitmap)
  1898. mwl8k_enable_bsses(hw, true, bitmap);
  1899. mwl8k_fw_unlock(hw);
  1900. return rc;
  1901. }
  1902. static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
  1903. struct ieee80211_vif *vif,
  1904. struct mwl8k_cmd_pkt *cmd)
  1905. {
  1906. if (vif != NULL)
  1907. cmd->macid = MWL8K_VIF(vif)->macid;
  1908. return mwl8k_post_cmd(hw, cmd);
  1909. }
  1910. /*
  1911. * Setup code shared between STA and AP firmware images.
  1912. */
  1913. static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
  1914. {
  1915. struct mwl8k_priv *priv = hw->priv;
  1916. BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
  1917. memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
  1918. BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
  1919. memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
  1920. priv->band_24.band = IEEE80211_BAND_2GHZ;
  1921. priv->band_24.channels = priv->channels_24;
  1922. priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
  1923. priv->band_24.bitrates = priv->rates_24;
  1924. priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
  1925. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
  1926. }
  1927. static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
  1928. {
  1929. struct mwl8k_priv *priv = hw->priv;
  1930. BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
  1931. memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
  1932. BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
  1933. memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
  1934. priv->band_50.band = IEEE80211_BAND_5GHZ;
  1935. priv->band_50.channels = priv->channels_50;
  1936. priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
  1937. priv->band_50.bitrates = priv->rates_50;
  1938. priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
  1939. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
  1940. }
  1941. /*
  1942. * CMD_GET_HW_SPEC (STA version).
  1943. */
  1944. struct mwl8k_cmd_get_hw_spec_sta {
  1945. struct mwl8k_cmd_pkt header;
  1946. __u8 hw_rev;
  1947. __u8 host_interface;
  1948. __le16 num_mcaddrs;
  1949. __u8 perm_addr[ETH_ALEN];
  1950. __le16 region_code;
  1951. __le32 fw_rev;
  1952. __le32 ps_cookie;
  1953. __le32 caps;
  1954. __u8 mcs_bitmap[16];
  1955. __le32 rx_queue_ptr;
  1956. __le32 num_tx_queues;
  1957. __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
  1958. __le32 caps2;
  1959. __le32 num_tx_desc_per_queue;
  1960. __le32 total_rxd;
  1961. } __packed;
  1962. #define MWL8K_CAP_MAX_AMSDU 0x20000000
  1963. #define MWL8K_CAP_GREENFIELD 0x08000000
  1964. #define MWL8K_CAP_AMPDU 0x04000000
  1965. #define MWL8K_CAP_RX_STBC 0x01000000
  1966. #define MWL8K_CAP_TX_STBC 0x00800000
  1967. #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
  1968. #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
  1969. #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
  1970. #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
  1971. #define MWL8K_CAP_DELAY_BA 0x00003000
  1972. #define MWL8K_CAP_MIMO 0x00000200
  1973. #define MWL8K_CAP_40MHZ 0x00000100
  1974. #define MWL8K_CAP_BAND_MASK 0x00000007
  1975. #define MWL8K_CAP_5GHZ 0x00000004
  1976. #define MWL8K_CAP_2GHZ4 0x00000001
  1977. static void
  1978. mwl8k_set_ht_caps(struct ieee80211_hw *hw,
  1979. struct ieee80211_supported_band *band, u32 cap)
  1980. {
  1981. int rx_streams;
  1982. int tx_streams;
  1983. band->ht_cap.ht_supported = 1;
  1984. if (cap & MWL8K_CAP_MAX_AMSDU)
  1985. band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  1986. if (cap & MWL8K_CAP_GREENFIELD)
  1987. band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
  1988. if (cap & MWL8K_CAP_AMPDU) {
  1989. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  1990. band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  1991. band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  1992. }
  1993. if (cap & MWL8K_CAP_RX_STBC)
  1994. band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
  1995. if (cap & MWL8K_CAP_TX_STBC)
  1996. band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  1997. if (cap & MWL8K_CAP_SHORTGI_40MHZ)
  1998. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  1999. if (cap & MWL8K_CAP_SHORTGI_20MHZ)
  2000. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  2001. if (cap & MWL8K_CAP_DELAY_BA)
  2002. band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
  2003. if (cap & MWL8K_CAP_40MHZ)
  2004. band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  2005. rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
  2006. tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
  2007. band->ht_cap.mcs.rx_mask[0] = 0xff;
  2008. if (rx_streams >= 2)
  2009. band->ht_cap.mcs.rx_mask[1] = 0xff;
  2010. if (rx_streams >= 3)
  2011. band->ht_cap.mcs.rx_mask[2] = 0xff;
  2012. band->ht_cap.mcs.rx_mask[4] = 0x01;
  2013. band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  2014. if (rx_streams != tx_streams) {
  2015. band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  2016. band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
  2017. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  2018. }
  2019. }
  2020. static void
  2021. mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
  2022. {
  2023. struct mwl8k_priv *priv = hw->priv;
  2024. if (priv->caps)
  2025. return;
  2026. if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
  2027. mwl8k_setup_2ghz_band(hw);
  2028. if (caps & MWL8K_CAP_MIMO)
  2029. mwl8k_set_ht_caps(hw, &priv->band_24, caps);
  2030. }
  2031. if (caps & MWL8K_CAP_5GHZ) {
  2032. mwl8k_setup_5ghz_band(hw);
  2033. if (caps & MWL8K_CAP_MIMO)
  2034. mwl8k_set_ht_caps(hw, &priv->band_50, caps);
  2035. }
  2036. priv->caps = caps;
  2037. }
  2038. static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
  2039. {
  2040. struct mwl8k_priv *priv = hw->priv;
  2041. struct mwl8k_cmd_get_hw_spec_sta *cmd;
  2042. int rc;
  2043. int i;
  2044. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2045. if (cmd == NULL)
  2046. return -ENOMEM;
  2047. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  2048. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2049. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  2050. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2051. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
  2052. cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
  2053. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  2054. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
  2055. cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
  2056. cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
  2057. rc = mwl8k_post_cmd(hw, &cmd->header);
  2058. if (!rc) {
  2059. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  2060. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  2061. priv->fw_rev = le32_to_cpu(cmd->fw_rev);
  2062. priv->hw_rev = cmd->hw_rev;
  2063. mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
  2064. priv->ap_macids_supported = 0x00000000;
  2065. priv->sta_macids_supported = 0x00000001;
  2066. }
  2067. kfree(cmd);
  2068. return rc;
  2069. }
  2070. /*
  2071. * CMD_GET_HW_SPEC (AP version).
  2072. */
  2073. struct mwl8k_cmd_get_hw_spec_ap {
  2074. struct mwl8k_cmd_pkt header;
  2075. __u8 hw_rev;
  2076. __u8 host_interface;
  2077. __le16 num_wcb;
  2078. __le16 num_mcaddrs;
  2079. __u8 perm_addr[ETH_ALEN];
  2080. __le16 region_code;
  2081. __le16 num_antenna;
  2082. __le32 fw_rev;
  2083. __le32 wcbbase0;
  2084. __le32 rxwrptr;
  2085. __le32 rxrdptr;
  2086. __le32 ps_cookie;
  2087. __le32 wcbbase1;
  2088. __le32 wcbbase2;
  2089. __le32 wcbbase3;
  2090. __le32 fw_api_version;
  2091. __le32 caps;
  2092. __le32 num_of_ampdu_queues;
  2093. __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
  2094. } __packed;
  2095. static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
  2096. {
  2097. struct mwl8k_priv *priv = hw->priv;
  2098. struct mwl8k_cmd_get_hw_spec_ap *cmd;
  2099. int rc, i;
  2100. u32 api_version;
  2101. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2102. if (cmd == NULL)
  2103. return -ENOMEM;
  2104. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  2105. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2106. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  2107. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2108. rc = mwl8k_post_cmd(hw, &cmd->header);
  2109. if (!rc) {
  2110. int off;
  2111. api_version = le32_to_cpu(cmd->fw_api_version);
  2112. if (priv->device_info->fw_api_ap != api_version) {
  2113. printk(KERN_ERR "%s: Unsupported fw API version for %s."
  2114. " Expected %d got %d.\n", MWL8K_NAME,
  2115. priv->device_info->part_name,
  2116. priv->device_info->fw_api_ap,
  2117. api_version);
  2118. rc = -EINVAL;
  2119. goto done;
  2120. }
  2121. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  2122. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  2123. priv->fw_rev = le32_to_cpu(cmd->fw_rev);
  2124. priv->hw_rev = cmd->hw_rev;
  2125. mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
  2126. priv->ap_macids_supported = 0x000000ff;
  2127. priv->sta_macids_supported = 0x00000100;
  2128. priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
  2129. if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
  2130. wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
  2131. " but we only support %d.\n",
  2132. priv->num_ampdu_queues,
  2133. MWL8K_MAX_AMPDU_QUEUES);
  2134. priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
  2135. }
  2136. off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
  2137. iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
  2138. off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
  2139. iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
  2140. priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
  2141. priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
  2142. priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
  2143. priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
  2144. for (i = 0; i < priv->num_ampdu_queues; i++)
  2145. priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
  2146. le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
  2147. }
  2148. done:
  2149. kfree(cmd);
  2150. return rc;
  2151. }
  2152. /*
  2153. * CMD_SET_HW_SPEC.
  2154. */
  2155. struct mwl8k_cmd_set_hw_spec {
  2156. struct mwl8k_cmd_pkt header;
  2157. __u8 hw_rev;
  2158. __u8 host_interface;
  2159. __le16 num_mcaddrs;
  2160. __u8 perm_addr[ETH_ALEN];
  2161. __le16 region_code;
  2162. __le32 fw_rev;
  2163. __le32 ps_cookie;
  2164. __le32 caps;
  2165. __le32 rx_queue_ptr;
  2166. __le32 num_tx_queues;
  2167. __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
  2168. __le32 flags;
  2169. __le32 num_tx_desc_per_queue;
  2170. __le32 total_rxd;
  2171. } __packed;
  2172. /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
  2173. * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
  2174. * the packets that are queued for more than 500ms, will be dropped in the
  2175. * hardware. This helps minimizing the issues caused due to head-of-line
  2176. * blocking where a slow client can hog the bandwidth and affect traffic to a
  2177. * faster client.
  2178. */
  2179. #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
  2180. #define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
  2181. #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
  2182. #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
  2183. #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
  2184. static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
  2185. {
  2186. struct mwl8k_priv *priv = hw->priv;
  2187. struct mwl8k_cmd_set_hw_spec *cmd;
  2188. int rc;
  2189. int i;
  2190. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2191. if (cmd == NULL)
  2192. return -ENOMEM;
  2193. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
  2194. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2195. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2196. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
  2197. cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
  2198. /*
  2199. * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
  2200. * that order. Firmware has Q3 as highest priority and Q0 as lowest
  2201. * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
  2202. * priority is interpreted the right way in firmware.
  2203. */
  2204. for (i = 0; i < mwl8k_tx_queues(priv); i++) {
  2205. int j = mwl8k_tx_queues(priv) - 1 - i;
  2206. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
  2207. }
  2208. cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
  2209. MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
  2210. MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON |
  2211. MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY |
  2212. MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR);
  2213. cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
  2214. cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
  2215. rc = mwl8k_post_cmd(hw, &cmd->header);
  2216. kfree(cmd);
  2217. return rc;
  2218. }
  2219. /*
  2220. * CMD_MAC_MULTICAST_ADR.
  2221. */
  2222. struct mwl8k_cmd_mac_multicast_adr {
  2223. struct mwl8k_cmd_pkt header;
  2224. __le16 action;
  2225. __le16 numaddr;
  2226. __u8 addr[0][ETH_ALEN];
  2227. };
  2228. #define MWL8K_ENABLE_RX_DIRECTED 0x0001
  2229. #define MWL8K_ENABLE_RX_MULTICAST 0x0002
  2230. #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
  2231. #define MWL8K_ENABLE_RX_BROADCAST 0x0008
  2232. static struct mwl8k_cmd_pkt *
  2233. __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
  2234. struct netdev_hw_addr_list *mc_list)
  2235. {
  2236. struct mwl8k_priv *priv = hw->priv;
  2237. struct mwl8k_cmd_mac_multicast_adr *cmd;
  2238. int size;
  2239. int mc_count = 0;
  2240. if (mc_list)
  2241. mc_count = netdev_hw_addr_list_count(mc_list);
  2242. if (allmulti || mc_count > priv->num_mcaddrs) {
  2243. allmulti = 1;
  2244. mc_count = 0;
  2245. }
  2246. size = sizeof(*cmd) + mc_count * ETH_ALEN;
  2247. cmd = kzalloc(size, GFP_ATOMIC);
  2248. if (cmd == NULL)
  2249. return NULL;
  2250. cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
  2251. cmd->header.length = cpu_to_le16(size);
  2252. cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
  2253. MWL8K_ENABLE_RX_BROADCAST);
  2254. if (allmulti) {
  2255. cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
  2256. } else if (mc_count) {
  2257. struct netdev_hw_addr *ha;
  2258. int i = 0;
  2259. cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
  2260. cmd->numaddr = cpu_to_le16(mc_count);
  2261. netdev_hw_addr_list_for_each(ha, mc_list) {
  2262. memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
  2263. }
  2264. }
  2265. return &cmd->header;
  2266. }
  2267. /*
  2268. * CMD_GET_STAT.
  2269. */
  2270. struct mwl8k_cmd_get_stat {
  2271. struct mwl8k_cmd_pkt header;
  2272. __le32 stats[64];
  2273. } __packed;
  2274. #define MWL8K_STAT_ACK_FAILURE 9
  2275. #define MWL8K_STAT_RTS_FAILURE 12
  2276. #define MWL8K_STAT_FCS_ERROR 24
  2277. #define MWL8K_STAT_RTS_SUCCESS 11
  2278. static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
  2279. struct ieee80211_low_level_stats *stats)
  2280. {
  2281. struct mwl8k_cmd_get_stat *cmd;
  2282. int rc;
  2283. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2284. if (cmd == NULL)
  2285. return -ENOMEM;
  2286. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
  2287. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2288. rc = mwl8k_post_cmd(hw, &cmd->header);
  2289. if (!rc) {
  2290. stats->dot11ACKFailureCount =
  2291. le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
  2292. stats->dot11RTSFailureCount =
  2293. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
  2294. stats->dot11FCSErrorCount =
  2295. le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
  2296. stats->dot11RTSSuccessCount =
  2297. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
  2298. }
  2299. kfree(cmd);
  2300. return rc;
  2301. }
  2302. /*
  2303. * CMD_RADIO_CONTROL.
  2304. */
  2305. struct mwl8k_cmd_radio_control {
  2306. struct mwl8k_cmd_pkt header;
  2307. __le16 action;
  2308. __le16 control;
  2309. __le16 radio_on;
  2310. } __packed;
  2311. static int
  2312. mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
  2313. {
  2314. struct mwl8k_priv *priv = hw->priv;
  2315. struct mwl8k_cmd_radio_control *cmd;
  2316. int rc;
  2317. if (enable == priv->radio_on && !force)
  2318. return 0;
  2319. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2320. if (cmd == NULL)
  2321. return -ENOMEM;
  2322. cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
  2323. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2324. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2325. cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
  2326. cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
  2327. rc = mwl8k_post_cmd(hw, &cmd->header);
  2328. kfree(cmd);
  2329. if (!rc)
  2330. priv->radio_on = enable;
  2331. return rc;
  2332. }
  2333. static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
  2334. {
  2335. return mwl8k_cmd_radio_control(hw, 0, 0);
  2336. }
  2337. static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
  2338. {
  2339. return mwl8k_cmd_radio_control(hw, 1, 0);
  2340. }
  2341. static int
  2342. mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
  2343. {
  2344. struct mwl8k_priv *priv = hw->priv;
  2345. priv->radio_short_preamble = short_preamble;
  2346. return mwl8k_cmd_radio_control(hw, 1, 1);
  2347. }
  2348. /*
  2349. * CMD_RF_TX_POWER.
  2350. */
  2351. #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
  2352. struct mwl8k_cmd_rf_tx_power {
  2353. struct mwl8k_cmd_pkt header;
  2354. __le16 action;
  2355. __le16 support_level;
  2356. __le16 current_level;
  2357. __le16 reserved;
  2358. __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
  2359. } __packed;
  2360. static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
  2361. {
  2362. struct mwl8k_cmd_rf_tx_power *cmd;
  2363. int rc;
  2364. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2365. if (cmd == NULL)
  2366. return -ENOMEM;
  2367. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
  2368. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2369. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2370. cmd->support_level = cpu_to_le16(dBm);
  2371. rc = mwl8k_post_cmd(hw, &cmd->header);
  2372. kfree(cmd);
  2373. return rc;
  2374. }
  2375. /*
  2376. * CMD_TX_POWER.
  2377. */
  2378. #define MWL8K_TX_POWER_LEVEL_TOTAL 12
  2379. struct mwl8k_cmd_tx_power {
  2380. struct mwl8k_cmd_pkt header;
  2381. __le16 action;
  2382. __le16 band;
  2383. __le16 channel;
  2384. __le16 bw;
  2385. __le16 sub_ch;
  2386. __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
  2387. } __packed;
  2388. static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
  2389. struct ieee80211_conf *conf,
  2390. unsigned short pwr)
  2391. {
  2392. struct ieee80211_channel *channel = conf->chandef.chan;
  2393. enum nl80211_channel_type channel_type =
  2394. cfg80211_get_chandef_type(&conf->chandef);
  2395. struct mwl8k_cmd_tx_power *cmd;
  2396. int rc;
  2397. int i;
  2398. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2399. if (cmd == NULL)
  2400. return -ENOMEM;
  2401. cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
  2402. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2403. cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
  2404. if (channel->band == IEEE80211_BAND_2GHZ)
  2405. cmd->band = cpu_to_le16(0x1);
  2406. else if (channel->band == IEEE80211_BAND_5GHZ)
  2407. cmd->band = cpu_to_le16(0x4);
  2408. cmd->channel = cpu_to_le16(channel->hw_value);
  2409. if (channel_type == NL80211_CHAN_NO_HT ||
  2410. channel_type == NL80211_CHAN_HT20) {
  2411. cmd->bw = cpu_to_le16(0x2);
  2412. } else {
  2413. cmd->bw = cpu_to_le16(0x4);
  2414. if (channel_type == NL80211_CHAN_HT40MINUS)
  2415. cmd->sub_ch = cpu_to_le16(0x3);
  2416. else if (channel_type == NL80211_CHAN_HT40PLUS)
  2417. cmd->sub_ch = cpu_to_le16(0x1);
  2418. }
  2419. for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
  2420. cmd->power_level_list[i] = cpu_to_le16(pwr);
  2421. rc = mwl8k_post_cmd(hw, &cmd->header);
  2422. kfree(cmd);
  2423. return rc;
  2424. }
  2425. /*
  2426. * CMD_RF_ANTENNA.
  2427. */
  2428. struct mwl8k_cmd_rf_antenna {
  2429. struct mwl8k_cmd_pkt header;
  2430. __le16 antenna;
  2431. __le16 mode;
  2432. } __packed;
  2433. #define MWL8K_RF_ANTENNA_RX 1
  2434. #define MWL8K_RF_ANTENNA_TX 2
  2435. static int
  2436. mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
  2437. {
  2438. struct mwl8k_cmd_rf_antenna *cmd;
  2439. int rc;
  2440. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2441. if (cmd == NULL)
  2442. return -ENOMEM;
  2443. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
  2444. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2445. cmd->antenna = cpu_to_le16(antenna);
  2446. cmd->mode = cpu_to_le16(mask);
  2447. rc = mwl8k_post_cmd(hw, &cmd->header);
  2448. kfree(cmd);
  2449. return rc;
  2450. }
  2451. /*
  2452. * CMD_SET_BEACON.
  2453. */
  2454. struct mwl8k_cmd_set_beacon {
  2455. struct mwl8k_cmd_pkt header;
  2456. __le16 beacon_len;
  2457. __u8 beacon[0];
  2458. };
  2459. static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
  2460. struct ieee80211_vif *vif, u8 *beacon, int len)
  2461. {
  2462. struct mwl8k_cmd_set_beacon *cmd;
  2463. int rc;
  2464. cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
  2465. if (cmd == NULL)
  2466. return -ENOMEM;
  2467. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
  2468. cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
  2469. cmd->beacon_len = cpu_to_le16(len);
  2470. memcpy(cmd->beacon, beacon, len);
  2471. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2472. kfree(cmd);
  2473. return rc;
  2474. }
  2475. /*
  2476. * CMD_SET_PRE_SCAN.
  2477. */
  2478. struct mwl8k_cmd_set_pre_scan {
  2479. struct mwl8k_cmd_pkt header;
  2480. } __packed;
  2481. static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
  2482. {
  2483. struct mwl8k_cmd_set_pre_scan *cmd;
  2484. int rc;
  2485. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2486. if (cmd == NULL)
  2487. return -ENOMEM;
  2488. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
  2489. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2490. rc = mwl8k_post_cmd(hw, &cmd->header);
  2491. kfree(cmd);
  2492. return rc;
  2493. }
  2494. /*
  2495. * CMD_SET_POST_SCAN.
  2496. */
  2497. struct mwl8k_cmd_set_post_scan {
  2498. struct mwl8k_cmd_pkt header;
  2499. __le32 isibss;
  2500. __u8 bssid[ETH_ALEN];
  2501. } __packed;
  2502. static int
  2503. mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
  2504. {
  2505. struct mwl8k_cmd_set_post_scan *cmd;
  2506. int rc;
  2507. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2508. if (cmd == NULL)
  2509. return -ENOMEM;
  2510. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
  2511. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2512. cmd->isibss = 0;
  2513. memcpy(cmd->bssid, mac, ETH_ALEN);
  2514. rc = mwl8k_post_cmd(hw, &cmd->header);
  2515. kfree(cmd);
  2516. return rc;
  2517. }
  2518. /*
  2519. * CMD_SET_RF_CHANNEL.
  2520. */
  2521. struct mwl8k_cmd_set_rf_channel {
  2522. struct mwl8k_cmd_pkt header;
  2523. __le16 action;
  2524. __u8 current_channel;
  2525. __le32 channel_flags;
  2526. } __packed;
  2527. static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
  2528. struct ieee80211_conf *conf)
  2529. {
  2530. struct ieee80211_channel *channel = conf->chandef.chan;
  2531. enum nl80211_channel_type channel_type =
  2532. cfg80211_get_chandef_type(&conf->chandef);
  2533. struct mwl8k_cmd_set_rf_channel *cmd;
  2534. int rc;
  2535. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2536. if (cmd == NULL)
  2537. return -ENOMEM;
  2538. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
  2539. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2540. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2541. cmd->current_channel = channel->hw_value;
  2542. if (channel->band == IEEE80211_BAND_2GHZ)
  2543. cmd->channel_flags |= cpu_to_le32(0x00000001);
  2544. else if (channel->band == IEEE80211_BAND_5GHZ)
  2545. cmd->channel_flags |= cpu_to_le32(0x00000004);
  2546. if (channel_type == NL80211_CHAN_NO_HT ||
  2547. channel_type == NL80211_CHAN_HT20)
  2548. cmd->channel_flags |= cpu_to_le32(0x00000080);
  2549. else if (channel_type == NL80211_CHAN_HT40MINUS)
  2550. cmd->channel_flags |= cpu_to_le32(0x000001900);
  2551. else if (channel_type == NL80211_CHAN_HT40PLUS)
  2552. cmd->channel_flags |= cpu_to_le32(0x000000900);
  2553. rc = mwl8k_post_cmd(hw, &cmd->header);
  2554. kfree(cmd);
  2555. return rc;
  2556. }
  2557. /*
  2558. * CMD_SET_AID.
  2559. */
  2560. #define MWL8K_FRAME_PROT_DISABLED 0x00
  2561. #define MWL8K_FRAME_PROT_11G 0x07
  2562. #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
  2563. #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
  2564. struct mwl8k_cmd_update_set_aid {
  2565. struct mwl8k_cmd_pkt header;
  2566. __le16 aid;
  2567. /* AP's MAC address (BSSID) */
  2568. __u8 bssid[ETH_ALEN];
  2569. __le16 protection_mode;
  2570. __u8 supp_rates[14];
  2571. } __packed;
  2572. static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
  2573. {
  2574. int i;
  2575. int j;
  2576. /*
  2577. * Clear nonstandard rate 4.
  2578. */
  2579. mask &= 0x1fef;
  2580. for (i = 0, j = 0; i < 13; i++) {
  2581. if (mask & (1 << i))
  2582. rates[j++] = mwl8k_rates_24[i].hw_value;
  2583. }
  2584. }
  2585. static int
  2586. mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
  2587. struct ieee80211_vif *vif, u32 legacy_rate_mask)
  2588. {
  2589. struct mwl8k_cmd_update_set_aid *cmd;
  2590. u16 prot_mode;
  2591. int rc;
  2592. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2593. if (cmd == NULL)
  2594. return -ENOMEM;
  2595. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
  2596. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2597. cmd->aid = cpu_to_le16(vif->bss_conf.aid);
  2598. memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
  2599. if (vif->bss_conf.use_cts_prot) {
  2600. prot_mode = MWL8K_FRAME_PROT_11G;
  2601. } else {
  2602. switch (vif->bss_conf.ht_operation_mode &
  2603. IEEE80211_HT_OP_MODE_PROTECTION) {
  2604. case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
  2605. prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
  2606. break;
  2607. case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
  2608. prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
  2609. break;
  2610. default:
  2611. prot_mode = MWL8K_FRAME_PROT_DISABLED;
  2612. break;
  2613. }
  2614. }
  2615. cmd->protection_mode = cpu_to_le16(prot_mode);
  2616. legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
  2617. rc = mwl8k_post_cmd(hw, &cmd->header);
  2618. kfree(cmd);
  2619. return rc;
  2620. }
  2621. /*
  2622. * CMD_SET_RATE.
  2623. */
  2624. struct mwl8k_cmd_set_rate {
  2625. struct mwl8k_cmd_pkt header;
  2626. __u8 legacy_rates[14];
  2627. /* Bitmap for supported MCS codes. */
  2628. __u8 mcs_set[16];
  2629. __u8 reserved[16];
  2630. } __packed;
  2631. static int
  2632. mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  2633. u32 legacy_rate_mask, u8 *mcs_rates)
  2634. {
  2635. struct mwl8k_cmd_set_rate *cmd;
  2636. int rc;
  2637. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2638. if (cmd == NULL)
  2639. return -ENOMEM;
  2640. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
  2641. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2642. legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
  2643. memcpy(cmd->mcs_set, mcs_rates, 16);
  2644. rc = mwl8k_post_cmd(hw, &cmd->header);
  2645. kfree(cmd);
  2646. return rc;
  2647. }
  2648. /*
  2649. * CMD_FINALIZE_JOIN.
  2650. */
  2651. #define MWL8K_FJ_BEACON_MAXLEN 128
  2652. struct mwl8k_cmd_finalize_join {
  2653. struct mwl8k_cmd_pkt header;
  2654. __le32 sleep_interval; /* Number of beacon periods to sleep */
  2655. __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
  2656. } __packed;
  2657. static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
  2658. int framelen, int dtim)
  2659. {
  2660. struct mwl8k_cmd_finalize_join *cmd;
  2661. struct ieee80211_mgmt *payload = frame;
  2662. int payload_len;
  2663. int rc;
  2664. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2665. if (cmd == NULL)
  2666. return -ENOMEM;
  2667. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
  2668. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2669. cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
  2670. payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
  2671. if (payload_len < 0)
  2672. payload_len = 0;
  2673. else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
  2674. payload_len = MWL8K_FJ_BEACON_MAXLEN;
  2675. memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
  2676. rc = mwl8k_post_cmd(hw, &cmd->header);
  2677. kfree(cmd);
  2678. return rc;
  2679. }
  2680. /*
  2681. * CMD_SET_RTS_THRESHOLD.
  2682. */
  2683. struct mwl8k_cmd_set_rts_threshold {
  2684. struct mwl8k_cmd_pkt header;
  2685. __le16 action;
  2686. __le16 threshold;
  2687. } __packed;
  2688. static int
  2689. mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
  2690. {
  2691. struct mwl8k_cmd_set_rts_threshold *cmd;
  2692. int rc;
  2693. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2694. if (cmd == NULL)
  2695. return -ENOMEM;
  2696. cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
  2697. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2698. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2699. cmd->threshold = cpu_to_le16(rts_thresh);
  2700. rc = mwl8k_post_cmd(hw, &cmd->header);
  2701. kfree(cmd);
  2702. return rc;
  2703. }
  2704. /*
  2705. * CMD_SET_SLOT.
  2706. */
  2707. struct mwl8k_cmd_set_slot {
  2708. struct mwl8k_cmd_pkt header;
  2709. __le16 action;
  2710. __u8 short_slot;
  2711. } __packed;
  2712. static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
  2713. {
  2714. struct mwl8k_cmd_set_slot *cmd;
  2715. int rc;
  2716. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2717. if (cmd == NULL)
  2718. return -ENOMEM;
  2719. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
  2720. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2721. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2722. cmd->short_slot = short_slot_time;
  2723. rc = mwl8k_post_cmd(hw, &cmd->header);
  2724. kfree(cmd);
  2725. return rc;
  2726. }
  2727. /*
  2728. * CMD_SET_EDCA_PARAMS.
  2729. */
  2730. struct mwl8k_cmd_set_edca_params {
  2731. struct mwl8k_cmd_pkt header;
  2732. /* See MWL8K_SET_EDCA_XXX below */
  2733. __le16 action;
  2734. /* TX opportunity in units of 32 us */
  2735. __le16 txop;
  2736. union {
  2737. struct {
  2738. /* Log exponent of max contention period: 0...15 */
  2739. __le32 log_cw_max;
  2740. /* Log exponent of min contention period: 0...15 */
  2741. __le32 log_cw_min;
  2742. /* Adaptive interframe spacing in units of 32us */
  2743. __u8 aifs;
  2744. /* TX queue to configure */
  2745. __u8 txq;
  2746. } ap;
  2747. struct {
  2748. /* Log exponent of max contention period: 0...15 */
  2749. __u8 log_cw_max;
  2750. /* Log exponent of min contention period: 0...15 */
  2751. __u8 log_cw_min;
  2752. /* Adaptive interframe spacing in units of 32us */
  2753. __u8 aifs;
  2754. /* TX queue to configure */
  2755. __u8 txq;
  2756. } sta;
  2757. };
  2758. } __packed;
  2759. #define MWL8K_SET_EDCA_CW 0x01
  2760. #define MWL8K_SET_EDCA_TXOP 0x02
  2761. #define MWL8K_SET_EDCA_AIFS 0x04
  2762. #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
  2763. MWL8K_SET_EDCA_TXOP | \
  2764. MWL8K_SET_EDCA_AIFS)
  2765. static int
  2766. mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
  2767. __u16 cw_min, __u16 cw_max,
  2768. __u8 aifs, __u16 txop)
  2769. {
  2770. struct mwl8k_priv *priv = hw->priv;
  2771. struct mwl8k_cmd_set_edca_params *cmd;
  2772. int rc;
  2773. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2774. if (cmd == NULL)
  2775. return -ENOMEM;
  2776. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
  2777. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2778. cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
  2779. cmd->txop = cpu_to_le16(txop);
  2780. if (priv->ap_fw) {
  2781. cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
  2782. cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
  2783. cmd->ap.aifs = aifs;
  2784. cmd->ap.txq = qnum;
  2785. } else {
  2786. cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
  2787. cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
  2788. cmd->sta.aifs = aifs;
  2789. cmd->sta.txq = qnum;
  2790. }
  2791. rc = mwl8k_post_cmd(hw, &cmd->header);
  2792. kfree(cmd);
  2793. return rc;
  2794. }
  2795. /*
  2796. * CMD_SET_WMM_MODE.
  2797. */
  2798. struct mwl8k_cmd_set_wmm_mode {
  2799. struct mwl8k_cmd_pkt header;
  2800. __le16 action;
  2801. } __packed;
  2802. static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
  2803. {
  2804. struct mwl8k_priv *priv = hw->priv;
  2805. struct mwl8k_cmd_set_wmm_mode *cmd;
  2806. int rc;
  2807. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2808. if (cmd == NULL)
  2809. return -ENOMEM;
  2810. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
  2811. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2812. cmd->action = cpu_to_le16(!!enable);
  2813. rc = mwl8k_post_cmd(hw, &cmd->header);
  2814. kfree(cmd);
  2815. if (!rc)
  2816. priv->wmm_enabled = enable;
  2817. return rc;
  2818. }
  2819. /*
  2820. * CMD_MIMO_CONFIG.
  2821. */
  2822. struct mwl8k_cmd_mimo_config {
  2823. struct mwl8k_cmd_pkt header;
  2824. __le32 action;
  2825. __u8 rx_antenna_map;
  2826. __u8 tx_antenna_map;
  2827. } __packed;
  2828. static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
  2829. {
  2830. struct mwl8k_cmd_mimo_config *cmd;
  2831. int rc;
  2832. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2833. if (cmd == NULL)
  2834. return -ENOMEM;
  2835. cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
  2836. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2837. cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
  2838. cmd->rx_antenna_map = rx;
  2839. cmd->tx_antenna_map = tx;
  2840. rc = mwl8k_post_cmd(hw, &cmd->header);
  2841. kfree(cmd);
  2842. return rc;
  2843. }
  2844. /*
  2845. * CMD_USE_FIXED_RATE (STA version).
  2846. */
  2847. struct mwl8k_cmd_use_fixed_rate_sta {
  2848. struct mwl8k_cmd_pkt header;
  2849. __le32 action;
  2850. __le32 allow_rate_drop;
  2851. __le32 num_rates;
  2852. struct {
  2853. __le32 is_ht_rate;
  2854. __le32 enable_retry;
  2855. __le32 rate;
  2856. __le32 retry_count;
  2857. } rate_entry[8];
  2858. __le32 rate_type;
  2859. __le32 reserved1;
  2860. __le32 reserved2;
  2861. } __packed;
  2862. #define MWL8K_USE_AUTO_RATE 0x0002
  2863. #define MWL8K_UCAST_RATE 0
  2864. static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
  2865. {
  2866. struct mwl8k_cmd_use_fixed_rate_sta *cmd;
  2867. int rc;
  2868. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2869. if (cmd == NULL)
  2870. return -ENOMEM;
  2871. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  2872. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2873. cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
  2874. cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
  2875. rc = mwl8k_post_cmd(hw, &cmd->header);
  2876. kfree(cmd);
  2877. return rc;
  2878. }
  2879. /*
  2880. * CMD_USE_FIXED_RATE (AP version).
  2881. */
  2882. struct mwl8k_cmd_use_fixed_rate_ap {
  2883. struct mwl8k_cmd_pkt header;
  2884. __le32 action;
  2885. __le32 allow_rate_drop;
  2886. __le32 num_rates;
  2887. struct mwl8k_rate_entry_ap {
  2888. __le32 is_ht_rate;
  2889. __le32 enable_retry;
  2890. __le32 rate;
  2891. __le32 retry_count;
  2892. } rate_entry[4];
  2893. u8 multicast_rate;
  2894. u8 multicast_rate_type;
  2895. u8 management_rate;
  2896. } __packed;
  2897. static int
  2898. mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
  2899. {
  2900. struct mwl8k_cmd_use_fixed_rate_ap *cmd;
  2901. int rc;
  2902. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2903. if (cmd == NULL)
  2904. return -ENOMEM;
  2905. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  2906. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2907. cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
  2908. cmd->multicast_rate = mcast;
  2909. cmd->management_rate = mgmt;
  2910. rc = mwl8k_post_cmd(hw, &cmd->header);
  2911. kfree(cmd);
  2912. return rc;
  2913. }
  2914. /*
  2915. * CMD_ENABLE_SNIFFER.
  2916. */
  2917. struct mwl8k_cmd_enable_sniffer {
  2918. struct mwl8k_cmd_pkt header;
  2919. __le32 action;
  2920. } __packed;
  2921. static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
  2922. {
  2923. struct mwl8k_cmd_enable_sniffer *cmd;
  2924. int rc;
  2925. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2926. if (cmd == NULL)
  2927. return -ENOMEM;
  2928. cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
  2929. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2930. cmd->action = cpu_to_le32(!!enable);
  2931. rc = mwl8k_post_cmd(hw, &cmd->header);
  2932. kfree(cmd);
  2933. return rc;
  2934. }
  2935. struct mwl8k_cmd_update_mac_addr {
  2936. struct mwl8k_cmd_pkt header;
  2937. union {
  2938. struct {
  2939. __le16 mac_type;
  2940. __u8 mac_addr[ETH_ALEN];
  2941. } mbss;
  2942. __u8 mac_addr[ETH_ALEN];
  2943. };
  2944. } __packed;
  2945. #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
  2946. #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
  2947. #define MWL8K_MAC_TYPE_PRIMARY_AP 2
  2948. #define MWL8K_MAC_TYPE_SECONDARY_AP 3
  2949. static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw,
  2950. struct ieee80211_vif *vif, u8 *mac, bool set)
  2951. {
  2952. struct mwl8k_priv *priv = hw->priv;
  2953. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  2954. struct mwl8k_cmd_update_mac_addr *cmd;
  2955. int mac_type;
  2956. int rc;
  2957. mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
  2958. if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
  2959. if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
  2960. if (priv->ap_fw)
  2961. mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
  2962. else
  2963. mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
  2964. else
  2965. mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
  2966. } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
  2967. if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
  2968. mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
  2969. else
  2970. mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
  2971. }
  2972. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2973. if (cmd == NULL)
  2974. return -ENOMEM;
  2975. if (set)
  2976. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
  2977. else
  2978. cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR);
  2979. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2980. if (priv->ap_fw) {
  2981. cmd->mbss.mac_type = cpu_to_le16(mac_type);
  2982. memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
  2983. } else {
  2984. memcpy(cmd->mac_addr, mac, ETH_ALEN);
  2985. }
  2986. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2987. kfree(cmd);
  2988. return rc;
  2989. }
  2990. /*
  2991. * MWL8K_CMD_SET_MAC_ADDR.
  2992. */
  2993. static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
  2994. struct ieee80211_vif *vif, u8 *mac)
  2995. {
  2996. return mwl8k_cmd_update_mac_addr(hw, vif, mac, true);
  2997. }
  2998. /*
  2999. * MWL8K_CMD_DEL_MAC_ADDR.
  3000. */
  3001. static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw,
  3002. struct ieee80211_vif *vif, u8 *mac)
  3003. {
  3004. return mwl8k_cmd_update_mac_addr(hw, vif, mac, false);
  3005. }
  3006. /*
  3007. * CMD_SET_RATEADAPT_MODE.
  3008. */
  3009. struct mwl8k_cmd_set_rate_adapt_mode {
  3010. struct mwl8k_cmd_pkt header;
  3011. __le16 action;
  3012. __le16 mode;
  3013. } __packed;
  3014. static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
  3015. {
  3016. struct mwl8k_cmd_set_rate_adapt_mode *cmd;
  3017. int rc;
  3018. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3019. if (cmd == NULL)
  3020. return -ENOMEM;
  3021. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
  3022. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3023. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  3024. cmd->mode = cpu_to_le16(mode);
  3025. rc = mwl8k_post_cmd(hw, &cmd->header);
  3026. kfree(cmd);
  3027. return rc;
  3028. }
  3029. /*
  3030. * CMD_GET_WATCHDOG_BITMAP.
  3031. */
  3032. struct mwl8k_cmd_get_watchdog_bitmap {
  3033. struct mwl8k_cmd_pkt header;
  3034. u8 bitmap;
  3035. } __packed;
  3036. static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
  3037. {
  3038. struct mwl8k_cmd_get_watchdog_bitmap *cmd;
  3039. int rc;
  3040. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3041. if (cmd == NULL)
  3042. return -ENOMEM;
  3043. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
  3044. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3045. rc = mwl8k_post_cmd(hw, &cmd->header);
  3046. if (!rc)
  3047. *bitmap = cmd->bitmap;
  3048. kfree(cmd);
  3049. return rc;
  3050. }
  3051. #define MWL8K_WMM_QUEUE_NUMBER 3
  3052. static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
  3053. u8 idx);
  3054. static void mwl8k_watchdog_ba_events(struct work_struct *work)
  3055. {
  3056. int rc;
  3057. u8 bitmap = 0, stream_index;
  3058. struct mwl8k_ampdu_stream *streams;
  3059. struct mwl8k_priv *priv =
  3060. container_of(work, struct mwl8k_priv, watchdog_ba_handle);
  3061. struct ieee80211_hw *hw = priv->hw;
  3062. int i;
  3063. u32 status = 0;
  3064. mwl8k_fw_lock(hw);
  3065. rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
  3066. if (rc)
  3067. goto done;
  3068. spin_lock(&priv->stream_lock);
  3069. /* the bitmap is the hw queue number. Map it to the ampdu queue. */
  3070. for (i = 0; i < TOTAL_HW_TX_QUEUES; i++) {
  3071. if (bitmap & (1 << i)) {
  3072. stream_index = (i + MWL8K_WMM_QUEUE_NUMBER) %
  3073. TOTAL_HW_TX_QUEUES;
  3074. streams = &priv->ampdu[stream_index];
  3075. if (streams->state == AMPDU_STREAM_ACTIVE) {
  3076. ieee80211_stop_tx_ba_session(streams->sta,
  3077. streams->tid);
  3078. spin_unlock(&priv->stream_lock);
  3079. mwl8k_destroy_ba(hw, stream_index);
  3080. spin_lock(&priv->stream_lock);
  3081. }
  3082. }
  3083. }
  3084. spin_unlock(&priv->stream_lock);
  3085. done:
  3086. atomic_dec(&priv->watchdog_event_pending);
  3087. status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3088. iowrite32((status | MWL8K_A2H_INT_BA_WATCHDOG),
  3089. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3090. mwl8k_fw_unlock(hw);
  3091. return;
  3092. }
  3093. /*
  3094. * CMD_BSS_START.
  3095. */
  3096. struct mwl8k_cmd_bss_start {
  3097. struct mwl8k_cmd_pkt header;
  3098. __le32 enable;
  3099. } __packed;
  3100. static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
  3101. struct ieee80211_vif *vif, int enable)
  3102. {
  3103. struct mwl8k_cmd_bss_start *cmd;
  3104. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3105. struct mwl8k_priv *priv = hw->priv;
  3106. int rc;
  3107. if (enable && (priv->running_bsses & (1 << mwl8k_vif->macid)))
  3108. return 0;
  3109. if (!enable && !(priv->running_bsses & (1 << mwl8k_vif->macid)))
  3110. return 0;
  3111. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3112. if (cmd == NULL)
  3113. return -ENOMEM;
  3114. cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
  3115. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3116. cmd->enable = cpu_to_le32(enable);
  3117. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3118. kfree(cmd);
  3119. if (!rc) {
  3120. if (enable)
  3121. priv->running_bsses |= (1 << mwl8k_vif->macid);
  3122. else
  3123. priv->running_bsses &= ~(1 << mwl8k_vif->macid);
  3124. }
  3125. return rc;
  3126. }
  3127. static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable, u32 bitmap)
  3128. {
  3129. struct mwl8k_priv *priv = hw->priv;
  3130. struct mwl8k_vif *mwl8k_vif, *tmp_vif;
  3131. struct ieee80211_vif *vif;
  3132. list_for_each_entry_safe(mwl8k_vif, tmp_vif, &priv->vif_list, list) {
  3133. vif = mwl8k_vif->vif;
  3134. if (!(bitmap & (1 << mwl8k_vif->macid)))
  3135. continue;
  3136. if (vif->type == NL80211_IFTYPE_AP)
  3137. mwl8k_cmd_bss_start(hw, vif, enable);
  3138. }
  3139. }
  3140. /*
  3141. * CMD_BASTREAM.
  3142. */
  3143. /*
  3144. * UPSTREAM is tx direction
  3145. */
  3146. #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
  3147. #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
  3148. enum ba_stream_action_type {
  3149. MWL8K_BA_CREATE,
  3150. MWL8K_BA_UPDATE,
  3151. MWL8K_BA_DESTROY,
  3152. MWL8K_BA_FLUSH,
  3153. MWL8K_BA_CHECK,
  3154. };
  3155. struct mwl8k_create_ba_stream {
  3156. __le32 flags;
  3157. __le32 idle_thrs;
  3158. __le32 bar_thrs;
  3159. __le32 window_size;
  3160. u8 peer_mac_addr[6];
  3161. u8 dialog_token;
  3162. u8 tid;
  3163. u8 queue_id;
  3164. u8 param_info;
  3165. __le32 ba_context;
  3166. u8 reset_seq_no_flag;
  3167. __le16 curr_seq_no;
  3168. u8 sta_src_mac_addr[6];
  3169. } __packed;
  3170. struct mwl8k_destroy_ba_stream {
  3171. __le32 flags;
  3172. __le32 ba_context;
  3173. } __packed;
  3174. struct mwl8k_cmd_bastream {
  3175. struct mwl8k_cmd_pkt header;
  3176. __le32 action;
  3177. union {
  3178. struct mwl8k_create_ba_stream create_params;
  3179. struct mwl8k_destroy_ba_stream destroy_params;
  3180. };
  3181. } __packed;
  3182. static int
  3183. mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
  3184. struct ieee80211_vif *vif)
  3185. {
  3186. struct mwl8k_cmd_bastream *cmd;
  3187. int rc;
  3188. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3189. if (cmd == NULL)
  3190. return -ENOMEM;
  3191. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3192. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3193. cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
  3194. cmd->create_params.queue_id = stream->idx;
  3195. memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
  3196. ETH_ALEN);
  3197. cmd->create_params.tid = stream->tid;
  3198. cmd->create_params.flags =
  3199. cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
  3200. cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
  3201. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3202. kfree(cmd);
  3203. return rc;
  3204. }
  3205. static int
  3206. mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
  3207. u8 buf_size, struct ieee80211_vif *vif)
  3208. {
  3209. struct mwl8k_cmd_bastream *cmd;
  3210. int rc;
  3211. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3212. if (cmd == NULL)
  3213. return -ENOMEM;
  3214. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3215. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3216. cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
  3217. cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
  3218. cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
  3219. cmd->create_params.queue_id = stream->idx;
  3220. memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
  3221. cmd->create_params.tid = stream->tid;
  3222. cmd->create_params.curr_seq_no = cpu_to_le16(0);
  3223. cmd->create_params.reset_seq_no_flag = 1;
  3224. cmd->create_params.param_info =
  3225. (stream->sta->ht_cap.ampdu_factor &
  3226. IEEE80211_HT_AMPDU_PARM_FACTOR) |
  3227. ((stream->sta->ht_cap.ampdu_density << 2) &
  3228. IEEE80211_HT_AMPDU_PARM_DENSITY);
  3229. cmd->create_params.flags =
  3230. cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
  3231. BASTREAM_FLAG_DIRECTION_UPSTREAM);
  3232. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3233. wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
  3234. stream->sta->addr, stream->tid);
  3235. kfree(cmd);
  3236. return rc;
  3237. }
  3238. static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
  3239. u8 idx)
  3240. {
  3241. struct mwl8k_cmd_bastream *cmd;
  3242. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3243. if (cmd == NULL)
  3244. return;
  3245. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3246. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3247. cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
  3248. cmd->destroy_params.ba_context = cpu_to_le32(idx);
  3249. mwl8k_post_cmd(hw, &cmd->header);
  3250. wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", idx);
  3251. kfree(cmd);
  3252. }
  3253. /*
  3254. * CMD_SET_NEW_STN.
  3255. */
  3256. struct mwl8k_cmd_set_new_stn {
  3257. struct mwl8k_cmd_pkt header;
  3258. __le16 aid;
  3259. __u8 mac_addr[6];
  3260. __le16 stn_id;
  3261. __le16 action;
  3262. __le16 rsvd;
  3263. __le32 legacy_rates;
  3264. __u8 ht_rates[4];
  3265. __le16 cap_info;
  3266. __le16 ht_capabilities_info;
  3267. __u8 mac_ht_param_info;
  3268. __u8 rev;
  3269. __u8 control_channel;
  3270. __u8 add_channel;
  3271. __le16 op_mode;
  3272. __le16 stbc;
  3273. __u8 add_qos_info;
  3274. __u8 is_qos_sta;
  3275. __le32 fw_sta_ptr;
  3276. } __packed;
  3277. #define MWL8K_STA_ACTION_ADD 0
  3278. #define MWL8K_STA_ACTION_REMOVE 2
  3279. static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
  3280. struct ieee80211_vif *vif,
  3281. struct ieee80211_sta *sta)
  3282. {
  3283. struct mwl8k_cmd_set_new_stn *cmd;
  3284. u32 rates;
  3285. int rc;
  3286. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3287. if (cmd == NULL)
  3288. return -ENOMEM;
  3289. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3290. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3291. cmd->aid = cpu_to_le16(sta->aid);
  3292. memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
  3293. cmd->stn_id = cpu_to_le16(sta->aid);
  3294. cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
  3295. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  3296. rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
  3297. else
  3298. rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  3299. cmd->legacy_rates = cpu_to_le32(rates);
  3300. if (sta->ht_cap.ht_supported) {
  3301. cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
  3302. cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
  3303. cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
  3304. cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
  3305. cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
  3306. cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
  3307. ((sta->ht_cap.ampdu_density & 7) << 2);
  3308. cmd->is_qos_sta = 1;
  3309. }
  3310. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3311. kfree(cmd);
  3312. return rc;
  3313. }
  3314. static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
  3315. struct ieee80211_vif *vif)
  3316. {
  3317. struct mwl8k_cmd_set_new_stn *cmd;
  3318. int rc;
  3319. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3320. if (cmd == NULL)
  3321. return -ENOMEM;
  3322. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3323. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3324. memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
  3325. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3326. kfree(cmd);
  3327. return rc;
  3328. }
  3329. static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
  3330. struct ieee80211_vif *vif, u8 *addr)
  3331. {
  3332. struct mwl8k_cmd_set_new_stn *cmd;
  3333. struct mwl8k_priv *priv = hw->priv;
  3334. int rc, i;
  3335. u8 idx;
  3336. spin_lock(&priv->stream_lock);
  3337. /* Destroy any active ampdu streams for this sta */
  3338. for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
  3339. struct mwl8k_ampdu_stream *s;
  3340. s = &priv->ampdu[i];
  3341. if (s->state != AMPDU_NO_STREAM) {
  3342. if (memcmp(s->sta->addr, addr, ETH_ALEN) == 0) {
  3343. if (s->state == AMPDU_STREAM_ACTIVE) {
  3344. idx = s->idx;
  3345. spin_unlock(&priv->stream_lock);
  3346. mwl8k_destroy_ba(hw, idx);
  3347. spin_lock(&priv->stream_lock);
  3348. } else if (s->state == AMPDU_STREAM_NEW) {
  3349. mwl8k_remove_stream(hw, s);
  3350. }
  3351. }
  3352. }
  3353. }
  3354. spin_unlock(&priv->stream_lock);
  3355. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3356. if (cmd == NULL)
  3357. return -ENOMEM;
  3358. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3359. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3360. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3361. cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
  3362. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3363. kfree(cmd);
  3364. return rc;
  3365. }
  3366. /*
  3367. * CMD_UPDATE_ENCRYPTION.
  3368. */
  3369. #define MAX_ENCR_KEY_LENGTH 16
  3370. #define MIC_KEY_LENGTH 8
  3371. struct mwl8k_cmd_update_encryption {
  3372. struct mwl8k_cmd_pkt header;
  3373. __le32 action;
  3374. __le32 reserved;
  3375. __u8 mac_addr[6];
  3376. __u8 encr_type;
  3377. } __packed;
  3378. struct mwl8k_cmd_set_key {
  3379. struct mwl8k_cmd_pkt header;
  3380. __le32 action;
  3381. __le32 reserved;
  3382. __le16 length;
  3383. __le16 key_type_id;
  3384. __le32 key_info;
  3385. __le32 key_id;
  3386. __le16 key_len;
  3387. __u8 key_material[MAX_ENCR_KEY_LENGTH];
  3388. __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
  3389. __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
  3390. __le16 tkip_rsc_low;
  3391. __le32 tkip_rsc_high;
  3392. __le16 tkip_tsc_low;
  3393. __le32 tkip_tsc_high;
  3394. __u8 mac_addr[6];
  3395. } __packed;
  3396. enum {
  3397. MWL8K_ENCR_ENABLE,
  3398. MWL8K_ENCR_SET_KEY,
  3399. MWL8K_ENCR_REMOVE_KEY,
  3400. MWL8K_ENCR_SET_GROUP_KEY,
  3401. };
  3402. #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
  3403. #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
  3404. #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
  3405. #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
  3406. #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
  3407. enum {
  3408. MWL8K_ALG_WEP,
  3409. MWL8K_ALG_TKIP,
  3410. MWL8K_ALG_CCMP,
  3411. };
  3412. #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
  3413. #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
  3414. #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
  3415. #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
  3416. #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
  3417. static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
  3418. struct ieee80211_vif *vif,
  3419. u8 *addr,
  3420. u8 encr_type)
  3421. {
  3422. struct mwl8k_cmd_update_encryption *cmd;
  3423. int rc;
  3424. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3425. if (cmd == NULL)
  3426. return -ENOMEM;
  3427. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
  3428. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3429. cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
  3430. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3431. cmd->encr_type = encr_type;
  3432. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3433. kfree(cmd);
  3434. return rc;
  3435. }
  3436. static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
  3437. u8 *addr,
  3438. struct ieee80211_key_conf *key)
  3439. {
  3440. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
  3441. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3442. cmd->length = cpu_to_le16(sizeof(*cmd) -
  3443. offsetof(struct mwl8k_cmd_set_key, length));
  3444. cmd->key_id = cpu_to_le32(key->keyidx);
  3445. cmd->key_len = cpu_to_le16(key->keylen);
  3446. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3447. switch (key->cipher) {
  3448. case WLAN_CIPHER_SUITE_WEP40:
  3449. case WLAN_CIPHER_SUITE_WEP104:
  3450. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
  3451. if (key->keyidx == 0)
  3452. cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
  3453. break;
  3454. case WLAN_CIPHER_SUITE_TKIP:
  3455. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
  3456. cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3457. ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
  3458. : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
  3459. cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
  3460. | MWL8K_KEY_FLAG_TSC_VALID);
  3461. break;
  3462. case WLAN_CIPHER_SUITE_CCMP:
  3463. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
  3464. cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3465. ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
  3466. : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
  3467. break;
  3468. default:
  3469. return -ENOTSUPP;
  3470. }
  3471. return 0;
  3472. }
  3473. static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
  3474. struct ieee80211_vif *vif,
  3475. u8 *addr,
  3476. struct ieee80211_key_conf *key)
  3477. {
  3478. struct mwl8k_cmd_set_key *cmd;
  3479. int rc;
  3480. int keymlen;
  3481. u32 action;
  3482. u8 idx;
  3483. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3484. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3485. if (cmd == NULL)
  3486. return -ENOMEM;
  3487. rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
  3488. if (rc < 0)
  3489. goto done;
  3490. idx = key->keyidx;
  3491. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3492. action = MWL8K_ENCR_SET_KEY;
  3493. else
  3494. action = MWL8K_ENCR_SET_GROUP_KEY;
  3495. switch (key->cipher) {
  3496. case WLAN_CIPHER_SUITE_WEP40:
  3497. case WLAN_CIPHER_SUITE_WEP104:
  3498. if (!mwl8k_vif->wep_key_conf[idx].enabled) {
  3499. memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
  3500. sizeof(*key) + key->keylen);
  3501. mwl8k_vif->wep_key_conf[idx].enabled = 1;
  3502. }
  3503. keymlen = key->keylen;
  3504. action = MWL8K_ENCR_SET_KEY;
  3505. break;
  3506. case WLAN_CIPHER_SUITE_TKIP:
  3507. keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
  3508. break;
  3509. case WLAN_CIPHER_SUITE_CCMP:
  3510. keymlen = key->keylen;
  3511. break;
  3512. default:
  3513. rc = -ENOTSUPP;
  3514. goto done;
  3515. }
  3516. memcpy(cmd->key_material, key->key, keymlen);
  3517. cmd->action = cpu_to_le32(action);
  3518. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3519. done:
  3520. kfree(cmd);
  3521. return rc;
  3522. }
  3523. static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
  3524. struct ieee80211_vif *vif,
  3525. u8 *addr,
  3526. struct ieee80211_key_conf *key)
  3527. {
  3528. struct mwl8k_cmd_set_key *cmd;
  3529. int rc;
  3530. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3531. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3532. if (cmd == NULL)
  3533. return -ENOMEM;
  3534. rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
  3535. if (rc < 0)
  3536. goto done;
  3537. if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  3538. key->cipher == WLAN_CIPHER_SUITE_WEP104)
  3539. mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
  3540. cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
  3541. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3542. done:
  3543. kfree(cmd);
  3544. return rc;
  3545. }
  3546. static int mwl8k_set_key(struct ieee80211_hw *hw,
  3547. enum set_key_cmd cmd_param,
  3548. struct ieee80211_vif *vif,
  3549. struct ieee80211_sta *sta,
  3550. struct ieee80211_key_conf *key)
  3551. {
  3552. int rc = 0;
  3553. u8 encr_type;
  3554. u8 *addr;
  3555. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3556. struct mwl8k_priv *priv = hw->priv;
  3557. if (vif->type == NL80211_IFTYPE_STATION && !priv->ap_fw)
  3558. return -EOPNOTSUPP;
  3559. if (sta == NULL)
  3560. addr = vif->addr;
  3561. else
  3562. addr = sta->addr;
  3563. if (cmd_param == SET_KEY) {
  3564. rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
  3565. if (rc)
  3566. goto out;
  3567. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
  3568. || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
  3569. encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
  3570. else
  3571. encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
  3572. rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
  3573. encr_type);
  3574. if (rc)
  3575. goto out;
  3576. mwl8k_vif->is_hw_crypto_enabled = true;
  3577. } else {
  3578. rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
  3579. if (rc)
  3580. goto out;
  3581. }
  3582. out:
  3583. return rc;
  3584. }
  3585. /*
  3586. * CMD_UPDATE_STADB.
  3587. */
  3588. struct ewc_ht_info {
  3589. __le16 control1;
  3590. __le16 control2;
  3591. __le16 control3;
  3592. } __packed;
  3593. struct peer_capability_info {
  3594. /* Peer type - AP vs. STA. */
  3595. __u8 peer_type;
  3596. /* Basic 802.11 capabilities from assoc resp. */
  3597. __le16 basic_caps;
  3598. /* Set if peer supports 802.11n high throughput (HT). */
  3599. __u8 ht_support;
  3600. /* Valid if HT is supported. */
  3601. __le16 ht_caps;
  3602. __u8 extended_ht_caps;
  3603. struct ewc_ht_info ewc_info;
  3604. /* Legacy rate table. Intersection of our rates and peer rates. */
  3605. __u8 legacy_rates[12];
  3606. /* HT rate table. Intersection of our rates and peer rates. */
  3607. __u8 ht_rates[16];
  3608. __u8 pad[16];
  3609. /* If set, interoperability mode, no proprietary extensions. */
  3610. __u8 interop;
  3611. __u8 pad2;
  3612. __u8 station_id;
  3613. __le16 amsdu_enabled;
  3614. } __packed;
  3615. struct mwl8k_cmd_update_stadb {
  3616. struct mwl8k_cmd_pkt header;
  3617. /* See STADB_ACTION_TYPE */
  3618. __le32 action;
  3619. /* Peer MAC address */
  3620. __u8 peer_addr[ETH_ALEN];
  3621. __le32 reserved;
  3622. /* Peer info - valid during add/update. */
  3623. struct peer_capability_info peer_info;
  3624. } __packed;
  3625. #define MWL8K_STA_DB_MODIFY_ENTRY 1
  3626. #define MWL8K_STA_DB_DEL_ENTRY 2
  3627. /* Peer Entry flags - used to define the type of the peer node */
  3628. #define MWL8K_PEER_TYPE_ACCESSPOINT 2
  3629. static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
  3630. struct ieee80211_vif *vif,
  3631. struct ieee80211_sta *sta)
  3632. {
  3633. struct mwl8k_cmd_update_stadb *cmd;
  3634. struct peer_capability_info *p;
  3635. u32 rates;
  3636. int rc;
  3637. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3638. if (cmd == NULL)
  3639. return -ENOMEM;
  3640. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  3641. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3642. cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
  3643. memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
  3644. p = &cmd->peer_info;
  3645. p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
  3646. p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
  3647. p->ht_support = sta->ht_cap.ht_supported;
  3648. p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
  3649. p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
  3650. ((sta->ht_cap.ampdu_density & 7) << 2);
  3651. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  3652. rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
  3653. else
  3654. rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  3655. legacy_rate_mask_to_array(p->legacy_rates, rates);
  3656. memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
  3657. p->interop = 1;
  3658. p->amsdu_enabled = 0;
  3659. rc = mwl8k_post_cmd(hw, &cmd->header);
  3660. if (!rc)
  3661. rc = p->station_id;
  3662. kfree(cmd);
  3663. return rc;
  3664. }
  3665. static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
  3666. struct ieee80211_vif *vif, u8 *addr)
  3667. {
  3668. struct mwl8k_cmd_update_stadb *cmd;
  3669. int rc;
  3670. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3671. if (cmd == NULL)
  3672. return -ENOMEM;
  3673. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  3674. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3675. cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
  3676. memcpy(cmd->peer_addr, addr, ETH_ALEN);
  3677. rc = mwl8k_post_cmd(hw, &cmd->header);
  3678. kfree(cmd);
  3679. return rc;
  3680. }
  3681. /*
  3682. * Interrupt handling.
  3683. */
  3684. static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
  3685. {
  3686. struct ieee80211_hw *hw = dev_id;
  3687. struct mwl8k_priv *priv = hw->priv;
  3688. u32 status;
  3689. status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3690. if (!status)
  3691. return IRQ_NONE;
  3692. if (status & MWL8K_A2H_INT_TX_DONE) {
  3693. status &= ~MWL8K_A2H_INT_TX_DONE;
  3694. tasklet_schedule(&priv->poll_tx_task);
  3695. }
  3696. if (status & MWL8K_A2H_INT_RX_READY) {
  3697. status &= ~MWL8K_A2H_INT_RX_READY;
  3698. tasklet_schedule(&priv->poll_rx_task);
  3699. }
  3700. if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
  3701. iowrite32(~MWL8K_A2H_INT_BA_WATCHDOG,
  3702. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3703. atomic_inc(&priv->watchdog_event_pending);
  3704. status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
  3705. ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
  3706. }
  3707. if (status)
  3708. iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3709. if (status & MWL8K_A2H_INT_OPC_DONE) {
  3710. if (priv->hostcmd_wait != NULL)
  3711. complete(priv->hostcmd_wait);
  3712. }
  3713. if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
  3714. if (!mutex_is_locked(&priv->fw_mutex) &&
  3715. priv->radio_on && priv->pending_tx_pkts)
  3716. mwl8k_tx_start(priv);
  3717. }
  3718. return IRQ_HANDLED;
  3719. }
  3720. static void mwl8k_tx_poll(unsigned long data)
  3721. {
  3722. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  3723. struct mwl8k_priv *priv = hw->priv;
  3724. int limit;
  3725. int i;
  3726. limit = 32;
  3727. spin_lock_bh(&priv->tx_lock);
  3728. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  3729. limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
  3730. if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
  3731. complete(priv->tx_wait);
  3732. priv->tx_wait = NULL;
  3733. }
  3734. spin_unlock_bh(&priv->tx_lock);
  3735. if (limit) {
  3736. writel(~MWL8K_A2H_INT_TX_DONE,
  3737. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3738. } else {
  3739. tasklet_schedule(&priv->poll_tx_task);
  3740. }
  3741. }
  3742. static void mwl8k_rx_poll(unsigned long data)
  3743. {
  3744. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  3745. struct mwl8k_priv *priv = hw->priv;
  3746. int limit;
  3747. limit = 32;
  3748. limit -= rxq_process(hw, 0, limit);
  3749. limit -= rxq_refill(hw, 0, limit);
  3750. if (limit) {
  3751. writel(~MWL8K_A2H_INT_RX_READY,
  3752. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3753. } else {
  3754. tasklet_schedule(&priv->poll_rx_task);
  3755. }
  3756. }
  3757. /*
  3758. * Core driver operations.
  3759. */
  3760. static void mwl8k_tx(struct ieee80211_hw *hw,
  3761. struct ieee80211_tx_control *control,
  3762. struct sk_buff *skb)
  3763. {
  3764. struct mwl8k_priv *priv = hw->priv;
  3765. int index = skb_get_queue_mapping(skb);
  3766. if (!priv->radio_on) {
  3767. wiphy_debug(hw->wiphy,
  3768. "dropped TX frame since radio disabled\n");
  3769. dev_kfree_skb(skb);
  3770. return;
  3771. }
  3772. mwl8k_txq_xmit(hw, index, control->sta, skb);
  3773. }
  3774. static int mwl8k_start(struct ieee80211_hw *hw)
  3775. {
  3776. struct mwl8k_priv *priv = hw->priv;
  3777. int rc;
  3778. rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
  3779. IRQF_SHARED, MWL8K_NAME, hw);
  3780. if (rc) {
  3781. priv->irq = -1;
  3782. wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
  3783. return -EIO;
  3784. }
  3785. priv->irq = priv->pdev->irq;
  3786. /* Enable TX reclaim and RX tasklets. */
  3787. tasklet_enable(&priv->poll_tx_task);
  3788. tasklet_enable(&priv->poll_rx_task);
  3789. /* Enable interrupts */
  3790. iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3791. iowrite32(MWL8K_A2H_EVENTS,
  3792. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3793. rc = mwl8k_fw_lock(hw);
  3794. if (!rc) {
  3795. rc = mwl8k_cmd_radio_enable(hw);
  3796. if (!priv->ap_fw) {
  3797. if (!rc)
  3798. rc = mwl8k_cmd_enable_sniffer(hw, 0);
  3799. if (!rc)
  3800. rc = mwl8k_cmd_set_pre_scan(hw);
  3801. if (!rc)
  3802. rc = mwl8k_cmd_set_post_scan(hw,
  3803. "\x00\x00\x00\x00\x00\x00");
  3804. }
  3805. if (!rc)
  3806. rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
  3807. if (!rc)
  3808. rc = mwl8k_cmd_set_wmm_mode(hw, 0);
  3809. mwl8k_fw_unlock(hw);
  3810. }
  3811. if (rc) {
  3812. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3813. free_irq(priv->pdev->irq, hw);
  3814. priv->irq = -1;
  3815. tasklet_disable(&priv->poll_tx_task);
  3816. tasklet_disable(&priv->poll_rx_task);
  3817. } else {
  3818. ieee80211_wake_queues(hw);
  3819. }
  3820. return rc;
  3821. }
  3822. static void mwl8k_stop(struct ieee80211_hw *hw)
  3823. {
  3824. struct mwl8k_priv *priv = hw->priv;
  3825. int i;
  3826. if (!priv->hw_restart_in_progress)
  3827. mwl8k_cmd_radio_disable(hw);
  3828. ieee80211_stop_queues(hw);
  3829. /* Disable interrupts */
  3830. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3831. if (priv->irq != -1) {
  3832. free_irq(priv->pdev->irq, hw);
  3833. priv->irq = -1;
  3834. }
  3835. /* Stop finalize join worker */
  3836. cancel_work_sync(&priv->finalize_join_worker);
  3837. cancel_work_sync(&priv->watchdog_ba_handle);
  3838. if (priv->beacon_skb != NULL)
  3839. dev_kfree_skb(priv->beacon_skb);
  3840. /* Stop TX reclaim and RX tasklets. */
  3841. tasklet_disable(&priv->poll_tx_task);
  3842. tasklet_disable(&priv->poll_rx_task);
  3843. /* Return all skbs to mac80211 */
  3844. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  3845. mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  3846. }
  3847. static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
  3848. static int mwl8k_add_interface(struct ieee80211_hw *hw,
  3849. struct ieee80211_vif *vif)
  3850. {
  3851. struct mwl8k_priv *priv = hw->priv;
  3852. struct mwl8k_vif *mwl8k_vif;
  3853. u32 macids_supported;
  3854. int macid, rc;
  3855. struct mwl8k_device_info *di;
  3856. /*
  3857. * Reject interface creation if sniffer mode is active, as
  3858. * STA operation is mutually exclusive with hardware sniffer
  3859. * mode. (Sniffer mode is only used on STA firmware.)
  3860. */
  3861. if (priv->sniffer_enabled) {
  3862. wiphy_info(hw->wiphy,
  3863. "unable to create STA interface because sniffer mode is enabled\n");
  3864. return -EINVAL;
  3865. }
  3866. di = priv->device_info;
  3867. switch (vif->type) {
  3868. case NL80211_IFTYPE_AP:
  3869. if (!priv->ap_fw && di->fw_image_ap) {
  3870. /* we must load the ap fw to meet this request */
  3871. if (!list_empty(&priv->vif_list))
  3872. return -EBUSY;
  3873. rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
  3874. if (rc)
  3875. return rc;
  3876. }
  3877. macids_supported = priv->ap_macids_supported;
  3878. break;
  3879. case NL80211_IFTYPE_STATION:
  3880. if (priv->ap_fw && di->fw_image_sta) {
  3881. if (!list_empty(&priv->vif_list)) {
  3882. wiphy_warn(hw->wiphy, "AP interface is running.\n"
  3883. "Adding STA interface for WDS");
  3884. } else {
  3885. /* we must load the sta fw to
  3886. * meet this request.
  3887. */
  3888. rc = mwl8k_reload_firmware(hw,
  3889. di->fw_image_sta);
  3890. if (rc)
  3891. return rc;
  3892. }
  3893. }
  3894. macids_supported = priv->sta_macids_supported;
  3895. break;
  3896. default:
  3897. return -EINVAL;
  3898. }
  3899. macid = ffs(macids_supported & ~priv->macids_used);
  3900. if (!macid--)
  3901. return -EBUSY;
  3902. /* Setup driver private area. */
  3903. mwl8k_vif = MWL8K_VIF(vif);
  3904. memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
  3905. mwl8k_vif->vif = vif;
  3906. mwl8k_vif->macid = macid;
  3907. mwl8k_vif->seqno = 0;
  3908. memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
  3909. mwl8k_vif->is_hw_crypto_enabled = false;
  3910. /* Set the mac address. */
  3911. mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
  3912. if (vif->type == NL80211_IFTYPE_AP)
  3913. mwl8k_cmd_set_new_stn_add_self(hw, vif);
  3914. priv->macids_used |= 1 << mwl8k_vif->macid;
  3915. list_add_tail(&mwl8k_vif->list, &priv->vif_list);
  3916. return 0;
  3917. }
  3918. static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif)
  3919. {
  3920. /* Has ieee80211_restart_hw re-added the removed interfaces? */
  3921. if (!priv->macids_used)
  3922. return;
  3923. priv->macids_used &= ~(1 << vif->macid);
  3924. list_del(&vif->list);
  3925. }
  3926. static void mwl8k_remove_interface(struct ieee80211_hw *hw,
  3927. struct ieee80211_vif *vif)
  3928. {
  3929. struct mwl8k_priv *priv = hw->priv;
  3930. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3931. if (vif->type == NL80211_IFTYPE_AP)
  3932. mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
  3933. mwl8k_cmd_del_mac_addr(hw, vif, vif->addr);
  3934. mwl8k_remove_vif(priv, mwl8k_vif);
  3935. }
  3936. static void mwl8k_hw_restart_work(struct work_struct *work)
  3937. {
  3938. struct mwl8k_priv *priv =
  3939. container_of(work, struct mwl8k_priv, fw_reload);
  3940. struct ieee80211_hw *hw = priv->hw;
  3941. struct mwl8k_device_info *di;
  3942. int rc;
  3943. /* If some command is waiting for a response, clear it */
  3944. if (priv->hostcmd_wait != NULL) {
  3945. complete(priv->hostcmd_wait);
  3946. priv->hostcmd_wait = NULL;
  3947. }
  3948. priv->hw_restart_owner = current;
  3949. di = priv->device_info;
  3950. mwl8k_fw_lock(hw);
  3951. if (priv->ap_fw)
  3952. rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
  3953. else
  3954. rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
  3955. if (rc)
  3956. goto fail;
  3957. priv->hw_restart_owner = NULL;
  3958. priv->hw_restart_in_progress = false;
  3959. /*
  3960. * This unlock will wake up the queues and
  3961. * also opens the command path for other
  3962. * commands
  3963. */
  3964. mwl8k_fw_unlock(hw);
  3965. ieee80211_restart_hw(hw);
  3966. wiphy_err(hw->wiphy, "Firmware restarted successfully\n");
  3967. return;
  3968. fail:
  3969. mwl8k_fw_unlock(hw);
  3970. wiphy_err(hw->wiphy, "Firmware restart failed\n");
  3971. }
  3972. static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
  3973. {
  3974. struct ieee80211_conf *conf = &hw->conf;
  3975. struct mwl8k_priv *priv = hw->priv;
  3976. int rc;
  3977. rc = mwl8k_fw_lock(hw);
  3978. if (rc)
  3979. return rc;
  3980. if (conf->flags & IEEE80211_CONF_IDLE)
  3981. rc = mwl8k_cmd_radio_disable(hw);
  3982. else
  3983. rc = mwl8k_cmd_radio_enable(hw);
  3984. if (rc)
  3985. goto out;
  3986. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  3987. rc = mwl8k_cmd_set_rf_channel(hw, conf);
  3988. if (rc)
  3989. goto out;
  3990. }
  3991. if (conf->power_level > 18)
  3992. conf->power_level = 18;
  3993. if (priv->ap_fw) {
  3994. if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
  3995. rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
  3996. if (rc)
  3997. goto out;
  3998. }
  3999. } else {
  4000. rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
  4001. if (rc)
  4002. goto out;
  4003. rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
  4004. }
  4005. out:
  4006. mwl8k_fw_unlock(hw);
  4007. return rc;
  4008. }
  4009. static void
  4010. mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4011. struct ieee80211_bss_conf *info, u32 changed)
  4012. {
  4013. struct mwl8k_priv *priv = hw->priv;
  4014. u32 ap_legacy_rates = 0;
  4015. u8 ap_mcs_rates[16];
  4016. int rc;
  4017. if (mwl8k_fw_lock(hw))
  4018. return;
  4019. /*
  4020. * No need to capture a beacon if we're no longer associated.
  4021. */
  4022. if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
  4023. priv->capture_beacon = false;
  4024. /*
  4025. * Get the AP's legacy and MCS rates.
  4026. */
  4027. if (vif->bss_conf.assoc) {
  4028. struct ieee80211_sta *ap;
  4029. rcu_read_lock();
  4030. ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
  4031. if (ap == NULL) {
  4032. rcu_read_unlock();
  4033. goto out;
  4034. }
  4035. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) {
  4036. ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
  4037. } else {
  4038. ap_legacy_rates =
  4039. ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  4040. }
  4041. memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
  4042. rcu_read_unlock();
  4043. }
  4044. if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc &&
  4045. !priv->ap_fw) {
  4046. rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
  4047. if (rc)
  4048. goto out;
  4049. rc = mwl8k_cmd_use_fixed_rate_sta(hw);
  4050. if (rc)
  4051. goto out;
  4052. } else {
  4053. if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc &&
  4054. priv->ap_fw) {
  4055. int idx;
  4056. int rate;
  4057. /* Use AP firmware specific rate command.
  4058. */
  4059. idx = ffs(vif->bss_conf.basic_rates);
  4060. if (idx)
  4061. idx--;
  4062. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  4063. rate = mwl8k_rates_24[idx].hw_value;
  4064. else
  4065. rate = mwl8k_rates_50[idx].hw_value;
  4066. mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
  4067. }
  4068. }
  4069. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  4070. rc = mwl8k_set_radio_preamble(hw,
  4071. vif->bss_conf.use_short_preamble);
  4072. if (rc)
  4073. goto out;
  4074. }
  4075. if ((changed & BSS_CHANGED_ERP_SLOT) && !priv->ap_fw) {
  4076. rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
  4077. if (rc)
  4078. goto out;
  4079. }
  4080. if (vif->bss_conf.assoc && !priv->ap_fw &&
  4081. (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
  4082. BSS_CHANGED_HT))) {
  4083. rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
  4084. if (rc)
  4085. goto out;
  4086. }
  4087. if (vif->bss_conf.assoc &&
  4088. (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
  4089. /*
  4090. * Finalize the join. Tell rx handler to process
  4091. * next beacon from our BSSID.
  4092. */
  4093. memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
  4094. priv->capture_beacon = true;
  4095. }
  4096. out:
  4097. mwl8k_fw_unlock(hw);
  4098. }
  4099. static void
  4100. mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4101. struct ieee80211_bss_conf *info, u32 changed)
  4102. {
  4103. int rc;
  4104. if (mwl8k_fw_lock(hw))
  4105. return;
  4106. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  4107. rc = mwl8k_set_radio_preamble(hw,
  4108. vif->bss_conf.use_short_preamble);
  4109. if (rc)
  4110. goto out;
  4111. }
  4112. if (changed & BSS_CHANGED_BASIC_RATES) {
  4113. int idx;
  4114. int rate;
  4115. /*
  4116. * Use lowest supported basic rate for multicasts
  4117. * and management frames (such as probe responses --
  4118. * beacons will always go out at 1 Mb/s).
  4119. */
  4120. idx = ffs(vif->bss_conf.basic_rates);
  4121. if (idx)
  4122. idx--;
  4123. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  4124. rate = mwl8k_rates_24[idx].hw_value;
  4125. else
  4126. rate = mwl8k_rates_50[idx].hw_value;
  4127. mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
  4128. }
  4129. if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
  4130. struct sk_buff *skb;
  4131. skb = ieee80211_beacon_get(hw, vif);
  4132. if (skb != NULL) {
  4133. mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
  4134. kfree_skb(skb);
  4135. }
  4136. }
  4137. if (changed & BSS_CHANGED_BEACON_ENABLED)
  4138. mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
  4139. out:
  4140. mwl8k_fw_unlock(hw);
  4141. }
  4142. static void
  4143. mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4144. struct ieee80211_bss_conf *info, u32 changed)
  4145. {
  4146. if (vif->type == NL80211_IFTYPE_STATION)
  4147. mwl8k_bss_info_changed_sta(hw, vif, info, changed);
  4148. if (vif->type == NL80211_IFTYPE_AP)
  4149. mwl8k_bss_info_changed_ap(hw, vif, info, changed);
  4150. }
  4151. static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
  4152. struct netdev_hw_addr_list *mc_list)
  4153. {
  4154. struct mwl8k_cmd_pkt *cmd;
  4155. /*
  4156. * Synthesize and return a command packet that programs the
  4157. * hardware multicast address filter. At this point we don't
  4158. * know whether FIF_ALLMULTI is being requested, but if it is,
  4159. * we'll end up throwing this packet away and creating a new
  4160. * one in mwl8k_configure_filter().
  4161. */
  4162. cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
  4163. return (unsigned long)cmd;
  4164. }
  4165. static int
  4166. mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
  4167. unsigned int changed_flags,
  4168. unsigned int *total_flags)
  4169. {
  4170. struct mwl8k_priv *priv = hw->priv;
  4171. /*
  4172. * Hardware sniffer mode is mutually exclusive with STA
  4173. * operation, so refuse to enable sniffer mode if a STA
  4174. * interface is active.
  4175. */
  4176. if (!list_empty(&priv->vif_list)) {
  4177. if (net_ratelimit())
  4178. wiphy_info(hw->wiphy,
  4179. "not enabling sniffer mode because STA interface is active\n");
  4180. return 0;
  4181. }
  4182. if (!priv->sniffer_enabled) {
  4183. if (mwl8k_cmd_enable_sniffer(hw, 1))
  4184. return 0;
  4185. priv->sniffer_enabled = true;
  4186. }
  4187. *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
  4188. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
  4189. FIF_OTHER_BSS;
  4190. return 1;
  4191. }
  4192. static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
  4193. {
  4194. if (!list_empty(&priv->vif_list))
  4195. return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
  4196. return NULL;
  4197. }
  4198. static void mwl8k_configure_filter(struct ieee80211_hw *hw,
  4199. unsigned int changed_flags,
  4200. unsigned int *total_flags,
  4201. u64 multicast)
  4202. {
  4203. struct mwl8k_priv *priv = hw->priv;
  4204. struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
  4205. /*
  4206. * AP firmware doesn't allow fine-grained control over
  4207. * the receive filter.
  4208. */
  4209. if (priv->ap_fw) {
  4210. *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
  4211. kfree(cmd);
  4212. return;
  4213. }
  4214. /*
  4215. * Enable hardware sniffer mode if FIF_CONTROL or
  4216. * FIF_OTHER_BSS is requested.
  4217. */
  4218. if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
  4219. mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
  4220. kfree(cmd);
  4221. return;
  4222. }
  4223. /* Clear unsupported feature flags */
  4224. *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
  4225. if (mwl8k_fw_lock(hw)) {
  4226. kfree(cmd);
  4227. return;
  4228. }
  4229. if (priv->sniffer_enabled) {
  4230. mwl8k_cmd_enable_sniffer(hw, 0);
  4231. priv->sniffer_enabled = false;
  4232. }
  4233. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  4234. if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
  4235. /*
  4236. * Disable the BSS filter.
  4237. */
  4238. mwl8k_cmd_set_pre_scan(hw);
  4239. } else {
  4240. struct mwl8k_vif *mwl8k_vif;
  4241. const u8 *bssid;
  4242. /*
  4243. * Enable the BSS filter.
  4244. *
  4245. * If there is an active STA interface, use that
  4246. * interface's BSSID, otherwise use a dummy one
  4247. * (where the OUI part needs to be nonzero for
  4248. * the BSSID to be accepted by POST_SCAN).
  4249. */
  4250. mwl8k_vif = mwl8k_first_vif(priv);
  4251. if (mwl8k_vif != NULL)
  4252. bssid = mwl8k_vif->vif->bss_conf.bssid;
  4253. else
  4254. bssid = "\x01\x00\x00\x00\x00\x00";
  4255. mwl8k_cmd_set_post_scan(hw, bssid);
  4256. }
  4257. }
  4258. /*
  4259. * If FIF_ALLMULTI is being requested, throw away the command
  4260. * packet that ->prepare_multicast() built and replace it with
  4261. * a command packet that enables reception of all multicast
  4262. * packets.
  4263. */
  4264. if (*total_flags & FIF_ALLMULTI) {
  4265. kfree(cmd);
  4266. cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
  4267. }
  4268. if (cmd != NULL) {
  4269. mwl8k_post_cmd(hw, cmd);
  4270. kfree(cmd);
  4271. }
  4272. mwl8k_fw_unlock(hw);
  4273. }
  4274. static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  4275. {
  4276. return mwl8k_cmd_set_rts_threshold(hw, value);
  4277. }
  4278. static int mwl8k_sta_remove(struct ieee80211_hw *hw,
  4279. struct ieee80211_vif *vif,
  4280. struct ieee80211_sta *sta)
  4281. {
  4282. struct mwl8k_priv *priv = hw->priv;
  4283. if (priv->ap_fw)
  4284. return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
  4285. else
  4286. return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
  4287. }
  4288. static int mwl8k_sta_add(struct ieee80211_hw *hw,
  4289. struct ieee80211_vif *vif,
  4290. struct ieee80211_sta *sta)
  4291. {
  4292. struct mwl8k_priv *priv = hw->priv;
  4293. int ret;
  4294. int i;
  4295. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  4296. struct ieee80211_key_conf *key;
  4297. if (!priv->ap_fw) {
  4298. ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
  4299. if (ret >= 0) {
  4300. MWL8K_STA(sta)->peer_id = ret;
  4301. if (sta->ht_cap.ht_supported)
  4302. MWL8K_STA(sta)->is_ampdu_allowed = true;
  4303. ret = 0;
  4304. }
  4305. } else {
  4306. ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
  4307. }
  4308. for (i = 0; i < NUM_WEP_KEYS; i++) {
  4309. key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
  4310. if (mwl8k_vif->wep_key_conf[i].enabled)
  4311. mwl8k_set_key(hw, SET_KEY, vif, sta, key);
  4312. }
  4313. return ret;
  4314. }
  4315. static int mwl8k_conf_tx(struct ieee80211_hw *hw,
  4316. struct ieee80211_vif *vif, u16 queue,
  4317. const struct ieee80211_tx_queue_params *params)
  4318. {
  4319. struct mwl8k_priv *priv = hw->priv;
  4320. int rc;
  4321. rc = mwl8k_fw_lock(hw);
  4322. if (!rc) {
  4323. BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
  4324. memcpy(&priv->wmm_params[queue], params, sizeof(*params));
  4325. if (!priv->wmm_enabled)
  4326. rc = mwl8k_cmd_set_wmm_mode(hw, 1);
  4327. if (!rc) {
  4328. int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
  4329. rc = mwl8k_cmd_set_edca_params(hw, q,
  4330. params->cw_min,
  4331. params->cw_max,
  4332. params->aifs,
  4333. params->txop);
  4334. }
  4335. mwl8k_fw_unlock(hw);
  4336. }
  4337. return rc;
  4338. }
  4339. static int mwl8k_get_stats(struct ieee80211_hw *hw,
  4340. struct ieee80211_low_level_stats *stats)
  4341. {
  4342. return mwl8k_cmd_get_stat(hw, stats);
  4343. }
  4344. static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
  4345. struct survey_info *survey)
  4346. {
  4347. struct mwl8k_priv *priv = hw->priv;
  4348. struct ieee80211_conf *conf = &hw->conf;
  4349. if (idx != 0)
  4350. return -ENOENT;
  4351. survey->channel = conf->chandef.chan;
  4352. survey->filled = SURVEY_INFO_NOISE_DBM;
  4353. survey->noise = priv->noise;
  4354. return 0;
  4355. }
  4356. #define MAX_AMPDU_ATTEMPTS 5
  4357. static int
  4358. mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4359. enum ieee80211_ampdu_mlme_action action,
  4360. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  4361. u8 buf_size)
  4362. {
  4363. int i, rc = 0;
  4364. struct mwl8k_priv *priv = hw->priv;
  4365. struct mwl8k_ampdu_stream *stream;
  4366. u8 *addr = sta->addr, idx;
  4367. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  4368. if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
  4369. return -ENOTSUPP;
  4370. spin_lock(&priv->stream_lock);
  4371. stream = mwl8k_lookup_stream(hw, addr, tid);
  4372. switch (action) {
  4373. case IEEE80211_AMPDU_RX_START:
  4374. case IEEE80211_AMPDU_RX_STOP:
  4375. break;
  4376. case IEEE80211_AMPDU_TX_START:
  4377. /* By the time we get here the hw queues may contain outgoing
  4378. * packets for this RA/TID that are not part of this BA
  4379. * session. The hw will assign sequence numbers to these
  4380. * packets as they go out. So if we query the hw for its next
  4381. * sequence number and use that for the SSN here, it may end up
  4382. * being wrong, which will lead to sequence number mismatch at
  4383. * the recipient. To avoid this, we reset the sequence number
  4384. * to O for the first MPDU in this BA stream.
  4385. */
  4386. *ssn = 0;
  4387. if (stream == NULL) {
  4388. /* This means that somebody outside this driver called
  4389. * ieee80211_start_tx_ba_session. This is unexpected
  4390. * because we do our own rate control. Just warn and
  4391. * move on.
  4392. */
  4393. wiphy_warn(hw->wiphy, "Unexpected call to %s. "
  4394. "Proceeding anyway.\n", __func__);
  4395. stream = mwl8k_add_stream(hw, sta, tid);
  4396. }
  4397. if (stream == NULL) {
  4398. wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
  4399. rc = -EBUSY;
  4400. break;
  4401. }
  4402. stream->state = AMPDU_STREAM_IN_PROGRESS;
  4403. /* Release the lock before we do the time consuming stuff */
  4404. spin_unlock(&priv->stream_lock);
  4405. for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
  4406. /* Check if link is still valid */
  4407. if (!sta_info->is_ampdu_allowed) {
  4408. spin_lock(&priv->stream_lock);
  4409. mwl8k_remove_stream(hw, stream);
  4410. spin_unlock(&priv->stream_lock);
  4411. return -EBUSY;
  4412. }
  4413. rc = mwl8k_check_ba(hw, stream, vif);
  4414. /* If HW restart is in progress mwl8k_post_cmd will
  4415. * return -EBUSY. Avoid retrying mwl8k_check_ba in
  4416. * such cases
  4417. */
  4418. if (!rc || rc == -EBUSY)
  4419. break;
  4420. /*
  4421. * HW queues take time to be flushed, give them
  4422. * sufficient time
  4423. */
  4424. msleep(1000);
  4425. }
  4426. spin_lock(&priv->stream_lock);
  4427. if (rc) {
  4428. wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
  4429. " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
  4430. mwl8k_remove_stream(hw, stream);
  4431. rc = -EBUSY;
  4432. break;
  4433. }
  4434. ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
  4435. break;
  4436. case IEEE80211_AMPDU_TX_STOP_CONT:
  4437. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  4438. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  4439. if (stream) {
  4440. if (stream->state == AMPDU_STREAM_ACTIVE) {
  4441. idx = stream->idx;
  4442. spin_unlock(&priv->stream_lock);
  4443. mwl8k_destroy_ba(hw, idx);
  4444. spin_lock(&priv->stream_lock);
  4445. }
  4446. mwl8k_remove_stream(hw, stream);
  4447. }
  4448. ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
  4449. break;
  4450. case IEEE80211_AMPDU_TX_OPERATIONAL:
  4451. BUG_ON(stream == NULL);
  4452. BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
  4453. spin_unlock(&priv->stream_lock);
  4454. rc = mwl8k_create_ba(hw, stream, buf_size, vif);
  4455. spin_lock(&priv->stream_lock);
  4456. if (!rc)
  4457. stream->state = AMPDU_STREAM_ACTIVE;
  4458. else {
  4459. idx = stream->idx;
  4460. spin_unlock(&priv->stream_lock);
  4461. mwl8k_destroy_ba(hw, idx);
  4462. spin_lock(&priv->stream_lock);
  4463. wiphy_debug(hw->wiphy,
  4464. "Failed adding stream for sta %pM tid %d\n",
  4465. addr, tid);
  4466. mwl8k_remove_stream(hw, stream);
  4467. }
  4468. break;
  4469. default:
  4470. rc = -ENOTSUPP;
  4471. }
  4472. spin_unlock(&priv->stream_lock);
  4473. return rc;
  4474. }
  4475. static const struct ieee80211_ops mwl8k_ops = {
  4476. .tx = mwl8k_tx,
  4477. .start = mwl8k_start,
  4478. .stop = mwl8k_stop,
  4479. .add_interface = mwl8k_add_interface,
  4480. .remove_interface = mwl8k_remove_interface,
  4481. .config = mwl8k_config,
  4482. .bss_info_changed = mwl8k_bss_info_changed,
  4483. .prepare_multicast = mwl8k_prepare_multicast,
  4484. .configure_filter = mwl8k_configure_filter,
  4485. .set_key = mwl8k_set_key,
  4486. .set_rts_threshold = mwl8k_set_rts_threshold,
  4487. .sta_add = mwl8k_sta_add,
  4488. .sta_remove = mwl8k_sta_remove,
  4489. .conf_tx = mwl8k_conf_tx,
  4490. .get_stats = mwl8k_get_stats,
  4491. .get_survey = mwl8k_get_survey,
  4492. .ampdu_action = mwl8k_ampdu_action,
  4493. };
  4494. static void mwl8k_finalize_join_worker(struct work_struct *work)
  4495. {
  4496. struct mwl8k_priv *priv =
  4497. container_of(work, struct mwl8k_priv, finalize_join_worker);
  4498. struct sk_buff *skb = priv->beacon_skb;
  4499. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  4500. int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
  4501. const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
  4502. mgmt->u.beacon.variable, len);
  4503. int dtim_period = 1;
  4504. if (tim && tim[1] >= 2)
  4505. dtim_period = tim[3];
  4506. mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
  4507. dev_kfree_skb(skb);
  4508. priv->beacon_skb = NULL;
  4509. }
  4510. enum {
  4511. MWL8363 = 0,
  4512. MWL8687,
  4513. MWL8366,
  4514. MWL8764,
  4515. };
  4516. #define MWL8K_8366_AP_FW_API 3
  4517. #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
  4518. #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
  4519. #define MWL8K_8764_AP_FW_API 1
  4520. #define _MWL8K_8764_AP_FW(api) "mwl8k/fmimage_8764_ap-" #api ".fw"
  4521. #define MWL8K_8764_AP_FW(api) _MWL8K_8764_AP_FW(api)
  4522. static struct mwl8k_device_info mwl8k_info_tbl[] = {
  4523. [MWL8363] = {
  4524. .part_name = "88w8363",
  4525. .helper_image = "mwl8k/helper_8363.fw",
  4526. .fw_image_sta = "mwl8k/fmimage_8363.fw",
  4527. },
  4528. [MWL8687] = {
  4529. .part_name = "88w8687",
  4530. .helper_image = "mwl8k/helper_8687.fw",
  4531. .fw_image_sta = "mwl8k/fmimage_8687.fw",
  4532. },
  4533. [MWL8366] = {
  4534. .part_name = "88w8366",
  4535. .helper_image = "mwl8k/helper_8366.fw",
  4536. .fw_image_sta = "mwl8k/fmimage_8366.fw",
  4537. .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
  4538. .fw_api_ap = MWL8K_8366_AP_FW_API,
  4539. .ap_rxd_ops = &rxd_ap_ops,
  4540. },
  4541. [MWL8764] = {
  4542. .part_name = "88w8764",
  4543. .fw_image_ap = MWL8K_8764_AP_FW(MWL8K_8764_AP_FW_API),
  4544. .fw_api_ap = MWL8K_8764_AP_FW_API,
  4545. .ap_rxd_ops = &rxd_ap_ops,
  4546. },
  4547. };
  4548. MODULE_FIRMWARE("mwl8k/helper_8363.fw");
  4549. MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
  4550. MODULE_FIRMWARE("mwl8k/helper_8687.fw");
  4551. MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
  4552. MODULE_FIRMWARE("mwl8k/helper_8366.fw");
  4553. MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
  4554. MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
  4555. static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
  4556. { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
  4557. { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
  4558. { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
  4559. { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
  4560. { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
  4561. { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
  4562. { PCI_VDEVICE(MARVELL, 0x2a41), .driver_data = MWL8366, },
  4563. { PCI_VDEVICE(MARVELL, 0x2a42), .driver_data = MWL8366, },
  4564. { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
  4565. { PCI_VDEVICE(MARVELL, 0x2b36), .driver_data = MWL8764, },
  4566. { },
  4567. };
  4568. MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
  4569. static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
  4570. {
  4571. int rc;
  4572. printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
  4573. "Trying alternative firmware %s\n", pci_name(priv->pdev),
  4574. priv->fw_pref, priv->fw_alt);
  4575. rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
  4576. if (rc) {
  4577. printk(KERN_ERR "%s: Error requesting alt fw %s\n",
  4578. pci_name(priv->pdev), priv->fw_alt);
  4579. return rc;
  4580. }
  4581. return 0;
  4582. }
  4583. static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
  4584. static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
  4585. {
  4586. struct mwl8k_priv *priv = context;
  4587. struct mwl8k_device_info *di = priv->device_info;
  4588. int rc;
  4589. switch (priv->fw_state) {
  4590. case FW_STATE_INIT:
  4591. if (!fw) {
  4592. printk(KERN_ERR "%s: Error requesting helper fw %s\n",
  4593. pci_name(priv->pdev), di->helper_image);
  4594. goto fail;
  4595. }
  4596. priv->fw_helper = fw;
  4597. rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
  4598. true);
  4599. if (rc && priv->fw_alt) {
  4600. rc = mwl8k_request_alt_fw(priv);
  4601. if (rc)
  4602. goto fail;
  4603. priv->fw_state = FW_STATE_LOADING_ALT;
  4604. } else if (rc)
  4605. goto fail;
  4606. else
  4607. priv->fw_state = FW_STATE_LOADING_PREF;
  4608. break;
  4609. case FW_STATE_LOADING_PREF:
  4610. if (!fw) {
  4611. if (priv->fw_alt) {
  4612. rc = mwl8k_request_alt_fw(priv);
  4613. if (rc)
  4614. goto fail;
  4615. priv->fw_state = FW_STATE_LOADING_ALT;
  4616. } else
  4617. goto fail;
  4618. } else {
  4619. priv->fw_ucode = fw;
  4620. rc = mwl8k_firmware_load_success(priv);
  4621. if (rc)
  4622. goto fail;
  4623. else
  4624. complete(&priv->firmware_loading_complete);
  4625. }
  4626. break;
  4627. case FW_STATE_LOADING_ALT:
  4628. if (!fw) {
  4629. printk(KERN_ERR "%s: Error requesting alt fw %s\n",
  4630. pci_name(priv->pdev), di->helper_image);
  4631. goto fail;
  4632. }
  4633. priv->fw_ucode = fw;
  4634. rc = mwl8k_firmware_load_success(priv);
  4635. if (rc)
  4636. goto fail;
  4637. else
  4638. complete(&priv->firmware_loading_complete);
  4639. break;
  4640. default:
  4641. printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
  4642. MWL8K_NAME, priv->fw_state);
  4643. BUG_ON(1);
  4644. }
  4645. return;
  4646. fail:
  4647. priv->fw_state = FW_STATE_ERROR;
  4648. complete(&priv->firmware_loading_complete);
  4649. device_release_driver(&priv->pdev->dev);
  4650. mwl8k_release_firmware(priv);
  4651. }
  4652. #define MAX_RESTART_ATTEMPTS 1
  4653. static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
  4654. bool nowait)
  4655. {
  4656. struct mwl8k_priv *priv = hw->priv;
  4657. int rc;
  4658. int count = MAX_RESTART_ATTEMPTS;
  4659. retry:
  4660. /* Reset firmware and hardware */
  4661. mwl8k_hw_reset(priv);
  4662. /* Ask userland hotplug daemon for the device firmware */
  4663. rc = mwl8k_request_firmware(priv, fw_image, nowait);
  4664. if (rc) {
  4665. wiphy_err(hw->wiphy, "Firmware files not found\n");
  4666. return rc;
  4667. }
  4668. if (nowait)
  4669. return rc;
  4670. /* Load firmware into hardware */
  4671. rc = mwl8k_load_firmware(hw);
  4672. if (rc)
  4673. wiphy_err(hw->wiphy, "Cannot start firmware\n");
  4674. /* Reclaim memory once firmware is successfully loaded */
  4675. mwl8k_release_firmware(priv);
  4676. if (rc && count) {
  4677. /* FW did not start successfully;
  4678. * lets try one more time
  4679. */
  4680. count--;
  4681. wiphy_err(hw->wiphy, "Trying to reload the firmware again\n");
  4682. msleep(20);
  4683. goto retry;
  4684. }
  4685. return rc;
  4686. }
  4687. static int mwl8k_init_txqs(struct ieee80211_hw *hw)
  4688. {
  4689. struct mwl8k_priv *priv = hw->priv;
  4690. int rc = 0;
  4691. int i;
  4692. for (i = 0; i < mwl8k_tx_queues(priv); i++) {
  4693. rc = mwl8k_txq_init(hw, i);
  4694. if (rc)
  4695. break;
  4696. if (priv->ap_fw)
  4697. iowrite32(priv->txq[i].txd_dma,
  4698. priv->sram + priv->txq_offset[i]);
  4699. }
  4700. return rc;
  4701. }
  4702. /* initialize hw after successfully loading a firmware image */
  4703. static int mwl8k_probe_hw(struct ieee80211_hw *hw)
  4704. {
  4705. struct mwl8k_priv *priv = hw->priv;
  4706. int rc = 0;
  4707. int i;
  4708. if (priv->ap_fw) {
  4709. priv->rxd_ops = priv->device_info->ap_rxd_ops;
  4710. if (priv->rxd_ops == NULL) {
  4711. wiphy_err(hw->wiphy,
  4712. "Driver does not have AP firmware image support for this hardware\n");
  4713. rc = -ENOENT;
  4714. goto err_stop_firmware;
  4715. }
  4716. } else {
  4717. priv->rxd_ops = &rxd_sta_ops;
  4718. }
  4719. priv->sniffer_enabled = false;
  4720. priv->wmm_enabled = false;
  4721. priv->pending_tx_pkts = 0;
  4722. atomic_set(&priv->watchdog_event_pending, 0);
  4723. rc = mwl8k_rxq_init(hw, 0);
  4724. if (rc)
  4725. goto err_stop_firmware;
  4726. rxq_refill(hw, 0, INT_MAX);
  4727. /* For the sta firmware, we need to know the dma addresses of tx queues
  4728. * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
  4729. * prior to issuing this command. But for the AP case, we learn the
  4730. * total number of queues from the result CMD_GET_HW_SPEC, so for this
  4731. * case we must initialize the tx queues after.
  4732. */
  4733. priv->num_ampdu_queues = 0;
  4734. if (!priv->ap_fw) {
  4735. rc = mwl8k_init_txqs(hw);
  4736. if (rc)
  4737. goto err_free_queues;
  4738. }
  4739. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  4740. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4741. iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY|
  4742. MWL8K_A2H_INT_BA_WATCHDOG,
  4743. priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
  4744. iowrite32(MWL8K_A2H_INT_OPC_DONE,
  4745. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  4746. rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
  4747. IRQF_SHARED, MWL8K_NAME, hw);
  4748. if (rc) {
  4749. wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
  4750. goto err_free_queues;
  4751. }
  4752. /*
  4753. * When hw restart is requested,
  4754. * mac80211 will take care of clearing
  4755. * the ampdu streams, so do not clear
  4756. * the ampdu state here
  4757. */
  4758. if (!priv->hw_restart_in_progress)
  4759. memset(priv->ampdu, 0, sizeof(priv->ampdu));
  4760. /*
  4761. * Temporarily enable interrupts. Initial firmware host
  4762. * commands use interrupts and avoid polling. Disable
  4763. * interrupts when done.
  4764. */
  4765. iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4766. /* Get config data, mac addrs etc */
  4767. if (priv->ap_fw) {
  4768. rc = mwl8k_cmd_get_hw_spec_ap(hw);
  4769. if (!rc)
  4770. rc = mwl8k_init_txqs(hw);
  4771. if (!rc)
  4772. rc = mwl8k_cmd_set_hw_spec(hw);
  4773. } else {
  4774. rc = mwl8k_cmd_get_hw_spec_sta(hw);
  4775. }
  4776. if (rc) {
  4777. wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
  4778. goto err_free_irq;
  4779. }
  4780. /* Turn radio off */
  4781. rc = mwl8k_cmd_radio_disable(hw);
  4782. if (rc) {
  4783. wiphy_err(hw->wiphy, "Cannot disable\n");
  4784. goto err_free_irq;
  4785. }
  4786. /* Clear MAC address */
  4787. rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
  4788. if (rc) {
  4789. wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
  4790. goto err_free_irq;
  4791. }
  4792. /* Configure Antennas */
  4793. rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
  4794. if (rc)
  4795. wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
  4796. rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
  4797. if (rc)
  4798. wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
  4799. /* Disable interrupts */
  4800. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4801. free_irq(priv->pdev->irq, hw);
  4802. wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
  4803. priv->device_info->part_name,
  4804. priv->hw_rev, hw->wiphy->perm_addr,
  4805. priv->ap_fw ? "AP" : "STA",
  4806. (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
  4807. (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
  4808. return 0;
  4809. err_free_irq:
  4810. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4811. free_irq(priv->pdev->irq, hw);
  4812. err_free_queues:
  4813. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4814. mwl8k_txq_deinit(hw, i);
  4815. mwl8k_rxq_deinit(hw, 0);
  4816. err_stop_firmware:
  4817. mwl8k_hw_reset(priv);
  4818. return rc;
  4819. }
  4820. /*
  4821. * invoke mwl8k_reload_firmware to change the firmware image after the device
  4822. * has already been registered
  4823. */
  4824. static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
  4825. {
  4826. int i, rc = 0;
  4827. struct mwl8k_priv *priv = hw->priv;
  4828. struct mwl8k_vif *vif, *tmp_vif;
  4829. mwl8k_stop(hw);
  4830. mwl8k_rxq_deinit(hw, 0);
  4831. /*
  4832. * All the existing interfaces are re-added by the ieee80211_reconfig;
  4833. * which means driver should remove existing interfaces before calling
  4834. * ieee80211_restart_hw
  4835. */
  4836. if (priv->hw_restart_in_progress)
  4837. list_for_each_entry_safe(vif, tmp_vif, &priv->vif_list, list)
  4838. mwl8k_remove_vif(priv, vif);
  4839. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4840. mwl8k_txq_deinit(hw, i);
  4841. rc = mwl8k_init_firmware(hw, fw_image, false);
  4842. if (rc)
  4843. goto fail;
  4844. rc = mwl8k_probe_hw(hw);
  4845. if (rc)
  4846. goto fail;
  4847. if (priv->hw_restart_in_progress)
  4848. return rc;
  4849. rc = mwl8k_start(hw);
  4850. if (rc)
  4851. goto fail;
  4852. rc = mwl8k_config(hw, ~0);
  4853. if (rc)
  4854. goto fail;
  4855. for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
  4856. rc = mwl8k_conf_tx(hw, NULL, i, &priv->wmm_params[i]);
  4857. if (rc)
  4858. goto fail;
  4859. }
  4860. return rc;
  4861. fail:
  4862. printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
  4863. return rc;
  4864. }
  4865. static const struct ieee80211_iface_limit ap_if_limits[] = {
  4866. { .max = 8, .types = BIT(NL80211_IFTYPE_AP) },
  4867. { .max = 1, .types = BIT(NL80211_IFTYPE_STATION) },
  4868. };
  4869. static const struct ieee80211_iface_combination ap_if_comb = {
  4870. .limits = ap_if_limits,
  4871. .n_limits = ARRAY_SIZE(ap_if_limits),
  4872. .max_interfaces = 8,
  4873. .num_different_channels = 1,
  4874. };
  4875. static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
  4876. {
  4877. struct ieee80211_hw *hw = priv->hw;
  4878. int i, rc;
  4879. rc = mwl8k_load_firmware(hw);
  4880. mwl8k_release_firmware(priv);
  4881. if (rc) {
  4882. wiphy_err(hw->wiphy, "Cannot start firmware\n");
  4883. return rc;
  4884. }
  4885. /*
  4886. * Extra headroom is the size of the required DMA header
  4887. * minus the size of the smallest 802.11 frame (CTS frame).
  4888. */
  4889. hw->extra_tx_headroom =
  4890. sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
  4891. hw->extra_tx_headroom -= priv->ap_fw ? REDUCED_TX_HEADROOM : 0;
  4892. hw->channel_change_time = 10;
  4893. hw->queues = MWL8K_TX_WMM_QUEUES;
  4894. /* Set rssi values to dBm */
  4895. hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
  4896. /*
  4897. * Ask mac80211 to not to trigger PS mode
  4898. * based on PM bit of incoming frames.
  4899. */
  4900. if (priv->ap_fw)
  4901. hw->flags |= IEEE80211_HW_AP_LINK_PS;
  4902. hw->vif_data_size = sizeof(struct mwl8k_vif);
  4903. hw->sta_data_size = sizeof(struct mwl8k_sta);
  4904. priv->macids_used = 0;
  4905. INIT_LIST_HEAD(&priv->vif_list);
  4906. /* Set default radio state and preamble */
  4907. priv->radio_on = false;
  4908. priv->radio_short_preamble = false;
  4909. /* Finalize join worker */
  4910. INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
  4911. /* Handle watchdog ba events */
  4912. INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
  4913. /* To reload the firmware if it crashes */
  4914. INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work);
  4915. /* TX reclaim and RX tasklets. */
  4916. tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
  4917. tasklet_disable(&priv->poll_tx_task);
  4918. tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
  4919. tasklet_disable(&priv->poll_rx_task);
  4920. /* Power management cookie */
  4921. priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
  4922. if (priv->cookie == NULL)
  4923. return -ENOMEM;
  4924. mutex_init(&priv->fw_mutex);
  4925. priv->fw_mutex_owner = NULL;
  4926. priv->fw_mutex_depth = 0;
  4927. priv->hostcmd_wait = NULL;
  4928. spin_lock_init(&priv->tx_lock);
  4929. spin_lock_init(&priv->stream_lock);
  4930. priv->tx_wait = NULL;
  4931. rc = mwl8k_probe_hw(hw);
  4932. if (rc)
  4933. goto err_free_cookie;
  4934. hw->wiphy->interface_modes = 0;
  4935. if (priv->ap_macids_supported || priv->device_info->fw_image_ap) {
  4936. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
  4937. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
  4938. hw->wiphy->iface_combinations = &ap_if_comb;
  4939. hw->wiphy->n_iface_combinations = 1;
  4940. }
  4941. if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
  4942. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
  4943. rc = ieee80211_register_hw(hw);
  4944. if (rc) {
  4945. wiphy_err(hw->wiphy, "Cannot register device\n");
  4946. goto err_unprobe_hw;
  4947. }
  4948. return 0;
  4949. err_unprobe_hw:
  4950. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4951. mwl8k_txq_deinit(hw, i);
  4952. mwl8k_rxq_deinit(hw, 0);
  4953. err_free_cookie:
  4954. if (priv->cookie != NULL)
  4955. pci_free_consistent(priv->pdev, 4,
  4956. priv->cookie, priv->cookie_dma);
  4957. return rc;
  4958. }
  4959. static int mwl8k_probe(struct pci_dev *pdev,
  4960. const struct pci_device_id *id)
  4961. {
  4962. static int printed_version;
  4963. struct ieee80211_hw *hw;
  4964. struct mwl8k_priv *priv;
  4965. struct mwl8k_device_info *di;
  4966. int rc;
  4967. if (!printed_version) {
  4968. printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
  4969. printed_version = 1;
  4970. }
  4971. rc = pci_enable_device(pdev);
  4972. if (rc) {
  4973. printk(KERN_ERR "%s: Cannot enable new PCI device\n",
  4974. MWL8K_NAME);
  4975. return rc;
  4976. }
  4977. rc = pci_request_regions(pdev, MWL8K_NAME);
  4978. if (rc) {
  4979. printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
  4980. MWL8K_NAME);
  4981. goto err_disable_device;
  4982. }
  4983. pci_set_master(pdev);
  4984. hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
  4985. if (hw == NULL) {
  4986. printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
  4987. rc = -ENOMEM;
  4988. goto err_free_reg;
  4989. }
  4990. SET_IEEE80211_DEV(hw, &pdev->dev);
  4991. pci_set_drvdata(pdev, hw);
  4992. priv = hw->priv;
  4993. priv->hw = hw;
  4994. priv->pdev = pdev;
  4995. priv->device_info = &mwl8k_info_tbl[id->driver_data];
  4996. if (id->driver_data == MWL8764)
  4997. priv->is_8764 = true;
  4998. priv->sram = pci_iomap(pdev, 0, 0x10000);
  4999. if (priv->sram == NULL) {
  5000. wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
  5001. rc = -EIO;
  5002. goto err_iounmap;
  5003. }
  5004. /*
  5005. * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
  5006. * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
  5007. */
  5008. priv->regs = pci_iomap(pdev, 1, 0x10000);
  5009. if (priv->regs == NULL) {
  5010. priv->regs = pci_iomap(pdev, 2, 0x10000);
  5011. if (priv->regs == NULL) {
  5012. wiphy_err(hw->wiphy, "Cannot map device registers\n");
  5013. rc = -EIO;
  5014. goto err_iounmap;
  5015. }
  5016. }
  5017. /*
  5018. * Choose the initial fw image depending on user input. If a second
  5019. * image is available, make it the alternative image that will be
  5020. * loaded if the first one fails.
  5021. */
  5022. init_completion(&priv->firmware_loading_complete);
  5023. di = priv->device_info;
  5024. if (ap_mode_default && di->fw_image_ap) {
  5025. priv->fw_pref = di->fw_image_ap;
  5026. priv->fw_alt = di->fw_image_sta;
  5027. } else if (!ap_mode_default && di->fw_image_sta) {
  5028. priv->fw_pref = di->fw_image_sta;
  5029. priv->fw_alt = di->fw_image_ap;
  5030. } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
  5031. printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
  5032. priv->fw_pref = di->fw_image_sta;
  5033. } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
  5034. printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
  5035. priv->fw_pref = di->fw_image_ap;
  5036. }
  5037. rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
  5038. if (rc)
  5039. goto err_stop_firmware;
  5040. priv->hw_restart_in_progress = false;
  5041. priv->running_bsses = 0;
  5042. return rc;
  5043. err_stop_firmware:
  5044. mwl8k_hw_reset(priv);
  5045. err_iounmap:
  5046. if (priv->regs != NULL)
  5047. pci_iounmap(pdev, priv->regs);
  5048. if (priv->sram != NULL)
  5049. pci_iounmap(pdev, priv->sram);
  5050. ieee80211_free_hw(hw);
  5051. err_free_reg:
  5052. pci_release_regions(pdev);
  5053. err_disable_device:
  5054. pci_disable_device(pdev);
  5055. return rc;
  5056. }
  5057. static void mwl8k_remove(struct pci_dev *pdev)
  5058. {
  5059. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  5060. struct mwl8k_priv *priv;
  5061. int i;
  5062. if (hw == NULL)
  5063. return;
  5064. priv = hw->priv;
  5065. wait_for_completion(&priv->firmware_loading_complete);
  5066. if (priv->fw_state == FW_STATE_ERROR) {
  5067. mwl8k_hw_reset(priv);
  5068. goto unmap;
  5069. }
  5070. ieee80211_stop_queues(hw);
  5071. ieee80211_unregister_hw(hw);
  5072. /* Remove TX reclaim and RX tasklets. */
  5073. tasklet_kill(&priv->poll_tx_task);
  5074. tasklet_kill(&priv->poll_rx_task);
  5075. /* Stop hardware */
  5076. mwl8k_hw_reset(priv);
  5077. /* Return all skbs to mac80211 */
  5078. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  5079. mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  5080. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  5081. mwl8k_txq_deinit(hw, i);
  5082. mwl8k_rxq_deinit(hw, 0);
  5083. pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
  5084. unmap:
  5085. pci_iounmap(pdev, priv->regs);
  5086. pci_iounmap(pdev, priv->sram);
  5087. ieee80211_free_hw(hw);
  5088. pci_release_regions(pdev);
  5089. pci_disable_device(pdev);
  5090. }
  5091. static struct pci_driver mwl8k_driver = {
  5092. .name = MWL8K_NAME,
  5093. .id_table = mwl8k_pci_id_table,
  5094. .probe = mwl8k_probe,
  5095. .remove = mwl8k_remove,
  5096. };
  5097. module_pci_driver(mwl8k_driver);
  5098. MODULE_DESCRIPTION(MWL8K_DESC);
  5099. MODULE_VERSION(MWL8K_VERSION);
  5100. MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
  5101. MODULE_LICENSE("GPL");