mwl8k.c 142 KB

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