mwl8k.c 143 KB

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