mwl8k.c 142 KB

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