mwl8k.c 153 KB

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