mac.c 186 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "mac.h"
  18. #include <net/mac80211.h>
  19. #include <linux/etherdevice.h>
  20. #include "hif.h"
  21. #include "core.h"
  22. #include "debug.h"
  23. #include "wmi.h"
  24. #include "htt.h"
  25. #include "txrx.h"
  26. #include "testmode.h"
  27. #include "wmi.h"
  28. #include "wmi-tlv.h"
  29. #include "wmi-ops.h"
  30. #include "wow.h"
  31. /*********/
  32. /* Rates */
  33. /*********/
  34. static struct ieee80211_rate ath10k_rates[] = {
  35. { .bitrate = 10,
  36. .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
  37. { .bitrate = 20,
  38. .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
  39. .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
  40. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  41. { .bitrate = 55,
  42. .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
  43. .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
  44. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  45. { .bitrate = 110,
  46. .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
  47. .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
  48. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  49. { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
  50. { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
  51. { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
  52. { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
  53. { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
  54. { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
  55. { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
  56. { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
  57. };
  58. #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
  59. #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
  60. #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
  61. ATH10K_MAC_FIRST_OFDM_RATE_IDX)
  62. #define ath10k_g_rates (ath10k_rates + 0)
  63. #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
  64. static bool ath10k_mac_bitrate_is_cck(int bitrate)
  65. {
  66. switch (bitrate) {
  67. case 10:
  68. case 20:
  69. case 55:
  70. case 110:
  71. return true;
  72. }
  73. return false;
  74. }
  75. static u8 ath10k_mac_bitrate_to_rate(int bitrate)
  76. {
  77. return DIV_ROUND_UP(bitrate, 5) |
  78. (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
  79. }
  80. u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
  81. u8 hw_rate, bool cck)
  82. {
  83. const struct ieee80211_rate *rate;
  84. int i;
  85. for (i = 0; i < sband->n_bitrates; i++) {
  86. rate = &sband->bitrates[i];
  87. if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
  88. continue;
  89. if (rate->hw_value == hw_rate)
  90. return i;
  91. else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
  92. rate->hw_value_short == hw_rate)
  93. return i;
  94. }
  95. return 0;
  96. }
  97. u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
  98. u32 bitrate)
  99. {
  100. int i;
  101. for (i = 0; i < sband->n_bitrates; i++)
  102. if (sband->bitrates[i].bitrate == bitrate)
  103. return i;
  104. return 0;
  105. }
  106. static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
  107. {
  108. switch ((mcs_map >> (2 * nss)) & 0x3) {
  109. case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
  110. case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
  111. case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
  112. }
  113. return 0;
  114. }
  115. static u32
  116. ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
  117. {
  118. int nss;
  119. for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
  120. if (ht_mcs_mask[nss])
  121. return nss + 1;
  122. return 1;
  123. }
  124. static u32
  125. ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
  126. {
  127. int nss;
  128. for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
  129. if (vht_mcs_mask[nss])
  130. return nss + 1;
  131. return 1;
  132. }
  133. /**********/
  134. /* Crypto */
  135. /**********/
  136. static int ath10k_send_key(struct ath10k_vif *arvif,
  137. struct ieee80211_key_conf *key,
  138. enum set_key_cmd cmd,
  139. const u8 *macaddr, u32 flags)
  140. {
  141. struct ath10k *ar = arvif->ar;
  142. struct wmi_vdev_install_key_arg arg = {
  143. .vdev_id = arvif->vdev_id,
  144. .key_idx = key->keyidx,
  145. .key_len = key->keylen,
  146. .key_data = key->key,
  147. .key_flags = flags,
  148. .macaddr = macaddr,
  149. };
  150. lockdep_assert_held(&arvif->ar->conf_mutex);
  151. switch (key->cipher) {
  152. case WLAN_CIPHER_SUITE_CCMP:
  153. arg.key_cipher = WMI_CIPHER_AES_CCM;
  154. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
  155. break;
  156. case WLAN_CIPHER_SUITE_TKIP:
  157. arg.key_cipher = WMI_CIPHER_TKIP;
  158. arg.key_txmic_len = 8;
  159. arg.key_rxmic_len = 8;
  160. break;
  161. case WLAN_CIPHER_SUITE_WEP40:
  162. case WLAN_CIPHER_SUITE_WEP104:
  163. arg.key_cipher = WMI_CIPHER_WEP;
  164. break;
  165. case WLAN_CIPHER_SUITE_AES_CMAC:
  166. WARN_ON(1);
  167. return -EINVAL;
  168. default:
  169. ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
  170. return -EOPNOTSUPP;
  171. }
  172. if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
  173. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  174. if (cmd == DISABLE_KEY) {
  175. arg.key_cipher = WMI_CIPHER_NONE;
  176. arg.key_data = NULL;
  177. }
  178. return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
  179. }
  180. static int ath10k_install_key(struct ath10k_vif *arvif,
  181. struct ieee80211_key_conf *key,
  182. enum set_key_cmd cmd,
  183. const u8 *macaddr, u32 flags)
  184. {
  185. struct ath10k *ar = arvif->ar;
  186. int ret;
  187. unsigned long time_left;
  188. lockdep_assert_held(&ar->conf_mutex);
  189. reinit_completion(&ar->install_key_done);
  190. if (arvif->nohwcrypt)
  191. return 1;
  192. ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
  193. if (ret)
  194. return ret;
  195. time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
  196. if (time_left == 0)
  197. return -ETIMEDOUT;
  198. return 0;
  199. }
  200. static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
  201. const u8 *addr)
  202. {
  203. struct ath10k *ar = arvif->ar;
  204. struct ath10k_peer *peer;
  205. int ret;
  206. int i;
  207. u32 flags;
  208. lockdep_assert_held(&ar->conf_mutex);
  209. if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
  210. arvif->vif->type != NL80211_IFTYPE_ADHOC &&
  211. arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
  212. return -EINVAL;
  213. spin_lock_bh(&ar->data_lock);
  214. peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
  215. spin_unlock_bh(&ar->data_lock);
  216. if (!peer)
  217. return -ENOENT;
  218. for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
  219. if (arvif->wep_keys[i] == NULL)
  220. continue;
  221. switch (arvif->vif->type) {
  222. case NL80211_IFTYPE_AP:
  223. flags = WMI_KEY_PAIRWISE;
  224. if (arvif->def_wep_key_idx == i)
  225. flags |= WMI_KEY_TX_USAGE;
  226. ret = ath10k_install_key(arvif, arvif->wep_keys[i],
  227. SET_KEY, addr, flags);
  228. if (ret < 0)
  229. return ret;
  230. break;
  231. case NL80211_IFTYPE_ADHOC:
  232. ret = ath10k_install_key(arvif, arvif->wep_keys[i],
  233. SET_KEY, addr,
  234. WMI_KEY_PAIRWISE);
  235. if (ret < 0)
  236. return ret;
  237. ret = ath10k_install_key(arvif, arvif->wep_keys[i],
  238. SET_KEY, addr, WMI_KEY_GROUP);
  239. if (ret < 0)
  240. return ret;
  241. break;
  242. default:
  243. WARN_ON(1);
  244. return -EINVAL;
  245. }
  246. spin_lock_bh(&ar->data_lock);
  247. peer->keys[i] = arvif->wep_keys[i];
  248. spin_unlock_bh(&ar->data_lock);
  249. }
  250. /* In some cases (notably with static WEP IBSS with multiple keys)
  251. * multicast Tx becomes broken. Both pairwise and groupwise keys are
  252. * installed already. Using WMI_KEY_TX_USAGE in different combinations
  253. * didn't seem help. Using def_keyid vdev parameter seems to be
  254. * effective so use that.
  255. *
  256. * FIXME: Revisit. Perhaps this can be done in a less hacky way.
  257. */
  258. if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
  259. return 0;
  260. if (arvif->def_wep_key_idx == -1)
  261. return 0;
  262. ret = ath10k_wmi_vdev_set_param(arvif->ar,
  263. arvif->vdev_id,
  264. arvif->ar->wmi.vdev_param->def_keyid,
  265. arvif->def_wep_key_idx);
  266. if (ret) {
  267. ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
  268. arvif->vdev_id, ret);
  269. return ret;
  270. }
  271. return 0;
  272. }
  273. static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
  274. const u8 *addr)
  275. {
  276. struct ath10k *ar = arvif->ar;
  277. struct ath10k_peer *peer;
  278. int first_errno = 0;
  279. int ret;
  280. int i;
  281. u32 flags = 0;
  282. lockdep_assert_held(&ar->conf_mutex);
  283. spin_lock_bh(&ar->data_lock);
  284. peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
  285. spin_unlock_bh(&ar->data_lock);
  286. if (!peer)
  287. return -ENOENT;
  288. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  289. if (peer->keys[i] == NULL)
  290. continue;
  291. /* key flags are not required to delete the key */
  292. ret = ath10k_install_key(arvif, peer->keys[i],
  293. DISABLE_KEY, addr, flags);
  294. if (ret < 0 && first_errno == 0)
  295. first_errno = ret;
  296. if (ret < 0)
  297. ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
  298. i, ret);
  299. spin_lock_bh(&ar->data_lock);
  300. peer->keys[i] = NULL;
  301. spin_unlock_bh(&ar->data_lock);
  302. }
  303. return first_errno;
  304. }
  305. bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
  306. u8 keyidx)
  307. {
  308. struct ath10k_peer *peer;
  309. int i;
  310. lockdep_assert_held(&ar->data_lock);
  311. /* We don't know which vdev this peer belongs to,
  312. * since WMI doesn't give us that information.
  313. *
  314. * FIXME: multi-bss needs to be handled.
  315. */
  316. peer = ath10k_peer_find(ar, 0, addr);
  317. if (!peer)
  318. return false;
  319. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  320. if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
  321. return true;
  322. }
  323. return false;
  324. }
  325. static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
  326. struct ieee80211_key_conf *key)
  327. {
  328. struct ath10k *ar = arvif->ar;
  329. struct ath10k_peer *peer;
  330. u8 addr[ETH_ALEN];
  331. int first_errno = 0;
  332. int ret;
  333. int i;
  334. u32 flags = 0;
  335. lockdep_assert_held(&ar->conf_mutex);
  336. for (;;) {
  337. /* since ath10k_install_key we can't hold data_lock all the
  338. * time, so we try to remove the keys incrementally */
  339. spin_lock_bh(&ar->data_lock);
  340. i = 0;
  341. list_for_each_entry(peer, &ar->peers, list) {
  342. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  343. if (peer->keys[i] == key) {
  344. ether_addr_copy(addr, peer->addr);
  345. peer->keys[i] = NULL;
  346. break;
  347. }
  348. }
  349. if (i < ARRAY_SIZE(peer->keys))
  350. break;
  351. }
  352. spin_unlock_bh(&ar->data_lock);
  353. if (i == ARRAY_SIZE(peer->keys))
  354. break;
  355. /* key flags are not required to delete the key */
  356. ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
  357. if (ret < 0 && first_errno == 0)
  358. first_errno = ret;
  359. if (ret)
  360. ath10k_warn(ar, "failed to remove key for %pM: %d\n",
  361. addr, ret);
  362. }
  363. return first_errno;
  364. }
  365. static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
  366. struct ieee80211_key_conf *key)
  367. {
  368. struct ath10k *ar = arvif->ar;
  369. struct ath10k_peer *peer;
  370. int ret;
  371. lockdep_assert_held(&ar->conf_mutex);
  372. list_for_each_entry(peer, &ar->peers, list) {
  373. if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
  374. continue;
  375. if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
  376. continue;
  377. if (peer->keys[key->keyidx] == key)
  378. continue;
  379. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
  380. arvif->vdev_id, key->keyidx);
  381. ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
  382. if (ret) {
  383. ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
  384. arvif->vdev_id, peer->addr, ret);
  385. return ret;
  386. }
  387. }
  388. return 0;
  389. }
  390. /*********************/
  391. /* General utilities */
  392. /*********************/
  393. static inline enum wmi_phy_mode
  394. chan_to_phymode(const struct cfg80211_chan_def *chandef)
  395. {
  396. enum wmi_phy_mode phymode = MODE_UNKNOWN;
  397. switch (chandef->chan->band) {
  398. case IEEE80211_BAND_2GHZ:
  399. switch (chandef->width) {
  400. case NL80211_CHAN_WIDTH_20_NOHT:
  401. if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
  402. phymode = MODE_11B;
  403. else
  404. phymode = MODE_11G;
  405. break;
  406. case NL80211_CHAN_WIDTH_20:
  407. phymode = MODE_11NG_HT20;
  408. break;
  409. case NL80211_CHAN_WIDTH_40:
  410. phymode = MODE_11NG_HT40;
  411. break;
  412. case NL80211_CHAN_WIDTH_5:
  413. case NL80211_CHAN_WIDTH_10:
  414. case NL80211_CHAN_WIDTH_80:
  415. case NL80211_CHAN_WIDTH_80P80:
  416. case NL80211_CHAN_WIDTH_160:
  417. phymode = MODE_UNKNOWN;
  418. break;
  419. }
  420. break;
  421. case IEEE80211_BAND_5GHZ:
  422. switch (chandef->width) {
  423. case NL80211_CHAN_WIDTH_20_NOHT:
  424. phymode = MODE_11A;
  425. break;
  426. case NL80211_CHAN_WIDTH_20:
  427. phymode = MODE_11NA_HT20;
  428. break;
  429. case NL80211_CHAN_WIDTH_40:
  430. phymode = MODE_11NA_HT40;
  431. break;
  432. case NL80211_CHAN_WIDTH_80:
  433. phymode = MODE_11AC_VHT80;
  434. break;
  435. case NL80211_CHAN_WIDTH_5:
  436. case NL80211_CHAN_WIDTH_10:
  437. case NL80211_CHAN_WIDTH_80P80:
  438. case NL80211_CHAN_WIDTH_160:
  439. phymode = MODE_UNKNOWN;
  440. break;
  441. }
  442. break;
  443. default:
  444. break;
  445. }
  446. WARN_ON(phymode == MODE_UNKNOWN);
  447. return phymode;
  448. }
  449. static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
  450. {
  451. /*
  452. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  453. * 0 for no restriction
  454. * 1 for 1/4 us
  455. * 2 for 1/2 us
  456. * 3 for 1 us
  457. * 4 for 2 us
  458. * 5 for 4 us
  459. * 6 for 8 us
  460. * 7 for 16 us
  461. */
  462. switch (mpdudensity) {
  463. case 0:
  464. return 0;
  465. case 1:
  466. case 2:
  467. case 3:
  468. /* Our lower layer calculations limit our precision to
  469. 1 microsecond */
  470. return 1;
  471. case 4:
  472. return 2;
  473. case 5:
  474. return 4;
  475. case 6:
  476. return 8;
  477. case 7:
  478. return 16;
  479. default:
  480. return 0;
  481. }
  482. }
  483. int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
  484. struct cfg80211_chan_def *def)
  485. {
  486. struct ieee80211_chanctx_conf *conf;
  487. rcu_read_lock();
  488. conf = rcu_dereference(vif->chanctx_conf);
  489. if (!conf) {
  490. rcu_read_unlock();
  491. return -ENOENT;
  492. }
  493. *def = conf->def;
  494. rcu_read_unlock();
  495. return 0;
  496. }
  497. static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
  498. struct ieee80211_chanctx_conf *conf,
  499. void *data)
  500. {
  501. int *num = data;
  502. (*num)++;
  503. }
  504. static int ath10k_mac_num_chanctxs(struct ath10k *ar)
  505. {
  506. int num = 0;
  507. ieee80211_iter_chan_contexts_atomic(ar->hw,
  508. ath10k_mac_num_chanctxs_iter,
  509. &num);
  510. return num;
  511. }
  512. static void
  513. ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
  514. struct ieee80211_chanctx_conf *conf,
  515. void *data)
  516. {
  517. struct cfg80211_chan_def **def = data;
  518. *def = &conf->def;
  519. }
  520. static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
  521. enum wmi_peer_type peer_type)
  522. {
  523. struct ath10k_vif *arvif;
  524. int num_peers = 0;
  525. int ret;
  526. lockdep_assert_held(&ar->conf_mutex);
  527. num_peers = ar->num_peers;
  528. /* Each vdev consumes a peer entry as well */
  529. list_for_each_entry(arvif, &ar->arvifs, list)
  530. num_peers++;
  531. if (num_peers >= ar->max_num_peers)
  532. return -ENOBUFS;
  533. ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
  534. if (ret) {
  535. ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
  536. addr, vdev_id, ret);
  537. return ret;
  538. }
  539. ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
  540. if (ret) {
  541. ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
  542. addr, vdev_id, ret);
  543. return ret;
  544. }
  545. ar->num_peers++;
  546. return 0;
  547. }
  548. static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
  549. {
  550. struct ath10k *ar = arvif->ar;
  551. u32 param;
  552. int ret;
  553. param = ar->wmi.pdev_param->sta_kickout_th;
  554. ret = ath10k_wmi_pdev_set_param(ar, param,
  555. ATH10K_KICKOUT_THRESHOLD);
  556. if (ret) {
  557. ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
  558. arvif->vdev_id, ret);
  559. return ret;
  560. }
  561. param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
  562. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
  563. ATH10K_KEEPALIVE_MIN_IDLE);
  564. if (ret) {
  565. ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
  566. arvif->vdev_id, ret);
  567. return ret;
  568. }
  569. param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
  570. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
  571. ATH10K_KEEPALIVE_MAX_IDLE);
  572. if (ret) {
  573. ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
  574. arvif->vdev_id, ret);
  575. return ret;
  576. }
  577. param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
  578. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
  579. ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
  580. if (ret) {
  581. ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
  582. arvif->vdev_id, ret);
  583. return ret;
  584. }
  585. return 0;
  586. }
  587. static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
  588. {
  589. struct ath10k *ar = arvif->ar;
  590. u32 vdev_param;
  591. vdev_param = ar->wmi.vdev_param->rts_threshold;
  592. return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
  593. }
  594. static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
  595. {
  596. int ret;
  597. lockdep_assert_held(&ar->conf_mutex);
  598. ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
  599. if (ret)
  600. return ret;
  601. ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
  602. if (ret)
  603. return ret;
  604. ar->num_peers--;
  605. return 0;
  606. }
  607. static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
  608. {
  609. struct ath10k_peer *peer, *tmp;
  610. lockdep_assert_held(&ar->conf_mutex);
  611. spin_lock_bh(&ar->data_lock);
  612. list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
  613. if (peer->vdev_id != vdev_id)
  614. continue;
  615. ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
  616. peer->addr, vdev_id);
  617. list_del(&peer->list);
  618. kfree(peer);
  619. ar->num_peers--;
  620. }
  621. spin_unlock_bh(&ar->data_lock);
  622. }
  623. static void ath10k_peer_cleanup_all(struct ath10k *ar)
  624. {
  625. struct ath10k_peer *peer, *tmp;
  626. lockdep_assert_held(&ar->conf_mutex);
  627. spin_lock_bh(&ar->data_lock);
  628. list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
  629. list_del(&peer->list);
  630. kfree(peer);
  631. }
  632. spin_unlock_bh(&ar->data_lock);
  633. ar->num_peers = 0;
  634. ar->num_stations = 0;
  635. }
  636. static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
  637. struct ieee80211_sta *sta,
  638. enum wmi_tdls_peer_state state)
  639. {
  640. int ret;
  641. struct wmi_tdls_peer_update_cmd_arg arg = {};
  642. struct wmi_tdls_peer_capab_arg cap = {};
  643. struct wmi_channel_arg chan_arg = {};
  644. lockdep_assert_held(&ar->conf_mutex);
  645. arg.vdev_id = vdev_id;
  646. arg.peer_state = state;
  647. ether_addr_copy(arg.addr, sta->addr);
  648. cap.peer_max_sp = sta->max_sp;
  649. cap.peer_uapsd_queues = sta->uapsd_queues;
  650. if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
  651. !sta->tdls_initiator)
  652. cap.is_peer_responder = 1;
  653. ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
  654. if (ret) {
  655. ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
  656. arg.addr, vdev_id, ret);
  657. return ret;
  658. }
  659. return 0;
  660. }
  661. /************************/
  662. /* Interface management */
  663. /************************/
  664. void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
  665. {
  666. struct ath10k *ar = arvif->ar;
  667. lockdep_assert_held(&ar->data_lock);
  668. if (!arvif->beacon)
  669. return;
  670. if (!arvif->beacon_buf)
  671. dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
  672. arvif->beacon->len, DMA_TO_DEVICE);
  673. if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
  674. arvif->beacon_state != ATH10K_BEACON_SENT))
  675. return;
  676. dev_kfree_skb_any(arvif->beacon);
  677. arvif->beacon = NULL;
  678. arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
  679. }
  680. static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
  681. {
  682. struct ath10k *ar = arvif->ar;
  683. lockdep_assert_held(&ar->data_lock);
  684. ath10k_mac_vif_beacon_free(arvif);
  685. if (arvif->beacon_buf) {
  686. dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
  687. arvif->beacon_buf, arvif->beacon_paddr);
  688. arvif->beacon_buf = NULL;
  689. }
  690. }
  691. static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
  692. {
  693. unsigned long time_left;
  694. lockdep_assert_held(&ar->conf_mutex);
  695. if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
  696. return -ESHUTDOWN;
  697. time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
  698. ATH10K_VDEV_SETUP_TIMEOUT_HZ);
  699. if (time_left == 0)
  700. return -ETIMEDOUT;
  701. return 0;
  702. }
  703. static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
  704. {
  705. struct cfg80211_chan_def *chandef = NULL;
  706. struct ieee80211_channel *channel = NULL;
  707. struct wmi_vdev_start_request_arg arg = {};
  708. int ret = 0;
  709. lockdep_assert_held(&ar->conf_mutex);
  710. ieee80211_iter_chan_contexts_atomic(ar->hw,
  711. ath10k_mac_get_any_chandef_iter,
  712. &chandef);
  713. if (WARN_ON_ONCE(!chandef))
  714. return -ENOENT;
  715. channel = chandef->chan;
  716. arg.vdev_id = vdev_id;
  717. arg.channel.freq = channel->center_freq;
  718. arg.channel.band_center_freq1 = chandef->center_freq1;
  719. /* TODO setup this dynamically, what in case we
  720. don't have any vifs? */
  721. arg.channel.mode = chan_to_phymode(chandef);
  722. arg.channel.chan_radar =
  723. !!(channel->flags & IEEE80211_CHAN_RADAR);
  724. arg.channel.min_power = 0;
  725. arg.channel.max_power = channel->max_power * 2;
  726. arg.channel.max_reg_power = channel->max_reg_power * 2;
  727. arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
  728. reinit_completion(&ar->vdev_setup_done);
  729. ret = ath10k_wmi_vdev_start(ar, &arg);
  730. if (ret) {
  731. ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
  732. vdev_id, ret);
  733. return ret;
  734. }
  735. ret = ath10k_vdev_setup_sync(ar);
  736. if (ret) {
  737. ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
  738. vdev_id, ret);
  739. return ret;
  740. }
  741. ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
  742. if (ret) {
  743. ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
  744. vdev_id, ret);
  745. goto vdev_stop;
  746. }
  747. ar->monitor_vdev_id = vdev_id;
  748. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
  749. ar->monitor_vdev_id);
  750. return 0;
  751. vdev_stop:
  752. ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
  753. if (ret)
  754. ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
  755. ar->monitor_vdev_id, ret);
  756. return ret;
  757. }
  758. static int ath10k_monitor_vdev_stop(struct ath10k *ar)
  759. {
  760. int ret = 0;
  761. lockdep_assert_held(&ar->conf_mutex);
  762. ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
  763. if (ret)
  764. ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
  765. ar->monitor_vdev_id, ret);
  766. reinit_completion(&ar->vdev_setup_done);
  767. ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
  768. if (ret)
  769. ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
  770. ar->monitor_vdev_id, ret);
  771. ret = ath10k_vdev_setup_sync(ar);
  772. if (ret)
  773. ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
  774. ar->monitor_vdev_id, ret);
  775. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
  776. ar->monitor_vdev_id);
  777. return ret;
  778. }
  779. static int ath10k_monitor_vdev_create(struct ath10k *ar)
  780. {
  781. int bit, ret = 0;
  782. lockdep_assert_held(&ar->conf_mutex);
  783. if (ar->free_vdev_map == 0) {
  784. ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
  785. return -ENOMEM;
  786. }
  787. bit = __ffs64(ar->free_vdev_map);
  788. ar->monitor_vdev_id = bit;
  789. ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
  790. WMI_VDEV_TYPE_MONITOR,
  791. 0, ar->mac_addr);
  792. if (ret) {
  793. ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
  794. ar->monitor_vdev_id, ret);
  795. return ret;
  796. }
  797. ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
  798. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
  799. ar->monitor_vdev_id);
  800. return 0;
  801. }
  802. static int ath10k_monitor_vdev_delete(struct ath10k *ar)
  803. {
  804. int ret = 0;
  805. lockdep_assert_held(&ar->conf_mutex);
  806. ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
  807. if (ret) {
  808. ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
  809. ar->monitor_vdev_id, ret);
  810. return ret;
  811. }
  812. ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
  813. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
  814. ar->monitor_vdev_id);
  815. return ret;
  816. }
  817. static int ath10k_monitor_start(struct ath10k *ar)
  818. {
  819. int ret;
  820. lockdep_assert_held(&ar->conf_mutex);
  821. ret = ath10k_monitor_vdev_create(ar);
  822. if (ret) {
  823. ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
  824. return ret;
  825. }
  826. ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
  827. if (ret) {
  828. ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
  829. ath10k_monitor_vdev_delete(ar);
  830. return ret;
  831. }
  832. ar->monitor_started = true;
  833. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
  834. return 0;
  835. }
  836. static int ath10k_monitor_stop(struct ath10k *ar)
  837. {
  838. int ret;
  839. lockdep_assert_held(&ar->conf_mutex);
  840. ret = ath10k_monitor_vdev_stop(ar);
  841. if (ret) {
  842. ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
  843. return ret;
  844. }
  845. ret = ath10k_monitor_vdev_delete(ar);
  846. if (ret) {
  847. ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
  848. return ret;
  849. }
  850. ar->monitor_started = false;
  851. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
  852. return 0;
  853. }
  854. static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
  855. {
  856. int num_ctx;
  857. /* At least one chanctx is required to derive a channel to start
  858. * monitor vdev on.
  859. */
  860. num_ctx = ath10k_mac_num_chanctxs(ar);
  861. if (num_ctx == 0)
  862. return false;
  863. /* If there's already an existing special monitor interface then don't
  864. * bother creating another monitor vdev.
  865. */
  866. if (ar->monitor_arvif)
  867. return false;
  868. return ar->monitor ||
  869. ar->filter_flags & FIF_OTHER_BSS ||
  870. test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  871. }
  872. static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
  873. {
  874. int num_ctx;
  875. num_ctx = ath10k_mac_num_chanctxs(ar);
  876. /* FIXME: Current interface combinations and cfg80211/mac80211 code
  877. * shouldn't allow this but make sure to prevent handling the following
  878. * case anyway since multi-channel DFS hasn't been tested at all.
  879. */
  880. if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
  881. return false;
  882. return true;
  883. }
  884. static int ath10k_monitor_recalc(struct ath10k *ar)
  885. {
  886. bool needed;
  887. bool allowed;
  888. int ret;
  889. lockdep_assert_held(&ar->conf_mutex);
  890. needed = ath10k_mac_monitor_vdev_is_needed(ar);
  891. allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
  892. ath10k_dbg(ar, ATH10K_DBG_MAC,
  893. "mac monitor recalc started? %d needed? %d allowed? %d\n",
  894. ar->monitor_started, needed, allowed);
  895. if (WARN_ON(needed && !allowed)) {
  896. if (ar->monitor_started) {
  897. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
  898. ret = ath10k_monitor_stop(ar);
  899. if (ret)
  900. ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
  901. ret);
  902. /* not serious */
  903. }
  904. return -EPERM;
  905. }
  906. if (needed == ar->monitor_started)
  907. return 0;
  908. if (needed)
  909. return ath10k_monitor_start(ar);
  910. else
  911. return ath10k_monitor_stop(ar);
  912. }
  913. static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
  914. {
  915. struct ath10k *ar = arvif->ar;
  916. u32 vdev_param, rts_cts = 0;
  917. lockdep_assert_held(&ar->conf_mutex);
  918. vdev_param = ar->wmi.vdev_param->enable_rtscts;
  919. rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
  920. if (arvif->num_legacy_stations > 0)
  921. rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
  922. WMI_RTSCTS_PROFILE);
  923. else
  924. rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
  925. WMI_RTSCTS_PROFILE);
  926. return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  927. rts_cts);
  928. }
  929. static int ath10k_start_cac(struct ath10k *ar)
  930. {
  931. int ret;
  932. lockdep_assert_held(&ar->conf_mutex);
  933. set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  934. ret = ath10k_monitor_recalc(ar);
  935. if (ret) {
  936. ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
  937. clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  938. return ret;
  939. }
  940. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
  941. ar->monitor_vdev_id);
  942. return 0;
  943. }
  944. static int ath10k_stop_cac(struct ath10k *ar)
  945. {
  946. lockdep_assert_held(&ar->conf_mutex);
  947. /* CAC is not running - do nothing */
  948. if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
  949. return 0;
  950. clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  951. ath10k_monitor_stop(ar);
  952. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
  953. return 0;
  954. }
  955. static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
  956. struct ieee80211_chanctx_conf *conf,
  957. void *data)
  958. {
  959. bool *ret = data;
  960. if (!*ret && conf->radar_enabled)
  961. *ret = true;
  962. }
  963. static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
  964. {
  965. bool has_radar = false;
  966. ieee80211_iter_chan_contexts_atomic(ar->hw,
  967. ath10k_mac_has_radar_iter,
  968. &has_radar);
  969. return has_radar;
  970. }
  971. static void ath10k_recalc_radar_detection(struct ath10k *ar)
  972. {
  973. int ret;
  974. lockdep_assert_held(&ar->conf_mutex);
  975. ath10k_stop_cac(ar);
  976. if (!ath10k_mac_has_radar_enabled(ar))
  977. return;
  978. if (ar->num_started_vdevs > 0)
  979. return;
  980. ret = ath10k_start_cac(ar);
  981. if (ret) {
  982. /*
  983. * Not possible to start CAC on current channel so starting
  984. * radiation is not allowed, make this channel DFS_UNAVAILABLE
  985. * by indicating that radar was detected.
  986. */
  987. ath10k_warn(ar, "failed to start CAC: %d\n", ret);
  988. ieee80211_radar_detected(ar->hw);
  989. }
  990. }
  991. static int ath10k_vdev_stop(struct ath10k_vif *arvif)
  992. {
  993. struct ath10k *ar = arvif->ar;
  994. int ret;
  995. lockdep_assert_held(&ar->conf_mutex);
  996. reinit_completion(&ar->vdev_setup_done);
  997. ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
  998. if (ret) {
  999. ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
  1000. arvif->vdev_id, ret);
  1001. return ret;
  1002. }
  1003. ret = ath10k_vdev_setup_sync(ar);
  1004. if (ret) {
  1005. ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
  1006. arvif->vdev_id, ret);
  1007. return ret;
  1008. }
  1009. WARN_ON(ar->num_started_vdevs == 0);
  1010. if (ar->num_started_vdevs != 0) {
  1011. ar->num_started_vdevs--;
  1012. ath10k_recalc_radar_detection(ar);
  1013. }
  1014. return ret;
  1015. }
  1016. static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
  1017. const struct cfg80211_chan_def *chandef,
  1018. bool restart)
  1019. {
  1020. struct ath10k *ar = arvif->ar;
  1021. struct wmi_vdev_start_request_arg arg = {};
  1022. int ret = 0;
  1023. lockdep_assert_held(&ar->conf_mutex);
  1024. reinit_completion(&ar->vdev_setup_done);
  1025. arg.vdev_id = arvif->vdev_id;
  1026. arg.dtim_period = arvif->dtim_period;
  1027. arg.bcn_intval = arvif->beacon_interval;
  1028. arg.channel.freq = chandef->chan->center_freq;
  1029. arg.channel.band_center_freq1 = chandef->center_freq1;
  1030. arg.channel.mode = chan_to_phymode(chandef);
  1031. arg.channel.min_power = 0;
  1032. arg.channel.max_power = chandef->chan->max_power * 2;
  1033. arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
  1034. arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
  1035. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  1036. arg.ssid = arvif->u.ap.ssid;
  1037. arg.ssid_len = arvif->u.ap.ssid_len;
  1038. arg.hidden_ssid = arvif->u.ap.hidden_ssid;
  1039. /* For now allow DFS for AP mode */
  1040. arg.channel.chan_radar =
  1041. !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
  1042. } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  1043. arg.ssid = arvif->vif->bss_conf.ssid;
  1044. arg.ssid_len = arvif->vif->bss_conf.ssid_len;
  1045. }
  1046. ath10k_dbg(ar, ATH10K_DBG_MAC,
  1047. "mac vdev %d start center_freq %d phymode %s\n",
  1048. arg.vdev_id, arg.channel.freq,
  1049. ath10k_wmi_phymode_str(arg.channel.mode));
  1050. if (restart)
  1051. ret = ath10k_wmi_vdev_restart(ar, &arg);
  1052. else
  1053. ret = ath10k_wmi_vdev_start(ar, &arg);
  1054. if (ret) {
  1055. ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
  1056. arg.vdev_id, ret);
  1057. return ret;
  1058. }
  1059. ret = ath10k_vdev_setup_sync(ar);
  1060. if (ret) {
  1061. ath10k_warn(ar,
  1062. "failed to synchronize setup for vdev %i restart %d: %d\n",
  1063. arg.vdev_id, restart, ret);
  1064. return ret;
  1065. }
  1066. ar->num_started_vdevs++;
  1067. ath10k_recalc_radar_detection(ar);
  1068. return ret;
  1069. }
  1070. static int ath10k_vdev_start(struct ath10k_vif *arvif,
  1071. const struct cfg80211_chan_def *def)
  1072. {
  1073. return ath10k_vdev_start_restart(arvif, def, false);
  1074. }
  1075. static int ath10k_vdev_restart(struct ath10k_vif *arvif,
  1076. const struct cfg80211_chan_def *def)
  1077. {
  1078. return ath10k_vdev_start_restart(arvif, def, true);
  1079. }
  1080. static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
  1081. struct sk_buff *bcn)
  1082. {
  1083. struct ath10k *ar = arvif->ar;
  1084. struct ieee80211_mgmt *mgmt;
  1085. const u8 *p2p_ie;
  1086. int ret;
  1087. if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
  1088. return 0;
  1089. mgmt = (void *)bcn->data;
  1090. p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
  1091. mgmt->u.beacon.variable,
  1092. bcn->len - (mgmt->u.beacon.variable -
  1093. bcn->data));
  1094. if (!p2p_ie)
  1095. return -ENOENT;
  1096. ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
  1097. if (ret) {
  1098. ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
  1099. arvif->vdev_id, ret);
  1100. return ret;
  1101. }
  1102. return 0;
  1103. }
  1104. static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
  1105. u8 oui_type, size_t ie_offset)
  1106. {
  1107. size_t len;
  1108. const u8 *next;
  1109. const u8 *end;
  1110. u8 *ie;
  1111. if (WARN_ON(skb->len < ie_offset))
  1112. return -EINVAL;
  1113. ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
  1114. skb->data + ie_offset,
  1115. skb->len - ie_offset);
  1116. if (!ie)
  1117. return -ENOENT;
  1118. len = ie[1] + 2;
  1119. end = skb->data + skb->len;
  1120. next = ie + len;
  1121. if (WARN_ON(next > end))
  1122. return -EINVAL;
  1123. memmove(ie, next, end - next);
  1124. skb_trim(skb, skb->len - len);
  1125. return 0;
  1126. }
  1127. static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
  1128. {
  1129. struct ath10k *ar = arvif->ar;
  1130. struct ieee80211_hw *hw = ar->hw;
  1131. struct ieee80211_vif *vif = arvif->vif;
  1132. struct ieee80211_mutable_offsets offs = {};
  1133. struct sk_buff *bcn;
  1134. int ret;
  1135. if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
  1136. return 0;
  1137. if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
  1138. arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
  1139. return 0;
  1140. bcn = ieee80211_beacon_get_template(hw, vif, &offs);
  1141. if (!bcn) {
  1142. ath10k_warn(ar, "failed to get beacon template from mac80211\n");
  1143. return -EPERM;
  1144. }
  1145. ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
  1146. if (ret) {
  1147. ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
  1148. kfree_skb(bcn);
  1149. return ret;
  1150. }
  1151. /* P2P IE is inserted by firmware automatically (as configured above)
  1152. * so remove it from the base beacon template to avoid duplicate P2P
  1153. * IEs in beacon frames.
  1154. */
  1155. ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
  1156. offsetof(struct ieee80211_mgmt,
  1157. u.beacon.variable));
  1158. ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
  1159. 0, NULL, 0);
  1160. kfree_skb(bcn);
  1161. if (ret) {
  1162. ath10k_warn(ar, "failed to submit beacon template command: %d\n",
  1163. ret);
  1164. return ret;
  1165. }
  1166. return 0;
  1167. }
  1168. static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
  1169. {
  1170. struct ath10k *ar = arvif->ar;
  1171. struct ieee80211_hw *hw = ar->hw;
  1172. struct ieee80211_vif *vif = arvif->vif;
  1173. struct sk_buff *prb;
  1174. int ret;
  1175. if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
  1176. return 0;
  1177. if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
  1178. return 0;
  1179. prb = ieee80211_proberesp_get(hw, vif);
  1180. if (!prb) {
  1181. ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
  1182. return -EPERM;
  1183. }
  1184. ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
  1185. kfree_skb(prb);
  1186. if (ret) {
  1187. ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
  1188. ret);
  1189. return ret;
  1190. }
  1191. return 0;
  1192. }
  1193. static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
  1194. {
  1195. struct ath10k *ar = arvif->ar;
  1196. struct cfg80211_chan_def def;
  1197. int ret;
  1198. /* When originally vdev is started during assign_vif_chanctx() some
  1199. * information is missing, notably SSID. Firmware revisions with beacon
  1200. * offloading require the SSID to be provided during vdev (re)start to
  1201. * handle hidden SSID properly.
  1202. *
  1203. * Vdev restart must be done after vdev has been both started and
  1204. * upped. Otherwise some firmware revisions (at least 10.2) fail to
  1205. * deliver vdev restart response event causing timeouts during vdev
  1206. * syncing in ath10k.
  1207. *
  1208. * Note: The vdev down/up and template reinstallation could be skipped
  1209. * since only wmi-tlv firmware are known to have beacon offload and
  1210. * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
  1211. * response delivery. It's probably more robust to keep it as is.
  1212. */
  1213. if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
  1214. return 0;
  1215. if (WARN_ON(!arvif->is_started))
  1216. return -EINVAL;
  1217. if (WARN_ON(!arvif->is_up))
  1218. return -EINVAL;
  1219. if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
  1220. return -EINVAL;
  1221. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  1222. if (ret) {
  1223. ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
  1224. arvif->vdev_id, ret);
  1225. return ret;
  1226. }
  1227. /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
  1228. * firmware will crash upon vdev up.
  1229. */
  1230. ret = ath10k_mac_setup_bcn_tmpl(arvif);
  1231. if (ret) {
  1232. ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
  1233. return ret;
  1234. }
  1235. ret = ath10k_mac_setup_prb_tmpl(arvif);
  1236. if (ret) {
  1237. ath10k_warn(ar, "failed to update presp template: %d\n", ret);
  1238. return ret;
  1239. }
  1240. ret = ath10k_vdev_restart(arvif, &def);
  1241. if (ret) {
  1242. ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
  1243. arvif->vdev_id, ret);
  1244. return ret;
  1245. }
  1246. ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
  1247. arvif->bssid);
  1248. if (ret) {
  1249. ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
  1250. arvif->vdev_id, ret);
  1251. return ret;
  1252. }
  1253. return 0;
  1254. }
  1255. static void ath10k_control_beaconing(struct ath10k_vif *arvif,
  1256. struct ieee80211_bss_conf *info)
  1257. {
  1258. struct ath10k *ar = arvif->ar;
  1259. int ret = 0;
  1260. lockdep_assert_held(&arvif->ar->conf_mutex);
  1261. if (!info->enable_beacon) {
  1262. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  1263. if (ret)
  1264. ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
  1265. arvif->vdev_id, ret);
  1266. arvif->is_up = false;
  1267. spin_lock_bh(&arvif->ar->data_lock);
  1268. ath10k_mac_vif_beacon_free(arvif);
  1269. spin_unlock_bh(&arvif->ar->data_lock);
  1270. return;
  1271. }
  1272. arvif->tx_seq_no = 0x1000;
  1273. arvif->aid = 0;
  1274. ether_addr_copy(arvif->bssid, info->bssid);
  1275. ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
  1276. arvif->bssid);
  1277. if (ret) {
  1278. ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
  1279. arvif->vdev_id, ret);
  1280. return;
  1281. }
  1282. arvif->is_up = true;
  1283. ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
  1284. if (ret) {
  1285. ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
  1286. arvif->vdev_id, ret);
  1287. return;
  1288. }
  1289. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
  1290. }
  1291. static void ath10k_control_ibss(struct ath10k_vif *arvif,
  1292. struct ieee80211_bss_conf *info,
  1293. const u8 self_peer[ETH_ALEN])
  1294. {
  1295. struct ath10k *ar = arvif->ar;
  1296. u32 vdev_param;
  1297. int ret = 0;
  1298. lockdep_assert_held(&arvif->ar->conf_mutex);
  1299. if (!info->ibss_joined) {
  1300. if (is_zero_ether_addr(arvif->bssid))
  1301. return;
  1302. eth_zero_addr(arvif->bssid);
  1303. return;
  1304. }
  1305. vdev_param = arvif->ar->wmi.vdev_param->atim_window;
  1306. ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
  1307. ATH10K_DEFAULT_ATIM);
  1308. if (ret)
  1309. ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
  1310. arvif->vdev_id, ret);
  1311. }
  1312. static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
  1313. {
  1314. struct ath10k *ar = arvif->ar;
  1315. u32 param;
  1316. u32 value;
  1317. int ret;
  1318. lockdep_assert_held(&arvif->ar->conf_mutex);
  1319. if (arvif->u.sta.uapsd)
  1320. value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
  1321. else
  1322. value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
  1323. param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
  1324. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
  1325. if (ret) {
  1326. ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
  1327. value, arvif->vdev_id, ret);
  1328. return ret;
  1329. }
  1330. return 0;
  1331. }
  1332. static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
  1333. {
  1334. struct ath10k *ar = arvif->ar;
  1335. u32 param;
  1336. u32 value;
  1337. int ret;
  1338. lockdep_assert_held(&arvif->ar->conf_mutex);
  1339. if (arvif->u.sta.uapsd)
  1340. value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
  1341. else
  1342. value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
  1343. param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
  1344. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  1345. param, value);
  1346. if (ret) {
  1347. ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
  1348. value, arvif->vdev_id, ret);
  1349. return ret;
  1350. }
  1351. return 0;
  1352. }
  1353. static int ath10k_mac_num_vifs_started(struct ath10k *ar)
  1354. {
  1355. struct ath10k_vif *arvif;
  1356. int num = 0;
  1357. lockdep_assert_held(&ar->conf_mutex);
  1358. list_for_each_entry(arvif, &ar->arvifs, list)
  1359. if (arvif->is_started)
  1360. num++;
  1361. return num;
  1362. }
  1363. static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
  1364. {
  1365. struct ath10k *ar = arvif->ar;
  1366. struct ieee80211_vif *vif = arvif->vif;
  1367. struct ieee80211_conf *conf = &ar->hw->conf;
  1368. enum wmi_sta_powersave_param param;
  1369. enum wmi_sta_ps_mode psmode;
  1370. int ret;
  1371. int ps_timeout;
  1372. bool enable_ps;
  1373. lockdep_assert_held(&arvif->ar->conf_mutex);
  1374. if (arvif->vif->type != NL80211_IFTYPE_STATION)
  1375. return 0;
  1376. enable_ps = arvif->ps;
  1377. if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
  1378. !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
  1379. ar->fw_features)) {
  1380. ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
  1381. arvif->vdev_id);
  1382. enable_ps = false;
  1383. }
  1384. if (!arvif->is_started) {
  1385. /* mac80211 can update vif powersave state while disconnected.
  1386. * Firmware doesn't behave nicely and consumes more power than
  1387. * necessary if PS is disabled on a non-started vdev. Hence
  1388. * force-enable PS for non-running vdevs.
  1389. */
  1390. psmode = WMI_STA_PS_MODE_ENABLED;
  1391. } else if (enable_ps) {
  1392. psmode = WMI_STA_PS_MODE_ENABLED;
  1393. param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
  1394. ps_timeout = conf->dynamic_ps_timeout;
  1395. if (ps_timeout == 0) {
  1396. /* Firmware doesn't like 0 */
  1397. ps_timeout = ieee80211_tu_to_usec(
  1398. vif->bss_conf.beacon_int) / 1000;
  1399. }
  1400. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
  1401. ps_timeout);
  1402. if (ret) {
  1403. ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
  1404. arvif->vdev_id, ret);
  1405. return ret;
  1406. }
  1407. } else {
  1408. psmode = WMI_STA_PS_MODE_DISABLED;
  1409. }
  1410. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
  1411. arvif->vdev_id, psmode ? "enable" : "disable");
  1412. ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
  1413. if (ret) {
  1414. ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
  1415. psmode, arvif->vdev_id, ret);
  1416. return ret;
  1417. }
  1418. return 0;
  1419. }
  1420. static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
  1421. {
  1422. struct ath10k *ar = arvif->ar;
  1423. struct wmi_sta_keepalive_arg arg = {};
  1424. int ret;
  1425. lockdep_assert_held(&arvif->ar->conf_mutex);
  1426. if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
  1427. return 0;
  1428. if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
  1429. return 0;
  1430. /* Some firmware revisions have a bug and ignore the `enabled` field.
  1431. * Instead use the interval to disable the keepalive.
  1432. */
  1433. arg.vdev_id = arvif->vdev_id;
  1434. arg.enabled = 1;
  1435. arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
  1436. arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
  1437. ret = ath10k_wmi_sta_keepalive(ar, &arg);
  1438. if (ret) {
  1439. ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
  1440. arvif->vdev_id, ret);
  1441. return ret;
  1442. }
  1443. return 0;
  1444. }
  1445. static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
  1446. {
  1447. struct ath10k *ar = arvif->ar;
  1448. struct ieee80211_vif *vif = arvif->vif;
  1449. int ret;
  1450. lockdep_assert_held(&arvif->ar->conf_mutex);
  1451. if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
  1452. return;
  1453. if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
  1454. return;
  1455. if (!vif->csa_active)
  1456. return;
  1457. if (!arvif->is_up)
  1458. return;
  1459. if (!ieee80211_csa_is_complete(vif)) {
  1460. ieee80211_csa_update_counter(vif);
  1461. ret = ath10k_mac_setup_bcn_tmpl(arvif);
  1462. if (ret)
  1463. ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
  1464. ret);
  1465. ret = ath10k_mac_setup_prb_tmpl(arvif);
  1466. if (ret)
  1467. ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
  1468. ret);
  1469. } else {
  1470. ieee80211_csa_finish(vif);
  1471. }
  1472. }
  1473. static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
  1474. {
  1475. struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
  1476. ap_csa_work);
  1477. struct ath10k *ar = arvif->ar;
  1478. mutex_lock(&ar->conf_mutex);
  1479. ath10k_mac_vif_ap_csa_count_down(arvif);
  1480. mutex_unlock(&ar->conf_mutex);
  1481. }
  1482. static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
  1483. struct ieee80211_vif *vif)
  1484. {
  1485. struct sk_buff *skb = data;
  1486. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1487. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1488. if (vif->type != NL80211_IFTYPE_STATION)
  1489. return;
  1490. if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
  1491. return;
  1492. cancel_delayed_work(&arvif->connection_loss_work);
  1493. }
  1494. void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
  1495. {
  1496. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  1497. IEEE80211_IFACE_ITER_NORMAL,
  1498. ath10k_mac_handle_beacon_iter,
  1499. skb);
  1500. }
  1501. static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
  1502. struct ieee80211_vif *vif)
  1503. {
  1504. u32 *vdev_id = data;
  1505. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1506. struct ath10k *ar = arvif->ar;
  1507. struct ieee80211_hw *hw = ar->hw;
  1508. if (arvif->vdev_id != *vdev_id)
  1509. return;
  1510. if (!arvif->is_up)
  1511. return;
  1512. ieee80211_beacon_loss(vif);
  1513. /* Firmware doesn't report beacon loss events repeatedly. If AP probe
  1514. * (done by mac80211) succeeds but beacons do not resume then it
  1515. * doesn't make sense to continue operation. Queue connection loss work
  1516. * which can be cancelled when beacon is received.
  1517. */
  1518. ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
  1519. ATH10K_CONNECTION_LOSS_HZ);
  1520. }
  1521. void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
  1522. {
  1523. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  1524. IEEE80211_IFACE_ITER_NORMAL,
  1525. ath10k_mac_handle_beacon_miss_iter,
  1526. &vdev_id);
  1527. }
  1528. static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
  1529. {
  1530. struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
  1531. connection_loss_work.work);
  1532. struct ieee80211_vif *vif = arvif->vif;
  1533. if (!arvif->is_up)
  1534. return;
  1535. ieee80211_connection_loss(vif);
  1536. }
  1537. /**********************/
  1538. /* Station management */
  1539. /**********************/
  1540. static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
  1541. struct ieee80211_vif *vif)
  1542. {
  1543. /* Some firmware revisions have unstable STA powersave when listen
  1544. * interval is set too high (e.g. 5). The symptoms are firmware doesn't
  1545. * generate NullFunc frames properly even if buffered frames have been
  1546. * indicated in Beacon TIM. Firmware would seldom wake up to pull
  1547. * buffered frames. Often pinging the device from AP would simply fail.
  1548. *
  1549. * As a workaround set it to 1.
  1550. */
  1551. if (vif->type == NL80211_IFTYPE_STATION)
  1552. return 1;
  1553. return ar->hw->conf.listen_interval;
  1554. }
  1555. static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
  1556. struct ieee80211_vif *vif,
  1557. struct ieee80211_sta *sta,
  1558. struct wmi_peer_assoc_complete_arg *arg)
  1559. {
  1560. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1561. u32 aid;
  1562. lockdep_assert_held(&ar->conf_mutex);
  1563. if (vif->type == NL80211_IFTYPE_STATION)
  1564. aid = vif->bss_conf.aid;
  1565. else
  1566. aid = sta->aid;
  1567. ether_addr_copy(arg->addr, sta->addr);
  1568. arg->vdev_id = arvif->vdev_id;
  1569. arg->peer_aid = aid;
  1570. arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
  1571. arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
  1572. arg->peer_num_spatial_streams = 1;
  1573. arg->peer_caps = vif->bss_conf.assoc_capability;
  1574. }
  1575. static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
  1576. struct ieee80211_vif *vif,
  1577. struct ieee80211_sta *sta,
  1578. struct wmi_peer_assoc_complete_arg *arg)
  1579. {
  1580. struct ieee80211_bss_conf *info = &vif->bss_conf;
  1581. struct cfg80211_chan_def def;
  1582. struct cfg80211_bss *bss;
  1583. const u8 *rsnie = NULL;
  1584. const u8 *wpaie = NULL;
  1585. lockdep_assert_held(&ar->conf_mutex);
  1586. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  1587. return;
  1588. bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
  1589. IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
  1590. if (bss) {
  1591. const struct cfg80211_bss_ies *ies;
  1592. rcu_read_lock();
  1593. rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
  1594. ies = rcu_dereference(bss->ies);
  1595. wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
  1596. WLAN_OUI_TYPE_MICROSOFT_WPA,
  1597. ies->data,
  1598. ies->len);
  1599. rcu_read_unlock();
  1600. cfg80211_put_bss(ar->hw->wiphy, bss);
  1601. }
  1602. /* FIXME: base on RSN IE/WPA IE is a correct idea? */
  1603. if (rsnie || wpaie) {
  1604. ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
  1605. arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
  1606. }
  1607. if (wpaie) {
  1608. ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
  1609. arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
  1610. }
  1611. if (sta->mfp &&
  1612. test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT, ar->fw_features)) {
  1613. arg->peer_flags |= ar->wmi.peer_flags->pmf;
  1614. }
  1615. }
  1616. static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
  1617. struct ieee80211_vif *vif,
  1618. struct ieee80211_sta *sta,
  1619. struct wmi_peer_assoc_complete_arg *arg)
  1620. {
  1621. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1622. struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
  1623. struct cfg80211_chan_def def;
  1624. const struct ieee80211_supported_band *sband;
  1625. const struct ieee80211_rate *rates;
  1626. enum ieee80211_band band;
  1627. u32 ratemask;
  1628. u8 rate;
  1629. int i;
  1630. lockdep_assert_held(&ar->conf_mutex);
  1631. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  1632. return;
  1633. band = def.chan->band;
  1634. sband = ar->hw->wiphy->bands[band];
  1635. ratemask = sta->supp_rates[band];
  1636. ratemask &= arvif->bitrate_mask.control[band].legacy;
  1637. rates = sband->bitrates;
  1638. rateset->num_rates = 0;
  1639. for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
  1640. if (!(ratemask & 1))
  1641. continue;
  1642. rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
  1643. rateset->rates[rateset->num_rates] = rate;
  1644. rateset->num_rates++;
  1645. }
  1646. }
  1647. static bool
  1648. ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
  1649. {
  1650. int nss;
  1651. for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
  1652. if (ht_mcs_mask[nss])
  1653. return false;
  1654. return true;
  1655. }
  1656. static bool
  1657. ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
  1658. {
  1659. int nss;
  1660. for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
  1661. if (vht_mcs_mask[nss])
  1662. return false;
  1663. return true;
  1664. }
  1665. static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
  1666. struct ieee80211_vif *vif,
  1667. struct ieee80211_sta *sta,
  1668. struct wmi_peer_assoc_complete_arg *arg)
  1669. {
  1670. const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1671. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1672. struct cfg80211_chan_def def;
  1673. enum ieee80211_band band;
  1674. const u8 *ht_mcs_mask;
  1675. const u16 *vht_mcs_mask;
  1676. int i, n;
  1677. u8 max_nss;
  1678. u32 stbc;
  1679. lockdep_assert_held(&ar->conf_mutex);
  1680. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  1681. return;
  1682. if (!ht_cap->ht_supported)
  1683. return;
  1684. band = def.chan->band;
  1685. ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
  1686. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  1687. if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
  1688. ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
  1689. return;
  1690. arg->peer_flags |= ar->wmi.peer_flags->ht;
  1691. arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  1692. ht_cap->ampdu_factor)) - 1;
  1693. arg->peer_mpdu_density =
  1694. ath10k_parse_mpdudensity(ht_cap->ampdu_density);
  1695. arg->peer_ht_caps = ht_cap->cap;
  1696. arg->peer_rate_caps |= WMI_RC_HT_FLAG;
  1697. if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
  1698. arg->peer_flags |= ar->wmi.peer_flags->ldbc;
  1699. if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
  1700. arg->peer_flags |= ar->wmi.peer_flags->bw40;
  1701. arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
  1702. }
  1703. if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
  1704. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
  1705. arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
  1706. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
  1707. arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
  1708. }
  1709. if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
  1710. arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
  1711. arg->peer_flags |= ar->wmi.peer_flags->stbc;
  1712. }
  1713. if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
  1714. stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
  1715. stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
  1716. stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
  1717. arg->peer_rate_caps |= stbc;
  1718. arg->peer_flags |= ar->wmi.peer_flags->stbc;
  1719. }
  1720. if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
  1721. arg->peer_rate_caps |= WMI_RC_TS_FLAG;
  1722. else if (ht_cap->mcs.rx_mask[1])
  1723. arg->peer_rate_caps |= WMI_RC_DS_FLAG;
  1724. for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
  1725. if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
  1726. (ht_mcs_mask[i / 8] & BIT(i % 8))) {
  1727. max_nss = (i / 8) + 1;
  1728. arg->peer_ht_rates.rates[n++] = i;
  1729. }
  1730. /*
  1731. * This is a workaround for HT-enabled STAs which break the spec
  1732. * and have no HT capabilities RX mask (no HT RX MCS map).
  1733. *
  1734. * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
  1735. * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
  1736. *
  1737. * Firmware asserts if such situation occurs.
  1738. */
  1739. if (n == 0) {
  1740. arg->peer_ht_rates.num_rates = 8;
  1741. for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
  1742. arg->peer_ht_rates.rates[i] = i;
  1743. } else {
  1744. arg->peer_ht_rates.num_rates = n;
  1745. arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
  1746. }
  1747. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
  1748. arg->addr,
  1749. arg->peer_ht_rates.num_rates,
  1750. arg->peer_num_spatial_streams);
  1751. }
  1752. static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
  1753. struct ath10k_vif *arvif,
  1754. struct ieee80211_sta *sta)
  1755. {
  1756. u32 uapsd = 0;
  1757. u32 max_sp = 0;
  1758. int ret = 0;
  1759. lockdep_assert_held(&ar->conf_mutex);
  1760. if (sta->wme && sta->uapsd_queues) {
  1761. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
  1762. sta->uapsd_queues, sta->max_sp);
  1763. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  1764. uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
  1765. WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
  1766. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  1767. uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
  1768. WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
  1769. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  1770. uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
  1771. WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
  1772. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  1773. uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
  1774. WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
  1775. if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
  1776. max_sp = sta->max_sp;
  1777. ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
  1778. sta->addr,
  1779. WMI_AP_PS_PEER_PARAM_UAPSD,
  1780. uapsd);
  1781. if (ret) {
  1782. ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
  1783. arvif->vdev_id, ret);
  1784. return ret;
  1785. }
  1786. ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
  1787. sta->addr,
  1788. WMI_AP_PS_PEER_PARAM_MAX_SP,
  1789. max_sp);
  1790. if (ret) {
  1791. ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
  1792. arvif->vdev_id, ret);
  1793. return ret;
  1794. }
  1795. /* TODO setup this based on STA listen interval and
  1796. beacon interval. Currently we don't know
  1797. sta->listen_interval - mac80211 patch required.
  1798. Currently use 10 seconds */
  1799. ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
  1800. WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
  1801. 10);
  1802. if (ret) {
  1803. ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
  1804. arvif->vdev_id, ret);
  1805. return ret;
  1806. }
  1807. }
  1808. return 0;
  1809. }
  1810. static u16
  1811. ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
  1812. const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
  1813. {
  1814. int idx_limit;
  1815. int nss;
  1816. u16 mcs_map;
  1817. u16 mcs;
  1818. for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
  1819. mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
  1820. vht_mcs_limit[nss];
  1821. if (mcs_map)
  1822. idx_limit = fls(mcs_map) - 1;
  1823. else
  1824. idx_limit = -1;
  1825. switch (idx_limit) {
  1826. case 0: /* fall through */
  1827. case 1: /* fall through */
  1828. case 2: /* fall through */
  1829. case 3: /* fall through */
  1830. case 4: /* fall through */
  1831. case 5: /* fall through */
  1832. case 6: /* fall through */
  1833. default:
  1834. /* see ath10k_mac_can_set_bitrate_mask() */
  1835. WARN_ON(1);
  1836. /* fall through */
  1837. case -1:
  1838. mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  1839. break;
  1840. case 7:
  1841. mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
  1842. break;
  1843. case 8:
  1844. mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
  1845. break;
  1846. case 9:
  1847. mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
  1848. break;
  1849. }
  1850. tx_mcs_set &= ~(0x3 << (nss * 2));
  1851. tx_mcs_set |= mcs << (nss * 2);
  1852. }
  1853. return tx_mcs_set;
  1854. }
  1855. static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
  1856. struct ieee80211_vif *vif,
  1857. struct ieee80211_sta *sta,
  1858. struct wmi_peer_assoc_complete_arg *arg)
  1859. {
  1860. const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  1861. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1862. struct cfg80211_chan_def def;
  1863. enum ieee80211_band band;
  1864. const u16 *vht_mcs_mask;
  1865. u8 ampdu_factor;
  1866. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  1867. return;
  1868. if (!vht_cap->vht_supported)
  1869. return;
  1870. band = def.chan->band;
  1871. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  1872. if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
  1873. return;
  1874. arg->peer_flags |= ar->wmi.peer_flags->vht;
  1875. if (def.chan->band == IEEE80211_BAND_2GHZ)
  1876. arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
  1877. arg->peer_vht_caps = vht_cap->cap;
  1878. ampdu_factor = (vht_cap->cap &
  1879. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
  1880. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  1881. /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
  1882. * zero in VHT IE. Using it would result in degraded throughput.
  1883. * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
  1884. * it if VHT max_mpdu is smaller. */
  1885. arg->peer_max_mpdu = max(arg->peer_max_mpdu,
  1886. (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  1887. ampdu_factor)) - 1);
  1888. if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
  1889. arg->peer_flags |= ar->wmi.peer_flags->bw80;
  1890. arg->peer_vht_rates.rx_max_rate =
  1891. __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
  1892. arg->peer_vht_rates.rx_mcs_set =
  1893. __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  1894. arg->peer_vht_rates.tx_max_rate =
  1895. __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
  1896. arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
  1897. __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
  1898. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
  1899. sta->addr, arg->peer_max_mpdu, arg->peer_flags);
  1900. }
  1901. static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
  1902. struct ieee80211_vif *vif,
  1903. struct ieee80211_sta *sta,
  1904. struct wmi_peer_assoc_complete_arg *arg)
  1905. {
  1906. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1907. switch (arvif->vdev_type) {
  1908. case WMI_VDEV_TYPE_AP:
  1909. if (sta->wme)
  1910. arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
  1911. if (sta->wme && sta->uapsd_queues) {
  1912. arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
  1913. arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
  1914. }
  1915. break;
  1916. case WMI_VDEV_TYPE_STA:
  1917. if (vif->bss_conf.qos)
  1918. arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
  1919. break;
  1920. case WMI_VDEV_TYPE_IBSS:
  1921. if (sta->wme)
  1922. arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
  1923. break;
  1924. default:
  1925. break;
  1926. }
  1927. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
  1928. sta->addr, !!(arg->peer_flags &
  1929. arvif->ar->wmi.peer_flags->qos));
  1930. }
  1931. static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
  1932. {
  1933. return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
  1934. ATH10K_MAC_FIRST_OFDM_RATE_IDX;
  1935. }
  1936. static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
  1937. struct ieee80211_vif *vif,
  1938. struct ieee80211_sta *sta,
  1939. struct wmi_peer_assoc_complete_arg *arg)
  1940. {
  1941. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1942. struct cfg80211_chan_def def;
  1943. enum ieee80211_band band;
  1944. const u8 *ht_mcs_mask;
  1945. const u16 *vht_mcs_mask;
  1946. enum wmi_phy_mode phymode = MODE_UNKNOWN;
  1947. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  1948. return;
  1949. band = def.chan->band;
  1950. ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
  1951. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  1952. switch (band) {
  1953. case IEEE80211_BAND_2GHZ:
  1954. if (sta->vht_cap.vht_supported &&
  1955. !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
  1956. if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
  1957. phymode = MODE_11AC_VHT40;
  1958. else
  1959. phymode = MODE_11AC_VHT20;
  1960. } else if (sta->ht_cap.ht_supported &&
  1961. !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
  1962. if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
  1963. phymode = MODE_11NG_HT40;
  1964. else
  1965. phymode = MODE_11NG_HT20;
  1966. } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
  1967. phymode = MODE_11G;
  1968. } else {
  1969. phymode = MODE_11B;
  1970. }
  1971. break;
  1972. case IEEE80211_BAND_5GHZ:
  1973. /*
  1974. * Check VHT first.
  1975. */
  1976. if (sta->vht_cap.vht_supported &&
  1977. !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
  1978. if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
  1979. phymode = MODE_11AC_VHT80;
  1980. else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
  1981. phymode = MODE_11AC_VHT40;
  1982. else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
  1983. phymode = MODE_11AC_VHT20;
  1984. } else if (sta->ht_cap.ht_supported &&
  1985. !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
  1986. if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
  1987. phymode = MODE_11NA_HT40;
  1988. else
  1989. phymode = MODE_11NA_HT20;
  1990. } else {
  1991. phymode = MODE_11A;
  1992. }
  1993. break;
  1994. default:
  1995. break;
  1996. }
  1997. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
  1998. sta->addr, ath10k_wmi_phymode_str(phymode));
  1999. arg->peer_phymode = phymode;
  2000. WARN_ON(phymode == MODE_UNKNOWN);
  2001. }
  2002. static int ath10k_peer_assoc_prepare(struct ath10k *ar,
  2003. struct ieee80211_vif *vif,
  2004. struct ieee80211_sta *sta,
  2005. struct wmi_peer_assoc_complete_arg *arg)
  2006. {
  2007. lockdep_assert_held(&ar->conf_mutex);
  2008. memset(arg, 0, sizeof(*arg));
  2009. ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
  2010. ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
  2011. ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
  2012. ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
  2013. ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
  2014. ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
  2015. ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
  2016. return 0;
  2017. }
  2018. static const u32 ath10k_smps_map[] = {
  2019. [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
  2020. [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
  2021. [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
  2022. [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
  2023. };
  2024. static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
  2025. const u8 *addr,
  2026. const struct ieee80211_sta_ht_cap *ht_cap)
  2027. {
  2028. int smps;
  2029. if (!ht_cap->ht_supported)
  2030. return 0;
  2031. smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
  2032. smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
  2033. if (smps >= ARRAY_SIZE(ath10k_smps_map))
  2034. return -EINVAL;
  2035. return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
  2036. WMI_PEER_SMPS_STATE,
  2037. ath10k_smps_map[smps]);
  2038. }
  2039. static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
  2040. struct ieee80211_vif *vif,
  2041. struct ieee80211_sta_vht_cap vht_cap)
  2042. {
  2043. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2044. int ret;
  2045. u32 param;
  2046. u32 value;
  2047. if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
  2048. return 0;
  2049. if (!(ar->vht_cap_info &
  2050. (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  2051. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
  2052. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  2053. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
  2054. return 0;
  2055. param = ar->wmi.vdev_param->txbf;
  2056. value = 0;
  2057. if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
  2058. return 0;
  2059. /* The following logic is correct. If a remote STA advertises support
  2060. * for being a beamformer then we should enable us being a beamformee.
  2061. */
  2062. if (ar->vht_cap_info &
  2063. (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  2064. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
  2065. if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
  2066. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
  2067. if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
  2068. value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
  2069. }
  2070. if (ar->vht_cap_info &
  2071. (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  2072. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
  2073. if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
  2074. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
  2075. if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
  2076. value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
  2077. }
  2078. if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
  2079. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
  2080. if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
  2081. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
  2082. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
  2083. if (ret) {
  2084. ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
  2085. value, ret);
  2086. return ret;
  2087. }
  2088. return 0;
  2089. }
  2090. /* can be called only in mac80211 callbacks due to `key_count` usage */
  2091. static void ath10k_bss_assoc(struct ieee80211_hw *hw,
  2092. struct ieee80211_vif *vif,
  2093. struct ieee80211_bss_conf *bss_conf)
  2094. {
  2095. struct ath10k *ar = hw->priv;
  2096. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2097. struct ieee80211_sta_ht_cap ht_cap;
  2098. struct ieee80211_sta_vht_cap vht_cap;
  2099. struct wmi_peer_assoc_complete_arg peer_arg;
  2100. struct ieee80211_sta *ap_sta;
  2101. int ret;
  2102. lockdep_assert_held(&ar->conf_mutex);
  2103. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
  2104. arvif->vdev_id, arvif->bssid, arvif->aid);
  2105. rcu_read_lock();
  2106. ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
  2107. if (!ap_sta) {
  2108. ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
  2109. bss_conf->bssid, arvif->vdev_id);
  2110. rcu_read_unlock();
  2111. return;
  2112. }
  2113. /* ap_sta must be accessed only within rcu section which must be left
  2114. * before calling ath10k_setup_peer_smps() which might sleep. */
  2115. ht_cap = ap_sta->ht_cap;
  2116. vht_cap = ap_sta->vht_cap;
  2117. ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
  2118. if (ret) {
  2119. ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
  2120. bss_conf->bssid, arvif->vdev_id, ret);
  2121. rcu_read_unlock();
  2122. return;
  2123. }
  2124. rcu_read_unlock();
  2125. ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
  2126. if (ret) {
  2127. ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
  2128. bss_conf->bssid, arvif->vdev_id, ret);
  2129. return;
  2130. }
  2131. ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
  2132. if (ret) {
  2133. ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
  2134. arvif->vdev_id, ret);
  2135. return;
  2136. }
  2137. ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
  2138. if (ret) {
  2139. ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
  2140. arvif->vdev_id, bss_conf->bssid, ret);
  2141. return;
  2142. }
  2143. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2144. "mac vdev %d up (associated) bssid %pM aid %d\n",
  2145. arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
  2146. WARN_ON(arvif->is_up);
  2147. arvif->aid = bss_conf->aid;
  2148. ether_addr_copy(arvif->bssid, bss_conf->bssid);
  2149. ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
  2150. if (ret) {
  2151. ath10k_warn(ar, "failed to set vdev %d up: %d\n",
  2152. arvif->vdev_id, ret);
  2153. return;
  2154. }
  2155. arvif->is_up = true;
  2156. /* Workaround: Some firmware revisions (tested with qca6174
  2157. * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
  2158. * poked with peer param command.
  2159. */
  2160. ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
  2161. WMI_PEER_DUMMY_VAR, 1);
  2162. if (ret) {
  2163. ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
  2164. arvif->bssid, arvif->vdev_id, ret);
  2165. return;
  2166. }
  2167. }
  2168. static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
  2169. struct ieee80211_vif *vif)
  2170. {
  2171. struct ath10k *ar = hw->priv;
  2172. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2173. struct ieee80211_sta_vht_cap vht_cap = {};
  2174. int ret;
  2175. lockdep_assert_held(&ar->conf_mutex);
  2176. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
  2177. arvif->vdev_id, arvif->bssid);
  2178. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  2179. if (ret)
  2180. ath10k_warn(ar, "faield to down vdev %i: %d\n",
  2181. arvif->vdev_id, ret);
  2182. arvif->def_wep_key_idx = -1;
  2183. ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
  2184. if (ret) {
  2185. ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
  2186. arvif->vdev_id, ret);
  2187. return;
  2188. }
  2189. arvif->is_up = false;
  2190. cancel_delayed_work_sync(&arvif->connection_loss_work);
  2191. }
  2192. static int ath10k_station_assoc(struct ath10k *ar,
  2193. struct ieee80211_vif *vif,
  2194. struct ieee80211_sta *sta,
  2195. bool reassoc)
  2196. {
  2197. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2198. struct wmi_peer_assoc_complete_arg peer_arg;
  2199. int ret = 0;
  2200. lockdep_assert_held(&ar->conf_mutex);
  2201. ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
  2202. if (ret) {
  2203. ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
  2204. sta->addr, arvif->vdev_id, ret);
  2205. return ret;
  2206. }
  2207. ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
  2208. if (ret) {
  2209. ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
  2210. sta->addr, arvif->vdev_id, ret);
  2211. return ret;
  2212. }
  2213. /* Re-assoc is run only to update supported rates for given station. It
  2214. * doesn't make much sense to reconfigure the peer completely.
  2215. */
  2216. if (!reassoc) {
  2217. ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
  2218. &sta->ht_cap);
  2219. if (ret) {
  2220. ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
  2221. arvif->vdev_id, ret);
  2222. return ret;
  2223. }
  2224. ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
  2225. if (ret) {
  2226. ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
  2227. sta->addr, arvif->vdev_id, ret);
  2228. return ret;
  2229. }
  2230. if (!sta->wme) {
  2231. arvif->num_legacy_stations++;
  2232. ret = ath10k_recalc_rtscts_prot(arvif);
  2233. if (ret) {
  2234. ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  2235. arvif->vdev_id, ret);
  2236. return ret;
  2237. }
  2238. }
  2239. /* Plumb cached keys only for static WEP */
  2240. if (arvif->def_wep_key_idx != -1) {
  2241. ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
  2242. if (ret) {
  2243. ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
  2244. arvif->vdev_id, ret);
  2245. return ret;
  2246. }
  2247. }
  2248. }
  2249. return ret;
  2250. }
  2251. static int ath10k_station_disassoc(struct ath10k *ar,
  2252. struct ieee80211_vif *vif,
  2253. struct ieee80211_sta *sta)
  2254. {
  2255. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2256. int ret = 0;
  2257. lockdep_assert_held(&ar->conf_mutex);
  2258. if (!sta->wme) {
  2259. arvif->num_legacy_stations--;
  2260. ret = ath10k_recalc_rtscts_prot(arvif);
  2261. if (ret) {
  2262. ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  2263. arvif->vdev_id, ret);
  2264. return ret;
  2265. }
  2266. }
  2267. ret = ath10k_clear_peer_keys(arvif, sta->addr);
  2268. if (ret) {
  2269. ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
  2270. arvif->vdev_id, ret);
  2271. return ret;
  2272. }
  2273. return ret;
  2274. }
  2275. /**************/
  2276. /* Regulatory */
  2277. /**************/
  2278. static int ath10k_update_channel_list(struct ath10k *ar)
  2279. {
  2280. struct ieee80211_hw *hw = ar->hw;
  2281. struct ieee80211_supported_band **bands;
  2282. enum ieee80211_band band;
  2283. struct ieee80211_channel *channel;
  2284. struct wmi_scan_chan_list_arg arg = {0};
  2285. struct wmi_channel_arg *ch;
  2286. bool passive;
  2287. int len;
  2288. int ret;
  2289. int i;
  2290. lockdep_assert_held(&ar->conf_mutex);
  2291. bands = hw->wiphy->bands;
  2292. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  2293. if (!bands[band])
  2294. continue;
  2295. for (i = 0; i < bands[band]->n_channels; i++) {
  2296. if (bands[band]->channels[i].flags &
  2297. IEEE80211_CHAN_DISABLED)
  2298. continue;
  2299. arg.n_channels++;
  2300. }
  2301. }
  2302. len = sizeof(struct wmi_channel_arg) * arg.n_channels;
  2303. arg.channels = kzalloc(len, GFP_KERNEL);
  2304. if (!arg.channels)
  2305. return -ENOMEM;
  2306. ch = arg.channels;
  2307. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  2308. if (!bands[band])
  2309. continue;
  2310. for (i = 0; i < bands[band]->n_channels; i++) {
  2311. channel = &bands[band]->channels[i];
  2312. if (channel->flags & IEEE80211_CHAN_DISABLED)
  2313. continue;
  2314. ch->allow_ht = true;
  2315. /* FIXME: when should we really allow VHT? */
  2316. ch->allow_vht = true;
  2317. ch->allow_ibss =
  2318. !(channel->flags & IEEE80211_CHAN_NO_IR);
  2319. ch->ht40plus =
  2320. !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
  2321. ch->chan_radar =
  2322. !!(channel->flags & IEEE80211_CHAN_RADAR);
  2323. passive = channel->flags & IEEE80211_CHAN_NO_IR;
  2324. ch->passive = passive;
  2325. ch->freq = channel->center_freq;
  2326. ch->band_center_freq1 = channel->center_freq;
  2327. ch->min_power = 0;
  2328. ch->max_power = channel->max_power * 2;
  2329. ch->max_reg_power = channel->max_reg_power * 2;
  2330. ch->max_antenna_gain = channel->max_antenna_gain * 2;
  2331. ch->reg_class_id = 0; /* FIXME */
  2332. /* FIXME: why use only legacy modes, why not any
  2333. * HT/VHT modes? Would that even make any
  2334. * difference? */
  2335. if (channel->band == IEEE80211_BAND_2GHZ)
  2336. ch->mode = MODE_11G;
  2337. else
  2338. ch->mode = MODE_11A;
  2339. if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
  2340. continue;
  2341. ath10k_dbg(ar, ATH10K_DBG_WMI,
  2342. "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
  2343. ch - arg.channels, arg.n_channels,
  2344. ch->freq, ch->max_power, ch->max_reg_power,
  2345. ch->max_antenna_gain, ch->mode);
  2346. ch++;
  2347. }
  2348. }
  2349. ret = ath10k_wmi_scan_chan_list(ar, &arg);
  2350. kfree(arg.channels);
  2351. return ret;
  2352. }
  2353. static enum wmi_dfs_region
  2354. ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
  2355. {
  2356. switch (dfs_region) {
  2357. case NL80211_DFS_UNSET:
  2358. return WMI_UNINIT_DFS_DOMAIN;
  2359. case NL80211_DFS_FCC:
  2360. return WMI_FCC_DFS_DOMAIN;
  2361. case NL80211_DFS_ETSI:
  2362. return WMI_ETSI_DFS_DOMAIN;
  2363. case NL80211_DFS_JP:
  2364. return WMI_MKK4_DFS_DOMAIN;
  2365. }
  2366. return WMI_UNINIT_DFS_DOMAIN;
  2367. }
  2368. static void ath10k_regd_update(struct ath10k *ar)
  2369. {
  2370. struct reg_dmn_pair_mapping *regpair;
  2371. int ret;
  2372. enum wmi_dfs_region wmi_dfs_reg;
  2373. enum nl80211_dfs_regions nl_dfs_reg;
  2374. lockdep_assert_held(&ar->conf_mutex);
  2375. ret = ath10k_update_channel_list(ar);
  2376. if (ret)
  2377. ath10k_warn(ar, "failed to update channel list: %d\n", ret);
  2378. regpair = ar->ath_common.regulatory.regpair;
  2379. if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
  2380. nl_dfs_reg = ar->dfs_detector->region;
  2381. wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
  2382. } else {
  2383. wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
  2384. }
  2385. /* Target allows setting up per-band regdomain but ath_common provides
  2386. * a combined one only */
  2387. ret = ath10k_wmi_pdev_set_regdomain(ar,
  2388. regpair->reg_domain,
  2389. regpair->reg_domain, /* 2ghz */
  2390. regpair->reg_domain, /* 5ghz */
  2391. regpair->reg_2ghz_ctl,
  2392. regpair->reg_5ghz_ctl,
  2393. wmi_dfs_reg);
  2394. if (ret)
  2395. ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
  2396. }
  2397. static void ath10k_reg_notifier(struct wiphy *wiphy,
  2398. struct regulatory_request *request)
  2399. {
  2400. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  2401. struct ath10k *ar = hw->priv;
  2402. bool result;
  2403. ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
  2404. if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
  2405. ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
  2406. request->dfs_region);
  2407. result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
  2408. request->dfs_region);
  2409. if (!result)
  2410. ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
  2411. request->dfs_region);
  2412. }
  2413. mutex_lock(&ar->conf_mutex);
  2414. if (ar->state == ATH10K_STATE_ON)
  2415. ath10k_regd_update(ar);
  2416. mutex_unlock(&ar->conf_mutex);
  2417. }
  2418. /***************/
  2419. /* TX handlers */
  2420. /***************/
  2421. void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
  2422. {
  2423. lockdep_assert_held(&ar->htt.tx_lock);
  2424. WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
  2425. ar->tx_paused |= BIT(reason);
  2426. ieee80211_stop_queues(ar->hw);
  2427. }
  2428. static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
  2429. struct ieee80211_vif *vif)
  2430. {
  2431. struct ath10k *ar = data;
  2432. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2433. if (arvif->tx_paused)
  2434. return;
  2435. ieee80211_wake_queue(ar->hw, arvif->vdev_id);
  2436. }
  2437. void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
  2438. {
  2439. lockdep_assert_held(&ar->htt.tx_lock);
  2440. WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
  2441. ar->tx_paused &= ~BIT(reason);
  2442. if (ar->tx_paused)
  2443. return;
  2444. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  2445. IEEE80211_IFACE_ITER_RESUME_ALL,
  2446. ath10k_mac_tx_unlock_iter,
  2447. ar);
  2448. ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
  2449. }
  2450. void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
  2451. {
  2452. struct ath10k *ar = arvif->ar;
  2453. lockdep_assert_held(&ar->htt.tx_lock);
  2454. WARN_ON(reason >= BITS_PER_LONG);
  2455. arvif->tx_paused |= BIT(reason);
  2456. ieee80211_stop_queue(ar->hw, arvif->vdev_id);
  2457. }
  2458. void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
  2459. {
  2460. struct ath10k *ar = arvif->ar;
  2461. lockdep_assert_held(&ar->htt.tx_lock);
  2462. WARN_ON(reason >= BITS_PER_LONG);
  2463. arvif->tx_paused &= ~BIT(reason);
  2464. if (ar->tx_paused)
  2465. return;
  2466. if (arvif->tx_paused)
  2467. return;
  2468. ieee80211_wake_queue(ar->hw, arvif->vdev_id);
  2469. }
  2470. static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
  2471. enum wmi_tlv_tx_pause_id pause_id,
  2472. enum wmi_tlv_tx_pause_action action)
  2473. {
  2474. struct ath10k *ar = arvif->ar;
  2475. lockdep_assert_held(&ar->htt.tx_lock);
  2476. switch (action) {
  2477. case WMI_TLV_TX_PAUSE_ACTION_STOP:
  2478. ath10k_mac_vif_tx_lock(arvif, pause_id);
  2479. break;
  2480. case WMI_TLV_TX_PAUSE_ACTION_WAKE:
  2481. ath10k_mac_vif_tx_unlock(arvif, pause_id);
  2482. break;
  2483. default:
  2484. ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
  2485. action, arvif->vdev_id);
  2486. break;
  2487. }
  2488. }
  2489. struct ath10k_mac_tx_pause {
  2490. u32 vdev_id;
  2491. enum wmi_tlv_tx_pause_id pause_id;
  2492. enum wmi_tlv_tx_pause_action action;
  2493. };
  2494. static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
  2495. struct ieee80211_vif *vif)
  2496. {
  2497. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2498. struct ath10k_mac_tx_pause *arg = data;
  2499. if (arvif->vdev_id != arg->vdev_id)
  2500. return;
  2501. ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
  2502. }
  2503. void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
  2504. enum wmi_tlv_tx_pause_id pause_id,
  2505. enum wmi_tlv_tx_pause_action action)
  2506. {
  2507. struct ath10k_mac_tx_pause arg = {
  2508. .vdev_id = vdev_id,
  2509. .pause_id = pause_id,
  2510. .action = action,
  2511. };
  2512. spin_lock_bh(&ar->htt.tx_lock);
  2513. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  2514. IEEE80211_IFACE_ITER_RESUME_ALL,
  2515. ath10k_mac_handle_tx_pause_iter,
  2516. &arg);
  2517. spin_unlock_bh(&ar->htt.tx_lock);
  2518. }
  2519. static enum ath10k_hw_txrx_mode
  2520. ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
  2521. struct ieee80211_vif *vif,
  2522. struct ieee80211_sta *sta,
  2523. struct sk_buff *skb)
  2524. {
  2525. const struct ieee80211_hdr *hdr = (void *)skb->data;
  2526. __le16 fc = hdr->frame_control;
  2527. if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
  2528. return ATH10K_HW_TXRX_RAW;
  2529. if (ieee80211_is_mgmt(fc))
  2530. return ATH10K_HW_TXRX_MGMT;
  2531. /* Workaround:
  2532. *
  2533. * NullFunc frames are mostly used to ping if a client or AP are still
  2534. * reachable and responsive. This implies tx status reports must be
  2535. * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
  2536. * come to a conclusion that the other end disappeared and tear down
  2537. * BSS connection or it can never disconnect from BSS/client (which is
  2538. * the case).
  2539. *
  2540. * Firmware with HTT older than 3.0 delivers incorrect tx status for
  2541. * NullFunc frames to driver. However there's a HTT Mgmt Tx command
  2542. * which seems to deliver correct tx reports for NullFunc frames. The
  2543. * downside of using it is it ignores client powersave state so it can
  2544. * end up disconnecting sleeping clients in AP mode. It should fix STA
  2545. * mode though because AP don't sleep.
  2546. */
  2547. if (ar->htt.target_version_major < 3 &&
  2548. (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
  2549. !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
  2550. return ATH10K_HW_TXRX_MGMT;
  2551. /* Workaround:
  2552. *
  2553. * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
  2554. * NativeWifi txmode - it selects AP key instead of peer key. It seems
  2555. * to work with Ethernet txmode so use it.
  2556. *
  2557. * FIXME: Check if raw mode works with TDLS.
  2558. */
  2559. if (ieee80211_is_data_present(fc) && sta && sta->tdls)
  2560. return ATH10K_HW_TXRX_ETHERNET;
  2561. if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
  2562. return ATH10K_HW_TXRX_RAW;
  2563. return ATH10K_HW_TXRX_NATIVE_WIFI;
  2564. }
  2565. static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
  2566. struct sk_buff *skb)
  2567. {
  2568. const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2569. const struct ieee80211_hdr *hdr = (void *)skb->data;
  2570. const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
  2571. IEEE80211_TX_CTL_INJECTED;
  2572. if (!ieee80211_has_protected(hdr->frame_control))
  2573. return false;
  2574. if ((info->flags & mask) == mask)
  2575. return false;
  2576. if (vif)
  2577. return !ath10k_vif_to_arvif(vif)->nohwcrypt;
  2578. return true;
  2579. }
  2580. /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
  2581. * Control in the header.
  2582. */
  2583. static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
  2584. {
  2585. struct ieee80211_hdr *hdr = (void *)skb->data;
  2586. struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
  2587. u8 *qos_ctl;
  2588. if (!ieee80211_is_data_qos(hdr->frame_control))
  2589. return;
  2590. qos_ctl = ieee80211_get_qos_ctl(hdr);
  2591. memmove(skb->data + IEEE80211_QOS_CTL_LEN,
  2592. skb->data, (void *)qos_ctl - (void *)skb->data);
  2593. skb_pull(skb, IEEE80211_QOS_CTL_LEN);
  2594. /* Some firmware revisions don't handle sending QoS NullFunc well.
  2595. * These frames are mainly used for CQM purposes so it doesn't really
  2596. * matter whether QoS NullFunc or NullFunc are sent.
  2597. */
  2598. hdr = (void *)skb->data;
  2599. if (ieee80211_is_qos_nullfunc(hdr->frame_control))
  2600. cb->flags &= ~ATH10K_SKB_F_QOS;
  2601. hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  2602. }
  2603. static void ath10k_tx_h_8023(struct sk_buff *skb)
  2604. {
  2605. struct ieee80211_hdr *hdr;
  2606. struct rfc1042_hdr *rfc1042;
  2607. struct ethhdr *eth;
  2608. size_t hdrlen;
  2609. u8 da[ETH_ALEN];
  2610. u8 sa[ETH_ALEN];
  2611. __be16 type;
  2612. hdr = (void *)skb->data;
  2613. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  2614. rfc1042 = (void *)skb->data + hdrlen;
  2615. ether_addr_copy(da, ieee80211_get_DA(hdr));
  2616. ether_addr_copy(sa, ieee80211_get_SA(hdr));
  2617. type = rfc1042->snap_type;
  2618. skb_pull(skb, hdrlen + sizeof(*rfc1042));
  2619. skb_push(skb, sizeof(*eth));
  2620. eth = (void *)skb->data;
  2621. ether_addr_copy(eth->h_dest, da);
  2622. ether_addr_copy(eth->h_source, sa);
  2623. eth->h_proto = type;
  2624. }
  2625. static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
  2626. struct ieee80211_vif *vif,
  2627. struct sk_buff *skb)
  2628. {
  2629. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  2630. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2631. /* This is case only for P2P_GO */
  2632. if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
  2633. return;
  2634. if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
  2635. spin_lock_bh(&ar->data_lock);
  2636. if (arvif->u.ap.noa_data)
  2637. if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
  2638. GFP_ATOMIC))
  2639. memcpy(skb_put(skb, arvif->u.ap.noa_len),
  2640. arvif->u.ap.noa_data,
  2641. arvif->u.ap.noa_len);
  2642. spin_unlock_bh(&ar->data_lock);
  2643. }
  2644. }
  2645. bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
  2646. {
  2647. /* FIXME: Not really sure since when the behaviour changed. At some
  2648. * point new firmware stopped requiring creation of peer entries for
  2649. * offchannel tx (and actually creating them causes issues with wmi-htc
  2650. * tx credit replenishment and reliability). Assuming it's at least 3.4
  2651. * because that's when the `freq` was introduced to TX_FRM HTT command.
  2652. */
  2653. return (ar->htt.target_version_major >= 3 &&
  2654. ar->htt.target_version_minor >= 4 &&
  2655. ar->htt.op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
  2656. }
  2657. static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
  2658. {
  2659. struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
  2660. int ret = 0;
  2661. spin_lock_bh(&ar->data_lock);
  2662. if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
  2663. ath10k_warn(ar, "wmi mgmt tx queue is full\n");
  2664. ret = -ENOSPC;
  2665. goto unlock;
  2666. }
  2667. __skb_queue_tail(q, skb);
  2668. ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
  2669. unlock:
  2670. spin_unlock_bh(&ar->data_lock);
  2671. return ret;
  2672. }
  2673. static void ath10k_mac_tx(struct ath10k *ar, enum ath10k_hw_txrx_mode txmode,
  2674. struct sk_buff *skb)
  2675. {
  2676. struct ath10k_htt *htt = &ar->htt;
  2677. int ret = 0;
  2678. switch (txmode) {
  2679. case ATH10K_HW_TXRX_RAW:
  2680. case ATH10K_HW_TXRX_NATIVE_WIFI:
  2681. case ATH10K_HW_TXRX_ETHERNET:
  2682. ret = ath10k_htt_tx(htt, txmode, skb);
  2683. break;
  2684. case ATH10K_HW_TXRX_MGMT:
  2685. if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
  2686. ar->fw_features))
  2687. ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
  2688. else if (ar->htt.target_version_major >= 3)
  2689. ret = ath10k_htt_tx(htt, txmode, skb);
  2690. else
  2691. ret = ath10k_htt_mgmt_tx(htt, skb);
  2692. break;
  2693. }
  2694. if (ret) {
  2695. ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
  2696. ret);
  2697. ieee80211_free_txskb(ar->hw, skb);
  2698. }
  2699. }
  2700. void ath10k_offchan_tx_purge(struct ath10k *ar)
  2701. {
  2702. struct sk_buff *skb;
  2703. for (;;) {
  2704. skb = skb_dequeue(&ar->offchan_tx_queue);
  2705. if (!skb)
  2706. break;
  2707. ieee80211_free_txskb(ar->hw, skb);
  2708. }
  2709. }
  2710. void ath10k_offchan_tx_work(struct work_struct *work)
  2711. {
  2712. struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
  2713. struct ath10k_peer *peer;
  2714. struct ath10k_vif *arvif;
  2715. struct ieee80211_hdr *hdr;
  2716. struct ieee80211_vif *vif;
  2717. struct ieee80211_sta *sta;
  2718. struct sk_buff *skb;
  2719. const u8 *peer_addr;
  2720. enum ath10k_hw_txrx_mode txmode;
  2721. int vdev_id;
  2722. int ret;
  2723. unsigned long time_left;
  2724. bool tmp_peer_created = false;
  2725. /* FW requirement: We must create a peer before FW will send out
  2726. * an offchannel frame. Otherwise the frame will be stuck and
  2727. * never transmitted. We delete the peer upon tx completion.
  2728. * It is unlikely that a peer for offchannel tx will already be
  2729. * present. However it may be in some rare cases so account for that.
  2730. * Otherwise we might remove a legitimate peer and break stuff. */
  2731. for (;;) {
  2732. skb = skb_dequeue(&ar->offchan_tx_queue);
  2733. if (!skb)
  2734. break;
  2735. mutex_lock(&ar->conf_mutex);
  2736. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
  2737. skb);
  2738. hdr = (struct ieee80211_hdr *)skb->data;
  2739. peer_addr = ieee80211_get_DA(hdr);
  2740. spin_lock_bh(&ar->data_lock);
  2741. vdev_id = ar->scan.vdev_id;
  2742. peer = ath10k_peer_find(ar, vdev_id, peer_addr);
  2743. spin_unlock_bh(&ar->data_lock);
  2744. if (peer)
  2745. /* FIXME: should this use ath10k_warn()? */
  2746. ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
  2747. peer_addr, vdev_id);
  2748. if (!peer) {
  2749. ret = ath10k_peer_create(ar, vdev_id, peer_addr,
  2750. WMI_PEER_TYPE_DEFAULT);
  2751. if (ret)
  2752. ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
  2753. peer_addr, vdev_id, ret);
  2754. tmp_peer_created = (ret == 0);
  2755. }
  2756. spin_lock_bh(&ar->data_lock);
  2757. reinit_completion(&ar->offchan_tx_completed);
  2758. ar->offchan_tx_skb = skb;
  2759. spin_unlock_bh(&ar->data_lock);
  2760. /* It's safe to access vif and sta - conf_mutex guarantees that
  2761. * sta_state() and remove_interface() are locked exclusively
  2762. * out wrt to this offchannel worker.
  2763. */
  2764. arvif = ath10k_get_arvif(ar, vdev_id);
  2765. if (arvif) {
  2766. vif = arvif->vif;
  2767. sta = ieee80211_find_sta(vif, peer_addr);
  2768. } else {
  2769. vif = NULL;
  2770. sta = NULL;
  2771. }
  2772. txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
  2773. ath10k_mac_tx(ar, txmode, skb);
  2774. time_left =
  2775. wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
  2776. if (time_left == 0)
  2777. ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
  2778. skb);
  2779. if (!peer && tmp_peer_created) {
  2780. ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
  2781. if (ret)
  2782. ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
  2783. peer_addr, vdev_id, ret);
  2784. }
  2785. mutex_unlock(&ar->conf_mutex);
  2786. }
  2787. }
  2788. void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
  2789. {
  2790. struct sk_buff *skb;
  2791. for (;;) {
  2792. skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
  2793. if (!skb)
  2794. break;
  2795. ieee80211_free_txskb(ar->hw, skb);
  2796. }
  2797. }
  2798. void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
  2799. {
  2800. struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
  2801. struct sk_buff *skb;
  2802. int ret;
  2803. for (;;) {
  2804. skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
  2805. if (!skb)
  2806. break;
  2807. ret = ath10k_wmi_mgmt_tx(ar, skb);
  2808. if (ret) {
  2809. ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
  2810. ret);
  2811. ieee80211_free_txskb(ar->hw, skb);
  2812. }
  2813. }
  2814. }
  2815. /************/
  2816. /* Scanning */
  2817. /************/
  2818. void __ath10k_scan_finish(struct ath10k *ar)
  2819. {
  2820. lockdep_assert_held(&ar->data_lock);
  2821. switch (ar->scan.state) {
  2822. case ATH10K_SCAN_IDLE:
  2823. break;
  2824. case ATH10K_SCAN_RUNNING:
  2825. case ATH10K_SCAN_ABORTING:
  2826. if (!ar->scan.is_roc)
  2827. ieee80211_scan_completed(ar->hw,
  2828. (ar->scan.state ==
  2829. ATH10K_SCAN_ABORTING));
  2830. else if (ar->scan.roc_notify)
  2831. ieee80211_remain_on_channel_expired(ar->hw);
  2832. /* fall through */
  2833. case ATH10K_SCAN_STARTING:
  2834. ar->scan.state = ATH10K_SCAN_IDLE;
  2835. ar->scan_channel = NULL;
  2836. ar->scan.roc_freq = 0;
  2837. ath10k_offchan_tx_purge(ar);
  2838. cancel_delayed_work(&ar->scan.timeout);
  2839. complete_all(&ar->scan.completed);
  2840. break;
  2841. }
  2842. }
  2843. void ath10k_scan_finish(struct ath10k *ar)
  2844. {
  2845. spin_lock_bh(&ar->data_lock);
  2846. __ath10k_scan_finish(ar);
  2847. spin_unlock_bh(&ar->data_lock);
  2848. }
  2849. static int ath10k_scan_stop(struct ath10k *ar)
  2850. {
  2851. struct wmi_stop_scan_arg arg = {
  2852. .req_id = 1, /* FIXME */
  2853. .req_type = WMI_SCAN_STOP_ONE,
  2854. .u.scan_id = ATH10K_SCAN_ID,
  2855. };
  2856. int ret;
  2857. lockdep_assert_held(&ar->conf_mutex);
  2858. ret = ath10k_wmi_stop_scan(ar, &arg);
  2859. if (ret) {
  2860. ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
  2861. goto out;
  2862. }
  2863. ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
  2864. if (ret == 0) {
  2865. ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
  2866. ret = -ETIMEDOUT;
  2867. } else if (ret > 0) {
  2868. ret = 0;
  2869. }
  2870. out:
  2871. /* Scan state should be updated upon scan completion but in case
  2872. * firmware fails to deliver the event (for whatever reason) it is
  2873. * desired to clean up scan state anyway. Firmware may have just
  2874. * dropped the scan completion event delivery due to transport pipe
  2875. * being overflown with data and/or it can recover on its own before
  2876. * next scan request is submitted.
  2877. */
  2878. spin_lock_bh(&ar->data_lock);
  2879. if (ar->scan.state != ATH10K_SCAN_IDLE)
  2880. __ath10k_scan_finish(ar);
  2881. spin_unlock_bh(&ar->data_lock);
  2882. return ret;
  2883. }
  2884. static void ath10k_scan_abort(struct ath10k *ar)
  2885. {
  2886. int ret;
  2887. lockdep_assert_held(&ar->conf_mutex);
  2888. spin_lock_bh(&ar->data_lock);
  2889. switch (ar->scan.state) {
  2890. case ATH10K_SCAN_IDLE:
  2891. /* This can happen if timeout worker kicked in and called
  2892. * abortion while scan completion was being processed.
  2893. */
  2894. break;
  2895. case ATH10K_SCAN_STARTING:
  2896. case ATH10K_SCAN_ABORTING:
  2897. ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
  2898. ath10k_scan_state_str(ar->scan.state),
  2899. ar->scan.state);
  2900. break;
  2901. case ATH10K_SCAN_RUNNING:
  2902. ar->scan.state = ATH10K_SCAN_ABORTING;
  2903. spin_unlock_bh(&ar->data_lock);
  2904. ret = ath10k_scan_stop(ar);
  2905. if (ret)
  2906. ath10k_warn(ar, "failed to abort scan: %d\n", ret);
  2907. spin_lock_bh(&ar->data_lock);
  2908. break;
  2909. }
  2910. spin_unlock_bh(&ar->data_lock);
  2911. }
  2912. void ath10k_scan_timeout_work(struct work_struct *work)
  2913. {
  2914. struct ath10k *ar = container_of(work, struct ath10k,
  2915. scan.timeout.work);
  2916. mutex_lock(&ar->conf_mutex);
  2917. ath10k_scan_abort(ar);
  2918. mutex_unlock(&ar->conf_mutex);
  2919. }
  2920. static int ath10k_start_scan(struct ath10k *ar,
  2921. const struct wmi_start_scan_arg *arg)
  2922. {
  2923. int ret;
  2924. lockdep_assert_held(&ar->conf_mutex);
  2925. ret = ath10k_wmi_start_scan(ar, arg);
  2926. if (ret)
  2927. return ret;
  2928. ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
  2929. if (ret == 0) {
  2930. ret = ath10k_scan_stop(ar);
  2931. if (ret)
  2932. ath10k_warn(ar, "failed to stop scan: %d\n", ret);
  2933. return -ETIMEDOUT;
  2934. }
  2935. /* If we failed to start the scan, return error code at
  2936. * this point. This is probably due to some issue in the
  2937. * firmware, but no need to wedge the driver due to that...
  2938. */
  2939. spin_lock_bh(&ar->data_lock);
  2940. if (ar->scan.state == ATH10K_SCAN_IDLE) {
  2941. spin_unlock_bh(&ar->data_lock);
  2942. return -EINVAL;
  2943. }
  2944. spin_unlock_bh(&ar->data_lock);
  2945. return 0;
  2946. }
  2947. /**********************/
  2948. /* mac80211 callbacks */
  2949. /**********************/
  2950. static void ath10k_tx(struct ieee80211_hw *hw,
  2951. struct ieee80211_tx_control *control,
  2952. struct sk_buff *skb)
  2953. {
  2954. struct ath10k *ar = hw->priv;
  2955. struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
  2956. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2957. struct ieee80211_vif *vif = info->control.vif;
  2958. struct ieee80211_sta *sta = control->sta;
  2959. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  2960. enum ath10k_hw_txrx_mode txmode;
  2961. /* We should disable CCK RATE due to P2P */
  2962. if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
  2963. ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
  2964. txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
  2965. skb_cb->flags = 0;
  2966. if (!ath10k_tx_h_use_hwcrypto(vif, skb))
  2967. skb_cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
  2968. if (ieee80211_is_mgmt(hdr->frame_control))
  2969. skb_cb->flags |= ATH10K_SKB_F_MGMT;
  2970. if (ieee80211_is_data_qos(hdr->frame_control))
  2971. skb_cb->flags |= ATH10K_SKB_F_QOS;
  2972. skb_cb->vif = vif;
  2973. switch (txmode) {
  2974. case ATH10K_HW_TXRX_MGMT:
  2975. case ATH10K_HW_TXRX_NATIVE_WIFI:
  2976. ath10k_tx_h_nwifi(hw, skb);
  2977. ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
  2978. ath10k_tx_h_seq_no(vif, skb);
  2979. break;
  2980. case ATH10K_HW_TXRX_ETHERNET:
  2981. ath10k_tx_h_8023(skb);
  2982. break;
  2983. case ATH10K_HW_TXRX_RAW:
  2984. if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
  2985. WARN_ON_ONCE(1);
  2986. ieee80211_free_txskb(hw, skb);
  2987. return;
  2988. }
  2989. }
  2990. if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
  2991. if (!ath10k_mac_tx_frm_has_freq(ar)) {
  2992. ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
  2993. skb);
  2994. skb_queue_tail(&ar->offchan_tx_queue, skb);
  2995. ieee80211_queue_work(hw, &ar->offchan_tx_work);
  2996. return;
  2997. }
  2998. }
  2999. ath10k_mac_tx(ar, txmode, skb);
  3000. }
  3001. /* Must not be called with conf_mutex held as workers can use that also. */
  3002. void ath10k_drain_tx(struct ath10k *ar)
  3003. {
  3004. /* make sure rcu-protected mac80211 tx path itself is drained */
  3005. synchronize_net();
  3006. ath10k_offchan_tx_purge(ar);
  3007. ath10k_mgmt_over_wmi_tx_purge(ar);
  3008. cancel_work_sync(&ar->offchan_tx_work);
  3009. cancel_work_sync(&ar->wmi_mgmt_tx_work);
  3010. }
  3011. void ath10k_halt(struct ath10k *ar)
  3012. {
  3013. struct ath10k_vif *arvif;
  3014. lockdep_assert_held(&ar->conf_mutex);
  3015. clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  3016. ar->filter_flags = 0;
  3017. ar->monitor = false;
  3018. ar->monitor_arvif = NULL;
  3019. if (ar->monitor_started)
  3020. ath10k_monitor_stop(ar);
  3021. ar->monitor_started = false;
  3022. ar->tx_paused = 0;
  3023. ath10k_scan_finish(ar);
  3024. ath10k_peer_cleanup_all(ar);
  3025. ath10k_core_stop(ar);
  3026. ath10k_hif_power_down(ar);
  3027. spin_lock_bh(&ar->data_lock);
  3028. list_for_each_entry(arvif, &ar->arvifs, list)
  3029. ath10k_mac_vif_beacon_cleanup(arvif);
  3030. spin_unlock_bh(&ar->data_lock);
  3031. }
  3032. static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  3033. {
  3034. struct ath10k *ar = hw->priv;
  3035. mutex_lock(&ar->conf_mutex);
  3036. *tx_ant = ar->cfg_tx_chainmask;
  3037. *rx_ant = ar->cfg_rx_chainmask;
  3038. mutex_unlock(&ar->conf_mutex);
  3039. return 0;
  3040. }
  3041. static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
  3042. {
  3043. /* It is not clear that allowing gaps in chainmask
  3044. * is helpful. Probably it will not do what user
  3045. * is hoping for, so warn in that case.
  3046. */
  3047. if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
  3048. return;
  3049. ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
  3050. dbg, cm);
  3051. }
  3052. static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
  3053. {
  3054. int nsts = ar->vht_cap_info;
  3055. nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
  3056. nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
  3057. /* If firmware does not deliver to host number of space-time
  3058. * streams supported, assume it support up to 4 BF STS and return
  3059. * the value for VHT CAP: nsts-1)
  3060. */
  3061. if (nsts == 0)
  3062. return 3;
  3063. return nsts;
  3064. }
  3065. static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
  3066. {
  3067. int sound_dim = ar->vht_cap_info;
  3068. sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
  3069. sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
  3070. /* If the sounding dimension is not advertised by the firmware,
  3071. * let's use a default value of 1
  3072. */
  3073. if (sound_dim == 0)
  3074. return 1;
  3075. return sound_dim;
  3076. }
  3077. static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
  3078. {
  3079. struct ieee80211_sta_vht_cap vht_cap = {0};
  3080. u16 mcs_map;
  3081. u32 val;
  3082. int i;
  3083. vht_cap.vht_supported = 1;
  3084. vht_cap.cap = ar->vht_cap_info;
  3085. if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  3086. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
  3087. val = ath10k_mac_get_vht_cap_bf_sts(ar);
  3088. val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
  3089. val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
  3090. vht_cap.cap |= val;
  3091. }
  3092. if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  3093. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
  3094. val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
  3095. val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
  3096. val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
  3097. vht_cap.cap |= val;
  3098. }
  3099. mcs_map = 0;
  3100. for (i = 0; i < 8; i++) {
  3101. if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
  3102. mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
  3103. else
  3104. mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
  3105. }
  3106. vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  3107. vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  3108. return vht_cap;
  3109. }
  3110. static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
  3111. {
  3112. int i;
  3113. struct ieee80211_sta_ht_cap ht_cap = {0};
  3114. if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
  3115. return ht_cap;
  3116. ht_cap.ht_supported = 1;
  3117. ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  3118. ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  3119. ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  3120. ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
  3121. ht_cap.cap |=
  3122. WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
  3123. if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
  3124. ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  3125. if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
  3126. ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  3127. if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
  3128. u32 smps;
  3129. smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
  3130. smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
  3131. ht_cap.cap |= smps;
  3132. }
  3133. if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
  3134. ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  3135. if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
  3136. u32 stbc;
  3137. stbc = ar->ht_cap_info;
  3138. stbc &= WMI_HT_CAP_RX_STBC;
  3139. stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
  3140. stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
  3141. stbc &= IEEE80211_HT_CAP_RX_STBC;
  3142. ht_cap.cap |= stbc;
  3143. }
  3144. if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
  3145. ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
  3146. if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
  3147. ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
  3148. /* max AMSDU is implicitly taken from vht_cap_info */
  3149. if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
  3150. ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  3151. for (i = 0; i < ar->num_rf_chains; i++) {
  3152. if (ar->cfg_rx_chainmask & BIT(i))
  3153. ht_cap.mcs.rx_mask[i] = 0xFF;
  3154. }
  3155. ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  3156. return ht_cap;
  3157. }
  3158. static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
  3159. {
  3160. struct ieee80211_supported_band *band;
  3161. struct ieee80211_sta_vht_cap vht_cap;
  3162. struct ieee80211_sta_ht_cap ht_cap;
  3163. ht_cap = ath10k_get_ht_cap(ar);
  3164. vht_cap = ath10k_create_vht_cap(ar);
  3165. if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
  3166. band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
  3167. band->ht_cap = ht_cap;
  3168. /* Enable the VHT support at 2.4 GHz */
  3169. band->vht_cap = vht_cap;
  3170. }
  3171. if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
  3172. band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
  3173. band->ht_cap = ht_cap;
  3174. band->vht_cap = vht_cap;
  3175. }
  3176. }
  3177. static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
  3178. {
  3179. int ret;
  3180. lockdep_assert_held(&ar->conf_mutex);
  3181. ath10k_check_chain_mask(ar, tx_ant, "tx");
  3182. ath10k_check_chain_mask(ar, rx_ant, "rx");
  3183. ar->cfg_tx_chainmask = tx_ant;
  3184. ar->cfg_rx_chainmask = rx_ant;
  3185. if ((ar->state != ATH10K_STATE_ON) &&
  3186. (ar->state != ATH10K_STATE_RESTARTED))
  3187. return 0;
  3188. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
  3189. tx_ant);
  3190. if (ret) {
  3191. ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
  3192. ret, tx_ant);
  3193. return ret;
  3194. }
  3195. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
  3196. rx_ant);
  3197. if (ret) {
  3198. ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
  3199. ret, rx_ant);
  3200. return ret;
  3201. }
  3202. /* Reload HT/VHT capability */
  3203. ath10k_mac_setup_ht_vht_cap(ar);
  3204. return 0;
  3205. }
  3206. static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  3207. {
  3208. struct ath10k *ar = hw->priv;
  3209. int ret;
  3210. mutex_lock(&ar->conf_mutex);
  3211. ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
  3212. mutex_unlock(&ar->conf_mutex);
  3213. return ret;
  3214. }
  3215. static int ath10k_start(struct ieee80211_hw *hw)
  3216. {
  3217. struct ath10k *ar = hw->priv;
  3218. u32 param;
  3219. int ret = 0;
  3220. /*
  3221. * This makes sense only when restarting hw. It is harmless to call
  3222. * uncoditionally. This is necessary to make sure no HTT/WMI tx
  3223. * commands will be submitted while restarting.
  3224. */
  3225. ath10k_drain_tx(ar);
  3226. mutex_lock(&ar->conf_mutex);
  3227. switch (ar->state) {
  3228. case ATH10K_STATE_OFF:
  3229. ar->state = ATH10K_STATE_ON;
  3230. break;
  3231. case ATH10K_STATE_RESTARTING:
  3232. ath10k_halt(ar);
  3233. ar->state = ATH10K_STATE_RESTARTED;
  3234. break;
  3235. case ATH10K_STATE_ON:
  3236. case ATH10K_STATE_RESTARTED:
  3237. case ATH10K_STATE_WEDGED:
  3238. WARN_ON(1);
  3239. ret = -EINVAL;
  3240. goto err;
  3241. case ATH10K_STATE_UTF:
  3242. ret = -EBUSY;
  3243. goto err;
  3244. }
  3245. ret = ath10k_hif_power_up(ar);
  3246. if (ret) {
  3247. ath10k_err(ar, "Could not init hif: %d\n", ret);
  3248. goto err_off;
  3249. }
  3250. ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
  3251. if (ret) {
  3252. ath10k_err(ar, "Could not init core: %d\n", ret);
  3253. goto err_power_down;
  3254. }
  3255. param = ar->wmi.pdev_param->pmf_qos;
  3256. ret = ath10k_wmi_pdev_set_param(ar, param, 1);
  3257. if (ret) {
  3258. ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
  3259. goto err_core_stop;
  3260. }
  3261. param = ar->wmi.pdev_param->dynamic_bw;
  3262. ret = ath10k_wmi_pdev_set_param(ar, param, 1);
  3263. if (ret) {
  3264. ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
  3265. goto err_core_stop;
  3266. }
  3267. if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
  3268. ret = ath10k_wmi_adaptive_qcs(ar, true);
  3269. if (ret) {
  3270. ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
  3271. ret);
  3272. goto err_core_stop;
  3273. }
  3274. }
  3275. if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
  3276. param = ar->wmi.pdev_param->burst_enable;
  3277. ret = ath10k_wmi_pdev_set_param(ar, param, 0);
  3278. if (ret) {
  3279. ath10k_warn(ar, "failed to disable burst: %d\n", ret);
  3280. goto err_core_stop;
  3281. }
  3282. }
  3283. __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
  3284. /*
  3285. * By default FW set ARP frames ac to voice (6). In that case ARP
  3286. * exchange is not working properly for UAPSD enabled AP. ARP requests
  3287. * which arrives with access category 0 are processed by network stack
  3288. * and send back with access category 0, but FW changes access category
  3289. * to 6. Set ARP frames access category to best effort (0) solves
  3290. * this problem.
  3291. */
  3292. param = ar->wmi.pdev_param->arp_ac_override;
  3293. ret = ath10k_wmi_pdev_set_param(ar, param, 0);
  3294. if (ret) {
  3295. ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
  3296. ret);
  3297. goto err_core_stop;
  3298. }
  3299. if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
  3300. ar->fw_features)) {
  3301. ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
  3302. WMI_CCA_DETECT_LEVEL_AUTO,
  3303. WMI_CCA_DETECT_MARGIN_AUTO);
  3304. if (ret) {
  3305. ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
  3306. ret);
  3307. goto err_core_stop;
  3308. }
  3309. }
  3310. param = ar->wmi.pdev_param->ani_enable;
  3311. ret = ath10k_wmi_pdev_set_param(ar, param, 1);
  3312. if (ret) {
  3313. ath10k_warn(ar, "failed to enable ani by default: %d\n",
  3314. ret);
  3315. goto err_core_stop;
  3316. }
  3317. ar->ani_enabled = true;
  3318. if (test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map)) {
  3319. param = ar->wmi.pdev_param->peer_stats_update_period;
  3320. ret = ath10k_wmi_pdev_set_param(ar, param,
  3321. PEER_DEFAULT_STATS_UPDATE_PERIOD);
  3322. if (ret) {
  3323. ath10k_warn(ar,
  3324. "failed to set peer stats period : %d\n",
  3325. ret);
  3326. goto err_core_stop;
  3327. }
  3328. }
  3329. ar->num_started_vdevs = 0;
  3330. ath10k_regd_update(ar);
  3331. ath10k_spectral_start(ar);
  3332. ath10k_thermal_set_throttling(ar);
  3333. mutex_unlock(&ar->conf_mutex);
  3334. return 0;
  3335. err_core_stop:
  3336. ath10k_core_stop(ar);
  3337. err_power_down:
  3338. ath10k_hif_power_down(ar);
  3339. err_off:
  3340. ar->state = ATH10K_STATE_OFF;
  3341. err:
  3342. mutex_unlock(&ar->conf_mutex);
  3343. return ret;
  3344. }
  3345. static void ath10k_stop(struct ieee80211_hw *hw)
  3346. {
  3347. struct ath10k *ar = hw->priv;
  3348. ath10k_drain_tx(ar);
  3349. mutex_lock(&ar->conf_mutex);
  3350. if (ar->state != ATH10K_STATE_OFF) {
  3351. ath10k_halt(ar);
  3352. ar->state = ATH10K_STATE_OFF;
  3353. }
  3354. mutex_unlock(&ar->conf_mutex);
  3355. cancel_delayed_work_sync(&ar->scan.timeout);
  3356. cancel_work_sync(&ar->restart_work);
  3357. }
  3358. static int ath10k_config_ps(struct ath10k *ar)
  3359. {
  3360. struct ath10k_vif *arvif;
  3361. int ret = 0;
  3362. lockdep_assert_held(&ar->conf_mutex);
  3363. list_for_each_entry(arvif, &ar->arvifs, list) {
  3364. ret = ath10k_mac_vif_setup_ps(arvif);
  3365. if (ret) {
  3366. ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
  3367. break;
  3368. }
  3369. }
  3370. return ret;
  3371. }
  3372. static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
  3373. {
  3374. int ret;
  3375. u32 param;
  3376. lockdep_assert_held(&ar->conf_mutex);
  3377. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
  3378. param = ar->wmi.pdev_param->txpower_limit2g;
  3379. ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
  3380. if (ret) {
  3381. ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
  3382. txpower, ret);
  3383. return ret;
  3384. }
  3385. param = ar->wmi.pdev_param->txpower_limit5g;
  3386. ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
  3387. if (ret) {
  3388. ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
  3389. txpower, ret);
  3390. return ret;
  3391. }
  3392. return 0;
  3393. }
  3394. static int ath10k_mac_txpower_recalc(struct ath10k *ar)
  3395. {
  3396. struct ath10k_vif *arvif;
  3397. int ret, txpower = -1;
  3398. lockdep_assert_held(&ar->conf_mutex);
  3399. list_for_each_entry(arvif, &ar->arvifs, list) {
  3400. WARN_ON(arvif->txpower < 0);
  3401. if (txpower == -1)
  3402. txpower = arvif->txpower;
  3403. else
  3404. txpower = min(txpower, arvif->txpower);
  3405. }
  3406. if (WARN_ON(txpower == -1))
  3407. return -EINVAL;
  3408. ret = ath10k_mac_txpower_setup(ar, txpower);
  3409. if (ret) {
  3410. ath10k_warn(ar, "failed to setup tx power %d: %d\n",
  3411. txpower, ret);
  3412. return ret;
  3413. }
  3414. return 0;
  3415. }
  3416. static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
  3417. {
  3418. struct ath10k *ar = hw->priv;
  3419. struct ieee80211_conf *conf = &hw->conf;
  3420. int ret = 0;
  3421. mutex_lock(&ar->conf_mutex);
  3422. if (changed & IEEE80211_CONF_CHANGE_PS)
  3423. ath10k_config_ps(ar);
  3424. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  3425. ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
  3426. ret = ath10k_monitor_recalc(ar);
  3427. if (ret)
  3428. ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
  3429. }
  3430. mutex_unlock(&ar->conf_mutex);
  3431. return ret;
  3432. }
  3433. static u32 get_nss_from_chainmask(u16 chain_mask)
  3434. {
  3435. if ((chain_mask & 0xf) == 0xf)
  3436. return 4;
  3437. else if ((chain_mask & 0x7) == 0x7)
  3438. return 3;
  3439. else if ((chain_mask & 0x3) == 0x3)
  3440. return 2;
  3441. return 1;
  3442. }
  3443. static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
  3444. {
  3445. u32 value = 0;
  3446. struct ath10k *ar = arvif->ar;
  3447. int nsts;
  3448. int sound_dim;
  3449. if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
  3450. return 0;
  3451. nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
  3452. if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  3453. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
  3454. value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
  3455. sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
  3456. if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  3457. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
  3458. value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
  3459. if (!value)
  3460. return 0;
  3461. if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
  3462. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
  3463. if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
  3464. value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
  3465. WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
  3466. if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
  3467. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
  3468. if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
  3469. value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
  3470. WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
  3471. return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  3472. ar->wmi.vdev_param->txbf, value);
  3473. }
  3474. /*
  3475. * TODO:
  3476. * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
  3477. * because we will send mgmt frames without CCK. This requirement
  3478. * for P2P_FIND/GO_NEG should be handled by checking CCK flag
  3479. * in the TX packet.
  3480. */
  3481. static int ath10k_add_interface(struct ieee80211_hw *hw,
  3482. struct ieee80211_vif *vif)
  3483. {
  3484. struct ath10k *ar = hw->priv;
  3485. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3486. enum wmi_sta_powersave_param param;
  3487. int ret = 0;
  3488. u32 value;
  3489. int bit;
  3490. int i;
  3491. u32 vdev_param;
  3492. vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
  3493. mutex_lock(&ar->conf_mutex);
  3494. memset(arvif, 0, sizeof(*arvif));
  3495. arvif->ar = ar;
  3496. arvif->vif = vif;
  3497. INIT_LIST_HEAD(&arvif->list);
  3498. INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
  3499. INIT_DELAYED_WORK(&arvif->connection_loss_work,
  3500. ath10k_mac_vif_sta_connection_loss_work);
  3501. for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
  3502. arvif->bitrate_mask.control[i].legacy = 0xffffffff;
  3503. memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
  3504. sizeof(arvif->bitrate_mask.control[i].ht_mcs));
  3505. memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
  3506. sizeof(arvif->bitrate_mask.control[i].vht_mcs));
  3507. }
  3508. if (ar->num_peers >= ar->max_num_peers) {
  3509. ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
  3510. ret = -ENOBUFS;
  3511. goto err;
  3512. }
  3513. if (ar->free_vdev_map == 0) {
  3514. ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
  3515. ret = -EBUSY;
  3516. goto err;
  3517. }
  3518. bit = __ffs64(ar->free_vdev_map);
  3519. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
  3520. bit, ar->free_vdev_map);
  3521. arvif->vdev_id = bit;
  3522. arvif->vdev_subtype =
  3523. ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
  3524. switch (vif->type) {
  3525. case NL80211_IFTYPE_P2P_DEVICE:
  3526. arvif->vdev_type = WMI_VDEV_TYPE_STA;
  3527. arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
  3528. (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
  3529. break;
  3530. case NL80211_IFTYPE_UNSPECIFIED:
  3531. case NL80211_IFTYPE_STATION:
  3532. arvif->vdev_type = WMI_VDEV_TYPE_STA;
  3533. if (vif->p2p)
  3534. arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
  3535. (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
  3536. break;
  3537. case NL80211_IFTYPE_ADHOC:
  3538. arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
  3539. break;
  3540. case NL80211_IFTYPE_MESH_POINT:
  3541. if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
  3542. arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
  3543. (ar, WMI_VDEV_SUBTYPE_MESH_11S);
  3544. } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
  3545. ret = -EINVAL;
  3546. ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
  3547. goto err;
  3548. }
  3549. arvif->vdev_type = WMI_VDEV_TYPE_AP;
  3550. break;
  3551. case NL80211_IFTYPE_AP:
  3552. arvif->vdev_type = WMI_VDEV_TYPE_AP;
  3553. if (vif->p2p)
  3554. arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
  3555. (ar, WMI_VDEV_SUBTYPE_P2P_GO);
  3556. break;
  3557. case NL80211_IFTYPE_MONITOR:
  3558. arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
  3559. break;
  3560. default:
  3561. WARN_ON(1);
  3562. break;
  3563. }
  3564. /* Using vdev_id as queue number will make it very easy to do per-vif
  3565. * tx queue locking. This shouldn't wrap due to interface combinations
  3566. * but do a modulo for correctness sake and prevent using offchannel tx
  3567. * queues for regular vif tx.
  3568. */
  3569. vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
  3570. for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
  3571. vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
  3572. /* Some firmware revisions don't wait for beacon tx completion before
  3573. * sending another SWBA event. This could lead to hardware using old
  3574. * (freed) beacon data in some cases, e.g. tx credit starvation
  3575. * combined with missed TBTT. This is very very rare.
  3576. *
  3577. * On non-IOMMU-enabled hosts this could be a possible security issue
  3578. * because hw could beacon some random data on the air. On
  3579. * IOMMU-enabled hosts DMAR faults would occur in most cases and target
  3580. * device would crash.
  3581. *
  3582. * Since there are no beacon tx completions (implicit nor explicit)
  3583. * propagated to host the only workaround for this is to allocate a
  3584. * DMA-coherent buffer for a lifetime of a vif and use it for all
  3585. * beacon tx commands. Worst case for this approach is some beacons may
  3586. * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
  3587. */
  3588. if (vif->type == NL80211_IFTYPE_ADHOC ||
  3589. vif->type == NL80211_IFTYPE_MESH_POINT ||
  3590. vif->type == NL80211_IFTYPE_AP) {
  3591. arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
  3592. IEEE80211_MAX_FRAME_LEN,
  3593. &arvif->beacon_paddr,
  3594. GFP_ATOMIC);
  3595. if (!arvif->beacon_buf) {
  3596. ret = -ENOMEM;
  3597. ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
  3598. ret);
  3599. goto err;
  3600. }
  3601. }
  3602. if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
  3603. arvif->nohwcrypt = true;
  3604. if (arvif->nohwcrypt &&
  3605. !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
  3606. ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
  3607. goto err;
  3608. }
  3609. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
  3610. arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
  3611. arvif->beacon_buf ? "single-buf" : "per-skb");
  3612. ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
  3613. arvif->vdev_subtype, vif->addr);
  3614. if (ret) {
  3615. ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
  3616. arvif->vdev_id, ret);
  3617. goto err;
  3618. }
  3619. ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
  3620. list_add(&arvif->list, &ar->arvifs);
  3621. /* It makes no sense to have firmware do keepalives. mac80211 already
  3622. * takes care of this with idle connection polling.
  3623. */
  3624. ret = ath10k_mac_vif_disable_keepalive(arvif);
  3625. if (ret) {
  3626. ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
  3627. arvif->vdev_id, ret);
  3628. goto err_vdev_delete;
  3629. }
  3630. arvif->def_wep_key_idx = -1;
  3631. vdev_param = ar->wmi.vdev_param->tx_encap_type;
  3632. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  3633. ATH10K_HW_TXRX_NATIVE_WIFI);
  3634. /* 10.X firmware does not support this VDEV parameter. Do not warn */
  3635. if (ret && ret != -EOPNOTSUPP) {
  3636. ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
  3637. arvif->vdev_id, ret);
  3638. goto err_vdev_delete;
  3639. }
  3640. if (ar->cfg_tx_chainmask) {
  3641. u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
  3642. vdev_param = ar->wmi.vdev_param->nss;
  3643. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  3644. nss);
  3645. if (ret) {
  3646. ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
  3647. arvif->vdev_id, ar->cfg_tx_chainmask, nss,
  3648. ret);
  3649. goto err_vdev_delete;
  3650. }
  3651. }
  3652. if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
  3653. arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  3654. ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
  3655. WMI_PEER_TYPE_DEFAULT);
  3656. if (ret) {
  3657. ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
  3658. arvif->vdev_id, ret);
  3659. goto err_vdev_delete;
  3660. }
  3661. }
  3662. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  3663. ret = ath10k_mac_set_kickout(arvif);
  3664. if (ret) {
  3665. ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
  3666. arvif->vdev_id, ret);
  3667. goto err_peer_delete;
  3668. }
  3669. }
  3670. if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
  3671. param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
  3672. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  3673. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  3674. param, value);
  3675. if (ret) {
  3676. ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
  3677. arvif->vdev_id, ret);
  3678. goto err_peer_delete;
  3679. }
  3680. ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
  3681. if (ret) {
  3682. ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
  3683. arvif->vdev_id, ret);
  3684. goto err_peer_delete;
  3685. }
  3686. ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
  3687. if (ret) {
  3688. ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
  3689. arvif->vdev_id, ret);
  3690. goto err_peer_delete;
  3691. }
  3692. }
  3693. ret = ath10k_mac_set_txbf_conf(arvif);
  3694. if (ret) {
  3695. ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
  3696. arvif->vdev_id, ret);
  3697. goto err_peer_delete;
  3698. }
  3699. ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
  3700. if (ret) {
  3701. ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
  3702. arvif->vdev_id, ret);
  3703. goto err_peer_delete;
  3704. }
  3705. arvif->txpower = vif->bss_conf.txpower;
  3706. ret = ath10k_mac_txpower_recalc(ar);
  3707. if (ret) {
  3708. ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
  3709. goto err_peer_delete;
  3710. }
  3711. if (vif->type == NL80211_IFTYPE_MONITOR) {
  3712. ar->monitor_arvif = arvif;
  3713. ret = ath10k_monitor_recalc(ar);
  3714. if (ret) {
  3715. ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
  3716. goto err_peer_delete;
  3717. }
  3718. }
  3719. spin_lock_bh(&ar->htt.tx_lock);
  3720. if (!ar->tx_paused)
  3721. ieee80211_wake_queue(ar->hw, arvif->vdev_id);
  3722. spin_unlock_bh(&ar->htt.tx_lock);
  3723. mutex_unlock(&ar->conf_mutex);
  3724. return 0;
  3725. err_peer_delete:
  3726. if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
  3727. arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
  3728. ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
  3729. err_vdev_delete:
  3730. ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
  3731. ar->free_vdev_map |= 1LL << arvif->vdev_id;
  3732. list_del(&arvif->list);
  3733. err:
  3734. if (arvif->beacon_buf) {
  3735. dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
  3736. arvif->beacon_buf, arvif->beacon_paddr);
  3737. arvif->beacon_buf = NULL;
  3738. }
  3739. mutex_unlock(&ar->conf_mutex);
  3740. return ret;
  3741. }
  3742. static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
  3743. {
  3744. int i;
  3745. for (i = 0; i < BITS_PER_LONG; i++)
  3746. ath10k_mac_vif_tx_unlock(arvif, i);
  3747. }
  3748. static void ath10k_remove_interface(struct ieee80211_hw *hw,
  3749. struct ieee80211_vif *vif)
  3750. {
  3751. struct ath10k *ar = hw->priv;
  3752. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3753. int ret;
  3754. cancel_work_sync(&arvif->ap_csa_work);
  3755. cancel_delayed_work_sync(&arvif->connection_loss_work);
  3756. mutex_lock(&ar->conf_mutex);
  3757. spin_lock_bh(&ar->data_lock);
  3758. ath10k_mac_vif_beacon_cleanup(arvif);
  3759. spin_unlock_bh(&ar->data_lock);
  3760. ret = ath10k_spectral_vif_stop(arvif);
  3761. if (ret)
  3762. ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
  3763. arvif->vdev_id, ret);
  3764. ar->free_vdev_map |= 1LL << arvif->vdev_id;
  3765. list_del(&arvif->list);
  3766. if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
  3767. arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  3768. ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
  3769. vif->addr);
  3770. if (ret)
  3771. ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
  3772. arvif->vdev_id, ret);
  3773. kfree(arvif->u.ap.noa_data);
  3774. }
  3775. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
  3776. arvif->vdev_id);
  3777. ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
  3778. if (ret)
  3779. ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
  3780. arvif->vdev_id, ret);
  3781. /* Some firmware revisions don't notify host about self-peer removal
  3782. * until after associated vdev is deleted.
  3783. */
  3784. if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
  3785. arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  3786. ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
  3787. vif->addr);
  3788. if (ret)
  3789. ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
  3790. arvif->vdev_id, ret);
  3791. spin_lock_bh(&ar->data_lock);
  3792. ar->num_peers--;
  3793. spin_unlock_bh(&ar->data_lock);
  3794. }
  3795. ath10k_peer_cleanup(ar, arvif->vdev_id);
  3796. if (vif->type == NL80211_IFTYPE_MONITOR) {
  3797. ar->monitor_arvif = NULL;
  3798. ret = ath10k_monitor_recalc(ar);
  3799. if (ret)
  3800. ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
  3801. }
  3802. spin_lock_bh(&ar->htt.tx_lock);
  3803. ath10k_mac_vif_tx_unlock_all(arvif);
  3804. spin_unlock_bh(&ar->htt.tx_lock);
  3805. mutex_unlock(&ar->conf_mutex);
  3806. }
  3807. /*
  3808. * FIXME: Has to be verified.
  3809. */
  3810. #define SUPPORTED_FILTERS \
  3811. (FIF_ALLMULTI | \
  3812. FIF_CONTROL | \
  3813. FIF_PSPOLL | \
  3814. FIF_OTHER_BSS | \
  3815. FIF_BCN_PRBRESP_PROMISC | \
  3816. FIF_PROBE_REQ | \
  3817. FIF_FCSFAIL)
  3818. static void ath10k_configure_filter(struct ieee80211_hw *hw,
  3819. unsigned int changed_flags,
  3820. unsigned int *total_flags,
  3821. u64 multicast)
  3822. {
  3823. struct ath10k *ar = hw->priv;
  3824. int ret;
  3825. mutex_lock(&ar->conf_mutex);
  3826. changed_flags &= SUPPORTED_FILTERS;
  3827. *total_flags &= SUPPORTED_FILTERS;
  3828. ar->filter_flags = *total_flags;
  3829. ret = ath10k_monitor_recalc(ar);
  3830. if (ret)
  3831. ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
  3832. mutex_unlock(&ar->conf_mutex);
  3833. }
  3834. static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
  3835. struct ieee80211_vif *vif,
  3836. struct ieee80211_bss_conf *info,
  3837. u32 changed)
  3838. {
  3839. struct ath10k *ar = hw->priv;
  3840. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3841. int ret = 0;
  3842. u32 vdev_param, pdev_param, slottime, preamble;
  3843. mutex_lock(&ar->conf_mutex);
  3844. if (changed & BSS_CHANGED_IBSS)
  3845. ath10k_control_ibss(arvif, info, vif->addr);
  3846. if (changed & BSS_CHANGED_BEACON_INT) {
  3847. arvif->beacon_interval = info->beacon_int;
  3848. vdev_param = ar->wmi.vdev_param->beacon_interval;
  3849. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  3850. arvif->beacon_interval);
  3851. ath10k_dbg(ar, ATH10K_DBG_MAC,
  3852. "mac vdev %d beacon_interval %d\n",
  3853. arvif->vdev_id, arvif->beacon_interval);
  3854. if (ret)
  3855. ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
  3856. arvif->vdev_id, ret);
  3857. }
  3858. if (changed & BSS_CHANGED_BEACON) {
  3859. ath10k_dbg(ar, ATH10K_DBG_MAC,
  3860. "vdev %d set beacon tx mode to staggered\n",
  3861. arvif->vdev_id);
  3862. pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
  3863. ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
  3864. WMI_BEACON_STAGGERED_MODE);
  3865. if (ret)
  3866. ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
  3867. arvif->vdev_id, ret);
  3868. ret = ath10k_mac_setup_bcn_tmpl(arvif);
  3869. if (ret)
  3870. ath10k_warn(ar, "failed to update beacon template: %d\n",
  3871. ret);
  3872. if (ieee80211_vif_is_mesh(vif)) {
  3873. /* mesh doesn't use SSID but firmware needs it */
  3874. strncpy(arvif->u.ap.ssid, "mesh",
  3875. sizeof(arvif->u.ap.ssid));
  3876. arvif->u.ap.ssid_len = 4;
  3877. }
  3878. }
  3879. if (changed & BSS_CHANGED_AP_PROBE_RESP) {
  3880. ret = ath10k_mac_setup_prb_tmpl(arvif);
  3881. if (ret)
  3882. ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
  3883. arvif->vdev_id, ret);
  3884. }
  3885. if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
  3886. arvif->dtim_period = info->dtim_period;
  3887. ath10k_dbg(ar, ATH10K_DBG_MAC,
  3888. "mac vdev %d dtim_period %d\n",
  3889. arvif->vdev_id, arvif->dtim_period);
  3890. vdev_param = ar->wmi.vdev_param->dtim_period;
  3891. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  3892. arvif->dtim_period);
  3893. if (ret)
  3894. ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
  3895. arvif->vdev_id, ret);
  3896. }
  3897. if (changed & BSS_CHANGED_SSID &&
  3898. vif->type == NL80211_IFTYPE_AP) {
  3899. arvif->u.ap.ssid_len = info->ssid_len;
  3900. if (info->ssid_len)
  3901. memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
  3902. arvif->u.ap.hidden_ssid = info->hidden_ssid;
  3903. }
  3904. if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
  3905. ether_addr_copy(arvif->bssid, info->bssid);
  3906. if (changed & BSS_CHANGED_BEACON_ENABLED)
  3907. ath10k_control_beaconing(arvif, info);
  3908. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  3909. arvif->use_cts_prot = info->use_cts_prot;
  3910. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
  3911. arvif->vdev_id, info->use_cts_prot);
  3912. ret = ath10k_recalc_rtscts_prot(arvif);
  3913. if (ret)
  3914. ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  3915. arvif->vdev_id, ret);
  3916. vdev_param = ar->wmi.vdev_param->protection_mode;
  3917. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  3918. info->use_cts_prot ? 1 : 0);
  3919. if (ret)
  3920. ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
  3921. info->use_cts_prot, arvif->vdev_id, ret);
  3922. }
  3923. if (changed & BSS_CHANGED_ERP_SLOT) {
  3924. if (info->use_short_slot)
  3925. slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
  3926. else
  3927. slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
  3928. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
  3929. arvif->vdev_id, slottime);
  3930. vdev_param = ar->wmi.vdev_param->slot_time;
  3931. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  3932. slottime);
  3933. if (ret)
  3934. ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
  3935. arvif->vdev_id, ret);
  3936. }
  3937. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  3938. if (info->use_short_preamble)
  3939. preamble = WMI_VDEV_PREAMBLE_SHORT;
  3940. else
  3941. preamble = WMI_VDEV_PREAMBLE_LONG;
  3942. ath10k_dbg(ar, ATH10K_DBG_MAC,
  3943. "mac vdev %d preamble %dn",
  3944. arvif->vdev_id, preamble);
  3945. vdev_param = ar->wmi.vdev_param->preamble;
  3946. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  3947. preamble);
  3948. if (ret)
  3949. ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
  3950. arvif->vdev_id, ret);
  3951. }
  3952. if (changed & BSS_CHANGED_ASSOC) {
  3953. if (info->assoc) {
  3954. /* Workaround: Make sure monitor vdev is not running
  3955. * when associating to prevent some firmware revisions
  3956. * (e.g. 10.1 and 10.2) from crashing.
  3957. */
  3958. if (ar->monitor_started)
  3959. ath10k_monitor_stop(ar);
  3960. ath10k_bss_assoc(hw, vif, info);
  3961. ath10k_monitor_recalc(ar);
  3962. } else {
  3963. ath10k_bss_disassoc(hw, vif);
  3964. }
  3965. }
  3966. if (changed & BSS_CHANGED_TXPOWER) {
  3967. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
  3968. arvif->vdev_id, info->txpower);
  3969. arvif->txpower = info->txpower;
  3970. ret = ath10k_mac_txpower_recalc(ar);
  3971. if (ret)
  3972. ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
  3973. }
  3974. if (changed & BSS_CHANGED_PS) {
  3975. arvif->ps = vif->bss_conf.ps;
  3976. ret = ath10k_config_ps(ar);
  3977. if (ret)
  3978. ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
  3979. arvif->vdev_id, ret);
  3980. }
  3981. mutex_unlock(&ar->conf_mutex);
  3982. }
  3983. static int ath10k_hw_scan(struct ieee80211_hw *hw,
  3984. struct ieee80211_vif *vif,
  3985. struct ieee80211_scan_request *hw_req)
  3986. {
  3987. struct ath10k *ar = hw->priv;
  3988. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3989. struct cfg80211_scan_request *req = &hw_req->req;
  3990. struct wmi_start_scan_arg arg;
  3991. int ret = 0;
  3992. int i;
  3993. mutex_lock(&ar->conf_mutex);
  3994. spin_lock_bh(&ar->data_lock);
  3995. switch (ar->scan.state) {
  3996. case ATH10K_SCAN_IDLE:
  3997. reinit_completion(&ar->scan.started);
  3998. reinit_completion(&ar->scan.completed);
  3999. ar->scan.state = ATH10K_SCAN_STARTING;
  4000. ar->scan.is_roc = false;
  4001. ar->scan.vdev_id = arvif->vdev_id;
  4002. ret = 0;
  4003. break;
  4004. case ATH10K_SCAN_STARTING:
  4005. case ATH10K_SCAN_RUNNING:
  4006. case ATH10K_SCAN_ABORTING:
  4007. ret = -EBUSY;
  4008. break;
  4009. }
  4010. spin_unlock_bh(&ar->data_lock);
  4011. if (ret)
  4012. goto exit;
  4013. memset(&arg, 0, sizeof(arg));
  4014. ath10k_wmi_start_scan_init(ar, &arg);
  4015. arg.vdev_id = arvif->vdev_id;
  4016. arg.scan_id = ATH10K_SCAN_ID;
  4017. if (req->ie_len) {
  4018. arg.ie_len = req->ie_len;
  4019. memcpy(arg.ie, req->ie, arg.ie_len);
  4020. }
  4021. if (req->n_ssids) {
  4022. arg.n_ssids = req->n_ssids;
  4023. for (i = 0; i < arg.n_ssids; i++) {
  4024. arg.ssids[i].len = req->ssids[i].ssid_len;
  4025. arg.ssids[i].ssid = req->ssids[i].ssid;
  4026. }
  4027. } else {
  4028. arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
  4029. }
  4030. if (req->n_channels) {
  4031. arg.n_channels = req->n_channels;
  4032. for (i = 0; i < arg.n_channels; i++)
  4033. arg.channels[i] = req->channels[i]->center_freq;
  4034. }
  4035. ret = ath10k_start_scan(ar, &arg);
  4036. if (ret) {
  4037. ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
  4038. spin_lock_bh(&ar->data_lock);
  4039. ar->scan.state = ATH10K_SCAN_IDLE;
  4040. spin_unlock_bh(&ar->data_lock);
  4041. }
  4042. /* Add a 200ms margin to account for event/command processing */
  4043. ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
  4044. msecs_to_jiffies(arg.max_scan_time +
  4045. 200));
  4046. exit:
  4047. mutex_unlock(&ar->conf_mutex);
  4048. return ret;
  4049. }
  4050. static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
  4051. struct ieee80211_vif *vif)
  4052. {
  4053. struct ath10k *ar = hw->priv;
  4054. mutex_lock(&ar->conf_mutex);
  4055. ath10k_scan_abort(ar);
  4056. mutex_unlock(&ar->conf_mutex);
  4057. cancel_delayed_work_sync(&ar->scan.timeout);
  4058. }
  4059. static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
  4060. struct ath10k_vif *arvif,
  4061. enum set_key_cmd cmd,
  4062. struct ieee80211_key_conf *key)
  4063. {
  4064. u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
  4065. int ret;
  4066. /* 10.1 firmware branch requires default key index to be set to group
  4067. * key index after installing it. Otherwise FW/HW Txes corrupted
  4068. * frames with multi-vif APs. This is not required for main firmware
  4069. * branch (e.g. 636).
  4070. *
  4071. * This is also needed for 636 fw for IBSS-RSN to work more reliably.
  4072. *
  4073. * FIXME: It remains unknown if this is required for multi-vif STA
  4074. * interfaces on 10.1.
  4075. */
  4076. if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
  4077. arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
  4078. return;
  4079. if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
  4080. return;
  4081. if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
  4082. return;
  4083. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  4084. return;
  4085. if (cmd != SET_KEY)
  4086. return;
  4087. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  4088. key->keyidx);
  4089. if (ret)
  4090. ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
  4091. arvif->vdev_id, ret);
  4092. }
  4093. static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  4094. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  4095. struct ieee80211_key_conf *key)
  4096. {
  4097. struct ath10k *ar = hw->priv;
  4098. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  4099. struct ath10k_peer *peer;
  4100. const u8 *peer_addr;
  4101. bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  4102. key->cipher == WLAN_CIPHER_SUITE_WEP104;
  4103. int ret = 0;
  4104. int ret2;
  4105. u32 flags = 0;
  4106. u32 flags2;
  4107. /* this one needs to be done in software */
  4108. if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
  4109. return 1;
  4110. if (arvif->nohwcrypt)
  4111. return 1;
  4112. if (key->keyidx > WMI_MAX_KEY_INDEX)
  4113. return -ENOSPC;
  4114. mutex_lock(&ar->conf_mutex);
  4115. if (sta)
  4116. peer_addr = sta->addr;
  4117. else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
  4118. peer_addr = vif->bss_conf.bssid;
  4119. else
  4120. peer_addr = vif->addr;
  4121. key->hw_key_idx = key->keyidx;
  4122. if (is_wep) {
  4123. if (cmd == SET_KEY)
  4124. arvif->wep_keys[key->keyidx] = key;
  4125. else
  4126. arvif->wep_keys[key->keyidx] = NULL;
  4127. }
  4128. /* the peer should not disappear in mid-way (unless FW goes awry) since
  4129. * we already hold conf_mutex. we just make sure its there now. */
  4130. spin_lock_bh(&ar->data_lock);
  4131. peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
  4132. spin_unlock_bh(&ar->data_lock);
  4133. if (!peer) {
  4134. if (cmd == SET_KEY) {
  4135. ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
  4136. peer_addr);
  4137. ret = -EOPNOTSUPP;
  4138. goto exit;
  4139. } else {
  4140. /* if the peer doesn't exist there is no key to disable
  4141. * anymore */
  4142. goto exit;
  4143. }
  4144. }
  4145. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  4146. flags |= WMI_KEY_PAIRWISE;
  4147. else
  4148. flags |= WMI_KEY_GROUP;
  4149. if (is_wep) {
  4150. if (cmd == DISABLE_KEY)
  4151. ath10k_clear_vdev_key(arvif, key);
  4152. /* When WEP keys are uploaded it's possible that there are
  4153. * stations associated already (e.g. when merging) without any
  4154. * keys. Static WEP needs an explicit per-peer key upload.
  4155. */
  4156. if (vif->type == NL80211_IFTYPE_ADHOC &&
  4157. cmd == SET_KEY)
  4158. ath10k_mac_vif_update_wep_key(arvif, key);
  4159. /* 802.1x never sets the def_wep_key_idx so each set_key()
  4160. * call changes default tx key.
  4161. *
  4162. * Static WEP sets def_wep_key_idx via .set_default_unicast_key
  4163. * after first set_key().
  4164. */
  4165. if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
  4166. flags |= WMI_KEY_TX_USAGE;
  4167. }
  4168. ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
  4169. if (ret) {
  4170. WARN_ON(ret > 0);
  4171. ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
  4172. arvif->vdev_id, peer_addr, ret);
  4173. goto exit;
  4174. }
  4175. /* mac80211 sets static WEP keys as groupwise while firmware requires
  4176. * them to be installed twice as both pairwise and groupwise.
  4177. */
  4178. if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
  4179. flags2 = flags;
  4180. flags2 &= ~WMI_KEY_GROUP;
  4181. flags2 |= WMI_KEY_PAIRWISE;
  4182. ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
  4183. if (ret) {
  4184. WARN_ON(ret > 0);
  4185. ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
  4186. arvif->vdev_id, peer_addr, ret);
  4187. ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
  4188. peer_addr, flags);
  4189. if (ret2) {
  4190. WARN_ON(ret2 > 0);
  4191. ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
  4192. arvif->vdev_id, peer_addr, ret2);
  4193. }
  4194. goto exit;
  4195. }
  4196. }
  4197. ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
  4198. spin_lock_bh(&ar->data_lock);
  4199. peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
  4200. if (peer && cmd == SET_KEY)
  4201. peer->keys[key->keyidx] = key;
  4202. else if (peer && cmd == DISABLE_KEY)
  4203. peer->keys[key->keyidx] = NULL;
  4204. else if (peer == NULL)
  4205. /* impossible unless FW goes crazy */
  4206. ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
  4207. spin_unlock_bh(&ar->data_lock);
  4208. exit:
  4209. mutex_unlock(&ar->conf_mutex);
  4210. return ret;
  4211. }
  4212. static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
  4213. struct ieee80211_vif *vif,
  4214. int keyidx)
  4215. {
  4216. struct ath10k *ar = hw->priv;
  4217. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  4218. int ret;
  4219. mutex_lock(&arvif->ar->conf_mutex);
  4220. if (arvif->ar->state != ATH10K_STATE_ON)
  4221. goto unlock;
  4222. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
  4223. arvif->vdev_id, keyidx);
  4224. ret = ath10k_wmi_vdev_set_param(arvif->ar,
  4225. arvif->vdev_id,
  4226. arvif->ar->wmi.vdev_param->def_keyid,
  4227. keyidx);
  4228. if (ret) {
  4229. ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
  4230. arvif->vdev_id,
  4231. ret);
  4232. goto unlock;
  4233. }
  4234. arvif->def_wep_key_idx = keyidx;
  4235. unlock:
  4236. mutex_unlock(&arvif->ar->conf_mutex);
  4237. }
  4238. static void ath10k_sta_rc_update_wk(struct work_struct *wk)
  4239. {
  4240. struct ath10k *ar;
  4241. struct ath10k_vif *arvif;
  4242. struct ath10k_sta *arsta;
  4243. struct ieee80211_sta *sta;
  4244. struct cfg80211_chan_def def;
  4245. enum ieee80211_band band;
  4246. const u8 *ht_mcs_mask;
  4247. const u16 *vht_mcs_mask;
  4248. u32 changed, bw, nss, smps;
  4249. int err;
  4250. arsta = container_of(wk, struct ath10k_sta, update_wk);
  4251. sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
  4252. arvif = arsta->arvif;
  4253. ar = arvif->ar;
  4254. if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
  4255. return;
  4256. band = def.chan->band;
  4257. ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
  4258. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  4259. spin_lock_bh(&ar->data_lock);
  4260. changed = arsta->changed;
  4261. arsta->changed = 0;
  4262. bw = arsta->bw;
  4263. nss = arsta->nss;
  4264. smps = arsta->smps;
  4265. spin_unlock_bh(&ar->data_lock);
  4266. mutex_lock(&ar->conf_mutex);
  4267. nss = max_t(u32, 1, nss);
  4268. nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
  4269. ath10k_mac_max_vht_nss(vht_mcs_mask)));
  4270. if (changed & IEEE80211_RC_BW_CHANGED) {
  4271. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
  4272. sta->addr, bw);
  4273. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  4274. WMI_PEER_CHAN_WIDTH, bw);
  4275. if (err)
  4276. ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
  4277. sta->addr, bw, err);
  4278. }
  4279. if (changed & IEEE80211_RC_NSS_CHANGED) {
  4280. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
  4281. sta->addr, nss);
  4282. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  4283. WMI_PEER_NSS, nss);
  4284. if (err)
  4285. ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
  4286. sta->addr, nss, err);
  4287. }
  4288. if (changed & IEEE80211_RC_SMPS_CHANGED) {
  4289. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
  4290. sta->addr, smps);
  4291. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  4292. WMI_PEER_SMPS_STATE, smps);
  4293. if (err)
  4294. ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
  4295. sta->addr, smps, err);
  4296. }
  4297. if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
  4298. changed & IEEE80211_RC_NSS_CHANGED) {
  4299. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
  4300. sta->addr);
  4301. err = ath10k_station_assoc(ar, arvif->vif, sta, true);
  4302. if (err)
  4303. ath10k_warn(ar, "failed to reassociate station: %pM\n",
  4304. sta->addr);
  4305. }
  4306. mutex_unlock(&ar->conf_mutex);
  4307. }
  4308. static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
  4309. struct ieee80211_sta *sta)
  4310. {
  4311. struct ath10k *ar = arvif->ar;
  4312. lockdep_assert_held(&ar->conf_mutex);
  4313. if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
  4314. return 0;
  4315. if (ar->num_stations >= ar->max_num_stations)
  4316. return -ENOBUFS;
  4317. ar->num_stations++;
  4318. return 0;
  4319. }
  4320. static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
  4321. struct ieee80211_sta *sta)
  4322. {
  4323. struct ath10k *ar = arvif->ar;
  4324. lockdep_assert_held(&ar->conf_mutex);
  4325. if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
  4326. return;
  4327. ar->num_stations--;
  4328. }
  4329. struct ath10k_mac_tdls_iter_data {
  4330. u32 num_tdls_stations;
  4331. struct ieee80211_vif *curr_vif;
  4332. };
  4333. static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
  4334. struct ieee80211_sta *sta)
  4335. {
  4336. struct ath10k_mac_tdls_iter_data *iter_data = data;
  4337. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  4338. struct ieee80211_vif *sta_vif = arsta->arvif->vif;
  4339. if (sta->tdls && sta_vif == iter_data->curr_vif)
  4340. iter_data->num_tdls_stations++;
  4341. }
  4342. static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
  4343. struct ieee80211_vif *vif)
  4344. {
  4345. struct ath10k_mac_tdls_iter_data data = {};
  4346. data.curr_vif = vif;
  4347. ieee80211_iterate_stations_atomic(hw,
  4348. ath10k_mac_tdls_vif_stations_count_iter,
  4349. &data);
  4350. return data.num_tdls_stations;
  4351. }
  4352. static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
  4353. struct ieee80211_vif *vif)
  4354. {
  4355. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  4356. int *num_tdls_vifs = data;
  4357. if (vif->type != NL80211_IFTYPE_STATION)
  4358. return;
  4359. if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
  4360. (*num_tdls_vifs)++;
  4361. }
  4362. static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
  4363. {
  4364. int num_tdls_vifs = 0;
  4365. ieee80211_iterate_active_interfaces_atomic(hw,
  4366. IEEE80211_IFACE_ITER_NORMAL,
  4367. ath10k_mac_tdls_vifs_count_iter,
  4368. &num_tdls_vifs);
  4369. return num_tdls_vifs;
  4370. }
  4371. static int ath10k_sta_state(struct ieee80211_hw *hw,
  4372. struct ieee80211_vif *vif,
  4373. struct ieee80211_sta *sta,
  4374. enum ieee80211_sta_state old_state,
  4375. enum ieee80211_sta_state new_state)
  4376. {
  4377. struct ath10k *ar = hw->priv;
  4378. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  4379. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  4380. int ret = 0;
  4381. if (old_state == IEEE80211_STA_NOTEXIST &&
  4382. new_state == IEEE80211_STA_NONE) {
  4383. memset(arsta, 0, sizeof(*arsta));
  4384. arsta->arvif = arvif;
  4385. INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
  4386. }
  4387. /* cancel must be done outside the mutex to avoid deadlock */
  4388. if ((old_state == IEEE80211_STA_NONE &&
  4389. new_state == IEEE80211_STA_NOTEXIST))
  4390. cancel_work_sync(&arsta->update_wk);
  4391. mutex_lock(&ar->conf_mutex);
  4392. if (old_state == IEEE80211_STA_NOTEXIST &&
  4393. new_state == IEEE80211_STA_NONE) {
  4394. /*
  4395. * New station addition.
  4396. */
  4397. enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
  4398. u32 num_tdls_stations;
  4399. u32 num_tdls_vifs;
  4400. ath10k_dbg(ar, ATH10K_DBG_MAC,
  4401. "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
  4402. arvif->vdev_id, sta->addr,
  4403. ar->num_stations + 1, ar->max_num_stations,
  4404. ar->num_peers + 1, ar->max_num_peers);
  4405. ret = ath10k_mac_inc_num_stations(arvif, sta);
  4406. if (ret) {
  4407. ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
  4408. ar->max_num_stations);
  4409. goto exit;
  4410. }
  4411. if (sta->tdls)
  4412. peer_type = WMI_PEER_TYPE_TDLS;
  4413. ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
  4414. peer_type);
  4415. if (ret) {
  4416. ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
  4417. sta->addr, arvif->vdev_id, ret);
  4418. ath10k_mac_dec_num_stations(arvif, sta);
  4419. goto exit;
  4420. }
  4421. if (!sta->tdls)
  4422. goto exit;
  4423. num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
  4424. num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
  4425. if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
  4426. num_tdls_stations == 0) {
  4427. ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
  4428. arvif->vdev_id, ar->max_num_tdls_vdevs);
  4429. ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
  4430. ath10k_mac_dec_num_stations(arvif, sta);
  4431. ret = -ENOBUFS;
  4432. goto exit;
  4433. }
  4434. if (num_tdls_stations == 0) {
  4435. /* This is the first tdls peer in current vif */
  4436. enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
  4437. ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
  4438. state);
  4439. if (ret) {
  4440. ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
  4441. arvif->vdev_id, ret);
  4442. ath10k_peer_delete(ar, arvif->vdev_id,
  4443. sta->addr);
  4444. ath10k_mac_dec_num_stations(arvif, sta);
  4445. goto exit;
  4446. }
  4447. }
  4448. ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
  4449. WMI_TDLS_PEER_STATE_PEERING);
  4450. if (ret) {
  4451. ath10k_warn(ar,
  4452. "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
  4453. sta->addr, arvif->vdev_id, ret);
  4454. ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
  4455. ath10k_mac_dec_num_stations(arvif, sta);
  4456. if (num_tdls_stations != 0)
  4457. goto exit;
  4458. ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
  4459. WMI_TDLS_DISABLE);
  4460. }
  4461. } else if ((old_state == IEEE80211_STA_NONE &&
  4462. new_state == IEEE80211_STA_NOTEXIST)) {
  4463. /*
  4464. * Existing station deletion.
  4465. */
  4466. ath10k_dbg(ar, ATH10K_DBG_MAC,
  4467. "mac vdev %d peer delete %pM (sta gone)\n",
  4468. arvif->vdev_id, sta->addr);
  4469. ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
  4470. if (ret)
  4471. ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
  4472. sta->addr, arvif->vdev_id, ret);
  4473. ath10k_mac_dec_num_stations(arvif, sta);
  4474. if (!sta->tdls)
  4475. goto exit;
  4476. if (ath10k_mac_tdls_vif_stations_count(hw, vif))
  4477. goto exit;
  4478. /* This was the last tdls peer in current vif */
  4479. ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
  4480. WMI_TDLS_DISABLE);
  4481. if (ret) {
  4482. ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
  4483. arvif->vdev_id, ret);
  4484. }
  4485. } else if (old_state == IEEE80211_STA_AUTH &&
  4486. new_state == IEEE80211_STA_ASSOC &&
  4487. (vif->type == NL80211_IFTYPE_AP ||
  4488. vif->type == NL80211_IFTYPE_MESH_POINT ||
  4489. vif->type == NL80211_IFTYPE_ADHOC)) {
  4490. /*
  4491. * New association.
  4492. */
  4493. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
  4494. sta->addr);
  4495. ret = ath10k_station_assoc(ar, vif, sta, false);
  4496. if (ret)
  4497. ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
  4498. sta->addr, arvif->vdev_id, ret);
  4499. } else if (old_state == IEEE80211_STA_ASSOC &&
  4500. new_state == IEEE80211_STA_AUTHORIZED &&
  4501. sta->tdls) {
  4502. /*
  4503. * Tdls station authorized.
  4504. */
  4505. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
  4506. sta->addr);
  4507. ret = ath10k_station_assoc(ar, vif, sta, false);
  4508. if (ret) {
  4509. ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
  4510. sta->addr, arvif->vdev_id, ret);
  4511. goto exit;
  4512. }
  4513. ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
  4514. WMI_TDLS_PEER_STATE_CONNECTED);
  4515. if (ret)
  4516. ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
  4517. sta->addr, arvif->vdev_id, ret);
  4518. } else if (old_state == IEEE80211_STA_ASSOC &&
  4519. new_state == IEEE80211_STA_AUTH &&
  4520. (vif->type == NL80211_IFTYPE_AP ||
  4521. vif->type == NL80211_IFTYPE_MESH_POINT ||
  4522. vif->type == NL80211_IFTYPE_ADHOC)) {
  4523. /*
  4524. * Disassociation.
  4525. */
  4526. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
  4527. sta->addr);
  4528. ret = ath10k_station_disassoc(ar, vif, sta);
  4529. if (ret)
  4530. ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
  4531. sta->addr, arvif->vdev_id, ret);
  4532. }
  4533. exit:
  4534. mutex_unlock(&ar->conf_mutex);
  4535. return ret;
  4536. }
  4537. static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
  4538. u16 ac, bool enable)
  4539. {
  4540. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  4541. struct wmi_sta_uapsd_auto_trig_arg arg = {};
  4542. u32 prio = 0, acc = 0;
  4543. u32 value = 0;
  4544. int ret = 0;
  4545. lockdep_assert_held(&ar->conf_mutex);
  4546. if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
  4547. return 0;
  4548. switch (ac) {
  4549. case IEEE80211_AC_VO:
  4550. value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
  4551. WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
  4552. prio = 7;
  4553. acc = 3;
  4554. break;
  4555. case IEEE80211_AC_VI:
  4556. value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
  4557. WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
  4558. prio = 5;
  4559. acc = 2;
  4560. break;
  4561. case IEEE80211_AC_BE:
  4562. value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
  4563. WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
  4564. prio = 2;
  4565. acc = 1;
  4566. break;
  4567. case IEEE80211_AC_BK:
  4568. value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
  4569. WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
  4570. prio = 0;
  4571. acc = 0;
  4572. break;
  4573. }
  4574. if (enable)
  4575. arvif->u.sta.uapsd |= value;
  4576. else
  4577. arvif->u.sta.uapsd &= ~value;
  4578. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  4579. WMI_STA_PS_PARAM_UAPSD,
  4580. arvif->u.sta.uapsd);
  4581. if (ret) {
  4582. ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
  4583. goto exit;
  4584. }
  4585. if (arvif->u.sta.uapsd)
  4586. value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
  4587. else
  4588. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  4589. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  4590. WMI_STA_PS_PARAM_RX_WAKE_POLICY,
  4591. value);
  4592. if (ret)
  4593. ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
  4594. ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
  4595. if (ret) {
  4596. ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
  4597. arvif->vdev_id, ret);
  4598. return ret;
  4599. }
  4600. ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
  4601. if (ret) {
  4602. ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
  4603. arvif->vdev_id, ret);
  4604. return ret;
  4605. }
  4606. if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
  4607. test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
  4608. /* Only userspace can make an educated decision when to send
  4609. * trigger frame. The following effectively disables u-UAPSD
  4610. * autotrigger in firmware (which is enabled by default
  4611. * provided the autotrigger service is available).
  4612. */
  4613. arg.wmm_ac = acc;
  4614. arg.user_priority = prio;
  4615. arg.service_interval = 0;
  4616. arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
  4617. arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
  4618. ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
  4619. arvif->bssid, &arg, 1);
  4620. if (ret) {
  4621. ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
  4622. ret);
  4623. return ret;
  4624. }
  4625. }
  4626. exit:
  4627. return ret;
  4628. }
  4629. static int ath10k_conf_tx(struct ieee80211_hw *hw,
  4630. struct ieee80211_vif *vif, u16 ac,
  4631. const struct ieee80211_tx_queue_params *params)
  4632. {
  4633. struct ath10k *ar = hw->priv;
  4634. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  4635. struct wmi_wmm_params_arg *p = NULL;
  4636. int ret;
  4637. mutex_lock(&ar->conf_mutex);
  4638. switch (ac) {
  4639. case IEEE80211_AC_VO:
  4640. p = &arvif->wmm_params.ac_vo;
  4641. break;
  4642. case IEEE80211_AC_VI:
  4643. p = &arvif->wmm_params.ac_vi;
  4644. break;
  4645. case IEEE80211_AC_BE:
  4646. p = &arvif->wmm_params.ac_be;
  4647. break;
  4648. case IEEE80211_AC_BK:
  4649. p = &arvif->wmm_params.ac_bk;
  4650. break;
  4651. }
  4652. if (WARN_ON(!p)) {
  4653. ret = -EINVAL;
  4654. goto exit;
  4655. }
  4656. p->cwmin = params->cw_min;
  4657. p->cwmax = params->cw_max;
  4658. p->aifs = params->aifs;
  4659. /*
  4660. * The channel time duration programmed in the HW is in absolute
  4661. * microseconds, while mac80211 gives the txop in units of
  4662. * 32 microseconds.
  4663. */
  4664. p->txop = params->txop * 32;
  4665. if (ar->wmi.ops->gen_vdev_wmm_conf) {
  4666. ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
  4667. &arvif->wmm_params);
  4668. if (ret) {
  4669. ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
  4670. arvif->vdev_id, ret);
  4671. goto exit;
  4672. }
  4673. } else {
  4674. /* This won't work well with multi-interface cases but it's
  4675. * better than nothing.
  4676. */
  4677. ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
  4678. if (ret) {
  4679. ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
  4680. goto exit;
  4681. }
  4682. }
  4683. ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
  4684. if (ret)
  4685. ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
  4686. exit:
  4687. mutex_unlock(&ar->conf_mutex);
  4688. return ret;
  4689. }
  4690. #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
  4691. static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
  4692. struct ieee80211_vif *vif,
  4693. struct ieee80211_channel *chan,
  4694. int duration,
  4695. enum ieee80211_roc_type type)
  4696. {
  4697. struct ath10k *ar = hw->priv;
  4698. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  4699. struct wmi_start_scan_arg arg;
  4700. int ret = 0;
  4701. u32 scan_time_msec;
  4702. mutex_lock(&ar->conf_mutex);
  4703. spin_lock_bh(&ar->data_lock);
  4704. switch (ar->scan.state) {
  4705. case ATH10K_SCAN_IDLE:
  4706. reinit_completion(&ar->scan.started);
  4707. reinit_completion(&ar->scan.completed);
  4708. reinit_completion(&ar->scan.on_channel);
  4709. ar->scan.state = ATH10K_SCAN_STARTING;
  4710. ar->scan.is_roc = true;
  4711. ar->scan.vdev_id = arvif->vdev_id;
  4712. ar->scan.roc_freq = chan->center_freq;
  4713. ar->scan.roc_notify = true;
  4714. ret = 0;
  4715. break;
  4716. case ATH10K_SCAN_STARTING:
  4717. case ATH10K_SCAN_RUNNING:
  4718. case ATH10K_SCAN_ABORTING:
  4719. ret = -EBUSY;
  4720. break;
  4721. }
  4722. spin_unlock_bh(&ar->data_lock);
  4723. if (ret)
  4724. goto exit;
  4725. scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
  4726. memset(&arg, 0, sizeof(arg));
  4727. ath10k_wmi_start_scan_init(ar, &arg);
  4728. arg.vdev_id = arvif->vdev_id;
  4729. arg.scan_id = ATH10K_SCAN_ID;
  4730. arg.n_channels = 1;
  4731. arg.channels[0] = chan->center_freq;
  4732. arg.dwell_time_active = scan_time_msec;
  4733. arg.dwell_time_passive = scan_time_msec;
  4734. arg.max_scan_time = scan_time_msec;
  4735. arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
  4736. arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
  4737. arg.burst_duration_ms = duration;
  4738. ret = ath10k_start_scan(ar, &arg);
  4739. if (ret) {
  4740. ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
  4741. spin_lock_bh(&ar->data_lock);
  4742. ar->scan.state = ATH10K_SCAN_IDLE;
  4743. spin_unlock_bh(&ar->data_lock);
  4744. goto exit;
  4745. }
  4746. ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
  4747. if (ret == 0) {
  4748. ath10k_warn(ar, "failed to switch to channel for roc scan\n");
  4749. ret = ath10k_scan_stop(ar);
  4750. if (ret)
  4751. ath10k_warn(ar, "failed to stop scan: %d\n", ret);
  4752. ret = -ETIMEDOUT;
  4753. goto exit;
  4754. }
  4755. ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
  4756. msecs_to_jiffies(duration));
  4757. ret = 0;
  4758. exit:
  4759. mutex_unlock(&ar->conf_mutex);
  4760. return ret;
  4761. }
  4762. static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
  4763. {
  4764. struct ath10k *ar = hw->priv;
  4765. mutex_lock(&ar->conf_mutex);
  4766. spin_lock_bh(&ar->data_lock);
  4767. ar->scan.roc_notify = false;
  4768. spin_unlock_bh(&ar->data_lock);
  4769. ath10k_scan_abort(ar);
  4770. mutex_unlock(&ar->conf_mutex);
  4771. cancel_delayed_work_sync(&ar->scan.timeout);
  4772. return 0;
  4773. }
  4774. /*
  4775. * Both RTS and Fragmentation threshold are interface-specific
  4776. * in ath10k, but device-specific in mac80211.
  4777. */
  4778. static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  4779. {
  4780. struct ath10k *ar = hw->priv;
  4781. struct ath10k_vif *arvif;
  4782. int ret = 0;
  4783. mutex_lock(&ar->conf_mutex);
  4784. list_for_each_entry(arvif, &ar->arvifs, list) {
  4785. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
  4786. arvif->vdev_id, value);
  4787. ret = ath10k_mac_set_rts(arvif, value);
  4788. if (ret) {
  4789. ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
  4790. arvif->vdev_id, ret);
  4791. break;
  4792. }
  4793. }
  4794. mutex_unlock(&ar->conf_mutex);
  4795. return ret;
  4796. }
  4797. static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
  4798. {
  4799. /* Even though there's a WMI enum for fragmentation threshold no known
  4800. * firmware actually implements it. Moreover it is not possible to rely
  4801. * frame fragmentation to mac80211 because firmware clears the "more
  4802. * fragments" bit in frame control making it impossible for remote
  4803. * devices to reassemble frames.
  4804. *
  4805. * Hence implement a dummy callback just to say fragmentation isn't
  4806. * supported. This effectively prevents mac80211 from doing frame
  4807. * fragmentation in software.
  4808. */
  4809. return -EOPNOTSUPP;
  4810. }
  4811. static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4812. u32 queues, bool drop)
  4813. {
  4814. struct ath10k *ar = hw->priv;
  4815. bool skip;
  4816. long time_left;
  4817. /* mac80211 doesn't care if we really xmit queued frames or not
  4818. * we'll collect those frames either way if we stop/delete vdevs */
  4819. if (drop)
  4820. return;
  4821. mutex_lock(&ar->conf_mutex);
  4822. if (ar->state == ATH10K_STATE_WEDGED)
  4823. goto skip;
  4824. time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
  4825. bool empty;
  4826. spin_lock_bh(&ar->htt.tx_lock);
  4827. empty = (ar->htt.num_pending_tx == 0);
  4828. spin_unlock_bh(&ar->htt.tx_lock);
  4829. skip = (ar->state == ATH10K_STATE_WEDGED) ||
  4830. test_bit(ATH10K_FLAG_CRASH_FLUSH,
  4831. &ar->dev_flags);
  4832. (empty || skip);
  4833. }), ATH10K_FLUSH_TIMEOUT_HZ);
  4834. if (time_left == 0 || skip)
  4835. ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
  4836. skip, ar->state, time_left);
  4837. skip:
  4838. mutex_unlock(&ar->conf_mutex);
  4839. }
  4840. /* TODO: Implement this function properly
  4841. * For now it is needed to reply to Probe Requests in IBSS mode.
  4842. * Propably we need this information from FW.
  4843. */
  4844. static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
  4845. {
  4846. return 1;
  4847. }
  4848. static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
  4849. enum ieee80211_reconfig_type reconfig_type)
  4850. {
  4851. struct ath10k *ar = hw->priv;
  4852. if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
  4853. return;
  4854. mutex_lock(&ar->conf_mutex);
  4855. /* If device failed to restart it will be in a different state, e.g.
  4856. * ATH10K_STATE_WEDGED */
  4857. if (ar->state == ATH10K_STATE_RESTARTED) {
  4858. ath10k_info(ar, "device successfully recovered\n");
  4859. ar->state = ATH10K_STATE_ON;
  4860. ieee80211_wake_queues(ar->hw);
  4861. }
  4862. mutex_unlock(&ar->conf_mutex);
  4863. }
  4864. static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
  4865. struct survey_info *survey)
  4866. {
  4867. struct ath10k *ar = hw->priv;
  4868. struct ieee80211_supported_band *sband;
  4869. struct survey_info *ar_survey = &ar->survey[idx];
  4870. int ret = 0;
  4871. mutex_lock(&ar->conf_mutex);
  4872. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  4873. if (sband && idx >= sband->n_channels) {
  4874. idx -= sband->n_channels;
  4875. sband = NULL;
  4876. }
  4877. if (!sband)
  4878. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  4879. if (!sband || idx >= sband->n_channels) {
  4880. ret = -ENOENT;
  4881. goto exit;
  4882. }
  4883. spin_lock_bh(&ar->data_lock);
  4884. memcpy(survey, ar_survey, sizeof(*survey));
  4885. spin_unlock_bh(&ar->data_lock);
  4886. survey->channel = &sband->channels[idx];
  4887. if (ar->rx_channel == survey->channel)
  4888. survey->filled |= SURVEY_INFO_IN_USE;
  4889. exit:
  4890. mutex_unlock(&ar->conf_mutex);
  4891. return ret;
  4892. }
  4893. static bool
  4894. ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
  4895. enum ieee80211_band band,
  4896. const struct cfg80211_bitrate_mask *mask)
  4897. {
  4898. int num_rates = 0;
  4899. int i;
  4900. num_rates += hweight32(mask->control[band].legacy);
  4901. for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
  4902. num_rates += hweight8(mask->control[band].ht_mcs[i]);
  4903. for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
  4904. num_rates += hweight16(mask->control[band].vht_mcs[i]);
  4905. return num_rates == 1;
  4906. }
  4907. static bool
  4908. ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
  4909. enum ieee80211_band band,
  4910. const struct cfg80211_bitrate_mask *mask,
  4911. int *nss)
  4912. {
  4913. struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
  4914. u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
  4915. u8 ht_nss_mask = 0;
  4916. u8 vht_nss_mask = 0;
  4917. int i;
  4918. if (mask->control[band].legacy)
  4919. return false;
  4920. for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
  4921. if (mask->control[band].ht_mcs[i] == 0)
  4922. continue;
  4923. else if (mask->control[band].ht_mcs[i] ==
  4924. sband->ht_cap.mcs.rx_mask[i])
  4925. ht_nss_mask |= BIT(i);
  4926. else
  4927. return false;
  4928. }
  4929. for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
  4930. if (mask->control[band].vht_mcs[i] == 0)
  4931. continue;
  4932. else if (mask->control[band].vht_mcs[i] ==
  4933. ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
  4934. vht_nss_mask |= BIT(i);
  4935. else
  4936. return false;
  4937. }
  4938. if (ht_nss_mask != vht_nss_mask)
  4939. return false;
  4940. if (ht_nss_mask == 0)
  4941. return false;
  4942. if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
  4943. return false;
  4944. *nss = fls(ht_nss_mask);
  4945. return true;
  4946. }
  4947. static int
  4948. ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
  4949. enum ieee80211_band band,
  4950. const struct cfg80211_bitrate_mask *mask,
  4951. u8 *rate, u8 *nss)
  4952. {
  4953. struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
  4954. int rate_idx;
  4955. int i;
  4956. u16 bitrate;
  4957. u8 preamble;
  4958. u8 hw_rate;
  4959. if (hweight32(mask->control[band].legacy) == 1) {
  4960. rate_idx = ffs(mask->control[band].legacy) - 1;
  4961. hw_rate = sband->bitrates[rate_idx].hw_value;
  4962. bitrate = sband->bitrates[rate_idx].bitrate;
  4963. if (ath10k_mac_bitrate_is_cck(bitrate))
  4964. preamble = WMI_RATE_PREAMBLE_CCK;
  4965. else
  4966. preamble = WMI_RATE_PREAMBLE_OFDM;
  4967. *nss = 1;
  4968. *rate = preamble << 6 |
  4969. (*nss - 1) << 4 |
  4970. hw_rate << 0;
  4971. return 0;
  4972. }
  4973. for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
  4974. if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
  4975. *nss = i + 1;
  4976. *rate = WMI_RATE_PREAMBLE_HT << 6 |
  4977. (*nss - 1) << 4 |
  4978. (ffs(mask->control[band].ht_mcs[i]) - 1);
  4979. return 0;
  4980. }
  4981. }
  4982. for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
  4983. if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
  4984. *nss = i + 1;
  4985. *rate = WMI_RATE_PREAMBLE_VHT << 6 |
  4986. (*nss - 1) << 4 |
  4987. (ffs(mask->control[band].vht_mcs[i]) - 1);
  4988. return 0;
  4989. }
  4990. }
  4991. return -EINVAL;
  4992. }
  4993. static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
  4994. u8 rate, u8 nss, u8 sgi, u8 ldpc)
  4995. {
  4996. struct ath10k *ar = arvif->ar;
  4997. u32 vdev_param;
  4998. int ret;
  4999. lockdep_assert_held(&ar->conf_mutex);
  5000. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
  5001. arvif->vdev_id, rate, nss, sgi);
  5002. vdev_param = ar->wmi.vdev_param->fixed_rate;
  5003. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
  5004. if (ret) {
  5005. ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
  5006. rate, ret);
  5007. return ret;
  5008. }
  5009. vdev_param = ar->wmi.vdev_param->nss;
  5010. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
  5011. if (ret) {
  5012. ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
  5013. return ret;
  5014. }
  5015. vdev_param = ar->wmi.vdev_param->sgi;
  5016. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
  5017. if (ret) {
  5018. ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
  5019. return ret;
  5020. }
  5021. vdev_param = ar->wmi.vdev_param->ldpc;
  5022. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
  5023. if (ret) {
  5024. ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
  5025. return ret;
  5026. }
  5027. return 0;
  5028. }
  5029. static bool
  5030. ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
  5031. enum ieee80211_band band,
  5032. const struct cfg80211_bitrate_mask *mask)
  5033. {
  5034. int i;
  5035. u16 vht_mcs;
  5036. /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
  5037. * to express all VHT MCS rate masks. Effectively only the following
  5038. * ranges can be used: none, 0-7, 0-8 and 0-9.
  5039. */
  5040. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  5041. vht_mcs = mask->control[band].vht_mcs[i];
  5042. switch (vht_mcs) {
  5043. case 0:
  5044. case BIT(8) - 1:
  5045. case BIT(9) - 1:
  5046. case BIT(10) - 1:
  5047. break;
  5048. default:
  5049. ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
  5050. return false;
  5051. }
  5052. }
  5053. return true;
  5054. }
  5055. static void ath10k_mac_set_bitrate_mask_iter(void *data,
  5056. struct ieee80211_sta *sta)
  5057. {
  5058. struct ath10k_vif *arvif = data;
  5059. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  5060. struct ath10k *ar = arvif->ar;
  5061. if (arsta->arvif != arvif)
  5062. return;
  5063. spin_lock_bh(&ar->data_lock);
  5064. arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
  5065. spin_unlock_bh(&ar->data_lock);
  5066. ieee80211_queue_work(ar->hw, &arsta->update_wk);
  5067. }
  5068. static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
  5069. struct ieee80211_vif *vif,
  5070. const struct cfg80211_bitrate_mask *mask)
  5071. {
  5072. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  5073. struct cfg80211_chan_def def;
  5074. struct ath10k *ar = arvif->ar;
  5075. enum ieee80211_band band;
  5076. const u8 *ht_mcs_mask;
  5077. const u16 *vht_mcs_mask;
  5078. u8 rate;
  5079. u8 nss;
  5080. u8 sgi;
  5081. u8 ldpc;
  5082. int single_nss;
  5083. int ret;
  5084. if (ath10k_mac_vif_chan(vif, &def))
  5085. return -EPERM;
  5086. band = def.chan->band;
  5087. ht_mcs_mask = mask->control[band].ht_mcs;
  5088. vht_mcs_mask = mask->control[band].vht_mcs;
  5089. ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
  5090. sgi = mask->control[band].gi;
  5091. if (sgi == NL80211_TXRATE_FORCE_LGI)
  5092. return -EINVAL;
  5093. if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
  5094. ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
  5095. &rate, &nss);
  5096. if (ret) {
  5097. ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
  5098. arvif->vdev_id, ret);
  5099. return ret;
  5100. }
  5101. } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
  5102. &single_nss)) {
  5103. rate = WMI_FIXED_RATE_NONE;
  5104. nss = single_nss;
  5105. } else {
  5106. rate = WMI_FIXED_RATE_NONE;
  5107. nss = min(ar->num_rf_chains,
  5108. max(ath10k_mac_max_ht_nss(ht_mcs_mask),
  5109. ath10k_mac_max_vht_nss(vht_mcs_mask)));
  5110. if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
  5111. return -EINVAL;
  5112. mutex_lock(&ar->conf_mutex);
  5113. arvif->bitrate_mask = *mask;
  5114. ieee80211_iterate_stations_atomic(ar->hw,
  5115. ath10k_mac_set_bitrate_mask_iter,
  5116. arvif);
  5117. mutex_unlock(&ar->conf_mutex);
  5118. }
  5119. mutex_lock(&ar->conf_mutex);
  5120. ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
  5121. if (ret) {
  5122. ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
  5123. arvif->vdev_id, ret);
  5124. goto exit;
  5125. }
  5126. exit:
  5127. mutex_unlock(&ar->conf_mutex);
  5128. return ret;
  5129. }
  5130. static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
  5131. struct ieee80211_vif *vif,
  5132. struct ieee80211_sta *sta,
  5133. u32 changed)
  5134. {
  5135. struct ath10k *ar = hw->priv;
  5136. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  5137. u32 bw, smps;
  5138. spin_lock_bh(&ar->data_lock);
  5139. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5140. "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
  5141. sta->addr, changed, sta->bandwidth, sta->rx_nss,
  5142. sta->smps_mode);
  5143. if (changed & IEEE80211_RC_BW_CHANGED) {
  5144. bw = WMI_PEER_CHWIDTH_20MHZ;
  5145. switch (sta->bandwidth) {
  5146. case IEEE80211_STA_RX_BW_20:
  5147. bw = WMI_PEER_CHWIDTH_20MHZ;
  5148. break;
  5149. case IEEE80211_STA_RX_BW_40:
  5150. bw = WMI_PEER_CHWIDTH_40MHZ;
  5151. break;
  5152. case IEEE80211_STA_RX_BW_80:
  5153. bw = WMI_PEER_CHWIDTH_80MHZ;
  5154. break;
  5155. case IEEE80211_STA_RX_BW_160:
  5156. ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
  5157. sta->bandwidth, sta->addr);
  5158. bw = WMI_PEER_CHWIDTH_20MHZ;
  5159. break;
  5160. }
  5161. arsta->bw = bw;
  5162. }
  5163. if (changed & IEEE80211_RC_NSS_CHANGED)
  5164. arsta->nss = sta->rx_nss;
  5165. if (changed & IEEE80211_RC_SMPS_CHANGED) {
  5166. smps = WMI_PEER_SMPS_PS_NONE;
  5167. switch (sta->smps_mode) {
  5168. case IEEE80211_SMPS_AUTOMATIC:
  5169. case IEEE80211_SMPS_OFF:
  5170. smps = WMI_PEER_SMPS_PS_NONE;
  5171. break;
  5172. case IEEE80211_SMPS_STATIC:
  5173. smps = WMI_PEER_SMPS_STATIC;
  5174. break;
  5175. case IEEE80211_SMPS_DYNAMIC:
  5176. smps = WMI_PEER_SMPS_DYNAMIC;
  5177. break;
  5178. case IEEE80211_SMPS_NUM_MODES:
  5179. ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
  5180. sta->smps_mode, sta->addr);
  5181. smps = WMI_PEER_SMPS_PS_NONE;
  5182. break;
  5183. }
  5184. arsta->smps = smps;
  5185. }
  5186. arsta->changed |= changed;
  5187. spin_unlock_bh(&ar->data_lock);
  5188. ieee80211_queue_work(hw, &arsta->update_wk);
  5189. }
  5190. static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  5191. {
  5192. /*
  5193. * FIXME: Return 0 for time being. Need to figure out whether FW
  5194. * has the API to fetch 64-bit local TSF
  5195. */
  5196. return 0;
  5197. }
  5198. static int ath10k_ampdu_action(struct ieee80211_hw *hw,
  5199. struct ieee80211_vif *vif,
  5200. struct ieee80211_ampdu_params *params)
  5201. {
  5202. struct ath10k *ar = hw->priv;
  5203. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  5204. struct ieee80211_sta *sta = params->sta;
  5205. enum ieee80211_ampdu_mlme_action action = params->action;
  5206. u16 tid = params->tid;
  5207. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
  5208. arvif->vdev_id, sta->addr, tid, action);
  5209. switch (action) {
  5210. case IEEE80211_AMPDU_RX_START:
  5211. case IEEE80211_AMPDU_RX_STOP:
  5212. /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
  5213. * creation/removal. Do we need to verify this?
  5214. */
  5215. return 0;
  5216. case IEEE80211_AMPDU_TX_START:
  5217. case IEEE80211_AMPDU_TX_STOP_CONT:
  5218. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  5219. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  5220. case IEEE80211_AMPDU_TX_OPERATIONAL:
  5221. /* Firmware offloads Tx aggregation entirely so deny mac80211
  5222. * Tx aggregation requests.
  5223. */
  5224. return -EOPNOTSUPP;
  5225. }
  5226. return -EINVAL;
  5227. }
  5228. static void
  5229. ath10k_mac_update_rx_channel(struct ath10k *ar,
  5230. struct ieee80211_chanctx_conf *ctx,
  5231. struct ieee80211_vif_chanctx_switch *vifs,
  5232. int n_vifs)
  5233. {
  5234. struct cfg80211_chan_def *def = NULL;
  5235. /* Both locks are required because ar->rx_channel is modified. This
  5236. * allows readers to hold either lock.
  5237. */
  5238. lockdep_assert_held(&ar->conf_mutex);
  5239. lockdep_assert_held(&ar->data_lock);
  5240. WARN_ON(ctx && vifs);
  5241. WARN_ON(vifs && n_vifs != 1);
  5242. /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
  5243. * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
  5244. * ppdu on Rx may reduce performance on low-end systems. It should be
  5245. * possible to make tables/hashmaps to speed the lookup up (be vary of
  5246. * cpu data cache lines though regarding sizes) but to keep the initial
  5247. * implementation simple and less intrusive fallback to the slow lookup
  5248. * only for multi-channel cases. Single-channel cases will remain to
  5249. * use the old channel derival and thus performance should not be
  5250. * affected much.
  5251. */
  5252. rcu_read_lock();
  5253. if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
  5254. ieee80211_iter_chan_contexts_atomic(ar->hw,
  5255. ath10k_mac_get_any_chandef_iter,
  5256. &def);
  5257. if (vifs)
  5258. def = &vifs[0].new_ctx->def;
  5259. ar->rx_channel = def->chan;
  5260. } else if (ctx && ath10k_mac_num_chanctxs(ar) == 0) {
  5261. ar->rx_channel = ctx->def.chan;
  5262. } else {
  5263. ar->rx_channel = NULL;
  5264. }
  5265. rcu_read_unlock();
  5266. }
  5267. static void
  5268. ath10k_mac_update_vif_chan(struct ath10k *ar,
  5269. struct ieee80211_vif_chanctx_switch *vifs,
  5270. int n_vifs)
  5271. {
  5272. struct ath10k_vif *arvif;
  5273. int ret;
  5274. int i;
  5275. lockdep_assert_held(&ar->conf_mutex);
  5276. /* First stop monitor interface. Some FW versions crash if there's a
  5277. * lone monitor interface.
  5278. */
  5279. if (ar->monitor_started)
  5280. ath10k_monitor_stop(ar);
  5281. for (i = 0; i < n_vifs; i++) {
  5282. arvif = ath10k_vif_to_arvif(vifs[i].vif);
  5283. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5284. "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
  5285. arvif->vdev_id,
  5286. vifs[i].old_ctx->def.chan->center_freq,
  5287. vifs[i].new_ctx->def.chan->center_freq,
  5288. vifs[i].old_ctx->def.width,
  5289. vifs[i].new_ctx->def.width);
  5290. if (WARN_ON(!arvif->is_started))
  5291. continue;
  5292. if (WARN_ON(!arvif->is_up))
  5293. continue;
  5294. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  5295. if (ret) {
  5296. ath10k_warn(ar, "failed to down vdev %d: %d\n",
  5297. arvif->vdev_id, ret);
  5298. continue;
  5299. }
  5300. }
  5301. /* All relevant vdevs are downed and associated channel resources
  5302. * should be available for the channel switch now.
  5303. */
  5304. spin_lock_bh(&ar->data_lock);
  5305. ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
  5306. spin_unlock_bh(&ar->data_lock);
  5307. for (i = 0; i < n_vifs; i++) {
  5308. arvif = ath10k_vif_to_arvif(vifs[i].vif);
  5309. if (WARN_ON(!arvif->is_started))
  5310. continue;
  5311. if (WARN_ON(!arvif->is_up))
  5312. continue;
  5313. ret = ath10k_mac_setup_bcn_tmpl(arvif);
  5314. if (ret)
  5315. ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
  5316. ret);
  5317. ret = ath10k_mac_setup_prb_tmpl(arvif);
  5318. if (ret)
  5319. ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
  5320. ret);
  5321. ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
  5322. if (ret) {
  5323. ath10k_warn(ar, "failed to restart vdev %d: %d\n",
  5324. arvif->vdev_id, ret);
  5325. continue;
  5326. }
  5327. ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
  5328. arvif->bssid);
  5329. if (ret) {
  5330. ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
  5331. arvif->vdev_id, ret);
  5332. continue;
  5333. }
  5334. }
  5335. ath10k_monitor_recalc(ar);
  5336. }
  5337. static int
  5338. ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
  5339. struct ieee80211_chanctx_conf *ctx)
  5340. {
  5341. struct ath10k *ar = hw->priv;
  5342. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5343. "mac chanctx add freq %hu width %d ptr %p\n",
  5344. ctx->def.chan->center_freq, ctx->def.width, ctx);
  5345. mutex_lock(&ar->conf_mutex);
  5346. spin_lock_bh(&ar->data_lock);
  5347. ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
  5348. spin_unlock_bh(&ar->data_lock);
  5349. ath10k_recalc_radar_detection(ar);
  5350. ath10k_monitor_recalc(ar);
  5351. mutex_unlock(&ar->conf_mutex);
  5352. return 0;
  5353. }
  5354. static void
  5355. ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
  5356. struct ieee80211_chanctx_conf *ctx)
  5357. {
  5358. struct ath10k *ar = hw->priv;
  5359. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5360. "mac chanctx remove freq %hu width %d ptr %p\n",
  5361. ctx->def.chan->center_freq, ctx->def.width, ctx);
  5362. mutex_lock(&ar->conf_mutex);
  5363. spin_lock_bh(&ar->data_lock);
  5364. ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
  5365. spin_unlock_bh(&ar->data_lock);
  5366. ath10k_recalc_radar_detection(ar);
  5367. ath10k_monitor_recalc(ar);
  5368. mutex_unlock(&ar->conf_mutex);
  5369. }
  5370. struct ath10k_mac_change_chanctx_arg {
  5371. struct ieee80211_chanctx_conf *ctx;
  5372. struct ieee80211_vif_chanctx_switch *vifs;
  5373. int n_vifs;
  5374. int next_vif;
  5375. };
  5376. static void
  5377. ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
  5378. struct ieee80211_vif *vif)
  5379. {
  5380. struct ath10k_mac_change_chanctx_arg *arg = data;
  5381. if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
  5382. return;
  5383. arg->n_vifs++;
  5384. }
  5385. static void
  5386. ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
  5387. struct ieee80211_vif *vif)
  5388. {
  5389. struct ath10k_mac_change_chanctx_arg *arg = data;
  5390. struct ieee80211_chanctx_conf *ctx;
  5391. ctx = rcu_access_pointer(vif->chanctx_conf);
  5392. if (ctx != arg->ctx)
  5393. return;
  5394. if (WARN_ON(arg->next_vif == arg->n_vifs))
  5395. return;
  5396. arg->vifs[arg->next_vif].vif = vif;
  5397. arg->vifs[arg->next_vif].old_ctx = ctx;
  5398. arg->vifs[arg->next_vif].new_ctx = ctx;
  5399. arg->next_vif++;
  5400. }
  5401. static void
  5402. ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
  5403. struct ieee80211_chanctx_conf *ctx,
  5404. u32 changed)
  5405. {
  5406. struct ath10k *ar = hw->priv;
  5407. struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
  5408. mutex_lock(&ar->conf_mutex);
  5409. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5410. "mac chanctx change freq %hu width %d ptr %p changed %x\n",
  5411. ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
  5412. /* This shouldn't really happen because channel switching should use
  5413. * switch_vif_chanctx().
  5414. */
  5415. if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
  5416. goto unlock;
  5417. if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
  5418. ieee80211_iterate_active_interfaces_atomic(
  5419. hw,
  5420. IEEE80211_IFACE_ITER_NORMAL,
  5421. ath10k_mac_change_chanctx_cnt_iter,
  5422. &arg);
  5423. if (arg.n_vifs == 0)
  5424. goto radar;
  5425. arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
  5426. GFP_KERNEL);
  5427. if (!arg.vifs)
  5428. goto radar;
  5429. ieee80211_iterate_active_interfaces_atomic(
  5430. hw,
  5431. IEEE80211_IFACE_ITER_NORMAL,
  5432. ath10k_mac_change_chanctx_fill_iter,
  5433. &arg);
  5434. ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
  5435. kfree(arg.vifs);
  5436. }
  5437. radar:
  5438. ath10k_recalc_radar_detection(ar);
  5439. /* FIXME: How to configure Rx chains properly? */
  5440. /* No other actions are actually necessary. Firmware maintains channel
  5441. * definitions per vdev internally and there's no host-side channel
  5442. * context abstraction to configure, e.g. channel width.
  5443. */
  5444. unlock:
  5445. mutex_unlock(&ar->conf_mutex);
  5446. }
  5447. static int
  5448. ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
  5449. struct ieee80211_vif *vif,
  5450. struct ieee80211_chanctx_conf *ctx)
  5451. {
  5452. struct ath10k *ar = hw->priv;
  5453. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  5454. int ret;
  5455. mutex_lock(&ar->conf_mutex);
  5456. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5457. "mac chanctx assign ptr %p vdev_id %i\n",
  5458. ctx, arvif->vdev_id);
  5459. if (WARN_ON(arvif->is_started)) {
  5460. mutex_unlock(&ar->conf_mutex);
  5461. return -EBUSY;
  5462. }
  5463. ret = ath10k_vdev_start(arvif, &ctx->def);
  5464. if (ret) {
  5465. ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
  5466. arvif->vdev_id, vif->addr,
  5467. ctx->def.chan->center_freq, ret);
  5468. goto err;
  5469. }
  5470. arvif->is_started = true;
  5471. ret = ath10k_mac_vif_setup_ps(arvif);
  5472. if (ret) {
  5473. ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
  5474. arvif->vdev_id, ret);
  5475. goto err_stop;
  5476. }
  5477. if (vif->type == NL80211_IFTYPE_MONITOR) {
  5478. ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
  5479. if (ret) {
  5480. ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
  5481. arvif->vdev_id, ret);
  5482. goto err_stop;
  5483. }
  5484. arvif->is_up = true;
  5485. }
  5486. mutex_unlock(&ar->conf_mutex);
  5487. return 0;
  5488. err_stop:
  5489. ath10k_vdev_stop(arvif);
  5490. arvif->is_started = false;
  5491. ath10k_mac_vif_setup_ps(arvif);
  5492. err:
  5493. mutex_unlock(&ar->conf_mutex);
  5494. return ret;
  5495. }
  5496. static void
  5497. ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
  5498. struct ieee80211_vif *vif,
  5499. struct ieee80211_chanctx_conf *ctx)
  5500. {
  5501. struct ath10k *ar = hw->priv;
  5502. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  5503. int ret;
  5504. mutex_lock(&ar->conf_mutex);
  5505. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5506. "mac chanctx unassign ptr %p vdev_id %i\n",
  5507. ctx, arvif->vdev_id);
  5508. WARN_ON(!arvif->is_started);
  5509. if (vif->type == NL80211_IFTYPE_MONITOR) {
  5510. WARN_ON(!arvif->is_up);
  5511. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  5512. if (ret)
  5513. ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
  5514. arvif->vdev_id, ret);
  5515. arvif->is_up = false;
  5516. }
  5517. ret = ath10k_vdev_stop(arvif);
  5518. if (ret)
  5519. ath10k_warn(ar, "failed to stop vdev %i: %d\n",
  5520. arvif->vdev_id, ret);
  5521. arvif->is_started = false;
  5522. mutex_unlock(&ar->conf_mutex);
  5523. }
  5524. static int
  5525. ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
  5526. struct ieee80211_vif_chanctx_switch *vifs,
  5527. int n_vifs,
  5528. enum ieee80211_chanctx_switch_mode mode)
  5529. {
  5530. struct ath10k *ar = hw->priv;
  5531. mutex_lock(&ar->conf_mutex);
  5532. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5533. "mac chanctx switch n_vifs %d mode %d\n",
  5534. n_vifs, mode);
  5535. ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
  5536. mutex_unlock(&ar->conf_mutex);
  5537. return 0;
  5538. }
  5539. static const struct ieee80211_ops ath10k_ops = {
  5540. .tx = ath10k_tx,
  5541. .start = ath10k_start,
  5542. .stop = ath10k_stop,
  5543. .config = ath10k_config,
  5544. .add_interface = ath10k_add_interface,
  5545. .remove_interface = ath10k_remove_interface,
  5546. .configure_filter = ath10k_configure_filter,
  5547. .bss_info_changed = ath10k_bss_info_changed,
  5548. .hw_scan = ath10k_hw_scan,
  5549. .cancel_hw_scan = ath10k_cancel_hw_scan,
  5550. .set_key = ath10k_set_key,
  5551. .set_default_unicast_key = ath10k_set_default_unicast_key,
  5552. .sta_state = ath10k_sta_state,
  5553. .conf_tx = ath10k_conf_tx,
  5554. .remain_on_channel = ath10k_remain_on_channel,
  5555. .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
  5556. .set_rts_threshold = ath10k_set_rts_threshold,
  5557. .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
  5558. .flush = ath10k_flush,
  5559. .tx_last_beacon = ath10k_tx_last_beacon,
  5560. .set_antenna = ath10k_set_antenna,
  5561. .get_antenna = ath10k_get_antenna,
  5562. .reconfig_complete = ath10k_reconfig_complete,
  5563. .get_survey = ath10k_get_survey,
  5564. .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
  5565. .sta_rc_update = ath10k_sta_rc_update,
  5566. .get_tsf = ath10k_get_tsf,
  5567. .ampdu_action = ath10k_ampdu_action,
  5568. .get_et_sset_count = ath10k_debug_get_et_sset_count,
  5569. .get_et_stats = ath10k_debug_get_et_stats,
  5570. .get_et_strings = ath10k_debug_get_et_strings,
  5571. .add_chanctx = ath10k_mac_op_add_chanctx,
  5572. .remove_chanctx = ath10k_mac_op_remove_chanctx,
  5573. .change_chanctx = ath10k_mac_op_change_chanctx,
  5574. .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
  5575. .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
  5576. .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
  5577. CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
  5578. #ifdef CONFIG_PM
  5579. .suspend = ath10k_wow_op_suspend,
  5580. .resume = ath10k_wow_op_resume,
  5581. #endif
  5582. #ifdef CONFIG_MAC80211_DEBUGFS
  5583. .sta_add_debugfs = ath10k_sta_add_debugfs,
  5584. #endif
  5585. };
  5586. #define CHAN2G(_channel, _freq, _flags) { \
  5587. .band = IEEE80211_BAND_2GHZ, \
  5588. .hw_value = (_channel), \
  5589. .center_freq = (_freq), \
  5590. .flags = (_flags), \
  5591. .max_antenna_gain = 0, \
  5592. .max_power = 30, \
  5593. }
  5594. #define CHAN5G(_channel, _freq, _flags) { \
  5595. .band = IEEE80211_BAND_5GHZ, \
  5596. .hw_value = (_channel), \
  5597. .center_freq = (_freq), \
  5598. .flags = (_flags), \
  5599. .max_antenna_gain = 0, \
  5600. .max_power = 30, \
  5601. }
  5602. static const struct ieee80211_channel ath10k_2ghz_channels[] = {
  5603. CHAN2G(1, 2412, 0),
  5604. CHAN2G(2, 2417, 0),
  5605. CHAN2G(3, 2422, 0),
  5606. CHAN2G(4, 2427, 0),
  5607. CHAN2G(5, 2432, 0),
  5608. CHAN2G(6, 2437, 0),
  5609. CHAN2G(7, 2442, 0),
  5610. CHAN2G(8, 2447, 0),
  5611. CHAN2G(9, 2452, 0),
  5612. CHAN2G(10, 2457, 0),
  5613. CHAN2G(11, 2462, 0),
  5614. CHAN2G(12, 2467, 0),
  5615. CHAN2G(13, 2472, 0),
  5616. CHAN2G(14, 2484, 0),
  5617. };
  5618. static const struct ieee80211_channel ath10k_5ghz_channels[] = {
  5619. CHAN5G(36, 5180, 0),
  5620. CHAN5G(40, 5200, 0),
  5621. CHAN5G(44, 5220, 0),
  5622. CHAN5G(48, 5240, 0),
  5623. CHAN5G(52, 5260, 0),
  5624. CHAN5G(56, 5280, 0),
  5625. CHAN5G(60, 5300, 0),
  5626. CHAN5G(64, 5320, 0),
  5627. CHAN5G(100, 5500, 0),
  5628. CHAN5G(104, 5520, 0),
  5629. CHAN5G(108, 5540, 0),
  5630. CHAN5G(112, 5560, 0),
  5631. CHAN5G(116, 5580, 0),
  5632. CHAN5G(120, 5600, 0),
  5633. CHAN5G(124, 5620, 0),
  5634. CHAN5G(128, 5640, 0),
  5635. CHAN5G(132, 5660, 0),
  5636. CHAN5G(136, 5680, 0),
  5637. CHAN5G(140, 5700, 0),
  5638. CHAN5G(144, 5720, 0),
  5639. CHAN5G(149, 5745, 0),
  5640. CHAN5G(153, 5765, 0),
  5641. CHAN5G(157, 5785, 0),
  5642. CHAN5G(161, 5805, 0),
  5643. CHAN5G(165, 5825, 0),
  5644. };
  5645. struct ath10k *ath10k_mac_create(size_t priv_size)
  5646. {
  5647. struct ieee80211_hw *hw;
  5648. struct ath10k *ar;
  5649. hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
  5650. if (!hw)
  5651. return NULL;
  5652. ar = hw->priv;
  5653. ar->hw = hw;
  5654. return ar;
  5655. }
  5656. void ath10k_mac_destroy(struct ath10k *ar)
  5657. {
  5658. ieee80211_free_hw(ar->hw);
  5659. }
  5660. static const struct ieee80211_iface_limit ath10k_if_limits[] = {
  5661. {
  5662. .max = 8,
  5663. .types = BIT(NL80211_IFTYPE_STATION)
  5664. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  5665. },
  5666. {
  5667. .max = 3,
  5668. .types = BIT(NL80211_IFTYPE_P2P_GO)
  5669. },
  5670. {
  5671. .max = 1,
  5672. .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
  5673. },
  5674. {
  5675. .max = 7,
  5676. .types = BIT(NL80211_IFTYPE_AP)
  5677. #ifdef CONFIG_MAC80211_MESH
  5678. | BIT(NL80211_IFTYPE_MESH_POINT)
  5679. #endif
  5680. },
  5681. };
  5682. static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
  5683. {
  5684. .max = 8,
  5685. .types = BIT(NL80211_IFTYPE_AP)
  5686. #ifdef CONFIG_MAC80211_MESH
  5687. | BIT(NL80211_IFTYPE_MESH_POINT)
  5688. #endif
  5689. },
  5690. {
  5691. .max = 1,
  5692. .types = BIT(NL80211_IFTYPE_STATION)
  5693. },
  5694. };
  5695. static const struct ieee80211_iface_combination ath10k_if_comb[] = {
  5696. {
  5697. .limits = ath10k_if_limits,
  5698. .n_limits = ARRAY_SIZE(ath10k_if_limits),
  5699. .max_interfaces = 8,
  5700. .num_different_channels = 1,
  5701. .beacon_int_infra_match = true,
  5702. },
  5703. };
  5704. static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
  5705. {
  5706. .limits = ath10k_10x_if_limits,
  5707. .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
  5708. .max_interfaces = 8,
  5709. .num_different_channels = 1,
  5710. .beacon_int_infra_match = true,
  5711. #ifdef CONFIG_ATH10K_DFS_CERTIFIED
  5712. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  5713. BIT(NL80211_CHAN_WIDTH_20) |
  5714. BIT(NL80211_CHAN_WIDTH_40) |
  5715. BIT(NL80211_CHAN_WIDTH_80),
  5716. #endif
  5717. },
  5718. };
  5719. static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
  5720. {
  5721. .max = 2,
  5722. .types = BIT(NL80211_IFTYPE_STATION),
  5723. },
  5724. {
  5725. .max = 2,
  5726. .types = BIT(NL80211_IFTYPE_AP) |
  5727. #ifdef CONFIG_MAC80211_MESH
  5728. BIT(NL80211_IFTYPE_MESH_POINT) |
  5729. #endif
  5730. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  5731. BIT(NL80211_IFTYPE_P2P_GO),
  5732. },
  5733. {
  5734. .max = 1,
  5735. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  5736. },
  5737. };
  5738. static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
  5739. {
  5740. .max = 2,
  5741. .types = BIT(NL80211_IFTYPE_STATION),
  5742. },
  5743. {
  5744. .max = 2,
  5745. .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
  5746. },
  5747. {
  5748. .max = 1,
  5749. .types = BIT(NL80211_IFTYPE_AP) |
  5750. #ifdef CONFIG_MAC80211_MESH
  5751. BIT(NL80211_IFTYPE_MESH_POINT) |
  5752. #endif
  5753. BIT(NL80211_IFTYPE_P2P_GO),
  5754. },
  5755. {
  5756. .max = 1,
  5757. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  5758. },
  5759. };
  5760. static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
  5761. {
  5762. .max = 1,
  5763. .types = BIT(NL80211_IFTYPE_STATION),
  5764. },
  5765. {
  5766. .max = 1,
  5767. .types = BIT(NL80211_IFTYPE_ADHOC),
  5768. },
  5769. };
  5770. /* FIXME: This is not thouroughly tested. These combinations may over- or
  5771. * underestimate hw/fw capabilities.
  5772. */
  5773. static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
  5774. {
  5775. .limits = ath10k_tlv_if_limit,
  5776. .num_different_channels = 1,
  5777. .max_interfaces = 4,
  5778. .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
  5779. },
  5780. {
  5781. .limits = ath10k_tlv_if_limit_ibss,
  5782. .num_different_channels = 1,
  5783. .max_interfaces = 2,
  5784. .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
  5785. },
  5786. };
  5787. static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
  5788. {
  5789. .limits = ath10k_tlv_if_limit,
  5790. .num_different_channels = 1,
  5791. .max_interfaces = 4,
  5792. .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
  5793. },
  5794. {
  5795. .limits = ath10k_tlv_qcs_if_limit,
  5796. .num_different_channels = 2,
  5797. .max_interfaces = 4,
  5798. .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
  5799. },
  5800. {
  5801. .limits = ath10k_tlv_if_limit_ibss,
  5802. .num_different_channels = 1,
  5803. .max_interfaces = 2,
  5804. .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
  5805. },
  5806. };
  5807. static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
  5808. {
  5809. .max = 1,
  5810. .types = BIT(NL80211_IFTYPE_STATION),
  5811. },
  5812. {
  5813. .max = 16,
  5814. .types = BIT(NL80211_IFTYPE_AP)
  5815. #ifdef CONFIG_MAC80211_MESH
  5816. | BIT(NL80211_IFTYPE_MESH_POINT)
  5817. #endif
  5818. },
  5819. };
  5820. static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
  5821. {
  5822. .limits = ath10k_10_4_if_limits,
  5823. .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
  5824. .max_interfaces = 16,
  5825. .num_different_channels = 1,
  5826. .beacon_int_infra_match = true,
  5827. #ifdef CONFIG_ATH10K_DFS_CERTIFIED
  5828. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  5829. BIT(NL80211_CHAN_WIDTH_20) |
  5830. BIT(NL80211_CHAN_WIDTH_40) |
  5831. BIT(NL80211_CHAN_WIDTH_80),
  5832. #endif
  5833. },
  5834. };
  5835. static void ath10k_get_arvif_iter(void *data, u8 *mac,
  5836. struct ieee80211_vif *vif)
  5837. {
  5838. struct ath10k_vif_iter *arvif_iter = data;
  5839. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  5840. if (arvif->vdev_id == arvif_iter->vdev_id)
  5841. arvif_iter->arvif = arvif;
  5842. }
  5843. struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
  5844. {
  5845. struct ath10k_vif_iter arvif_iter;
  5846. u32 flags;
  5847. memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
  5848. arvif_iter.vdev_id = vdev_id;
  5849. flags = IEEE80211_IFACE_ITER_RESUME_ALL;
  5850. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  5851. flags,
  5852. ath10k_get_arvif_iter,
  5853. &arvif_iter);
  5854. if (!arvif_iter.arvif) {
  5855. ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
  5856. return NULL;
  5857. }
  5858. return arvif_iter.arvif;
  5859. }
  5860. int ath10k_mac_register(struct ath10k *ar)
  5861. {
  5862. static const u32 cipher_suites[] = {
  5863. WLAN_CIPHER_SUITE_WEP40,
  5864. WLAN_CIPHER_SUITE_WEP104,
  5865. WLAN_CIPHER_SUITE_TKIP,
  5866. WLAN_CIPHER_SUITE_CCMP,
  5867. WLAN_CIPHER_SUITE_AES_CMAC,
  5868. };
  5869. struct ieee80211_supported_band *band;
  5870. void *channels;
  5871. int ret;
  5872. SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
  5873. SET_IEEE80211_DEV(ar->hw, ar->dev);
  5874. BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
  5875. ARRAY_SIZE(ath10k_5ghz_channels)) !=
  5876. ATH10K_NUM_CHANS);
  5877. if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
  5878. channels = kmemdup(ath10k_2ghz_channels,
  5879. sizeof(ath10k_2ghz_channels),
  5880. GFP_KERNEL);
  5881. if (!channels) {
  5882. ret = -ENOMEM;
  5883. goto err_free;
  5884. }
  5885. band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
  5886. band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
  5887. band->channels = channels;
  5888. band->n_bitrates = ath10k_g_rates_size;
  5889. band->bitrates = ath10k_g_rates;
  5890. ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
  5891. }
  5892. if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
  5893. channels = kmemdup(ath10k_5ghz_channels,
  5894. sizeof(ath10k_5ghz_channels),
  5895. GFP_KERNEL);
  5896. if (!channels) {
  5897. ret = -ENOMEM;
  5898. goto err_free;
  5899. }
  5900. band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
  5901. band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
  5902. band->channels = channels;
  5903. band->n_bitrates = ath10k_a_rates_size;
  5904. band->bitrates = ath10k_a_rates;
  5905. ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
  5906. }
  5907. ath10k_mac_setup_ht_vht_cap(ar);
  5908. ar->hw->wiphy->interface_modes =
  5909. BIT(NL80211_IFTYPE_STATION) |
  5910. BIT(NL80211_IFTYPE_AP) |
  5911. BIT(NL80211_IFTYPE_MESH_POINT);
  5912. ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
  5913. ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
  5914. if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
  5915. ar->hw->wiphy->interface_modes |=
  5916. BIT(NL80211_IFTYPE_P2P_DEVICE) |
  5917. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  5918. BIT(NL80211_IFTYPE_P2P_GO);
  5919. ieee80211_hw_set(ar->hw, SIGNAL_DBM);
  5920. ieee80211_hw_set(ar->hw, SUPPORTS_PS);
  5921. ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
  5922. ieee80211_hw_set(ar->hw, MFP_CAPABLE);
  5923. ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
  5924. ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
  5925. ieee80211_hw_set(ar->hw, AP_LINK_PS);
  5926. ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
  5927. ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
  5928. ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
  5929. ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
  5930. ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
  5931. ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
  5932. ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
  5933. if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
  5934. ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
  5935. ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
  5936. ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  5937. if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
  5938. ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
  5939. if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
  5940. ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
  5941. ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
  5942. }
  5943. ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
  5944. ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
  5945. ar->hw->vif_data_size = sizeof(struct ath10k_vif);
  5946. ar->hw->sta_data_size = sizeof(struct ath10k_sta);
  5947. ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
  5948. if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
  5949. ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  5950. /* Firmware delivers WPS/P2P Probe Requests frames to driver so
  5951. * that userspace (e.g. wpa_supplicant/hostapd) can generate
  5952. * correct Probe Responses. This is more of a hack advert..
  5953. */
  5954. ar->hw->wiphy->probe_resp_offload |=
  5955. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  5956. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  5957. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  5958. }
  5959. if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
  5960. ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  5961. ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  5962. ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  5963. ar->hw->wiphy->max_remain_on_channel_duration = 5000;
  5964. ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  5965. ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
  5966. ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
  5967. ret = ath10k_wow_init(ar);
  5968. if (ret) {
  5969. ath10k_warn(ar, "failed to init wow: %d\n", ret);
  5970. goto err_free;
  5971. }
  5972. wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
  5973. /*
  5974. * on LL hardware queues are managed entirely by the FW
  5975. * so we only advertise to mac we can do the queues thing
  5976. */
  5977. ar->hw->queues = IEEE80211_MAX_QUEUES;
  5978. /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
  5979. * something that vdev_ids can't reach so that we don't stop the queue
  5980. * accidentally.
  5981. */
  5982. ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
  5983. switch (ar->wmi.op_version) {
  5984. case ATH10K_FW_WMI_OP_VERSION_MAIN:
  5985. ar->hw->wiphy->iface_combinations = ath10k_if_comb;
  5986. ar->hw->wiphy->n_iface_combinations =
  5987. ARRAY_SIZE(ath10k_if_comb);
  5988. ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
  5989. break;
  5990. case ATH10K_FW_WMI_OP_VERSION_TLV:
  5991. if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
  5992. ar->hw->wiphy->iface_combinations =
  5993. ath10k_tlv_qcs_if_comb;
  5994. ar->hw->wiphy->n_iface_combinations =
  5995. ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
  5996. } else {
  5997. ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
  5998. ar->hw->wiphy->n_iface_combinations =
  5999. ARRAY_SIZE(ath10k_tlv_if_comb);
  6000. }
  6001. ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
  6002. break;
  6003. case ATH10K_FW_WMI_OP_VERSION_10_1:
  6004. case ATH10K_FW_WMI_OP_VERSION_10_2:
  6005. case ATH10K_FW_WMI_OP_VERSION_10_2_4:
  6006. ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
  6007. ar->hw->wiphy->n_iface_combinations =
  6008. ARRAY_SIZE(ath10k_10x_if_comb);
  6009. break;
  6010. case ATH10K_FW_WMI_OP_VERSION_10_4:
  6011. ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
  6012. ar->hw->wiphy->n_iface_combinations =
  6013. ARRAY_SIZE(ath10k_10_4_if_comb);
  6014. break;
  6015. case ATH10K_FW_WMI_OP_VERSION_UNSET:
  6016. case ATH10K_FW_WMI_OP_VERSION_MAX:
  6017. WARN_ON(1);
  6018. ret = -EINVAL;
  6019. goto err_free;
  6020. }
  6021. if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
  6022. ar->hw->netdev_features = NETIF_F_HW_CSUM;
  6023. if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
  6024. /* Init ath dfs pattern detector */
  6025. ar->ath_common.debug_mask = ATH_DBG_DFS;
  6026. ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
  6027. NL80211_DFS_UNSET);
  6028. if (!ar->dfs_detector)
  6029. ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
  6030. }
  6031. ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
  6032. ath10k_reg_notifier);
  6033. if (ret) {
  6034. ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
  6035. goto err_dfs_detector_exit;
  6036. }
  6037. ar->hw->wiphy->cipher_suites = cipher_suites;
  6038. ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  6039. ret = ieee80211_register_hw(ar->hw);
  6040. if (ret) {
  6041. ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
  6042. goto err_dfs_detector_exit;
  6043. }
  6044. if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
  6045. ret = regulatory_hint(ar->hw->wiphy,
  6046. ar->ath_common.regulatory.alpha2);
  6047. if (ret)
  6048. goto err_unregister;
  6049. }
  6050. return 0;
  6051. err_unregister:
  6052. ieee80211_unregister_hw(ar->hw);
  6053. err_dfs_detector_exit:
  6054. if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
  6055. ar->dfs_detector->exit(ar->dfs_detector);
  6056. err_free:
  6057. kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
  6058. kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
  6059. SET_IEEE80211_DEV(ar->hw, NULL);
  6060. return ret;
  6061. }
  6062. void ath10k_mac_unregister(struct ath10k *ar)
  6063. {
  6064. ieee80211_unregister_hw(ar->hw);
  6065. if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
  6066. ar->dfs_detector->exit(ar->dfs_detector);
  6067. kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
  6068. kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
  6069. SET_IEEE80211_DEV(ar->hw, NULL);
  6070. }