mwl8k.c 119 KB

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