mwl8k.c 132 KB

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