mwl8k.c 154 KB

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