mwl8k.c 149 KB

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