mwl8k.c 136 KB

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