mwl8k.c 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904
  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. ether_addr_equal(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) {
  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. rcu_read_lock();
  1390. sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1,
  1391. wh->addr2);
  1392. if (sta) {
  1393. sta_info = MWL8K_STA(sta);
  1394. BUG_ON(sta_info == NULL);
  1395. rate_info = le16_to_cpu(tx_desc->rate_info);
  1396. /* If rate is < 6.5 Mpbs for an ht station
  1397. * do not form an ampdu. If the station is a
  1398. * legacy station (format = 0), do not form an
  1399. * ampdu
  1400. */
  1401. if (RI_RATE_ID_MCS(rate_info) < 1 ||
  1402. RI_FORMAT(rate_info) == 0) {
  1403. sta_info->is_ampdu_allowed = false;
  1404. } else {
  1405. sta_info->is_ampdu_allowed = true;
  1406. }
  1407. }
  1408. rcu_read_unlock();
  1409. }
  1410. ieee80211_tx_info_clear_status(info);
  1411. /* Rate control is happening in the firmware.
  1412. * Ensure no tx rate is being reported.
  1413. */
  1414. info->status.rates[0].idx = -1;
  1415. info->status.rates[0].count = 1;
  1416. if (MWL8K_TXD_SUCCESS(status))
  1417. info->flags |= IEEE80211_TX_STAT_ACK;
  1418. ieee80211_tx_status_irqsafe(hw, skb);
  1419. processed++;
  1420. }
  1421. return processed;
  1422. }
  1423. /* must be called only when the card's transmit is completely halted */
  1424. static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
  1425. {
  1426. struct mwl8k_priv *priv = hw->priv;
  1427. struct mwl8k_tx_queue *txq = priv->txq + index;
  1428. if (txq->txd == NULL)
  1429. return;
  1430. mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
  1431. kfree(txq->skb);
  1432. txq->skb = NULL;
  1433. pci_free_consistent(priv->pdev,
  1434. MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
  1435. txq->txd, txq->txd_dma);
  1436. txq->txd = NULL;
  1437. }
  1438. /* caller must hold priv->stream_lock when calling the stream functions */
  1439. static struct mwl8k_ampdu_stream *
  1440. mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
  1441. {
  1442. struct mwl8k_ampdu_stream *stream;
  1443. struct mwl8k_priv *priv = hw->priv;
  1444. int i;
  1445. for (i = 0; i < priv->num_ampdu_queues; i++) {
  1446. stream = &priv->ampdu[i];
  1447. if (stream->state == AMPDU_NO_STREAM) {
  1448. stream->sta = sta;
  1449. stream->state = AMPDU_STREAM_NEW;
  1450. stream->tid = tid;
  1451. stream->idx = i;
  1452. stream->txq_idx = MWL8K_TX_WMM_QUEUES + i;
  1453. wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
  1454. sta->addr, tid);
  1455. return stream;
  1456. }
  1457. }
  1458. return NULL;
  1459. }
  1460. static int
  1461. mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
  1462. {
  1463. int ret;
  1464. /* if the stream has already been started, don't start it again */
  1465. if (stream->state != AMPDU_STREAM_NEW)
  1466. return 0;
  1467. ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
  1468. if (ret)
  1469. wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
  1470. "%d\n", stream->sta->addr, stream->tid, ret);
  1471. else
  1472. wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
  1473. stream->sta->addr, stream->tid);
  1474. return ret;
  1475. }
  1476. static void
  1477. mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
  1478. {
  1479. wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
  1480. stream->tid);
  1481. memset(stream, 0, sizeof(*stream));
  1482. }
  1483. static struct mwl8k_ampdu_stream *
  1484. mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
  1485. {
  1486. struct mwl8k_priv *priv = hw->priv;
  1487. int i;
  1488. for (i = 0 ; i < priv->num_ampdu_queues; i++) {
  1489. struct mwl8k_ampdu_stream *stream;
  1490. stream = &priv->ampdu[i];
  1491. if (stream->state == AMPDU_NO_STREAM)
  1492. continue;
  1493. if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
  1494. stream->tid == tid)
  1495. return stream;
  1496. }
  1497. return NULL;
  1498. }
  1499. #define MWL8K_AMPDU_PACKET_THRESHOLD 64
  1500. static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid)
  1501. {
  1502. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  1503. struct tx_traffic_info *tx_stats;
  1504. BUG_ON(tid >= MWL8K_MAX_TID);
  1505. tx_stats = &sta_info->tx_stats[tid];
  1506. return sta_info->is_ampdu_allowed &&
  1507. tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD;
  1508. }
  1509. static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid)
  1510. {
  1511. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  1512. struct tx_traffic_info *tx_stats;
  1513. BUG_ON(tid >= MWL8K_MAX_TID);
  1514. tx_stats = &sta_info->tx_stats[tid];
  1515. if (tx_stats->start_time == 0)
  1516. tx_stats->start_time = jiffies;
  1517. /* reset the packet count after each second elapses. If the number of
  1518. * packets ever exceeds the ampdu_min_traffic threshold, we will allow
  1519. * an ampdu stream to be started.
  1520. */
  1521. if (jiffies - tx_stats->start_time > HZ) {
  1522. tx_stats->pkts = 0;
  1523. tx_stats->start_time = 0;
  1524. } else
  1525. tx_stats->pkts++;
  1526. }
  1527. static void
  1528. mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
  1529. {
  1530. struct mwl8k_priv *priv = hw->priv;
  1531. struct ieee80211_tx_info *tx_info;
  1532. struct mwl8k_vif *mwl8k_vif;
  1533. struct ieee80211_sta *sta;
  1534. struct ieee80211_hdr *wh;
  1535. struct mwl8k_tx_queue *txq;
  1536. struct mwl8k_tx_desc *tx;
  1537. dma_addr_t dma;
  1538. u32 txstatus;
  1539. u8 txdatarate;
  1540. u16 qos;
  1541. int txpriority;
  1542. u8 tid = 0;
  1543. struct mwl8k_ampdu_stream *stream = NULL;
  1544. bool start_ba_session = false;
  1545. bool mgmtframe = false;
  1546. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
  1547. wh = (struct ieee80211_hdr *)skb->data;
  1548. if (ieee80211_is_data_qos(wh->frame_control))
  1549. qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
  1550. else
  1551. qos = 0;
  1552. if (ieee80211_is_mgmt(wh->frame_control))
  1553. mgmtframe = true;
  1554. if (priv->ap_fw)
  1555. mwl8k_encapsulate_tx_frame(priv, skb);
  1556. else
  1557. mwl8k_add_dma_header(priv, skb, 0, 0);
  1558. wh = &((struct mwl8k_dma_data *)skb->data)->wh;
  1559. tx_info = IEEE80211_SKB_CB(skb);
  1560. sta = tx_info->control.sta;
  1561. mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
  1562. if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1563. wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1564. wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
  1565. mwl8k_vif->seqno += 0x10;
  1566. }
  1567. /* Setup firmware control bit fields for each frame type. */
  1568. txstatus = 0;
  1569. txdatarate = 0;
  1570. if (ieee80211_is_mgmt(wh->frame_control) ||
  1571. ieee80211_is_ctl(wh->frame_control)) {
  1572. txdatarate = 0;
  1573. qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
  1574. } else if (ieee80211_is_data(wh->frame_control)) {
  1575. txdatarate = 1;
  1576. if (is_multicast_ether_addr(wh->addr1))
  1577. txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
  1578. qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
  1579. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
  1580. qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
  1581. else
  1582. qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
  1583. }
  1584. /* Queue ADDBA request in the respective data queue. While setting up
  1585. * the ampdu stream, mac80211 queues further packets for that
  1586. * particular ra/tid pair. However, packets piled up in the hardware
  1587. * for that ra/tid pair will still go out. ADDBA request and the
  1588. * related data packets going out from different queues asynchronously
  1589. * will cause a shift in the receiver window which might result in
  1590. * ampdu packets getting dropped at the receiver after the stream has
  1591. * been setup.
  1592. */
  1593. if (unlikely(ieee80211_is_action(wh->frame_control) &&
  1594. mgmt->u.action.category == WLAN_CATEGORY_BACK &&
  1595. mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
  1596. priv->ap_fw)) {
  1597. u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
  1598. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  1599. index = mwl8k_tid_queue_mapping(tid);
  1600. }
  1601. txpriority = index;
  1602. if (priv->ap_fw && sta && sta->ht_cap.ht_supported
  1603. && skb->protocol != cpu_to_be16(ETH_P_PAE)
  1604. && ieee80211_is_data_qos(wh->frame_control)) {
  1605. tid = qos & 0xf;
  1606. mwl8k_tx_count_packet(sta, tid);
  1607. spin_lock(&priv->stream_lock);
  1608. stream = mwl8k_lookup_stream(hw, sta->addr, tid);
  1609. if (stream != NULL) {
  1610. if (stream->state == AMPDU_STREAM_ACTIVE) {
  1611. txpriority = stream->txq_idx;
  1612. index = stream->txq_idx;
  1613. } else if (stream->state == AMPDU_STREAM_NEW) {
  1614. /* We get here if the driver sends us packets
  1615. * after we've initiated a stream, but before
  1616. * our ampdu_action routine has been called
  1617. * with IEEE80211_AMPDU_TX_START to get the SSN
  1618. * for the ADDBA request. So this packet can
  1619. * go out with no risk of sequence number
  1620. * mismatch. No special handling is required.
  1621. */
  1622. } else {
  1623. /* Drop packets that would go out after the
  1624. * ADDBA request was sent but before the ADDBA
  1625. * response is received. If we don't do this,
  1626. * the recipient would probably receive it
  1627. * after the ADDBA request with SSN 0. This
  1628. * will cause the recipient's BA receive window
  1629. * to shift, which would cause the subsequent
  1630. * packets in the BA stream to be discarded.
  1631. * mac80211 queues our packets for us in this
  1632. * case, so this is really just a safety check.
  1633. */
  1634. wiphy_warn(hw->wiphy,
  1635. "Cannot send packet while ADDBA "
  1636. "dialog is underway.\n");
  1637. spin_unlock(&priv->stream_lock);
  1638. dev_kfree_skb(skb);
  1639. return;
  1640. }
  1641. } else {
  1642. /* Defer calling mwl8k_start_stream so that the current
  1643. * skb can go out before the ADDBA request. This
  1644. * prevents sequence number mismatch at the recepient
  1645. * as described above.
  1646. */
  1647. if (mwl8k_ampdu_allowed(sta, tid)) {
  1648. stream = mwl8k_add_stream(hw, sta, tid);
  1649. if (stream != NULL)
  1650. start_ba_session = true;
  1651. }
  1652. }
  1653. spin_unlock(&priv->stream_lock);
  1654. }
  1655. dma = pci_map_single(priv->pdev, skb->data,
  1656. skb->len, PCI_DMA_TODEVICE);
  1657. if (pci_dma_mapping_error(priv->pdev, dma)) {
  1658. wiphy_debug(hw->wiphy,
  1659. "failed to dma map skb, dropping TX frame.\n");
  1660. if (start_ba_session) {
  1661. spin_lock(&priv->stream_lock);
  1662. mwl8k_remove_stream(hw, stream);
  1663. spin_unlock(&priv->stream_lock);
  1664. }
  1665. dev_kfree_skb(skb);
  1666. return;
  1667. }
  1668. spin_lock_bh(&priv->tx_lock);
  1669. txq = priv->txq + index;
  1670. /* Mgmt frames that go out frequently are probe
  1671. * responses. Other mgmt frames got out relatively
  1672. * infrequently. Hence reserve 2 buffers so that
  1673. * other mgmt frames do not get dropped due to an
  1674. * already queued probe response in one of the
  1675. * reserved buffers.
  1676. */
  1677. if (txq->len >= MWL8K_TX_DESCS - 2) {
  1678. if (!mgmtframe || txq->len == MWL8K_TX_DESCS) {
  1679. if (start_ba_session) {
  1680. spin_lock(&priv->stream_lock);
  1681. mwl8k_remove_stream(hw, stream);
  1682. spin_unlock(&priv->stream_lock);
  1683. }
  1684. spin_unlock_bh(&priv->tx_lock);
  1685. dev_kfree_skb(skb);
  1686. return;
  1687. }
  1688. }
  1689. BUG_ON(txq->skb[txq->tail] != NULL);
  1690. txq->skb[txq->tail] = skb;
  1691. tx = txq->txd + txq->tail;
  1692. tx->data_rate = txdatarate;
  1693. tx->tx_priority = txpriority;
  1694. tx->qos_control = cpu_to_le16(qos);
  1695. tx->pkt_phys_addr = cpu_to_le32(dma);
  1696. tx->pkt_len = cpu_to_le16(skb->len);
  1697. tx->rate_info = 0;
  1698. if (!priv->ap_fw && tx_info->control.sta != NULL)
  1699. tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
  1700. else
  1701. tx->peer_id = 0;
  1702. if (priv->ap_fw)
  1703. tx->timestamp = cpu_to_le32(ioread32(priv->regs +
  1704. MWL8K_HW_TIMER_REGISTER));
  1705. wmb();
  1706. tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
  1707. txq->len++;
  1708. priv->pending_tx_pkts++;
  1709. txq->tail++;
  1710. if (txq->tail == MWL8K_TX_DESCS)
  1711. txq->tail = 0;
  1712. mwl8k_tx_start(priv);
  1713. spin_unlock_bh(&priv->tx_lock);
  1714. /* Initiate the ampdu session here */
  1715. if (start_ba_session) {
  1716. spin_lock(&priv->stream_lock);
  1717. if (mwl8k_start_stream(hw, stream))
  1718. mwl8k_remove_stream(hw, stream);
  1719. spin_unlock(&priv->stream_lock);
  1720. }
  1721. }
  1722. /*
  1723. * Firmware access.
  1724. *
  1725. * We have the following requirements for issuing firmware commands:
  1726. * - Some commands require that the packet transmit path is idle when
  1727. * the command is issued. (For simplicity, we'll just quiesce the
  1728. * transmit path for every command.)
  1729. * - There are certain sequences of commands that need to be issued to
  1730. * the hardware sequentially, with no other intervening commands.
  1731. *
  1732. * This leads to an implementation of a "firmware lock" as a mutex that
  1733. * can be taken recursively, and which is taken by both the low-level
  1734. * command submission function (mwl8k_post_cmd) as well as any users of
  1735. * that function that require issuing of an atomic sequence of commands,
  1736. * and quiesces the transmit path whenever it's taken.
  1737. */
  1738. static int mwl8k_fw_lock(struct ieee80211_hw *hw)
  1739. {
  1740. struct mwl8k_priv *priv = hw->priv;
  1741. if (priv->fw_mutex_owner != current) {
  1742. int rc;
  1743. mutex_lock(&priv->fw_mutex);
  1744. ieee80211_stop_queues(hw);
  1745. rc = mwl8k_tx_wait_empty(hw);
  1746. if (rc) {
  1747. if (!priv->hw_restart_in_progress)
  1748. ieee80211_wake_queues(hw);
  1749. mutex_unlock(&priv->fw_mutex);
  1750. return rc;
  1751. }
  1752. priv->fw_mutex_owner = current;
  1753. }
  1754. priv->fw_mutex_depth++;
  1755. return 0;
  1756. }
  1757. static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
  1758. {
  1759. struct mwl8k_priv *priv = hw->priv;
  1760. if (!--priv->fw_mutex_depth) {
  1761. if (!priv->hw_restart_in_progress)
  1762. ieee80211_wake_queues(hw);
  1763. priv->fw_mutex_owner = NULL;
  1764. mutex_unlock(&priv->fw_mutex);
  1765. }
  1766. }
  1767. /*
  1768. * Command processing.
  1769. */
  1770. /* Timeout firmware commands after 10s */
  1771. #define MWL8K_CMD_TIMEOUT_MS 10000
  1772. static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
  1773. {
  1774. DECLARE_COMPLETION_ONSTACK(cmd_wait);
  1775. struct mwl8k_priv *priv = hw->priv;
  1776. void __iomem *regs = priv->regs;
  1777. dma_addr_t dma_addr;
  1778. unsigned int dma_size;
  1779. int rc;
  1780. unsigned long timeout = 0;
  1781. u8 buf[32];
  1782. cmd->result = (__force __le16) 0xffff;
  1783. dma_size = le16_to_cpu(cmd->length);
  1784. dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
  1785. PCI_DMA_BIDIRECTIONAL);
  1786. if (pci_dma_mapping_error(priv->pdev, dma_addr))
  1787. return -ENOMEM;
  1788. rc = mwl8k_fw_lock(hw);
  1789. if (rc) {
  1790. pci_unmap_single(priv->pdev, dma_addr, dma_size,
  1791. PCI_DMA_BIDIRECTIONAL);
  1792. return rc;
  1793. }
  1794. priv->hostcmd_wait = &cmd_wait;
  1795. iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
  1796. iowrite32(MWL8K_H2A_INT_DOORBELL,
  1797. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1798. iowrite32(MWL8K_H2A_INT_DUMMY,
  1799. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1800. timeout = wait_for_completion_timeout(&cmd_wait,
  1801. msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
  1802. priv->hostcmd_wait = NULL;
  1803. mwl8k_fw_unlock(hw);
  1804. pci_unmap_single(priv->pdev, dma_addr, dma_size,
  1805. PCI_DMA_BIDIRECTIONAL);
  1806. if (!timeout) {
  1807. wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
  1808. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1809. MWL8K_CMD_TIMEOUT_MS);
  1810. rc = -ETIMEDOUT;
  1811. } else {
  1812. int ms;
  1813. ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
  1814. rc = cmd->result ? -EINVAL : 0;
  1815. if (rc)
  1816. wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
  1817. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1818. le16_to_cpu(cmd->result));
  1819. else if (ms > 2000)
  1820. wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
  1821. mwl8k_cmd_name(cmd->code,
  1822. buf, sizeof(buf)),
  1823. ms);
  1824. }
  1825. return rc;
  1826. }
  1827. static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
  1828. struct ieee80211_vif *vif,
  1829. struct mwl8k_cmd_pkt *cmd)
  1830. {
  1831. if (vif != NULL)
  1832. cmd->macid = MWL8K_VIF(vif)->macid;
  1833. return mwl8k_post_cmd(hw, cmd);
  1834. }
  1835. /*
  1836. * Setup code shared between STA and AP firmware images.
  1837. */
  1838. static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
  1839. {
  1840. struct mwl8k_priv *priv = hw->priv;
  1841. BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
  1842. memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
  1843. BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
  1844. memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
  1845. priv->band_24.band = IEEE80211_BAND_2GHZ;
  1846. priv->band_24.channels = priv->channels_24;
  1847. priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
  1848. priv->band_24.bitrates = priv->rates_24;
  1849. priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
  1850. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
  1851. }
  1852. static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
  1853. {
  1854. struct mwl8k_priv *priv = hw->priv;
  1855. BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
  1856. memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
  1857. BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
  1858. memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
  1859. priv->band_50.band = IEEE80211_BAND_5GHZ;
  1860. priv->band_50.channels = priv->channels_50;
  1861. priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
  1862. priv->band_50.bitrates = priv->rates_50;
  1863. priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
  1864. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
  1865. }
  1866. /*
  1867. * CMD_GET_HW_SPEC (STA version).
  1868. */
  1869. struct mwl8k_cmd_get_hw_spec_sta {
  1870. struct mwl8k_cmd_pkt header;
  1871. __u8 hw_rev;
  1872. __u8 host_interface;
  1873. __le16 num_mcaddrs;
  1874. __u8 perm_addr[ETH_ALEN];
  1875. __le16 region_code;
  1876. __le32 fw_rev;
  1877. __le32 ps_cookie;
  1878. __le32 caps;
  1879. __u8 mcs_bitmap[16];
  1880. __le32 rx_queue_ptr;
  1881. __le32 num_tx_queues;
  1882. __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
  1883. __le32 caps2;
  1884. __le32 num_tx_desc_per_queue;
  1885. __le32 total_rxd;
  1886. } __packed;
  1887. #define MWL8K_CAP_MAX_AMSDU 0x20000000
  1888. #define MWL8K_CAP_GREENFIELD 0x08000000
  1889. #define MWL8K_CAP_AMPDU 0x04000000
  1890. #define MWL8K_CAP_RX_STBC 0x01000000
  1891. #define MWL8K_CAP_TX_STBC 0x00800000
  1892. #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
  1893. #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
  1894. #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
  1895. #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
  1896. #define MWL8K_CAP_DELAY_BA 0x00003000
  1897. #define MWL8K_CAP_MIMO 0x00000200
  1898. #define MWL8K_CAP_40MHZ 0x00000100
  1899. #define MWL8K_CAP_BAND_MASK 0x00000007
  1900. #define MWL8K_CAP_5GHZ 0x00000004
  1901. #define MWL8K_CAP_2GHZ4 0x00000001
  1902. static void
  1903. mwl8k_set_ht_caps(struct ieee80211_hw *hw,
  1904. struct ieee80211_supported_band *band, u32 cap)
  1905. {
  1906. int rx_streams;
  1907. int tx_streams;
  1908. band->ht_cap.ht_supported = 1;
  1909. if (cap & MWL8K_CAP_MAX_AMSDU)
  1910. band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  1911. if (cap & MWL8K_CAP_GREENFIELD)
  1912. band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
  1913. if (cap & MWL8K_CAP_AMPDU) {
  1914. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  1915. band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  1916. band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  1917. }
  1918. if (cap & MWL8K_CAP_RX_STBC)
  1919. band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
  1920. if (cap & MWL8K_CAP_TX_STBC)
  1921. band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  1922. if (cap & MWL8K_CAP_SHORTGI_40MHZ)
  1923. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  1924. if (cap & MWL8K_CAP_SHORTGI_20MHZ)
  1925. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  1926. if (cap & MWL8K_CAP_DELAY_BA)
  1927. band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
  1928. if (cap & MWL8K_CAP_40MHZ)
  1929. band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1930. rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
  1931. tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
  1932. band->ht_cap.mcs.rx_mask[0] = 0xff;
  1933. if (rx_streams >= 2)
  1934. band->ht_cap.mcs.rx_mask[1] = 0xff;
  1935. if (rx_streams >= 3)
  1936. band->ht_cap.mcs.rx_mask[2] = 0xff;
  1937. band->ht_cap.mcs.rx_mask[4] = 0x01;
  1938. band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  1939. if (rx_streams != tx_streams) {
  1940. band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  1941. band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
  1942. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  1943. }
  1944. }
  1945. static void
  1946. mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
  1947. {
  1948. struct mwl8k_priv *priv = hw->priv;
  1949. if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
  1950. mwl8k_setup_2ghz_band(hw);
  1951. if (caps & MWL8K_CAP_MIMO)
  1952. mwl8k_set_ht_caps(hw, &priv->band_24, caps);
  1953. }
  1954. if (caps & MWL8K_CAP_5GHZ) {
  1955. mwl8k_setup_5ghz_band(hw);
  1956. if (caps & MWL8K_CAP_MIMO)
  1957. mwl8k_set_ht_caps(hw, &priv->band_50, caps);
  1958. }
  1959. }
  1960. static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
  1961. {
  1962. struct mwl8k_priv *priv = hw->priv;
  1963. struct mwl8k_cmd_get_hw_spec_sta *cmd;
  1964. int rc;
  1965. int i;
  1966. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1967. if (cmd == NULL)
  1968. return -ENOMEM;
  1969. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  1970. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1971. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  1972. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  1973. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
  1974. cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
  1975. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  1976. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
  1977. cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
  1978. cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
  1979. rc = mwl8k_post_cmd(hw, &cmd->header);
  1980. if (!rc) {
  1981. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  1982. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  1983. priv->fw_rev = le32_to_cpu(cmd->fw_rev);
  1984. priv->hw_rev = cmd->hw_rev;
  1985. mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
  1986. priv->ap_macids_supported = 0x00000000;
  1987. priv->sta_macids_supported = 0x00000001;
  1988. }
  1989. kfree(cmd);
  1990. return rc;
  1991. }
  1992. /*
  1993. * CMD_GET_HW_SPEC (AP version).
  1994. */
  1995. struct mwl8k_cmd_get_hw_spec_ap {
  1996. struct mwl8k_cmd_pkt header;
  1997. __u8 hw_rev;
  1998. __u8 host_interface;
  1999. __le16 num_wcb;
  2000. __le16 num_mcaddrs;
  2001. __u8 perm_addr[ETH_ALEN];
  2002. __le16 region_code;
  2003. __le16 num_antenna;
  2004. __le32 fw_rev;
  2005. __le32 wcbbase0;
  2006. __le32 rxwrptr;
  2007. __le32 rxrdptr;
  2008. __le32 ps_cookie;
  2009. __le32 wcbbase1;
  2010. __le32 wcbbase2;
  2011. __le32 wcbbase3;
  2012. __le32 fw_api_version;
  2013. __le32 caps;
  2014. __le32 num_of_ampdu_queues;
  2015. __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
  2016. } __packed;
  2017. static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
  2018. {
  2019. struct mwl8k_priv *priv = hw->priv;
  2020. struct mwl8k_cmd_get_hw_spec_ap *cmd;
  2021. int rc, i;
  2022. u32 api_version;
  2023. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2024. if (cmd == NULL)
  2025. return -ENOMEM;
  2026. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  2027. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2028. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  2029. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2030. rc = mwl8k_post_cmd(hw, &cmd->header);
  2031. if (!rc) {
  2032. int off;
  2033. api_version = le32_to_cpu(cmd->fw_api_version);
  2034. if (priv->device_info->fw_api_ap != api_version) {
  2035. printk(KERN_ERR "%s: Unsupported fw API version for %s."
  2036. " Expected %d got %d.\n", MWL8K_NAME,
  2037. priv->device_info->part_name,
  2038. priv->device_info->fw_api_ap,
  2039. api_version);
  2040. rc = -EINVAL;
  2041. goto done;
  2042. }
  2043. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  2044. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  2045. priv->fw_rev = le32_to_cpu(cmd->fw_rev);
  2046. priv->hw_rev = cmd->hw_rev;
  2047. mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
  2048. priv->ap_macids_supported = 0x000000ff;
  2049. priv->sta_macids_supported = 0x00000000;
  2050. priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
  2051. if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
  2052. wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
  2053. " but we only support %d.\n",
  2054. priv->num_ampdu_queues,
  2055. MWL8K_MAX_AMPDU_QUEUES);
  2056. priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
  2057. }
  2058. off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
  2059. iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
  2060. off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
  2061. iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
  2062. priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
  2063. priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
  2064. priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
  2065. priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
  2066. for (i = 0; i < priv->num_ampdu_queues; i++)
  2067. priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
  2068. le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
  2069. }
  2070. done:
  2071. kfree(cmd);
  2072. return rc;
  2073. }
  2074. /*
  2075. * CMD_SET_HW_SPEC.
  2076. */
  2077. struct mwl8k_cmd_set_hw_spec {
  2078. struct mwl8k_cmd_pkt header;
  2079. __u8 hw_rev;
  2080. __u8 host_interface;
  2081. __le16 num_mcaddrs;
  2082. __u8 perm_addr[ETH_ALEN];
  2083. __le16 region_code;
  2084. __le32 fw_rev;
  2085. __le32 ps_cookie;
  2086. __le32 caps;
  2087. __le32 rx_queue_ptr;
  2088. __le32 num_tx_queues;
  2089. __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
  2090. __le32 flags;
  2091. __le32 num_tx_desc_per_queue;
  2092. __le32 total_rxd;
  2093. } __packed;
  2094. /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
  2095. * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
  2096. * the packets that are queued for more than 500ms, will be dropped in the
  2097. * hardware. This helps minimizing the issues caused due to head-of-line
  2098. * blocking where a slow client can hog the bandwidth and affect traffic to a
  2099. * faster client.
  2100. */
  2101. #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
  2102. #define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
  2103. #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
  2104. #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
  2105. #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
  2106. static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
  2107. {
  2108. struct mwl8k_priv *priv = hw->priv;
  2109. struct mwl8k_cmd_set_hw_spec *cmd;
  2110. int rc;
  2111. int i;
  2112. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2113. if (cmd == NULL)
  2114. return -ENOMEM;
  2115. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
  2116. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2117. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2118. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
  2119. cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
  2120. /*
  2121. * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
  2122. * that order. Firmware has Q3 as highest priority and Q0 as lowest
  2123. * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
  2124. * priority is interpreted the right way in firmware.
  2125. */
  2126. for (i = 0; i < mwl8k_tx_queues(priv); i++) {
  2127. int j = mwl8k_tx_queues(priv) - 1 - i;
  2128. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
  2129. }
  2130. cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
  2131. MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
  2132. MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON |
  2133. MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY |
  2134. MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR);
  2135. cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
  2136. cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
  2137. rc = mwl8k_post_cmd(hw, &cmd->header);
  2138. kfree(cmd);
  2139. return rc;
  2140. }
  2141. /*
  2142. * CMD_MAC_MULTICAST_ADR.
  2143. */
  2144. struct mwl8k_cmd_mac_multicast_adr {
  2145. struct mwl8k_cmd_pkt header;
  2146. __le16 action;
  2147. __le16 numaddr;
  2148. __u8 addr[0][ETH_ALEN];
  2149. };
  2150. #define MWL8K_ENABLE_RX_DIRECTED 0x0001
  2151. #define MWL8K_ENABLE_RX_MULTICAST 0x0002
  2152. #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
  2153. #define MWL8K_ENABLE_RX_BROADCAST 0x0008
  2154. static struct mwl8k_cmd_pkt *
  2155. __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
  2156. struct netdev_hw_addr_list *mc_list)
  2157. {
  2158. struct mwl8k_priv *priv = hw->priv;
  2159. struct mwl8k_cmd_mac_multicast_adr *cmd;
  2160. int size;
  2161. int mc_count = 0;
  2162. if (mc_list)
  2163. mc_count = netdev_hw_addr_list_count(mc_list);
  2164. if (allmulti || mc_count > priv->num_mcaddrs) {
  2165. allmulti = 1;
  2166. mc_count = 0;
  2167. }
  2168. size = sizeof(*cmd) + mc_count * ETH_ALEN;
  2169. cmd = kzalloc(size, GFP_ATOMIC);
  2170. if (cmd == NULL)
  2171. return NULL;
  2172. cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
  2173. cmd->header.length = cpu_to_le16(size);
  2174. cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
  2175. MWL8K_ENABLE_RX_BROADCAST);
  2176. if (allmulti) {
  2177. cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
  2178. } else if (mc_count) {
  2179. struct netdev_hw_addr *ha;
  2180. int i = 0;
  2181. cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
  2182. cmd->numaddr = cpu_to_le16(mc_count);
  2183. netdev_hw_addr_list_for_each(ha, mc_list) {
  2184. memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
  2185. }
  2186. }
  2187. return &cmd->header;
  2188. }
  2189. /*
  2190. * CMD_GET_STAT.
  2191. */
  2192. struct mwl8k_cmd_get_stat {
  2193. struct mwl8k_cmd_pkt header;
  2194. __le32 stats[64];
  2195. } __packed;
  2196. #define MWL8K_STAT_ACK_FAILURE 9
  2197. #define MWL8K_STAT_RTS_FAILURE 12
  2198. #define MWL8K_STAT_FCS_ERROR 24
  2199. #define MWL8K_STAT_RTS_SUCCESS 11
  2200. static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
  2201. struct ieee80211_low_level_stats *stats)
  2202. {
  2203. struct mwl8k_cmd_get_stat *cmd;
  2204. int rc;
  2205. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2206. if (cmd == NULL)
  2207. return -ENOMEM;
  2208. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
  2209. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2210. rc = mwl8k_post_cmd(hw, &cmd->header);
  2211. if (!rc) {
  2212. stats->dot11ACKFailureCount =
  2213. le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
  2214. stats->dot11RTSFailureCount =
  2215. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
  2216. stats->dot11FCSErrorCount =
  2217. le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
  2218. stats->dot11RTSSuccessCount =
  2219. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
  2220. }
  2221. kfree(cmd);
  2222. return rc;
  2223. }
  2224. /*
  2225. * CMD_RADIO_CONTROL.
  2226. */
  2227. struct mwl8k_cmd_radio_control {
  2228. struct mwl8k_cmd_pkt header;
  2229. __le16 action;
  2230. __le16 control;
  2231. __le16 radio_on;
  2232. } __packed;
  2233. static int
  2234. mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
  2235. {
  2236. struct mwl8k_priv *priv = hw->priv;
  2237. struct mwl8k_cmd_radio_control *cmd;
  2238. int rc;
  2239. if (enable == priv->radio_on && !force)
  2240. return 0;
  2241. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2242. if (cmd == NULL)
  2243. return -ENOMEM;
  2244. cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
  2245. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2246. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2247. cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
  2248. cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
  2249. rc = mwl8k_post_cmd(hw, &cmd->header);
  2250. kfree(cmd);
  2251. if (!rc)
  2252. priv->radio_on = enable;
  2253. return rc;
  2254. }
  2255. static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
  2256. {
  2257. return mwl8k_cmd_radio_control(hw, 0, 0);
  2258. }
  2259. static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
  2260. {
  2261. return mwl8k_cmd_radio_control(hw, 1, 0);
  2262. }
  2263. static int
  2264. mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
  2265. {
  2266. struct mwl8k_priv *priv = hw->priv;
  2267. priv->radio_short_preamble = short_preamble;
  2268. return mwl8k_cmd_radio_control(hw, 1, 1);
  2269. }
  2270. /*
  2271. * CMD_RF_TX_POWER.
  2272. */
  2273. #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
  2274. struct mwl8k_cmd_rf_tx_power {
  2275. struct mwl8k_cmd_pkt header;
  2276. __le16 action;
  2277. __le16 support_level;
  2278. __le16 current_level;
  2279. __le16 reserved;
  2280. __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
  2281. } __packed;
  2282. static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
  2283. {
  2284. struct mwl8k_cmd_rf_tx_power *cmd;
  2285. int rc;
  2286. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2287. if (cmd == NULL)
  2288. return -ENOMEM;
  2289. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
  2290. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2291. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2292. cmd->support_level = cpu_to_le16(dBm);
  2293. rc = mwl8k_post_cmd(hw, &cmd->header);
  2294. kfree(cmd);
  2295. return rc;
  2296. }
  2297. /*
  2298. * CMD_TX_POWER.
  2299. */
  2300. #define MWL8K_TX_POWER_LEVEL_TOTAL 12
  2301. struct mwl8k_cmd_tx_power {
  2302. struct mwl8k_cmd_pkt header;
  2303. __le16 action;
  2304. __le16 band;
  2305. __le16 channel;
  2306. __le16 bw;
  2307. __le16 sub_ch;
  2308. __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
  2309. } __packed;
  2310. static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
  2311. struct ieee80211_conf *conf,
  2312. unsigned short pwr)
  2313. {
  2314. struct ieee80211_channel *channel = conf->channel;
  2315. struct mwl8k_cmd_tx_power *cmd;
  2316. int rc;
  2317. int i;
  2318. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2319. if (cmd == NULL)
  2320. return -ENOMEM;
  2321. cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
  2322. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2323. cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
  2324. if (channel->band == IEEE80211_BAND_2GHZ)
  2325. cmd->band = cpu_to_le16(0x1);
  2326. else if (channel->band == IEEE80211_BAND_5GHZ)
  2327. cmd->band = cpu_to_le16(0x4);
  2328. cmd->channel = cpu_to_le16(channel->hw_value);
  2329. if (conf->channel_type == NL80211_CHAN_NO_HT ||
  2330. conf->channel_type == NL80211_CHAN_HT20) {
  2331. cmd->bw = cpu_to_le16(0x2);
  2332. } else {
  2333. cmd->bw = cpu_to_le16(0x4);
  2334. if (conf->channel_type == NL80211_CHAN_HT40MINUS)
  2335. cmd->sub_ch = cpu_to_le16(0x3);
  2336. else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
  2337. cmd->sub_ch = cpu_to_le16(0x1);
  2338. }
  2339. for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
  2340. cmd->power_level_list[i] = cpu_to_le16(pwr);
  2341. rc = mwl8k_post_cmd(hw, &cmd->header);
  2342. kfree(cmd);
  2343. return rc;
  2344. }
  2345. /*
  2346. * CMD_RF_ANTENNA.
  2347. */
  2348. struct mwl8k_cmd_rf_antenna {
  2349. struct mwl8k_cmd_pkt header;
  2350. __le16 antenna;
  2351. __le16 mode;
  2352. } __packed;
  2353. #define MWL8K_RF_ANTENNA_RX 1
  2354. #define MWL8K_RF_ANTENNA_TX 2
  2355. static int
  2356. mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
  2357. {
  2358. struct mwl8k_cmd_rf_antenna *cmd;
  2359. int rc;
  2360. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2361. if (cmd == NULL)
  2362. return -ENOMEM;
  2363. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
  2364. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2365. cmd->antenna = cpu_to_le16(antenna);
  2366. cmd->mode = cpu_to_le16(mask);
  2367. rc = mwl8k_post_cmd(hw, &cmd->header);
  2368. kfree(cmd);
  2369. return rc;
  2370. }
  2371. /*
  2372. * CMD_SET_BEACON.
  2373. */
  2374. struct mwl8k_cmd_set_beacon {
  2375. struct mwl8k_cmd_pkt header;
  2376. __le16 beacon_len;
  2377. __u8 beacon[0];
  2378. };
  2379. static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
  2380. struct ieee80211_vif *vif, u8 *beacon, int len)
  2381. {
  2382. struct mwl8k_cmd_set_beacon *cmd;
  2383. int rc;
  2384. cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
  2385. if (cmd == NULL)
  2386. return -ENOMEM;
  2387. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
  2388. cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
  2389. cmd->beacon_len = cpu_to_le16(len);
  2390. memcpy(cmd->beacon, beacon, len);
  2391. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2392. kfree(cmd);
  2393. return rc;
  2394. }
  2395. /*
  2396. * CMD_SET_PRE_SCAN.
  2397. */
  2398. struct mwl8k_cmd_set_pre_scan {
  2399. struct mwl8k_cmd_pkt header;
  2400. } __packed;
  2401. static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
  2402. {
  2403. struct mwl8k_cmd_set_pre_scan *cmd;
  2404. int rc;
  2405. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2406. if (cmd == NULL)
  2407. return -ENOMEM;
  2408. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
  2409. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2410. rc = mwl8k_post_cmd(hw, &cmd->header);
  2411. kfree(cmd);
  2412. return rc;
  2413. }
  2414. /*
  2415. * CMD_SET_POST_SCAN.
  2416. */
  2417. struct mwl8k_cmd_set_post_scan {
  2418. struct mwl8k_cmd_pkt header;
  2419. __le32 isibss;
  2420. __u8 bssid[ETH_ALEN];
  2421. } __packed;
  2422. static int
  2423. mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
  2424. {
  2425. struct mwl8k_cmd_set_post_scan *cmd;
  2426. int rc;
  2427. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2428. if (cmd == NULL)
  2429. return -ENOMEM;
  2430. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
  2431. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2432. cmd->isibss = 0;
  2433. memcpy(cmd->bssid, mac, ETH_ALEN);
  2434. rc = mwl8k_post_cmd(hw, &cmd->header);
  2435. kfree(cmd);
  2436. return rc;
  2437. }
  2438. /*
  2439. * CMD_SET_RF_CHANNEL.
  2440. */
  2441. struct mwl8k_cmd_set_rf_channel {
  2442. struct mwl8k_cmd_pkt header;
  2443. __le16 action;
  2444. __u8 current_channel;
  2445. __le32 channel_flags;
  2446. } __packed;
  2447. static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
  2448. struct ieee80211_conf *conf)
  2449. {
  2450. struct ieee80211_channel *channel = conf->channel;
  2451. struct mwl8k_cmd_set_rf_channel *cmd;
  2452. int rc;
  2453. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2454. if (cmd == NULL)
  2455. return -ENOMEM;
  2456. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
  2457. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2458. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2459. cmd->current_channel = channel->hw_value;
  2460. if (channel->band == IEEE80211_BAND_2GHZ)
  2461. cmd->channel_flags |= cpu_to_le32(0x00000001);
  2462. else if (channel->band == IEEE80211_BAND_5GHZ)
  2463. cmd->channel_flags |= cpu_to_le32(0x00000004);
  2464. if (conf->channel_type == NL80211_CHAN_NO_HT ||
  2465. conf->channel_type == NL80211_CHAN_HT20)
  2466. cmd->channel_flags |= cpu_to_le32(0x00000080);
  2467. else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
  2468. cmd->channel_flags |= cpu_to_le32(0x000001900);
  2469. else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
  2470. cmd->channel_flags |= cpu_to_le32(0x000000900);
  2471. rc = mwl8k_post_cmd(hw, &cmd->header);
  2472. kfree(cmd);
  2473. return rc;
  2474. }
  2475. /*
  2476. * CMD_SET_AID.
  2477. */
  2478. #define MWL8K_FRAME_PROT_DISABLED 0x00
  2479. #define MWL8K_FRAME_PROT_11G 0x07
  2480. #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
  2481. #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
  2482. struct mwl8k_cmd_update_set_aid {
  2483. struct mwl8k_cmd_pkt header;
  2484. __le16 aid;
  2485. /* AP's MAC address (BSSID) */
  2486. __u8 bssid[ETH_ALEN];
  2487. __le16 protection_mode;
  2488. __u8 supp_rates[14];
  2489. } __packed;
  2490. static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
  2491. {
  2492. int i;
  2493. int j;
  2494. /*
  2495. * Clear nonstandard rates 4 and 13.
  2496. */
  2497. mask &= 0x1fef;
  2498. for (i = 0, j = 0; i < 14; i++) {
  2499. if (mask & (1 << i))
  2500. rates[j++] = mwl8k_rates_24[i].hw_value;
  2501. }
  2502. }
  2503. static int
  2504. mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
  2505. struct ieee80211_vif *vif, u32 legacy_rate_mask)
  2506. {
  2507. struct mwl8k_cmd_update_set_aid *cmd;
  2508. u16 prot_mode;
  2509. int rc;
  2510. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2511. if (cmd == NULL)
  2512. return -ENOMEM;
  2513. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
  2514. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2515. cmd->aid = cpu_to_le16(vif->bss_conf.aid);
  2516. memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
  2517. if (vif->bss_conf.use_cts_prot) {
  2518. prot_mode = MWL8K_FRAME_PROT_11G;
  2519. } else {
  2520. switch (vif->bss_conf.ht_operation_mode &
  2521. IEEE80211_HT_OP_MODE_PROTECTION) {
  2522. case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
  2523. prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
  2524. break;
  2525. case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
  2526. prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
  2527. break;
  2528. default:
  2529. prot_mode = MWL8K_FRAME_PROT_DISABLED;
  2530. break;
  2531. }
  2532. }
  2533. cmd->protection_mode = cpu_to_le16(prot_mode);
  2534. legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
  2535. rc = mwl8k_post_cmd(hw, &cmd->header);
  2536. kfree(cmd);
  2537. return rc;
  2538. }
  2539. /*
  2540. * CMD_SET_RATE.
  2541. */
  2542. struct mwl8k_cmd_set_rate {
  2543. struct mwl8k_cmd_pkt header;
  2544. __u8 legacy_rates[14];
  2545. /* Bitmap for supported MCS codes. */
  2546. __u8 mcs_set[16];
  2547. __u8 reserved[16];
  2548. } __packed;
  2549. static int
  2550. mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  2551. u32 legacy_rate_mask, u8 *mcs_rates)
  2552. {
  2553. struct mwl8k_cmd_set_rate *cmd;
  2554. int rc;
  2555. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2556. if (cmd == NULL)
  2557. return -ENOMEM;
  2558. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
  2559. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2560. legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
  2561. memcpy(cmd->mcs_set, mcs_rates, 16);
  2562. rc = mwl8k_post_cmd(hw, &cmd->header);
  2563. kfree(cmd);
  2564. return rc;
  2565. }
  2566. /*
  2567. * CMD_FINALIZE_JOIN.
  2568. */
  2569. #define MWL8K_FJ_BEACON_MAXLEN 128
  2570. struct mwl8k_cmd_finalize_join {
  2571. struct mwl8k_cmd_pkt header;
  2572. __le32 sleep_interval; /* Number of beacon periods to sleep */
  2573. __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
  2574. } __packed;
  2575. static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
  2576. int framelen, int dtim)
  2577. {
  2578. struct mwl8k_cmd_finalize_join *cmd;
  2579. struct ieee80211_mgmt *payload = frame;
  2580. int payload_len;
  2581. int rc;
  2582. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2583. if (cmd == NULL)
  2584. return -ENOMEM;
  2585. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
  2586. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2587. cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
  2588. payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
  2589. if (payload_len < 0)
  2590. payload_len = 0;
  2591. else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
  2592. payload_len = MWL8K_FJ_BEACON_MAXLEN;
  2593. memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
  2594. rc = mwl8k_post_cmd(hw, &cmd->header);
  2595. kfree(cmd);
  2596. return rc;
  2597. }
  2598. /*
  2599. * CMD_SET_RTS_THRESHOLD.
  2600. */
  2601. struct mwl8k_cmd_set_rts_threshold {
  2602. struct mwl8k_cmd_pkt header;
  2603. __le16 action;
  2604. __le16 threshold;
  2605. } __packed;
  2606. static int
  2607. mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
  2608. {
  2609. struct mwl8k_cmd_set_rts_threshold *cmd;
  2610. int rc;
  2611. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2612. if (cmd == NULL)
  2613. return -ENOMEM;
  2614. cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
  2615. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2616. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2617. cmd->threshold = cpu_to_le16(rts_thresh);
  2618. rc = mwl8k_post_cmd(hw, &cmd->header);
  2619. kfree(cmd);
  2620. return rc;
  2621. }
  2622. /*
  2623. * CMD_SET_SLOT.
  2624. */
  2625. struct mwl8k_cmd_set_slot {
  2626. struct mwl8k_cmd_pkt header;
  2627. __le16 action;
  2628. __u8 short_slot;
  2629. } __packed;
  2630. static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
  2631. {
  2632. struct mwl8k_cmd_set_slot *cmd;
  2633. int rc;
  2634. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2635. if (cmd == NULL)
  2636. return -ENOMEM;
  2637. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
  2638. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2639. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2640. cmd->short_slot = short_slot_time;
  2641. rc = mwl8k_post_cmd(hw, &cmd->header);
  2642. kfree(cmd);
  2643. return rc;
  2644. }
  2645. /*
  2646. * CMD_SET_EDCA_PARAMS.
  2647. */
  2648. struct mwl8k_cmd_set_edca_params {
  2649. struct mwl8k_cmd_pkt header;
  2650. /* See MWL8K_SET_EDCA_XXX below */
  2651. __le16 action;
  2652. /* TX opportunity in units of 32 us */
  2653. __le16 txop;
  2654. union {
  2655. struct {
  2656. /* Log exponent of max contention period: 0...15 */
  2657. __le32 log_cw_max;
  2658. /* Log exponent of min contention period: 0...15 */
  2659. __le32 log_cw_min;
  2660. /* Adaptive interframe spacing in units of 32us */
  2661. __u8 aifs;
  2662. /* TX queue to configure */
  2663. __u8 txq;
  2664. } ap;
  2665. struct {
  2666. /* Log exponent of max contention period: 0...15 */
  2667. __u8 log_cw_max;
  2668. /* Log exponent of min contention period: 0...15 */
  2669. __u8 log_cw_min;
  2670. /* Adaptive interframe spacing in units of 32us */
  2671. __u8 aifs;
  2672. /* TX queue to configure */
  2673. __u8 txq;
  2674. } sta;
  2675. };
  2676. } __packed;
  2677. #define MWL8K_SET_EDCA_CW 0x01
  2678. #define MWL8K_SET_EDCA_TXOP 0x02
  2679. #define MWL8K_SET_EDCA_AIFS 0x04
  2680. #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
  2681. MWL8K_SET_EDCA_TXOP | \
  2682. MWL8K_SET_EDCA_AIFS)
  2683. static int
  2684. mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
  2685. __u16 cw_min, __u16 cw_max,
  2686. __u8 aifs, __u16 txop)
  2687. {
  2688. struct mwl8k_priv *priv = hw->priv;
  2689. struct mwl8k_cmd_set_edca_params *cmd;
  2690. int rc;
  2691. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2692. if (cmd == NULL)
  2693. return -ENOMEM;
  2694. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
  2695. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2696. cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
  2697. cmd->txop = cpu_to_le16(txop);
  2698. if (priv->ap_fw) {
  2699. cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
  2700. cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
  2701. cmd->ap.aifs = aifs;
  2702. cmd->ap.txq = qnum;
  2703. } else {
  2704. cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
  2705. cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
  2706. cmd->sta.aifs = aifs;
  2707. cmd->sta.txq = qnum;
  2708. }
  2709. rc = mwl8k_post_cmd(hw, &cmd->header);
  2710. kfree(cmd);
  2711. return rc;
  2712. }
  2713. /*
  2714. * CMD_SET_WMM_MODE.
  2715. */
  2716. struct mwl8k_cmd_set_wmm_mode {
  2717. struct mwl8k_cmd_pkt header;
  2718. __le16 action;
  2719. } __packed;
  2720. static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
  2721. {
  2722. struct mwl8k_priv *priv = hw->priv;
  2723. struct mwl8k_cmd_set_wmm_mode *cmd;
  2724. int rc;
  2725. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2726. if (cmd == NULL)
  2727. return -ENOMEM;
  2728. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
  2729. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2730. cmd->action = cpu_to_le16(!!enable);
  2731. rc = mwl8k_post_cmd(hw, &cmd->header);
  2732. kfree(cmd);
  2733. if (!rc)
  2734. priv->wmm_enabled = enable;
  2735. return rc;
  2736. }
  2737. /*
  2738. * CMD_MIMO_CONFIG.
  2739. */
  2740. struct mwl8k_cmd_mimo_config {
  2741. struct mwl8k_cmd_pkt header;
  2742. __le32 action;
  2743. __u8 rx_antenna_map;
  2744. __u8 tx_antenna_map;
  2745. } __packed;
  2746. static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
  2747. {
  2748. struct mwl8k_cmd_mimo_config *cmd;
  2749. int rc;
  2750. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2751. if (cmd == NULL)
  2752. return -ENOMEM;
  2753. cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
  2754. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2755. cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
  2756. cmd->rx_antenna_map = rx;
  2757. cmd->tx_antenna_map = tx;
  2758. rc = mwl8k_post_cmd(hw, &cmd->header);
  2759. kfree(cmd);
  2760. return rc;
  2761. }
  2762. /*
  2763. * CMD_USE_FIXED_RATE (STA version).
  2764. */
  2765. struct mwl8k_cmd_use_fixed_rate_sta {
  2766. struct mwl8k_cmd_pkt header;
  2767. __le32 action;
  2768. __le32 allow_rate_drop;
  2769. __le32 num_rates;
  2770. struct {
  2771. __le32 is_ht_rate;
  2772. __le32 enable_retry;
  2773. __le32 rate;
  2774. __le32 retry_count;
  2775. } rate_entry[8];
  2776. __le32 rate_type;
  2777. __le32 reserved1;
  2778. __le32 reserved2;
  2779. } __packed;
  2780. #define MWL8K_USE_AUTO_RATE 0x0002
  2781. #define MWL8K_UCAST_RATE 0
  2782. static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
  2783. {
  2784. struct mwl8k_cmd_use_fixed_rate_sta *cmd;
  2785. int rc;
  2786. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2787. if (cmd == NULL)
  2788. return -ENOMEM;
  2789. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  2790. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2791. cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
  2792. cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
  2793. rc = mwl8k_post_cmd(hw, &cmd->header);
  2794. kfree(cmd);
  2795. return rc;
  2796. }
  2797. /*
  2798. * CMD_USE_FIXED_RATE (AP version).
  2799. */
  2800. struct mwl8k_cmd_use_fixed_rate_ap {
  2801. struct mwl8k_cmd_pkt header;
  2802. __le32 action;
  2803. __le32 allow_rate_drop;
  2804. __le32 num_rates;
  2805. struct mwl8k_rate_entry_ap {
  2806. __le32 is_ht_rate;
  2807. __le32 enable_retry;
  2808. __le32 rate;
  2809. __le32 retry_count;
  2810. } rate_entry[4];
  2811. u8 multicast_rate;
  2812. u8 multicast_rate_type;
  2813. u8 management_rate;
  2814. } __packed;
  2815. static int
  2816. mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
  2817. {
  2818. struct mwl8k_cmd_use_fixed_rate_ap *cmd;
  2819. int rc;
  2820. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2821. if (cmd == NULL)
  2822. return -ENOMEM;
  2823. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  2824. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2825. cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
  2826. cmd->multicast_rate = mcast;
  2827. cmd->management_rate = mgmt;
  2828. rc = mwl8k_post_cmd(hw, &cmd->header);
  2829. kfree(cmd);
  2830. return rc;
  2831. }
  2832. /*
  2833. * CMD_ENABLE_SNIFFER.
  2834. */
  2835. struct mwl8k_cmd_enable_sniffer {
  2836. struct mwl8k_cmd_pkt header;
  2837. __le32 action;
  2838. } __packed;
  2839. static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
  2840. {
  2841. struct mwl8k_cmd_enable_sniffer *cmd;
  2842. int rc;
  2843. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2844. if (cmd == NULL)
  2845. return -ENOMEM;
  2846. cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
  2847. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2848. cmd->action = cpu_to_le32(!!enable);
  2849. rc = mwl8k_post_cmd(hw, &cmd->header);
  2850. kfree(cmd);
  2851. return rc;
  2852. }
  2853. struct mwl8k_cmd_update_mac_addr {
  2854. struct mwl8k_cmd_pkt header;
  2855. union {
  2856. struct {
  2857. __le16 mac_type;
  2858. __u8 mac_addr[ETH_ALEN];
  2859. } mbss;
  2860. __u8 mac_addr[ETH_ALEN];
  2861. };
  2862. } __packed;
  2863. #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
  2864. #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
  2865. #define MWL8K_MAC_TYPE_PRIMARY_AP 2
  2866. #define MWL8K_MAC_TYPE_SECONDARY_AP 3
  2867. static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw,
  2868. struct ieee80211_vif *vif, u8 *mac, bool set)
  2869. {
  2870. struct mwl8k_priv *priv = hw->priv;
  2871. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  2872. struct mwl8k_cmd_update_mac_addr *cmd;
  2873. int mac_type;
  2874. int rc;
  2875. mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
  2876. if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
  2877. if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
  2878. mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
  2879. else
  2880. mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
  2881. } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
  2882. if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
  2883. mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
  2884. else
  2885. mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
  2886. }
  2887. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2888. if (cmd == NULL)
  2889. return -ENOMEM;
  2890. if (set)
  2891. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
  2892. else
  2893. cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR);
  2894. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2895. if (priv->ap_fw) {
  2896. cmd->mbss.mac_type = cpu_to_le16(mac_type);
  2897. memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
  2898. } else {
  2899. memcpy(cmd->mac_addr, mac, ETH_ALEN);
  2900. }
  2901. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2902. kfree(cmd);
  2903. return rc;
  2904. }
  2905. /*
  2906. * MWL8K_CMD_SET_MAC_ADDR.
  2907. */
  2908. static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
  2909. struct ieee80211_vif *vif, u8 *mac)
  2910. {
  2911. return mwl8k_cmd_update_mac_addr(hw, vif, mac, true);
  2912. }
  2913. /*
  2914. * MWL8K_CMD_DEL_MAC_ADDR.
  2915. */
  2916. static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw,
  2917. struct ieee80211_vif *vif, u8 *mac)
  2918. {
  2919. return mwl8k_cmd_update_mac_addr(hw, vif, mac, false);
  2920. }
  2921. /*
  2922. * CMD_SET_RATEADAPT_MODE.
  2923. */
  2924. struct mwl8k_cmd_set_rate_adapt_mode {
  2925. struct mwl8k_cmd_pkt header;
  2926. __le16 action;
  2927. __le16 mode;
  2928. } __packed;
  2929. static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
  2930. {
  2931. struct mwl8k_cmd_set_rate_adapt_mode *cmd;
  2932. int rc;
  2933. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2934. if (cmd == NULL)
  2935. return -ENOMEM;
  2936. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
  2937. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2938. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2939. cmd->mode = cpu_to_le16(mode);
  2940. rc = mwl8k_post_cmd(hw, &cmd->header);
  2941. kfree(cmd);
  2942. return rc;
  2943. }
  2944. /*
  2945. * CMD_GET_WATCHDOG_BITMAP.
  2946. */
  2947. struct mwl8k_cmd_get_watchdog_bitmap {
  2948. struct mwl8k_cmd_pkt header;
  2949. u8 bitmap;
  2950. } __packed;
  2951. static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
  2952. {
  2953. struct mwl8k_cmd_get_watchdog_bitmap *cmd;
  2954. int rc;
  2955. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2956. if (cmd == NULL)
  2957. return -ENOMEM;
  2958. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
  2959. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2960. rc = mwl8k_post_cmd(hw, &cmd->header);
  2961. if (!rc)
  2962. *bitmap = cmd->bitmap;
  2963. kfree(cmd);
  2964. return rc;
  2965. }
  2966. #define INVALID_BA 0xAA
  2967. static void mwl8k_watchdog_ba_events(struct work_struct *work)
  2968. {
  2969. int rc;
  2970. u8 bitmap = 0, stream_index;
  2971. struct mwl8k_ampdu_stream *streams;
  2972. struct mwl8k_priv *priv =
  2973. container_of(work, struct mwl8k_priv, watchdog_ba_handle);
  2974. rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
  2975. if (rc)
  2976. return;
  2977. if (bitmap == INVALID_BA)
  2978. return;
  2979. /* the bitmap is the hw queue number. Map it to the ampdu queue. */
  2980. stream_index = bitmap - MWL8K_TX_WMM_QUEUES;
  2981. BUG_ON(stream_index >= priv->num_ampdu_queues);
  2982. streams = &priv->ampdu[stream_index];
  2983. if (streams->state == AMPDU_STREAM_ACTIVE)
  2984. ieee80211_stop_tx_ba_session(streams->sta, streams->tid);
  2985. return;
  2986. }
  2987. /*
  2988. * CMD_BSS_START.
  2989. */
  2990. struct mwl8k_cmd_bss_start {
  2991. struct mwl8k_cmd_pkt header;
  2992. __le32 enable;
  2993. } __packed;
  2994. static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
  2995. struct ieee80211_vif *vif, int enable)
  2996. {
  2997. struct mwl8k_cmd_bss_start *cmd;
  2998. int rc;
  2999. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3000. if (cmd == NULL)
  3001. return -ENOMEM;
  3002. cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
  3003. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3004. cmd->enable = cpu_to_le32(enable);
  3005. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3006. kfree(cmd);
  3007. return rc;
  3008. }
  3009. /*
  3010. * CMD_BASTREAM.
  3011. */
  3012. /*
  3013. * UPSTREAM is tx direction
  3014. */
  3015. #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
  3016. #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
  3017. enum ba_stream_action_type {
  3018. MWL8K_BA_CREATE,
  3019. MWL8K_BA_UPDATE,
  3020. MWL8K_BA_DESTROY,
  3021. MWL8K_BA_FLUSH,
  3022. MWL8K_BA_CHECK,
  3023. };
  3024. struct mwl8k_create_ba_stream {
  3025. __le32 flags;
  3026. __le32 idle_thrs;
  3027. __le32 bar_thrs;
  3028. __le32 window_size;
  3029. u8 peer_mac_addr[6];
  3030. u8 dialog_token;
  3031. u8 tid;
  3032. u8 queue_id;
  3033. u8 param_info;
  3034. __le32 ba_context;
  3035. u8 reset_seq_no_flag;
  3036. __le16 curr_seq_no;
  3037. u8 sta_src_mac_addr[6];
  3038. } __packed;
  3039. struct mwl8k_destroy_ba_stream {
  3040. __le32 flags;
  3041. __le32 ba_context;
  3042. } __packed;
  3043. struct mwl8k_cmd_bastream {
  3044. struct mwl8k_cmd_pkt header;
  3045. __le32 action;
  3046. union {
  3047. struct mwl8k_create_ba_stream create_params;
  3048. struct mwl8k_destroy_ba_stream destroy_params;
  3049. };
  3050. } __packed;
  3051. static int
  3052. mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
  3053. {
  3054. struct mwl8k_cmd_bastream *cmd;
  3055. int rc;
  3056. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3057. if (cmd == NULL)
  3058. return -ENOMEM;
  3059. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3060. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3061. cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
  3062. cmd->create_params.queue_id = stream->idx;
  3063. memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
  3064. ETH_ALEN);
  3065. cmd->create_params.tid = stream->tid;
  3066. cmd->create_params.flags =
  3067. cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
  3068. cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
  3069. rc = mwl8k_post_cmd(hw, &cmd->header);
  3070. kfree(cmd);
  3071. return rc;
  3072. }
  3073. static int
  3074. mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
  3075. u8 buf_size)
  3076. {
  3077. struct mwl8k_cmd_bastream *cmd;
  3078. int rc;
  3079. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3080. if (cmd == NULL)
  3081. return -ENOMEM;
  3082. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3083. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3084. cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
  3085. cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
  3086. cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
  3087. cmd->create_params.queue_id = stream->idx;
  3088. memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
  3089. cmd->create_params.tid = stream->tid;
  3090. cmd->create_params.curr_seq_no = cpu_to_le16(0);
  3091. cmd->create_params.reset_seq_no_flag = 1;
  3092. cmd->create_params.param_info =
  3093. (stream->sta->ht_cap.ampdu_factor &
  3094. IEEE80211_HT_AMPDU_PARM_FACTOR) |
  3095. ((stream->sta->ht_cap.ampdu_density << 2) &
  3096. IEEE80211_HT_AMPDU_PARM_DENSITY);
  3097. cmd->create_params.flags =
  3098. cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
  3099. BASTREAM_FLAG_DIRECTION_UPSTREAM);
  3100. rc = mwl8k_post_cmd(hw, &cmd->header);
  3101. wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
  3102. stream->sta->addr, stream->tid);
  3103. kfree(cmd);
  3104. return rc;
  3105. }
  3106. static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
  3107. struct mwl8k_ampdu_stream *stream)
  3108. {
  3109. struct mwl8k_cmd_bastream *cmd;
  3110. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3111. if (cmd == NULL)
  3112. return;
  3113. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3114. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3115. cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
  3116. cmd->destroy_params.ba_context = cpu_to_le32(stream->idx);
  3117. mwl8k_post_cmd(hw, &cmd->header);
  3118. wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", stream->idx);
  3119. kfree(cmd);
  3120. }
  3121. /*
  3122. * CMD_SET_NEW_STN.
  3123. */
  3124. struct mwl8k_cmd_set_new_stn {
  3125. struct mwl8k_cmd_pkt header;
  3126. __le16 aid;
  3127. __u8 mac_addr[6];
  3128. __le16 stn_id;
  3129. __le16 action;
  3130. __le16 rsvd;
  3131. __le32 legacy_rates;
  3132. __u8 ht_rates[4];
  3133. __le16 cap_info;
  3134. __le16 ht_capabilities_info;
  3135. __u8 mac_ht_param_info;
  3136. __u8 rev;
  3137. __u8 control_channel;
  3138. __u8 add_channel;
  3139. __le16 op_mode;
  3140. __le16 stbc;
  3141. __u8 add_qos_info;
  3142. __u8 is_qos_sta;
  3143. __le32 fw_sta_ptr;
  3144. } __packed;
  3145. #define MWL8K_STA_ACTION_ADD 0
  3146. #define MWL8K_STA_ACTION_REMOVE 2
  3147. static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
  3148. struct ieee80211_vif *vif,
  3149. struct ieee80211_sta *sta)
  3150. {
  3151. struct mwl8k_cmd_set_new_stn *cmd;
  3152. u32 rates;
  3153. int rc;
  3154. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3155. if (cmd == NULL)
  3156. return -ENOMEM;
  3157. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3158. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3159. cmd->aid = cpu_to_le16(sta->aid);
  3160. memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
  3161. cmd->stn_id = cpu_to_le16(sta->aid);
  3162. cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
  3163. if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
  3164. rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
  3165. else
  3166. rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  3167. cmd->legacy_rates = cpu_to_le32(rates);
  3168. if (sta->ht_cap.ht_supported) {
  3169. cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
  3170. cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
  3171. cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
  3172. cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
  3173. cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
  3174. cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
  3175. ((sta->ht_cap.ampdu_density & 7) << 2);
  3176. cmd->is_qos_sta = 1;
  3177. }
  3178. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3179. kfree(cmd);
  3180. return rc;
  3181. }
  3182. static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
  3183. struct ieee80211_vif *vif)
  3184. {
  3185. struct mwl8k_cmd_set_new_stn *cmd;
  3186. int rc;
  3187. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3188. if (cmd == NULL)
  3189. return -ENOMEM;
  3190. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3191. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3192. memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
  3193. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3194. kfree(cmd);
  3195. return rc;
  3196. }
  3197. static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
  3198. struct ieee80211_vif *vif, u8 *addr)
  3199. {
  3200. struct mwl8k_cmd_set_new_stn *cmd;
  3201. int rc;
  3202. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3203. if (cmd == NULL)
  3204. return -ENOMEM;
  3205. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3206. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3207. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3208. cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
  3209. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3210. kfree(cmd);
  3211. return rc;
  3212. }
  3213. /*
  3214. * CMD_UPDATE_ENCRYPTION.
  3215. */
  3216. #define MAX_ENCR_KEY_LENGTH 16
  3217. #define MIC_KEY_LENGTH 8
  3218. struct mwl8k_cmd_update_encryption {
  3219. struct mwl8k_cmd_pkt header;
  3220. __le32 action;
  3221. __le32 reserved;
  3222. __u8 mac_addr[6];
  3223. __u8 encr_type;
  3224. } __packed;
  3225. struct mwl8k_cmd_set_key {
  3226. struct mwl8k_cmd_pkt header;
  3227. __le32 action;
  3228. __le32 reserved;
  3229. __le16 length;
  3230. __le16 key_type_id;
  3231. __le32 key_info;
  3232. __le32 key_id;
  3233. __le16 key_len;
  3234. __u8 key_material[MAX_ENCR_KEY_LENGTH];
  3235. __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
  3236. __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
  3237. __le16 tkip_rsc_low;
  3238. __le32 tkip_rsc_high;
  3239. __le16 tkip_tsc_low;
  3240. __le32 tkip_tsc_high;
  3241. __u8 mac_addr[6];
  3242. } __packed;
  3243. enum {
  3244. MWL8K_ENCR_ENABLE,
  3245. MWL8K_ENCR_SET_KEY,
  3246. MWL8K_ENCR_REMOVE_KEY,
  3247. MWL8K_ENCR_SET_GROUP_KEY,
  3248. };
  3249. #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
  3250. #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
  3251. #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
  3252. #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
  3253. #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
  3254. enum {
  3255. MWL8K_ALG_WEP,
  3256. MWL8K_ALG_TKIP,
  3257. MWL8K_ALG_CCMP,
  3258. };
  3259. #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
  3260. #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
  3261. #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
  3262. #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
  3263. #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
  3264. static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
  3265. struct ieee80211_vif *vif,
  3266. u8 *addr,
  3267. u8 encr_type)
  3268. {
  3269. struct mwl8k_cmd_update_encryption *cmd;
  3270. int rc;
  3271. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3272. if (cmd == NULL)
  3273. return -ENOMEM;
  3274. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
  3275. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3276. cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
  3277. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3278. cmd->encr_type = encr_type;
  3279. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3280. kfree(cmd);
  3281. return rc;
  3282. }
  3283. static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
  3284. u8 *addr,
  3285. struct ieee80211_key_conf *key)
  3286. {
  3287. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
  3288. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3289. cmd->length = cpu_to_le16(sizeof(*cmd) -
  3290. offsetof(struct mwl8k_cmd_set_key, length));
  3291. cmd->key_id = cpu_to_le32(key->keyidx);
  3292. cmd->key_len = cpu_to_le16(key->keylen);
  3293. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3294. switch (key->cipher) {
  3295. case WLAN_CIPHER_SUITE_WEP40:
  3296. case WLAN_CIPHER_SUITE_WEP104:
  3297. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
  3298. if (key->keyidx == 0)
  3299. cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
  3300. break;
  3301. case WLAN_CIPHER_SUITE_TKIP:
  3302. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
  3303. cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3304. ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
  3305. : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
  3306. cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
  3307. | MWL8K_KEY_FLAG_TSC_VALID);
  3308. break;
  3309. case WLAN_CIPHER_SUITE_CCMP:
  3310. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
  3311. cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3312. ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
  3313. : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
  3314. break;
  3315. default:
  3316. return -ENOTSUPP;
  3317. }
  3318. return 0;
  3319. }
  3320. static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
  3321. struct ieee80211_vif *vif,
  3322. u8 *addr,
  3323. struct ieee80211_key_conf *key)
  3324. {
  3325. struct mwl8k_cmd_set_key *cmd;
  3326. int rc;
  3327. int keymlen;
  3328. u32 action;
  3329. u8 idx;
  3330. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3331. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3332. if (cmd == NULL)
  3333. return -ENOMEM;
  3334. rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
  3335. if (rc < 0)
  3336. goto done;
  3337. idx = key->keyidx;
  3338. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3339. action = MWL8K_ENCR_SET_KEY;
  3340. else
  3341. action = MWL8K_ENCR_SET_GROUP_KEY;
  3342. switch (key->cipher) {
  3343. case WLAN_CIPHER_SUITE_WEP40:
  3344. case WLAN_CIPHER_SUITE_WEP104:
  3345. if (!mwl8k_vif->wep_key_conf[idx].enabled) {
  3346. memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
  3347. sizeof(*key) + key->keylen);
  3348. mwl8k_vif->wep_key_conf[idx].enabled = 1;
  3349. }
  3350. keymlen = key->keylen;
  3351. action = MWL8K_ENCR_SET_KEY;
  3352. break;
  3353. case WLAN_CIPHER_SUITE_TKIP:
  3354. keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
  3355. break;
  3356. case WLAN_CIPHER_SUITE_CCMP:
  3357. keymlen = key->keylen;
  3358. break;
  3359. default:
  3360. rc = -ENOTSUPP;
  3361. goto done;
  3362. }
  3363. memcpy(cmd->key_material, key->key, keymlen);
  3364. cmd->action = cpu_to_le32(action);
  3365. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3366. done:
  3367. kfree(cmd);
  3368. return rc;
  3369. }
  3370. static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
  3371. struct ieee80211_vif *vif,
  3372. u8 *addr,
  3373. struct ieee80211_key_conf *key)
  3374. {
  3375. struct mwl8k_cmd_set_key *cmd;
  3376. int rc;
  3377. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3378. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3379. if (cmd == NULL)
  3380. return -ENOMEM;
  3381. rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
  3382. if (rc < 0)
  3383. goto done;
  3384. if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  3385. key->cipher == WLAN_CIPHER_SUITE_WEP104)
  3386. mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
  3387. cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
  3388. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3389. done:
  3390. kfree(cmd);
  3391. return rc;
  3392. }
  3393. static int mwl8k_set_key(struct ieee80211_hw *hw,
  3394. enum set_key_cmd cmd_param,
  3395. struct ieee80211_vif *vif,
  3396. struct ieee80211_sta *sta,
  3397. struct ieee80211_key_conf *key)
  3398. {
  3399. int rc = 0;
  3400. u8 encr_type;
  3401. u8 *addr;
  3402. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3403. if (vif->type == NL80211_IFTYPE_STATION)
  3404. return -EOPNOTSUPP;
  3405. if (sta == NULL)
  3406. addr = vif->addr;
  3407. else
  3408. addr = sta->addr;
  3409. if (cmd_param == SET_KEY) {
  3410. rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
  3411. if (rc)
  3412. goto out;
  3413. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
  3414. || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
  3415. encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
  3416. else
  3417. encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
  3418. rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
  3419. encr_type);
  3420. if (rc)
  3421. goto out;
  3422. mwl8k_vif->is_hw_crypto_enabled = true;
  3423. } else {
  3424. rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
  3425. if (rc)
  3426. goto out;
  3427. }
  3428. out:
  3429. return rc;
  3430. }
  3431. /*
  3432. * CMD_UPDATE_STADB.
  3433. */
  3434. struct ewc_ht_info {
  3435. __le16 control1;
  3436. __le16 control2;
  3437. __le16 control3;
  3438. } __packed;
  3439. struct peer_capability_info {
  3440. /* Peer type - AP vs. STA. */
  3441. __u8 peer_type;
  3442. /* Basic 802.11 capabilities from assoc resp. */
  3443. __le16 basic_caps;
  3444. /* Set if peer supports 802.11n high throughput (HT). */
  3445. __u8 ht_support;
  3446. /* Valid if HT is supported. */
  3447. __le16 ht_caps;
  3448. __u8 extended_ht_caps;
  3449. struct ewc_ht_info ewc_info;
  3450. /* Legacy rate table. Intersection of our rates and peer rates. */
  3451. __u8 legacy_rates[12];
  3452. /* HT rate table. Intersection of our rates and peer rates. */
  3453. __u8 ht_rates[16];
  3454. __u8 pad[16];
  3455. /* If set, interoperability mode, no proprietary extensions. */
  3456. __u8 interop;
  3457. __u8 pad2;
  3458. __u8 station_id;
  3459. __le16 amsdu_enabled;
  3460. } __packed;
  3461. struct mwl8k_cmd_update_stadb {
  3462. struct mwl8k_cmd_pkt header;
  3463. /* See STADB_ACTION_TYPE */
  3464. __le32 action;
  3465. /* Peer MAC address */
  3466. __u8 peer_addr[ETH_ALEN];
  3467. __le32 reserved;
  3468. /* Peer info - valid during add/update. */
  3469. struct peer_capability_info peer_info;
  3470. } __packed;
  3471. #define MWL8K_STA_DB_MODIFY_ENTRY 1
  3472. #define MWL8K_STA_DB_DEL_ENTRY 2
  3473. /* Peer Entry flags - used to define the type of the peer node */
  3474. #define MWL8K_PEER_TYPE_ACCESSPOINT 2
  3475. static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
  3476. struct ieee80211_vif *vif,
  3477. struct ieee80211_sta *sta)
  3478. {
  3479. struct mwl8k_cmd_update_stadb *cmd;
  3480. struct peer_capability_info *p;
  3481. u32 rates;
  3482. int rc;
  3483. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3484. if (cmd == NULL)
  3485. return -ENOMEM;
  3486. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  3487. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3488. cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
  3489. memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
  3490. p = &cmd->peer_info;
  3491. p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
  3492. p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
  3493. p->ht_support = sta->ht_cap.ht_supported;
  3494. p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
  3495. p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
  3496. ((sta->ht_cap.ampdu_density & 7) << 2);
  3497. if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
  3498. rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
  3499. else
  3500. rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  3501. legacy_rate_mask_to_array(p->legacy_rates, rates);
  3502. memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
  3503. p->interop = 1;
  3504. p->amsdu_enabled = 0;
  3505. rc = mwl8k_post_cmd(hw, &cmd->header);
  3506. kfree(cmd);
  3507. return rc ? rc : p->station_id;
  3508. }
  3509. static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
  3510. struct ieee80211_vif *vif, u8 *addr)
  3511. {
  3512. struct mwl8k_cmd_update_stadb *cmd;
  3513. int rc;
  3514. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3515. if (cmd == NULL)
  3516. return -ENOMEM;
  3517. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  3518. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3519. cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
  3520. memcpy(cmd->peer_addr, addr, ETH_ALEN);
  3521. rc = mwl8k_post_cmd(hw, &cmd->header);
  3522. kfree(cmd);
  3523. return rc;
  3524. }
  3525. /*
  3526. * Interrupt handling.
  3527. */
  3528. static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
  3529. {
  3530. struct ieee80211_hw *hw = dev_id;
  3531. struct mwl8k_priv *priv = hw->priv;
  3532. u32 status;
  3533. status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3534. if (!status)
  3535. return IRQ_NONE;
  3536. if (status & MWL8K_A2H_INT_TX_DONE) {
  3537. status &= ~MWL8K_A2H_INT_TX_DONE;
  3538. tasklet_schedule(&priv->poll_tx_task);
  3539. }
  3540. if (status & MWL8K_A2H_INT_RX_READY) {
  3541. status &= ~MWL8K_A2H_INT_RX_READY;
  3542. tasklet_schedule(&priv->poll_rx_task);
  3543. }
  3544. if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
  3545. status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
  3546. ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
  3547. }
  3548. if (status)
  3549. iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3550. if (status & MWL8K_A2H_INT_OPC_DONE) {
  3551. if (priv->hostcmd_wait != NULL)
  3552. complete(priv->hostcmd_wait);
  3553. }
  3554. if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
  3555. if (!mutex_is_locked(&priv->fw_mutex) &&
  3556. priv->radio_on && priv->pending_tx_pkts)
  3557. mwl8k_tx_start(priv);
  3558. }
  3559. return IRQ_HANDLED;
  3560. }
  3561. static void mwl8k_tx_poll(unsigned long data)
  3562. {
  3563. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  3564. struct mwl8k_priv *priv = hw->priv;
  3565. int limit;
  3566. int i;
  3567. limit = 32;
  3568. spin_lock_bh(&priv->tx_lock);
  3569. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  3570. limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
  3571. if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
  3572. complete(priv->tx_wait);
  3573. priv->tx_wait = NULL;
  3574. }
  3575. spin_unlock_bh(&priv->tx_lock);
  3576. if (limit) {
  3577. writel(~MWL8K_A2H_INT_TX_DONE,
  3578. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3579. } else {
  3580. tasklet_schedule(&priv->poll_tx_task);
  3581. }
  3582. }
  3583. static void mwl8k_rx_poll(unsigned long data)
  3584. {
  3585. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  3586. struct mwl8k_priv *priv = hw->priv;
  3587. int limit;
  3588. limit = 32;
  3589. limit -= rxq_process(hw, 0, limit);
  3590. limit -= rxq_refill(hw, 0, limit);
  3591. if (limit) {
  3592. writel(~MWL8K_A2H_INT_RX_READY,
  3593. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3594. } else {
  3595. tasklet_schedule(&priv->poll_rx_task);
  3596. }
  3597. }
  3598. /*
  3599. * Core driver operations.
  3600. */
  3601. static void mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  3602. {
  3603. struct mwl8k_priv *priv = hw->priv;
  3604. int index = skb_get_queue_mapping(skb);
  3605. if (!priv->radio_on) {
  3606. wiphy_debug(hw->wiphy,
  3607. "dropped TX frame since radio disabled\n");
  3608. dev_kfree_skb(skb);
  3609. return;
  3610. }
  3611. mwl8k_txq_xmit(hw, index, skb);
  3612. }
  3613. static int mwl8k_start(struct ieee80211_hw *hw)
  3614. {
  3615. struct mwl8k_priv *priv = hw->priv;
  3616. int rc;
  3617. rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
  3618. IRQF_SHARED, MWL8K_NAME, hw);
  3619. if (rc) {
  3620. priv->irq = -1;
  3621. wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
  3622. return -EIO;
  3623. }
  3624. priv->irq = priv->pdev->irq;
  3625. /* Enable TX reclaim and RX tasklets. */
  3626. tasklet_enable(&priv->poll_tx_task);
  3627. tasklet_enable(&priv->poll_rx_task);
  3628. /* Enable interrupts */
  3629. iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3630. iowrite32(MWL8K_A2H_EVENTS,
  3631. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3632. rc = mwl8k_fw_lock(hw);
  3633. if (!rc) {
  3634. rc = mwl8k_cmd_radio_enable(hw);
  3635. if (!priv->ap_fw) {
  3636. if (!rc)
  3637. rc = mwl8k_cmd_enable_sniffer(hw, 0);
  3638. if (!rc)
  3639. rc = mwl8k_cmd_set_pre_scan(hw);
  3640. if (!rc)
  3641. rc = mwl8k_cmd_set_post_scan(hw,
  3642. "\x00\x00\x00\x00\x00\x00");
  3643. }
  3644. if (!rc)
  3645. rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
  3646. if (!rc)
  3647. rc = mwl8k_cmd_set_wmm_mode(hw, 0);
  3648. mwl8k_fw_unlock(hw);
  3649. }
  3650. if (rc) {
  3651. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3652. free_irq(priv->pdev->irq, hw);
  3653. priv->irq = -1;
  3654. tasklet_disable(&priv->poll_tx_task);
  3655. tasklet_disable(&priv->poll_rx_task);
  3656. }
  3657. return rc;
  3658. }
  3659. static void mwl8k_stop(struct ieee80211_hw *hw)
  3660. {
  3661. struct mwl8k_priv *priv = hw->priv;
  3662. int i;
  3663. if (!priv->hw_restart_in_progress)
  3664. mwl8k_cmd_radio_disable(hw);
  3665. ieee80211_stop_queues(hw);
  3666. /* Disable interrupts */
  3667. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3668. if (priv->irq != -1) {
  3669. free_irq(priv->pdev->irq, hw);
  3670. priv->irq = -1;
  3671. }
  3672. /* Stop finalize join worker */
  3673. cancel_work_sync(&priv->finalize_join_worker);
  3674. cancel_work_sync(&priv->watchdog_ba_handle);
  3675. if (priv->beacon_skb != NULL)
  3676. dev_kfree_skb(priv->beacon_skb);
  3677. /* Stop TX reclaim and RX tasklets. */
  3678. tasklet_disable(&priv->poll_tx_task);
  3679. tasklet_disable(&priv->poll_rx_task);
  3680. /* Return all skbs to mac80211 */
  3681. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  3682. mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  3683. }
  3684. static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
  3685. static int mwl8k_add_interface(struct ieee80211_hw *hw,
  3686. struct ieee80211_vif *vif)
  3687. {
  3688. struct mwl8k_priv *priv = hw->priv;
  3689. struct mwl8k_vif *mwl8k_vif;
  3690. u32 macids_supported;
  3691. int macid, rc;
  3692. struct mwl8k_device_info *di;
  3693. /*
  3694. * Reject interface creation if sniffer mode is active, as
  3695. * STA operation is mutually exclusive with hardware sniffer
  3696. * mode. (Sniffer mode is only used on STA firmware.)
  3697. */
  3698. if (priv->sniffer_enabled) {
  3699. wiphy_info(hw->wiphy,
  3700. "unable to create STA interface because sniffer mode is enabled\n");
  3701. return -EINVAL;
  3702. }
  3703. di = priv->device_info;
  3704. switch (vif->type) {
  3705. case NL80211_IFTYPE_AP:
  3706. if (!priv->ap_fw && di->fw_image_ap) {
  3707. /* we must load the ap fw to meet this request */
  3708. if (!list_empty(&priv->vif_list))
  3709. return -EBUSY;
  3710. rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
  3711. if (rc)
  3712. return rc;
  3713. }
  3714. macids_supported = priv->ap_macids_supported;
  3715. break;
  3716. case NL80211_IFTYPE_STATION:
  3717. if (priv->ap_fw && di->fw_image_sta) {
  3718. /* we must load the sta fw to meet this request */
  3719. if (!list_empty(&priv->vif_list))
  3720. return -EBUSY;
  3721. rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
  3722. if (rc)
  3723. return rc;
  3724. }
  3725. macids_supported = priv->sta_macids_supported;
  3726. break;
  3727. default:
  3728. return -EINVAL;
  3729. }
  3730. macid = ffs(macids_supported & ~priv->macids_used);
  3731. if (!macid--)
  3732. return -EBUSY;
  3733. /* Setup driver private area. */
  3734. mwl8k_vif = MWL8K_VIF(vif);
  3735. memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
  3736. mwl8k_vif->vif = vif;
  3737. mwl8k_vif->macid = macid;
  3738. mwl8k_vif->seqno = 0;
  3739. memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
  3740. mwl8k_vif->is_hw_crypto_enabled = false;
  3741. /* Set the mac address. */
  3742. mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
  3743. if (priv->ap_fw)
  3744. mwl8k_cmd_set_new_stn_add_self(hw, vif);
  3745. priv->macids_used |= 1 << mwl8k_vif->macid;
  3746. list_add_tail(&mwl8k_vif->list, &priv->vif_list);
  3747. return 0;
  3748. }
  3749. static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif)
  3750. {
  3751. /* Has ieee80211_restart_hw re-added the removed interfaces? */
  3752. if (!priv->macids_used)
  3753. return;
  3754. priv->macids_used &= ~(1 << vif->macid);
  3755. list_del(&vif->list);
  3756. }
  3757. static void mwl8k_remove_interface(struct ieee80211_hw *hw,
  3758. struct ieee80211_vif *vif)
  3759. {
  3760. struct mwl8k_priv *priv = hw->priv;
  3761. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3762. if (priv->ap_fw)
  3763. mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
  3764. mwl8k_cmd_del_mac_addr(hw, vif, vif->addr);
  3765. mwl8k_remove_vif(priv, mwl8k_vif);
  3766. }
  3767. static void mwl8k_hw_restart_work(struct work_struct *work)
  3768. {
  3769. struct mwl8k_priv *priv =
  3770. container_of(work, struct mwl8k_priv, fw_reload);
  3771. struct ieee80211_hw *hw = priv->hw;
  3772. struct mwl8k_device_info *di;
  3773. int rc;
  3774. /* If some command is waiting for a response, clear it */
  3775. if (priv->hostcmd_wait != NULL) {
  3776. complete(priv->hostcmd_wait);
  3777. priv->hostcmd_wait = NULL;
  3778. }
  3779. priv->hw_restart_owner = current;
  3780. di = priv->device_info;
  3781. mwl8k_fw_lock(hw);
  3782. if (priv->ap_fw)
  3783. rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
  3784. else
  3785. rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
  3786. if (rc)
  3787. goto fail;
  3788. priv->hw_restart_owner = NULL;
  3789. priv->hw_restart_in_progress = false;
  3790. /*
  3791. * This unlock will wake up the queues and
  3792. * also opens the command path for other
  3793. * commands
  3794. */
  3795. mwl8k_fw_unlock(hw);
  3796. ieee80211_restart_hw(hw);
  3797. wiphy_err(hw->wiphy, "Firmware restarted successfully\n");
  3798. return;
  3799. fail:
  3800. mwl8k_fw_unlock(hw);
  3801. wiphy_err(hw->wiphy, "Firmware restart failed\n");
  3802. }
  3803. static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
  3804. {
  3805. struct ieee80211_conf *conf = &hw->conf;
  3806. struct mwl8k_priv *priv = hw->priv;
  3807. int rc;
  3808. if (conf->flags & IEEE80211_CONF_IDLE) {
  3809. mwl8k_cmd_radio_disable(hw);
  3810. return 0;
  3811. }
  3812. rc = mwl8k_fw_lock(hw);
  3813. if (rc)
  3814. return rc;
  3815. rc = mwl8k_cmd_radio_enable(hw);
  3816. if (rc)
  3817. goto out;
  3818. rc = mwl8k_cmd_set_rf_channel(hw, conf);
  3819. if (rc)
  3820. goto out;
  3821. if (conf->power_level > 18)
  3822. conf->power_level = 18;
  3823. if (priv->ap_fw) {
  3824. if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
  3825. rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
  3826. if (rc)
  3827. goto out;
  3828. }
  3829. rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
  3830. if (rc)
  3831. wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
  3832. rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
  3833. if (rc)
  3834. wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
  3835. } else {
  3836. rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
  3837. if (rc)
  3838. goto out;
  3839. rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
  3840. }
  3841. out:
  3842. mwl8k_fw_unlock(hw);
  3843. return rc;
  3844. }
  3845. static void
  3846. mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3847. struct ieee80211_bss_conf *info, u32 changed)
  3848. {
  3849. struct mwl8k_priv *priv = hw->priv;
  3850. u32 ap_legacy_rates = 0;
  3851. u8 ap_mcs_rates[16];
  3852. int rc;
  3853. if (mwl8k_fw_lock(hw))
  3854. return;
  3855. /*
  3856. * No need to capture a beacon if we're no longer associated.
  3857. */
  3858. if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
  3859. priv->capture_beacon = false;
  3860. /*
  3861. * Get the AP's legacy and MCS rates.
  3862. */
  3863. if (vif->bss_conf.assoc) {
  3864. struct ieee80211_sta *ap;
  3865. rcu_read_lock();
  3866. ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
  3867. if (ap == NULL) {
  3868. rcu_read_unlock();
  3869. goto out;
  3870. }
  3871. if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
  3872. ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
  3873. } else {
  3874. ap_legacy_rates =
  3875. ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  3876. }
  3877. memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
  3878. rcu_read_unlock();
  3879. }
  3880. if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
  3881. rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
  3882. if (rc)
  3883. goto out;
  3884. rc = mwl8k_cmd_use_fixed_rate_sta(hw);
  3885. if (rc)
  3886. goto out;
  3887. }
  3888. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  3889. rc = mwl8k_set_radio_preamble(hw,
  3890. vif->bss_conf.use_short_preamble);
  3891. if (rc)
  3892. goto out;
  3893. }
  3894. if (changed & BSS_CHANGED_ERP_SLOT) {
  3895. rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
  3896. if (rc)
  3897. goto out;
  3898. }
  3899. if (vif->bss_conf.assoc &&
  3900. (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
  3901. BSS_CHANGED_HT))) {
  3902. rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
  3903. if (rc)
  3904. goto out;
  3905. }
  3906. if (vif->bss_conf.assoc &&
  3907. (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
  3908. /*
  3909. * Finalize the join. Tell rx handler to process
  3910. * next beacon from our BSSID.
  3911. */
  3912. memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
  3913. priv->capture_beacon = true;
  3914. }
  3915. out:
  3916. mwl8k_fw_unlock(hw);
  3917. }
  3918. static void
  3919. mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3920. struct ieee80211_bss_conf *info, u32 changed)
  3921. {
  3922. int rc;
  3923. if (mwl8k_fw_lock(hw))
  3924. return;
  3925. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  3926. rc = mwl8k_set_radio_preamble(hw,
  3927. vif->bss_conf.use_short_preamble);
  3928. if (rc)
  3929. goto out;
  3930. }
  3931. if (changed & BSS_CHANGED_BASIC_RATES) {
  3932. int idx;
  3933. int rate;
  3934. /*
  3935. * Use lowest supported basic rate for multicasts
  3936. * and management frames (such as probe responses --
  3937. * beacons will always go out at 1 Mb/s).
  3938. */
  3939. idx = ffs(vif->bss_conf.basic_rates);
  3940. if (idx)
  3941. idx--;
  3942. if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
  3943. rate = mwl8k_rates_24[idx].hw_value;
  3944. else
  3945. rate = mwl8k_rates_50[idx].hw_value;
  3946. mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
  3947. }
  3948. if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
  3949. struct sk_buff *skb;
  3950. skb = ieee80211_beacon_get(hw, vif);
  3951. if (skb != NULL) {
  3952. mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
  3953. kfree_skb(skb);
  3954. }
  3955. }
  3956. if (changed & BSS_CHANGED_BEACON_ENABLED)
  3957. mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
  3958. out:
  3959. mwl8k_fw_unlock(hw);
  3960. }
  3961. static void
  3962. mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3963. struct ieee80211_bss_conf *info, u32 changed)
  3964. {
  3965. struct mwl8k_priv *priv = hw->priv;
  3966. if (!priv->ap_fw)
  3967. mwl8k_bss_info_changed_sta(hw, vif, info, changed);
  3968. else
  3969. mwl8k_bss_info_changed_ap(hw, vif, info, changed);
  3970. }
  3971. static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
  3972. struct netdev_hw_addr_list *mc_list)
  3973. {
  3974. struct mwl8k_cmd_pkt *cmd;
  3975. /*
  3976. * Synthesize and return a command packet that programs the
  3977. * hardware multicast address filter. At this point we don't
  3978. * know whether FIF_ALLMULTI is being requested, but if it is,
  3979. * we'll end up throwing this packet away and creating a new
  3980. * one in mwl8k_configure_filter().
  3981. */
  3982. cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
  3983. return (unsigned long)cmd;
  3984. }
  3985. static int
  3986. mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
  3987. unsigned int changed_flags,
  3988. unsigned int *total_flags)
  3989. {
  3990. struct mwl8k_priv *priv = hw->priv;
  3991. /*
  3992. * Hardware sniffer mode is mutually exclusive with STA
  3993. * operation, so refuse to enable sniffer mode if a STA
  3994. * interface is active.
  3995. */
  3996. if (!list_empty(&priv->vif_list)) {
  3997. if (net_ratelimit())
  3998. wiphy_info(hw->wiphy,
  3999. "not enabling sniffer mode because STA interface is active\n");
  4000. return 0;
  4001. }
  4002. if (!priv->sniffer_enabled) {
  4003. if (mwl8k_cmd_enable_sniffer(hw, 1))
  4004. return 0;
  4005. priv->sniffer_enabled = true;
  4006. }
  4007. *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
  4008. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
  4009. FIF_OTHER_BSS;
  4010. return 1;
  4011. }
  4012. static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
  4013. {
  4014. if (!list_empty(&priv->vif_list))
  4015. return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
  4016. return NULL;
  4017. }
  4018. static void mwl8k_configure_filter(struct ieee80211_hw *hw,
  4019. unsigned int changed_flags,
  4020. unsigned int *total_flags,
  4021. u64 multicast)
  4022. {
  4023. struct mwl8k_priv *priv = hw->priv;
  4024. struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
  4025. /*
  4026. * AP firmware doesn't allow fine-grained control over
  4027. * the receive filter.
  4028. */
  4029. if (priv->ap_fw) {
  4030. *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
  4031. kfree(cmd);
  4032. return;
  4033. }
  4034. /*
  4035. * Enable hardware sniffer mode if FIF_CONTROL or
  4036. * FIF_OTHER_BSS is requested.
  4037. */
  4038. if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
  4039. mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
  4040. kfree(cmd);
  4041. return;
  4042. }
  4043. /* Clear unsupported feature flags */
  4044. *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
  4045. if (mwl8k_fw_lock(hw)) {
  4046. kfree(cmd);
  4047. return;
  4048. }
  4049. if (priv->sniffer_enabled) {
  4050. mwl8k_cmd_enable_sniffer(hw, 0);
  4051. priv->sniffer_enabled = false;
  4052. }
  4053. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  4054. if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
  4055. /*
  4056. * Disable the BSS filter.
  4057. */
  4058. mwl8k_cmd_set_pre_scan(hw);
  4059. } else {
  4060. struct mwl8k_vif *mwl8k_vif;
  4061. const u8 *bssid;
  4062. /*
  4063. * Enable the BSS filter.
  4064. *
  4065. * If there is an active STA interface, use that
  4066. * interface's BSSID, otherwise use a dummy one
  4067. * (where the OUI part needs to be nonzero for
  4068. * the BSSID to be accepted by POST_SCAN).
  4069. */
  4070. mwl8k_vif = mwl8k_first_vif(priv);
  4071. if (mwl8k_vif != NULL)
  4072. bssid = mwl8k_vif->vif->bss_conf.bssid;
  4073. else
  4074. bssid = "\x01\x00\x00\x00\x00\x00";
  4075. mwl8k_cmd_set_post_scan(hw, bssid);
  4076. }
  4077. }
  4078. /*
  4079. * If FIF_ALLMULTI is being requested, throw away the command
  4080. * packet that ->prepare_multicast() built and replace it with
  4081. * a command packet that enables reception of all multicast
  4082. * packets.
  4083. */
  4084. if (*total_flags & FIF_ALLMULTI) {
  4085. kfree(cmd);
  4086. cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
  4087. }
  4088. if (cmd != NULL) {
  4089. mwl8k_post_cmd(hw, cmd);
  4090. kfree(cmd);
  4091. }
  4092. mwl8k_fw_unlock(hw);
  4093. }
  4094. static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  4095. {
  4096. return mwl8k_cmd_set_rts_threshold(hw, value);
  4097. }
  4098. static int mwl8k_sta_remove(struct ieee80211_hw *hw,
  4099. struct ieee80211_vif *vif,
  4100. struct ieee80211_sta *sta)
  4101. {
  4102. struct mwl8k_priv *priv = hw->priv;
  4103. if (priv->ap_fw)
  4104. return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
  4105. else
  4106. return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
  4107. }
  4108. static int mwl8k_sta_add(struct ieee80211_hw *hw,
  4109. struct ieee80211_vif *vif,
  4110. struct ieee80211_sta *sta)
  4111. {
  4112. struct mwl8k_priv *priv = hw->priv;
  4113. int ret;
  4114. int i;
  4115. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  4116. struct ieee80211_key_conf *key;
  4117. if (!priv->ap_fw) {
  4118. ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
  4119. if (ret >= 0) {
  4120. MWL8K_STA(sta)->peer_id = ret;
  4121. if (sta->ht_cap.ht_supported)
  4122. MWL8K_STA(sta)->is_ampdu_allowed = true;
  4123. ret = 0;
  4124. }
  4125. } else {
  4126. ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
  4127. }
  4128. for (i = 0; i < NUM_WEP_KEYS; i++) {
  4129. key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
  4130. if (mwl8k_vif->wep_key_conf[i].enabled)
  4131. mwl8k_set_key(hw, SET_KEY, vif, sta, key);
  4132. }
  4133. return ret;
  4134. }
  4135. static int mwl8k_conf_tx(struct ieee80211_hw *hw,
  4136. struct ieee80211_vif *vif, u16 queue,
  4137. const struct ieee80211_tx_queue_params *params)
  4138. {
  4139. struct mwl8k_priv *priv = hw->priv;
  4140. int rc;
  4141. rc = mwl8k_fw_lock(hw);
  4142. if (!rc) {
  4143. BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
  4144. memcpy(&priv->wmm_params[queue], params, sizeof(*params));
  4145. if (!priv->wmm_enabled)
  4146. rc = mwl8k_cmd_set_wmm_mode(hw, 1);
  4147. if (!rc) {
  4148. int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
  4149. rc = mwl8k_cmd_set_edca_params(hw, q,
  4150. params->cw_min,
  4151. params->cw_max,
  4152. params->aifs,
  4153. params->txop);
  4154. }
  4155. mwl8k_fw_unlock(hw);
  4156. }
  4157. return rc;
  4158. }
  4159. static int mwl8k_get_stats(struct ieee80211_hw *hw,
  4160. struct ieee80211_low_level_stats *stats)
  4161. {
  4162. return mwl8k_cmd_get_stat(hw, stats);
  4163. }
  4164. static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
  4165. struct survey_info *survey)
  4166. {
  4167. struct mwl8k_priv *priv = hw->priv;
  4168. struct ieee80211_conf *conf = &hw->conf;
  4169. if (idx != 0)
  4170. return -ENOENT;
  4171. survey->channel = conf->channel;
  4172. survey->filled = SURVEY_INFO_NOISE_DBM;
  4173. survey->noise = priv->noise;
  4174. return 0;
  4175. }
  4176. #define MAX_AMPDU_ATTEMPTS 5
  4177. static int
  4178. mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4179. enum ieee80211_ampdu_mlme_action action,
  4180. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  4181. u8 buf_size)
  4182. {
  4183. int i, rc = 0;
  4184. struct mwl8k_priv *priv = hw->priv;
  4185. struct mwl8k_ampdu_stream *stream;
  4186. u8 *addr = sta->addr;
  4187. if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
  4188. return -ENOTSUPP;
  4189. spin_lock(&priv->stream_lock);
  4190. stream = mwl8k_lookup_stream(hw, addr, tid);
  4191. switch (action) {
  4192. case IEEE80211_AMPDU_RX_START:
  4193. case IEEE80211_AMPDU_RX_STOP:
  4194. break;
  4195. case IEEE80211_AMPDU_TX_START:
  4196. /* By the time we get here the hw queues may contain outgoing
  4197. * packets for this RA/TID that are not part of this BA
  4198. * session. The hw will assign sequence numbers to these
  4199. * packets as they go out. So if we query the hw for its next
  4200. * sequence number and use that for the SSN here, it may end up
  4201. * being wrong, which will lead to sequence number mismatch at
  4202. * the recipient. To avoid this, we reset the sequence number
  4203. * to O for the first MPDU in this BA stream.
  4204. */
  4205. *ssn = 0;
  4206. if (stream == NULL) {
  4207. /* This means that somebody outside this driver called
  4208. * ieee80211_start_tx_ba_session. This is unexpected
  4209. * because we do our own rate control. Just warn and
  4210. * move on.
  4211. */
  4212. wiphy_warn(hw->wiphy, "Unexpected call to %s. "
  4213. "Proceeding anyway.\n", __func__);
  4214. stream = mwl8k_add_stream(hw, sta, tid);
  4215. }
  4216. if (stream == NULL) {
  4217. wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
  4218. rc = -EBUSY;
  4219. break;
  4220. }
  4221. stream->state = AMPDU_STREAM_IN_PROGRESS;
  4222. /* Release the lock before we do the time consuming stuff */
  4223. spin_unlock(&priv->stream_lock);
  4224. for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
  4225. rc = mwl8k_check_ba(hw, stream);
  4226. /* If HW restart is in progress mwl8k_post_cmd will
  4227. * return -EBUSY. Avoid retrying mwl8k_check_ba in
  4228. * such cases
  4229. */
  4230. if (!rc || rc == -EBUSY)
  4231. break;
  4232. /*
  4233. * HW queues take time to be flushed, give them
  4234. * sufficient time
  4235. */
  4236. msleep(1000);
  4237. }
  4238. spin_lock(&priv->stream_lock);
  4239. if (rc) {
  4240. wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
  4241. " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
  4242. mwl8k_remove_stream(hw, stream);
  4243. rc = -EBUSY;
  4244. break;
  4245. }
  4246. ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
  4247. break;
  4248. case IEEE80211_AMPDU_TX_STOP:
  4249. if (stream) {
  4250. if (stream->state == AMPDU_STREAM_ACTIVE) {
  4251. spin_unlock(&priv->stream_lock);
  4252. mwl8k_destroy_ba(hw, stream);
  4253. spin_lock(&priv->stream_lock);
  4254. }
  4255. mwl8k_remove_stream(hw, stream);
  4256. }
  4257. ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
  4258. break;
  4259. case IEEE80211_AMPDU_TX_OPERATIONAL:
  4260. BUG_ON(stream == NULL);
  4261. BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
  4262. spin_unlock(&priv->stream_lock);
  4263. rc = mwl8k_create_ba(hw, stream, buf_size);
  4264. spin_lock(&priv->stream_lock);
  4265. if (!rc)
  4266. stream->state = AMPDU_STREAM_ACTIVE;
  4267. else {
  4268. spin_unlock(&priv->stream_lock);
  4269. mwl8k_destroy_ba(hw, stream);
  4270. spin_lock(&priv->stream_lock);
  4271. wiphy_debug(hw->wiphy,
  4272. "Failed adding stream for sta %pM tid %d\n",
  4273. addr, tid);
  4274. mwl8k_remove_stream(hw, stream);
  4275. }
  4276. break;
  4277. default:
  4278. rc = -ENOTSUPP;
  4279. }
  4280. spin_unlock(&priv->stream_lock);
  4281. return rc;
  4282. }
  4283. static const struct ieee80211_ops mwl8k_ops = {
  4284. .tx = mwl8k_tx,
  4285. .start = mwl8k_start,
  4286. .stop = mwl8k_stop,
  4287. .add_interface = mwl8k_add_interface,
  4288. .remove_interface = mwl8k_remove_interface,
  4289. .config = mwl8k_config,
  4290. .bss_info_changed = mwl8k_bss_info_changed,
  4291. .prepare_multicast = mwl8k_prepare_multicast,
  4292. .configure_filter = mwl8k_configure_filter,
  4293. .set_key = mwl8k_set_key,
  4294. .set_rts_threshold = mwl8k_set_rts_threshold,
  4295. .sta_add = mwl8k_sta_add,
  4296. .sta_remove = mwl8k_sta_remove,
  4297. .conf_tx = mwl8k_conf_tx,
  4298. .get_stats = mwl8k_get_stats,
  4299. .get_survey = mwl8k_get_survey,
  4300. .ampdu_action = mwl8k_ampdu_action,
  4301. };
  4302. static void mwl8k_finalize_join_worker(struct work_struct *work)
  4303. {
  4304. struct mwl8k_priv *priv =
  4305. container_of(work, struct mwl8k_priv, finalize_join_worker);
  4306. struct sk_buff *skb = priv->beacon_skb;
  4307. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  4308. int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
  4309. const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
  4310. mgmt->u.beacon.variable, len);
  4311. int dtim_period = 1;
  4312. if (tim && tim[1] >= 2)
  4313. dtim_period = tim[3];
  4314. mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
  4315. dev_kfree_skb(skb);
  4316. priv->beacon_skb = NULL;
  4317. }
  4318. enum {
  4319. MWL8363 = 0,
  4320. MWL8687,
  4321. MWL8366,
  4322. };
  4323. #define MWL8K_8366_AP_FW_API 2
  4324. #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
  4325. #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
  4326. static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
  4327. [MWL8363] = {
  4328. .part_name = "88w8363",
  4329. .helper_image = "mwl8k/helper_8363.fw",
  4330. .fw_image_sta = "mwl8k/fmimage_8363.fw",
  4331. },
  4332. [MWL8687] = {
  4333. .part_name = "88w8687",
  4334. .helper_image = "mwl8k/helper_8687.fw",
  4335. .fw_image_sta = "mwl8k/fmimage_8687.fw",
  4336. },
  4337. [MWL8366] = {
  4338. .part_name = "88w8366",
  4339. .helper_image = "mwl8k/helper_8366.fw",
  4340. .fw_image_sta = "mwl8k/fmimage_8366.fw",
  4341. .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
  4342. .fw_api_ap = MWL8K_8366_AP_FW_API,
  4343. .ap_rxd_ops = &rxd_8366_ap_ops,
  4344. },
  4345. };
  4346. MODULE_FIRMWARE("mwl8k/helper_8363.fw");
  4347. MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
  4348. MODULE_FIRMWARE("mwl8k/helper_8687.fw");
  4349. MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
  4350. MODULE_FIRMWARE("mwl8k/helper_8366.fw");
  4351. MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
  4352. MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
  4353. static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
  4354. { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
  4355. { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
  4356. { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
  4357. { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
  4358. { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
  4359. { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
  4360. { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
  4361. { },
  4362. };
  4363. MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
  4364. static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
  4365. {
  4366. int rc;
  4367. printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
  4368. "Trying alternative firmware %s\n", pci_name(priv->pdev),
  4369. priv->fw_pref, priv->fw_alt);
  4370. rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
  4371. if (rc) {
  4372. printk(KERN_ERR "%s: Error requesting alt fw %s\n",
  4373. pci_name(priv->pdev), priv->fw_alt);
  4374. return rc;
  4375. }
  4376. return 0;
  4377. }
  4378. static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
  4379. static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
  4380. {
  4381. struct mwl8k_priv *priv = context;
  4382. struct mwl8k_device_info *di = priv->device_info;
  4383. int rc;
  4384. switch (priv->fw_state) {
  4385. case FW_STATE_INIT:
  4386. if (!fw) {
  4387. printk(KERN_ERR "%s: Error requesting helper fw %s\n",
  4388. pci_name(priv->pdev), di->helper_image);
  4389. goto fail;
  4390. }
  4391. priv->fw_helper = fw;
  4392. rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
  4393. true);
  4394. if (rc && priv->fw_alt) {
  4395. rc = mwl8k_request_alt_fw(priv);
  4396. if (rc)
  4397. goto fail;
  4398. priv->fw_state = FW_STATE_LOADING_ALT;
  4399. } else if (rc)
  4400. goto fail;
  4401. else
  4402. priv->fw_state = FW_STATE_LOADING_PREF;
  4403. break;
  4404. case FW_STATE_LOADING_PREF:
  4405. if (!fw) {
  4406. if (priv->fw_alt) {
  4407. rc = mwl8k_request_alt_fw(priv);
  4408. if (rc)
  4409. goto fail;
  4410. priv->fw_state = FW_STATE_LOADING_ALT;
  4411. } else
  4412. goto fail;
  4413. } else {
  4414. priv->fw_ucode = fw;
  4415. rc = mwl8k_firmware_load_success(priv);
  4416. if (rc)
  4417. goto fail;
  4418. else
  4419. complete(&priv->firmware_loading_complete);
  4420. }
  4421. break;
  4422. case FW_STATE_LOADING_ALT:
  4423. if (!fw) {
  4424. printk(KERN_ERR "%s: Error requesting alt fw %s\n",
  4425. pci_name(priv->pdev), di->helper_image);
  4426. goto fail;
  4427. }
  4428. priv->fw_ucode = fw;
  4429. rc = mwl8k_firmware_load_success(priv);
  4430. if (rc)
  4431. goto fail;
  4432. else
  4433. complete(&priv->firmware_loading_complete);
  4434. break;
  4435. default:
  4436. printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
  4437. MWL8K_NAME, priv->fw_state);
  4438. BUG_ON(1);
  4439. }
  4440. return;
  4441. fail:
  4442. priv->fw_state = FW_STATE_ERROR;
  4443. complete(&priv->firmware_loading_complete);
  4444. device_release_driver(&priv->pdev->dev);
  4445. mwl8k_release_firmware(priv);
  4446. }
  4447. #define MAX_RESTART_ATTEMPTS 1
  4448. static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
  4449. bool nowait)
  4450. {
  4451. struct mwl8k_priv *priv = hw->priv;
  4452. int rc;
  4453. int count = MAX_RESTART_ATTEMPTS;
  4454. retry:
  4455. /* Reset firmware and hardware */
  4456. mwl8k_hw_reset(priv);
  4457. /* Ask userland hotplug daemon for the device firmware */
  4458. rc = mwl8k_request_firmware(priv, fw_image, nowait);
  4459. if (rc) {
  4460. wiphy_err(hw->wiphy, "Firmware files not found\n");
  4461. return rc;
  4462. }
  4463. if (nowait)
  4464. return rc;
  4465. /* Load firmware into hardware */
  4466. rc = mwl8k_load_firmware(hw);
  4467. if (rc)
  4468. wiphy_err(hw->wiphy, "Cannot start firmware\n");
  4469. /* Reclaim memory once firmware is successfully loaded */
  4470. mwl8k_release_firmware(priv);
  4471. if (rc && count) {
  4472. /* FW did not start successfully;
  4473. * lets try one more time
  4474. */
  4475. count--;
  4476. wiphy_err(hw->wiphy, "Trying to reload the firmware again\n");
  4477. msleep(20);
  4478. goto retry;
  4479. }
  4480. return rc;
  4481. }
  4482. static int mwl8k_init_txqs(struct ieee80211_hw *hw)
  4483. {
  4484. struct mwl8k_priv *priv = hw->priv;
  4485. int rc = 0;
  4486. int i;
  4487. for (i = 0; i < mwl8k_tx_queues(priv); i++) {
  4488. rc = mwl8k_txq_init(hw, i);
  4489. if (rc)
  4490. break;
  4491. if (priv->ap_fw)
  4492. iowrite32(priv->txq[i].txd_dma,
  4493. priv->sram + priv->txq_offset[i]);
  4494. }
  4495. return rc;
  4496. }
  4497. /* initialize hw after successfully loading a firmware image */
  4498. static int mwl8k_probe_hw(struct ieee80211_hw *hw)
  4499. {
  4500. struct mwl8k_priv *priv = hw->priv;
  4501. int rc = 0;
  4502. int i;
  4503. if (priv->ap_fw) {
  4504. priv->rxd_ops = priv->device_info->ap_rxd_ops;
  4505. if (priv->rxd_ops == NULL) {
  4506. wiphy_err(hw->wiphy,
  4507. "Driver does not have AP firmware image support for this hardware\n");
  4508. goto err_stop_firmware;
  4509. }
  4510. } else {
  4511. priv->rxd_ops = &rxd_sta_ops;
  4512. }
  4513. priv->sniffer_enabled = false;
  4514. priv->wmm_enabled = false;
  4515. priv->pending_tx_pkts = 0;
  4516. rc = mwl8k_rxq_init(hw, 0);
  4517. if (rc)
  4518. goto err_stop_firmware;
  4519. rxq_refill(hw, 0, INT_MAX);
  4520. /* For the sta firmware, we need to know the dma addresses of tx queues
  4521. * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
  4522. * prior to issuing this command. But for the AP case, we learn the
  4523. * total number of queues from the result CMD_GET_HW_SPEC, so for this
  4524. * case we must initialize the tx queues after.
  4525. */
  4526. priv->num_ampdu_queues = 0;
  4527. if (!priv->ap_fw) {
  4528. rc = mwl8k_init_txqs(hw);
  4529. if (rc)
  4530. goto err_free_queues;
  4531. }
  4532. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  4533. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4534. iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY|
  4535. MWL8K_A2H_INT_BA_WATCHDOG,
  4536. priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
  4537. iowrite32(MWL8K_A2H_INT_OPC_DONE,
  4538. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  4539. rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
  4540. IRQF_SHARED, MWL8K_NAME, hw);
  4541. if (rc) {
  4542. wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
  4543. goto err_free_queues;
  4544. }
  4545. /*
  4546. * When hw restart is requested,
  4547. * mac80211 will take care of clearing
  4548. * the ampdu streams, so do not clear
  4549. * the ampdu state here
  4550. */
  4551. if (!priv->hw_restart_in_progress)
  4552. memset(priv->ampdu, 0, sizeof(priv->ampdu));
  4553. /*
  4554. * Temporarily enable interrupts. Initial firmware host
  4555. * commands use interrupts and avoid polling. Disable
  4556. * interrupts when done.
  4557. */
  4558. iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4559. /* Get config data, mac addrs etc */
  4560. if (priv->ap_fw) {
  4561. rc = mwl8k_cmd_get_hw_spec_ap(hw);
  4562. if (!rc)
  4563. rc = mwl8k_init_txqs(hw);
  4564. if (!rc)
  4565. rc = mwl8k_cmd_set_hw_spec(hw);
  4566. } else {
  4567. rc = mwl8k_cmd_get_hw_spec_sta(hw);
  4568. }
  4569. if (rc) {
  4570. wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
  4571. goto err_free_irq;
  4572. }
  4573. /* Turn radio off */
  4574. rc = mwl8k_cmd_radio_disable(hw);
  4575. if (rc) {
  4576. wiphy_err(hw->wiphy, "Cannot disable\n");
  4577. goto err_free_irq;
  4578. }
  4579. /* Clear MAC address */
  4580. rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
  4581. if (rc) {
  4582. wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
  4583. goto err_free_irq;
  4584. }
  4585. /* Disable interrupts */
  4586. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4587. free_irq(priv->pdev->irq, hw);
  4588. wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
  4589. priv->device_info->part_name,
  4590. priv->hw_rev, hw->wiphy->perm_addr,
  4591. priv->ap_fw ? "AP" : "STA",
  4592. (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
  4593. (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
  4594. return 0;
  4595. err_free_irq:
  4596. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4597. free_irq(priv->pdev->irq, hw);
  4598. err_free_queues:
  4599. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4600. mwl8k_txq_deinit(hw, i);
  4601. mwl8k_rxq_deinit(hw, 0);
  4602. err_stop_firmware:
  4603. mwl8k_hw_reset(priv);
  4604. return rc;
  4605. }
  4606. /*
  4607. * invoke mwl8k_reload_firmware to change the firmware image after the device
  4608. * has already been registered
  4609. */
  4610. static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
  4611. {
  4612. int i, rc = 0;
  4613. struct mwl8k_priv *priv = hw->priv;
  4614. struct mwl8k_vif *vif, *tmp_vif;
  4615. mwl8k_stop(hw);
  4616. mwl8k_rxq_deinit(hw, 0);
  4617. /*
  4618. * All the existing interfaces are re-added by the ieee80211_reconfig;
  4619. * which means driver should remove existing interfaces before calling
  4620. * ieee80211_restart_hw
  4621. */
  4622. if (priv->hw_restart_in_progress)
  4623. list_for_each_entry_safe(vif, tmp_vif, &priv->vif_list, list)
  4624. mwl8k_remove_vif(priv, vif);
  4625. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4626. mwl8k_txq_deinit(hw, i);
  4627. rc = mwl8k_init_firmware(hw, fw_image, false);
  4628. if (rc)
  4629. goto fail;
  4630. rc = mwl8k_probe_hw(hw);
  4631. if (rc)
  4632. goto fail;
  4633. if (priv->hw_restart_in_progress)
  4634. return rc;
  4635. rc = mwl8k_start(hw);
  4636. if (rc)
  4637. goto fail;
  4638. rc = mwl8k_config(hw, ~0);
  4639. if (rc)
  4640. goto fail;
  4641. for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
  4642. rc = mwl8k_conf_tx(hw, NULL, i, &priv->wmm_params[i]);
  4643. if (rc)
  4644. goto fail;
  4645. }
  4646. return rc;
  4647. fail:
  4648. printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
  4649. return rc;
  4650. }
  4651. static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
  4652. {
  4653. struct ieee80211_hw *hw = priv->hw;
  4654. int i, rc;
  4655. rc = mwl8k_load_firmware(hw);
  4656. mwl8k_release_firmware(priv);
  4657. if (rc) {
  4658. wiphy_err(hw->wiphy, "Cannot start firmware\n");
  4659. return rc;
  4660. }
  4661. /*
  4662. * Extra headroom is the size of the required DMA header
  4663. * minus the size of the smallest 802.11 frame (CTS frame).
  4664. */
  4665. hw->extra_tx_headroom =
  4666. sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
  4667. hw->extra_tx_headroom -= priv->ap_fw ? REDUCED_TX_HEADROOM : 0;
  4668. hw->channel_change_time = 10;
  4669. hw->queues = MWL8K_TX_WMM_QUEUES;
  4670. /* Set rssi values to dBm */
  4671. hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
  4672. /*
  4673. * Ask mac80211 to not to trigger PS mode
  4674. * based on PM bit of incoming frames.
  4675. */
  4676. if (priv->ap_fw)
  4677. hw->flags |= IEEE80211_HW_AP_LINK_PS;
  4678. hw->vif_data_size = sizeof(struct mwl8k_vif);
  4679. hw->sta_data_size = sizeof(struct mwl8k_sta);
  4680. priv->macids_used = 0;
  4681. INIT_LIST_HEAD(&priv->vif_list);
  4682. /* Set default radio state and preamble */
  4683. priv->radio_on = false;
  4684. priv->radio_short_preamble = false;
  4685. /* Finalize join worker */
  4686. INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
  4687. /* Handle watchdog ba events */
  4688. INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
  4689. /* To reload the firmware if it crashes */
  4690. INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work);
  4691. /* TX reclaim and RX tasklets. */
  4692. tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
  4693. tasklet_disable(&priv->poll_tx_task);
  4694. tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
  4695. tasklet_disable(&priv->poll_rx_task);
  4696. /* Power management cookie */
  4697. priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
  4698. if (priv->cookie == NULL)
  4699. return -ENOMEM;
  4700. mutex_init(&priv->fw_mutex);
  4701. priv->fw_mutex_owner = NULL;
  4702. priv->fw_mutex_depth = 0;
  4703. priv->hostcmd_wait = NULL;
  4704. spin_lock_init(&priv->tx_lock);
  4705. spin_lock_init(&priv->stream_lock);
  4706. priv->tx_wait = NULL;
  4707. rc = mwl8k_probe_hw(hw);
  4708. if (rc)
  4709. goto err_free_cookie;
  4710. hw->wiphy->interface_modes = 0;
  4711. if (priv->ap_macids_supported || priv->device_info->fw_image_ap)
  4712. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
  4713. if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
  4714. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
  4715. rc = ieee80211_register_hw(hw);
  4716. if (rc) {
  4717. wiphy_err(hw->wiphy, "Cannot register device\n");
  4718. goto err_unprobe_hw;
  4719. }
  4720. return 0;
  4721. err_unprobe_hw:
  4722. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4723. mwl8k_txq_deinit(hw, i);
  4724. mwl8k_rxq_deinit(hw, 0);
  4725. err_free_cookie:
  4726. if (priv->cookie != NULL)
  4727. pci_free_consistent(priv->pdev, 4,
  4728. priv->cookie, priv->cookie_dma);
  4729. return rc;
  4730. }
  4731. static int __devinit mwl8k_probe(struct pci_dev *pdev,
  4732. const struct pci_device_id *id)
  4733. {
  4734. static int printed_version;
  4735. struct ieee80211_hw *hw;
  4736. struct mwl8k_priv *priv;
  4737. struct mwl8k_device_info *di;
  4738. int rc;
  4739. if (!printed_version) {
  4740. printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
  4741. printed_version = 1;
  4742. }
  4743. rc = pci_enable_device(pdev);
  4744. if (rc) {
  4745. printk(KERN_ERR "%s: Cannot enable new PCI device\n",
  4746. MWL8K_NAME);
  4747. return rc;
  4748. }
  4749. rc = pci_request_regions(pdev, MWL8K_NAME);
  4750. if (rc) {
  4751. printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
  4752. MWL8K_NAME);
  4753. goto err_disable_device;
  4754. }
  4755. pci_set_master(pdev);
  4756. hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
  4757. if (hw == NULL) {
  4758. printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
  4759. rc = -ENOMEM;
  4760. goto err_free_reg;
  4761. }
  4762. SET_IEEE80211_DEV(hw, &pdev->dev);
  4763. pci_set_drvdata(pdev, hw);
  4764. priv = hw->priv;
  4765. priv->hw = hw;
  4766. priv->pdev = pdev;
  4767. priv->device_info = &mwl8k_info_tbl[id->driver_data];
  4768. priv->sram = pci_iomap(pdev, 0, 0x10000);
  4769. if (priv->sram == NULL) {
  4770. wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
  4771. goto err_iounmap;
  4772. }
  4773. /*
  4774. * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
  4775. * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
  4776. */
  4777. priv->regs = pci_iomap(pdev, 1, 0x10000);
  4778. if (priv->regs == NULL) {
  4779. priv->regs = pci_iomap(pdev, 2, 0x10000);
  4780. if (priv->regs == NULL) {
  4781. wiphy_err(hw->wiphy, "Cannot map device registers\n");
  4782. goto err_iounmap;
  4783. }
  4784. }
  4785. /*
  4786. * Choose the initial fw image depending on user input. If a second
  4787. * image is available, make it the alternative image that will be
  4788. * loaded if the first one fails.
  4789. */
  4790. init_completion(&priv->firmware_loading_complete);
  4791. di = priv->device_info;
  4792. if (ap_mode_default && di->fw_image_ap) {
  4793. priv->fw_pref = di->fw_image_ap;
  4794. priv->fw_alt = di->fw_image_sta;
  4795. } else if (!ap_mode_default && di->fw_image_sta) {
  4796. priv->fw_pref = di->fw_image_sta;
  4797. priv->fw_alt = di->fw_image_ap;
  4798. } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
  4799. printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
  4800. priv->fw_pref = di->fw_image_sta;
  4801. } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
  4802. printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
  4803. priv->fw_pref = di->fw_image_ap;
  4804. }
  4805. rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
  4806. if (rc)
  4807. goto err_stop_firmware;
  4808. priv->hw_restart_in_progress = false;
  4809. return rc;
  4810. err_stop_firmware:
  4811. mwl8k_hw_reset(priv);
  4812. err_iounmap:
  4813. if (priv->regs != NULL)
  4814. pci_iounmap(pdev, priv->regs);
  4815. if (priv->sram != NULL)
  4816. pci_iounmap(pdev, priv->sram);
  4817. pci_set_drvdata(pdev, NULL);
  4818. ieee80211_free_hw(hw);
  4819. err_free_reg:
  4820. pci_release_regions(pdev);
  4821. err_disable_device:
  4822. pci_disable_device(pdev);
  4823. return rc;
  4824. }
  4825. static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
  4826. {
  4827. printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
  4828. }
  4829. static void __devexit mwl8k_remove(struct pci_dev *pdev)
  4830. {
  4831. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  4832. struct mwl8k_priv *priv;
  4833. int i;
  4834. if (hw == NULL)
  4835. return;
  4836. priv = hw->priv;
  4837. wait_for_completion(&priv->firmware_loading_complete);
  4838. if (priv->fw_state == FW_STATE_ERROR) {
  4839. mwl8k_hw_reset(priv);
  4840. goto unmap;
  4841. }
  4842. ieee80211_stop_queues(hw);
  4843. ieee80211_unregister_hw(hw);
  4844. /* Remove TX reclaim and RX tasklets. */
  4845. tasklet_kill(&priv->poll_tx_task);
  4846. tasklet_kill(&priv->poll_rx_task);
  4847. /* Stop hardware */
  4848. mwl8k_hw_reset(priv);
  4849. /* Return all skbs to mac80211 */
  4850. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4851. mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  4852. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4853. mwl8k_txq_deinit(hw, i);
  4854. mwl8k_rxq_deinit(hw, 0);
  4855. pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
  4856. unmap:
  4857. pci_iounmap(pdev, priv->regs);
  4858. pci_iounmap(pdev, priv->sram);
  4859. pci_set_drvdata(pdev, NULL);
  4860. ieee80211_free_hw(hw);
  4861. pci_release_regions(pdev);
  4862. pci_disable_device(pdev);
  4863. }
  4864. static struct pci_driver mwl8k_driver = {
  4865. .name = MWL8K_NAME,
  4866. .id_table = mwl8k_pci_id_table,
  4867. .probe = mwl8k_probe,
  4868. .remove = __devexit_p(mwl8k_remove),
  4869. .shutdown = __devexit_p(mwl8k_shutdown),
  4870. };
  4871. module_pci_driver(mwl8k_driver);
  4872. MODULE_DESCRIPTION(MWL8K_DESC);
  4873. MODULE_VERSION(MWL8K_VERSION);
  4874. MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
  4875. MODULE_LICENSE("GPL");