mwl8k.c 142 KB

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