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_alloc_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. memset(rxq->rxd, 0, size);
  985. rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
  986. if (rxq->buf == NULL) {
  987. pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
  988. return -ENOMEM;
  989. }
  990. for (i = 0; i < MWL8K_RX_DESCS; i++) {
  991. int desc_size;
  992. void *rxd;
  993. int nexti;
  994. dma_addr_t next_dma_addr;
  995. desc_size = priv->rxd_ops->rxd_size;
  996. rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
  997. nexti = i + 1;
  998. if (nexti == MWL8K_RX_DESCS)
  999. nexti = 0;
  1000. next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
  1001. priv->rxd_ops->rxd_init(rxd, next_dma_addr);
  1002. }
  1003. return 0;
  1004. }
  1005. static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
  1006. {
  1007. struct mwl8k_priv *priv = hw->priv;
  1008. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  1009. int refilled;
  1010. refilled = 0;
  1011. while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
  1012. struct sk_buff *skb;
  1013. dma_addr_t addr;
  1014. int rx;
  1015. void *rxd;
  1016. skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
  1017. if (skb == NULL)
  1018. break;
  1019. addr = pci_map_single(priv->pdev, skb->data,
  1020. MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
  1021. rxq->rxd_count++;
  1022. rx = rxq->tail++;
  1023. if (rxq->tail == MWL8K_RX_DESCS)
  1024. rxq->tail = 0;
  1025. rxq->buf[rx].skb = skb;
  1026. dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
  1027. rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
  1028. priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
  1029. refilled++;
  1030. }
  1031. return refilled;
  1032. }
  1033. /* Must be called only when the card's reception is completely halted */
  1034. static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
  1035. {
  1036. struct mwl8k_priv *priv = hw->priv;
  1037. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  1038. int i;
  1039. if (rxq->rxd == NULL)
  1040. return;
  1041. for (i = 0; i < MWL8K_RX_DESCS; i++) {
  1042. if (rxq->buf[i].skb != NULL) {
  1043. pci_unmap_single(priv->pdev,
  1044. dma_unmap_addr(&rxq->buf[i], dma),
  1045. MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
  1046. dma_unmap_addr_set(&rxq->buf[i], dma, 0);
  1047. kfree_skb(rxq->buf[i].skb);
  1048. rxq->buf[i].skb = NULL;
  1049. }
  1050. }
  1051. kfree(rxq->buf);
  1052. rxq->buf = NULL;
  1053. pci_free_consistent(priv->pdev,
  1054. MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
  1055. rxq->rxd, rxq->rxd_dma);
  1056. rxq->rxd = NULL;
  1057. }
  1058. /*
  1059. * Scan a list of BSSIDs to process for finalize join.
  1060. * Allows for extension to process multiple BSSIDs.
  1061. */
  1062. static inline int
  1063. mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
  1064. {
  1065. return priv->capture_beacon &&
  1066. ieee80211_is_beacon(wh->frame_control) &&
  1067. ether_addr_equal_64bits(wh->addr3, priv->capture_bssid);
  1068. }
  1069. static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
  1070. struct sk_buff *skb)
  1071. {
  1072. struct mwl8k_priv *priv = hw->priv;
  1073. priv->capture_beacon = false;
  1074. memset(priv->capture_bssid, 0, ETH_ALEN);
  1075. /*
  1076. * Use GFP_ATOMIC as rxq_process is called from
  1077. * the primary interrupt handler, memory allocation call
  1078. * must not sleep.
  1079. */
  1080. priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
  1081. if (priv->beacon_skb != NULL)
  1082. ieee80211_queue_work(hw, &priv->finalize_join_worker);
  1083. }
  1084. static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
  1085. u8 *bssid)
  1086. {
  1087. struct mwl8k_vif *mwl8k_vif;
  1088. list_for_each_entry(mwl8k_vif,
  1089. vif_list, list) {
  1090. if (memcmp(bssid, mwl8k_vif->bssid,
  1091. ETH_ALEN) == 0)
  1092. return mwl8k_vif;
  1093. }
  1094. return NULL;
  1095. }
  1096. static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
  1097. {
  1098. struct mwl8k_priv *priv = hw->priv;
  1099. struct mwl8k_vif *mwl8k_vif = NULL;
  1100. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  1101. int processed;
  1102. processed = 0;
  1103. while (rxq->rxd_count && limit--) {
  1104. struct sk_buff *skb;
  1105. void *rxd;
  1106. int pkt_len;
  1107. struct ieee80211_rx_status status;
  1108. struct ieee80211_hdr *wh;
  1109. __le16 qos;
  1110. skb = rxq->buf[rxq->head].skb;
  1111. if (skb == NULL)
  1112. break;
  1113. rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
  1114. pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
  1115. &priv->noise);
  1116. if (pkt_len < 0)
  1117. break;
  1118. rxq->buf[rxq->head].skb = NULL;
  1119. pci_unmap_single(priv->pdev,
  1120. dma_unmap_addr(&rxq->buf[rxq->head], dma),
  1121. MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
  1122. dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
  1123. rxq->head++;
  1124. if (rxq->head == MWL8K_RX_DESCS)
  1125. rxq->head = 0;
  1126. rxq->rxd_count--;
  1127. wh = &((struct mwl8k_dma_data *)skb->data)->wh;
  1128. /*
  1129. * Check for a pending join operation. Save a
  1130. * copy of the beacon and schedule a tasklet to
  1131. * send a FINALIZE_JOIN command to the firmware.
  1132. */
  1133. if (mwl8k_capture_bssid(priv, (void *)skb->data))
  1134. mwl8k_save_beacon(hw, skb);
  1135. if (ieee80211_has_protected(wh->frame_control)) {
  1136. /* Check if hw crypto has been enabled for
  1137. * this bss. If yes, set the status flags
  1138. * accordingly
  1139. */
  1140. mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
  1141. wh->addr1);
  1142. if (mwl8k_vif != NULL &&
  1143. mwl8k_vif->is_hw_crypto_enabled) {
  1144. /*
  1145. * When MMIC ERROR is encountered
  1146. * by the firmware, payload is
  1147. * dropped and only 32 bytes of
  1148. * mwl8k Firmware header is sent
  1149. * to the host.
  1150. *
  1151. * We need to add four bytes of
  1152. * key information. In it
  1153. * MAC80211 expects keyidx set to
  1154. * 0 for triggering Counter
  1155. * Measure of MMIC failure.
  1156. */
  1157. if (status.flag & RX_FLAG_MMIC_ERROR) {
  1158. struct mwl8k_dma_data *tr;
  1159. tr = (struct mwl8k_dma_data *)skb->data;
  1160. memset((void *)&(tr->data), 0, 4);
  1161. pkt_len += 4;
  1162. }
  1163. if (!ieee80211_is_auth(wh->frame_control))
  1164. status.flag |= RX_FLAG_IV_STRIPPED |
  1165. RX_FLAG_DECRYPTED |
  1166. RX_FLAG_MMIC_STRIPPED;
  1167. }
  1168. }
  1169. skb_put(skb, pkt_len);
  1170. mwl8k_remove_dma_header(skb, qos);
  1171. memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
  1172. ieee80211_rx_irqsafe(hw, skb);
  1173. processed++;
  1174. }
  1175. return processed;
  1176. }
  1177. /*
  1178. * Packet transmission.
  1179. */
  1180. #define MWL8K_TXD_STATUS_OK 0x00000001
  1181. #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
  1182. #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
  1183. #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
  1184. #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
  1185. #define MWL8K_QOS_QLEN_UNSPEC 0xff00
  1186. #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
  1187. #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
  1188. #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
  1189. #define MWL8K_QOS_EOSP 0x0010
  1190. struct mwl8k_tx_desc {
  1191. __le32 status;
  1192. __u8 data_rate;
  1193. __u8 tx_priority;
  1194. __le16 qos_control;
  1195. __le32 pkt_phys_addr;
  1196. __le16 pkt_len;
  1197. __u8 dest_MAC_addr[ETH_ALEN];
  1198. __le32 next_txd_phys_addr;
  1199. __le32 timestamp;
  1200. __le16 rate_info;
  1201. __u8 peer_id;
  1202. __u8 tx_frag_cnt;
  1203. } __packed;
  1204. #define MWL8K_TX_DESCS 128
  1205. static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
  1206. {
  1207. struct mwl8k_priv *priv = hw->priv;
  1208. struct mwl8k_tx_queue *txq = priv->txq + index;
  1209. int size;
  1210. int i;
  1211. txq->len = 0;
  1212. txq->head = 0;
  1213. txq->tail = 0;
  1214. size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
  1215. txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
  1216. if (txq->txd == NULL) {
  1217. wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
  1218. return -ENOMEM;
  1219. }
  1220. memset(txq->txd, 0, size);
  1221. txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
  1222. if (txq->skb == NULL) {
  1223. pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
  1224. return -ENOMEM;
  1225. }
  1226. for (i = 0; i < MWL8K_TX_DESCS; i++) {
  1227. struct mwl8k_tx_desc *tx_desc;
  1228. int nexti;
  1229. tx_desc = txq->txd + i;
  1230. nexti = (i + 1) % MWL8K_TX_DESCS;
  1231. tx_desc->status = 0;
  1232. tx_desc->next_txd_phys_addr =
  1233. cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
  1234. }
  1235. return 0;
  1236. }
  1237. static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
  1238. {
  1239. iowrite32(MWL8K_H2A_INT_PPA_READY,
  1240. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1241. iowrite32(MWL8K_H2A_INT_DUMMY,
  1242. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1243. ioread32(priv->regs + MWL8K_HIU_INT_CODE);
  1244. }
  1245. static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
  1246. {
  1247. struct mwl8k_priv *priv = hw->priv;
  1248. int i;
  1249. for (i = 0; i < mwl8k_tx_queues(priv); i++) {
  1250. struct mwl8k_tx_queue *txq = priv->txq + i;
  1251. int fw_owned = 0;
  1252. int drv_owned = 0;
  1253. int unused = 0;
  1254. int desc;
  1255. for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
  1256. struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
  1257. u32 status;
  1258. status = le32_to_cpu(tx_desc->status);
  1259. if (status & MWL8K_TXD_STATUS_FW_OWNED)
  1260. fw_owned++;
  1261. else
  1262. drv_owned++;
  1263. if (tx_desc->pkt_len == 0)
  1264. unused++;
  1265. }
  1266. wiphy_err(hw->wiphy,
  1267. "txq[%d] len=%d head=%d tail=%d "
  1268. "fw_owned=%d drv_owned=%d unused=%d\n",
  1269. i,
  1270. txq->len, txq->head, txq->tail,
  1271. fw_owned, drv_owned, unused);
  1272. }
  1273. }
  1274. /*
  1275. * Must be called with priv->fw_mutex held and tx queues stopped.
  1276. */
  1277. #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
  1278. static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
  1279. {
  1280. struct mwl8k_priv *priv = hw->priv;
  1281. DECLARE_COMPLETION_ONSTACK(tx_wait);
  1282. int retry;
  1283. int rc;
  1284. might_sleep();
  1285. /* Since fw restart is in progress, allow only the firmware
  1286. * commands from the restart code and block the other
  1287. * commands since they are going to fail in any case since
  1288. * the firmware has crashed
  1289. */
  1290. if (priv->hw_restart_in_progress) {
  1291. if (priv->hw_restart_owner == current)
  1292. return 0;
  1293. else
  1294. return -EBUSY;
  1295. }
  1296. if (atomic_read(&priv->watchdog_event_pending))
  1297. return 0;
  1298. /*
  1299. * The TX queues are stopped at this point, so this test
  1300. * doesn't need to take ->tx_lock.
  1301. */
  1302. if (!priv->pending_tx_pkts)
  1303. return 0;
  1304. retry = 1;
  1305. rc = 0;
  1306. spin_lock_bh(&priv->tx_lock);
  1307. priv->tx_wait = &tx_wait;
  1308. while (!rc) {
  1309. int oldcount;
  1310. unsigned long timeout;
  1311. oldcount = priv->pending_tx_pkts;
  1312. spin_unlock_bh(&priv->tx_lock);
  1313. timeout = wait_for_completion_timeout(&tx_wait,
  1314. msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
  1315. if (atomic_read(&priv->watchdog_event_pending)) {
  1316. spin_lock_bh(&priv->tx_lock);
  1317. priv->tx_wait = NULL;
  1318. spin_unlock_bh(&priv->tx_lock);
  1319. return 0;
  1320. }
  1321. spin_lock_bh(&priv->tx_lock);
  1322. if (timeout || !priv->pending_tx_pkts) {
  1323. WARN_ON(priv->pending_tx_pkts);
  1324. if (retry)
  1325. wiphy_notice(hw->wiphy, "tx rings drained\n");
  1326. break;
  1327. }
  1328. if (retry) {
  1329. mwl8k_tx_start(priv);
  1330. retry = 0;
  1331. continue;
  1332. }
  1333. if (priv->pending_tx_pkts < oldcount) {
  1334. wiphy_notice(hw->wiphy,
  1335. "waiting for tx rings to drain (%d -> %d pkts)\n",
  1336. oldcount, priv->pending_tx_pkts);
  1337. retry = 1;
  1338. continue;
  1339. }
  1340. priv->tx_wait = NULL;
  1341. wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
  1342. MWL8K_TX_WAIT_TIMEOUT_MS);
  1343. mwl8k_dump_tx_rings(hw);
  1344. priv->hw_restart_in_progress = true;
  1345. ieee80211_queue_work(hw, &priv->fw_reload);
  1346. rc = -ETIMEDOUT;
  1347. }
  1348. priv->tx_wait = NULL;
  1349. spin_unlock_bh(&priv->tx_lock);
  1350. return rc;
  1351. }
  1352. #define MWL8K_TXD_SUCCESS(status) \
  1353. ((status) & (MWL8K_TXD_STATUS_OK | \
  1354. MWL8K_TXD_STATUS_OK_RETRY | \
  1355. MWL8K_TXD_STATUS_OK_MORE_RETRY))
  1356. static int mwl8k_tid_queue_mapping(u8 tid)
  1357. {
  1358. BUG_ON(tid > 7);
  1359. switch (tid) {
  1360. case 0:
  1361. case 3:
  1362. return IEEE80211_AC_BE;
  1363. break;
  1364. case 1:
  1365. case 2:
  1366. return IEEE80211_AC_BK;
  1367. break;
  1368. case 4:
  1369. case 5:
  1370. return IEEE80211_AC_VI;
  1371. break;
  1372. case 6:
  1373. case 7:
  1374. return IEEE80211_AC_VO;
  1375. break;
  1376. default:
  1377. return -1;
  1378. break;
  1379. }
  1380. }
  1381. /* The firmware will fill in the rate information
  1382. * for each packet that gets queued in the hardware
  1383. * and these macros will interpret that info.
  1384. */
  1385. #define RI_FORMAT(a) (a & 0x0001)
  1386. #define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3)
  1387. static int
  1388. mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
  1389. {
  1390. struct mwl8k_priv *priv = hw->priv;
  1391. struct mwl8k_tx_queue *txq = priv->txq + index;
  1392. int processed;
  1393. processed = 0;
  1394. while (txq->len > 0 && limit--) {
  1395. int tx;
  1396. struct mwl8k_tx_desc *tx_desc;
  1397. unsigned long addr;
  1398. int size;
  1399. struct sk_buff *skb;
  1400. struct ieee80211_tx_info *info;
  1401. u32 status;
  1402. struct ieee80211_sta *sta;
  1403. struct mwl8k_sta *sta_info = NULL;
  1404. u16 rate_info;
  1405. struct ieee80211_hdr *wh;
  1406. tx = txq->head;
  1407. tx_desc = txq->txd + tx;
  1408. status = le32_to_cpu(tx_desc->status);
  1409. if (status & MWL8K_TXD_STATUS_FW_OWNED) {
  1410. if (!force)
  1411. break;
  1412. tx_desc->status &=
  1413. ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
  1414. }
  1415. txq->head = (tx + 1) % MWL8K_TX_DESCS;
  1416. BUG_ON(txq->len == 0);
  1417. txq->len--;
  1418. priv->pending_tx_pkts--;
  1419. addr = le32_to_cpu(tx_desc->pkt_phys_addr);
  1420. size = le16_to_cpu(tx_desc->pkt_len);
  1421. skb = txq->skb[tx];
  1422. txq->skb[tx] = NULL;
  1423. BUG_ON(skb == NULL);
  1424. pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
  1425. mwl8k_remove_dma_header(skb, tx_desc->qos_control);
  1426. wh = (struct ieee80211_hdr *) skb->data;
  1427. /* Mark descriptor as unused */
  1428. tx_desc->pkt_phys_addr = 0;
  1429. tx_desc->pkt_len = 0;
  1430. info = IEEE80211_SKB_CB(skb);
  1431. if (ieee80211_is_data(wh->frame_control)) {
  1432. rcu_read_lock();
  1433. sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1,
  1434. wh->addr2);
  1435. if (sta) {
  1436. sta_info = MWL8K_STA(sta);
  1437. BUG_ON(sta_info == NULL);
  1438. rate_info = le16_to_cpu(tx_desc->rate_info);
  1439. /* If rate is < 6.5 Mpbs for an ht station
  1440. * do not form an ampdu. If the station is a
  1441. * legacy station (format = 0), do not form an
  1442. * ampdu
  1443. */
  1444. if (RI_RATE_ID_MCS(rate_info) < 1 ||
  1445. RI_FORMAT(rate_info) == 0) {
  1446. sta_info->is_ampdu_allowed = false;
  1447. } else {
  1448. sta_info->is_ampdu_allowed = true;
  1449. }
  1450. }
  1451. rcu_read_unlock();
  1452. }
  1453. ieee80211_tx_info_clear_status(info);
  1454. /* Rate control is happening in the firmware.
  1455. * Ensure no tx rate is being reported.
  1456. */
  1457. info->status.rates[0].idx = -1;
  1458. info->status.rates[0].count = 1;
  1459. if (MWL8K_TXD_SUCCESS(status))
  1460. info->flags |= IEEE80211_TX_STAT_ACK;
  1461. ieee80211_tx_status_irqsafe(hw, skb);
  1462. processed++;
  1463. }
  1464. return processed;
  1465. }
  1466. /* must be called only when the card's transmit is completely halted */
  1467. static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
  1468. {
  1469. struct mwl8k_priv *priv = hw->priv;
  1470. struct mwl8k_tx_queue *txq = priv->txq + index;
  1471. if (txq->txd == NULL)
  1472. return;
  1473. mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
  1474. kfree(txq->skb);
  1475. txq->skb = NULL;
  1476. pci_free_consistent(priv->pdev,
  1477. MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
  1478. txq->txd, txq->txd_dma);
  1479. txq->txd = NULL;
  1480. }
  1481. /* caller must hold priv->stream_lock when calling the stream functions */
  1482. static struct mwl8k_ampdu_stream *
  1483. mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
  1484. {
  1485. struct mwl8k_ampdu_stream *stream;
  1486. struct mwl8k_priv *priv = hw->priv;
  1487. int i;
  1488. for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
  1489. stream = &priv->ampdu[i];
  1490. if (stream->state == AMPDU_NO_STREAM) {
  1491. stream->sta = sta;
  1492. stream->state = AMPDU_STREAM_NEW;
  1493. stream->tid = tid;
  1494. stream->idx = i;
  1495. wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
  1496. sta->addr, tid);
  1497. return stream;
  1498. }
  1499. }
  1500. return NULL;
  1501. }
  1502. static int
  1503. mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
  1504. {
  1505. int ret;
  1506. /* if the stream has already been started, don't start it again */
  1507. if (stream->state != AMPDU_STREAM_NEW)
  1508. return 0;
  1509. ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
  1510. if (ret)
  1511. wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
  1512. "%d\n", stream->sta->addr, stream->tid, ret);
  1513. else
  1514. wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
  1515. stream->sta->addr, stream->tid);
  1516. return ret;
  1517. }
  1518. static void
  1519. mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
  1520. {
  1521. wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
  1522. stream->tid);
  1523. memset(stream, 0, sizeof(*stream));
  1524. }
  1525. static struct mwl8k_ampdu_stream *
  1526. mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
  1527. {
  1528. struct mwl8k_priv *priv = hw->priv;
  1529. int i;
  1530. for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
  1531. struct mwl8k_ampdu_stream *stream;
  1532. stream = &priv->ampdu[i];
  1533. if (stream->state == AMPDU_NO_STREAM)
  1534. continue;
  1535. if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
  1536. stream->tid == tid)
  1537. return stream;
  1538. }
  1539. return NULL;
  1540. }
  1541. #define MWL8K_AMPDU_PACKET_THRESHOLD 64
  1542. static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid)
  1543. {
  1544. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  1545. struct tx_traffic_info *tx_stats;
  1546. BUG_ON(tid >= MWL8K_MAX_TID);
  1547. tx_stats = &sta_info->tx_stats[tid];
  1548. return sta_info->is_ampdu_allowed &&
  1549. tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD;
  1550. }
  1551. static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid)
  1552. {
  1553. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  1554. struct tx_traffic_info *tx_stats;
  1555. BUG_ON(tid >= MWL8K_MAX_TID);
  1556. tx_stats = &sta_info->tx_stats[tid];
  1557. if (tx_stats->start_time == 0)
  1558. tx_stats->start_time = jiffies;
  1559. /* reset the packet count after each second elapses. If the number of
  1560. * packets ever exceeds the ampdu_min_traffic threshold, we will allow
  1561. * an ampdu stream to be started.
  1562. */
  1563. if (jiffies - tx_stats->start_time > HZ) {
  1564. tx_stats->pkts = 0;
  1565. tx_stats->start_time = 0;
  1566. } else
  1567. tx_stats->pkts++;
  1568. }
  1569. /* The hardware ampdu queues start from 5.
  1570. * txpriorities for ampdu queues are
  1571. * 5 6 7 0 1 2 3 4 ie., queue 5 is highest
  1572. * and queue 3 is lowest (queue 4 is reserved)
  1573. */
  1574. #define BA_QUEUE 5
  1575. static void
  1576. mwl8k_txq_xmit(struct ieee80211_hw *hw,
  1577. int index,
  1578. struct ieee80211_sta *sta,
  1579. struct sk_buff *skb)
  1580. {
  1581. struct mwl8k_priv *priv = hw->priv;
  1582. struct ieee80211_tx_info *tx_info;
  1583. struct mwl8k_vif *mwl8k_vif;
  1584. struct ieee80211_hdr *wh;
  1585. struct mwl8k_tx_queue *txq;
  1586. struct mwl8k_tx_desc *tx;
  1587. dma_addr_t dma;
  1588. u32 txstatus;
  1589. u8 txdatarate;
  1590. u16 qos;
  1591. int txpriority;
  1592. u8 tid = 0;
  1593. struct mwl8k_ampdu_stream *stream = NULL;
  1594. bool start_ba_session = false;
  1595. bool mgmtframe = false;
  1596. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
  1597. bool eapol_frame = false;
  1598. wh = (struct ieee80211_hdr *)skb->data;
  1599. if (ieee80211_is_data_qos(wh->frame_control))
  1600. qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
  1601. else
  1602. qos = 0;
  1603. if (skb->protocol == cpu_to_be16(ETH_P_PAE))
  1604. eapol_frame = true;
  1605. if (ieee80211_is_mgmt(wh->frame_control))
  1606. mgmtframe = true;
  1607. if (priv->ap_fw)
  1608. mwl8k_encapsulate_tx_frame(priv, skb);
  1609. else
  1610. mwl8k_add_dma_header(priv, skb, 0, 0);
  1611. wh = &((struct mwl8k_dma_data *)skb->data)->wh;
  1612. tx_info = IEEE80211_SKB_CB(skb);
  1613. mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
  1614. if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1615. wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1616. wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
  1617. mwl8k_vif->seqno += 0x10;
  1618. }
  1619. /* Setup firmware control bit fields for each frame type. */
  1620. txstatus = 0;
  1621. txdatarate = 0;
  1622. if (ieee80211_is_mgmt(wh->frame_control) ||
  1623. ieee80211_is_ctl(wh->frame_control)) {
  1624. txdatarate = 0;
  1625. qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
  1626. } else if (ieee80211_is_data(wh->frame_control)) {
  1627. txdatarate = 1;
  1628. if (is_multicast_ether_addr(wh->addr1))
  1629. txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
  1630. qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
  1631. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
  1632. qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
  1633. else
  1634. qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
  1635. }
  1636. /* Queue ADDBA request in the respective data queue. While setting up
  1637. * the ampdu stream, mac80211 queues further packets for that
  1638. * particular ra/tid pair. However, packets piled up in the hardware
  1639. * for that ra/tid pair will still go out. ADDBA request and the
  1640. * related data packets going out from different queues asynchronously
  1641. * will cause a shift in the receiver window which might result in
  1642. * ampdu packets getting dropped at the receiver after the stream has
  1643. * been setup.
  1644. */
  1645. if (unlikely(ieee80211_is_action(wh->frame_control) &&
  1646. mgmt->u.action.category == WLAN_CATEGORY_BACK &&
  1647. mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
  1648. priv->ap_fw)) {
  1649. u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
  1650. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  1651. index = mwl8k_tid_queue_mapping(tid);
  1652. }
  1653. txpriority = index;
  1654. if (priv->ap_fw && sta && sta->ht_cap.ht_supported && !eapol_frame &&
  1655. ieee80211_is_data_qos(wh->frame_control)) {
  1656. tid = qos & 0xf;
  1657. mwl8k_tx_count_packet(sta, tid);
  1658. spin_lock(&priv->stream_lock);
  1659. stream = mwl8k_lookup_stream(hw, sta->addr, tid);
  1660. if (stream != NULL) {
  1661. if (stream->state == AMPDU_STREAM_ACTIVE) {
  1662. WARN_ON(!(qos & MWL8K_QOS_ACK_POLICY_BLOCKACK));
  1663. txpriority = (BA_QUEUE + stream->idx) %
  1664. TOTAL_HW_TX_QUEUES;
  1665. if (stream->idx <= 1)
  1666. index = stream->idx +
  1667. MWL8K_TX_WMM_QUEUES;
  1668. } else if (stream->state == AMPDU_STREAM_NEW) {
  1669. /* We get here if the driver sends us packets
  1670. * after we've initiated a stream, but before
  1671. * our ampdu_action routine has been called
  1672. * with IEEE80211_AMPDU_TX_START to get the SSN
  1673. * for the ADDBA request. So this packet can
  1674. * go out with no risk of sequence number
  1675. * mismatch. No special handling is required.
  1676. */
  1677. } else {
  1678. /* Drop packets that would go out after the
  1679. * ADDBA request was sent but before the ADDBA
  1680. * response is received. If we don't do this,
  1681. * the recipient would probably receive it
  1682. * after the ADDBA request with SSN 0. This
  1683. * will cause the recipient's BA receive window
  1684. * to shift, which would cause the subsequent
  1685. * packets in the BA stream to be discarded.
  1686. * mac80211 queues our packets for us in this
  1687. * case, so this is really just a safety check.
  1688. */
  1689. wiphy_warn(hw->wiphy,
  1690. "Cannot send packet while ADDBA "
  1691. "dialog is underway.\n");
  1692. spin_unlock(&priv->stream_lock);
  1693. dev_kfree_skb(skb);
  1694. return;
  1695. }
  1696. } else {
  1697. /* Defer calling mwl8k_start_stream so that the current
  1698. * skb can go out before the ADDBA request. This
  1699. * prevents sequence number mismatch at the recepient
  1700. * as described above.
  1701. */
  1702. if (mwl8k_ampdu_allowed(sta, tid)) {
  1703. stream = mwl8k_add_stream(hw, sta, tid);
  1704. if (stream != NULL)
  1705. start_ba_session = true;
  1706. }
  1707. }
  1708. spin_unlock(&priv->stream_lock);
  1709. } else {
  1710. qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
  1711. qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
  1712. }
  1713. dma = pci_map_single(priv->pdev, skb->data,
  1714. skb->len, PCI_DMA_TODEVICE);
  1715. if (pci_dma_mapping_error(priv->pdev, dma)) {
  1716. wiphy_debug(hw->wiphy,
  1717. "failed to dma map skb, dropping TX frame.\n");
  1718. if (start_ba_session) {
  1719. spin_lock(&priv->stream_lock);
  1720. mwl8k_remove_stream(hw, stream);
  1721. spin_unlock(&priv->stream_lock);
  1722. }
  1723. dev_kfree_skb(skb);
  1724. return;
  1725. }
  1726. spin_lock_bh(&priv->tx_lock);
  1727. txq = priv->txq + index;
  1728. /* Mgmt frames that go out frequently are probe
  1729. * responses. Other mgmt frames got out relatively
  1730. * infrequently. Hence reserve 2 buffers so that
  1731. * other mgmt frames do not get dropped due to an
  1732. * already queued probe response in one of the
  1733. * reserved buffers.
  1734. */
  1735. if (txq->len >= MWL8K_TX_DESCS - 2) {
  1736. if (!mgmtframe || txq->len == MWL8K_TX_DESCS) {
  1737. if (start_ba_session) {
  1738. spin_lock(&priv->stream_lock);
  1739. mwl8k_remove_stream(hw, stream);
  1740. spin_unlock(&priv->stream_lock);
  1741. }
  1742. mwl8k_tx_start(priv);
  1743. spin_unlock_bh(&priv->tx_lock);
  1744. pci_unmap_single(priv->pdev, dma, skb->len,
  1745. PCI_DMA_TODEVICE);
  1746. dev_kfree_skb(skb);
  1747. return;
  1748. }
  1749. }
  1750. BUG_ON(txq->skb[txq->tail] != NULL);
  1751. txq->skb[txq->tail] = skb;
  1752. tx = txq->txd + txq->tail;
  1753. tx->data_rate = txdatarate;
  1754. tx->tx_priority = txpriority;
  1755. tx->qos_control = cpu_to_le16(qos);
  1756. tx->pkt_phys_addr = cpu_to_le32(dma);
  1757. tx->pkt_len = cpu_to_le16(skb->len);
  1758. tx->rate_info = 0;
  1759. if (!priv->ap_fw && sta != NULL)
  1760. tx->peer_id = MWL8K_STA(sta)->peer_id;
  1761. else
  1762. tx->peer_id = 0;
  1763. if (priv->ap_fw && ieee80211_is_data(wh->frame_control) && !eapol_frame)
  1764. tx->timestamp = cpu_to_le32(ioread32(priv->regs +
  1765. MWL8K_HW_TIMER_REGISTER));
  1766. else
  1767. tx->timestamp = 0;
  1768. wmb();
  1769. tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
  1770. txq->len++;
  1771. priv->pending_tx_pkts++;
  1772. txq->tail++;
  1773. if (txq->tail == MWL8K_TX_DESCS)
  1774. txq->tail = 0;
  1775. mwl8k_tx_start(priv);
  1776. spin_unlock_bh(&priv->tx_lock);
  1777. /* Initiate the ampdu session here */
  1778. if (start_ba_session) {
  1779. spin_lock(&priv->stream_lock);
  1780. if (mwl8k_start_stream(hw, stream))
  1781. mwl8k_remove_stream(hw, stream);
  1782. spin_unlock(&priv->stream_lock);
  1783. }
  1784. }
  1785. /*
  1786. * Firmware access.
  1787. *
  1788. * We have the following requirements for issuing firmware commands:
  1789. * - Some commands require that the packet transmit path is idle when
  1790. * the command is issued. (For simplicity, we'll just quiesce the
  1791. * transmit path for every command.)
  1792. * - There are certain sequences of commands that need to be issued to
  1793. * the hardware sequentially, with no other intervening commands.
  1794. *
  1795. * This leads to an implementation of a "firmware lock" as a mutex that
  1796. * can be taken recursively, and which is taken by both the low-level
  1797. * command submission function (mwl8k_post_cmd) as well as any users of
  1798. * that function that require issuing of an atomic sequence of commands,
  1799. * and quiesces the transmit path whenever it's taken.
  1800. */
  1801. static int mwl8k_fw_lock(struct ieee80211_hw *hw)
  1802. {
  1803. struct mwl8k_priv *priv = hw->priv;
  1804. if (priv->fw_mutex_owner != current) {
  1805. int rc;
  1806. mutex_lock(&priv->fw_mutex);
  1807. ieee80211_stop_queues(hw);
  1808. rc = mwl8k_tx_wait_empty(hw);
  1809. if (rc) {
  1810. if (!priv->hw_restart_in_progress)
  1811. ieee80211_wake_queues(hw);
  1812. mutex_unlock(&priv->fw_mutex);
  1813. return rc;
  1814. }
  1815. priv->fw_mutex_owner = current;
  1816. }
  1817. priv->fw_mutex_depth++;
  1818. return 0;
  1819. }
  1820. static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
  1821. {
  1822. struct mwl8k_priv *priv = hw->priv;
  1823. if (!--priv->fw_mutex_depth) {
  1824. if (!priv->hw_restart_in_progress)
  1825. ieee80211_wake_queues(hw);
  1826. priv->fw_mutex_owner = NULL;
  1827. mutex_unlock(&priv->fw_mutex);
  1828. }
  1829. }
  1830. static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable,
  1831. u32 bitmap);
  1832. /*
  1833. * Command processing.
  1834. */
  1835. /* Timeout firmware commands after 10s */
  1836. #define MWL8K_CMD_TIMEOUT_MS 10000
  1837. static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
  1838. {
  1839. DECLARE_COMPLETION_ONSTACK(cmd_wait);
  1840. struct mwl8k_priv *priv = hw->priv;
  1841. void __iomem *regs = priv->regs;
  1842. dma_addr_t dma_addr;
  1843. unsigned int dma_size;
  1844. int rc;
  1845. unsigned long timeout = 0;
  1846. u8 buf[32];
  1847. u32 bitmap = 0;
  1848. wiphy_dbg(hw->wiphy, "Posting %s [%d]\n",
  1849. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), cmd->macid);
  1850. /* Before posting firmware commands that could change the hardware
  1851. * characteristics, make sure that all BSSes are stopped temporary.
  1852. * Enable these stopped BSSes after completion of the commands
  1853. */
  1854. rc = mwl8k_fw_lock(hw);
  1855. if (rc)
  1856. return rc;
  1857. if (priv->ap_fw && priv->running_bsses) {
  1858. switch (le16_to_cpu(cmd->code)) {
  1859. case MWL8K_CMD_SET_RF_CHANNEL:
  1860. case MWL8K_CMD_RADIO_CONTROL:
  1861. case MWL8K_CMD_RF_TX_POWER:
  1862. case MWL8K_CMD_TX_POWER:
  1863. case MWL8K_CMD_RF_ANTENNA:
  1864. case MWL8K_CMD_RTS_THRESHOLD:
  1865. case MWL8K_CMD_MIMO_CONFIG:
  1866. bitmap = priv->running_bsses;
  1867. mwl8k_enable_bsses(hw, false, bitmap);
  1868. break;
  1869. }
  1870. }
  1871. cmd->result = (__force __le16) 0xffff;
  1872. dma_size = le16_to_cpu(cmd->length);
  1873. dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
  1874. PCI_DMA_BIDIRECTIONAL);
  1875. if (pci_dma_mapping_error(priv->pdev, dma_addr))
  1876. return -ENOMEM;
  1877. priv->hostcmd_wait = &cmd_wait;
  1878. iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
  1879. iowrite32(MWL8K_H2A_INT_DOORBELL,
  1880. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1881. iowrite32(MWL8K_H2A_INT_DUMMY,
  1882. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1883. timeout = wait_for_completion_timeout(&cmd_wait,
  1884. msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
  1885. priv->hostcmd_wait = NULL;
  1886. pci_unmap_single(priv->pdev, dma_addr, dma_size,
  1887. PCI_DMA_BIDIRECTIONAL);
  1888. if (!timeout) {
  1889. wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
  1890. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1891. MWL8K_CMD_TIMEOUT_MS);
  1892. rc = -ETIMEDOUT;
  1893. } else {
  1894. int ms;
  1895. ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
  1896. rc = cmd->result ? -EINVAL : 0;
  1897. if (rc)
  1898. wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
  1899. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1900. le16_to_cpu(cmd->result));
  1901. else if (ms > 2000)
  1902. wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
  1903. mwl8k_cmd_name(cmd->code,
  1904. buf, sizeof(buf)),
  1905. ms);
  1906. }
  1907. if (bitmap)
  1908. mwl8k_enable_bsses(hw, true, bitmap);
  1909. mwl8k_fw_unlock(hw);
  1910. return rc;
  1911. }
  1912. static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
  1913. struct ieee80211_vif *vif,
  1914. struct mwl8k_cmd_pkt *cmd)
  1915. {
  1916. if (vif != NULL)
  1917. cmd->macid = MWL8K_VIF(vif)->macid;
  1918. return mwl8k_post_cmd(hw, cmd);
  1919. }
  1920. /*
  1921. * Setup code shared between STA and AP firmware images.
  1922. */
  1923. static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
  1924. {
  1925. struct mwl8k_priv *priv = hw->priv;
  1926. BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
  1927. memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
  1928. BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
  1929. memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
  1930. priv->band_24.band = IEEE80211_BAND_2GHZ;
  1931. priv->band_24.channels = priv->channels_24;
  1932. priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
  1933. priv->band_24.bitrates = priv->rates_24;
  1934. priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
  1935. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
  1936. }
  1937. static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
  1938. {
  1939. struct mwl8k_priv *priv = hw->priv;
  1940. BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
  1941. memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
  1942. BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
  1943. memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
  1944. priv->band_50.band = IEEE80211_BAND_5GHZ;
  1945. priv->band_50.channels = priv->channels_50;
  1946. priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
  1947. priv->band_50.bitrates = priv->rates_50;
  1948. priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
  1949. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
  1950. }
  1951. /*
  1952. * CMD_GET_HW_SPEC (STA version).
  1953. */
  1954. struct mwl8k_cmd_get_hw_spec_sta {
  1955. struct mwl8k_cmd_pkt header;
  1956. __u8 hw_rev;
  1957. __u8 host_interface;
  1958. __le16 num_mcaddrs;
  1959. __u8 perm_addr[ETH_ALEN];
  1960. __le16 region_code;
  1961. __le32 fw_rev;
  1962. __le32 ps_cookie;
  1963. __le32 caps;
  1964. __u8 mcs_bitmap[16];
  1965. __le32 rx_queue_ptr;
  1966. __le32 num_tx_queues;
  1967. __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
  1968. __le32 caps2;
  1969. __le32 num_tx_desc_per_queue;
  1970. __le32 total_rxd;
  1971. } __packed;
  1972. #define MWL8K_CAP_MAX_AMSDU 0x20000000
  1973. #define MWL8K_CAP_GREENFIELD 0x08000000
  1974. #define MWL8K_CAP_AMPDU 0x04000000
  1975. #define MWL8K_CAP_RX_STBC 0x01000000
  1976. #define MWL8K_CAP_TX_STBC 0x00800000
  1977. #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
  1978. #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
  1979. #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
  1980. #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
  1981. #define MWL8K_CAP_DELAY_BA 0x00003000
  1982. #define MWL8K_CAP_MIMO 0x00000200
  1983. #define MWL8K_CAP_40MHZ 0x00000100
  1984. #define MWL8K_CAP_BAND_MASK 0x00000007
  1985. #define MWL8K_CAP_5GHZ 0x00000004
  1986. #define MWL8K_CAP_2GHZ4 0x00000001
  1987. static void
  1988. mwl8k_set_ht_caps(struct ieee80211_hw *hw,
  1989. struct ieee80211_supported_band *band, u32 cap)
  1990. {
  1991. int rx_streams;
  1992. int tx_streams;
  1993. band->ht_cap.ht_supported = 1;
  1994. if (cap & MWL8K_CAP_MAX_AMSDU)
  1995. band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  1996. if (cap & MWL8K_CAP_GREENFIELD)
  1997. band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
  1998. if (cap & MWL8K_CAP_AMPDU) {
  1999. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  2000. band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  2001. band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  2002. }
  2003. if (cap & MWL8K_CAP_RX_STBC)
  2004. band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
  2005. if (cap & MWL8K_CAP_TX_STBC)
  2006. band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  2007. if (cap & MWL8K_CAP_SHORTGI_40MHZ)
  2008. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  2009. if (cap & MWL8K_CAP_SHORTGI_20MHZ)
  2010. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  2011. if (cap & MWL8K_CAP_DELAY_BA)
  2012. band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
  2013. if (cap & MWL8K_CAP_40MHZ)
  2014. band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  2015. rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
  2016. tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
  2017. band->ht_cap.mcs.rx_mask[0] = 0xff;
  2018. if (rx_streams >= 2)
  2019. band->ht_cap.mcs.rx_mask[1] = 0xff;
  2020. if (rx_streams >= 3)
  2021. band->ht_cap.mcs.rx_mask[2] = 0xff;
  2022. band->ht_cap.mcs.rx_mask[4] = 0x01;
  2023. band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  2024. if (rx_streams != tx_streams) {
  2025. band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  2026. band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
  2027. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  2028. }
  2029. }
  2030. static void
  2031. mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
  2032. {
  2033. struct mwl8k_priv *priv = hw->priv;
  2034. if (priv->caps)
  2035. return;
  2036. if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
  2037. mwl8k_setup_2ghz_band(hw);
  2038. if (caps & MWL8K_CAP_MIMO)
  2039. mwl8k_set_ht_caps(hw, &priv->band_24, caps);
  2040. }
  2041. if (caps & MWL8K_CAP_5GHZ) {
  2042. mwl8k_setup_5ghz_band(hw);
  2043. if (caps & MWL8K_CAP_MIMO)
  2044. mwl8k_set_ht_caps(hw, &priv->band_50, caps);
  2045. }
  2046. priv->caps = caps;
  2047. }
  2048. static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
  2049. {
  2050. struct mwl8k_priv *priv = hw->priv;
  2051. struct mwl8k_cmd_get_hw_spec_sta *cmd;
  2052. int rc;
  2053. int i;
  2054. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2055. if (cmd == NULL)
  2056. return -ENOMEM;
  2057. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  2058. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2059. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  2060. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2061. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
  2062. cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
  2063. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  2064. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
  2065. cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
  2066. cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
  2067. rc = mwl8k_post_cmd(hw, &cmd->header);
  2068. if (!rc) {
  2069. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  2070. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  2071. priv->fw_rev = le32_to_cpu(cmd->fw_rev);
  2072. priv->hw_rev = cmd->hw_rev;
  2073. mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
  2074. priv->ap_macids_supported = 0x00000000;
  2075. priv->sta_macids_supported = 0x00000001;
  2076. }
  2077. kfree(cmd);
  2078. return rc;
  2079. }
  2080. /*
  2081. * CMD_GET_HW_SPEC (AP version).
  2082. */
  2083. struct mwl8k_cmd_get_hw_spec_ap {
  2084. struct mwl8k_cmd_pkt header;
  2085. __u8 hw_rev;
  2086. __u8 host_interface;
  2087. __le16 num_wcb;
  2088. __le16 num_mcaddrs;
  2089. __u8 perm_addr[ETH_ALEN];
  2090. __le16 region_code;
  2091. __le16 num_antenna;
  2092. __le32 fw_rev;
  2093. __le32 wcbbase0;
  2094. __le32 rxwrptr;
  2095. __le32 rxrdptr;
  2096. __le32 ps_cookie;
  2097. __le32 wcbbase1;
  2098. __le32 wcbbase2;
  2099. __le32 wcbbase3;
  2100. __le32 fw_api_version;
  2101. __le32 caps;
  2102. __le32 num_of_ampdu_queues;
  2103. __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
  2104. } __packed;
  2105. static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
  2106. {
  2107. struct mwl8k_priv *priv = hw->priv;
  2108. struct mwl8k_cmd_get_hw_spec_ap *cmd;
  2109. int rc, i;
  2110. u32 api_version;
  2111. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2112. if (cmd == NULL)
  2113. return -ENOMEM;
  2114. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  2115. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2116. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  2117. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2118. rc = mwl8k_post_cmd(hw, &cmd->header);
  2119. if (!rc) {
  2120. int off;
  2121. api_version = le32_to_cpu(cmd->fw_api_version);
  2122. if (priv->device_info->fw_api_ap != api_version) {
  2123. printk(KERN_ERR "%s: Unsupported fw API version for %s."
  2124. " Expected %d got %d.\n", MWL8K_NAME,
  2125. priv->device_info->part_name,
  2126. priv->device_info->fw_api_ap,
  2127. api_version);
  2128. rc = -EINVAL;
  2129. goto done;
  2130. }
  2131. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  2132. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  2133. priv->fw_rev = le32_to_cpu(cmd->fw_rev);
  2134. priv->hw_rev = cmd->hw_rev;
  2135. mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
  2136. priv->ap_macids_supported = 0x000000ff;
  2137. priv->sta_macids_supported = 0x00000100;
  2138. priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
  2139. if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
  2140. wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
  2141. " but we only support %d.\n",
  2142. priv->num_ampdu_queues,
  2143. MWL8K_MAX_AMPDU_QUEUES);
  2144. priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
  2145. }
  2146. off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
  2147. iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
  2148. off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
  2149. iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
  2150. priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
  2151. priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
  2152. priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
  2153. priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
  2154. for (i = 0; i < priv->num_ampdu_queues; i++)
  2155. priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
  2156. le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
  2157. }
  2158. done:
  2159. kfree(cmd);
  2160. return rc;
  2161. }
  2162. /*
  2163. * CMD_SET_HW_SPEC.
  2164. */
  2165. struct mwl8k_cmd_set_hw_spec {
  2166. struct mwl8k_cmd_pkt header;
  2167. __u8 hw_rev;
  2168. __u8 host_interface;
  2169. __le16 num_mcaddrs;
  2170. __u8 perm_addr[ETH_ALEN];
  2171. __le16 region_code;
  2172. __le32 fw_rev;
  2173. __le32 ps_cookie;
  2174. __le32 caps;
  2175. __le32 rx_queue_ptr;
  2176. __le32 num_tx_queues;
  2177. __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
  2178. __le32 flags;
  2179. __le32 num_tx_desc_per_queue;
  2180. __le32 total_rxd;
  2181. } __packed;
  2182. /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
  2183. * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
  2184. * the packets that are queued for more than 500ms, will be dropped in the
  2185. * hardware. This helps minimizing the issues caused due to head-of-line
  2186. * blocking where a slow client can hog the bandwidth and affect traffic to a
  2187. * faster client.
  2188. */
  2189. #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
  2190. #define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
  2191. #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
  2192. #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
  2193. #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
  2194. static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
  2195. {
  2196. struct mwl8k_priv *priv = hw->priv;
  2197. struct mwl8k_cmd_set_hw_spec *cmd;
  2198. int rc;
  2199. int i;
  2200. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2201. if (cmd == NULL)
  2202. return -ENOMEM;
  2203. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
  2204. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2205. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2206. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
  2207. cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
  2208. /*
  2209. * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
  2210. * that order. Firmware has Q3 as highest priority and Q0 as lowest
  2211. * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
  2212. * priority is interpreted the right way in firmware.
  2213. */
  2214. for (i = 0; i < mwl8k_tx_queues(priv); i++) {
  2215. int j = mwl8k_tx_queues(priv) - 1 - i;
  2216. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
  2217. }
  2218. cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
  2219. MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
  2220. MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON |
  2221. MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY |
  2222. MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR);
  2223. cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
  2224. cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
  2225. rc = mwl8k_post_cmd(hw, &cmd->header);
  2226. kfree(cmd);
  2227. return rc;
  2228. }
  2229. /*
  2230. * CMD_MAC_MULTICAST_ADR.
  2231. */
  2232. struct mwl8k_cmd_mac_multicast_adr {
  2233. struct mwl8k_cmd_pkt header;
  2234. __le16 action;
  2235. __le16 numaddr;
  2236. __u8 addr[0][ETH_ALEN];
  2237. };
  2238. #define MWL8K_ENABLE_RX_DIRECTED 0x0001
  2239. #define MWL8K_ENABLE_RX_MULTICAST 0x0002
  2240. #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
  2241. #define MWL8K_ENABLE_RX_BROADCAST 0x0008
  2242. static struct mwl8k_cmd_pkt *
  2243. __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
  2244. struct netdev_hw_addr_list *mc_list)
  2245. {
  2246. struct mwl8k_priv *priv = hw->priv;
  2247. struct mwl8k_cmd_mac_multicast_adr *cmd;
  2248. int size;
  2249. int mc_count = 0;
  2250. if (mc_list)
  2251. mc_count = netdev_hw_addr_list_count(mc_list);
  2252. if (allmulti || mc_count > priv->num_mcaddrs) {
  2253. allmulti = 1;
  2254. mc_count = 0;
  2255. }
  2256. size = sizeof(*cmd) + mc_count * ETH_ALEN;
  2257. cmd = kzalloc(size, GFP_ATOMIC);
  2258. if (cmd == NULL)
  2259. return NULL;
  2260. cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
  2261. cmd->header.length = cpu_to_le16(size);
  2262. cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
  2263. MWL8K_ENABLE_RX_BROADCAST);
  2264. if (allmulti) {
  2265. cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
  2266. } else if (mc_count) {
  2267. struct netdev_hw_addr *ha;
  2268. int i = 0;
  2269. cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
  2270. cmd->numaddr = cpu_to_le16(mc_count);
  2271. netdev_hw_addr_list_for_each(ha, mc_list) {
  2272. memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
  2273. }
  2274. }
  2275. return &cmd->header;
  2276. }
  2277. /*
  2278. * CMD_GET_STAT.
  2279. */
  2280. struct mwl8k_cmd_get_stat {
  2281. struct mwl8k_cmd_pkt header;
  2282. __le32 stats[64];
  2283. } __packed;
  2284. #define MWL8K_STAT_ACK_FAILURE 9
  2285. #define MWL8K_STAT_RTS_FAILURE 12
  2286. #define MWL8K_STAT_FCS_ERROR 24
  2287. #define MWL8K_STAT_RTS_SUCCESS 11
  2288. static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
  2289. struct ieee80211_low_level_stats *stats)
  2290. {
  2291. struct mwl8k_cmd_get_stat *cmd;
  2292. int rc;
  2293. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2294. if (cmd == NULL)
  2295. return -ENOMEM;
  2296. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
  2297. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2298. rc = mwl8k_post_cmd(hw, &cmd->header);
  2299. if (!rc) {
  2300. stats->dot11ACKFailureCount =
  2301. le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
  2302. stats->dot11RTSFailureCount =
  2303. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
  2304. stats->dot11FCSErrorCount =
  2305. le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
  2306. stats->dot11RTSSuccessCount =
  2307. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
  2308. }
  2309. kfree(cmd);
  2310. return rc;
  2311. }
  2312. /*
  2313. * CMD_RADIO_CONTROL.
  2314. */
  2315. struct mwl8k_cmd_radio_control {
  2316. struct mwl8k_cmd_pkt header;
  2317. __le16 action;
  2318. __le16 control;
  2319. __le16 radio_on;
  2320. } __packed;
  2321. static int
  2322. mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
  2323. {
  2324. struct mwl8k_priv *priv = hw->priv;
  2325. struct mwl8k_cmd_radio_control *cmd;
  2326. int rc;
  2327. if (enable == priv->radio_on && !force)
  2328. return 0;
  2329. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2330. if (cmd == NULL)
  2331. return -ENOMEM;
  2332. cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
  2333. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2334. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2335. cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
  2336. cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
  2337. rc = mwl8k_post_cmd(hw, &cmd->header);
  2338. kfree(cmd);
  2339. if (!rc)
  2340. priv->radio_on = enable;
  2341. return rc;
  2342. }
  2343. static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
  2344. {
  2345. return mwl8k_cmd_radio_control(hw, 0, 0);
  2346. }
  2347. static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
  2348. {
  2349. return mwl8k_cmd_radio_control(hw, 1, 0);
  2350. }
  2351. static int
  2352. mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
  2353. {
  2354. struct mwl8k_priv *priv = hw->priv;
  2355. priv->radio_short_preamble = short_preamble;
  2356. return mwl8k_cmd_radio_control(hw, 1, 1);
  2357. }
  2358. /*
  2359. * CMD_RF_TX_POWER.
  2360. */
  2361. #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
  2362. struct mwl8k_cmd_rf_tx_power {
  2363. struct mwl8k_cmd_pkt header;
  2364. __le16 action;
  2365. __le16 support_level;
  2366. __le16 current_level;
  2367. __le16 reserved;
  2368. __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
  2369. } __packed;
  2370. static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
  2371. {
  2372. struct mwl8k_cmd_rf_tx_power *cmd;
  2373. int rc;
  2374. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2375. if (cmd == NULL)
  2376. return -ENOMEM;
  2377. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
  2378. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2379. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2380. cmd->support_level = cpu_to_le16(dBm);
  2381. rc = mwl8k_post_cmd(hw, &cmd->header);
  2382. kfree(cmd);
  2383. return rc;
  2384. }
  2385. /*
  2386. * CMD_TX_POWER.
  2387. */
  2388. #define MWL8K_TX_POWER_LEVEL_TOTAL 12
  2389. struct mwl8k_cmd_tx_power {
  2390. struct mwl8k_cmd_pkt header;
  2391. __le16 action;
  2392. __le16 band;
  2393. __le16 channel;
  2394. __le16 bw;
  2395. __le16 sub_ch;
  2396. __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
  2397. } __packed;
  2398. static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
  2399. struct ieee80211_conf *conf,
  2400. unsigned short pwr)
  2401. {
  2402. struct ieee80211_channel *channel = conf->chandef.chan;
  2403. enum nl80211_channel_type channel_type =
  2404. cfg80211_get_chandef_type(&conf->chandef);
  2405. struct mwl8k_cmd_tx_power *cmd;
  2406. int rc;
  2407. int i;
  2408. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2409. if (cmd == NULL)
  2410. return -ENOMEM;
  2411. cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
  2412. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2413. cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
  2414. if (channel->band == IEEE80211_BAND_2GHZ)
  2415. cmd->band = cpu_to_le16(0x1);
  2416. else if (channel->band == IEEE80211_BAND_5GHZ)
  2417. cmd->band = cpu_to_le16(0x4);
  2418. cmd->channel = cpu_to_le16(channel->hw_value);
  2419. if (channel_type == NL80211_CHAN_NO_HT ||
  2420. channel_type == NL80211_CHAN_HT20) {
  2421. cmd->bw = cpu_to_le16(0x2);
  2422. } else {
  2423. cmd->bw = cpu_to_le16(0x4);
  2424. if (channel_type == NL80211_CHAN_HT40MINUS)
  2425. cmd->sub_ch = cpu_to_le16(0x3);
  2426. else if (channel_type == NL80211_CHAN_HT40PLUS)
  2427. cmd->sub_ch = cpu_to_le16(0x1);
  2428. }
  2429. for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
  2430. cmd->power_level_list[i] = cpu_to_le16(pwr);
  2431. rc = mwl8k_post_cmd(hw, &cmd->header);
  2432. kfree(cmd);
  2433. return rc;
  2434. }
  2435. /*
  2436. * CMD_RF_ANTENNA.
  2437. */
  2438. struct mwl8k_cmd_rf_antenna {
  2439. struct mwl8k_cmd_pkt header;
  2440. __le16 antenna;
  2441. __le16 mode;
  2442. } __packed;
  2443. #define MWL8K_RF_ANTENNA_RX 1
  2444. #define MWL8K_RF_ANTENNA_TX 2
  2445. static int
  2446. mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
  2447. {
  2448. struct mwl8k_cmd_rf_antenna *cmd;
  2449. int rc;
  2450. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2451. if (cmd == NULL)
  2452. return -ENOMEM;
  2453. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
  2454. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2455. cmd->antenna = cpu_to_le16(antenna);
  2456. cmd->mode = cpu_to_le16(mask);
  2457. rc = mwl8k_post_cmd(hw, &cmd->header);
  2458. kfree(cmd);
  2459. return rc;
  2460. }
  2461. /*
  2462. * CMD_SET_BEACON.
  2463. */
  2464. struct mwl8k_cmd_set_beacon {
  2465. struct mwl8k_cmd_pkt header;
  2466. __le16 beacon_len;
  2467. __u8 beacon[0];
  2468. };
  2469. static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
  2470. struct ieee80211_vif *vif, u8 *beacon, int len)
  2471. {
  2472. struct mwl8k_cmd_set_beacon *cmd;
  2473. int rc;
  2474. cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
  2475. if (cmd == NULL)
  2476. return -ENOMEM;
  2477. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
  2478. cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
  2479. cmd->beacon_len = cpu_to_le16(len);
  2480. memcpy(cmd->beacon, beacon, len);
  2481. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2482. kfree(cmd);
  2483. return rc;
  2484. }
  2485. /*
  2486. * CMD_SET_PRE_SCAN.
  2487. */
  2488. struct mwl8k_cmd_set_pre_scan {
  2489. struct mwl8k_cmd_pkt header;
  2490. } __packed;
  2491. static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
  2492. {
  2493. struct mwl8k_cmd_set_pre_scan *cmd;
  2494. int rc;
  2495. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2496. if (cmd == NULL)
  2497. return -ENOMEM;
  2498. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
  2499. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2500. rc = mwl8k_post_cmd(hw, &cmd->header);
  2501. kfree(cmd);
  2502. return rc;
  2503. }
  2504. /*
  2505. * CMD_BBP_REG_ACCESS.
  2506. */
  2507. struct mwl8k_cmd_bbp_reg_access {
  2508. struct mwl8k_cmd_pkt header;
  2509. __le16 action;
  2510. __le16 offset;
  2511. u8 value;
  2512. u8 rsrv[3];
  2513. } __packed;
  2514. static int
  2515. mwl8k_cmd_bbp_reg_access(struct ieee80211_hw *hw,
  2516. u16 action,
  2517. u16 offset,
  2518. u8 *value)
  2519. {
  2520. struct mwl8k_cmd_bbp_reg_access *cmd;
  2521. int rc;
  2522. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2523. if (cmd == NULL)
  2524. return -ENOMEM;
  2525. cmd->header.code = cpu_to_le16(MWL8K_CMD_BBP_REG_ACCESS);
  2526. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2527. cmd->action = cpu_to_le16(action);
  2528. cmd->offset = cpu_to_le16(offset);
  2529. rc = mwl8k_post_cmd(hw, &cmd->header);
  2530. if (!rc)
  2531. *value = cmd->value;
  2532. else
  2533. *value = 0;
  2534. kfree(cmd);
  2535. return rc;
  2536. }
  2537. /*
  2538. * CMD_SET_POST_SCAN.
  2539. */
  2540. struct mwl8k_cmd_set_post_scan {
  2541. struct mwl8k_cmd_pkt header;
  2542. __le32 isibss;
  2543. __u8 bssid[ETH_ALEN];
  2544. } __packed;
  2545. static int
  2546. mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
  2547. {
  2548. struct mwl8k_cmd_set_post_scan *cmd;
  2549. int rc;
  2550. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2551. if (cmd == NULL)
  2552. return -ENOMEM;
  2553. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
  2554. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2555. cmd->isibss = 0;
  2556. memcpy(cmd->bssid, mac, ETH_ALEN);
  2557. rc = mwl8k_post_cmd(hw, &cmd->header);
  2558. kfree(cmd);
  2559. return rc;
  2560. }
  2561. static int freq_to_idx(struct mwl8k_priv *priv, int freq)
  2562. {
  2563. struct ieee80211_supported_band *sband;
  2564. int band, ch, idx = 0;
  2565. for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
  2566. sband = priv->hw->wiphy->bands[band];
  2567. if (!sband)
  2568. continue;
  2569. for (ch = 0; ch < sband->n_channels; ch++, idx++)
  2570. if (sband->channels[ch].center_freq == freq)
  2571. goto exit;
  2572. }
  2573. exit:
  2574. return idx;
  2575. }
  2576. static void mwl8k_update_survey(struct mwl8k_priv *priv,
  2577. struct ieee80211_channel *channel)
  2578. {
  2579. u32 cca_cnt, rx_rdy;
  2580. s8 nf = 0, idx;
  2581. struct survey_info *survey;
  2582. idx = freq_to_idx(priv, priv->acs_chan->center_freq);
  2583. if (idx >= MWL8K_NUM_CHANS) {
  2584. wiphy_err(priv->hw->wiphy, "Failed to update survey\n");
  2585. return;
  2586. }
  2587. survey = &priv->survey[idx];
  2588. cca_cnt = ioread32(priv->regs + NOK_CCA_CNT_REG);
  2589. cca_cnt /= 1000; /* uSecs to mSecs */
  2590. survey->channel_time_busy = (u64) cca_cnt;
  2591. rx_rdy = ioread32(priv->regs + BBU_RXRDY_CNT_REG);
  2592. rx_rdy /= 1000; /* uSecs to mSecs */
  2593. survey->channel_time_rx = (u64) rx_rdy;
  2594. priv->channel_time = jiffies - priv->channel_time;
  2595. survey->channel_time = jiffies_to_msecs(priv->channel_time);
  2596. survey->channel = channel;
  2597. mwl8k_cmd_bbp_reg_access(priv->hw, 0, BBU_AVG_NOISE_VAL, &nf);
  2598. /* Make sure sign is negative else ACS at hostapd fails */
  2599. survey->noise = nf * -1;
  2600. survey->filled = SURVEY_INFO_NOISE_DBM |
  2601. SURVEY_INFO_CHANNEL_TIME |
  2602. SURVEY_INFO_CHANNEL_TIME_BUSY |
  2603. SURVEY_INFO_CHANNEL_TIME_RX;
  2604. }
  2605. /*
  2606. * CMD_SET_RF_CHANNEL.
  2607. */
  2608. struct mwl8k_cmd_set_rf_channel {
  2609. struct mwl8k_cmd_pkt header;
  2610. __le16 action;
  2611. __u8 current_channel;
  2612. __le32 channel_flags;
  2613. } __packed;
  2614. static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
  2615. struct ieee80211_conf *conf)
  2616. {
  2617. struct ieee80211_channel *channel = conf->chandef.chan;
  2618. enum nl80211_channel_type channel_type =
  2619. cfg80211_get_chandef_type(&conf->chandef);
  2620. struct mwl8k_cmd_set_rf_channel *cmd;
  2621. struct mwl8k_priv *priv = hw->priv;
  2622. int rc;
  2623. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2624. if (cmd == NULL)
  2625. return -ENOMEM;
  2626. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
  2627. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2628. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2629. cmd->current_channel = channel->hw_value;
  2630. if (channel->band == IEEE80211_BAND_2GHZ)
  2631. cmd->channel_flags |= cpu_to_le32(0x00000001);
  2632. else if (channel->band == IEEE80211_BAND_5GHZ)
  2633. cmd->channel_flags |= cpu_to_le32(0x00000004);
  2634. if (!priv->sw_scan_start) {
  2635. if (channel_type == NL80211_CHAN_NO_HT ||
  2636. channel_type == NL80211_CHAN_HT20)
  2637. cmd->channel_flags |= cpu_to_le32(0x00000080);
  2638. else if (channel_type == NL80211_CHAN_HT40MINUS)
  2639. cmd->channel_flags |= cpu_to_le32(0x000001900);
  2640. else if (channel_type == NL80211_CHAN_HT40PLUS)
  2641. cmd->channel_flags |= cpu_to_le32(0x000000900);
  2642. } else {
  2643. cmd->channel_flags |= cpu_to_le32(0x00000080);
  2644. }
  2645. if (priv->sw_scan_start) {
  2646. /* Store current channel stats
  2647. * before switching to newer one.
  2648. * This will be processed only for AP fw.
  2649. */
  2650. if (priv->channel_time != 0)
  2651. mwl8k_update_survey(priv, priv->acs_chan);
  2652. priv->channel_time = jiffies;
  2653. priv->acs_chan = channel;
  2654. }
  2655. rc = mwl8k_post_cmd(hw, &cmd->header);
  2656. kfree(cmd);
  2657. return rc;
  2658. }
  2659. /*
  2660. * CMD_SET_AID.
  2661. */
  2662. #define MWL8K_FRAME_PROT_DISABLED 0x00
  2663. #define MWL8K_FRAME_PROT_11G 0x07
  2664. #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
  2665. #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
  2666. struct mwl8k_cmd_update_set_aid {
  2667. struct mwl8k_cmd_pkt header;
  2668. __le16 aid;
  2669. /* AP's MAC address (BSSID) */
  2670. __u8 bssid[ETH_ALEN];
  2671. __le16 protection_mode;
  2672. __u8 supp_rates[14];
  2673. } __packed;
  2674. static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
  2675. {
  2676. int i;
  2677. int j;
  2678. /*
  2679. * Clear nonstandard rate 4.
  2680. */
  2681. mask &= 0x1fef;
  2682. for (i = 0, j = 0; i < 13; i++) {
  2683. if (mask & (1 << i))
  2684. rates[j++] = mwl8k_rates_24[i].hw_value;
  2685. }
  2686. }
  2687. static int
  2688. mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
  2689. struct ieee80211_vif *vif, u32 legacy_rate_mask)
  2690. {
  2691. struct mwl8k_cmd_update_set_aid *cmd;
  2692. u16 prot_mode;
  2693. int rc;
  2694. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2695. if (cmd == NULL)
  2696. return -ENOMEM;
  2697. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
  2698. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2699. cmd->aid = cpu_to_le16(vif->bss_conf.aid);
  2700. memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
  2701. if (vif->bss_conf.use_cts_prot) {
  2702. prot_mode = MWL8K_FRAME_PROT_11G;
  2703. } else {
  2704. switch (vif->bss_conf.ht_operation_mode &
  2705. IEEE80211_HT_OP_MODE_PROTECTION) {
  2706. case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
  2707. prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
  2708. break;
  2709. case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
  2710. prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
  2711. break;
  2712. default:
  2713. prot_mode = MWL8K_FRAME_PROT_DISABLED;
  2714. break;
  2715. }
  2716. }
  2717. cmd->protection_mode = cpu_to_le16(prot_mode);
  2718. legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
  2719. rc = mwl8k_post_cmd(hw, &cmd->header);
  2720. kfree(cmd);
  2721. return rc;
  2722. }
  2723. /*
  2724. * CMD_SET_RATE.
  2725. */
  2726. struct mwl8k_cmd_set_rate {
  2727. struct mwl8k_cmd_pkt header;
  2728. __u8 legacy_rates[14];
  2729. /* Bitmap for supported MCS codes. */
  2730. __u8 mcs_set[16];
  2731. __u8 reserved[16];
  2732. } __packed;
  2733. static int
  2734. mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  2735. u32 legacy_rate_mask, u8 *mcs_rates)
  2736. {
  2737. struct mwl8k_cmd_set_rate *cmd;
  2738. int rc;
  2739. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2740. if (cmd == NULL)
  2741. return -ENOMEM;
  2742. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
  2743. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2744. legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
  2745. memcpy(cmd->mcs_set, mcs_rates, 16);
  2746. rc = mwl8k_post_cmd(hw, &cmd->header);
  2747. kfree(cmd);
  2748. return rc;
  2749. }
  2750. /*
  2751. * CMD_FINALIZE_JOIN.
  2752. */
  2753. #define MWL8K_FJ_BEACON_MAXLEN 128
  2754. struct mwl8k_cmd_finalize_join {
  2755. struct mwl8k_cmd_pkt header;
  2756. __le32 sleep_interval; /* Number of beacon periods to sleep */
  2757. __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
  2758. } __packed;
  2759. static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
  2760. int framelen, int dtim)
  2761. {
  2762. struct mwl8k_cmd_finalize_join *cmd;
  2763. struct ieee80211_mgmt *payload = frame;
  2764. int payload_len;
  2765. int rc;
  2766. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2767. if (cmd == NULL)
  2768. return -ENOMEM;
  2769. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
  2770. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2771. cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
  2772. payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
  2773. if (payload_len < 0)
  2774. payload_len = 0;
  2775. else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
  2776. payload_len = MWL8K_FJ_BEACON_MAXLEN;
  2777. memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
  2778. rc = mwl8k_post_cmd(hw, &cmd->header);
  2779. kfree(cmd);
  2780. return rc;
  2781. }
  2782. /*
  2783. * CMD_SET_RTS_THRESHOLD.
  2784. */
  2785. struct mwl8k_cmd_set_rts_threshold {
  2786. struct mwl8k_cmd_pkt header;
  2787. __le16 action;
  2788. __le16 threshold;
  2789. } __packed;
  2790. static int
  2791. mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
  2792. {
  2793. struct mwl8k_cmd_set_rts_threshold *cmd;
  2794. int rc;
  2795. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2796. if (cmd == NULL)
  2797. return -ENOMEM;
  2798. cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
  2799. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2800. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2801. cmd->threshold = cpu_to_le16(rts_thresh);
  2802. rc = mwl8k_post_cmd(hw, &cmd->header);
  2803. kfree(cmd);
  2804. return rc;
  2805. }
  2806. /*
  2807. * CMD_SET_SLOT.
  2808. */
  2809. struct mwl8k_cmd_set_slot {
  2810. struct mwl8k_cmd_pkt header;
  2811. __le16 action;
  2812. __u8 short_slot;
  2813. } __packed;
  2814. static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
  2815. {
  2816. struct mwl8k_cmd_set_slot *cmd;
  2817. int rc;
  2818. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2819. if (cmd == NULL)
  2820. return -ENOMEM;
  2821. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
  2822. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2823. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2824. cmd->short_slot = short_slot_time;
  2825. rc = mwl8k_post_cmd(hw, &cmd->header);
  2826. kfree(cmd);
  2827. return rc;
  2828. }
  2829. /*
  2830. * CMD_SET_EDCA_PARAMS.
  2831. */
  2832. struct mwl8k_cmd_set_edca_params {
  2833. struct mwl8k_cmd_pkt header;
  2834. /* See MWL8K_SET_EDCA_XXX below */
  2835. __le16 action;
  2836. /* TX opportunity in units of 32 us */
  2837. __le16 txop;
  2838. union {
  2839. struct {
  2840. /* Log exponent of max contention period: 0...15 */
  2841. __le32 log_cw_max;
  2842. /* Log exponent of min contention period: 0...15 */
  2843. __le32 log_cw_min;
  2844. /* Adaptive interframe spacing in units of 32us */
  2845. __u8 aifs;
  2846. /* TX queue to configure */
  2847. __u8 txq;
  2848. } ap;
  2849. struct {
  2850. /* Log exponent of max contention period: 0...15 */
  2851. __u8 log_cw_max;
  2852. /* Log exponent of min contention period: 0...15 */
  2853. __u8 log_cw_min;
  2854. /* Adaptive interframe spacing in units of 32us */
  2855. __u8 aifs;
  2856. /* TX queue to configure */
  2857. __u8 txq;
  2858. } sta;
  2859. };
  2860. } __packed;
  2861. #define MWL8K_SET_EDCA_CW 0x01
  2862. #define MWL8K_SET_EDCA_TXOP 0x02
  2863. #define MWL8K_SET_EDCA_AIFS 0x04
  2864. #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
  2865. MWL8K_SET_EDCA_TXOP | \
  2866. MWL8K_SET_EDCA_AIFS)
  2867. static int
  2868. mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
  2869. __u16 cw_min, __u16 cw_max,
  2870. __u8 aifs, __u16 txop)
  2871. {
  2872. struct mwl8k_priv *priv = hw->priv;
  2873. struct mwl8k_cmd_set_edca_params *cmd;
  2874. int rc;
  2875. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2876. if (cmd == NULL)
  2877. return -ENOMEM;
  2878. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
  2879. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2880. cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
  2881. cmd->txop = cpu_to_le16(txop);
  2882. if (priv->ap_fw) {
  2883. cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
  2884. cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
  2885. cmd->ap.aifs = aifs;
  2886. cmd->ap.txq = qnum;
  2887. } else {
  2888. cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
  2889. cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
  2890. cmd->sta.aifs = aifs;
  2891. cmd->sta.txq = qnum;
  2892. }
  2893. rc = mwl8k_post_cmd(hw, &cmd->header);
  2894. kfree(cmd);
  2895. return rc;
  2896. }
  2897. /*
  2898. * CMD_SET_WMM_MODE.
  2899. */
  2900. struct mwl8k_cmd_set_wmm_mode {
  2901. struct mwl8k_cmd_pkt header;
  2902. __le16 action;
  2903. } __packed;
  2904. static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
  2905. {
  2906. struct mwl8k_priv *priv = hw->priv;
  2907. struct mwl8k_cmd_set_wmm_mode *cmd;
  2908. int rc;
  2909. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2910. if (cmd == NULL)
  2911. return -ENOMEM;
  2912. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
  2913. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2914. cmd->action = cpu_to_le16(!!enable);
  2915. rc = mwl8k_post_cmd(hw, &cmd->header);
  2916. kfree(cmd);
  2917. if (!rc)
  2918. priv->wmm_enabled = enable;
  2919. return rc;
  2920. }
  2921. /*
  2922. * CMD_MIMO_CONFIG.
  2923. */
  2924. struct mwl8k_cmd_mimo_config {
  2925. struct mwl8k_cmd_pkt header;
  2926. __le32 action;
  2927. __u8 rx_antenna_map;
  2928. __u8 tx_antenna_map;
  2929. } __packed;
  2930. static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
  2931. {
  2932. struct mwl8k_cmd_mimo_config *cmd;
  2933. int rc;
  2934. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2935. if (cmd == NULL)
  2936. return -ENOMEM;
  2937. cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
  2938. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2939. cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
  2940. cmd->rx_antenna_map = rx;
  2941. cmd->tx_antenna_map = tx;
  2942. rc = mwl8k_post_cmd(hw, &cmd->header);
  2943. kfree(cmd);
  2944. return rc;
  2945. }
  2946. /*
  2947. * CMD_USE_FIXED_RATE (STA version).
  2948. */
  2949. struct mwl8k_cmd_use_fixed_rate_sta {
  2950. struct mwl8k_cmd_pkt header;
  2951. __le32 action;
  2952. __le32 allow_rate_drop;
  2953. __le32 num_rates;
  2954. struct {
  2955. __le32 is_ht_rate;
  2956. __le32 enable_retry;
  2957. __le32 rate;
  2958. __le32 retry_count;
  2959. } rate_entry[8];
  2960. __le32 rate_type;
  2961. __le32 reserved1;
  2962. __le32 reserved2;
  2963. } __packed;
  2964. #define MWL8K_USE_AUTO_RATE 0x0002
  2965. #define MWL8K_UCAST_RATE 0
  2966. static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
  2967. {
  2968. struct mwl8k_cmd_use_fixed_rate_sta *cmd;
  2969. int rc;
  2970. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2971. if (cmd == NULL)
  2972. return -ENOMEM;
  2973. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  2974. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2975. cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
  2976. cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
  2977. rc = mwl8k_post_cmd(hw, &cmd->header);
  2978. kfree(cmd);
  2979. return rc;
  2980. }
  2981. /*
  2982. * CMD_USE_FIXED_RATE (AP version).
  2983. */
  2984. struct mwl8k_cmd_use_fixed_rate_ap {
  2985. struct mwl8k_cmd_pkt header;
  2986. __le32 action;
  2987. __le32 allow_rate_drop;
  2988. __le32 num_rates;
  2989. struct mwl8k_rate_entry_ap {
  2990. __le32 is_ht_rate;
  2991. __le32 enable_retry;
  2992. __le32 rate;
  2993. __le32 retry_count;
  2994. } rate_entry[4];
  2995. u8 multicast_rate;
  2996. u8 multicast_rate_type;
  2997. u8 management_rate;
  2998. } __packed;
  2999. static int
  3000. mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
  3001. {
  3002. struct mwl8k_cmd_use_fixed_rate_ap *cmd;
  3003. int rc;
  3004. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3005. if (cmd == NULL)
  3006. return -ENOMEM;
  3007. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  3008. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3009. cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
  3010. cmd->multicast_rate = mcast;
  3011. cmd->management_rate = mgmt;
  3012. rc = mwl8k_post_cmd(hw, &cmd->header);
  3013. kfree(cmd);
  3014. return rc;
  3015. }
  3016. /*
  3017. * CMD_ENABLE_SNIFFER.
  3018. */
  3019. struct mwl8k_cmd_enable_sniffer {
  3020. struct mwl8k_cmd_pkt header;
  3021. __le32 action;
  3022. } __packed;
  3023. static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
  3024. {
  3025. struct mwl8k_cmd_enable_sniffer *cmd;
  3026. int rc;
  3027. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3028. if (cmd == NULL)
  3029. return -ENOMEM;
  3030. cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
  3031. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3032. cmd->action = cpu_to_le32(!!enable);
  3033. rc = mwl8k_post_cmd(hw, &cmd->header);
  3034. kfree(cmd);
  3035. return rc;
  3036. }
  3037. struct mwl8k_cmd_update_mac_addr {
  3038. struct mwl8k_cmd_pkt header;
  3039. union {
  3040. struct {
  3041. __le16 mac_type;
  3042. __u8 mac_addr[ETH_ALEN];
  3043. } mbss;
  3044. __u8 mac_addr[ETH_ALEN];
  3045. };
  3046. } __packed;
  3047. #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
  3048. #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
  3049. #define MWL8K_MAC_TYPE_PRIMARY_AP 2
  3050. #define MWL8K_MAC_TYPE_SECONDARY_AP 3
  3051. static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw,
  3052. struct ieee80211_vif *vif, u8 *mac, bool set)
  3053. {
  3054. struct mwl8k_priv *priv = hw->priv;
  3055. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3056. struct mwl8k_cmd_update_mac_addr *cmd;
  3057. int mac_type;
  3058. int rc;
  3059. mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
  3060. if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
  3061. if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
  3062. if (priv->ap_fw)
  3063. mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
  3064. else
  3065. mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
  3066. else
  3067. mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
  3068. } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
  3069. if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
  3070. mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
  3071. else
  3072. mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
  3073. }
  3074. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3075. if (cmd == NULL)
  3076. return -ENOMEM;
  3077. if (set)
  3078. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
  3079. else
  3080. cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR);
  3081. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3082. if (priv->ap_fw) {
  3083. cmd->mbss.mac_type = cpu_to_le16(mac_type);
  3084. memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
  3085. } else {
  3086. memcpy(cmd->mac_addr, mac, ETH_ALEN);
  3087. }
  3088. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3089. kfree(cmd);
  3090. return rc;
  3091. }
  3092. /*
  3093. * MWL8K_CMD_SET_MAC_ADDR.
  3094. */
  3095. static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
  3096. struct ieee80211_vif *vif, u8 *mac)
  3097. {
  3098. return mwl8k_cmd_update_mac_addr(hw, vif, mac, true);
  3099. }
  3100. /*
  3101. * MWL8K_CMD_DEL_MAC_ADDR.
  3102. */
  3103. static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw,
  3104. struct ieee80211_vif *vif, u8 *mac)
  3105. {
  3106. return mwl8k_cmd_update_mac_addr(hw, vif, mac, false);
  3107. }
  3108. /*
  3109. * CMD_SET_RATEADAPT_MODE.
  3110. */
  3111. struct mwl8k_cmd_set_rate_adapt_mode {
  3112. struct mwl8k_cmd_pkt header;
  3113. __le16 action;
  3114. __le16 mode;
  3115. } __packed;
  3116. static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
  3117. {
  3118. struct mwl8k_cmd_set_rate_adapt_mode *cmd;
  3119. int rc;
  3120. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3121. if (cmd == NULL)
  3122. return -ENOMEM;
  3123. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
  3124. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3125. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  3126. cmd->mode = cpu_to_le16(mode);
  3127. rc = mwl8k_post_cmd(hw, &cmd->header);
  3128. kfree(cmd);
  3129. return rc;
  3130. }
  3131. /*
  3132. * CMD_GET_WATCHDOG_BITMAP.
  3133. */
  3134. struct mwl8k_cmd_get_watchdog_bitmap {
  3135. struct mwl8k_cmd_pkt header;
  3136. u8 bitmap;
  3137. } __packed;
  3138. static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
  3139. {
  3140. struct mwl8k_cmd_get_watchdog_bitmap *cmd;
  3141. int rc;
  3142. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3143. if (cmd == NULL)
  3144. return -ENOMEM;
  3145. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
  3146. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3147. rc = mwl8k_post_cmd(hw, &cmd->header);
  3148. if (!rc)
  3149. *bitmap = cmd->bitmap;
  3150. kfree(cmd);
  3151. return rc;
  3152. }
  3153. #define MWL8K_WMM_QUEUE_NUMBER 3
  3154. static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
  3155. u8 idx);
  3156. static void mwl8k_watchdog_ba_events(struct work_struct *work)
  3157. {
  3158. int rc;
  3159. u8 bitmap = 0, stream_index;
  3160. struct mwl8k_ampdu_stream *streams;
  3161. struct mwl8k_priv *priv =
  3162. container_of(work, struct mwl8k_priv, watchdog_ba_handle);
  3163. struct ieee80211_hw *hw = priv->hw;
  3164. int i;
  3165. u32 status = 0;
  3166. mwl8k_fw_lock(hw);
  3167. rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
  3168. if (rc)
  3169. goto done;
  3170. spin_lock(&priv->stream_lock);
  3171. /* the bitmap is the hw queue number. Map it to the ampdu queue. */
  3172. for (i = 0; i < TOTAL_HW_TX_QUEUES; i++) {
  3173. if (bitmap & (1 << i)) {
  3174. stream_index = (i + MWL8K_WMM_QUEUE_NUMBER) %
  3175. TOTAL_HW_TX_QUEUES;
  3176. streams = &priv->ampdu[stream_index];
  3177. if (streams->state == AMPDU_STREAM_ACTIVE) {
  3178. ieee80211_stop_tx_ba_session(streams->sta,
  3179. streams->tid);
  3180. spin_unlock(&priv->stream_lock);
  3181. mwl8k_destroy_ba(hw, stream_index);
  3182. spin_lock(&priv->stream_lock);
  3183. }
  3184. }
  3185. }
  3186. spin_unlock(&priv->stream_lock);
  3187. done:
  3188. atomic_dec(&priv->watchdog_event_pending);
  3189. status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3190. iowrite32((status | MWL8K_A2H_INT_BA_WATCHDOG),
  3191. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3192. mwl8k_fw_unlock(hw);
  3193. return;
  3194. }
  3195. /*
  3196. * CMD_BSS_START.
  3197. */
  3198. struct mwl8k_cmd_bss_start {
  3199. struct mwl8k_cmd_pkt header;
  3200. __le32 enable;
  3201. } __packed;
  3202. static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
  3203. struct ieee80211_vif *vif, int enable)
  3204. {
  3205. struct mwl8k_cmd_bss_start *cmd;
  3206. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3207. struct mwl8k_priv *priv = hw->priv;
  3208. int rc;
  3209. if (enable && (priv->running_bsses & (1 << mwl8k_vif->macid)))
  3210. return 0;
  3211. if (!enable && !(priv->running_bsses & (1 << mwl8k_vif->macid)))
  3212. return 0;
  3213. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3214. if (cmd == NULL)
  3215. return -ENOMEM;
  3216. cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
  3217. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3218. cmd->enable = cpu_to_le32(enable);
  3219. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3220. kfree(cmd);
  3221. if (!rc) {
  3222. if (enable)
  3223. priv->running_bsses |= (1 << mwl8k_vif->macid);
  3224. else
  3225. priv->running_bsses &= ~(1 << mwl8k_vif->macid);
  3226. }
  3227. return rc;
  3228. }
  3229. static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable, u32 bitmap)
  3230. {
  3231. struct mwl8k_priv *priv = hw->priv;
  3232. struct mwl8k_vif *mwl8k_vif, *tmp_vif;
  3233. struct ieee80211_vif *vif;
  3234. list_for_each_entry_safe(mwl8k_vif, tmp_vif, &priv->vif_list, list) {
  3235. vif = mwl8k_vif->vif;
  3236. if (!(bitmap & (1 << mwl8k_vif->macid)))
  3237. continue;
  3238. if (vif->type == NL80211_IFTYPE_AP)
  3239. mwl8k_cmd_bss_start(hw, vif, enable);
  3240. }
  3241. }
  3242. /*
  3243. * CMD_BASTREAM.
  3244. */
  3245. /*
  3246. * UPSTREAM is tx direction
  3247. */
  3248. #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
  3249. #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
  3250. enum ba_stream_action_type {
  3251. MWL8K_BA_CREATE,
  3252. MWL8K_BA_UPDATE,
  3253. MWL8K_BA_DESTROY,
  3254. MWL8K_BA_FLUSH,
  3255. MWL8K_BA_CHECK,
  3256. };
  3257. struct mwl8k_create_ba_stream {
  3258. __le32 flags;
  3259. __le32 idle_thrs;
  3260. __le32 bar_thrs;
  3261. __le32 window_size;
  3262. u8 peer_mac_addr[6];
  3263. u8 dialog_token;
  3264. u8 tid;
  3265. u8 queue_id;
  3266. u8 param_info;
  3267. __le32 ba_context;
  3268. u8 reset_seq_no_flag;
  3269. __le16 curr_seq_no;
  3270. u8 sta_src_mac_addr[6];
  3271. } __packed;
  3272. struct mwl8k_destroy_ba_stream {
  3273. __le32 flags;
  3274. __le32 ba_context;
  3275. } __packed;
  3276. struct mwl8k_cmd_bastream {
  3277. struct mwl8k_cmd_pkt header;
  3278. __le32 action;
  3279. union {
  3280. struct mwl8k_create_ba_stream create_params;
  3281. struct mwl8k_destroy_ba_stream destroy_params;
  3282. };
  3283. } __packed;
  3284. static int
  3285. mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
  3286. struct ieee80211_vif *vif)
  3287. {
  3288. struct mwl8k_cmd_bastream *cmd;
  3289. int rc;
  3290. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3291. if (cmd == NULL)
  3292. return -ENOMEM;
  3293. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3294. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3295. cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
  3296. cmd->create_params.queue_id = stream->idx;
  3297. memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
  3298. ETH_ALEN);
  3299. cmd->create_params.tid = stream->tid;
  3300. cmd->create_params.flags =
  3301. cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
  3302. cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
  3303. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3304. kfree(cmd);
  3305. return rc;
  3306. }
  3307. static int
  3308. mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
  3309. u8 buf_size, struct ieee80211_vif *vif)
  3310. {
  3311. struct mwl8k_cmd_bastream *cmd;
  3312. int rc;
  3313. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3314. if (cmd == NULL)
  3315. return -ENOMEM;
  3316. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3317. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3318. cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
  3319. cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
  3320. cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
  3321. cmd->create_params.queue_id = stream->idx;
  3322. memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
  3323. cmd->create_params.tid = stream->tid;
  3324. cmd->create_params.curr_seq_no = cpu_to_le16(0);
  3325. cmd->create_params.reset_seq_no_flag = 1;
  3326. cmd->create_params.param_info =
  3327. (stream->sta->ht_cap.ampdu_factor &
  3328. IEEE80211_HT_AMPDU_PARM_FACTOR) |
  3329. ((stream->sta->ht_cap.ampdu_density << 2) &
  3330. IEEE80211_HT_AMPDU_PARM_DENSITY);
  3331. cmd->create_params.flags =
  3332. cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
  3333. BASTREAM_FLAG_DIRECTION_UPSTREAM);
  3334. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3335. wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
  3336. stream->sta->addr, stream->tid);
  3337. kfree(cmd);
  3338. return rc;
  3339. }
  3340. static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
  3341. u8 idx)
  3342. {
  3343. struct mwl8k_cmd_bastream *cmd;
  3344. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3345. if (cmd == NULL)
  3346. return;
  3347. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3348. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3349. cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
  3350. cmd->destroy_params.ba_context = cpu_to_le32(idx);
  3351. mwl8k_post_cmd(hw, &cmd->header);
  3352. wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", idx);
  3353. kfree(cmd);
  3354. }
  3355. /*
  3356. * CMD_SET_NEW_STN.
  3357. */
  3358. struct mwl8k_cmd_set_new_stn {
  3359. struct mwl8k_cmd_pkt header;
  3360. __le16 aid;
  3361. __u8 mac_addr[6];
  3362. __le16 stn_id;
  3363. __le16 action;
  3364. __le16 rsvd;
  3365. __le32 legacy_rates;
  3366. __u8 ht_rates[4];
  3367. __le16 cap_info;
  3368. __le16 ht_capabilities_info;
  3369. __u8 mac_ht_param_info;
  3370. __u8 rev;
  3371. __u8 control_channel;
  3372. __u8 add_channel;
  3373. __le16 op_mode;
  3374. __le16 stbc;
  3375. __u8 add_qos_info;
  3376. __u8 is_qos_sta;
  3377. __le32 fw_sta_ptr;
  3378. } __packed;
  3379. #define MWL8K_STA_ACTION_ADD 0
  3380. #define MWL8K_STA_ACTION_REMOVE 2
  3381. static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
  3382. struct ieee80211_vif *vif,
  3383. struct ieee80211_sta *sta)
  3384. {
  3385. struct mwl8k_cmd_set_new_stn *cmd;
  3386. u32 rates;
  3387. int rc;
  3388. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3389. if (cmd == NULL)
  3390. return -ENOMEM;
  3391. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3392. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3393. cmd->aid = cpu_to_le16(sta->aid);
  3394. memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
  3395. cmd->stn_id = cpu_to_le16(sta->aid);
  3396. cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
  3397. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  3398. rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
  3399. else
  3400. rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  3401. cmd->legacy_rates = cpu_to_le32(rates);
  3402. if (sta->ht_cap.ht_supported) {
  3403. cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
  3404. cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
  3405. cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
  3406. cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
  3407. cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
  3408. cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
  3409. ((sta->ht_cap.ampdu_density & 7) << 2);
  3410. cmd->is_qos_sta = 1;
  3411. }
  3412. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3413. kfree(cmd);
  3414. return rc;
  3415. }
  3416. static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
  3417. struct ieee80211_vif *vif)
  3418. {
  3419. struct mwl8k_cmd_set_new_stn *cmd;
  3420. int rc;
  3421. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3422. if (cmd == NULL)
  3423. return -ENOMEM;
  3424. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3425. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3426. memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
  3427. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3428. kfree(cmd);
  3429. return rc;
  3430. }
  3431. static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
  3432. struct ieee80211_vif *vif, u8 *addr)
  3433. {
  3434. struct mwl8k_cmd_set_new_stn *cmd;
  3435. struct mwl8k_priv *priv = hw->priv;
  3436. int rc, i;
  3437. u8 idx;
  3438. spin_lock(&priv->stream_lock);
  3439. /* Destroy any active ampdu streams for this sta */
  3440. for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
  3441. struct mwl8k_ampdu_stream *s;
  3442. s = &priv->ampdu[i];
  3443. if (s->state != AMPDU_NO_STREAM) {
  3444. if (memcmp(s->sta->addr, addr, ETH_ALEN) == 0) {
  3445. if (s->state == AMPDU_STREAM_ACTIVE) {
  3446. idx = s->idx;
  3447. spin_unlock(&priv->stream_lock);
  3448. mwl8k_destroy_ba(hw, idx);
  3449. spin_lock(&priv->stream_lock);
  3450. } else if (s->state == AMPDU_STREAM_NEW) {
  3451. mwl8k_remove_stream(hw, s);
  3452. }
  3453. }
  3454. }
  3455. }
  3456. spin_unlock(&priv->stream_lock);
  3457. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3458. if (cmd == NULL)
  3459. return -ENOMEM;
  3460. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3461. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3462. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3463. cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
  3464. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3465. kfree(cmd);
  3466. return rc;
  3467. }
  3468. /*
  3469. * CMD_UPDATE_ENCRYPTION.
  3470. */
  3471. #define MAX_ENCR_KEY_LENGTH 16
  3472. #define MIC_KEY_LENGTH 8
  3473. struct mwl8k_cmd_update_encryption {
  3474. struct mwl8k_cmd_pkt header;
  3475. __le32 action;
  3476. __le32 reserved;
  3477. __u8 mac_addr[6];
  3478. __u8 encr_type;
  3479. } __packed;
  3480. struct mwl8k_cmd_set_key {
  3481. struct mwl8k_cmd_pkt header;
  3482. __le32 action;
  3483. __le32 reserved;
  3484. __le16 length;
  3485. __le16 key_type_id;
  3486. __le32 key_info;
  3487. __le32 key_id;
  3488. __le16 key_len;
  3489. __u8 key_material[MAX_ENCR_KEY_LENGTH];
  3490. __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
  3491. __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
  3492. __le16 tkip_rsc_low;
  3493. __le32 tkip_rsc_high;
  3494. __le16 tkip_tsc_low;
  3495. __le32 tkip_tsc_high;
  3496. __u8 mac_addr[6];
  3497. } __packed;
  3498. enum {
  3499. MWL8K_ENCR_ENABLE,
  3500. MWL8K_ENCR_SET_KEY,
  3501. MWL8K_ENCR_REMOVE_KEY,
  3502. MWL8K_ENCR_SET_GROUP_KEY,
  3503. };
  3504. #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
  3505. #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
  3506. #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
  3507. #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
  3508. #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
  3509. enum {
  3510. MWL8K_ALG_WEP,
  3511. MWL8K_ALG_TKIP,
  3512. MWL8K_ALG_CCMP,
  3513. };
  3514. #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
  3515. #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
  3516. #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
  3517. #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
  3518. #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
  3519. static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
  3520. struct ieee80211_vif *vif,
  3521. u8 *addr,
  3522. u8 encr_type)
  3523. {
  3524. struct mwl8k_cmd_update_encryption *cmd;
  3525. int rc;
  3526. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3527. if (cmd == NULL)
  3528. return -ENOMEM;
  3529. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
  3530. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3531. cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
  3532. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3533. cmd->encr_type = encr_type;
  3534. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3535. kfree(cmd);
  3536. return rc;
  3537. }
  3538. static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
  3539. u8 *addr,
  3540. struct ieee80211_key_conf *key)
  3541. {
  3542. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
  3543. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3544. cmd->length = cpu_to_le16(sizeof(*cmd) -
  3545. offsetof(struct mwl8k_cmd_set_key, length));
  3546. cmd->key_id = cpu_to_le32(key->keyidx);
  3547. cmd->key_len = cpu_to_le16(key->keylen);
  3548. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3549. switch (key->cipher) {
  3550. case WLAN_CIPHER_SUITE_WEP40:
  3551. case WLAN_CIPHER_SUITE_WEP104:
  3552. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
  3553. if (key->keyidx == 0)
  3554. cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
  3555. break;
  3556. case WLAN_CIPHER_SUITE_TKIP:
  3557. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
  3558. cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3559. ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
  3560. : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
  3561. cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
  3562. | MWL8K_KEY_FLAG_TSC_VALID);
  3563. break;
  3564. case WLAN_CIPHER_SUITE_CCMP:
  3565. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
  3566. cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3567. ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
  3568. : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
  3569. break;
  3570. default:
  3571. return -ENOTSUPP;
  3572. }
  3573. return 0;
  3574. }
  3575. static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
  3576. struct ieee80211_vif *vif,
  3577. u8 *addr,
  3578. struct ieee80211_key_conf *key)
  3579. {
  3580. struct mwl8k_cmd_set_key *cmd;
  3581. int rc;
  3582. int keymlen;
  3583. u32 action;
  3584. u8 idx;
  3585. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3586. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3587. if (cmd == NULL)
  3588. return -ENOMEM;
  3589. rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
  3590. if (rc < 0)
  3591. goto done;
  3592. idx = key->keyidx;
  3593. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3594. action = MWL8K_ENCR_SET_KEY;
  3595. else
  3596. action = MWL8K_ENCR_SET_GROUP_KEY;
  3597. switch (key->cipher) {
  3598. case WLAN_CIPHER_SUITE_WEP40:
  3599. case WLAN_CIPHER_SUITE_WEP104:
  3600. if (!mwl8k_vif->wep_key_conf[idx].enabled) {
  3601. memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
  3602. sizeof(*key) + key->keylen);
  3603. mwl8k_vif->wep_key_conf[idx].enabled = 1;
  3604. }
  3605. keymlen = key->keylen;
  3606. action = MWL8K_ENCR_SET_KEY;
  3607. break;
  3608. case WLAN_CIPHER_SUITE_TKIP:
  3609. keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
  3610. break;
  3611. case WLAN_CIPHER_SUITE_CCMP:
  3612. keymlen = key->keylen;
  3613. break;
  3614. default:
  3615. rc = -ENOTSUPP;
  3616. goto done;
  3617. }
  3618. memcpy(cmd->key_material, key->key, keymlen);
  3619. cmd->action = cpu_to_le32(action);
  3620. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3621. done:
  3622. kfree(cmd);
  3623. return rc;
  3624. }
  3625. static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
  3626. struct ieee80211_vif *vif,
  3627. u8 *addr,
  3628. struct ieee80211_key_conf *key)
  3629. {
  3630. struct mwl8k_cmd_set_key *cmd;
  3631. int rc;
  3632. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3633. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3634. if (cmd == NULL)
  3635. return -ENOMEM;
  3636. rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
  3637. if (rc < 0)
  3638. goto done;
  3639. if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  3640. key->cipher == WLAN_CIPHER_SUITE_WEP104)
  3641. mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
  3642. cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
  3643. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3644. done:
  3645. kfree(cmd);
  3646. return rc;
  3647. }
  3648. static int mwl8k_set_key(struct ieee80211_hw *hw,
  3649. enum set_key_cmd cmd_param,
  3650. struct ieee80211_vif *vif,
  3651. struct ieee80211_sta *sta,
  3652. struct ieee80211_key_conf *key)
  3653. {
  3654. int rc = 0;
  3655. u8 encr_type;
  3656. u8 *addr;
  3657. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3658. struct mwl8k_priv *priv = hw->priv;
  3659. if (vif->type == NL80211_IFTYPE_STATION && !priv->ap_fw)
  3660. return -EOPNOTSUPP;
  3661. if (sta == NULL)
  3662. addr = vif->addr;
  3663. else
  3664. addr = sta->addr;
  3665. if (cmd_param == SET_KEY) {
  3666. rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
  3667. if (rc)
  3668. goto out;
  3669. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
  3670. || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
  3671. encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
  3672. else
  3673. encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
  3674. rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
  3675. encr_type);
  3676. if (rc)
  3677. goto out;
  3678. mwl8k_vif->is_hw_crypto_enabled = true;
  3679. } else {
  3680. rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
  3681. if (rc)
  3682. goto out;
  3683. }
  3684. out:
  3685. return rc;
  3686. }
  3687. /*
  3688. * CMD_UPDATE_STADB.
  3689. */
  3690. struct ewc_ht_info {
  3691. __le16 control1;
  3692. __le16 control2;
  3693. __le16 control3;
  3694. } __packed;
  3695. struct peer_capability_info {
  3696. /* Peer type - AP vs. STA. */
  3697. __u8 peer_type;
  3698. /* Basic 802.11 capabilities from assoc resp. */
  3699. __le16 basic_caps;
  3700. /* Set if peer supports 802.11n high throughput (HT). */
  3701. __u8 ht_support;
  3702. /* Valid if HT is supported. */
  3703. __le16 ht_caps;
  3704. __u8 extended_ht_caps;
  3705. struct ewc_ht_info ewc_info;
  3706. /* Legacy rate table. Intersection of our rates and peer rates. */
  3707. __u8 legacy_rates[12];
  3708. /* HT rate table. Intersection of our rates and peer rates. */
  3709. __u8 ht_rates[16];
  3710. __u8 pad[16];
  3711. /* If set, interoperability mode, no proprietary extensions. */
  3712. __u8 interop;
  3713. __u8 pad2;
  3714. __u8 station_id;
  3715. __le16 amsdu_enabled;
  3716. } __packed;
  3717. struct mwl8k_cmd_update_stadb {
  3718. struct mwl8k_cmd_pkt header;
  3719. /* See STADB_ACTION_TYPE */
  3720. __le32 action;
  3721. /* Peer MAC address */
  3722. __u8 peer_addr[ETH_ALEN];
  3723. __le32 reserved;
  3724. /* Peer info - valid during add/update. */
  3725. struct peer_capability_info peer_info;
  3726. } __packed;
  3727. #define MWL8K_STA_DB_MODIFY_ENTRY 1
  3728. #define MWL8K_STA_DB_DEL_ENTRY 2
  3729. /* Peer Entry flags - used to define the type of the peer node */
  3730. #define MWL8K_PEER_TYPE_ACCESSPOINT 2
  3731. static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
  3732. struct ieee80211_vif *vif,
  3733. struct ieee80211_sta *sta)
  3734. {
  3735. struct mwl8k_cmd_update_stadb *cmd;
  3736. struct peer_capability_info *p;
  3737. u32 rates;
  3738. int rc;
  3739. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3740. if (cmd == NULL)
  3741. return -ENOMEM;
  3742. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  3743. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3744. cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
  3745. memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
  3746. p = &cmd->peer_info;
  3747. p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
  3748. p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
  3749. p->ht_support = sta->ht_cap.ht_supported;
  3750. p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
  3751. p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
  3752. ((sta->ht_cap.ampdu_density & 7) << 2);
  3753. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  3754. rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
  3755. else
  3756. rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  3757. legacy_rate_mask_to_array(p->legacy_rates, rates);
  3758. memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
  3759. p->interop = 1;
  3760. p->amsdu_enabled = 0;
  3761. rc = mwl8k_post_cmd(hw, &cmd->header);
  3762. if (!rc)
  3763. rc = p->station_id;
  3764. kfree(cmd);
  3765. return rc;
  3766. }
  3767. static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
  3768. struct ieee80211_vif *vif, u8 *addr)
  3769. {
  3770. struct mwl8k_cmd_update_stadb *cmd;
  3771. int rc;
  3772. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3773. if (cmd == NULL)
  3774. return -ENOMEM;
  3775. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  3776. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3777. cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
  3778. memcpy(cmd->peer_addr, addr, ETH_ALEN);
  3779. rc = mwl8k_post_cmd(hw, &cmd->header);
  3780. kfree(cmd);
  3781. return rc;
  3782. }
  3783. /*
  3784. * Interrupt handling.
  3785. */
  3786. static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
  3787. {
  3788. struct ieee80211_hw *hw = dev_id;
  3789. struct mwl8k_priv *priv = hw->priv;
  3790. u32 status;
  3791. status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3792. if (!status)
  3793. return IRQ_NONE;
  3794. if (status & MWL8K_A2H_INT_TX_DONE) {
  3795. status &= ~MWL8K_A2H_INT_TX_DONE;
  3796. tasklet_schedule(&priv->poll_tx_task);
  3797. }
  3798. if (status & MWL8K_A2H_INT_RX_READY) {
  3799. status &= ~MWL8K_A2H_INT_RX_READY;
  3800. tasklet_schedule(&priv->poll_rx_task);
  3801. }
  3802. if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
  3803. iowrite32(~MWL8K_A2H_INT_BA_WATCHDOG,
  3804. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3805. atomic_inc(&priv->watchdog_event_pending);
  3806. status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
  3807. ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
  3808. }
  3809. if (status)
  3810. iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3811. if (status & MWL8K_A2H_INT_OPC_DONE) {
  3812. if (priv->hostcmd_wait != NULL)
  3813. complete(priv->hostcmd_wait);
  3814. }
  3815. if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
  3816. if (!mutex_is_locked(&priv->fw_mutex) &&
  3817. priv->radio_on && priv->pending_tx_pkts)
  3818. mwl8k_tx_start(priv);
  3819. }
  3820. return IRQ_HANDLED;
  3821. }
  3822. static void mwl8k_tx_poll(unsigned long data)
  3823. {
  3824. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  3825. struct mwl8k_priv *priv = hw->priv;
  3826. int limit;
  3827. int i;
  3828. limit = 32;
  3829. spin_lock_bh(&priv->tx_lock);
  3830. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  3831. limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
  3832. if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
  3833. complete(priv->tx_wait);
  3834. priv->tx_wait = NULL;
  3835. }
  3836. spin_unlock_bh(&priv->tx_lock);
  3837. if (limit) {
  3838. writel(~MWL8K_A2H_INT_TX_DONE,
  3839. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3840. } else {
  3841. tasklet_schedule(&priv->poll_tx_task);
  3842. }
  3843. }
  3844. static void mwl8k_rx_poll(unsigned long data)
  3845. {
  3846. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  3847. struct mwl8k_priv *priv = hw->priv;
  3848. int limit;
  3849. limit = 32;
  3850. limit -= rxq_process(hw, 0, limit);
  3851. limit -= rxq_refill(hw, 0, limit);
  3852. if (limit) {
  3853. writel(~MWL8K_A2H_INT_RX_READY,
  3854. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3855. } else {
  3856. tasklet_schedule(&priv->poll_rx_task);
  3857. }
  3858. }
  3859. /*
  3860. * Core driver operations.
  3861. */
  3862. static void mwl8k_tx(struct ieee80211_hw *hw,
  3863. struct ieee80211_tx_control *control,
  3864. struct sk_buff *skb)
  3865. {
  3866. struct mwl8k_priv *priv = hw->priv;
  3867. int index = skb_get_queue_mapping(skb);
  3868. if (!priv->radio_on) {
  3869. wiphy_debug(hw->wiphy,
  3870. "dropped TX frame since radio disabled\n");
  3871. dev_kfree_skb(skb);
  3872. return;
  3873. }
  3874. mwl8k_txq_xmit(hw, index, control->sta, skb);
  3875. }
  3876. static int mwl8k_start(struct ieee80211_hw *hw)
  3877. {
  3878. struct mwl8k_priv *priv = hw->priv;
  3879. int rc;
  3880. rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
  3881. IRQF_SHARED, MWL8K_NAME, hw);
  3882. if (rc) {
  3883. priv->irq = -1;
  3884. wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
  3885. return -EIO;
  3886. }
  3887. priv->irq = priv->pdev->irq;
  3888. /* Enable TX reclaim and RX tasklets. */
  3889. tasklet_enable(&priv->poll_tx_task);
  3890. tasklet_enable(&priv->poll_rx_task);
  3891. /* Enable interrupts */
  3892. iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3893. iowrite32(MWL8K_A2H_EVENTS,
  3894. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3895. rc = mwl8k_fw_lock(hw);
  3896. if (!rc) {
  3897. rc = mwl8k_cmd_radio_enable(hw);
  3898. if (!priv->ap_fw) {
  3899. if (!rc)
  3900. rc = mwl8k_cmd_enable_sniffer(hw, 0);
  3901. if (!rc)
  3902. rc = mwl8k_cmd_set_pre_scan(hw);
  3903. if (!rc)
  3904. rc = mwl8k_cmd_set_post_scan(hw,
  3905. "\x00\x00\x00\x00\x00\x00");
  3906. }
  3907. if (!rc)
  3908. rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
  3909. if (!rc)
  3910. rc = mwl8k_cmd_set_wmm_mode(hw, 0);
  3911. mwl8k_fw_unlock(hw);
  3912. }
  3913. if (rc) {
  3914. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3915. free_irq(priv->pdev->irq, hw);
  3916. priv->irq = -1;
  3917. tasklet_disable(&priv->poll_tx_task);
  3918. tasklet_disable(&priv->poll_rx_task);
  3919. } else {
  3920. ieee80211_wake_queues(hw);
  3921. }
  3922. return rc;
  3923. }
  3924. static void mwl8k_stop(struct ieee80211_hw *hw)
  3925. {
  3926. struct mwl8k_priv *priv = hw->priv;
  3927. int i;
  3928. if (!priv->hw_restart_in_progress)
  3929. mwl8k_cmd_radio_disable(hw);
  3930. ieee80211_stop_queues(hw);
  3931. /* Disable interrupts */
  3932. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3933. if (priv->irq != -1) {
  3934. free_irq(priv->pdev->irq, hw);
  3935. priv->irq = -1;
  3936. }
  3937. /* Stop finalize join worker */
  3938. cancel_work_sync(&priv->finalize_join_worker);
  3939. cancel_work_sync(&priv->watchdog_ba_handle);
  3940. if (priv->beacon_skb != NULL)
  3941. dev_kfree_skb(priv->beacon_skb);
  3942. /* Stop TX reclaim and RX tasklets. */
  3943. tasklet_disable(&priv->poll_tx_task);
  3944. tasklet_disable(&priv->poll_rx_task);
  3945. /* Return all skbs to mac80211 */
  3946. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  3947. mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  3948. }
  3949. static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
  3950. static int mwl8k_add_interface(struct ieee80211_hw *hw,
  3951. struct ieee80211_vif *vif)
  3952. {
  3953. struct mwl8k_priv *priv = hw->priv;
  3954. struct mwl8k_vif *mwl8k_vif;
  3955. u32 macids_supported;
  3956. int macid, rc;
  3957. struct mwl8k_device_info *di;
  3958. /*
  3959. * Reject interface creation if sniffer mode is active, as
  3960. * STA operation is mutually exclusive with hardware sniffer
  3961. * mode. (Sniffer mode is only used on STA firmware.)
  3962. */
  3963. if (priv->sniffer_enabled) {
  3964. wiphy_info(hw->wiphy,
  3965. "unable to create STA interface because sniffer mode is enabled\n");
  3966. return -EINVAL;
  3967. }
  3968. di = priv->device_info;
  3969. switch (vif->type) {
  3970. case NL80211_IFTYPE_AP:
  3971. if (!priv->ap_fw && di->fw_image_ap) {
  3972. /* we must load the ap fw to meet this request */
  3973. if (!list_empty(&priv->vif_list))
  3974. return -EBUSY;
  3975. rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
  3976. if (rc)
  3977. return rc;
  3978. }
  3979. macids_supported = priv->ap_macids_supported;
  3980. break;
  3981. case NL80211_IFTYPE_STATION:
  3982. if (priv->ap_fw && di->fw_image_sta) {
  3983. if (!list_empty(&priv->vif_list)) {
  3984. wiphy_warn(hw->wiphy, "AP interface is running.\n"
  3985. "Adding STA interface for WDS");
  3986. } else {
  3987. /* we must load the sta fw to
  3988. * meet this request.
  3989. */
  3990. rc = mwl8k_reload_firmware(hw,
  3991. di->fw_image_sta);
  3992. if (rc)
  3993. return rc;
  3994. }
  3995. }
  3996. macids_supported = priv->sta_macids_supported;
  3997. break;
  3998. default:
  3999. return -EINVAL;
  4000. }
  4001. macid = ffs(macids_supported & ~priv->macids_used);
  4002. if (!macid--)
  4003. return -EBUSY;
  4004. /* Setup driver private area. */
  4005. mwl8k_vif = MWL8K_VIF(vif);
  4006. memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
  4007. mwl8k_vif->vif = vif;
  4008. mwl8k_vif->macid = macid;
  4009. mwl8k_vif->seqno = 0;
  4010. memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
  4011. mwl8k_vif->is_hw_crypto_enabled = false;
  4012. /* Set the mac address. */
  4013. mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
  4014. if (vif->type == NL80211_IFTYPE_AP)
  4015. mwl8k_cmd_set_new_stn_add_self(hw, vif);
  4016. priv->macids_used |= 1 << mwl8k_vif->macid;
  4017. list_add_tail(&mwl8k_vif->list, &priv->vif_list);
  4018. return 0;
  4019. }
  4020. static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif)
  4021. {
  4022. /* Has ieee80211_restart_hw re-added the removed interfaces? */
  4023. if (!priv->macids_used)
  4024. return;
  4025. priv->macids_used &= ~(1 << vif->macid);
  4026. list_del(&vif->list);
  4027. }
  4028. static void mwl8k_remove_interface(struct ieee80211_hw *hw,
  4029. struct ieee80211_vif *vif)
  4030. {
  4031. struct mwl8k_priv *priv = hw->priv;
  4032. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  4033. if (vif->type == NL80211_IFTYPE_AP)
  4034. mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
  4035. mwl8k_cmd_del_mac_addr(hw, vif, vif->addr);
  4036. mwl8k_remove_vif(priv, mwl8k_vif);
  4037. }
  4038. static void mwl8k_hw_restart_work(struct work_struct *work)
  4039. {
  4040. struct mwl8k_priv *priv =
  4041. container_of(work, struct mwl8k_priv, fw_reload);
  4042. struct ieee80211_hw *hw = priv->hw;
  4043. struct mwl8k_device_info *di;
  4044. int rc;
  4045. /* If some command is waiting for a response, clear it */
  4046. if (priv->hostcmd_wait != NULL) {
  4047. complete(priv->hostcmd_wait);
  4048. priv->hostcmd_wait = NULL;
  4049. }
  4050. priv->hw_restart_owner = current;
  4051. di = priv->device_info;
  4052. mwl8k_fw_lock(hw);
  4053. if (priv->ap_fw)
  4054. rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
  4055. else
  4056. rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
  4057. if (rc)
  4058. goto fail;
  4059. priv->hw_restart_owner = NULL;
  4060. priv->hw_restart_in_progress = false;
  4061. /*
  4062. * This unlock will wake up the queues and
  4063. * also opens the command path for other
  4064. * commands
  4065. */
  4066. mwl8k_fw_unlock(hw);
  4067. ieee80211_restart_hw(hw);
  4068. wiphy_err(hw->wiphy, "Firmware restarted successfully\n");
  4069. return;
  4070. fail:
  4071. mwl8k_fw_unlock(hw);
  4072. wiphy_err(hw->wiphy, "Firmware restart failed\n");
  4073. }
  4074. static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
  4075. {
  4076. struct ieee80211_conf *conf = &hw->conf;
  4077. struct mwl8k_priv *priv = hw->priv;
  4078. int rc;
  4079. rc = mwl8k_fw_lock(hw);
  4080. if (rc)
  4081. return rc;
  4082. if (conf->flags & IEEE80211_CONF_IDLE)
  4083. rc = mwl8k_cmd_radio_disable(hw);
  4084. else
  4085. rc = mwl8k_cmd_radio_enable(hw);
  4086. if (rc)
  4087. goto out;
  4088. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  4089. rc = mwl8k_cmd_set_rf_channel(hw, conf);
  4090. if (rc)
  4091. goto out;
  4092. }
  4093. if (conf->power_level > 18)
  4094. conf->power_level = 18;
  4095. if (priv->ap_fw) {
  4096. if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
  4097. rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
  4098. if (rc)
  4099. goto out;
  4100. }
  4101. } else {
  4102. rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
  4103. if (rc)
  4104. goto out;
  4105. rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
  4106. }
  4107. out:
  4108. mwl8k_fw_unlock(hw);
  4109. return rc;
  4110. }
  4111. static void
  4112. mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4113. struct ieee80211_bss_conf *info, u32 changed)
  4114. {
  4115. struct mwl8k_priv *priv = hw->priv;
  4116. u32 ap_legacy_rates = 0;
  4117. u8 ap_mcs_rates[16];
  4118. int rc;
  4119. if (mwl8k_fw_lock(hw))
  4120. return;
  4121. /*
  4122. * No need to capture a beacon if we're no longer associated.
  4123. */
  4124. if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
  4125. priv->capture_beacon = false;
  4126. /*
  4127. * Get the AP's legacy and MCS rates.
  4128. */
  4129. if (vif->bss_conf.assoc) {
  4130. struct ieee80211_sta *ap;
  4131. rcu_read_lock();
  4132. ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
  4133. if (ap == NULL) {
  4134. rcu_read_unlock();
  4135. goto out;
  4136. }
  4137. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) {
  4138. ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
  4139. } else {
  4140. ap_legacy_rates =
  4141. ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  4142. }
  4143. memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
  4144. rcu_read_unlock();
  4145. }
  4146. if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc &&
  4147. !priv->ap_fw) {
  4148. rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
  4149. if (rc)
  4150. goto out;
  4151. rc = mwl8k_cmd_use_fixed_rate_sta(hw);
  4152. if (rc)
  4153. goto out;
  4154. } else {
  4155. if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc &&
  4156. priv->ap_fw) {
  4157. int idx;
  4158. int rate;
  4159. /* Use AP firmware specific rate command.
  4160. */
  4161. idx = ffs(vif->bss_conf.basic_rates);
  4162. if (idx)
  4163. idx--;
  4164. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  4165. rate = mwl8k_rates_24[idx].hw_value;
  4166. else
  4167. rate = mwl8k_rates_50[idx].hw_value;
  4168. mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
  4169. }
  4170. }
  4171. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  4172. rc = mwl8k_set_radio_preamble(hw,
  4173. vif->bss_conf.use_short_preamble);
  4174. if (rc)
  4175. goto out;
  4176. }
  4177. if ((changed & BSS_CHANGED_ERP_SLOT) && !priv->ap_fw) {
  4178. rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
  4179. if (rc)
  4180. goto out;
  4181. }
  4182. if (vif->bss_conf.assoc && !priv->ap_fw &&
  4183. (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
  4184. BSS_CHANGED_HT))) {
  4185. rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
  4186. if (rc)
  4187. goto out;
  4188. }
  4189. if (vif->bss_conf.assoc &&
  4190. (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
  4191. /*
  4192. * Finalize the join. Tell rx handler to process
  4193. * next beacon from our BSSID.
  4194. */
  4195. memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
  4196. priv->capture_beacon = true;
  4197. }
  4198. out:
  4199. mwl8k_fw_unlock(hw);
  4200. }
  4201. static void
  4202. mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4203. struct ieee80211_bss_conf *info, u32 changed)
  4204. {
  4205. int rc;
  4206. if (mwl8k_fw_lock(hw))
  4207. return;
  4208. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  4209. rc = mwl8k_set_radio_preamble(hw,
  4210. vif->bss_conf.use_short_preamble);
  4211. if (rc)
  4212. goto out;
  4213. }
  4214. if (changed & BSS_CHANGED_BASIC_RATES) {
  4215. int idx;
  4216. int rate;
  4217. /*
  4218. * Use lowest supported basic rate for multicasts
  4219. * and management frames (such as probe responses --
  4220. * beacons will always go out at 1 Mb/s).
  4221. */
  4222. idx = ffs(vif->bss_conf.basic_rates);
  4223. if (idx)
  4224. idx--;
  4225. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  4226. rate = mwl8k_rates_24[idx].hw_value;
  4227. else
  4228. rate = mwl8k_rates_50[idx].hw_value;
  4229. mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
  4230. }
  4231. if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
  4232. struct sk_buff *skb;
  4233. skb = ieee80211_beacon_get(hw, vif);
  4234. if (skb != NULL) {
  4235. mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
  4236. kfree_skb(skb);
  4237. }
  4238. }
  4239. if (changed & BSS_CHANGED_BEACON_ENABLED)
  4240. mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
  4241. out:
  4242. mwl8k_fw_unlock(hw);
  4243. }
  4244. static void
  4245. mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4246. struct ieee80211_bss_conf *info, u32 changed)
  4247. {
  4248. if (vif->type == NL80211_IFTYPE_STATION)
  4249. mwl8k_bss_info_changed_sta(hw, vif, info, changed);
  4250. if (vif->type == NL80211_IFTYPE_AP)
  4251. mwl8k_bss_info_changed_ap(hw, vif, info, changed);
  4252. }
  4253. static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
  4254. struct netdev_hw_addr_list *mc_list)
  4255. {
  4256. struct mwl8k_cmd_pkt *cmd;
  4257. /*
  4258. * Synthesize and return a command packet that programs the
  4259. * hardware multicast address filter. At this point we don't
  4260. * know whether FIF_ALLMULTI is being requested, but if it is,
  4261. * we'll end up throwing this packet away and creating a new
  4262. * one in mwl8k_configure_filter().
  4263. */
  4264. cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
  4265. return (unsigned long)cmd;
  4266. }
  4267. static int
  4268. mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
  4269. unsigned int changed_flags,
  4270. unsigned int *total_flags)
  4271. {
  4272. struct mwl8k_priv *priv = hw->priv;
  4273. /*
  4274. * Hardware sniffer mode is mutually exclusive with STA
  4275. * operation, so refuse to enable sniffer mode if a STA
  4276. * interface is active.
  4277. */
  4278. if (!list_empty(&priv->vif_list)) {
  4279. if (net_ratelimit())
  4280. wiphy_info(hw->wiphy,
  4281. "not enabling sniffer mode because STA interface is active\n");
  4282. return 0;
  4283. }
  4284. if (!priv->sniffer_enabled) {
  4285. if (mwl8k_cmd_enable_sniffer(hw, 1))
  4286. return 0;
  4287. priv->sniffer_enabled = true;
  4288. }
  4289. *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
  4290. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
  4291. FIF_OTHER_BSS;
  4292. return 1;
  4293. }
  4294. static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
  4295. {
  4296. if (!list_empty(&priv->vif_list))
  4297. return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
  4298. return NULL;
  4299. }
  4300. static void mwl8k_configure_filter(struct ieee80211_hw *hw,
  4301. unsigned int changed_flags,
  4302. unsigned int *total_flags,
  4303. u64 multicast)
  4304. {
  4305. struct mwl8k_priv *priv = hw->priv;
  4306. struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
  4307. /*
  4308. * AP firmware doesn't allow fine-grained control over
  4309. * the receive filter.
  4310. */
  4311. if (priv->ap_fw) {
  4312. *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
  4313. kfree(cmd);
  4314. return;
  4315. }
  4316. /*
  4317. * Enable hardware sniffer mode if FIF_CONTROL or
  4318. * FIF_OTHER_BSS is requested.
  4319. */
  4320. if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
  4321. mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
  4322. kfree(cmd);
  4323. return;
  4324. }
  4325. /* Clear unsupported feature flags */
  4326. *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
  4327. if (mwl8k_fw_lock(hw)) {
  4328. kfree(cmd);
  4329. return;
  4330. }
  4331. if (priv->sniffer_enabled) {
  4332. mwl8k_cmd_enable_sniffer(hw, 0);
  4333. priv->sniffer_enabled = false;
  4334. }
  4335. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  4336. if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
  4337. /*
  4338. * Disable the BSS filter.
  4339. */
  4340. mwl8k_cmd_set_pre_scan(hw);
  4341. } else {
  4342. struct mwl8k_vif *mwl8k_vif;
  4343. const u8 *bssid;
  4344. /*
  4345. * Enable the BSS filter.
  4346. *
  4347. * If there is an active STA interface, use that
  4348. * interface's BSSID, otherwise use a dummy one
  4349. * (where the OUI part needs to be nonzero for
  4350. * the BSSID to be accepted by POST_SCAN).
  4351. */
  4352. mwl8k_vif = mwl8k_first_vif(priv);
  4353. if (mwl8k_vif != NULL)
  4354. bssid = mwl8k_vif->vif->bss_conf.bssid;
  4355. else
  4356. bssid = "\x01\x00\x00\x00\x00\x00";
  4357. mwl8k_cmd_set_post_scan(hw, bssid);
  4358. }
  4359. }
  4360. /*
  4361. * If FIF_ALLMULTI is being requested, throw away the command
  4362. * packet that ->prepare_multicast() built and replace it with
  4363. * a command packet that enables reception of all multicast
  4364. * packets.
  4365. */
  4366. if (*total_flags & FIF_ALLMULTI) {
  4367. kfree(cmd);
  4368. cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
  4369. }
  4370. if (cmd != NULL) {
  4371. mwl8k_post_cmd(hw, cmd);
  4372. kfree(cmd);
  4373. }
  4374. mwl8k_fw_unlock(hw);
  4375. }
  4376. static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  4377. {
  4378. return mwl8k_cmd_set_rts_threshold(hw, value);
  4379. }
  4380. static int mwl8k_sta_remove(struct ieee80211_hw *hw,
  4381. struct ieee80211_vif *vif,
  4382. struct ieee80211_sta *sta)
  4383. {
  4384. struct mwl8k_priv *priv = hw->priv;
  4385. if (priv->ap_fw)
  4386. return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
  4387. else
  4388. return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
  4389. }
  4390. static int mwl8k_sta_add(struct ieee80211_hw *hw,
  4391. struct ieee80211_vif *vif,
  4392. struct ieee80211_sta *sta)
  4393. {
  4394. struct mwl8k_priv *priv = hw->priv;
  4395. int ret;
  4396. int i;
  4397. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  4398. struct ieee80211_key_conf *key;
  4399. if (!priv->ap_fw) {
  4400. ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
  4401. if (ret >= 0) {
  4402. MWL8K_STA(sta)->peer_id = ret;
  4403. if (sta->ht_cap.ht_supported)
  4404. MWL8K_STA(sta)->is_ampdu_allowed = true;
  4405. ret = 0;
  4406. }
  4407. } else {
  4408. ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
  4409. }
  4410. for (i = 0; i < NUM_WEP_KEYS; i++) {
  4411. key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
  4412. if (mwl8k_vif->wep_key_conf[i].enabled)
  4413. mwl8k_set_key(hw, SET_KEY, vif, sta, key);
  4414. }
  4415. return ret;
  4416. }
  4417. static int mwl8k_conf_tx(struct ieee80211_hw *hw,
  4418. struct ieee80211_vif *vif, u16 queue,
  4419. const struct ieee80211_tx_queue_params *params)
  4420. {
  4421. struct mwl8k_priv *priv = hw->priv;
  4422. int rc;
  4423. rc = mwl8k_fw_lock(hw);
  4424. if (!rc) {
  4425. BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
  4426. memcpy(&priv->wmm_params[queue], params, sizeof(*params));
  4427. if (!priv->wmm_enabled)
  4428. rc = mwl8k_cmd_set_wmm_mode(hw, 1);
  4429. if (!rc) {
  4430. int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
  4431. rc = mwl8k_cmd_set_edca_params(hw, q,
  4432. params->cw_min,
  4433. params->cw_max,
  4434. params->aifs,
  4435. params->txop);
  4436. }
  4437. mwl8k_fw_unlock(hw);
  4438. }
  4439. return rc;
  4440. }
  4441. static int mwl8k_get_stats(struct ieee80211_hw *hw,
  4442. struct ieee80211_low_level_stats *stats)
  4443. {
  4444. return mwl8k_cmd_get_stat(hw, stats);
  4445. }
  4446. static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
  4447. struct survey_info *survey)
  4448. {
  4449. struct mwl8k_priv *priv = hw->priv;
  4450. struct ieee80211_conf *conf = &hw->conf;
  4451. struct ieee80211_supported_band *sband;
  4452. if (priv->ap_fw) {
  4453. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  4454. if (sband && idx >= sband->n_channels) {
  4455. idx -= sband->n_channels;
  4456. sband = NULL;
  4457. }
  4458. if (!sband)
  4459. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  4460. if (!sband || idx >= sband->n_channels)
  4461. return -ENOENT;
  4462. memcpy(survey, &priv->survey[idx], sizeof(*survey));
  4463. survey->channel = &sband->channels[idx];
  4464. return 0;
  4465. }
  4466. if (idx != 0)
  4467. return -ENOENT;
  4468. survey->channel = conf->chandef.chan;
  4469. survey->filled = SURVEY_INFO_NOISE_DBM;
  4470. survey->noise = priv->noise;
  4471. return 0;
  4472. }
  4473. #define MAX_AMPDU_ATTEMPTS 5
  4474. static int
  4475. mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4476. enum ieee80211_ampdu_mlme_action action,
  4477. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  4478. u8 buf_size)
  4479. {
  4480. int i, rc = 0;
  4481. struct mwl8k_priv *priv = hw->priv;
  4482. struct mwl8k_ampdu_stream *stream;
  4483. u8 *addr = sta->addr, idx;
  4484. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  4485. if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
  4486. return -ENOTSUPP;
  4487. spin_lock(&priv->stream_lock);
  4488. stream = mwl8k_lookup_stream(hw, addr, tid);
  4489. switch (action) {
  4490. case IEEE80211_AMPDU_RX_START:
  4491. case IEEE80211_AMPDU_RX_STOP:
  4492. break;
  4493. case IEEE80211_AMPDU_TX_START:
  4494. /* By the time we get here the hw queues may contain outgoing
  4495. * packets for this RA/TID that are not part of this BA
  4496. * session. The hw will assign sequence numbers to these
  4497. * packets as they go out. So if we query the hw for its next
  4498. * sequence number and use that for the SSN here, it may end up
  4499. * being wrong, which will lead to sequence number mismatch at
  4500. * the recipient. To avoid this, we reset the sequence number
  4501. * to O for the first MPDU in this BA stream.
  4502. */
  4503. *ssn = 0;
  4504. if (stream == NULL) {
  4505. /* This means that somebody outside this driver called
  4506. * ieee80211_start_tx_ba_session. This is unexpected
  4507. * because we do our own rate control. Just warn and
  4508. * move on.
  4509. */
  4510. wiphy_warn(hw->wiphy, "Unexpected call to %s. "
  4511. "Proceeding anyway.\n", __func__);
  4512. stream = mwl8k_add_stream(hw, sta, tid);
  4513. }
  4514. if (stream == NULL) {
  4515. wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
  4516. rc = -EBUSY;
  4517. break;
  4518. }
  4519. stream->state = AMPDU_STREAM_IN_PROGRESS;
  4520. /* Release the lock before we do the time consuming stuff */
  4521. spin_unlock(&priv->stream_lock);
  4522. for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
  4523. /* Check if link is still valid */
  4524. if (!sta_info->is_ampdu_allowed) {
  4525. spin_lock(&priv->stream_lock);
  4526. mwl8k_remove_stream(hw, stream);
  4527. spin_unlock(&priv->stream_lock);
  4528. return -EBUSY;
  4529. }
  4530. rc = mwl8k_check_ba(hw, stream, vif);
  4531. /* If HW restart is in progress mwl8k_post_cmd will
  4532. * return -EBUSY. Avoid retrying mwl8k_check_ba in
  4533. * such cases
  4534. */
  4535. if (!rc || rc == -EBUSY)
  4536. break;
  4537. /*
  4538. * HW queues take time to be flushed, give them
  4539. * sufficient time
  4540. */
  4541. msleep(1000);
  4542. }
  4543. spin_lock(&priv->stream_lock);
  4544. if (rc) {
  4545. wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
  4546. " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
  4547. mwl8k_remove_stream(hw, stream);
  4548. rc = -EBUSY;
  4549. break;
  4550. }
  4551. ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
  4552. break;
  4553. case IEEE80211_AMPDU_TX_STOP_CONT:
  4554. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  4555. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  4556. if (stream) {
  4557. if (stream->state == AMPDU_STREAM_ACTIVE) {
  4558. idx = stream->idx;
  4559. spin_unlock(&priv->stream_lock);
  4560. mwl8k_destroy_ba(hw, idx);
  4561. spin_lock(&priv->stream_lock);
  4562. }
  4563. mwl8k_remove_stream(hw, stream);
  4564. }
  4565. ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
  4566. break;
  4567. case IEEE80211_AMPDU_TX_OPERATIONAL:
  4568. BUG_ON(stream == NULL);
  4569. BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
  4570. spin_unlock(&priv->stream_lock);
  4571. rc = mwl8k_create_ba(hw, stream, buf_size, vif);
  4572. spin_lock(&priv->stream_lock);
  4573. if (!rc)
  4574. stream->state = AMPDU_STREAM_ACTIVE;
  4575. else {
  4576. idx = stream->idx;
  4577. spin_unlock(&priv->stream_lock);
  4578. mwl8k_destroy_ba(hw, idx);
  4579. spin_lock(&priv->stream_lock);
  4580. wiphy_debug(hw->wiphy,
  4581. "Failed adding stream for sta %pM tid %d\n",
  4582. addr, tid);
  4583. mwl8k_remove_stream(hw, stream);
  4584. }
  4585. break;
  4586. default:
  4587. rc = -ENOTSUPP;
  4588. }
  4589. spin_unlock(&priv->stream_lock);
  4590. return rc;
  4591. }
  4592. static void mwl8k_sw_scan_start(struct ieee80211_hw *hw)
  4593. {
  4594. struct mwl8k_priv *priv = hw->priv;
  4595. u8 tmp;
  4596. if (!priv->ap_fw)
  4597. return;
  4598. /* clear all stats */
  4599. priv->channel_time = 0;
  4600. ioread32(priv->regs + BBU_RXRDY_CNT_REG);
  4601. ioread32(priv->regs + NOK_CCA_CNT_REG);
  4602. mwl8k_cmd_bbp_reg_access(priv->hw, 0, BBU_AVG_NOISE_VAL, &tmp);
  4603. priv->sw_scan_start = true;
  4604. }
  4605. static void mwl8k_sw_scan_complete(struct ieee80211_hw *hw)
  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 DEFINE_PCI_DEVICE_TABLE(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. hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
  5040. /*
  5041. * Ask mac80211 to not to trigger PS mode
  5042. * based on PM bit of incoming frames.
  5043. */
  5044. if (priv->ap_fw)
  5045. hw->flags |= IEEE80211_HW_AP_LINK_PS;
  5046. hw->vif_data_size = sizeof(struct mwl8k_vif);
  5047. hw->sta_data_size = sizeof(struct mwl8k_sta);
  5048. priv->macids_used = 0;
  5049. INIT_LIST_HEAD(&priv->vif_list);
  5050. /* Set default radio state and preamble */
  5051. priv->radio_on = false;
  5052. priv->radio_short_preamble = false;
  5053. /* Finalize join worker */
  5054. INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
  5055. /* Handle watchdog ba events */
  5056. INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
  5057. /* To reload the firmware if it crashes */
  5058. INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work);
  5059. /* TX reclaim and RX tasklets. */
  5060. tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
  5061. tasklet_disable(&priv->poll_tx_task);
  5062. tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
  5063. tasklet_disable(&priv->poll_rx_task);
  5064. /* Power management cookie */
  5065. priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
  5066. if (priv->cookie == NULL)
  5067. return -ENOMEM;
  5068. mutex_init(&priv->fw_mutex);
  5069. priv->fw_mutex_owner = NULL;
  5070. priv->fw_mutex_depth = 0;
  5071. priv->hostcmd_wait = NULL;
  5072. spin_lock_init(&priv->tx_lock);
  5073. spin_lock_init(&priv->stream_lock);
  5074. priv->tx_wait = NULL;
  5075. rc = mwl8k_probe_hw(hw);
  5076. if (rc)
  5077. goto err_free_cookie;
  5078. hw->wiphy->interface_modes = 0;
  5079. if (priv->ap_macids_supported || priv->device_info->fw_image_ap) {
  5080. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
  5081. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
  5082. hw->wiphy->iface_combinations = &ap_if_comb;
  5083. hw->wiphy->n_iface_combinations = 1;
  5084. }
  5085. if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
  5086. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
  5087. rc = ieee80211_register_hw(hw);
  5088. if (rc) {
  5089. wiphy_err(hw->wiphy, "Cannot register device\n");
  5090. goto err_unprobe_hw;
  5091. }
  5092. return 0;
  5093. err_unprobe_hw:
  5094. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  5095. mwl8k_txq_deinit(hw, i);
  5096. mwl8k_rxq_deinit(hw, 0);
  5097. err_free_cookie:
  5098. if (priv->cookie != NULL)
  5099. pci_free_consistent(priv->pdev, 4,
  5100. priv->cookie, priv->cookie_dma);
  5101. return rc;
  5102. }
  5103. static int mwl8k_probe(struct pci_dev *pdev,
  5104. const struct pci_device_id *id)
  5105. {
  5106. static int printed_version;
  5107. struct ieee80211_hw *hw;
  5108. struct mwl8k_priv *priv;
  5109. struct mwl8k_device_info *di;
  5110. int rc;
  5111. if (!printed_version) {
  5112. printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
  5113. printed_version = 1;
  5114. }
  5115. rc = pci_enable_device(pdev);
  5116. if (rc) {
  5117. printk(KERN_ERR "%s: Cannot enable new PCI device\n",
  5118. MWL8K_NAME);
  5119. return rc;
  5120. }
  5121. rc = pci_request_regions(pdev, MWL8K_NAME);
  5122. if (rc) {
  5123. printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
  5124. MWL8K_NAME);
  5125. goto err_disable_device;
  5126. }
  5127. pci_set_master(pdev);
  5128. hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
  5129. if (hw == NULL) {
  5130. printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
  5131. rc = -ENOMEM;
  5132. goto err_free_reg;
  5133. }
  5134. SET_IEEE80211_DEV(hw, &pdev->dev);
  5135. pci_set_drvdata(pdev, hw);
  5136. priv = hw->priv;
  5137. priv->hw = hw;
  5138. priv->pdev = pdev;
  5139. priv->device_info = &mwl8k_info_tbl[id->driver_data];
  5140. if (id->driver_data == MWL8764)
  5141. priv->is_8764 = true;
  5142. priv->sram = pci_iomap(pdev, 0, 0x10000);
  5143. if (priv->sram == NULL) {
  5144. wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
  5145. rc = -EIO;
  5146. goto err_iounmap;
  5147. }
  5148. /*
  5149. * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
  5150. * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
  5151. */
  5152. priv->regs = pci_iomap(pdev, 1, 0x10000);
  5153. if (priv->regs == NULL) {
  5154. priv->regs = pci_iomap(pdev, 2, 0x10000);
  5155. if (priv->regs == NULL) {
  5156. wiphy_err(hw->wiphy, "Cannot map device registers\n");
  5157. rc = -EIO;
  5158. goto err_iounmap;
  5159. }
  5160. }
  5161. /*
  5162. * Choose the initial fw image depending on user input. If a second
  5163. * image is available, make it the alternative image that will be
  5164. * loaded if the first one fails.
  5165. */
  5166. init_completion(&priv->firmware_loading_complete);
  5167. di = priv->device_info;
  5168. if (ap_mode_default && di->fw_image_ap) {
  5169. priv->fw_pref = di->fw_image_ap;
  5170. priv->fw_alt = di->fw_image_sta;
  5171. } else if (!ap_mode_default && di->fw_image_sta) {
  5172. priv->fw_pref = di->fw_image_sta;
  5173. priv->fw_alt = di->fw_image_ap;
  5174. } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
  5175. printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
  5176. priv->fw_pref = di->fw_image_sta;
  5177. } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
  5178. printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
  5179. priv->fw_pref = di->fw_image_ap;
  5180. }
  5181. rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
  5182. if (rc)
  5183. goto err_stop_firmware;
  5184. priv->hw_restart_in_progress = false;
  5185. priv->running_bsses = 0;
  5186. return rc;
  5187. err_stop_firmware:
  5188. mwl8k_hw_reset(priv);
  5189. err_iounmap:
  5190. if (priv->regs != NULL)
  5191. pci_iounmap(pdev, priv->regs);
  5192. if (priv->sram != NULL)
  5193. pci_iounmap(pdev, priv->sram);
  5194. ieee80211_free_hw(hw);
  5195. err_free_reg:
  5196. pci_release_regions(pdev);
  5197. err_disable_device:
  5198. pci_disable_device(pdev);
  5199. return rc;
  5200. }
  5201. static void mwl8k_remove(struct pci_dev *pdev)
  5202. {
  5203. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  5204. struct mwl8k_priv *priv;
  5205. int i;
  5206. if (hw == NULL)
  5207. return;
  5208. priv = hw->priv;
  5209. wait_for_completion(&priv->firmware_loading_complete);
  5210. if (priv->fw_state == FW_STATE_ERROR) {
  5211. mwl8k_hw_reset(priv);
  5212. goto unmap;
  5213. }
  5214. ieee80211_stop_queues(hw);
  5215. ieee80211_unregister_hw(hw);
  5216. /* Remove TX reclaim and RX tasklets. */
  5217. tasklet_kill(&priv->poll_tx_task);
  5218. tasklet_kill(&priv->poll_rx_task);
  5219. /* Stop hardware */
  5220. mwl8k_hw_reset(priv);
  5221. /* Return all skbs to mac80211 */
  5222. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  5223. mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  5224. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  5225. mwl8k_txq_deinit(hw, i);
  5226. mwl8k_rxq_deinit(hw, 0);
  5227. pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
  5228. unmap:
  5229. pci_iounmap(pdev, priv->regs);
  5230. pci_iounmap(pdev, priv->sram);
  5231. ieee80211_free_hw(hw);
  5232. pci_release_regions(pdev);
  5233. pci_disable_device(pdev);
  5234. }
  5235. static struct pci_driver mwl8k_driver = {
  5236. .name = MWL8K_NAME,
  5237. .id_table = mwl8k_pci_id_table,
  5238. .probe = mwl8k_probe,
  5239. .remove = mwl8k_remove,
  5240. };
  5241. module_pci_driver(mwl8k_driver);
  5242. MODULE_DESCRIPTION(MWL8K_DESC);
  5243. MODULE_VERSION(MWL8K_VERSION);
  5244. MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
  5245. MODULE_LICENSE("GPL");