mwl8k.c 141 KB

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