mwl8k.c 119 KB

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