mac.c 264 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326
  1. // SPDX-License-Identifier: ISC
  2. /*
  3. * Copyright (c) 2005-2011 Atheros Communications Inc.
  4. * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
  5. * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
  6. */
  7. #include "mac.h"
  8. #include <net/cfg80211.h>
  9. #include <net/mac80211.h>
  10. #include <linux/etherdevice.h>
  11. #include <linux/acpi.h>
  12. #include <linux/of.h>
  13. #include <linux/bitfield.h>
  14. #include "hif.h"
  15. #include "core.h"
  16. #include "debug.h"
  17. #include "wmi.h"
  18. #include "htt.h"
  19. #include "txrx.h"
  20. #include "testmode.h"
  21. #include "wmi-tlv.h"
  22. #include "wmi-ops.h"
  23. #include "wow.h"
  24. /*********/
  25. /* Rates */
  26. /*********/
  27. static struct ieee80211_rate ath10k_rates[] = {
  28. { .bitrate = 10,
  29. .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
  30. { .bitrate = 20,
  31. .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
  32. .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
  33. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  34. { .bitrate = 55,
  35. .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
  36. .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
  37. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  38. { .bitrate = 110,
  39. .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
  40. .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
  41. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  42. { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
  43. { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
  44. { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
  45. { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
  46. { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
  47. { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
  48. { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
  49. { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
  50. };
  51. static struct ieee80211_rate ath10k_rates_rev2[] = {
  52. { .bitrate = 10,
  53. .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M },
  54. { .bitrate = 20,
  55. .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M,
  56. .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M,
  57. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  58. { .bitrate = 55,
  59. .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M,
  60. .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M,
  61. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  62. { .bitrate = 110,
  63. .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M,
  64. .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M,
  65. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  66. { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
  67. { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
  68. { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
  69. { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
  70. { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
  71. { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
  72. { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
  73. { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
  74. };
  75. static const struct cfg80211_sar_freq_ranges ath10k_sar_freq_ranges[] = {
  76. {.start_freq = 2402, .end_freq = 2494 },
  77. {.start_freq = 5170, .end_freq = 5875 },
  78. };
  79. static const struct cfg80211_sar_capa ath10k_sar_capa = {
  80. .type = NL80211_SAR_TYPE_POWER,
  81. .num_freq_ranges = (ARRAY_SIZE(ath10k_sar_freq_ranges)),
  82. .freq_ranges = &ath10k_sar_freq_ranges[0],
  83. };
  84. #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
  85. #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
  86. #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
  87. ATH10K_MAC_FIRST_OFDM_RATE_IDX)
  88. #define ath10k_g_rates (ath10k_rates + 0)
  89. #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
  90. #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
  91. #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
  92. #define ath10k_wmi_legacy_rates ath10k_rates
  93. static bool ath10k_mac_bitrate_is_cck(int bitrate)
  94. {
  95. switch (bitrate) {
  96. case 10:
  97. case 20:
  98. case 55:
  99. case 110:
  100. return true;
  101. }
  102. return false;
  103. }
  104. static u8 ath10k_mac_bitrate_to_rate(int bitrate)
  105. {
  106. return DIV_ROUND_UP(bitrate, 5) |
  107. (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
  108. }
  109. u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
  110. u8 hw_rate, bool cck)
  111. {
  112. const struct ieee80211_rate *rate;
  113. int i;
  114. for (i = 0; i < sband->n_bitrates; i++) {
  115. rate = &sband->bitrates[i];
  116. if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
  117. continue;
  118. if (rate->hw_value == hw_rate)
  119. return i;
  120. else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
  121. rate->hw_value_short == hw_rate)
  122. return i;
  123. }
  124. return 0;
  125. }
  126. u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
  127. u32 bitrate)
  128. {
  129. int i;
  130. for (i = 0; i < sband->n_bitrates; i++)
  131. if (sband->bitrates[i].bitrate == bitrate)
  132. return i;
  133. return 0;
  134. }
  135. static int ath10k_mac_get_rate_hw_value(int bitrate)
  136. {
  137. int i;
  138. u8 hw_value_prefix = 0;
  139. if (ath10k_mac_bitrate_is_cck(bitrate))
  140. hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6;
  141. for (i = 0; i < ARRAY_SIZE(ath10k_rates); i++) {
  142. if (ath10k_rates[i].bitrate == bitrate)
  143. return hw_value_prefix | ath10k_rates[i].hw_value;
  144. }
  145. return -EINVAL;
  146. }
  147. static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
  148. {
  149. switch ((mcs_map >> (2 * nss)) & 0x3) {
  150. case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
  151. case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
  152. case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
  153. }
  154. return 0;
  155. }
  156. static u32
  157. ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
  158. {
  159. int nss;
  160. for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
  161. if (ht_mcs_mask[nss])
  162. return nss + 1;
  163. return 1;
  164. }
  165. static u32
  166. ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
  167. {
  168. int nss;
  169. for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
  170. if (vht_mcs_mask[nss])
  171. return nss + 1;
  172. return 1;
  173. }
  174. int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
  175. {
  176. enum wmi_host_platform_type platform_type;
  177. int ret;
  178. if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
  179. platform_type = WMI_HOST_PLATFORM_LOW_PERF;
  180. else
  181. platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
  182. ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
  183. if (ret && ret != -EOPNOTSUPP) {
  184. ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
  185. return ret;
  186. }
  187. return 0;
  188. }
  189. /**********/
  190. /* Crypto */
  191. /**********/
  192. static int ath10k_send_key(struct ath10k_vif *arvif,
  193. struct ieee80211_key_conf *key,
  194. enum set_key_cmd cmd,
  195. const u8 *macaddr, u32 flags)
  196. {
  197. struct ath10k *ar = arvif->ar;
  198. struct wmi_vdev_install_key_arg arg = {
  199. .vdev_id = arvif->vdev_id,
  200. .key_idx = key->keyidx,
  201. .key_len = key->keylen,
  202. .key_data = key->key,
  203. .key_flags = flags,
  204. .macaddr = macaddr,
  205. };
  206. lockdep_assert_held(&arvif->ar->conf_mutex);
  207. switch (key->cipher) {
  208. case WLAN_CIPHER_SUITE_CCMP:
  209. arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_CCM];
  210. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
  211. break;
  212. case WLAN_CIPHER_SUITE_TKIP:
  213. arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_TKIP];
  214. arg.key_txmic_len = 8;
  215. arg.key_rxmic_len = 8;
  216. break;
  217. case WLAN_CIPHER_SUITE_WEP40:
  218. case WLAN_CIPHER_SUITE_WEP104:
  219. arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_WEP];
  220. break;
  221. case WLAN_CIPHER_SUITE_CCMP_256:
  222. arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_CCM];
  223. break;
  224. case WLAN_CIPHER_SUITE_GCMP:
  225. case WLAN_CIPHER_SUITE_GCMP_256:
  226. arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_GCM];
  227. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
  228. break;
  229. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  230. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  231. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  232. case WLAN_CIPHER_SUITE_AES_CMAC:
  233. WARN_ON(1);
  234. return -EINVAL;
  235. default:
  236. ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
  237. return -EOPNOTSUPP;
  238. }
  239. if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
  240. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  241. if (cmd == DISABLE_KEY) {
  242. arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_NONE];
  243. arg.key_data = NULL;
  244. }
  245. return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
  246. }
  247. static int ath10k_install_key(struct ath10k_vif *arvif,
  248. struct ieee80211_key_conf *key,
  249. enum set_key_cmd cmd,
  250. const u8 *macaddr, u32 flags)
  251. {
  252. struct ath10k *ar = arvif->ar;
  253. int ret;
  254. unsigned long time_left;
  255. lockdep_assert_held(&ar->conf_mutex);
  256. reinit_completion(&ar->install_key_done);
  257. if (arvif->nohwcrypt)
  258. return 1;
  259. ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
  260. if (ret)
  261. return ret;
  262. time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
  263. if (time_left == 0)
  264. return -ETIMEDOUT;
  265. return 0;
  266. }
  267. static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
  268. const u8 *addr)
  269. {
  270. struct ath10k *ar = arvif->ar;
  271. struct ath10k_peer *peer;
  272. int ret;
  273. int i;
  274. u32 flags;
  275. lockdep_assert_held(&ar->conf_mutex);
  276. if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
  277. arvif->vif->type != NL80211_IFTYPE_ADHOC &&
  278. arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
  279. return -EINVAL;
  280. spin_lock_bh(&ar->data_lock);
  281. peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
  282. spin_unlock_bh(&ar->data_lock);
  283. if (!peer)
  284. return -ENOENT;
  285. for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
  286. if (arvif->wep_keys[i] == NULL)
  287. continue;
  288. switch (arvif->vif->type) {
  289. case NL80211_IFTYPE_AP:
  290. flags = WMI_KEY_PAIRWISE;
  291. if (arvif->def_wep_key_idx == i)
  292. flags |= WMI_KEY_TX_USAGE;
  293. ret = ath10k_install_key(arvif, arvif->wep_keys[i],
  294. SET_KEY, addr, flags);
  295. if (ret < 0)
  296. return ret;
  297. break;
  298. case NL80211_IFTYPE_ADHOC:
  299. ret = ath10k_install_key(arvif, arvif->wep_keys[i],
  300. SET_KEY, addr,
  301. WMI_KEY_PAIRWISE);
  302. if (ret < 0)
  303. return ret;
  304. ret = ath10k_install_key(arvif, arvif->wep_keys[i],
  305. SET_KEY, addr, WMI_KEY_GROUP);
  306. if (ret < 0)
  307. return ret;
  308. break;
  309. default:
  310. WARN_ON(1);
  311. return -EINVAL;
  312. }
  313. spin_lock_bh(&ar->data_lock);
  314. peer->keys[i] = arvif->wep_keys[i];
  315. spin_unlock_bh(&ar->data_lock);
  316. }
  317. /* In some cases (notably with static WEP IBSS with multiple keys)
  318. * multicast Tx becomes broken. Both pairwise and groupwise keys are
  319. * installed already. Using WMI_KEY_TX_USAGE in different combinations
  320. * didn't seem help. Using def_keyid vdev parameter seems to be
  321. * effective so use that.
  322. *
  323. * FIXME: Revisit. Perhaps this can be done in a less hacky way.
  324. */
  325. if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
  326. return 0;
  327. if (arvif->def_wep_key_idx == -1)
  328. return 0;
  329. ret = ath10k_wmi_vdev_set_param(arvif->ar,
  330. arvif->vdev_id,
  331. arvif->ar->wmi.vdev_param->def_keyid,
  332. arvif->def_wep_key_idx);
  333. if (ret) {
  334. ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
  335. arvif->vdev_id, ret);
  336. return ret;
  337. }
  338. return 0;
  339. }
  340. static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
  341. const u8 *addr)
  342. {
  343. struct ath10k *ar = arvif->ar;
  344. struct ath10k_peer *peer;
  345. int first_errno = 0;
  346. int ret;
  347. int i;
  348. u32 flags = 0;
  349. lockdep_assert_held(&ar->conf_mutex);
  350. spin_lock_bh(&ar->data_lock);
  351. peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
  352. spin_unlock_bh(&ar->data_lock);
  353. if (!peer)
  354. return -ENOENT;
  355. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  356. if (peer->keys[i] == NULL)
  357. continue;
  358. /* key flags are not required to delete the key */
  359. ret = ath10k_install_key(arvif, peer->keys[i],
  360. DISABLE_KEY, addr, flags);
  361. if (ret < 0 && first_errno == 0)
  362. first_errno = ret;
  363. if (ret < 0)
  364. ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
  365. i, ret);
  366. spin_lock_bh(&ar->data_lock);
  367. peer->keys[i] = NULL;
  368. spin_unlock_bh(&ar->data_lock);
  369. }
  370. return first_errno;
  371. }
  372. bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
  373. u8 keyidx)
  374. {
  375. struct ath10k_peer *peer;
  376. int i;
  377. lockdep_assert_held(&ar->data_lock);
  378. /* We don't know which vdev this peer belongs to,
  379. * since WMI doesn't give us that information.
  380. *
  381. * FIXME: multi-bss needs to be handled.
  382. */
  383. peer = ath10k_peer_find(ar, 0, addr);
  384. if (!peer)
  385. return false;
  386. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  387. if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
  388. return true;
  389. }
  390. return false;
  391. }
  392. static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
  393. struct ieee80211_key_conf *key)
  394. {
  395. struct ath10k *ar = arvif->ar;
  396. struct ath10k_peer *peer;
  397. u8 addr[ETH_ALEN];
  398. int first_errno = 0;
  399. int ret;
  400. int i;
  401. u32 flags = 0;
  402. lockdep_assert_held(&ar->conf_mutex);
  403. for (;;) {
  404. /* since ath10k_install_key we can't hold data_lock all the
  405. * time, so we try to remove the keys incrementally
  406. */
  407. spin_lock_bh(&ar->data_lock);
  408. i = 0;
  409. list_for_each_entry(peer, &ar->peers, list) {
  410. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  411. if (peer->keys[i] == key) {
  412. ether_addr_copy(addr, peer->addr);
  413. peer->keys[i] = NULL;
  414. break;
  415. }
  416. }
  417. if (i < ARRAY_SIZE(peer->keys))
  418. break;
  419. }
  420. spin_unlock_bh(&ar->data_lock);
  421. if (i == ARRAY_SIZE(peer->keys))
  422. break;
  423. /* key flags are not required to delete the key */
  424. ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
  425. if (ret < 0 && first_errno == 0)
  426. first_errno = ret;
  427. if (ret)
  428. ath10k_warn(ar, "failed to remove key for %pM: %d\n",
  429. addr, ret);
  430. }
  431. return first_errno;
  432. }
  433. static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
  434. struct ieee80211_key_conf *key)
  435. {
  436. struct ath10k *ar = arvif->ar;
  437. struct ath10k_peer *peer;
  438. int ret;
  439. lockdep_assert_held(&ar->conf_mutex);
  440. list_for_each_entry(peer, &ar->peers, list) {
  441. if (ether_addr_equal(peer->addr, arvif->vif->addr))
  442. continue;
  443. if (ether_addr_equal(peer->addr, arvif->bssid))
  444. continue;
  445. if (peer->keys[key->keyidx] == key)
  446. continue;
  447. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
  448. arvif->vdev_id, key->keyidx);
  449. ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
  450. if (ret) {
  451. ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
  452. arvif->vdev_id, peer->addr, ret);
  453. return ret;
  454. }
  455. }
  456. return 0;
  457. }
  458. /*********************/
  459. /* General utilities */
  460. /*********************/
  461. static inline enum wmi_phy_mode
  462. chan_to_phymode(const struct cfg80211_chan_def *chandef)
  463. {
  464. enum wmi_phy_mode phymode = MODE_UNKNOWN;
  465. switch (chandef->chan->band) {
  466. case NL80211_BAND_2GHZ:
  467. switch (chandef->width) {
  468. case NL80211_CHAN_WIDTH_20_NOHT:
  469. if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
  470. phymode = MODE_11B;
  471. else
  472. phymode = MODE_11G;
  473. break;
  474. case NL80211_CHAN_WIDTH_20:
  475. phymode = MODE_11NG_HT20;
  476. break;
  477. case NL80211_CHAN_WIDTH_40:
  478. phymode = MODE_11NG_HT40;
  479. break;
  480. default:
  481. phymode = MODE_UNKNOWN;
  482. break;
  483. }
  484. break;
  485. case NL80211_BAND_5GHZ:
  486. switch (chandef->width) {
  487. case NL80211_CHAN_WIDTH_20_NOHT:
  488. phymode = MODE_11A;
  489. break;
  490. case NL80211_CHAN_WIDTH_20:
  491. phymode = MODE_11NA_HT20;
  492. break;
  493. case NL80211_CHAN_WIDTH_40:
  494. phymode = MODE_11NA_HT40;
  495. break;
  496. case NL80211_CHAN_WIDTH_80:
  497. phymode = MODE_11AC_VHT80;
  498. break;
  499. case NL80211_CHAN_WIDTH_160:
  500. phymode = MODE_11AC_VHT160;
  501. break;
  502. case NL80211_CHAN_WIDTH_80P80:
  503. phymode = MODE_11AC_VHT80_80;
  504. break;
  505. default:
  506. phymode = MODE_UNKNOWN;
  507. break;
  508. }
  509. break;
  510. default:
  511. break;
  512. }
  513. WARN_ON(phymode == MODE_UNKNOWN);
  514. return phymode;
  515. }
  516. static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
  517. {
  518. /*
  519. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  520. * 0 for no restriction
  521. * 1 for 1/4 us
  522. * 2 for 1/2 us
  523. * 3 for 1 us
  524. * 4 for 2 us
  525. * 5 for 4 us
  526. * 6 for 8 us
  527. * 7 for 16 us
  528. */
  529. switch (mpdudensity) {
  530. case 0:
  531. return 0;
  532. case 1:
  533. case 2:
  534. case 3:
  535. /* Our lower layer calculations limit our precision to
  536. * 1 microsecond
  537. */
  538. return 1;
  539. case 4:
  540. return 2;
  541. case 5:
  542. return 4;
  543. case 6:
  544. return 8;
  545. case 7:
  546. return 16;
  547. default:
  548. return 0;
  549. }
  550. }
  551. int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
  552. struct cfg80211_chan_def *def)
  553. {
  554. struct ieee80211_chanctx_conf *conf;
  555. rcu_read_lock();
  556. conf = rcu_dereference(vif->bss_conf.chanctx_conf);
  557. if (!conf) {
  558. rcu_read_unlock();
  559. return -ENOENT;
  560. }
  561. *def = conf->def;
  562. rcu_read_unlock();
  563. return 0;
  564. }
  565. static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
  566. struct ieee80211_chanctx_conf *conf,
  567. void *data)
  568. {
  569. int *num = data;
  570. (*num)++;
  571. }
  572. static int ath10k_mac_num_chanctxs(struct ath10k *ar)
  573. {
  574. int num = 0;
  575. ieee80211_iter_chan_contexts_atomic(ar->hw,
  576. ath10k_mac_num_chanctxs_iter,
  577. &num);
  578. return num;
  579. }
  580. static void
  581. ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
  582. struct ieee80211_chanctx_conf *conf,
  583. void *data)
  584. {
  585. struct cfg80211_chan_def **def = data;
  586. *def = &conf->def;
  587. }
  588. static void ath10k_wait_for_peer_delete_done(struct ath10k *ar, u32 vdev_id,
  589. const u8 *addr)
  590. {
  591. unsigned long time_left;
  592. int ret;
  593. if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS, ar->wmi.svc_map)) {
  594. ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
  595. if (ret) {
  596. ath10k_warn(ar, "failed wait for peer deleted");
  597. return;
  598. }
  599. time_left = wait_for_completion_timeout(&ar->peer_delete_done,
  600. 5 * HZ);
  601. if (!time_left)
  602. ath10k_warn(ar, "Timeout in receiving peer delete response\n");
  603. }
  604. }
  605. static int ath10k_peer_create(struct ath10k *ar,
  606. struct ieee80211_vif *vif,
  607. struct ieee80211_sta *sta,
  608. u32 vdev_id,
  609. const u8 *addr,
  610. enum wmi_peer_type peer_type)
  611. {
  612. struct ath10k_vif *arvif;
  613. struct ath10k_peer *peer;
  614. int num_peers = 0;
  615. int ret;
  616. lockdep_assert_held(&ar->conf_mutex);
  617. num_peers = ar->num_peers;
  618. /* Each vdev consumes a peer entry as well */
  619. list_for_each_entry(arvif, &ar->arvifs, list)
  620. num_peers++;
  621. if (num_peers >= ar->max_num_peers)
  622. return -ENOBUFS;
  623. ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
  624. if (ret) {
  625. ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
  626. addr, vdev_id, ret);
  627. return ret;
  628. }
  629. ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
  630. if (ret) {
  631. ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
  632. addr, vdev_id, ret);
  633. return ret;
  634. }
  635. spin_lock_bh(&ar->data_lock);
  636. peer = ath10k_peer_find(ar, vdev_id, addr);
  637. if (!peer) {
  638. spin_unlock_bh(&ar->data_lock);
  639. ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
  640. addr, vdev_id);
  641. ath10k_wait_for_peer_delete_done(ar, vdev_id, addr);
  642. return -ENOENT;
  643. }
  644. peer->vif = vif;
  645. peer->sta = sta;
  646. spin_unlock_bh(&ar->data_lock);
  647. ar->num_peers++;
  648. return 0;
  649. }
  650. static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
  651. {
  652. struct ath10k *ar = arvif->ar;
  653. u32 param;
  654. int ret;
  655. param = ar->wmi.pdev_param->sta_kickout_th;
  656. ret = ath10k_wmi_pdev_set_param(ar, param,
  657. ATH10K_KICKOUT_THRESHOLD);
  658. if (ret) {
  659. ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
  660. arvif->vdev_id, ret);
  661. return ret;
  662. }
  663. param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
  664. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
  665. ATH10K_KEEPALIVE_MIN_IDLE);
  666. if (ret) {
  667. ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
  668. arvif->vdev_id, ret);
  669. return ret;
  670. }
  671. param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
  672. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
  673. ATH10K_KEEPALIVE_MAX_IDLE);
  674. if (ret) {
  675. ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
  676. arvif->vdev_id, ret);
  677. return ret;
  678. }
  679. param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
  680. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
  681. ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
  682. if (ret) {
  683. ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
  684. arvif->vdev_id, ret);
  685. return ret;
  686. }
  687. return 0;
  688. }
  689. static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
  690. {
  691. struct ath10k *ar = arvif->ar;
  692. u32 vdev_param;
  693. vdev_param = ar->wmi.vdev_param->rts_threshold;
  694. return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
  695. }
  696. static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
  697. {
  698. int ret;
  699. lockdep_assert_held(&ar->conf_mutex);
  700. ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
  701. if (ret)
  702. return ret;
  703. ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
  704. if (ret)
  705. return ret;
  706. if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS, ar->wmi.svc_map)) {
  707. unsigned long time_left;
  708. time_left = wait_for_completion_timeout
  709. (&ar->peer_delete_done, 5 * HZ);
  710. if (!time_left) {
  711. ath10k_warn(ar, "Timeout in receiving peer delete response\n");
  712. return -ETIMEDOUT;
  713. }
  714. }
  715. ar->num_peers--;
  716. return 0;
  717. }
  718. static void ath10k_peer_map_cleanup(struct ath10k *ar, struct ath10k_peer *peer)
  719. {
  720. int peer_id, i;
  721. lockdep_assert_held(&ar->conf_mutex);
  722. for_each_set_bit(peer_id, peer->peer_ids,
  723. ATH10K_MAX_NUM_PEER_IDS) {
  724. ar->peer_map[peer_id] = NULL;
  725. }
  726. /* Double check that peer is properly un-referenced from
  727. * the peer_map
  728. */
  729. for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
  730. if (ar->peer_map[i] == peer) {
  731. ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
  732. peer->addr, peer, i);
  733. ar->peer_map[i] = NULL;
  734. }
  735. }
  736. list_del(&peer->list);
  737. kfree(peer);
  738. ar->num_peers--;
  739. }
  740. static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
  741. {
  742. struct ath10k_peer *peer, *tmp;
  743. lockdep_assert_held(&ar->conf_mutex);
  744. spin_lock_bh(&ar->data_lock);
  745. list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
  746. if (peer->vdev_id != vdev_id)
  747. continue;
  748. ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
  749. peer->addr, vdev_id);
  750. ath10k_peer_map_cleanup(ar, peer);
  751. }
  752. spin_unlock_bh(&ar->data_lock);
  753. }
  754. static void ath10k_peer_cleanup_all(struct ath10k *ar)
  755. {
  756. struct ath10k_peer *peer, *tmp;
  757. int i;
  758. lockdep_assert_held(&ar->conf_mutex);
  759. spin_lock_bh(&ar->data_lock);
  760. list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
  761. list_del(&peer->list);
  762. kfree(peer);
  763. }
  764. for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
  765. ar->peer_map[i] = NULL;
  766. spin_unlock_bh(&ar->data_lock);
  767. ar->num_peers = 0;
  768. ar->num_stations = 0;
  769. }
  770. static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
  771. struct ieee80211_sta *sta,
  772. enum wmi_tdls_peer_state state)
  773. {
  774. int ret;
  775. struct wmi_tdls_peer_update_cmd_arg arg = {};
  776. struct wmi_tdls_peer_capab_arg cap = {};
  777. struct wmi_channel_arg chan_arg = {};
  778. lockdep_assert_held(&ar->conf_mutex);
  779. arg.vdev_id = vdev_id;
  780. arg.peer_state = state;
  781. ether_addr_copy(arg.addr, sta->addr);
  782. cap.peer_max_sp = sta->max_sp;
  783. cap.peer_uapsd_queues = sta->uapsd_queues;
  784. if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
  785. !sta->tdls_initiator)
  786. cap.is_peer_responder = 1;
  787. ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
  788. if (ret) {
  789. ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
  790. arg.addr, vdev_id, ret);
  791. return ret;
  792. }
  793. return 0;
  794. }
  795. /************************/
  796. /* Interface management */
  797. /************************/
  798. void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
  799. {
  800. struct ath10k *ar = arvif->ar;
  801. lockdep_assert_held(&ar->data_lock);
  802. if (!arvif->beacon)
  803. return;
  804. if (!arvif->beacon_buf)
  805. dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
  806. arvif->beacon->len, DMA_TO_DEVICE);
  807. if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
  808. arvif->beacon_state != ATH10K_BEACON_SENT))
  809. return;
  810. dev_kfree_skb_any(arvif->beacon);
  811. arvif->beacon = NULL;
  812. arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
  813. }
  814. static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
  815. {
  816. struct ath10k *ar = arvif->ar;
  817. lockdep_assert_held(&ar->data_lock);
  818. ath10k_mac_vif_beacon_free(arvif);
  819. if (arvif->beacon_buf) {
  820. if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL)
  821. kfree(arvif->beacon_buf);
  822. else
  823. dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
  824. arvif->beacon_buf,
  825. arvif->beacon_paddr);
  826. arvif->beacon_buf = NULL;
  827. }
  828. }
  829. static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
  830. {
  831. unsigned long time_left;
  832. lockdep_assert_held(&ar->conf_mutex);
  833. if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
  834. return -ESHUTDOWN;
  835. time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
  836. ATH10K_VDEV_SETUP_TIMEOUT_HZ);
  837. if (time_left == 0)
  838. return -ETIMEDOUT;
  839. return ar->last_wmi_vdev_start_status;
  840. }
  841. static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
  842. {
  843. struct cfg80211_chan_def *chandef = NULL;
  844. struct ieee80211_channel *channel = NULL;
  845. struct wmi_vdev_start_request_arg arg = {};
  846. int ret = 0;
  847. lockdep_assert_held(&ar->conf_mutex);
  848. ieee80211_iter_chan_contexts_atomic(ar->hw,
  849. ath10k_mac_get_any_chandef_iter,
  850. &chandef);
  851. if (WARN_ON_ONCE(!chandef))
  852. return -ENOENT;
  853. channel = chandef->chan;
  854. arg.vdev_id = vdev_id;
  855. arg.channel.freq = channel->center_freq;
  856. arg.channel.band_center_freq1 = chandef->center_freq1;
  857. arg.channel.band_center_freq2 = chandef->center_freq2;
  858. /* TODO setup this dynamically, what in case we
  859. * don't have any vifs?
  860. */
  861. arg.channel.mode = chan_to_phymode(chandef);
  862. arg.channel.chan_radar =
  863. !!(channel->flags & IEEE80211_CHAN_RADAR);
  864. arg.channel.min_power = 0;
  865. arg.channel.max_power = channel->max_power * 2;
  866. arg.channel.max_reg_power = channel->max_reg_power * 2;
  867. arg.channel.max_antenna_gain = channel->max_antenna_gain;
  868. reinit_completion(&ar->vdev_setup_done);
  869. reinit_completion(&ar->vdev_delete_done);
  870. ret = ath10k_wmi_vdev_start(ar, &arg);
  871. if (ret) {
  872. ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
  873. vdev_id, ret);
  874. return ret;
  875. }
  876. ret = ath10k_vdev_setup_sync(ar);
  877. if (ret) {
  878. ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
  879. vdev_id, ret);
  880. return ret;
  881. }
  882. ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
  883. if (ret) {
  884. ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
  885. vdev_id, ret);
  886. goto vdev_stop;
  887. }
  888. ar->monitor_vdev_id = vdev_id;
  889. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
  890. ar->monitor_vdev_id);
  891. return 0;
  892. vdev_stop:
  893. ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
  894. if (ret)
  895. ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
  896. ar->monitor_vdev_id, ret);
  897. return ret;
  898. }
  899. static int ath10k_monitor_vdev_stop(struct ath10k *ar)
  900. {
  901. int ret = 0;
  902. lockdep_assert_held(&ar->conf_mutex);
  903. ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
  904. if (ret)
  905. ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
  906. ar->monitor_vdev_id, ret);
  907. reinit_completion(&ar->vdev_setup_done);
  908. reinit_completion(&ar->vdev_delete_done);
  909. ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
  910. if (ret)
  911. ath10k_warn(ar, "failed to request monitor vdev %i stop: %d\n",
  912. ar->monitor_vdev_id, ret);
  913. ret = ath10k_vdev_setup_sync(ar);
  914. if (ret)
  915. ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
  916. ar->monitor_vdev_id, ret);
  917. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
  918. ar->monitor_vdev_id);
  919. return ret;
  920. }
  921. static int ath10k_monitor_vdev_create(struct ath10k *ar)
  922. {
  923. int bit, ret = 0;
  924. lockdep_assert_held(&ar->conf_mutex);
  925. if (ar->free_vdev_map == 0) {
  926. ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
  927. return -ENOMEM;
  928. }
  929. bit = __ffs64(ar->free_vdev_map);
  930. ar->monitor_vdev_id = bit;
  931. ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
  932. WMI_VDEV_TYPE_MONITOR,
  933. 0, ar->mac_addr);
  934. if (ret) {
  935. ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
  936. ar->monitor_vdev_id, ret);
  937. return ret;
  938. }
  939. ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
  940. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
  941. ar->monitor_vdev_id);
  942. return 0;
  943. }
  944. static int ath10k_monitor_vdev_delete(struct ath10k *ar)
  945. {
  946. int ret = 0;
  947. lockdep_assert_held(&ar->conf_mutex);
  948. ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
  949. if (ret) {
  950. ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
  951. ar->monitor_vdev_id, ret);
  952. return ret;
  953. }
  954. ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
  955. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
  956. ar->monitor_vdev_id);
  957. return ret;
  958. }
  959. static int ath10k_monitor_start(struct ath10k *ar)
  960. {
  961. int ret;
  962. lockdep_assert_held(&ar->conf_mutex);
  963. ret = ath10k_monitor_vdev_create(ar);
  964. if (ret) {
  965. ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
  966. return ret;
  967. }
  968. ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
  969. if (ret) {
  970. ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
  971. ath10k_monitor_vdev_delete(ar);
  972. return ret;
  973. }
  974. ar->monitor_started = true;
  975. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
  976. return 0;
  977. }
  978. static int ath10k_monitor_stop(struct ath10k *ar)
  979. {
  980. int ret;
  981. lockdep_assert_held(&ar->conf_mutex);
  982. ret = ath10k_monitor_vdev_stop(ar);
  983. if (ret) {
  984. ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
  985. return ret;
  986. }
  987. ret = ath10k_monitor_vdev_delete(ar);
  988. if (ret) {
  989. ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
  990. return ret;
  991. }
  992. ar->monitor_started = false;
  993. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
  994. return 0;
  995. }
  996. static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
  997. {
  998. int num_ctx;
  999. /* At least one chanctx is required to derive a channel to start
  1000. * monitor vdev on.
  1001. */
  1002. num_ctx = ath10k_mac_num_chanctxs(ar);
  1003. if (num_ctx == 0)
  1004. return false;
  1005. /* If there's already an existing special monitor interface then don't
  1006. * bother creating another monitor vdev.
  1007. */
  1008. if (ar->monitor_arvif)
  1009. return false;
  1010. return ar->monitor ||
  1011. (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST,
  1012. ar->running_fw->fw_file.fw_features) &&
  1013. (ar->filter_flags & FIF_OTHER_BSS)) ||
  1014. test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  1015. }
  1016. static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
  1017. {
  1018. int num_ctx;
  1019. num_ctx = ath10k_mac_num_chanctxs(ar);
  1020. /* FIXME: Current interface combinations and cfg80211/mac80211 code
  1021. * shouldn't allow this but make sure to prevent handling the following
  1022. * case anyway since multi-channel DFS hasn't been tested at all.
  1023. */
  1024. if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
  1025. return false;
  1026. return true;
  1027. }
  1028. static int ath10k_monitor_recalc(struct ath10k *ar)
  1029. {
  1030. bool needed;
  1031. bool allowed;
  1032. int ret;
  1033. lockdep_assert_held(&ar->conf_mutex);
  1034. needed = ath10k_mac_monitor_vdev_is_needed(ar);
  1035. allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
  1036. ath10k_dbg(ar, ATH10K_DBG_MAC,
  1037. "mac monitor recalc started? %d needed? %d allowed? %d\n",
  1038. ar->monitor_started, needed, allowed);
  1039. if (WARN_ON(needed && !allowed)) {
  1040. if (ar->monitor_started) {
  1041. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
  1042. ret = ath10k_monitor_stop(ar);
  1043. if (ret)
  1044. ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
  1045. ret);
  1046. /* not serious */
  1047. }
  1048. return -EPERM;
  1049. }
  1050. if (needed == ar->monitor_started)
  1051. return 0;
  1052. if (needed)
  1053. return ath10k_monitor_start(ar);
  1054. else
  1055. return ath10k_monitor_stop(ar);
  1056. }
  1057. static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
  1058. {
  1059. struct ath10k *ar = arvif->ar;
  1060. lockdep_assert_held(&ar->conf_mutex);
  1061. if (!arvif->is_started) {
  1062. ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
  1063. return false;
  1064. }
  1065. return true;
  1066. }
  1067. static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
  1068. {
  1069. struct ath10k *ar = arvif->ar;
  1070. u32 vdev_param;
  1071. lockdep_assert_held(&ar->conf_mutex);
  1072. vdev_param = ar->wmi.vdev_param->protection_mode;
  1073. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
  1074. arvif->vdev_id, arvif->use_cts_prot);
  1075. return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  1076. arvif->use_cts_prot ? 1 : 0);
  1077. }
  1078. static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
  1079. {
  1080. struct ath10k *ar = arvif->ar;
  1081. u32 vdev_param, rts_cts = 0;
  1082. lockdep_assert_held(&ar->conf_mutex);
  1083. vdev_param = ar->wmi.vdev_param->enable_rtscts;
  1084. rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
  1085. if (arvif->num_legacy_stations > 0)
  1086. rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
  1087. WMI_RTSCTS_PROFILE);
  1088. else
  1089. rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
  1090. WMI_RTSCTS_PROFILE);
  1091. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
  1092. arvif->vdev_id, rts_cts);
  1093. return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  1094. rts_cts);
  1095. }
  1096. static int ath10k_start_cac(struct ath10k *ar)
  1097. {
  1098. int ret;
  1099. lockdep_assert_held(&ar->conf_mutex);
  1100. set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  1101. ret = ath10k_monitor_recalc(ar);
  1102. if (ret) {
  1103. ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
  1104. clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  1105. return ret;
  1106. }
  1107. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
  1108. ar->monitor_vdev_id);
  1109. return 0;
  1110. }
  1111. static int ath10k_stop_cac(struct ath10k *ar)
  1112. {
  1113. lockdep_assert_held(&ar->conf_mutex);
  1114. /* CAC is not running - do nothing */
  1115. if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
  1116. return 0;
  1117. clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  1118. ath10k_monitor_stop(ar);
  1119. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
  1120. return 0;
  1121. }
  1122. static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
  1123. struct ieee80211_chanctx_conf *conf,
  1124. void *data)
  1125. {
  1126. bool *ret = data;
  1127. if (!*ret && conf->radar_enabled)
  1128. *ret = true;
  1129. }
  1130. static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
  1131. {
  1132. bool has_radar = false;
  1133. ieee80211_iter_chan_contexts_atomic(ar->hw,
  1134. ath10k_mac_has_radar_iter,
  1135. &has_radar);
  1136. return has_radar;
  1137. }
  1138. static void ath10k_recalc_radar_detection(struct ath10k *ar)
  1139. {
  1140. int ret;
  1141. lockdep_assert_held(&ar->conf_mutex);
  1142. ath10k_stop_cac(ar);
  1143. if (!ath10k_mac_has_radar_enabled(ar))
  1144. return;
  1145. if (ar->num_started_vdevs > 0)
  1146. return;
  1147. ret = ath10k_start_cac(ar);
  1148. if (ret) {
  1149. /*
  1150. * Not possible to start CAC on current channel so starting
  1151. * radiation is not allowed, make this channel DFS_UNAVAILABLE
  1152. * by indicating that radar was detected.
  1153. */
  1154. ath10k_warn(ar, "failed to start CAC: %d\n", ret);
  1155. ieee80211_radar_detected(ar->hw);
  1156. }
  1157. }
  1158. static int ath10k_vdev_stop(struct ath10k_vif *arvif)
  1159. {
  1160. struct ath10k *ar = arvif->ar;
  1161. int ret;
  1162. lockdep_assert_held(&ar->conf_mutex);
  1163. reinit_completion(&ar->vdev_setup_done);
  1164. reinit_completion(&ar->vdev_delete_done);
  1165. ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
  1166. if (ret) {
  1167. ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
  1168. arvif->vdev_id, ret);
  1169. return ret;
  1170. }
  1171. ret = ath10k_vdev_setup_sync(ar);
  1172. if (ret) {
  1173. ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n",
  1174. arvif->vdev_id, ret);
  1175. return ret;
  1176. }
  1177. WARN_ON(ar->num_started_vdevs == 0);
  1178. if (ar->num_started_vdevs != 0) {
  1179. ar->num_started_vdevs--;
  1180. ath10k_recalc_radar_detection(ar);
  1181. }
  1182. return ret;
  1183. }
  1184. static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
  1185. const struct cfg80211_chan_def *chandef,
  1186. bool restart)
  1187. {
  1188. struct ath10k *ar = arvif->ar;
  1189. struct wmi_vdev_start_request_arg arg = {};
  1190. int ret = 0;
  1191. lockdep_assert_held(&ar->conf_mutex);
  1192. reinit_completion(&ar->vdev_setup_done);
  1193. reinit_completion(&ar->vdev_delete_done);
  1194. arg.vdev_id = arvif->vdev_id;
  1195. arg.dtim_period = arvif->dtim_period;
  1196. arg.bcn_intval = arvif->beacon_interval;
  1197. arg.channel.freq = chandef->chan->center_freq;
  1198. arg.channel.band_center_freq1 = chandef->center_freq1;
  1199. arg.channel.band_center_freq2 = chandef->center_freq2;
  1200. arg.channel.mode = chan_to_phymode(chandef);
  1201. arg.channel.min_power = 0;
  1202. arg.channel.max_power = chandef->chan->max_power * 2;
  1203. arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
  1204. arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain;
  1205. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  1206. arg.ssid = arvif->u.ap.ssid;
  1207. arg.ssid_len = arvif->u.ap.ssid_len;
  1208. arg.hidden_ssid = arvif->u.ap.hidden_ssid;
  1209. /* For now allow DFS for AP mode */
  1210. arg.channel.chan_radar =
  1211. !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
  1212. } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  1213. arg.ssid = arvif->vif->cfg.ssid;
  1214. arg.ssid_len = arvif->vif->cfg.ssid_len;
  1215. }
  1216. ath10k_dbg(ar, ATH10K_DBG_MAC,
  1217. "mac vdev %d start center_freq %d phymode %s\n",
  1218. arg.vdev_id, arg.channel.freq,
  1219. ath10k_wmi_phymode_str(arg.channel.mode));
  1220. if (restart)
  1221. ret = ath10k_wmi_vdev_restart(ar, &arg);
  1222. else
  1223. ret = ath10k_wmi_vdev_start(ar, &arg);
  1224. if (ret) {
  1225. ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
  1226. arg.vdev_id, ret);
  1227. return ret;
  1228. }
  1229. ret = ath10k_vdev_setup_sync(ar);
  1230. if (ret) {
  1231. ath10k_warn(ar,
  1232. "failed to synchronize setup for vdev %i restart %d: %d\n",
  1233. arg.vdev_id, restart, ret);
  1234. return ret;
  1235. }
  1236. ar->num_started_vdevs++;
  1237. ath10k_recalc_radar_detection(ar);
  1238. return ret;
  1239. }
  1240. static int ath10k_vdev_start(struct ath10k_vif *arvif,
  1241. const struct cfg80211_chan_def *def)
  1242. {
  1243. return ath10k_vdev_start_restart(arvif, def, false);
  1244. }
  1245. static int ath10k_vdev_restart(struct ath10k_vif *arvif,
  1246. const struct cfg80211_chan_def *def)
  1247. {
  1248. return ath10k_vdev_start_restart(arvif, def, true);
  1249. }
  1250. static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
  1251. struct sk_buff *bcn)
  1252. {
  1253. struct ath10k *ar = arvif->ar;
  1254. struct ieee80211_mgmt *mgmt;
  1255. const u8 *p2p_ie;
  1256. int ret;
  1257. if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
  1258. return 0;
  1259. mgmt = (void *)bcn->data;
  1260. p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
  1261. mgmt->u.beacon.variable,
  1262. bcn->len - (mgmt->u.beacon.variable -
  1263. bcn->data));
  1264. if (!p2p_ie)
  1265. return -ENOENT;
  1266. ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
  1267. if (ret) {
  1268. ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
  1269. arvif->vdev_id, ret);
  1270. return ret;
  1271. }
  1272. return 0;
  1273. }
  1274. static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
  1275. u8 oui_type, size_t ie_offset)
  1276. {
  1277. size_t len;
  1278. const u8 *next;
  1279. const u8 *end;
  1280. u8 *ie;
  1281. if (WARN_ON(skb->len < ie_offset))
  1282. return -EINVAL;
  1283. ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
  1284. skb->data + ie_offset,
  1285. skb->len - ie_offset);
  1286. if (!ie)
  1287. return -ENOENT;
  1288. len = ie[1] + 2;
  1289. end = skb->data + skb->len;
  1290. next = ie + len;
  1291. if (WARN_ON(next > end))
  1292. return -EINVAL;
  1293. memmove(ie, next, end - next);
  1294. skb_trim(skb, skb->len - len);
  1295. return 0;
  1296. }
  1297. static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
  1298. {
  1299. struct ath10k *ar = arvif->ar;
  1300. struct ieee80211_hw *hw = ar->hw;
  1301. struct ieee80211_vif *vif = arvif->vif;
  1302. struct ieee80211_mutable_offsets offs = {};
  1303. struct sk_buff *bcn;
  1304. int ret;
  1305. if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
  1306. return 0;
  1307. if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
  1308. arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
  1309. return 0;
  1310. bcn = ieee80211_beacon_get_template(hw, vif, &offs, 0);
  1311. if (!bcn) {
  1312. ath10k_warn(ar, "failed to get beacon template from mac80211\n");
  1313. return -EPERM;
  1314. }
  1315. ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
  1316. if (ret) {
  1317. ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
  1318. kfree_skb(bcn);
  1319. return ret;
  1320. }
  1321. /* P2P IE is inserted by firmware automatically (as configured above)
  1322. * so remove it from the base beacon template to avoid duplicate P2P
  1323. * IEs in beacon frames.
  1324. */
  1325. ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
  1326. offsetof(struct ieee80211_mgmt,
  1327. u.beacon.variable));
  1328. ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
  1329. 0, NULL, 0);
  1330. kfree_skb(bcn);
  1331. if (ret) {
  1332. ath10k_warn(ar, "failed to submit beacon template command: %d\n",
  1333. ret);
  1334. return ret;
  1335. }
  1336. return 0;
  1337. }
  1338. static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
  1339. {
  1340. struct ath10k *ar = arvif->ar;
  1341. struct ieee80211_hw *hw = ar->hw;
  1342. struct ieee80211_vif *vif = arvif->vif;
  1343. struct sk_buff *prb;
  1344. int ret;
  1345. if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
  1346. return 0;
  1347. if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
  1348. return 0;
  1349. /* For mesh, probe response and beacon share the same template */
  1350. if (ieee80211_vif_is_mesh(vif))
  1351. return 0;
  1352. prb = ieee80211_proberesp_get(hw, vif);
  1353. if (!prb) {
  1354. ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
  1355. return -EPERM;
  1356. }
  1357. ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
  1358. kfree_skb(prb);
  1359. if (ret) {
  1360. ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
  1361. ret);
  1362. return ret;
  1363. }
  1364. return 0;
  1365. }
  1366. static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
  1367. {
  1368. struct ath10k *ar = arvif->ar;
  1369. struct cfg80211_chan_def def;
  1370. int ret;
  1371. /* When originally vdev is started during assign_vif_chanctx() some
  1372. * information is missing, notably SSID. Firmware revisions with beacon
  1373. * offloading require the SSID to be provided during vdev (re)start to
  1374. * handle hidden SSID properly.
  1375. *
  1376. * Vdev restart must be done after vdev has been both started and
  1377. * upped. Otherwise some firmware revisions (at least 10.2) fail to
  1378. * deliver vdev restart response event causing timeouts during vdev
  1379. * syncing in ath10k.
  1380. *
  1381. * Note: The vdev down/up and template reinstallation could be skipped
  1382. * since only wmi-tlv firmware are known to have beacon offload and
  1383. * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
  1384. * response delivery. It's probably more robust to keep it as is.
  1385. */
  1386. if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
  1387. return 0;
  1388. if (WARN_ON(!arvif->is_started))
  1389. return -EINVAL;
  1390. if (WARN_ON(!arvif->is_up))
  1391. return -EINVAL;
  1392. if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
  1393. return -EINVAL;
  1394. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  1395. if (ret) {
  1396. ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
  1397. arvif->vdev_id, ret);
  1398. return ret;
  1399. }
  1400. /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
  1401. * firmware will crash upon vdev up.
  1402. */
  1403. ret = ath10k_mac_setup_bcn_tmpl(arvif);
  1404. if (ret) {
  1405. ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
  1406. return ret;
  1407. }
  1408. ret = ath10k_mac_setup_prb_tmpl(arvif);
  1409. if (ret) {
  1410. ath10k_warn(ar, "failed to update presp template: %d\n", ret);
  1411. return ret;
  1412. }
  1413. ret = ath10k_vdev_restart(arvif, &def);
  1414. if (ret) {
  1415. ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
  1416. arvif->vdev_id, ret);
  1417. return ret;
  1418. }
  1419. ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
  1420. arvif->bssid);
  1421. if (ret) {
  1422. ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
  1423. arvif->vdev_id, ret);
  1424. return ret;
  1425. }
  1426. return 0;
  1427. }
  1428. static void ath10k_control_beaconing(struct ath10k_vif *arvif,
  1429. struct ieee80211_bss_conf *info)
  1430. {
  1431. struct ath10k *ar = arvif->ar;
  1432. int ret = 0;
  1433. lockdep_assert_held(&arvif->ar->conf_mutex);
  1434. if (!info->enable_beacon) {
  1435. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  1436. if (ret)
  1437. ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
  1438. arvif->vdev_id, ret);
  1439. arvif->is_up = false;
  1440. spin_lock_bh(&arvif->ar->data_lock);
  1441. ath10k_mac_vif_beacon_free(arvif);
  1442. spin_unlock_bh(&arvif->ar->data_lock);
  1443. return;
  1444. }
  1445. arvif->tx_seq_no = 0x1000;
  1446. arvif->aid = 0;
  1447. ether_addr_copy(arvif->bssid, info->bssid);
  1448. ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
  1449. arvif->bssid);
  1450. if (ret) {
  1451. ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
  1452. arvif->vdev_id, ret);
  1453. return;
  1454. }
  1455. arvif->is_up = true;
  1456. ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
  1457. if (ret) {
  1458. ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
  1459. arvif->vdev_id, ret);
  1460. return;
  1461. }
  1462. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
  1463. }
  1464. static void ath10k_control_ibss(struct ath10k_vif *arvif,
  1465. struct ieee80211_vif *vif)
  1466. {
  1467. struct ath10k *ar = arvif->ar;
  1468. u32 vdev_param;
  1469. int ret = 0;
  1470. lockdep_assert_held(&arvif->ar->conf_mutex);
  1471. if (!vif->cfg.ibss_joined) {
  1472. if (is_zero_ether_addr(arvif->bssid))
  1473. return;
  1474. eth_zero_addr(arvif->bssid);
  1475. return;
  1476. }
  1477. vdev_param = arvif->ar->wmi.vdev_param->atim_window;
  1478. ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
  1479. ATH10K_DEFAULT_ATIM);
  1480. if (ret)
  1481. ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
  1482. arvif->vdev_id, ret);
  1483. }
  1484. static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
  1485. {
  1486. struct ath10k *ar = arvif->ar;
  1487. u32 param;
  1488. u32 value;
  1489. int ret;
  1490. lockdep_assert_held(&arvif->ar->conf_mutex);
  1491. if (arvif->u.sta.uapsd)
  1492. value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
  1493. else
  1494. value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
  1495. param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
  1496. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
  1497. if (ret) {
  1498. ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
  1499. value, arvif->vdev_id, ret);
  1500. return ret;
  1501. }
  1502. return 0;
  1503. }
  1504. static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
  1505. {
  1506. struct ath10k *ar = arvif->ar;
  1507. u32 param;
  1508. u32 value;
  1509. int ret;
  1510. lockdep_assert_held(&arvif->ar->conf_mutex);
  1511. if (arvif->u.sta.uapsd)
  1512. value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
  1513. else
  1514. value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
  1515. param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
  1516. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  1517. param, value);
  1518. if (ret) {
  1519. ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
  1520. value, arvif->vdev_id, ret);
  1521. return ret;
  1522. }
  1523. return 0;
  1524. }
  1525. static int ath10k_mac_num_vifs_started(struct ath10k *ar)
  1526. {
  1527. struct ath10k_vif *arvif;
  1528. int num = 0;
  1529. lockdep_assert_held(&ar->conf_mutex);
  1530. list_for_each_entry(arvif, &ar->arvifs, list)
  1531. if (arvif->is_started)
  1532. num++;
  1533. return num;
  1534. }
  1535. static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
  1536. {
  1537. struct ath10k *ar = arvif->ar;
  1538. struct ieee80211_vif *vif = arvif->vif;
  1539. struct ieee80211_conf *conf = &ar->hw->conf;
  1540. enum wmi_sta_powersave_param param;
  1541. enum wmi_sta_ps_mode psmode;
  1542. int ret;
  1543. int ps_timeout;
  1544. bool enable_ps;
  1545. lockdep_assert_held(&arvif->ar->conf_mutex);
  1546. if (arvif->vif->type != NL80211_IFTYPE_STATION)
  1547. return 0;
  1548. enable_ps = arvif->ps;
  1549. if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
  1550. !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
  1551. ar->running_fw->fw_file.fw_features)) {
  1552. ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
  1553. arvif->vdev_id);
  1554. enable_ps = false;
  1555. }
  1556. if (!arvif->is_started) {
  1557. /* mac80211 can update vif powersave state while disconnected.
  1558. * Firmware doesn't behave nicely and consumes more power than
  1559. * necessary if PS is disabled on a non-started vdev. Hence
  1560. * force-enable PS for non-running vdevs.
  1561. */
  1562. psmode = WMI_STA_PS_MODE_ENABLED;
  1563. } else if (enable_ps) {
  1564. psmode = WMI_STA_PS_MODE_ENABLED;
  1565. param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
  1566. ps_timeout = conf->dynamic_ps_timeout;
  1567. if (ps_timeout == 0) {
  1568. /* Firmware doesn't like 0 */
  1569. ps_timeout = ieee80211_tu_to_usec(
  1570. vif->bss_conf.beacon_int) / 1000;
  1571. }
  1572. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
  1573. ps_timeout);
  1574. if (ret) {
  1575. ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
  1576. arvif->vdev_id, ret);
  1577. return ret;
  1578. }
  1579. } else {
  1580. psmode = WMI_STA_PS_MODE_DISABLED;
  1581. }
  1582. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
  1583. arvif->vdev_id, psmode ? "enable" : "disable");
  1584. ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
  1585. if (ret) {
  1586. ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
  1587. psmode, arvif->vdev_id, ret);
  1588. return ret;
  1589. }
  1590. return 0;
  1591. }
  1592. static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
  1593. {
  1594. struct ath10k *ar = arvif->ar;
  1595. struct wmi_sta_keepalive_arg arg = {};
  1596. int ret;
  1597. lockdep_assert_held(&arvif->ar->conf_mutex);
  1598. if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
  1599. return 0;
  1600. if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
  1601. return 0;
  1602. /* Some firmware revisions have a bug and ignore the `enabled` field.
  1603. * Instead use the interval to disable the keepalive.
  1604. */
  1605. arg.vdev_id = arvif->vdev_id;
  1606. arg.enabled = 1;
  1607. arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
  1608. arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
  1609. ret = ath10k_wmi_sta_keepalive(ar, &arg);
  1610. if (ret) {
  1611. ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
  1612. arvif->vdev_id, ret);
  1613. return ret;
  1614. }
  1615. return 0;
  1616. }
  1617. static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
  1618. {
  1619. struct ath10k *ar = arvif->ar;
  1620. struct ieee80211_vif *vif = arvif->vif;
  1621. int ret;
  1622. lockdep_assert_held(&arvif->ar->conf_mutex);
  1623. if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
  1624. return;
  1625. if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
  1626. return;
  1627. if (!vif->bss_conf.csa_active)
  1628. return;
  1629. if (!arvif->is_up)
  1630. return;
  1631. if (!ieee80211_beacon_cntdwn_is_complete(vif)) {
  1632. ieee80211_beacon_update_cntdwn(vif);
  1633. ret = ath10k_mac_setup_bcn_tmpl(arvif);
  1634. if (ret)
  1635. ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
  1636. ret);
  1637. ret = ath10k_mac_setup_prb_tmpl(arvif);
  1638. if (ret)
  1639. ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
  1640. ret);
  1641. } else {
  1642. ieee80211_csa_finish(vif);
  1643. }
  1644. }
  1645. static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
  1646. {
  1647. struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
  1648. ap_csa_work);
  1649. struct ath10k *ar = arvif->ar;
  1650. mutex_lock(&ar->conf_mutex);
  1651. ath10k_mac_vif_ap_csa_count_down(arvif);
  1652. mutex_unlock(&ar->conf_mutex);
  1653. }
  1654. static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
  1655. struct ieee80211_vif *vif)
  1656. {
  1657. struct sk_buff *skb = data;
  1658. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1659. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  1660. if (vif->type != NL80211_IFTYPE_STATION)
  1661. return;
  1662. if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
  1663. return;
  1664. cancel_delayed_work(&arvif->connection_loss_work);
  1665. }
  1666. void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
  1667. {
  1668. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  1669. ATH10K_ITER_NORMAL_FLAGS,
  1670. ath10k_mac_handle_beacon_iter,
  1671. skb);
  1672. }
  1673. static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
  1674. struct ieee80211_vif *vif)
  1675. {
  1676. u32 *vdev_id = data;
  1677. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  1678. struct ath10k *ar = arvif->ar;
  1679. struct ieee80211_hw *hw = ar->hw;
  1680. if (arvif->vdev_id != *vdev_id)
  1681. return;
  1682. if (!arvif->is_up)
  1683. return;
  1684. ieee80211_beacon_loss(vif);
  1685. /* Firmware doesn't report beacon loss events repeatedly. If AP probe
  1686. * (done by mac80211) succeeds but beacons do not resume then it
  1687. * doesn't make sense to continue operation. Queue connection loss work
  1688. * which can be cancelled when beacon is received.
  1689. */
  1690. ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
  1691. ATH10K_CONNECTION_LOSS_HZ);
  1692. }
  1693. void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
  1694. {
  1695. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  1696. ATH10K_ITER_NORMAL_FLAGS,
  1697. ath10k_mac_handle_beacon_miss_iter,
  1698. &vdev_id);
  1699. }
  1700. static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
  1701. {
  1702. struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
  1703. connection_loss_work.work);
  1704. struct ieee80211_vif *vif = arvif->vif;
  1705. if (!arvif->is_up)
  1706. return;
  1707. ieee80211_connection_loss(vif);
  1708. }
  1709. /**********************/
  1710. /* Station management */
  1711. /**********************/
  1712. static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
  1713. struct ieee80211_vif *vif)
  1714. {
  1715. /* Some firmware revisions have unstable STA powersave when listen
  1716. * interval is set too high (e.g. 5). The symptoms are firmware doesn't
  1717. * generate NullFunc frames properly even if buffered frames have been
  1718. * indicated in Beacon TIM. Firmware would seldom wake up to pull
  1719. * buffered frames. Often pinging the device from AP would simply fail.
  1720. *
  1721. * As a workaround set it to 1.
  1722. */
  1723. if (vif->type == NL80211_IFTYPE_STATION)
  1724. return 1;
  1725. return ar->hw->conf.listen_interval;
  1726. }
  1727. static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
  1728. struct ieee80211_vif *vif,
  1729. struct ieee80211_sta *sta,
  1730. struct wmi_peer_assoc_complete_arg *arg)
  1731. {
  1732. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  1733. u32 aid;
  1734. lockdep_assert_held(&ar->conf_mutex);
  1735. if (vif->type == NL80211_IFTYPE_STATION)
  1736. aid = vif->cfg.aid;
  1737. else
  1738. aid = sta->aid;
  1739. ether_addr_copy(arg->addr, sta->addr);
  1740. arg->vdev_id = arvif->vdev_id;
  1741. arg->peer_aid = aid;
  1742. arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
  1743. arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
  1744. arg->peer_num_spatial_streams = 1;
  1745. arg->peer_caps = vif->bss_conf.assoc_capability;
  1746. }
  1747. static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
  1748. struct ieee80211_vif *vif,
  1749. struct ieee80211_sta *sta,
  1750. struct wmi_peer_assoc_complete_arg *arg)
  1751. {
  1752. struct ieee80211_bss_conf *info = &vif->bss_conf;
  1753. struct cfg80211_chan_def def;
  1754. struct cfg80211_bss *bss;
  1755. const u8 *rsnie = NULL;
  1756. const u8 *wpaie = NULL;
  1757. lockdep_assert_held(&ar->conf_mutex);
  1758. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  1759. return;
  1760. bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid,
  1761. vif->cfg.ssid_len ? vif->cfg.ssid : NULL,
  1762. vif->cfg.ssid_len,
  1763. IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
  1764. if (bss) {
  1765. const struct cfg80211_bss_ies *ies;
  1766. rcu_read_lock();
  1767. rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
  1768. ies = rcu_dereference(bss->ies);
  1769. wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
  1770. WLAN_OUI_TYPE_MICROSOFT_WPA,
  1771. ies->data,
  1772. ies->len);
  1773. rcu_read_unlock();
  1774. cfg80211_put_bss(ar->hw->wiphy, bss);
  1775. }
  1776. /* FIXME: base on RSN IE/WPA IE is a correct idea? */
  1777. if (rsnie || wpaie) {
  1778. ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
  1779. arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
  1780. }
  1781. if (wpaie) {
  1782. ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
  1783. arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
  1784. }
  1785. if (sta->mfp &&
  1786. test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
  1787. ar->running_fw->fw_file.fw_features)) {
  1788. arg->peer_flags |= ar->wmi.peer_flags->pmf;
  1789. }
  1790. }
  1791. static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
  1792. struct ieee80211_vif *vif,
  1793. struct ieee80211_sta *sta,
  1794. struct wmi_peer_assoc_complete_arg *arg)
  1795. {
  1796. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  1797. struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
  1798. struct cfg80211_chan_def def;
  1799. const struct ieee80211_supported_band *sband;
  1800. const struct ieee80211_rate *rates;
  1801. enum nl80211_band band;
  1802. u32 ratemask;
  1803. u8 rate;
  1804. int i;
  1805. lockdep_assert_held(&ar->conf_mutex);
  1806. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  1807. return;
  1808. band = def.chan->band;
  1809. sband = ar->hw->wiphy->bands[band];
  1810. ratemask = sta->deflink.supp_rates[band];
  1811. ratemask &= arvif->bitrate_mask.control[band].legacy;
  1812. rates = sband->bitrates;
  1813. rateset->num_rates = 0;
  1814. for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
  1815. if (!(ratemask & 1))
  1816. continue;
  1817. rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
  1818. rateset->rates[rateset->num_rates] = rate;
  1819. rateset->num_rates++;
  1820. }
  1821. }
  1822. static bool
  1823. ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
  1824. {
  1825. int nss;
  1826. for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
  1827. if (ht_mcs_mask[nss])
  1828. return false;
  1829. return true;
  1830. }
  1831. static bool
  1832. ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
  1833. {
  1834. int nss;
  1835. for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
  1836. if (vht_mcs_mask[nss])
  1837. return false;
  1838. return true;
  1839. }
  1840. static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
  1841. struct ieee80211_vif *vif,
  1842. struct ieee80211_sta *sta,
  1843. struct wmi_peer_assoc_complete_arg *arg)
  1844. {
  1845. const struct ieee80211_sta_ht_cap *ht_cap = &sta->deflink.ht_cap;
  1846. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  1847. struct cfg80211_chan_def def;
  1848. enum nl80211_band band;
  1849. const u8 *ht_mcs_mask;
  1850. const u16 *vht_mcs_mask;
  1851. int i, n;
  1852. u8 max_nss;
  1853. u32 stbc;
  1854. lockdep_assert_held(&ar->conf_mutex);
  1855. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  1856. return;
  1857. if (!ht_cap->ht_supported)
  1858. return;
  1859. band = def.chan->band;
  1860. ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
  1861. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  1862. if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
  1863. ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
  1864. return;
  1865. arg->peer_flags |= ar->wmi.peer_flags->ht;
  1866. arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  1867. ht_cap->ampdu_factor)) - 1;
  1868. arg->peer_mpdu_density =
  1869. ath10k_parse_mpdudensity(ht_cap->ampdu_density);
  1870. arg->peer_ht_caps = ht_cap->cap;
  1871. arg->peer_rate_caps |= WMI_RC_HT_FLAG;
  1872. if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
  1873. arg->peer_flags |= ar->wmi.peer_flags->ldbc;
  1874. if (sta->deflink.bandwidth >= IEEE80211_STA_RX_BW_40) {
  1875. arg->peer_flags |= ar->wmi.peer_flags->bw40;
  1876. arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
  1877. }
  1878. if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
  1879. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
  1880. arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
  1881. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
  1882. arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
  1883. }
  1884. if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
  1885. arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
  1886. arg->peer_flags |= ar->wmi.peer_flags->stbc;
  1887. }
  1888. if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
  1889. stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
  1890. stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
  1891. stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
  1892. arg->peer_rate_caps |= stbc;
  1893. arg->peer_flags |= ar->wmi.peer_flags->stbc;
  1894. }
  1895. if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
  1896. arg->peer_rate_caps |= WMI_RC_TS_FLAG;
  1897. else if (ht_cap->mcs.rx_mask[1])
  1898. arg->peer_rate_caps |= WMI_RC_DS_FLAG;
  1899. for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
  1900. if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
  1901. (ht_mcs_mask[i / 8] & BIT(i % 8))) {
  1902. max_nss = (i / 8) + 1;
  1903. arg->peer_ht_rates.rates[n++] = i;
  1904. }
  1905. /*
  1906. * This is a workaround for HT-enabled STAs which break the spec
  1907. * and have no HT capabilities RX mask (no HT RX MCS map).
  1908. *
  1909. * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
  1910. * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
  1911. *
  1912. * Firmware asserts if such situation occurs.
  1913. */
  1914. if (n == 0) {
  1915. arg->peer_ht_rates.num_rates = 8;
  1916. for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
  1917. arg->peer_ht_rates.rates[i] = i;
  1918. } else {
  1919. arg->peer_ht_rates.num_rates = n;
  1920. arg->peer_num_spatial_streams = min(sta->deflink.rx_nss,
  1921. max_nss);
  1922. }
  1923. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
  1924. arg->addr,
  1925. arg->peer_ht_rates.num_rates,
  1926. arg->peer_num_spatial_streams);
  1927. }
  1928. static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
  1929. struct ath10k_vif *arvif,
  1930. struct ieee80211_sta *sta)
  1931. {
  1932. u32 uapsd = 0;
  1933. u32 max_sp = 0;
  1934. int ret = 0;
  1935. lockdep_assert_held(&ar->conf_mutex);
  1936. if (sta->wme && sta->uapsd_queues) {
  1937. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
  1938. sta->uapsd_queues, sta->max_sp);
  1939. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  1940. uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
  1941. WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
  1942. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  1943. uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
  1944. WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
  1945. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  1946. uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
  1947. WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
  1948. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  1949. uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
  1950. WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
  1951. if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
  1952. max_sp = sta->max_sp;
  1953. ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
  1954. sta->addr,
  1955. WMI_AP_PS_PEER_PARAM_UAPSD,
  1956. uapsd);
  1957. if (ret) {
  1958. ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
  1959. arvif->vdev_id, ret);
  1960. return ret;
  1961. }
  1962. ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
  1963. sta->addr,
  1964. WMI_AP_PS_PEER_PARAM_MAX_SP,
  1965. max_sp);
  1966. if (ret) {
  1967. ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
  1968. arvif->vdev_id, ret);
  1969. return ret;
  1970. }
  1971. /* TODO setup this based on STA listen interval and
  1972. * beacon interval. Currently we don't know
  1973. * sta->listen_interval - mac80211 patch required.
  1974. * Currently use 10 seconds
  1975. */
  1976. ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
  1977. WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
  1978. 10);
  1979. if (ret) {
  1980. ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
  1981. arvif->vdev_id, ret);
  1982. return ret;
  1983. }
  1984. }
  1985. return 0;
  1986. }
  1987. static u16
  1988. ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
  1989. const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
  1990. {
  1991. int idx_limit;
  1992. int nss;
  1993. u16 mcs_map;
  1994. u16 mcs;
  1995. for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
  1996. mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
  1997. vht_mcs_limit[nss];
  1998. if (mcs_map)
  1999. idx_limit = fls(mcs_map) - 1;
  2000. else
  2001. idx_limit = -1;
  2002. switch (idx_limit) {
  2003. case 0:
  2004. case 1:
  2005. case 2:
  2006. case 3:
  2007. case 4:
  2008. case 5:
  2009. case 6:
  2010. default:
  2011. /* see ath10k_mac_can_set_bitrate_mask() */
  2012. WARN_ON(1);
  2013. fallthrough;
  2014. case -1:
  2015. mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  2016. break;
  2017. case 7:
  2018. mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
  2019. break;
  2020. case 8:
  2021. mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
  2022. break;
  2023. case 9:
  2024. mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
  2025. break;
  2026. }
  2027. tx_mcs_set &= ~(0x3 << (nss * 2));
  2028. tx_mcs_set |= mcs << (nss * 2);
  2029. }
  2030. return tx_mcs_set;
  2031. }
  2032. static u32 get_160mhz_nss_from_maxrate(int rate)
  2033. {
  2034. u32 nss;
  2035. switch (rate) {
  2036. case 780:
  2037. nss = 1;
  2038. break;
  2039. case 1560:
  2040. nss = 2;
  2041. break;
  2042. case 2106:
  2043. nss = 3; /* not support MCS9 from spec*/
  2044. break;
  2045. case 3120:
  2046. nss = 4;
  2047. break;
  2048. default:
  2049. nss = 1;
  2050. }
  2051. return nss;
  2052. }
  2053. static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
  2054. struct ieee80211_vif *vif,
  2055. struct ieee80211_sta *sta,
  2056. struct wmi_peer_assoc_complete_arg *arg)
  2057. {
  2058. const struct ieee80211_sta_vht_cap *vht_cap = &sta->deflink.vht_cap;
  2059. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  2060. struct ath10k_hw_params *hw = &ar->hw_params;
  2061. struct cfg80211_chan_def def;
  2062. enum nl80211_band band;
  2063. const u16 *vht_mcs_mask;
  2064. u8 ampdu_factor;
  2065. u8 max_nss, vht_mcs;
  2066. int i;
  2067. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  2068. return;
  2069. if (!vht_cap->vht_supported)
  2070. return;
  2071. band = def.chan->band;
  2072. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  2073. if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
  2074. return;
  2075. arg->peer_flags |= ar->wmi.peer_flags->vht;
  2076. if (def.chan->band == NL80211_BAND_2GHZ)
  2077. arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
  2078. arg->peer_vht_caps = vht_cap->cap;
  2079. ampdu_factor = (vht_cap->cap &
  2080. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
  2081. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  2082. /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
  2083. * zero in VHT IE. Using it would result in degraded throughput.
  2084. * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
  2085. * it if VHT max_mpdu is smaller.
  2086. */
  2087. arg->peer_max_mpdu = max(arg->peer_max_mpdu,
  2088. (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  2089. ampdu_factor)) - 1);
  2090. if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80)
  2091. arg->peer_flags |= ar->wmi.peer_flags->bw80;
  2092. if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160)
  2093. arg->peer_flags |= ar->wmi.peer_flags->bw160;
  2094. /* Calculate peer NSS capability from VHT capabilities if STA
  2095. * supports VHT.
  2096. */
  2097. for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
  2098. vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
  2099. (2 * i) & 3;
  2100. if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) &&
  2101. vht_mcs_mask[i])
  2102. max_nss = i + 1;
  2103. }
  2104. arg->peer_num_spatial_streams = min(sta->deflink.rx_nss, max_nss);
  2105. arg->peer_vht_rates.rx_max_rate =
  2106. __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
  2107. arg->peer_vht_rates.rx_mcs_set =
  2108. __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  2109. arg->peer_vht_rates.tx_max_rate =
  2110. __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
  2111. arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
  2112. __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
  2113. /* Configure bandwidth-NSS mapping to FW
  2114. * for the chip's tx chains setting on 160Mhz bw
  2115. */
  2116. if (arg->peer_phymode == MODE_11AC_VHT160 ||
  2117. arg->peer_phymode == MODE_11AC_VHT80_80) {
  2118. u32 rx_nss;
  2119. u32 max_rate;
  2120. max_rate = arg->peer_vht_rates.rx_max_rate;
  2121. rx_nss = get_160mhz_nss_from_maxrate(max_rate);
  2122. if (rx_nss == 0)
  2123. rx_nss = arg->peer_num_spatial_streams;
  2124. else
  2125. rx_nss = min(arg->peer_num_spatial_streams, rx_nss);
  2126. max_rate = hw->vht160_mcs_tx_highest;
  2127. rx_nss = min(rx_nss, get_160mhz_nss_from_maxrate(max_rate));
  2128. arg->peer_bw_rxnss_override =
  2129. FIELD_PREP(WMI_PEER_NSS_MAP_ENABLE, 1) |
  2130. FIELD_PREP(WMI_PEER_NSS_160MHZ_MASK, (rx_nss - 1));
  2131. if (arg->peer_phymode == MODE_11AC_VHT80_80) {
  2132. arg->peer_bw_rxnss_override |=
  2133. FIELD_PREP(WMI_PEER_NSS_80_80MHZ_MASK, (rx_nss - 1));
  2134. }
  2135. }
  2136. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2137. "mac vht peer %pM max_mpdu %d flags 0x%x peer_rx_nss_override 0x%x\n",
  2138. sta->addr, arg->peer_max_mpdu,
  2139. arg->peer_flags, arg->peer_bw_rxnss_override);
  2140. }
  2141. static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
  2142. struct ieee80211_vif *vif,
  2143. struct ieee80211_sta *sta,
  2144. struct wmi_peer_assoc_complete_arg *arg)
  2145. {
  2146. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  2147. switch (arvif->vdev_type) {
  2148. case WMI_VDEV_TYPE_AP:
  2149. if (sta->wme)
  2150. arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
  2151. if (sta->wme && sta->uapsd_queues) {
  2152. arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
  2153. arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
  2154. }
  2155. break;
  2156. case WMI_VDEV_TYPE_STA:
  2157. if (sta->wme)
  2158. arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
  2159. break;
  2160. case WMI_VDEV_TYPE_IBSS:
  2161. if (sta->wme)
  2162. arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
  2163. break;
  2164. default:
  2165. break;
  2166. }
  2167. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
  2168. sta->addr, !!(arg->peer_flags &
  2169. arvif->ar->wmi.peer_flags->qos));
  2170. }
  2171. static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
  2172. {
  2173. return sta->deflink.supp_rates[NL80211_BAND_2GHZ] >>
  2174. ATH10K_MAC_FIRST_OFDM_RATE_IDX;
  2175. }
  2176. static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
  2177. struct ieee80211_sta *sta)
  2178. {
  2179. struct ieee80211_sta_vht_cap *vht_cap = &sta->deflink.vht_cap;
  2180. if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160) {
  2181. switch (vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
  2182. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
  2183. return MODE_11AC_VHT160;
  2184. case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
  2185. return MODE_11AC_VHT80_80;
  2186. default:
  2187. /* not sure if this is a valid case? */
  2188. return MODE_11AC_VHT160;
  2189. }
  2190. }
  2191. if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80)
  2192. return MODE_11AC_VHT80;
  2193. if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40)
  2194. return MODE_11AC_VHT40;
  2195. if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_20)
  2196. return MODE_11AC_VHT20;
  2197. return MODE_UNKNOWN;
  2198. }
  2199. static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
  2200. struct ieee80211_vif *vif,
  2201. struct ieee80211_sta *sta,
  2202. struct wmi_peer_assoc_complete_arg *arg)
  2203. {
  2204. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  2205. struct cfg80211_chan_def def;
  2206. enum nl80211_band band;
  2207. const u8 *ht_mcs_mask;
  2208. const u16 *vht_mcs_mask;
  2209. enum wmi_phy_mode phymode = MODE_UNKNOWN;
  2210. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  2211. return;
  2212. band = def.chan->band;
  2213. ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
  2214. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  2215. switch (band) {
  2216. case NL80211_BAND_2GHZ:
  2217. if (sta->deflink.vht_cap.vht_supported &&
  2218. !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
  2219. if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40)
  2220. phymode = MODE_11AC_VHT40;
  2221. else
  2222. phymode = MODE_11AC_VHT20;
  2223. } else if (sta->deflink.ht_cap.ht_supported &&
  2224. !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
  2225. if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40)
  2226. phymode = MODE_11NG_HT40;
  2227. else
  2228. phymode = MODE_11NG_HT20;
  2229. } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
  2230. phymode = MODE_11G;
  2231. } else {
  2232. phymode = MODE_11B;
  2233. }
  2234. break;
  2235. case NL80211_BAND_5GHZ:
  2236. /*
  2237. * Check VHT first.
  2238. */
  2239. if (sta->deflink.vht_cap.vht_supported &&
  2240. !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
  2241. phymode = ath10k_mac_get_phymode_vht(ar, sta);
  2242. } else if (sta->deflink.ht_cap.ht_supported &&
  2243. !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
  2244. if (sta->deflink.bandwidth >= IEEE80211_STA_RX_BW_40)
  2245. phymode = MODE_11NA_HT40;
  2246. else
  2247. phymode = MODE_11NA_HT20;
  2248. } else {
  2249. phymode = MODE_11A;
  2250. }
  2251. break;
  2252. default:
  2253. break;
  2254. }
  2255. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
  2256. sta->addr, ath10k_wmi_phymode_str(phymode));
  2257. arg->peer_phymode = phymode;
  2258. WARN_ON(phymode == MODE_UNKNOWN);
  2259. }
  2260. static int ath10k_peer_assoc_prepare(struct ath10k *ar,
  2261. struct ieee80211_vif *vif,
  2262. struct ieee80211_sta *sta,
  2263. struct wmi_peer_assoc_complete_arg *arg)
  2264. {
  2265. lockdep_assert_held(&ar->conf_mutex);
  2266. memset(arg, 0, sizeof(*arg));
  2267. ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
  2268. ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
  2269. ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
  2270. ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
  2271. ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
  2272. ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
  2273. ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
  2274. return 0;
  2275. }
  2276. static const u32 ath10k_smps_map[] = {
  2277. [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
  2278. [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
  2279. [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
  2280. [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
  2281. };
  2282. static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
  2283. const u8 *addr,
  2284. const struct ieee80211_sta_ht_cap *ht_cap)
  2285. {
  2286. int smps;
  2287. if (!ht_cap->ht_supported)
  2288. return 0;
  2289. smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
  2290. smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
  2291. if (smps >= ARRAY_SIZE(ath10k_smps_map))
  2292. return -EINVAL;
  2293. return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
  2294. ar->wmi.peer_param->smps_state,
  2295. ath10k_smps_map[smps]);
  2296. }
  2297. static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
  2298. struct ieee80211_vif *vif,
  2299. struct ieee80211_sta_vht_cap vht_cap)
  2300. {
  2301. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  2302. int ret;
  2303. u32 param;
  2304. u32 value;
  2305. if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
  2306. return 0;
  2307. if (!(ar->vht_cap_info &
  2308. (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  2309. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
  2310. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  2311. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
  2312. return 0;
  2313. param = ar->wmi.vdev_param->txbf;
  2314. value = 0;
  2315. if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
  2316. return 0;
  2317. /* The following logic is correct. If a remote STA advertises support
  2318. * for being a beamformer then we should enable us being a beamformee.
  2319. */
  2320. if (ar->vht_cap_info &
  2321. (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  2322. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
  2323. if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
  2324. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
  2325. if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
  2326. value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
  2327. }
  2328. if (ar->vht_cap_info &
  2329. (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  2330. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
  2331. if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
  2332. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
  2333. if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
  2334. value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
  2335. }
  2336. if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
  2337. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
  2338. if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
  2339. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
  2340. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
  2341. if (ret) {
  2342. ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
  2343. value, ret);
  2344. return ret;
  2345. }
  2346. return 0;
  2347. }
  2348. static bool ath10k_mac_is_connected(struct ath10k *ar)
  2349. {
  2350. struct ath10k_vif *arvif;
  2351. list_for_each_entry(arvif, &ar->arvifs, list) {
  2352. if (arvif->is_up && arvif->vdev_type == WMI_VDEV_TYPE_STA)
  2353. return true;
  2354. }
  2355. return false;
  2356. }
  2357. static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
  2358. {
  2359. int ret;
  2360. u32 param;
  2361. int tx_power_2g, tx_power_5g;
  2362. bool connected;
  2363. lockdep_assert_held(&ar->conf_mutex);
  2364. /* ath10k internally uses unit of 0.5 dBm so multiply by 2 */
  2365. tx_power_2g = txpower * 2;
  2366. tx_power_5g = txpower * 2;
  2367. connected = ath10k_mac_is_connected(ar);
  2368. if (connected && ar->tx_power_2g_limit)
  2369. if (tx_power_2g > ar->tx_power_2g_limit)
  2370. tx_power_2g = ar->tx_power_2g_limit;
  2371. if (connected && ar->tx_power_5g_limit)
  2372. if (tx_power_5g > ar->tx_power_5g_limit)
  2373. tx_power_5g = ar->tx_power_5g_limit;
  2374. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower 2g: %d, 5g: %d\n",
  2375. tx_power_2g, tx_power_5g);
  2376. param = ar->wmi.pdev_param->txpower_limit2g;
  2377. ret = ath10k_wmi_pdev_set_param(ar, param, tx_power_2g);
  2378. if (ret) {
  2379. ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
  2380. tx_power_2g, ret);
  2381. return ret;
  2382. }
  2383. param = ar->wmi.pdev_param->txpower_limit5g;
  2384. ret = ath10k_wmi_pdev_set_param(ar, param, tx_power_5g);
  2385. if (ret) {
  2386. ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
  2387. tx_power_5g, ret);
  2388. return ret;
  2389. }
  2390. return 0;
  2391. }
  2392. static int ath10k_mac_txpower_recalc(struct ath10k *ar)
  2393. {
  2394. struct ath10k_vif *arvif;
  2395. int ret, txpower = -1;
  2396. lockdep_assert_held(&ar->conf_mutex);
  2397. list_for_each_entry(arvif, &ar->arvifs, list) {
  2398. /* txpower not initialized yet? */
  2399. if (arvif->txpower == INT_MIN)
  2400. continue;
  2401. if (txpower == -1)
  2402. txpower = arvif->txpower;
  2403. else
  2404. txpower = min(txpower, arvif->txpower);
  2405. }
  2406. if (txpower == -1)
  2407. return 0;
  2408. ret = ath10k_mac_txpower_setup(ar, txpower);
  2409. if (ret) {
  2410. ath10k_warn(ar, "failed to setup tx power %d: %d\n",
  2411. txpower, ret);
  2412. return ret;
  2413. }
  2414. return 0;
  2415. }
  2416. static int ath10k_mac_set_sar_power(struct ath10k *ar)
  2417. {
  2418. if (!ar->hw_params.dynamic_sar_support)
  2419. return -EOPNOTSUPP;
  2420. if (!ath10k_mac_is_connected(ar))
  2421. return 0;
  2422. /* if connected, then arvif->txpower must be valid */
  2423. return ath10k_mac_txpower_recalc(ar);
  2424. }
  2425. static int ath10k_mac_set_sar_specs(struct ieee80211_hw *hw,
  2426. const struct cfg80211_sar_specs *sar)
  2427. {
  2428. const struct cfg80211_sar_sub_specs *sub_specs;
  2429. struct ath10k *ar = hw->priv;
  2430. u32 i;
  2431. int ret;
  2432. mutex_lock(&ar->conf_mutex);
  2433. if (!ar->hw_params.dynamic_sar_support) {
  2434. ret = -EOPNOTSUPP;
  2435. goto err;
  2436. }
  2437. if (!sar || sar->type != NL80211_SAR_TYPE_POWER ||
  2438. sar->num_sub_specs == 0) {
  2439. ret = -EINVAL;
  2440. goto err;
  2441. }
  2442. sub_specs = sar->sub_specs;
  2443. /* 0dbm is not a practical value for ath10k, so use 0
  2444. * as no SAR limitation on it.
  2445. */
  2446. ar->tx_power_2g_limit = 0;
  2447. ar->tx_power_5g_limit = 0;
  2448. /* note the power is in 0.25dbm unit, while ath10k uses
  2449. * 0.5dbm unit.
  2450. */
  2451. for (i = 0; i < sar->num_sub_specs; i++) {
  2452. if (sub_specs->freq_range_index == 0)
  2453. ar->tx_power_2g_limit = sub_specs->power / 2;
  2454. else if (sub_specs->freq_range_index == 1)
  2455. ar->tx_power_5g_limit = sub_specs->power / 2;
  2456. sub_specs++;
  2457. }
  2458. ret = ath10k_mac_set_sar_power(ar);
  2459. if (ret) {
  2460. ath10k_warn(ar, "failed to set sar power: %d", ret);
  2461. goto err;
  2462. }
  2463. err:
  2464. mutex_unlock(&ar->conf_mutex);
  2465. return ret;
  2466. }
  2467. /* can be called only in mac80211 callbacks due to `key_count` usage */
  2468. static void ath10k_bss_assoc(struct ieee80211_hw *hw,
  2469. struct ieee80211_vif *vif,
  2470. struct ieee80211_bss_conf *bss_conf)
  2471. {
  2472. struct ath10k *ar = hw->priv;
  2473. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  2474. struct ieee80211_sta_ht_cap ht_cap;
  2475. struct ieee80211_sta_vht_cap vht_cap;
  2476. struct wmi_peer_assoc_complete_arg peer_arg;
  2477. struct ieee80211_sta *ap_sta;
  2478. int ret;
  2479. lockdep_assert_held(&ar->conf_mutex);
  2480. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
  2481. arvif->vdev_id, arvif->bssid, arvif->aid);
  2482. rcu_read_lock();
  2483. ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
  2484. if (!ap_sta) {
  2485. ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
  2486. bss_conf->bssid, arvif->vdev_id);
  2487. rcu_read_unlock();
  2488. return;
  2489. }
  2490. /* ap_sta must be accessed only within rcu section which must be left
  2491. * before calling ath10k_setup_peer_smps() which might sleep.
  2492. */
  2493. ht_cap = ap_sta->deflink.ht_cap;
  2494. vht_cap = ap_sta->deflink.vht_cap;
  2495. ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
  2496. if (ret) {
  2497. ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
  2498. bss_conf->bssid, arvif->vdev_id, ret);
  2499. rcu_read_unlock();
  2500. return;
  2501. }
  2502. rcu_read_unlock();
  2503. ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
  2504. if (ret) {
  2505. ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
  2506. bss_conf->bssid, arvif->vdev_id, ret);
  2507. return;
  2508. }
  2509. ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
  2510. if (ret) {
  2511. ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
  2512. arvif->vdev_id, ret);
  2513. return;
  2514. }
  2515. ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
  2516. if (ret) {
  2517. ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
  2518. arvif->vdev_id, bss_conf->bssid, ret);
  2519. return;
  2520. }
  2521. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2522. "mac vdev %d up (associated) bssid %pM aid %d\n",
  2523. arvif->vdev_id, bss_conf->bssid, vif->cfg.aid);
  2524. WARN_ON(arvif->is_up);
  2525. arvif->aid = vif->cfg.aid;
  2526. ether_addr_copy(arvif->bssid, bss_conf->bssid);
  2527. ret = ath10k_wmi_pdev_set_param(ar,
  2528. ar->wmi.pdev_param->peer_stats_info_enable, 1);
  2529. if (ret)
  2530. ath10k_warn(ar, "failed to enable peer stats info: %d\n", ret);
  2531. ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
  2532. if (ret) {
  2533. ath10k_warn(ar, "failed to set vdev %d up: %d\n",
  2534. arvif->vdev_id, ret);
  2535. return;
  2536. }
  2537. arvif->is_up = true;
  2538. ath10k_mac_set_sar_power(ar);
  2539. /* Workaround: Some firmware revisions (tested with qca6174
  2540. * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
  2541. * poked with peer param command.
  2542. */
  2543. ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
  2544. ar->wmi.peer_param->dummy_var, 1);
  2545. if (ret) {
  2546. ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
  2547. arvif->bssid, arvif->vdev_id, ret);
  2548. return;
  2549. }
  2550. }
  2551. static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
  2552. struct ieee80211_vif *vif)
  2553. {
  2554. struct ath10k *ar = hw->priv;
  2555. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  2556. struct ieee80211_sta_vht_cap vht_cap = {};
  2557. int ret;
  2558. lockdep_assert_held(&ar->conf_mutex);
  2559. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
  2560. arvif->vdev_id, arvif->bssid);
  2561. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  2562. if (ret)
  2563. ath10k_warn(ar, "failed to down vdev %i: %d\n",
  2564. arvif->vdev_id, ret);
  2565. arvif->def_wep_key_idx = -1;
  2566. ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
  2567. if (ret) {
  2568. ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
  2569. arvif->vdev_id, ret);
  2570. return;
  2571. }
  2572. arvif->is_up = false;
  2573. ath10k_mac_txpower_recalc(ar);
  2574. cancel_delayed_work_sync(&arvif->connection_loss_work);
  2575. }
  2576. static int ath10k_new_peer_tid_config(struct ath10k *ar,
  2577. struct ieee80211_sta *sta,
  2578. struct ath10k_vif *arvif)
  2579. {
  2580. struct wmi_per_peer_per_tid_cfg_arg arg = {};
  2581. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  2582. bool config_apply;
  2583. int ret, i;
  2584. for (i = 0; i < ATH10K_TID_MAX; i++) {
  2585. config_apply = false;
  2586. if (arvif->retry_long[i] || arvif->ampdu[i] ||
  2587. arvif->rate_ctrl[i] || arvif->rtscts[i]) {
  2588. config_apply = true;
  2589. arg.tid = i;
  2590. arg.vdev_id = arvif->vdev_id;
  2591. arg.retry_count = arvif->retry_long[i];
  2592. arg.aggr_control = arvif->ampdu[i];
  2593. arg.rate_ctrl = arvif->rate_ctrl[i];
  2594. arg.rcode_flags = arvif->rate_code[i];
  2595. if (arvif->rtscts[i])
  2596. arg.ext_tid_cfg_bitmap =
  2597. WMI_EXT_TID_RTS_CTS_CONFIG;
  2598. else
  2599. arg.ext_tid_cfg_bitmap = 0;
  2600. arg.rtscts_ctrl = arvif->rtscts[i];
  2601. }
  2602. if (arvif->noack[i]) {
  2603. arg.ack_policy = arvif->noack[i];
  2604. arg.rate_ctrl = WMI_TID_CONFIG_RATE_CONTROL_DEFAULT_LOWEST_RATE;
  2605. arg.aggr_control = WMI_TID_CONFIG_AGGR_CONTROL_DISABLE;
  2606. config_apply = true;
  2607. }
  2608. /* Assign default value(-1) to newly connected station.
  2609. * This is to identify station specific tid configuration not
  2610. * configured for the station.
  2611. */
  2612. arsta->retry_long[i] = -1;
  2613. arsta->noack[i] = -1;
  2614. arsta->ampdu[i] = -1;
  2615. if (!config_apply)
  2616. continue;
  2617. ether_addr_copy(arg.peer_macaddr.addr, sta->addr);
  2618. ret = ath10k_wmi_set_per_peer_per_tid_cfg(ar, &arg);
  2619. if (ret) {
  2620. ath10k_warn(ar, "failed to set per tid retry/aggr config for sta %pM: %d\n",
  2621. sta->addr, ret);
  2622. return ret;
  2623. }
  2624. memset(&arg, 0, sizeof(arg));
  2625. }
  2626. return 0;
  2627. }
  2628. static int ath10k_station_assoc(struct ath10k *ar,
  2629. struct ieee80211_vif *vif,
  2630. struct ieee80211_sta *sta,
  2631. bool reassoc)
  2632. {
  2633. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  2634. struct wmi_peer_assoc_complete_arg peer_arg;
  2635. int ret = 0;
  2636. lockdep_assert_held(&ar->conf_mutex);
  2637. ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
  2638. if (ret) {
  2639. ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
  2640. sta->addr, arvif->vdev_id, ret);
  2641. return ret;
  2642. }
  2643. ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
  2644. if (ret) {
  2645. ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
  2646. sta->addr, arvif->vdev_id, ret);
  2647. return ret;
  2648. }
  2649. /* Re-assoc is run only to update supported rates for given station. It
  2650. * doesn't make much sense to reconfigure the peer completely.
  2651. */
  2652. if (!reassoc) {
  2653. ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
  2654. &sta->deflink.ht_cap);
  2655. if (ret) {
  2656. ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
  2657. arvif->vdev_id, ret);
  2658. return ret;
  2659. }
  2660. ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
  2661. if (ret) {
  2662. ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
  2663. sta->addr, arvif->vdev_id, ret);
  2664. return ret;
  2665. }
  2666. if (!sta->wme) {
  2667. arvif->num_legacy_stations++;
  2668. ret = ath10k_recalc_rtscts_prot(arvif);
  2669. if (ret) {
  2670. ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  2671. arvif->vdev_id, ret);
  2672. return ret;
  2673. }
  2674. }
  2675. /* Plumb cached keys only for static WEP */
  2676. if ((arvif->def_wep_key_idx != -1) && (!sta->tdls)) {
  2677. ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
  2678. if (ret) {
  2679. ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
  2680. arvif->vdev_id, ret);
  2681. return ret;
  2682. }
  2683. }
  2684. }
  2685. if (!test_bit(WMI_SERVICE_PEER_TID_CONFIGS_SUPPORT, ar->wmi.svc_map))
  2686. return ret;
  2687. return ath10k_new_peer_tid_config(ar, sta, arvif);
  2688. }
  2689. static int ath10k_station_disassoc(struct ath10k *ar,
  2690. struct ieee80211_vif *vif,
  2691. struct ieee80211_sta *sta)
  2692. {
  2693. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  2694. int ret = 0;
  2695. lockdep_assert_held(&ar->conf_mutex);
  2696. if (!sta->wme) {
  2697. arvif->num_legacy_stations--;
  2698. ret = ath10k_recalc_rtscts_prot(arvif);
  2699. if (ret) {
  2700. ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  2701. arvif->vdev_id, ret);
  2702. return ret;
  2703. }
  2704. }
  2705. ret = ath10k_clear_peer_keys(arvif, sta->addr);
  2706. if (ret) {
  2707. ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
  2708. arvif->vdev_id, ret);
  2709. return ret;
  2710. }
  2711. return ret;
  2712. }
  2713. /**************/
  2714. /* Regulatory */
  2715. /**************/
  2716. static int ath10k_update_channel_list(struct ath10k *ar)
  2717. {
  2718. struct ieee80211_hw *hw = ar->hw;
  2719. struct ieee80211_supported_band **bands;
  2720. enum nl80211_band band;
  2721. struct ieee80211_channel *channel;
  2722. struct wmi_scan_chan_list_arg arg = {0};
  2723. struct wmi_channel_arg *ch;
  2724. bool passive;
  2725. int len;
  2726. int ret;
  2727. int i;
  2728. lockdep_assert_held(&ar->conf_mutex);
  2729. bands = hw->wiphy->bands;
  2730. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  2731. if (!bands[band])
  2732. continue;
  2733. for (i = 0; i < bands[band]->n_channels; i++) {
  2734. if (bands[band]->channels[i].flags &
  2735. IEEE80211_CHAN_DISABLED)
  2736. continue;
  2737. arg.n_channels++;
  2738. }
  2739. }
  2740. len = sizeof(struct wmi_channel_arg) * arg.n_channels;
  2741. arg.channels = kzalloc(len, GFP_KERNEL);
  2742. if (!arg.channels)
  2743. return -ENOMEM;
  2744. ch = arg.channels;
  2745. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  2746. if (!bands[band])
  2747. continue;
  2748. for (i = 0; i < bands[band]->n_channels; i++) {
  2749. channel = &bands[band]->channels[i];
  2750. if (channel->flags & IEEE80211_CHAN_DISABLED)
  2751. continue;
  2752. ch->allow_ht = true;
  2753. /* FIXME: when should we really allow VHT? */
  2754. ch->allow_vht = true;
  2755. ch->allow_ibss =
  2756. !(channel->flags & IEEE80211_CHAN_NO_IR);
  2757. ch->ht40plus =
  2758. !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
  2759. ch->chan_radar =
  2760. !!(channel->flags & IEEE80211_CHAN_RADAR);
  2761. passive = channel->flags & IEEE80211_CHAN_NO_IR;
  2762. ch->passive = passive;
  2763. /* the firmware is ignoring the "radar" flag of the
  2764. * channel and is scanning actively using Probe Requests
  2765. * on "Radar detection"/DFS channels which are not
  2766. * marked as "available"
  2767. */
  2768. ch->passive |= ch->chan_radar;
  2769. ch->freq = channel->center_freq;
  2770. ch->band_center_freq1 = channel->center_freq;
  2771. ch->min_power = 0;
  2772. ch->max_power = channel->max_power * 2;
  2773. ch->max_reg_power = channel->max_reg_power * 2;
  2774. ch->max_antenna_gain = channel->max_antenna_gain;
  2775. ch->reg_class_id = 0; /* FIXME */
  2776. /* FIXME: why use only legacy modes, why not any
  2777. * HT/VHT modes? Would that even make any
  2778. * difference?
  2779. */
  2780. if (channel->band == NL80211_BAND_2GHZ)
  2781. ch->mode = MODE_11G;
  2782. else
  2783. ch->mode = MODE_11A;
  2784. if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
  2785. continue;
  2786. ath10k_dbg(ar, ATH10K_DBG_WMI,
  2787. "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
  2788. ch - arg.channels, arg.n_channels,
  2789. ch->freq, ch->max_power, ch->max_reg_power,
  2790. ch->max_antenna_gain, ch->mode);
  2791. ch++;
  2792. }
  2793. }
  2794. ret = ath10k_wmi_scan_chan_list(ar, &arg);
  2795. kfree(arg.channels);
  2796. return ret;
  2797. }
  2798. static enum wmi_dfs_region
  2799. ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
  2800. {
  2801. switch (dfs_region) {
  2802. case NL80211_DFS_UNSET:
  2803. return WMI_UNINIT_DFS_DOMAIN;
  2804. case NL80211_DFS_FCC:
  2805. return WMI_FCC_DFS_DOMAIN;
  2806. case NL80211_DFS_ETSI:
  2807. return WMI_ETSI_DFS_DOMAIN;
  2808. case NL80211_DFS_JP:
  2809. return WMI_MKK4_DFS_DOMAIN;
  2810. }
  2811. return WMI_UNINIT_DFS_DOMAIN;
  2812. }
  2813. static void ath10k_regd_update(struct ath10k *ar)
  2814. {
  2815. struct reg_dmn_pair_mapping *regpair;
  2816. int ret;
  2817. enum wmi_dfs_region wmi_dfs_reg;
  2818. enum nl80211_dfs_regions nl_dfs_reg;
  2819. lockdep_assert_held(&ar->conf_mutex);
  2820. ret = ath10k_update_channel_list(ar);
  2821. if (ret)
  2822. ath10k_warn(ar, "failed to update channel list: %d\n", ret);
  2823. regpair = ar->ath_common.regulatory.regpair;
  2824. if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
  2825. nl_dfs_reg = ar->dfs_detector->region;
  2826. wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
  2827. } else {
  2828. wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
  2829. }
  2830. /* Target allows setting up per-band regdomain but ath_common provides
  2831. * a combined one only
  2832. */
  2833. ret = ath10k_wmi_pdev_set_regdomain(ar,
  2834. regpair->reg_domain,
  2835. regpair->reg_domain, /* 2ghz */
  2836. regpair->reg_domain, /* 5ghz */
  2837. regpair->reg_2ghz_ctl,
  2838. regpair->reg_5ghz_ctl,
  2839. wmi_dfs_reg);
  2840. if (ret)
  2841. ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
  2842. }
  2843. static void ath10k_mac_update_channel_list(struct ath10k *ar,
  2844. struct ieee80211_supported_band *band)
  2845. {
  2846. int i;
  2847. if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
  2848. for (i = 0; i < band->n_channels; i++) {
  2849. if (band->channels[i].center_freq < ar->low_5ghz_chan ||
  2850. band->channels[i].center_freq > ar->high_5ghz_chan)
  2851. band->channels[i].flags |=
  2852. IEEE80211_CHAN_DISABLED;
  2853. }
  2854. }
  2855. }
  2856. static void ath10k_reg_notifier(struct wiphy *wiphy,
  2857. struct regulatory_request *request)
  2858. {
  2859. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  2860. struct ath10k *ar = hw->priv;
  2861. bool result;
  2862. ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
  2863. if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
  2864. ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
  2865. request->dfs_region);
  2866. result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
  2867. request->dfs_region);
  2868. if (!result)
  2869. ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
  2870. request->dfs_region);
  2871. }
  2872. mutex_lock(&ar->conf_mutex);
  2873. if (ar->state == ATH10K_STATE_ON)
  2874. ath10k_regd_update(ar);
  2875. mutex_unlock(&ar->conf_mutex);
  2876. if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
  2877. ath10k_mac_update_channel_list(ar,
  2878. ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
  2879. }
  2880. static void ath10k_stop_radar_confirmation(struct ath10k *ar)
  2881. {
  2882. spin_lock_bh(&ar->data_lock);
  2883. ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_STOPPED;
  2884. spin_unlock_bh(&ar->data_lock);
  2885. cancel_work_sync(&ar->radar_confirmation_work);
  2886. }
  2887. /***************/
  2888. /* TX handlers */
  2889. /***************/
  2890. enum ath10k_mac_tx_path {
  2891. ATH10K_MAC_TX_HTT,
  2892. ATH10K_MAC_TX_HTT_MGMT,
  2893. ATH10K_MAC_TX_WMI_MGMT,
  2894. ATH10K_MAC_TX_UNKNOWN,
  2895. };
  2896. void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
  2897. {
  2898. lockdep_assert_held(&ar->htt.tx_lock);
  2899. WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
  2900. ar->tx_paused |= BIT(reason);
  2901. ieee80211_stop_queues(ar->hw);
  2902. }
  2903. static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
  2904. struct ieee80211_vif *vif)
  2905. {
  2906. struct ath10k *ar = data;
  2907. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  2908. if (arvif->tx_paused)
  2909. return;
  2910. ieee80211_wake_queue(ar->hw, arvif->vdev_id);
  2911. }
  2912. void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
  2913. {
  2914. lockdep_assert_held(&ar->htt.tx_lock);
  2915. WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
  2916. ar->tx_paused &= ~BIT(reason);
  2917. if (ar->tx_paused)
  2918. return;
  2919. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  2920. ATH10K_ITER_RESUME_FLAGS,
  2921. ath10k_mac_tx_unlock_iter,
  2922. ar);
  2923. ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
  2924. }
  2925. void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
  2926. {
  2927. struct ath10k *ar = arvif->ar;
  2928. lockdep_assert_held(&ar->htt.tx_lock);
  2929. WARN_ON(reason >= BITS_PER_LONG);
  2930. arvif->tx_paused |= BIT(reason);
  2931. ieee80211_stop_queue(ar->hw, arvif->vdev_id);
  2932. }
  2933. void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
  2934. {
  2935. struct ath10k *ar = arvif->ar;
  2936. lockdep_assert_held(&ar->htt.tx_lock);
  2937. WARN_ON(reason >= BITS_PER_LONG);
  2938. arvif->tx_paused &= ~BIT(reason);
  2939. if (ar->tx_paused)
  2940. return;
  2941. if (arvif->tx_paused)
  2942. return;
  2943. ieee80211_wake_queue(ar->hw, arvif->vdev_id);
  2944. }
  2945. static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
  2946. enum wmi_tlv_tx_pause_id pause_id,
  2947. enum wmi_tlv_tx_pause_action action)
  2948. {
  2949. struct ath10k *ar = arvif->ar;
  2950. lockdep_assert_held(&ar->htt.tx_lock);
  2951. switch (action) {
  2952. case WMI_TLV_TX_PAUSE_ACTION_STOP:
  2953. ath10k_mac_vif_tx_lock(arvif, pause_id);
  2954. break;
  2955. case WMI_TLV_TX_PAUSE_ACTION_WAKE:
  2956. ath10k_mac_vif_tx_unlock(arvif, pause_id);
  2957. break;
  2958. default:
  2959. ath10k_dbg(ar, ATH10K_DBG_BOOT,
  2960. "received unknown tx pause action %d on vdev %i, ignoring\n",
  2961. action, arvif->vdev_id);
  2962. break;
  2963. }
  2964. }
  2965. struct ath10k_mac_tx_pause {
  2966. u32 vdev_id;
  2967. enum wmi_tlv_tx_pause_id pause_id;
  2968. enum wmi_tlv_tx_pause_action action;
  2969. };
  2970. static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
  2971. struct ieee80211_vif *vif)
  2972. {
  2973. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  2974. struct ath10k_mac_tx_pause *arg = data;
  2975. if (arvif->vdev_id != arg->vdev_id)
  2976. return;
  2977. ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
  2978. }
  2979. void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
  2980. enum wmi_tlv_tx_pause_id pause_id,
  2981. enum wmi_tlv_tx_pause_action action)
  2982. {
  2983. struct ath10k_mac_tx_pause arg = {
  2984. .vdev_id = vdev_id,
  2985. .pause_id = pause_id,
  2986. .action = action,
  2987. };
  2988. spin_lock_bh(&ar->htt.tx_lock);
  2989. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  2990. ATH10K_ITER_RESUME_FLAGS,
  2991. ath10k_mac_handle_tx_pause_iter,
  2992. &arg);
  2993. spin_unlock_bh(&ar->htt.tx_lock);
  2994. }
  2995. static enum ath10k_hw_txrx_mode
  2996. ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
  2997. struct ieee80211_vif *vif,
  2998. struct ieee80211_sta *sta,
  2999. struct sk_buff *skb)
  3000. {
  3001. const struct ieee80211_hdr *hdr = (void *)skb->data;
  3002. const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
  3003. __le16 fc = hdr->frame_control;
  3004. if (IEEE80211_SKB_CB(skb)->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)
  3005. return ATH10K_HW_TXRX_ETHERNET;
  3006. if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
  3007. return ATH10K_HW_TXRX_RAW;
  3008. if (ieee80211_is_mgmt(fc))
  3009. return ATH10K_HW_TXRX_MGMT;
  3010. /* Workaround:
  3011. *
  3012. * NullFunc frames are mostly used to ping if a client or AP are still
  3013. * reachable and responsive. This implies tx status reports must be
  3014. * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
  3015. * come to a conclusion that the other end disappeared and tear down
  3016. * BSS connection or it can never disconnect from BSS/client (which is
  3017. * the case).
  3018. *
  3019. * Firmware with HTT older than 3.0 delivers incorrect tx status for
  3020. * NullFunc frames to driver. However there's a HTT Mgmt Tx command
  3021. * which seems to deliver correct tx reports for NullFunc frames. The
  3022. * downside of using it is it ignores client powersave state so it can
  3023. * end up disconnecting sleeping clients in AP mode. It should fix STA
  3024. * mode though because AP don't sleep.
  3025. */
  3026. if (ar->htt.target_version_major < 3 &&
  3027. (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
  3028. !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
  3029. ar->running_fw->fw_file.fw_features))
  3030. return ATH10K_HW_TXRX_MGMT;
  3031. /* Workaround:
  3032. *
  3033. * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
  3034. * NativeWifi txmode - it selects AP key instead of peer key. It seems
  3035. * to work with Ethernet txmode so use it.
  3036. *
  3037. * FIXME: Check if raw mode works with TDLS.
  3038. */
  3039. if (ieee80211_is_data_present(fc) && sta && sta->tdls)
  3040. return ATH10K_HW_TXRX_ETHERNET;
  3041. if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) ||
  3042. skb_cb->flags & ATH10K_SKB_F_RAW_TX)
  3043. return ATH10K_HW_TXRX_RAW;
  3044. return ATH10K_HW_TXRX_NATIVE_WIFI;
  3045. }
  3046. static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
  3047. struct sk_buff *skb)
  3048. {
  3049. const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  3050. const struct ieee80211_hdr *hdr = (void *)skb->data;
  3051. const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
  3052. IEEE80211_TX_CTL_INJECTED;
  3053. if (!ieee80211_has_protected(hdr->frame_control))
  3054. return false;
  3055. if ((info->flags & mask) == mask)
  3056. return false;
  3057. if (vif)
  3058. return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
  3059. return true;
  3060. }
  3061. /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
  3062. * Control in the header.
  3063. */
  3064. static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
  3065. {
  3066. struct ieee80211_hdr *hdr = (void *)skb->data;
  3067. struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
  3068. u8 *qos_ctl;
  3069. if (!ieee80211_is_data_qos(hdr->frame_control))
  3070. return;
  3071. qos_ctl = ieee80211_get_qos_ctl(hdr);
  3072. memmove(skb->data + IEEE80211_QOS_CTL_LEN,
  3073. skb->data, (void *)qos_ctl - (void *)skb->data);
  3074. skb_pull(skb, IEEE80211_QOS_CTL_LEN);
  3075. /* Some firmware revisions don't handle sending QoS NullFunc well.
  3076. * These frames are mainly used for CQM purposes so it doesn't really
  3077. * matter whether QoS NullFunc or NullFunc are sent.
  3078. */
  3079. hdr = (void *)skb->data;
  3080. if (ieee80211_is_qos_nullfunc(hdr->frame_control))
  3081. cb->flags &= ~ATH10K_SKB_F_QOS;
  3082. hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  3083. }
  3084. static void ath10k_tx_h_8023(struct sk_buff *skb)
  3085. {
  3086. struct ieee80211_hdr *hdr;
  3087. struct rfc1042_hdr *rfc1042;
  3088. struct ethhdr *eth;
  3089. size_t hdrlen;
  3090. u8 da[ETH_ALEN];
  3091. u8 sa[ETH_ALEN];
  3092. __be16 type;
  3093. hdr = (void *)skb->data;
  3094. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  3095. rfc1042 = (void *)skb->data + hdrlen;
  3096. ether_addr_copy(da, ieee80211_get_DA(hdr));
  3097. ether_addr_copy(sa, ieee80211_get_SA(hdr));
  3098. type = rfc1042->snap_type;
  3099. skb_pull(skb, hdrlen + sizeof(*rfc1042));
  3100. skb_push(skb, sizeof(*eth));
  3101. eth = (void *)skb->data;
  3102. ether_addr_copy(eth->h_dest, da);
  3103. ether_addr_copy(eth->h_source, sa);
  3104. eth->h_proto = type;
  3105. }
  3106. static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
  3107. struct ieee80211_vif *vif,
  3108. struct sk_buff *skb)
  3109. {
  3110. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  3111. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  3112. /* This is case only for P2P_GO */
  3113. if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
  3114. return;
  3115. if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
  3116. spin_lock_bh(&ar->data_lock);
  3117. if (arvif->u.ap.noa_data)
  3118. if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
  3119. GFP_ATOMIC))
  3120. skb_put_data(skb, arvif->u.ap.noa_data,
  3121. arvif->u.ap.noa_len);
  3122. spin_unlock_bh(&ar->data_lock);
  3123. }
  3124. }
  3125. static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
  3126. struct ieee80211_vif *vif,
  3127. struct ieee80211_txq *txq,
  3128. struct ieee80211_sta *sta,
  3129. struct sk_buff *skb, u16 airtime)
  3130. {
  3131. struct ieee80211_hdr *hdr = (void *)skb->data;
  3132. struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
  3133. const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  3134. bool is_data = ieee80211_is_data(hdr->frame_control) ||
  3135. ieee80211_is_data_qos(hdr->frame_control);
  3136. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  3137. struct ath10k_sta *arsta;
  3138. u8 tid, *qos_ctl;
  3139. bool noack = false;
  3140. cb->flags = 0;
  3141. if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
  3142. cb->flags |= ATH10K_SKB_F_QOS; /* Assume data frames are QoS */
  3143. goto finish_cb_fill;
  3144. }
  3145. if (!ath10k_tx_h_use_hwcrypto(vif, skb))
  3146. cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
  3147. if (ieee80211_is_mgmt(hdr->frame_control))
  3148. cb->flags |= ATH10K_SKB_F_MGMT;
  3149. if (ieee80211_is_data_qos(hdr->frame_control)) {
  3150. cb->flags |= ATH10K_SKB_F_QOS;
  3151. qos_ctl = ieee80211_get_qos_ctl(hdr);
  3152. tid = (*qos_ctl) & IEEE80211_QOS_CTL_TID_MASK;
  3153. if (arvif->noack[tid] == WMI_PEER_TID_CONFIG_NOACK)
  3154. noack = true;
  3155. if (sta) {
  3156. arsta = (struct ath10k_sta *)sta->drv_priv;
  3157. if (arsta->noack[tid] == WMI_PEER_TID_CONFIG_NOACK)
  3158. noack = true;
  3159. if (arsta->noack[tid] == WMI_PEER_TID_CONFIG_ACK)
  3160. noack = false;
  3161. }
  3162. if (noack)
  3163. cb->flags |= ATH10K_SKB_F_NOACK_TID;
  3164. }
  3165. /* Data frames encrypted in software will be posted to firmware
  3166. * with tx encap mode set to RAW. Ex: Multicast traffic generated
  3167. * for a specific VLAN group will always be encrypted in software.
  3168. */
  3169. if (is_data && ieee80211_has_protected(hdr->frame_control) &&
  3170. !info->control.hw_key) {
  3171. cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
  3172. cb->flags |= ATH10K_SKB_F_RAW_TX;
  3173. }
  3174. finish_cb_fill:
  3175. cb->vif = vif;
  3176. cb->txq = txq;
  3177. cb->airtime_est = airtime;
  3178. if (sta) {
  3179. arsta = (struct ath10k_sta *)sta->drv_priv;
  3180. spin_lock_bh(&ar->data_lock);
  3181. cb->ucast_cipher = arsta->ucast_cipher;
  3182. spin_unlock_bh(&ar->data_lock);
  3183. }
  3184. }
  3185. bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
  3186. {
  3187. /* FIXME: Not really sure since when the behaviour changed. At some
  3188. * point new firmware stopped requiring creation of peer entries for
  3189. * offchannel tx (and actually creating them causes issues with wmi-htc
  3190. * tx credit replenishment and reliability). Assuming it's at least 3.4
  3191. * because that's when the `freq` was introduced to TX_FRM HTT command.
  3192. */
  3193. return (ar->htt.target_version_major >= 3 &&
  3194. ar->htt.target_version_minor >= 4 &&
  3195. ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
  3196. }
  3197. static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
  3198. {
  3199. struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
  3200. if (skb_queue_len_lockless(q) >= ATH10K_MAX_NUM_MGMT_PENDING) {
  3201. ath10k_warn(ar, "wmi mgmt tx queue is full\n");
  3202. return -ENOSPC;
  3203. }
  3204. skb_queue_tail(q, skb);
  3205. ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
  3206. return 0;
  3207. }
  3208. static enum ath10k_mac_tx_path
  3209. ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
  3210. struct sk_buff *skb,
  3211. enum ath10k_hw_txrx_mode txmode)
  3212. {
  3213. switch (txmode) {
  3214. case ATH10K_HW_TXRX_RAW:
  3215. case ATH10K_HW_TXRX_NATIVE_WIFI:
  3216. case ATH10K_HW_TXRX_ETHERNET:
  3217. return ATH10K_MAC_TX_HTT;
  3218. case ATH10K_HW_TXRX_MGMT:
  3219. if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
  3220. ar->running_fw->fw_file.fw_features) ||
  3221. test_bit(WMI_SERVICE_MGMT_TX_WMI,
  3222. ar->wmi.svc_map))
  3223. return ATH10K_MAC_TX_WMI_MGMT;
  3224. else if (ar->htt.target_version_major >= 3)
  3225. return ATH10K_MAC_TX_HTT;
  3226. else
  3227. return ATH10K_MAC_TX_HTT_MGMT;
  3228. }
  3229. return ATH10K_MAC_TX_UNKNOWN;
  3230. }
  3231. static int ath10k_mac_tx_submit(struct ath10k *ar,
  3232. enum ath10k_hw_txrx_mode txmode,
  3233. enum ath10k_mac_tx_path txpath,
  3234. struct sk_buff *skb)
  3235. {
  3236. struct ath10k_htt *htt = &ar->htt;
  3237. int ret = -EINVAL;
  3238. switch (txpath) {
  3239. case ATH10K_MAC_TX_HTT:
  3240. ret = ath10k_htt_tx(htt, txmode, skb);
  3241. break;
  3242. case ATH10K_MAC_TX_HTT_MGMT:
  3243. ret = ath10k_htt_mgmt_tx(htt, skb);
  3244. break;
  3245. case ATH10K_MAC_TX_WMI_MGMT:
  3246. ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
  3247. break;
  3248. case ATH10K_MAC_TX_UNKNOWN:
  3249. WARN_ON_ONCE(1);
  3250. ret = -EINVAL;
  3251. break;
  3252. }
  3253. if (ret) {
  3254. ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
  3255. ret);
  3256. ieee80211_free_txskb(ar->hw, skb);
  3257. }
  3258. return ret;
  3259. }
  3260. /* This function consumes the sk_buff regardless of return value as far as
  3261. * caller is concerned so no freeing is necessary afterwards.
  3262. */
  3263. static int ath10k_mac_tx(struct ath10k *ar,
  3264. struct ieee80211_vif *vif,
  3265. enum ath10k_hw_txrx_mode txmode,
  3266. enum ath10k_mac_tx_path txpath,
  3267. struct sk_buff *skb, bool noque_offchan)
  3268. {
  3269. struct ieee80211_hw *hw = ar->hw;
  3270. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  3271. const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
  3272. int ret;
  3273. /* We should disable CCK RATE due to P2P */
  3274. if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
  3275. ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
  3276. switch (txmode) {
  3277. case ATH10K_HW_TXRX_MGMT:
  3278. case ATH10K_HW_TXRX_NATIVE_WIFI:
  3279. ath10k_tx_h_nwifi(hw, skb);
  3280. ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
  3281. ath10k_tx_h_seq_no(vif, skb);
  3282. break;
  3283. case ATH10K_HW_TXRX_ETHERNET:
  3284. /* Convert 802.11->802.3 header only if the frame was earlier
  3285. * encapsulated to 802.11 by mac80211. Otherwise pass it as is.
  3286. */
  3287. if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP))
  3288. ath10k_tx_h_8023(skb);
  3289. break;
  3290. case ATH10K_HW_TXRX_RAW:
  3291. if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) &&
  3292. !(skb_cb->flags & ATH10K_SKB_F_RAW_TX)) {
  3293. WARN_ON_ONCE(1);
  3294. ieee80211_free_txskb(hw, skb);
  3295. return -ENOTSUPP;
  3296. }
  3297. }
  3298. if (!noque_offchan && info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
  3299. if (!ath10k_mac_tx_frm_has_freq(ar)) {
  3300. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac queued offchannel skb %pK len %d\n",
  3301. skb, skb->len);
  3302. skb_queue_tail(&ar->offchan_tx_queue, skb);
  3303. ieee80211_queue_work(hw, &ar->offchan_tx_work);
  3304. return 0;
  3305. }
  3306. }
  3307. ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
  3308. if (ret) {
  3309. ath10k_warn(ar, "failed to submit frame: %d\n", ret);
  3310. return ret;
  3311. }
  3312. return 0;
  3313. }
  3314. void ath10k_offchan_tx_purge(struct ath10k *ar)
  3315. {
  3316. struct sk_buff *skb;
  3317. for (;;) {
  3318. skb = skb_dequeue(&ar->offchan_tx_queue);
  3319. if (!skb)
  3320. break;
  3321. ieee80211_free_txskb(ar->hw, skb);
  3322. }
  3323. }
  3324. void ath10k_offchan_tx_work(struct work_struct *work)
  3325. {
  3326. struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
  3327. struct ath10k_peer *peer;
  3328. struct ath10k_vif *arvif;
  3329. enum ath10k_hw_txrx_mode txmode;
  3330. enum ath10k_mac_tx_path txpath;
  3331. struct ieee80211_hdr *hdr;
  3332. struct ieee80211_vif *vif;
  3333. struct ieee80211_sta *sta;
  3334. struct sk_buff *skb;
  3335. const u8 *peer_addr;
  3336. int vdev_id;
  3337. int ret;
  3338. unsigned long time_left;
  3339. bool tmp_peer_created = false;
  3340. /* FW requirement: We must create a peer before FW will send out
  3341. * an offchannel frame. Otherwise the frame will be stuck and
  3342. * never transmitted. We delete the peer upon tx completion.
  3343. * It is unlikely that a peer for offchannel tx will already be
  3344. * present. However it may be in some rare cases so account for that.
  3345. * Otherwise we might remove a legitimate peer and break stuff.
  3346. */
  3347. for (;;) {
  3348. skb = skb_dequeue(&ar->offchan_tx_queue);
  3349. if (!skb)
  3350. break;
  3351. mutex_lock(&ar->conf_mutex);
  3352. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK len %d\n",
  3353. skb, skb->len);
  3354. hdr = (struct ieee80211_hdr *)skb->data;
  3355. peer_addr = ieee80211_get_DA(hdr);
  3356. spin_lock_bh(&ar->data_lock);
  3357. vdev_id = ar->scan.vdev_id;
  3358. peer = ath10k_peer_find(ar, vdev_id, peer_addr);
  3359. spin_unlock_bh(&ar->data_lock);
  3360. if (peer) {
  3361. ath10k_warn(ar, "peer %pM on vdev %d already present\n",
  3362. peer_addr, vdev_id);
  3363. } else {
  3364. ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
  3365. peer_addr,
  3366. WMI_PEER_TYPE_DEFAULT);
  3367. if (ret)
  3368. ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
  3369. peer_addr, vdev_id, ret);
  3370. tmp_peer_created = (ret == 0);
  3371. }
  3372. spin_lock_bh(&ar->data_lock);
  3373. reinit_completion(&ar->offchan_tx_completed);
  3374. ar->offchan_tx_skb = skb;
  3375. spin_unlock_bh(&ar->data_lock);
  3376. /* It's safe to access vif and sta - conf_mutex guarantees that
  3377. * sta_state() and remove_interface() are locked exclusively
  3378. * out wrt to this offchannel worker.
  3379. */
  3380. arvif = ath10k_get_arvif(ar, vdev_id);
  3381. if (arvif) {
  3382. vif = arvif->vif;
  3383. sta = ieee80211_find_sta(vif, peer_addr);
  3384. } else {
  3385. vif = NULL;
  3386. sta = NULL;
  3387. }
  3388. txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
  3389. txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
  3390. ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, true);
  3391. if (ret) {
  3392. ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
  3393. ret);
  3394. /* not serious */
  3395. }
  3396. time_left =
  3397. wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
  3398. if (time_left == 0)
  3399. ath10k_warn(ar, "timed out waiting for offchannel skb %pK, len: %d\n",
  3400. skb, skb->len);
  3401. if (!peer && tmp_peer_created) {
  3402. ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
  3403. if (ret)
  3404. ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
  3405. peer_addr, vdev_id, ret);
  3406. }
  3407. mutex_unlock(&ar->conf_mutex);
  3408. }
  3409. }
  3410. void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
  3411. {
  3412. struct sk_buff *skb;
  3413. for (;;) {
  3414. skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
  3415. if (!skb)
  3416. break;
  3417. ieee80211_free_txskb(ar->hw, skb);
  3418. }
  3419. }
  3420. void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
  3421. {
  3422. struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
  3423. struct sk_buff *skb;
  3424. dma_addr_t paddr;
  3425. int ret;
  3426. for (;;) {
  3427. skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
  3428. if (!skb)
  3429. break;
  3430. if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF,
  3431. ar->running_fw->fw_file.fw_features)) {
  3432. paddr = dma_map_single(ar->dev, skb->data,
  3433. skb->len, DMA_TO_DEVICE);
  3434. if (dma_mapping_error(ar->dev, paddr)) {
  3435. ieee80211_free_txskb(ar->hw, skb);
  3436. continue;
  3437. }
  3438. ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr);
  3439. if (ret) {
  3440. ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n",
  3441. ret);
  3442. /* remove this msdu from idr tracking */
  3443. ath10k_wmi_cleanup_mgmt_tx_send(ar, skb);
  3444. dma_unmap_single(ar->dev, paddr, skb->len,
  3445. DMA_TO_DEVICE);
  3446. ieee80211_free_txskb(ar->hw, skb);
  3447. }
  3448. } else {
  3449. ret = ath10k_wmi_mgmt_tx(ar, skb);
  3450. if (ret) {
  3451. ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
  3452. ret);
  3453. ieee80211_free_txskb(ar->hw, skb);
  3454. }
  3455. }
  3456. }
  3457. }
  3458. static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
  3459. {
  3460. struct ath10k_txq *artxq;
  3461. if (!txq)
  3462. return;
  3463. artxq = (void *)txq->drv_priv;
  3464. INIT_LIST_HEAD(&artxq->list);
  3465. }
  3466. static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
  3467. {
  3468. struct ath10k_skb_cb *cb;
  3469. struct sk_buff *msdu;
  3470. int msdu_id;
  3471. if (!txq)
  3472. return;
  3473. spin_lock_bh(&ar->htt.tx_lock);
  3474. idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
  3475. cb = ATH10K_SKB_CB(msdu);
  3476. if (cb->txq == txq)
  3477. cb->txq = NULL;
  3478. }
  3479. spin_unlock_bh(&ar->htt.tx_lock);
  3480. }
  3481. struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
  3482. u16 peer_id,
  3483. u8 tid)
  3484. {
  3485. struct ath10k_peer *peer;
  3486. lockdep_assert_held(&ar->data_lock);
  3487. peer = ar->peer_map[peer_id];
  3488. if (!peer)
  3489. return NULL;
  3490. if (peer->removed)
  3491. return NULL;
  3492. if (peer->sta)
  3493. return peer->sta->txq[tid];
  3494. else if (peer->vif)
  3495. return peer->vif->txq;
  3496. else
  3497. return NULL;
  3498. }
  3499. static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
  3500. struct ieee80211_txq *txq)
  3501. {
  3502. struct ath10k *ar = hw->priv;
  3503. struct ath10k_txq *artxq = (void *)txq->drv_priv;
  3504. /* No need to get locks */
  3505. if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
  3506. return true;
  3507. if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
  3508. return true;
  3509. if (artxq->num_fw_queued < artxq->num_push_allowed)
  3510. return true;
  3511. return false;
  3512. }
  3513. /* Return estimated airtime in microsecond, which is calculated using last
  3514. * reported TX rate. This is just a rough estimation because host driver has no
  3515. * knowledge of the actual transmit rate, retries or aggregation. If actual
  3516. * airtime can be reported by firmware, then delta between estimated and actual
  3517. * airtime can be adjusted from deficit.
  3518. */
  3519. #define IEEE80211_ATF_OVERHEAD 100 /* IFS + some slot time */
  3520. #define IEEE80211_ATF_OVERHEAD_IFS 16 /* IFS only */
  3521. static u16 ath10k_mac_update_airtime(struct ath10k *ar,
  3522. struct ieee80211_txq *txq,
  3523. struct sk_buff *skb)
  3524. {
  3525. struct ath10k_sta *arsta;
  3526. u32 pktlen;
  3527. u16 airtime = 0;
  3528. if (!txq || !txq->sta)
  3529. return airtime;
  3530. if (test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
  3531. return airtime;
  3532. spin_lock_bh(&ar->data_lock);
  3533. arsta = (struct ath10k_sta *)txq->sta->drv_priv;
  3534. pktlen = skb->len + 38; /* Assume MAC header 30, SNAP 8 for most case */
  3535. if (arsta->last_tx_bitrate) {
  3536. /* airtime in us, last_tx_bitrate in 100kbps */
  3537. airtime = (pktlen * 8 * (1000 / 100))
  3538. / arsta->last_tx_bitrate;
  3539. /* overhead for media access time and IFS */
  3540. airtime += IEEE80211_ATF_OVERHEAD_IFS;
  3541. } else {
  3542. /* This is mostly for throttle excessive BC/MC frames, and the
  3543. * airtime/rate doesn't need be exact. Airtime of BC/MC frames
  3544. * in 2G get some discount, which helps prevent very low rate
  3545. * frames from being blocked for too long.
  3546. */
  3547. airtime = (pktlen * 8 * (1000 / 100)) / 60; /* 6M */
  3548. airtime += IEEE80211_ATF_OVERHEAD;
  3549. }
  3550. spin_unlock_bh(&ar->data_lock);
  3551. return airtime;
  3552. }
  3553. int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
  3554. struct ieee80211_txq *txq)
  3555. {
  3556. struct ath10k *ar = hw->priv;
  3557. struct ath10k_htt *htt = &ar->htt;
  3558. struct ath10k_txq *artxq = (void *)txq->drv_priv;
  3559. struct ieee80211_vif *vif = txq->vif;
  3560. struct ieee80211_sta *sta = txq->sta;
  3561. enum ath10k_hw_txrx_mode txmode;
  3562. enum ath10k_mac_tx_path txpath;
  3563. struct sk_buff *skb;
  3564. struct ieee80211_hdr *hdr;
  3565. size_t skb_len;
  3566. bool is_mgmt, is_presp;
  3567. int ret;
  3568. u16 airtime;
  3569. spin_lock_bh(&ar->htt.tx_lock);
  3570. ret = ath10k_htt_tx_inc_pending(htt);
  3571. spin_unlock_bh(&ar->htt.tx_lock);
  3572. if (ret)
  3573. return ret;
  3574. skb = ieee80211_tx_dequeue_ni(hw, txq);
  3575. if (!skb) {
  3576. spin_lock_bh(&ar->htt.tx_lock);
  3577. ath10k_htt_tx_dec_pending(htt);
  3578. spin_unlock_bh(&ar->htt.tx_lock);
  3579. return -ENOENT;
  3580. }
  3581. airtime = ath10k_mac_update_airtime(ar, txq, skb);
  3582. ath10k_mac_tx_h_fill_cb(ar, vif, txq, sta, skb, airtime);
  3583. skb_len = skb->len;
  3584. txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
  3585. txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
  3586. is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
  3587. if (is_mgmt) {
  3588. hdr = (struct ieee80211_hdr *)skb->data;
  3589. is_presp = ieee80211_is_probe_resp(hdr->frame_control);
  3590. spin_lock_bh(&ar->htt.tx_lock);
  3591. ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
  3592. if (ret) {
  3593. ath10k_htt_tx_dec_pending(htt);
  3594. spin_unlock_bh(&ar->htt.tx_lock);
  3595. return ret;
  3596. }
  3597. spin_unlock_bh(&ar->htt.tx_lock);
  3598. }
  3599. ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
  3600. if (unlikely(ret)) {
  3601. ath10k_warn(ar, "failed to push frame: %d\n", ret);
  3602. spin_lock_bh(&ar->htt.tx_lock);
  3603. ath10k_htt_tx_dec_pending(htt);
  3604. if (is_mgmt)
  3605. ath10k_htt_tx_mgmt_dec_pending(htt);
  3606. spin_unlock_bh(&ar->htt.tx_lock);
  3607. return ret;
  3608. }
  3609. spin_lock_bh(&ar->htt.tx_lock);
  3610. artxq->num_fw_queued++;
  3611. spin_unlock_bh(&ar->htt.tx_lock);
  3612. return skb_len;
  3613. }
  3614. static int ath10k_mac_schedule_txq(struct ieee80211_hw *hw, u32 ac)
  3615. {
  3616. struct ieee80211_txq *txq;
  3617. int ret = 0;
  3618. ieee80211_txq_schedule_start(hw, ac);
  3619. while ((txq = ieee80211_next_txq(hw, ac))) {
  3620. while (ath10k_mac_tx_can_push(hw, txq)) {
  3621. ret = ath10k_mac_tx_push_txq(hw, txq);
  3622. if (ret < 0)
  3623. break;
  3624. }
  3625. ieee80211_return_txq(hw, txq, false);
  3626. ath10k_htt_tx_txq_update(hw, txq);
  3627. if (ret == -EBUSY)
  3628. break;
  3629. }
  3630. ieee80211_txq_schedule_end(hw, ac);
  3631. return ret;
  3632. }
  3633. void ath10k_mac_tx_push_pending(struct ath10k *ar)
  3634. {
  3635. struct ieee80211_hw *hw = ar->hw;
  3636. u32 ac;
  3637. if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH)
  3638. return;
  3639. if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
  3640. return;
  3641. rcu_read_lock();
  3642. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  3643. if (ath10k_mac_schedule_txq(hw, ac) == -EBUSY)
  3644. break;
  3645. }
  3646. rcu_read_unlock();
  3647. }
  3648. EXPORT_SYMBOL(ath10k_mac_tx_push_pending);
  3649. /************/
  3650. /* Scanning */
  3651. /************/
  3652. void __ath10k_scan_finish(struct ath10k *ar)
  3653. {
  3654. lockdep_assert_held(&ar->data_lock);
  3655. switch (ar->scan.state) {
  3656. case ATH10K_SCAN_IDLE:
  3657. break;
  3658. case ATH10K_SCAN_RUNNING:
  3659. case ATH10K_SCAN_ABORTING:
  3660. if (!ar->scan.is_roc) {
  3661. struct cfg80211_scan_info info = {
  3662. .aborted = (ar->scan.state ==
  3663. ATH10K_SCAN_ABORTING),
  3664. };
  3665. ieee80211_scan_completed(ar->hw, &info);
  3666. } else if (ar->scan.roc_notify) {
  3667. ieee80211_remain_on_channel_expired(ar->hw);
  3668. }
  3669. fallthrough;
  3670. case ATH10K_SCAN_STARTING:
  3671. ar->scan.state = ATH10K_SCAN_IDLE;
  3672. ar->scan_channel = NULL;
  3673. ar->scan.roc_freq = 0;
  3674. ath10k_offchan_tx_purge(ar);
  3675. cancel_delayed_work(&ar->scan.timeout);
  3676. complete(&ar->scan.completed);
  3677. break;
  3678. }
  3679. }
  3680. void ath10k_scan_finish(struct ath10k *ar)
  3681. {
  3682. spin_lock_bh(&ar->data_lock);
  3683. __ath10k_scan_finish(ar);
  3684. spin_unlock_bh(&ar->data_lock);
  3685. }
  3686. static int ath10k_scan_stop(struct ath10k *ar)
  3687. {
  3688. struct wmi_stop_scan_arg arg = {
  3689. .req_id = 1, /* FIXME */
  3690. .req_type = WMI_SCAN_STOP_ONE,
  3691. .u.scan_id = ATH10K_SCAN_ID,
  3692. };
  3693. int ret;
  3694. lockdep_assert_held(&ar->conf_mutex);
  3695. ret = ath10k_wmi_stop_scan(ar, &arg);
  3696. if (ret) {
  3697. ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
  3698. goto out;
  3699. }
  3700. ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
  3701. if (ret == 0) {
  3702. ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
  3703. ret = -ETIMEDOUT;
  3704. } else if (ret > 0) {
  3705. ret = 0;
  3706. }
  3707. out:
  3708. /* Scan state should be updated upon scan completion but in case
  3709. * firmware fails to deliver the event (for whatever reason) it is
  3710. * desired to clean up scan state anyway. Firmware may have just
  3711. * dropped the scan completion event delivery due to transport pipe
  3712. * being overflown with data and/or it can recover on its own before
  3713. * next scan request is submitted.
  3714. */
  3715. spin_lock_bh(&ar->data_lock);
  3716. if (ar->scan.state != ATH10K_SCAN_IDLE)
  3717. __ath10k_scan_finish(ar);
  3718. spin_unlock_bh(&ar->data_lock);
  3719. return ret;
  3720. }
  3721. static void ath10k_scan_abort(struct ath10k *ar)
  3722. {
  3723. int ret;
  3724. lockdep_assert_held(&ar->conf_mutex);
  3725. spin_lock_bh(&ar->data_lock);
  3726. switch (ar->scan.state) {
  3727. case ATH10K_SCAN_IDLE:
  3728. /* This can happen if timeout worker kicked in and called
  3729. * abortion while scan completion was being processed.
  3730. */
  3731. break;
  3732. case ATH10K_SCAN_STARTING:
  3733. case ATH10K_SCAN_ABORTING:
  3734. ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
  3735. ath10k_scan_state_str(ar->scan.state),
  3736. ar->scan.state);
  3737. break;
  3738. case ATH10K_SCAN_RUNNING:
  3739. ar->scan.state = ATH10K_SCAN_ABORTING;
  3740. spin_unlock_bh(&ar->data_lock);
  3741. ret = ath10k_scan_stop(ar);
  3742. if (ret)
  3743. ath10k_warn(ar, "failed to abort scan: %d\n", ret);
  3744. spin_lock_bh(&ar->data_lock);
  3745. break;
  3746. }
  3747. spin_unlock_bh(&ar->data_lock);
  3748. }
  3749. void ath10k_scan_timeout_work(struct work_struct *work)
  3750. {
  3751. struct ath10k *ar = container_of(work, struct ath10k,
  3752. scan.timeout.work);
  3753. mutex_lock(&ar->conf_mutex);
  3754. ath10k_scan_abort(ar);
  3755. mutex_unlock(&ar->conf_mutex);
  3756. }
  3757. static int ath10k_start_scan(struct ath10k *ar,
  3758. const struct wmi_start_scan_arg *arg)
  3759. {
  3760. int ret;
  3761. lockdep_assert_held(&ar->conf_mutex);
  3762. ret = ath10k_wmi_start_scan(ar, arg);
  3763. if (ret)
  3764. return ret;
  3765. ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
  3766. if (ret == 0) {
  3767. ret = ath10k_scan_stop(ar);
  3768. if (ret)
  3769. ath10k_warn(ar, "failed to stop scan: %d\n", ret);
  3770. return -ETIMEDOUT;
  3771. }
  3772. /* If we failed to start the scan, return error code at
  3773. * this point. This is probably due to some issue in the
  3774. * firmware, but no need to wedge the driver due to that...
  3775. */
  3776. spin_lock_bh(&ar->data_lock);
  3777. if (ar->scan.state == ATH10K_SCAN_IDLE) {
  3778. spin_unlock_bh(&ar->data_lock);
  3779. return -EINVAL;
  3780. }
  3781. spin_unlock_bh(&ar->data_lock);
  3782. return 0;
  3783. }
  3784. /**********************/
  3785. /* mac80211 callbacks */
  3786. /**********************/
  3787. static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
  3788. struct ieee80211_tx_control *control,
  3789. struct sk_buff *skb)
  3790. {
  3791. struct ath10k *ar = hw->priv;
  3792. struct ath10k_htt *htt = &ar->htt;
  3793. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  3794. struct ieee80211_vif *vif = info->control.vif;
  3795. struct ieee80211_sta *sta = control->sta;
  3796. struct ieee80211_txq *txq = NULL;
  3797. enum ath10k_hw_txrx_mode txmode;
  3798. enum ath10k_mac_tx_path txpath;
  3799. bool is_htt;
  3800. bool is_mgmt;
  3801. int ret;
  3802. u16 airtime;
  3803. airtime = ath10k_mac_update_airtime(ar, txq, skb);
  3804. ath10k_mac_tx_h_fill_cb(ar, vif, txq, sta, skb, airtime);
  3805. txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
  3806. txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
  3807. is_htt = (txpath == ATH10K_MAC_TX_HTT ||
  3808. txpath == ATH10K_MAC_TX_HTT_MGMT);
  3809. is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
  3810. if (is_htt) {
  3811. bool is_presp = false;
  3812. spin_lock_bh(&ar->htt.tx_lock);
  3813. if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) {
  3814. struct ieee80211_hdr *hdr = (void *)skb->data;
  3815. is_presp = ieee80211_is_probe_resp(hdr->frame_control);
  3816. }
  3817. ret = ath10k_htt_tx_inc_pending(htt);
  3818. if (ret) {
  3819. ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
  3820. ret);
  3821. spin_unlock_bh(&ar->htt.tx_lock);
  3822. ieee80211_free_txskb(ar->hw, skb);
  3823. return;
  3824. }
  3825. ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
  3826. if (ret) {
  3827. ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
  3828. ret);
  3829. ath10k_htt_tx_dec_pending(htt);
  3830. spin_unlock_bh(&ar->htt.tx_lock);
  3831. ieee80211_free_txskb(ar->hw, skb);
  3832. return;
  3833. }
  3834. spin_unlock_bh(&ar->htt.tx_lock);
  3835. }
  3836. ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
  3837. if (ret) {
  3838. ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
  3839. if (is_htt) {
  3840. spin_lock_bh(&ar->htt.tx_lock);
  3841. ath10k_htt_tx_dec_pending(htt);
  3842. if (is_mgmt)
  3843. ath10k_htt_tx_mgmt_dec_pending(htt);
  3844. spin_unlock_bh(&ar->htt.tx_lock);
  3845. }
  3846. return;
  3847. }
  3848. }
  3849. static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
  3850. struct ieee80211_txq *txq)
  3851. {
  3852. struct ath10k *ar = hw->priv;
  3853. int ret;
  3854. u8 ac = txq->ac;
  3855. ath10k_htt_tx_txq_update(hw, txq);
  3856. if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH)
  3857. return;
  3858. spin_lock_bh(&ar->queue_lock[ac]);
  3859. ieee80211_txq_schedule_start(hw, ac);
  3860. txq = ieee80211_next_txq(hw, ac);
  3861. if (!txq)
  3862. goto out;
  3863. while (ath10k_mac_tx_can_push(hw, txq)) {
  3864. ret = ath10k_mac_tx_push_txq(hw, txq);
  3865. if (ret < 0)
  3866. break;
  3867. }
  3868. ieee80211_return_txq(hw, txq, false);
  3869. ath10k_htt_tx_txq_update(hw, txq);
  3870. out:
  3871. ieee80211_txq_schedule_end(hw, ac);
  3872. spin_unlock_bh(&ar->queue_lock[ac]);
  3873. }
  3874. /* Must not be called with conf_mutex held as workers can use that also. */
  3875. void ath10k_drain_tx(struct ath10k *ar)
  3876. {
  3877. lockdep_assert_not_held(&ar->conf_mutex);
  3878. /* make sure rcu-protected mac80211 tx path itself is drained */
  3879. synchronize_net();
  3880. ath10k_offchan_tx_purge(ar);
  3881. ath10k_mgmt_over_wmi_tx_purge(ar);
  3882. cancel_work_sync(&ar->offchan_tx_work);
  3883. cancel_work_sync(&ar->wmi_mgmt_tx_work);
  3884. }
  3885. void ath10k_halt(struct ath10k *ar)
  3886. {
  3887. struct ath10k_vif *arvif;
  3888. lockdep_assert_held(&ar->conf_mutex);
  3889. clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  3890. ar->filter_flags = 0;
  3891. ar->monitor = false;
  3892. ar->monitor_arvif = NULL;
  3893. if (ar->monitor_started)
  3894. ath10k_monitor_stop(ar);
  3895. ar->monitor_started = false;
  3896. ar->tx_paused = 0;
  3897. ath10k_scan_finish(ar);
  3898. ath10k_peer_cleanup_all(ar);
  3899. ath10k_stop_radar_confirmation(ar);
  3900. ath10k_core_stop(ar);
  3901. ath10k_hif_power_down(ar);
  3902. spin_lock_bh(&ar->data_lock);
  3903. list_for_each_entry(arvif, &ar->arvifs, list)
  3904. ath10k_mac_vif_beacon_cleanup(arvif);
  3905. spin_unlock_bh(&ar->data_lock);
  3906. }
  3907. static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  3908. {
  3909. struct ath10k *ar = hw->priv;
  3910. mutex_lock(&ar->conf_mutex);
  3911. *tx_ant = ar->cfg_tx_chainmask;
  3912. *rx_ant = ar->cfg_rx_chainmask;
  3913. mutex_unlock(&ar->conf_mutex);
  3914. return 0;
  3915. }
  3916. static bool ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
  3917. {
  3918. /* It is not clear that allowing gaps in chainmask
  3919. * is helpful. Probably it will not do what user
  3920. * is hoping for, so warn in that case.
  3921. */
  3922. if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
  3923. return true;
  3924. ath10k_warn(ar, "mac %s antenna chainmask is invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
  3925. dbg, cm);
  3926. return false;
  3927. }
  3928. static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
  3929. {
  3930. int nsts = ar->vht_cap_info;
  3931. nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
  3932. nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
  3933. /* If firmware does not deliver to host number of space-time
  3934. * streams supported, assume it support up to 4 BF STS and return
  3935. * the value for VHT CAP: nsts-1)
  3936. */
  3937. if (nsts == 0)
  3938. return 3;
  3939. return nsts;
  3940. }
  3941. static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
  3942. {
  3943. int sound_dim = ar->vht_cap_info;
  3944. sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
  3945. sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
  3946. /* If the sounding dimension is not advertised by the firmware,
  3947. * let's use a default value of 1
  3948. */
  3949. if (sound_dim == 0)
  3950. return 1;
  3951. return sound_dim;
  3952. }
  3953. static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
  3954. {
  3955. struct ieee80211_sta_vht_cap vht_cap = {0};
  3956. struct ath10k_hw_params *hw = &ar->hw_params;
  3957. u16 mcs_map;
  3958. u32 val;
  3959. int i;
  3960. vht_cap.vht_supported = 1;
  3961. vht_cap.cap = ar->vht_cap_info;
  3962. if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  3963. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
  3964. val = ath10k_mac_get_vht_cap_bf_sts(ar);
  3965. val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
  3966. val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
  3967. vht_cap.cap |= val;
  3968. }
  3969. if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  3970. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
  3971. val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
  3972. val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
  3973. val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
  3974. vht_cap.cap |= val;
  3975. }
  3976. mcs_map = 0;
  3977. for (i = 0; i < 8; i++) {
  3978. if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
  3979. mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
  3980. else
  3981. mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
  3982. }
  3983. if (ar->cfg_tx_chainmask <= 1)
  3984. vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
  3985. vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  3986. vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  3987. /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
  3988. * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
  3989. * user-space a clue if that is the case.
  3990. */
  3991. if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) &&
  3992. (hw->vht160_mcs_rx_highest != 0 ||
  3993. hw->vht160_mcs_tx_highest != 0)) {
  3994. vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest);
  3995. vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest);
  3996. }
  3997. return vht_cap;
  3998. }
  3999. static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
  4000. {
  4001. int i;
  4002. struct ieee80211_sta_ht_cap ht_cap = {0};
  4003. if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
  4004. return ht_cap;
  4005. ht_cap.ht_supported = 1;
  4006. ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  4007. ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  4008. ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  4009. ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
  4010. ht_cap.cap |=
  4011. WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
  4012. if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
  4013. ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  4014. if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
  4015. ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  4016. if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
  4017. u32 smps;
  4018. smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
  4019. smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
  4020. ht_cap.cap |= smps;
  4021. }
  4022. if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
  4023. ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  4024. if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
  4025. u32 stbc;
  4026. stbc = ar->ht_cap_info;
  4027. stbc &= WMI_HT_CAP_RX_STBC;
  4028. stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
  4029. stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
  4030. stbc &= IEEE80211_HT_CAP_RX_STBC;
  4031. ht_cap.cap |= stbc;
  4032. }
  4033. if (ar->ht_cap_info & WMI_HT_CAP_LDPC || (ar->ht_cap_info &
  4034. WMI_HT_CAP_RX_LDPC && (ar->ht_cap_info & WMI_HT_CAP_TX_LDPC)))
  4035. ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
  4036. if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
  4037. ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
  4038. /* max AMSDU is implicitly taken from vht_cap_info */
  4039. if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
  4040. ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  4041. for (i = 0; i < ar->num_rf_chains; i++) {
  4042. if (ar->cfg_rx_chainmask & BIT(i))
  4043. ht_cap.mcs.rx_mask[i] = 0xFF;
  4044. }
  4045. ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  4046. return ht_cap;
  4047. }
  4048. static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
  4049. {
  4050. struct ieee80211_supported_band *band;
  4051. struct ieee80211_sta_vht_cap vht_cap;
  4052. struct ieee80211_sta_ht_cap ht_cap;
  4053. ht_cap = ath10k_get_ht_cap(ar);
  4054. vht_cap = ath10k_create_vht_cap(ar);
  4055. if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
  4056. band = &ar->mac.sbands[NL80211_BAND_2GHZ];
  4057. band->ht_cap = ht_cap;
  4058. }
  4059. if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
  4060. band = &ar->mac.sbands[NL80211_BAND_5GHZ];
  4061. band->ht_cap = ht_cap;
  4062. band->vht_cap = vht_cap;
  4063. }
  4064. }
  4065. static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
  4066. {
  4067. int ret;
  4068. bool is_valid_tx_chain_mask, is_valid_rx_chain_mask;
  4069. lockdep_assert_held(&ar->conf_mutex);
  4070. is_valid_tx_chain_mask = ath10k_check_chain_mask(ar, tx_ant, "tx");
  4071. is_valid_rx_chain_mask = ath10k_check_chain_mask(ar, rx_ant, "rx");
  4072. if (!is_valid_tx_chain_mask || !is_valid_rx_chain_mask)
  4073. return -EINVAL;
  4074. ar->cfg_tx_chainmask = tx_ant;
  4075. ar->cfg_rx_chainmask = rx_ant;
  4076. if ((ar->state != ATH10K_STATE_ON) &&
  4077. (ar->state != ATH10K_STATE_RESTARTED))
  4078. return 0;
  4079. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
  4080. tx_ant);
  4081. if (ret) {
  4082. ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
  4083. ret, tx_ant);
  4084. return ret;
  4085. }
  4086. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
  4087. rx_ant);
  4088. if (ret) {
  4089. ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
  4090. ret, rx_ant);
  4091. return ret;
  4092. }
  4093. /* Reload HT/VHT capability */
  4094. ath10k_mac_setup_ht_vht_cap(ar);
  4095. return 0;
  4096. }
  4097. static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  4098. {
  4099. struct ath10k *ar = hw->priv;
  4100. int ret;
  4101. mutex_lock(&ar->conf_mutex);
  4102. ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
  4103. mutex_unlock(&ar->conf_mutex);
  4104. return ret;
  4105. }
  4106. static int __ath10k_fetch_bb_timing_dt(struct ath10k *ar,
  4107. struct wmi_bb_timing_cfg_arg *bb_timing)
  4108. {
  4109. struct device_node *node;
  4110. const char *fem_name;
  4111. int ret;
  4112. node = ar->dev->of_node;
  4113. if (!node)
  4114. return -ENOENT;
  4115. ret = of_property_read_string_index(node, "ext-fem-name", 0, &fem_name);
  4116. if (ret)
  4117. return -ENOENT;
  4118. /*
  4119. * If external Front End module used in hardware, then default base band timing
  4120. * parameter cannot be used since they were fine tuned for reference hardware,
  4121. * so choosing different value suitable for that external FEM.
  4122. */
  4123. if (!strcmp("microsemi-lx5586", fem_name)) {
  4124. bb_timing->bb_tx_timing = 0x00;
  4125. bb_timing->bb_xpa_timing = 0x0101;
  4126. } else {
  4127. return -ENOENT;
  4128. }
  4129. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot bb_tx_timing 0x%x bb_xpa_timing 0x%x\n",
  4130. bb_timing->bb_tx_timing, bb_timing->bb_xpa_timing);
  4131. return 0;
  4132. }
  4133. static int ath10k_mac_rfkill_config(struct ath10k *ar)
  4134. {
  4135. u32 param;
  4136. int ret;
  4137. if (ar->hw_values->rfkill_pin == 0) {
  4138. ath10k_warn(ar, "ath10k does not support hardware rfkill with this device\n");
  4139. return -EOPNOTSUPP;
  4140. }
  4141. ath10k_dbg(ar, ATH10K_DBG_MAC,
  4142. "mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d",
  4143. ar->hw_values->rfkill_pin, ar->hw_values->rfkill_cfg,
  4144. ar->hw_values->rfkill_on_level);
  4145. param = FIELD_PREP(WMI_TLV_RFKILL_CFG_RADIO_LEVEL,
  4146. ar->hw_values->rfkill_on_level) |
  4147. FIELD_PREP(WMI_TLV_RFKILL_CFG_GPIO_PIN_NUM,
  4148. ar->hw_values->rfkill_pin) |
  4149. FIELD_PREP(WMI_TLV_RFKILL_CFG_PIN_AS_GPIO,
  4150. ar->hw_values->rfkill_cfg);
  4151. ret = ath10k_wmi_pdev_set_param(ar,
  4152. ar->wmi.pdev_param->rfkill_config,
  4153. param);
  4154. if (ret) {
  4155. ath10k_warn(ar,
  4156. "failed to set rfkill config 0x%x: %d\n",
  4157. param, ret);
  4158. return ret;
  4159. }
  4160. return 0;
  4161. }
  4162. int ath10k_mac_rfkill_enable_radio(struct ath10k *ar, bool enable)
  4163. {
  4164. enum wmi_tlv_rfkill_enable_radio param;
  4165. int ret;
  4166. if (enable)
  4167. param = WMI_TLV_RFKILL_ENABLE_RADIO_ON;
  4168. else
  4169. param = WMI_TLV_RFKILL_ENABLE_RADIO_OFF;
  4170. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac rfkill enable %d", param);
  4171. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rfkill_enable,
  4172. param);
  4173. if (ret) {
  4174. ath10k_warn(ar, "failed to set rfkill enable param %d: %d\n",
  4175. param, ret);
  4176. return ret;
  4177. }
  4178. return 0;
  4179. }
  4180. static int ath10k_start(struct ieee80211_hw *hw)
  4181. {
  4182. struct ath10k *ar = hw->priv;
  4183. u32 param;
  4184. int ret = 0;
  4185. struct wmi_bb_timing_cfg_arg bb_timing = {0};
  4186. /*
  4187. * This makes sense only when restarting hw. It is harmless to call
  4188. * unconditionally. This is necessary to make sure no HTT/WMI tx
  4189. * commands will be submitted while restarting.
  4190. */
  4191. ath10k_drain_tx(ar);
  4192. mutex_lock(&ar->conf_mutex);
  4193. switch (ar->state) {
  4194. case ATH10K_STATE_OFF:
  4195. ar->state = ATH10K_STATE_ON;
  4196. break;
  4197. case ATH10K_STATE_RESTARTING:
  4198. ar->state = ATH10K_STATE_RESTARTED;
  4199. break;
  4200. case ATH10K_STATE_ON:
  4201. case ATH10K_STATE_RESTARTED:
  4202. case ATH10K_STATE_WEDGED:
  4203. WARN_ON(1);
  4204. ret = -EINVAL;
  4205. goto err;
  4206. case ATH10K_STATE_UTF:
  4207. ret = -EBUSY;
  4208. goto err;
  4209. }
  4210. spin_lock_bh(&ar->data_lock);
  4211. if (ar->hw_rfkill_on) {
  4212. ar->hw_rfkill_on = false;
  4213. spin_unlock_bh(&ar->data_lock);
  4214. goto err;
  4215. }
  4216. spin_unlock_bh(&ar->data_lock);
  4217. ret = ath10k_hif_power_up(ar, ATH10K_FIRMWARE_MODE_NORMAL);
  4218. if (ret) {
  4219. ath10k_err(ar, "Could not init hif: %d\n", ret);
  4220. goto err_off;
  4221. }
  4222. ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
  4223. &ar->normal_mode_fw);
  4224. if (ret) {
  4225. ath10k_err(ar, "Could not init core: %d\n", ret);
  4226. goto err_power_down;
  4227. }
  4228. if (ar->sys_cap_info & WMI_TLV_SYS_CAP_INFO_RFKILL) {
  4229. ret = ath10k_mac_rfkill_config(ar);
  4230. if (ret && ret != -EOPNOTSUPP) {
  4231. ath10k_warn(ar, "failed to configure rfkill: %d", ret);
  4232. goto err_core_stop;
  4233. }
  4234. }
  4235. param = ar->wmi.pdev_param->pmf_qos;
  4236. ret = ath10k_wmi_pdev_set_param(ar, param, 1);
  4237. if (ret) {
  4238. ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
  4239. goto err_core_stop;
  4240. }
  4241. param = ar->wmi.pdev_param->dynamic_bw;
  4242. ret = ath10k_wmi_pdev_set_param(ar, param, 1);
  4243. if (ret) {
  4244. ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
  4245. goto err_core_stop;
  4246. }
  4247. if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
  4248. ret = ath10k_wmi_scan_prob_req_oui(ar, ar->mac_addr);
  4249. if (ret) {
  4250. ath10k_err(ar, "failed to set prob req oui: %i\n", ret);
  4251. goto err_core_stop;
  4252. }
  4253. }
  4254. if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
  4255. ret = ath10k_wmi_adaptive_qcs(ar, true);
  4256. if (ret) {
  4257. ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
  4258. ret);
  4259. goto err_core_stop;
  4260. }
  4261. }
  4262. if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
  4263. param = ar->wmi.pdev_param->burst_enable;
  4264. ret = ath10k_wmi_pdev_set_param(ar, param, 0);
  4265. if (ret) {
  4266. ath10k_warn(ar, "failed to disable burst: %d\n", ret);
  4267. goto err_core_stop;
  4268. }
  4269. }
  4270. param = ar->wmi.pdev_param->idle_ps_config;
  4271. ret = ath10k_wmi_pdev_set_param(ar, param, 1);
  4272. if (ret && ret != -EOPNOTSUPP) {
  4273. ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret);
  4274. goto err_core_stop;
  4275. }
  4276. __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
  4277. /*
  4278. * By default FW set ARP frames ac to voice (6). In that case ARP
  4279. * exchange is not working properly for UAPSD enabled AP. ARP requests
  4280. * which arrives with access category 0 are processed by network stack
  4281. * and send back with access category 0, but FW changes access category
  4282. * to 6. Set ARP frames access category to best effort (0) solves
  4283. * this problem.
  4284. */
  4285. param = ar->wmi.pdev_param->arp_ac_override;
  4286. ret = ath10k_wmi_pdev_set_param(ar, param, 0);
  4287. if (ret) {
  4288. ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
  4289. ret);
  4290. goto err_core_stop;
  4291. }
  4292. if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
  4293. ar->running_fw->fw_file.fw_features)) {
  4294. ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
  4295. WMI_CCA_DETECT_LEVEL_AUTO,
  4296. WMI_CCA_DETECT_MARGIN_AUTO);
  4297. if (ret) {
  4298. ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
  4299. ret);
  4300. goto err_core_stop;
  4301. }
  4302. }
  4303. param = ar->wmi.pdev_param->ani_enable;
  4304. ret = ath10k_wmi_pdev_set_param(ar, param, 1);
  4305. if (ret) {
  4306. ath10k_warn(ar, "failed to enable ani by default: %d\n",
  4307. ret);
  4308. goto err_core_stop;
  4309. }
  4310. ar->ani_enabled = true;
  4311. if (ath10k_peer_stats_enabled(ar)) {
  4312. param = ar->wmi.pdev_param->peer_stats_update_period;
  4313. ret = ath10k_wmi_pdev_set_param(ar, param,
  4314. PEER_DEFAULT_STATS_UPDATE_PERIOD);
  4315. if (ret) {
  4316. ath10k_warn(ar,
  4317. "failed to set peer stats period : %d\n",
  4318. ret);
  4319. goto err_core_stop;
  4320. }
  4321. }
  4322. param = ar->wmi.pdev_param->enable_btcoex;
  4323. if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
  4324. test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
  4325. ar->running_fw->fw_file.fw_features) &&
  4326. ar->coex_support) {
  4327. ret = ath10k_wmi_pdev_set_param(ar, param, 0);
  4328. if (ret) {
  4329. ath10k_warn(ar,
  4330. "failed to set btcoex param: %d\n", ret);
  4331. goto err_core_stop;
  4332. }
  4333. clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
  4334. }
  4335. if (test_bit(WMI_SERVICE_BB_TIMING_CONFIG_SUPPORT, ar->wmi.svc_map)) {
  4336. ret = __ath10k_fetch_bb_timing_dt(ar, &bb_timing);
  4337. if (!ret) {
  4338. ret = ath10k_wmi_pdev_bb_timing(ar, &bb_timing);
  4339. if (ret) {
  4340. ath10k_warn(ar,
  4341. "failed to set bb timings: %d\n",
  4342. ret);
  4343. goto err_core_stop;
  4344. }
  4345. }
  4346. }
  4347. ar->num_started_vdevs = 0;
  4348. ath10k_regd_update(ar);
  4349. ath10k_spectral_start(ar);
  4350. ath10k_thermal_set_throttling(ar);
  4351. ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE;
  4352. mutex_unlock(&ar->conf_mutex);
  4353. return 0;
  4354. err_core_stop:
  4355. ath10k_core_stop(ar);
  4356. err_power_down:
  4357. ath10k_hif_power_down(ar);
  4358. err_off:
  4359. ar->state = ATH10K_STATE_OFF;
  4360. err:
  4361. mutex_unlock(&ar->conf_mutex);
  4362. return ret;
  4363. }
  4364. static void ath10k_stop(struct ieee80211_hw *hw)
  4365. {
  4366. struct ath10k *ar = hw->priv;
  4367. u32 opt;
  4368. ath10k_drain_tx(ar);
  4369. mutex_lock(&ar->conf_mutex);
  4370. if (ar->state != ATH10K_STATE_OFF) {
  4371. if (!ar->hw_rfkill_on) {
  4372. /* If the current driver state is RESTARTING but not yet
  4373. * fully RESTARTED because of incoming suspend event,
  4374. * then ath10k_halt() is already called via
  4375. * ath10k_core_restart() and should not be called here.
  4376. */
  4377. if (ar->state != ATH10K_STATE_RESTARTING) {
  4378. ath10k_halt(ar);
  4379. } else {
  4380. /* Suspending here, because when in RESTARTING
  4381. * state, ath10k_core_stop() skips
  4382. * ath10k_wait_for_suspend().
  4383. */
  4384. opt = WMI_PDEV_SUSPEND_AND_DISABLE_INTR;
  4385. ath10k_wait_for_suspend(ar, opt);
  4386. }
  4387. }
  4388. ar->state = ATH10K_STATE_OFF;
  4389. }
  4390. mutex_unlock(&ar->conf_mutex);
  4391. cancel_work_sync(&ar->set_coverage_class_work);
  4392. cancel_delayed_work_sync(&ar->scan.timeout);
  4393. cancel_work_sync(&ar->restart_work);
  4394. }
  4395. static int ath10k_config_ps(struct ath10k *ar)
  4396. {
  4397. struct ath10k_vif *arvif;
  4398. int ret = 0;
  4399. lockdep_assert_held(&ar->conf_mutex);
  4400. list_for_each_entry(arvif, &ar->arvifs, list) {
  4401. ret = ath10k_mac_vif_setup_ps(arvif);
  4402. if (ret) {
  4403. ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
  4404. break;
  4405. }
  4406. }
  4407. return ret;
  4408. }
  4409. static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
  4410. {
  4411. struct ath10k *ar = hw->priv;
  4412. struct ieee80211_conf *conf = &hw->conf;
  4413. int ret = 0;
  4414. mutex_lock(&ar->conf_mutex);
  4415. if (changed & IEEE80211_CONF_CHANGE_PS)
  4416. ath10k_config_ps(ar);
  4417. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  4418. ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
  4419. ret = ath10k_monitor_recalc(ar);
  4420. if (ret)
  4421. ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
  4422. }
  4423. mutex_unlock(&ar->conf_mutex);
  4424. return ret;
  4425. }
  4426. static u32 get_nss_from_chainmask(u16 chain_mask)
  4427. {
  4428. if ((chain_mask & 0xf) == 0xf)
  4429. return 4;
  4430. else if ((chain_mask & 0x7) == 0x7)
  4431. return 3;
  4432. else if ((chain_mask & 0x3) == 0x3)
  4433. return 2;
  4434. return 1;
  4435. }
  4436. static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
  4437. {
  4438. u32 value = 0;
  4439. struct ath10k *ar = arvif->ar;
  4440. int nsts;
  4441. int sound_dim;
  4442. if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
  4443. return 0;
  4444. nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
  4445. if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  4446. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
  4447. value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
  4448. sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
  4449. if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  4450. IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
  4451. value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
  4452. if (!value)
  4453. return 0;
  4454. if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
  4455. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
  4456. if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
  4457. value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
  4458. WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
  4459. if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
  4460. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
  4461. if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
  4462. value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
  4463. WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
  4464. return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  4465. ar->wmi.vdev_param->txbf, value);
  4466. }
  4467. static void ath10k_update_vif_offload(struct ieee80211_hw *hw,
  4468. struct ieee80211_vif *vif)
  4469. {
  4470. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  4471. struct ath10k *ar = hw->priv;
  4472. u32 vdev_param;
  4473. int ret;
  4474. if (ath10k_frame_mode != ATH10K_HW_TXRX_ETHERNET ||
  4475. ar->wmi.vdev_param->tx_encap_type == WMI_VDEV_PARAM_UNSUPPORTED ||
  4476. (vif->type != NL80211_IFTYPE_STATION &&
  4477. vif->type != NL80211_IFTYPE_AP))
  4478. vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
  4479. vdev_param = ar->wmi.vdev_param->tx_encap_type;
  4480. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  4481. ATH10K_HW_TXRX_NATIVE_WIFI);
  4482. /* 10.X firmware does not support this VDEV parameter. Do not warn */
  4483. if (ret && ret != -EOPNOTSUPP) {
  4484. ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
  4485. arvif->vdev_id, ret);
  4486. }
  4487. }
  4488. /*
  4489. * TODO:
  4490. * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
  4491. * because we will send mgmt frames without CCK. This requirement
  4492. * for P2P_FIND/GO_NEG should be handled by checking CCK flag
  4493. * in the TX packet.
  4494. */
  4495. static int ath10k_add_interface(struct ieee80211_hw *hw,
  4496. struct ieee80211_vif *vif)
  4497. {
  4498. struct ath10k *ar = hw->priv;
  4499. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  4500. struct ath10k_peer *peer;
  4501. enum wmi_sta_powersave_param param;
  4502. int ret = 0;
  4503. u32 value;
  4504. int bit;
  4505. int i;
  4506. u32 vdev_param;
  4507. vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
  4508. mutex_lock(&ar->conf_mutex);
  4509. memset(arvif, 0, sizeof(*arvif));
  4510. ath10k_mac_txq_init(vif->txq);
  4511. arvif->ar = ar;
  4512. arvif->vif = vif;
  4513. INIT_LIST_HEAD(&arvif->list);
  4514. INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
  4515. INIT_DELAYED_WORK(&arvif->connection_loss_work,
  4516. ath10k_mac_vif_sta_connection_loss_work);
  4517. for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
  4518. arvif->bitrate_mask.control[i].legacy = 0xffffffff;
  4519. memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
  4520. sizeof(arvif->bitrate_mask.control[i].ht_mcs));
  4521. memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
  4522. sizeof(arvif->bitrate_mask.control[i].vht_mcs));
  4523. }
  4524. if (ar->num_peers >= ar->max_num_peers) {
  4525. ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
  4526. ret = -ENOBUFS;
  4527. goto err;
  4528. }
  4529. if (ar->free_vdev_map == 0) {
  4530. ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
  4531. ret = -EBUSY;
  4532. goto err;
  4533. }
  4534. bit = __ffs64(ar->free_vdev_map);
  4535. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
  4536. bit, ar->free_vdev_map);
  4537. arvif->vdev_id = bit;
  4538. arvif->vdev_subtype =
  4539. ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
  4540. switch (vif->type) {
  4541. case NL80211_IFTYPE_P2P_DEVICE:
  4542. arvif->vdev_type = WMI_VDEV_TYPE_STA;
  4543. arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
  4544. (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
  4545. break;
  4546. case NL80211_IFTYPE_UNSPECIFIED:
  4547. case NL80211_IFTYPE_STATION:
  4548. arvif->vdev_type = WMI_VDEV_TYPE_STA;
  4549. if (vif->p2p)
  4550. arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
  4551. (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
  4552. break;
  4553. case NL80211_IFTYPE_ADHOC:
  4554. arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
  4555. break;
  4556. case NL80211_IFTYPE_MESH_POINT:
  4557. if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
  4558. arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
  4559. (ar, WMI_VDEV_SUBTYPE_MESH_11S);
  4560. } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
  4561. ret = -EINVAL;
  4562. ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
  4563. goto err;
  4564. }
  4565. arvif->vdev_type = WMI_VDEV_TYPE_AP;
  4566. break;
  4567. case NL80211_IFTYPE_AP:
  4568. arvif->vdev_type = WMI_VDEV_TYPE_AP;
  4569. if (vif->p2p)
  4570. arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
  4571. (ar, WMI_VDEV_SUBTYPE_P2P_GO);
  4572. break;
  4573. case NL80211_IFTYPE_MONITOR:
  4574. arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
  4575. break;
  4576. default:
  4577. WARN_ON(1);
  4578. break;
  4579. }
  4580. /* Using vdev_id as queue number will make it very easy to do per-vif
  4581. * tx queue locking. This shouldn't wrap due to interface combinations
  4582. * but do a modulo for correctness sake and prevent using offchannel tx
  4583. * queues for regular vif tx.
  4584. */
  4585. vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
  4586. for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
  4587. vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
  4588. /* Some firmware revisions don't wait for beacon tx completion before
  4589. * sending another SWBA event. This could lead to hardware using old
  4590. * (freed) beacon data in some cases, e.g. tx credit starvation
  4591. * combined with missed TBTT. This is very rare.
  4592. *
  4593. * On non-IOMMU-enabled hosts this could be a possible security issue
  4594. * because hw could beacon some random data on the air. On
  4595. * IOMMU-enabled hosts DMAR faults would occur in most cases and target
  4596. * device would crash.
  4597. *
  4598. * Since there are no beacon tx completions (implicit nor explicit)
  4599. * propagated to host the only workaround for this is to allocate a
  4600. * DMA-coherent buffer for a lifetime of a vif and use it for all
  4601. * beacon tx commands. Worst case for this approach is some beacons may
  4602. * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
  4603. */
  4604. if (vif->type == NL80211_IFTYPE_ADHOC ||
  4605. vif->type == NL80211_IFTYPE_MESH_POINT ||
  4606. vif->type == NL80211_IFTYPE_AP) {
  4607. if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL) {
  4608. arvif->beacon_buf = kmalloc(IEEE80211_MAX_FRAME_LEN,
  4609. GFP_KERNEL);
  4610. /* Using a kernel pointer in place of a dma_addr_t
  4611. * token can lead to undefined behavior if that
  4612. * makes it into cache management functions. Use a
  4613. * known-invalid address token instead, which
  4614. * avoids the warning and makes it easier to catch
  4615. * bugs if it does end up getting used.
  4616. */
  4617. arvif->beacon_paddr = DMA_MAPPING_ERROR;
  4618. } else {
  4619. arvif->beacon_buf =
  4620. dma_alloc_coherent(ar->dev,
  4621. IEEE80211_MAX_FRAME_LEN,
  4622. &arvif->beacon_paddr,
  4623. GFP_ATOMIC);
  4624. }
  4625. if (!arvif->beacon_buf) {
  4626. ret = -ENOMEM;
  4627. ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
  4628. ret);
  4629. goto err;
  4630. }
  4631. }
  4632. if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
  4633. arvif->nohwcrypt = true;
  4634. if (arvif->nohwcrypt &&
  4635. !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
  4636. ret = -EINVAL;
  4637. ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
  4638. goto err;
  4639. }
  4640. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
  4641. arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
  4642. arvif->beacon_buf ? "single-buf" : "per-skb");
  4643. ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
  4644. arvif->vdev_subtype, vif->addr);
  4645. if (ret) {
  4646. ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
  4647. arvif->vdev_id, ret);
  4648. goto err;
  4649. }
  4650. if (test_bit(WMI_SERVICE_VDEV_DISABLE_4_ADDR_SRC_LRN_SUPPORT,
  4651. ar->wmi.svc_map)) {
  4652. vdev_param = ar->wmi.vdev_param->disable_4addr_src_lrn;
  4653. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  4654. WMI_VDEV_DISABLE_4_ADDR_SRC_LRN);
  4655. if (ret && ret != -EOPNOTSUPP) {
  4656. ath10k_warn(ar, "failed to disable 4addr src lrn vdev %i: %d\n",
  4657. arvif->vdev_id, ret);
  4658. }
  4659. }
  4660. ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
  4661. spin_lock_bh(&ar->data_lock);
  4662. list_add(&arvif->list, &ar->arvifs);
  4663. spin_unlock_bh(&ar->data_lock);
  4664. /* It makes no sense to have firmware do keepalives. mac80211 already
  4665. * takes care of this with idle connection polling.
  4666. */
  4667. ret = ath10k_mac_vif_disable_keepalive(arvif);
  4668. if (ret) {
  4669. ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
  4670. arvif->vdev_id, ret);
  4671. goto err_vdev_delete;
  4672. }
  4673. arvif->def_wep_key_idx = -1;
  4674. ath10k_update_vif_offload(hw, vif);
  4675. /* Configuring number of spatial stream for monitor interface is causing
  4676. * target assert in qca9888 and qca6174.
  4677. */
  4678. if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
  4679. u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
  4680. vdev_param = ar->wmi.vdev_param->nss;
  4681. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  4682. nss);
  4683. if (ret) {
  4684. ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
  4685. arvif->vdev_id, ar->cfg_tx_chainmask, nss,
  4686. ret);
  4687. goto err_vdev_delete;
  4688. }
  4689. }
  4690. if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
  4691. arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  4692. ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
  4693. vif->addr, WMI_PEER_TYPE_DEFAULT);
  4694. if (ret) {
  4695. ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
  4696. arvif->vdev_id, ret);
  4697. goto err_vdev_delete;
  4698. }
  4699. spin_lock_bh(&ar->data_lock);
  4700. peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
  4701. if (!peer) {
  4702. ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
  4703. vif->addr, arvif->vdev_id);
  4704. spin_unlock_bh(&ar->data_lock);
  4705. ret = -ENOENT;
  4706. goto err_peer_delete;
  4707. }
  4708. arvif->peer_id = find_first_bit(peer->peer_ids,
  4709. ATH10K_MAX_NUM_PEER_IDS);
  4710. spin_unlock_bh(&ar->data_lock);
  4711. } else {
  4712. arvif->peer_id = HTT_INVALID_PEERID;
  4713. }
  4714. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  4715. ret = ath10k_mac_set_kickout(arvif);
  4716. if (ret) {
  4717. ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
  4718. arvif->vdev_id, ret);
  4719. goto err_peer_delete;
  4720. }
  4721. }
  4722. if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
  4723. param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
  4724. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  4725. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  4726. param, value);
  4727. if (ret) {
  4728. ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
  4729. arvif->vdev_id, ret);
  4730. goto err_peer_delete;
  4731. }
  4732. ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
  4733. if (ret) {
  4734. ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
  4735. arvif->vdev_id, ret);
  4736. goto err_peer_delete;
  4737. }
  4738. ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
  4739. if (ret) {
  4740. ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
  4741. arvif->vdev_id, ret);
  4742. goto err_peer_delete;
  4743. }
  4744. }
  4745. ret = ath10k_mac_set_txbf_conf(arvif);
  4746. if (ret) {
  4747. ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
  4748. arvif->vdev_id, ret);
  4749. goto err_peer_delete;
  4750. }
  4751. ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
  4752. if (ret) {
  4753. ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
  4754. arvif->vdev_id, ret);
  4755. goto err_peer_delete;
  4756. }
  4757. arvif->txpower = vif->bss_conf.txpower;
  4758. ret = ath10k_mac_txpower_recalc(ar);
  4759. if (ret) {
  4760. ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
  4761. goto err_peer_delete;
  4762. }
  4763. if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) {
  4764. vdev_param = ar->wmi.vdev_param->rtt_responder_role;
  4765. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  4766. arvif->ftm_responder);
  4767. /* It is harmless to not set FTM role. Do not warn */
  4768. if (ret && ret != -EOPNOTSUPP)
  4769. ath10k_warn(ar, "failed to set vdev %i FTM Responder: %d\n",
  4770. arvif->vdev_id, ret);
  4771. }
  4772. if (vif->type == NL80211_IFTYPE_MONITOR) {
  4773. ar->monitor_arvif = arvif;
  4774. ret = ath10k_monitor_recalc(ar);
  4775. if (ret) {
  4776. ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
  4777. goto err_peer_delete;
  4778. }
  4779. }
  4780. spin_lock_bh(&ar->htt.tx_lock);
  4781. if (!ar->tx_paused)
  4782. ieee80211_wake_queue(ar->hw, arvif->vdev_id);
  4783. spin_unlock_bh(&ar->htt.tx_lock);
  4784. mutex_unlock(&ar->conf_mutex);
  4785. return 0;
  4786. err_peer_delete:
  4787. if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
  4788. arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  4789. ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
  4790. ath10k_wait_for_peer_delete_done(ar, arvif->vdev_id,
  4791. vif->addr);
  4792. }
  4793. err_vdev_delete:
  4794. ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
  4795. ar->free_vdev_map |= 1LL << arvif->vdev_id;
  4796. spin_lock_bh(&ar->data_lock);
  4797. list_del(&arvif->list);
  4798. spin_unlock_bh(&ar->data_lock);
  4799. err:
  4800. if (arvif->beacon_buf) {
  4801. if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL)
  4802. kfree(arvif->beacon_buf);
  4803. else
  4804. dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
  4805. arvif->beacon_buf,
  4806. arvif->beacon_paddr);
  4807. arvif->beacon_buf = NULL;
  4808. }
  4809. mutex_unlock(&ar->conf_mutex);
  4810. return ret;
  4811. }
  4812. static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
  4813. {
  4814. int i;
  4815. for (i = 0; i < BITS_PER_LONG; i++)
  4816. ath10k_mac_vif_tx_unlock(arvif, i);
  4817. }
  4818. static void ath10k_remove_interface(struct ieee80211_hw *hw,
  4819. struct ieee80211_vif *vif)
  4820. {
  4821. struct ath10k *ar = hw->priv;
  4822. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  4823. struct ath10k_peer *peer;
  4824. unsigned long time_left;
  4825. int ret;
  4826. int i;
  4827. cancel_work_sync(&arvif->ap_csa_work);
  4828. cancel_delayed_work_sync(&arvif->connection_loss_work);
  4829. mutex_lock(&ar->conf_mutex);
  4830. ret = ath10k_spectral_vif_stop(arvif);
  4831. if (ret)
  4832. ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
  4833. arvif->vdev_id, ret);
  4834. ar->free_vdev_map |= 1LL << arvif->vdev_id;
  4835. spin_lock_bh(&ar->data_lock);
  4836. list_del(&arvif->list);
  4837. spin_unlock_bh(&ar->data_lock);
  4838. if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
  4839. arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  4840. ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
  4841. vif->addr);
  4842. if (ret)
  4843. ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
  4844. arvif->vdev_id, ret);
  4845. ath10k_wait_for_peer_delete_done(ar, arvif->vdev_id,
  4846. vif->addr);
  4847. kfree(arvif->u.ap.noa_data);
  4848. }
  4849. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
  4850. arvif->vdev_id);
  4851. ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
  4852. if (ret)
  4853. ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
  4854. arvif->vdev_id, ret);
  4855. if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS, ar->wmi.svc_map)) {
  4856. time_left = wait_for_completion_timeout(&ar->vdev_delete_done,
  4857. ATH10K_VDEV_DELETE_TIMEOUT_HZ);
  4858. if (time_left == 0) {
  4859. ath10k_warn(ar, "Timeout in receiving vdev delete response\n");
  4860. goto out;
  4861. }
  4862. }
  4863. /* Some firmware revisions don't notify host about self-peer removal
  4864. * until after associated vdev is deleted.
  4865. */
  4866. if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
  4867. arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  4868. ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
  4869. vif->addr);
  4870. if (ret)
  4871. ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
  4872. arvif->vdev_id, ret);
  4873. spin_lock_bh(&ar->data_lock);
  4874. ar->num_peers--;
  4875. spin_unlock_bh(&ar->data_lock);
  4876. }
  4877. spin_lock_bh(&ar->data_lock);
  4878. for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
  4879. peer = ar->peer_map[i];
  4880. if (!peer)
  4881. continue;
  4882. if (peer->vif == vif) {
  4883. ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
  4884. vif->addr, arvif->vdev_id);
  4885. peer->vif = NULL;
  4886. }
  4887. }
  4888. /* Clean this up late, less opportunity for firmware to access
  4889. * DMA memory we have deleted.
  4890. */
  4891. ath10k_mac_vif_beacon_cleanup(arvif);
  4892. spin_unlock_bh(&ar->data_lock);
  4893. ath10k_peer_cleanup(ar, arvif->vdev_id);
  4894. ath10k_mac_txq_unref(ar, vif->txq);
  4895. if (vif->type == NL80211_IFTYPE_MONITOR) {
  4896. ar->monitor_arvif = NULL;
  4897. ret = ath10k_monitor_recalc(ar);
  4898. if (ret)
  4899. ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
  4900. }
  4901. ret = ath10k_mac_txpower_recalc(ar);
  4902. if (ret)
  4903. ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
  4904. spin_lock_bh(&ar->htt.tx_lock);
  4905. ath10k_mac_vif_tx_unlock_all(arvif);
  4906. spin_unlock_bh(&ar->htt.tx_lock);
  4907. ath10k_mac_txq_unref(ar, vif->txq);
  4908. out:
  4909. mutex_unlock(&ar->conf_mutex);
  4910. }
  4911. /*
  4912. * FIXME: Has to be verified.
  4913. */
  4914. #define SUPPORTED_FILTERS \
  4915. (FIF_ALLMULTI | \
  4916. FIF_CONTROL | \
  4917. FIF_PSPOLL | \
  4918. FIF_OTHER_BSS | \
  4919. FIF_BCN_PRBRESP_PROMISC | \
  4920. FIF_PROBE_REQ | \
  4921. FIF_FCSFAIL)
  4922. static void ath10k_configure_filter(struct ieee80211_hw *hw,
  4923. unsigned int changed_flags,
  4924. unsigned int *total_flags,
  4925. u64 multicast)
  4926. {
  4927. struct ath10k *ar = hw->priv;
  4928. int ret;
  4929. mutex_lock(&ar->conf_mutex);
  4930. changed_flags &= SUPPORTED_FILTERS;
  4931. *total_flags &= SUPPORTED_FILTERS;
  4932. ar->filter_flags = *total_flags;
  4933. ret = ath10k_monitor_recalc(ar);
  4934. if (ret)
  4935. ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
  4936. mutex_unlock(&ar->conf_mutex);
  4937. }
  4938. static void ath10k_recalculate_mgmt_rate(struct ath10k *ar,
  4939. struct ieee80211_vif *vif,
  4940. struct cfg80211_chan_def *def)
  4941. {
  4942. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  4943. const struct ieee80211_supported_band *sband;
  4944. u8 basic_rate_idx;
  4945. int hw_rate_code;
  4946. u32 vdev_param;
  4947. u16 bitrate;
  4948. int ret;
  4949. lockdep_assert_held(&ar->conf_mutex);
  4950. sband = ar->hw->wiphy->bands[def->chan->band];
  4951. basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
  4952. bitrate = sband->bitrates[basic_rate_idx].bitrate;
  4953. hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
  4954. if (hw_rate_code < 0) {
  4955. ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
  4956. return;
  4957. }
  4958. vdev_param = ar->wmi.vdev_param->mgmt_rate;
  4959. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  4960. hw_rate_code);
  4961. if (ret)
  4962. ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
  4963. }
  4964. static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
  4965. struct ieee80211_vif *vif,
  4966. struct ieee80211_bss_conf *info,
  4967. u64 changed)
  4968. {
  4969. struct ath10k *ar = hw->priv;
  4970. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  4971. struct cfg80211_chan_def def;
  4972. u32 vdev_param, pdev_param, slottime, preamble;
  4973. u16 bitrate, hw_value;
  4974. u8 rate, rateidx;
  4975. int ret = 0, mcast_rate;
  4976. enum nl80211_band band;
  4977. mutex_lock(&ar->conf_mutex);
  4978. if (changed & BSS_CHANGED_IBSS)
  4979. ath10k_control_ibss(arvif, vif);
  4980. if (changed & BSS_CHANGED_BEACON_INT) {
  4981. arvif->beacon_interval = info->beacon_int;
  4982. vdev_param = ar->wmi.vdev_param->beacon_interval;
  4983. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  4984. arvif->beacon_interval);
  4985. ath10k_dbg(ar, ATH10K_DBG_MAC,
  4986. "mac vdev %d beacon_interval %d\n",
  4987. arvif->vdev_id, arvif->beacon_interval);
  4988. if (ret)
  4989. ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
  4990. arvif->vdev_id, ret);
  4991. }
  4992. if (changed & BSS_CHANGED_BEACON) {
  4993. ath10k_dbg(ar, ATH10K_DBG_MAC,
  4994. "vdev %d set beacon tx mode to staggered\n",
  4995. arvif->vdev_id);
  4996. pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
  4997. ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
  4998. WMI_BEACON_STAGGERED_MODE);
  4999. if (ret)
  5000. ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
  5001. arvif->vdev_id, ret);
  5002. ret = ath10k_mac_setup_bcn_tmpl(arvif);
  5003. if (ret)
  5004. ath10k_warn(ar, "failed to update beacon template: %d\n",
  5005. ret);
  5006. if (ieee80211_vif_is_mesh(vif)) {
  5007. /* mesh doesn't use SSID but firmware needs it */
  5008. strncpy(arvif->u.ap.ssid, "mesh",
  5009. sizeof(arvif->u.ap.ssid));
  5010. arvif->u.ap.ssid_len = 4;
  5011. }
  5012. }
  5013. if (changed & BSS_CHANGED_AP_PROBE_RESP) {
  5014. ret = ath10k_mac_setup_prb_tmpl(arvif);
  5015. if (ret)
  5016. ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
  5017. arvif->vdev_id, ret);
  5018. }
  5019. if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
  5020. arvif->dtim_period = info->dtim_period;
  5021. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5022. "mac vdev %d dtim_period %d\n",
  5023. arvif->vdev_id, arvif->dtim_period);
  5024. vdev_param = ar->wmi.vdev_param->dtim_period;
  5025. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  5026. arvif->dtim_period);
  5027. if (ret)
  5028. ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
  5029. arvif->vdev_id, ret);
  5030. }
  5031. if (changed & BSS_CHANGED_SSID &&
  5032. vif->type == NL80211_IFTYPE_AP) {
  5033. arvif->u.ap.ssid_len = vif->cfg.ssid_len;
  5034. if (vif->cfg.ssid_len)
  5035. memcpy(arvif->u.ap.ssid, vif->cfg.ssid,
  5036. vif->cfg.ssid_len);
  5037. arvif->u.ap.hidden_ssid = info->hidden_ssid;
  5038. }
  5039. if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
  5040. ether_addr_copy(arvif->bssid, info->bssid);
  5041. if (changed & BSS_CHANGED_FTM_RESPONDER &&
  5042. arvif->ftm_responder != info->ftm_responder &&
  5043. test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) {
  5044. arvif->ftm_responder = info->ftm_responder;
  5045. vdev_param = ar->wmi.vdev_param->rtt_responder_role;
  5046. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  5047. arvif->ftm_responder);
  5048. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5049. "mac vdev %d ftm_responder %d:ret %d\n",
  5050. arvif->vdev_id, arvif->ftm_responder, ret);
  5051. }
  5052. if (changed & BSS_CHANGED_BEACON_ENABLED)
  5053. ath10k_control_beaconing(arvif, info);
  5054. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  5055. arvif->use_cts_prot = info->use_cts_prot;
  5056. ret = ath10k_recalc_rtscts_prot(arvif);
  5057. if (ret)
  5058. ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  5059. arvif->vdev_id, ret);
  5060. if (ath10k_mac_can_set_cts_prot(arvif)) {
  5061. ret = ath10k_mac_set_cts_prot(arvif);
  5062. if (ret)
  5063. ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
  5064. arvif->vdev_id, ret);
  5065. }
  5066. }
  5067. if (changed & BSS_CHANGED_ERP_SLOT) {
  5068. if (info->use_short_slot)
  5069. slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
  5070. else
  5071. slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
  5072. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
  5073. arvif->vdev_id, slottime);
  5074. vdev_param = ar->wmi.vdev_param->slot_time;
  5075. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  5076. slottime);
  5077. if (ret)
  5078. ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
  5079. arvif->vdev_id, ret);
  5080. }
  5081. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  5082. if (info->use_short_preamble)
  5083. preamble = WMI_VDEV_PREAMBLE_SHORT;
  5084. else
  5085. preamble = WMI_VDEV_PREAMBLE_LONG;
  5086. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5087. "mac vdev %d preamble %dn",
  5088. arvif->vdev_id, preamble);
  5089. vdev_param = ar->wmi.vdev_param->preamble;
  5090. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  5091. preamble);
  5092. if (ret)
  5093. ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
  5094. arvif->vdev_id, ret);
  5095. }
  5096. if (changed & BSS_CHANGED_ASSOC) {
  5097. if (vif->cfg.assoc) {
  5098. /* Workaround: Make sure monitor vdev is not running
  5099. * when associating to prevent some firmware revisions
  5100. * (e.g. 10.1 and 10.2) from crashing.
  5101. */
  5102. if (ar->monitor_started)
  5103. ath10k_monitor_stop(ar);
  5104. ath10k_bss_assoc(hw, vif, info);
  5105. ath10k_monitor_recalc(ar);
  5106. } else {
  5107. ath10k_bss_disassoc(hw, vif);
  5108. }
  5109. }
  5110. if (changed & BSS_CHANGED_TXPOWER) {
  5111. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
  5112. arvif->vdev_id, info->txpower);
  5113. arvif->txpower = info->txpower;
  5114. ret = ath10k_mac_txpower_recalc(ar);
  5115. if (ret)
  5116. ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
  5117. }
  5118. if (changed & BSS_CHANGED_PS) {
  5119. arvif->ps = vif->cfg.ps;
  5120. ret = ath10k_config_ps(ar);
  5121. if (ret)
  5122. ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
  5123. arvif->vdev_id, ret);
  5124. }
  5125. if (changed & BSS_CHANGED_MCAST_RATE &&
  5126. !ath10k_mac_vif_chan(arvif->vif, &def)) {
  5127. band = def.chan->band;
  5128. mcast_rate = vif->bss_conf.mcast_rate[band];
  5129. if (mcast_rate > 0)
  5130. rateidx = mcast_rate - 1;
  5131. else
  5132. rateidx = ffs(vif->bss_conf.basic_rates) - 1;
  5133. if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
  5134. rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
  5135. bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate;
  5136. hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value;
  5137. if (ath10k_mac_bitrate_is_cck(bitrate))
  5138. preamble = WMI_RATE_PREAMBLE_CCK;
  5139. else
  5140. preamble = WMI_RATE_PREAMBLE_OFDM;
  5141. rate = ATH10K_HW_RATECODE(hw_value, 0, preamble);
  5142. ath10k_dbg(ar, ATH10K_DBG_MAC,
  5143. "mac vdev %d mcast_rate %x\n",
  5144. arvif->vdev_id, rate);
  5145. vdev_param = ar->wmi.vdev_param->mcast_data_rate;
  5146. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  5147. vdev_param, rate);
  5148. if (ret)
  5149. ath10k_warn(ar,
  5150. "failed to set mcast rate on vdev %i: %d\n",
  5151. arvif->vdev_id, ret);
  5152. vdev_param = ar->wmi.vdev_param->bcast_data_rate;
  5153. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  5154. vdev_param, rate);
  5155. if (ret)
  5156. ath10k_warn(ar,
  5157. "failed to set bcast rate on vdev %i: %d\n",
  5158. arvif->vdev_id, ret);
  5159. }
  5160. if (changed & BSS_CHANGED_BASIC_RATES &&
  5161. !ath10k_mac_vif_chan(arvif->vif, &def))
  5162. ath10k_recalculate_mgmt_rate(ar, vif, &def);
  5163. mutex_unlock(&ar->conf_mutex);
  5164. }
  5165. static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
  5166. {
  5167. struct ath10k *ar = hw->priv;
  5168. /* This function should never be called if setting the coverage class
  5169. * is not supported on this hardware.
  5170. */
  5171. if (!ar->hw_params.hw_ops->set_coverage_class) {
  5172. WARN_ON_ONCE(1);
  5173. return;
  5174. }
  5175. ar->hw_params.hw_ops->set_coverage_class(ar, value);
  5176. }
  5177. struct ath10k_mac_tdls_iter_data {
  5178. u32 num_tdls_stations;
  5179. struct ieee80211_vif *curr_vif;
  5180. };
  5181. static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
  5182. struct ieee80211_sta *sta)
  5183. {
  5184. struct ath10k_mac_tdls_iter_data *iter_data = data;
  5185. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  5186. struct ieee80211_vif *sta_vif = arsta->arvif->vif;
  5187. if (sta->tdls && sta_vif == iter_data->curr_vif)
  5188. iter_data->num_tdls_stations++;
  5189. }
  5190. static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
  5191. struct ieee80211_vif *vif)
  5192. {
  5193. struct ath10k_mac_tdls_iter_data data = {};
  5194. data.curr_vif = vif;
  5195. ieee80211_iterate_stations_atomic(hw,
  5196. ath10k_mac_tdls_vif_stations_count_iter,
  5197. &data);
  5198. return data.num_tdls_stations;
  5199. }
  5200. static int ath10k_hw_scan(struct ieee80211_hw *hw,
  5201. struct ieee80211_vif *vif,
  5202. struct ieee80211_scan_request *hw_req)
  5203. {
  5204. struct ath10k *ar = hw->priv;
  5205. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  5206. struct cfg80211_scan_request *req = &hw_req->req;
  5207. struct wmi_start_scan_arg arg;
  5208. int ret = 0;
  5209. int i;
  5210. u32 scan_timeout;
  5211. mutex_lock(&ar->conf_mutex);
  5212. if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
  5213. ret = -EBUSY;
  5214. goto exit;
  5215. }
  5216. spin_lock_bh(&ar->data_lock);
  5217. switch (ar->scan.state) {
  5218. case ATH10K_SCAN_IDLE:
  5219. reinit_completion(&ar->scan.started);
  5220. reinit_completion(&ar->scan.completed);
  5221. ar->scan.state = ATH10K_SCAN_STARTING;
  5222. ar->scan.is_roc = false;
  5223. ar->scan.vdev_id = arvif->vdev_id;
  5224. ret = 0;
  5225. break;
  5226. case ATH10K_SCAN_STARTING:
  5227. case ATH10K_SCAN_RUNNING:
  5228. case ATH10K_SCAN_ABORTING:
  5229. ret = -EBUSY;
  5230. break;
  5231. }
  5232. spin_unlock_bh(&ar->data_lock);
  5233. if (ret)
  5234. goto exit;
  5235. memset(&arg, 0, sizeof(arg));
  5236. ath10k_wmi_start_scan_init(ar, &arg);
  5237. arg.vdev_id = arvif->vdev_id;
  5238. arg.scan_id = ATH10K_SCAN_ID;
  5239. if (req->ie_len) {
  5240. arg.ie_len = req->ie_len;
  5241. memcpy(arg.ie, req->ie, arg.ie_len);
  5242. }
  5243. if (req->n_ssids) {
  5244. arg.n_ssids = req->n_ssids;
  5245. for (i = 0; i < arg.n_ssids; i++) {
  5246. arg.ssids[i].len = req->ssids[i].ssid_len;
  5247. arg.ssids[i].ssid = req->ssids[i].ssid;
  5248. }
  5249. } else {
  5250. arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
  5251. }
  5252. if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  5253. arg.scan_ctrl_flags |= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ;
  5254. ether_addr_copy(arg.mac_addr.addr, req->mac_addr);
  5255. ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask);
  5256. }
  5257. if (req->n_channels) {
  5258. arg.n_channels = req->n_channels;
  5259. for (i = 0; i < arg.n_channels; i++)
  5260. arg.channels[i] = req->channels[i]->center_freq;
  5261. }
  5262. /* if duration is set, default dwell times will be overwritten */
  5263. if (req->duration) {
  5264. arg.dwell_time_active = req->duration;
  5265. arg.dwell_time_passive = req->duration;
  5266. arg.burst_duration_ms = req->duration;
  5267. scan_timeout = min_t(u32, arg.max_rest_time *
  5268. (arg.n_channels - 1) + (req->duration +
  5269. ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) *
  5270. arg.n_channels, arg.max_scan_time);
  5271. } else {
  5272. scan_timeout = arg.max_scan_time;
  5273. }
  5274. /* Add a 200ms margin to account for event/command processing */
  5275. scan_timeout += 200;
  5276. ret = ath10k_start_scan(ar, &arg);
  5277. if (ret) {
  5278. ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
  5279. spin_lock_bh(&ar->data_lock);
  5280. ar->scan.state = ATH10K_SCAN_IDLE;
  5281. spin_unlock_bh(&ar->data_lock);
  5282. }
  5283. ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
  5284. msecs_to_jiffies(scan_timeout));
  5285. exit:
  5286. mutex_unlock(&ar->conf_mutex);
  5287. return ret;
  5288. }
  5289. static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
  5290. struct ieee80211_vif *vif)
  5291. {
  5292. struct ath10k *ar = hw->priv;
  5293. mutex_lock(&ar->conf_mutex);
  5294. ath10k_scan_abort(ar);
  5295. mutex_unlock(&ar->conf_mutex);
  5296. cancel_delayed_work_sync(&ar->scan.timeout);
  5297. }
  5298. static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
  5299. struct ath10k_vif *arvif,
  5300. enum set_key_cmd cmd,
  5301. struct ieee80211_key_conf *key)
  5302. {
  5303. u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
  5304. int ret;
  5305. /* 10.1 firmware branch requires default key index to be set to group
  5306. * key index after installing it. Otherwise FW/HW Txes corrupted
  5307. * frames with multi-vif APs. This is not required for main firmware
  5308. * branch (e.g. 636).
  5309. *
  5310. * This is also needed for 636 fw for IBSS-RSN to work more reliably.
  5311. *
  5312. * FIXME: It remains unknown if this is required for multi-vif STA
  5313. * interfaces on 10.1.
  5314. */
  5315. if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
  5316. arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
  5317. return;
  5318. if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
  5319. return;
  5320. if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
  5321. return;
  5322. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  5323. return;
  5324. if (cmd != SET_KEY)
  5325. return;
  5326. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  5327. key->keyidx);
  5328. if (ret)
  5329. ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
  5330. arvif->vdev_id, ret);
  5331. }
  5332. static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  5333. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  5334. struct ieee80211_key_conf *key)
  5335. {
  5336. struct ath10k *ar = hw->priv;
  5337. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  5338. struct ath10k_sta *arsta;
  5339. struct ath10k_peer *peer;
  5340. const u8 *peer_addr;
  5341. bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  5342. key->cipher == WLAN_CIPHER_SUITE_WEP104;
  5343. int ret = 0;
  5344. int ret2;
  5345. u32 flags = 0;
  5346. u32 flags2;
  5347. /* this one needs to be done in software */
  5348. if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
  5349. key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
  5350. key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
  5351. key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
  5352. return 1;
  5353. if (arvif->nohwcrypt)
  5354. return 1;
  5355. if (key->keyidx > WMI_MAX_KEY_INDEX)
  5356. return -ENOSPC;
  5357. mutex_lock(&ar->conf_mutex);
  5358. if (sta) {
  5359. arsta = (struct ath10k_sta *)sta->drv_priv;
  5360. peer_addr = sta->addr;
  5361. spin_lock_bh(&ar->data_lock);
  5362. arsta->ucast_cipher = key->cipher;
  5363. spin_unlock_bh(&ar->data_lock);
  5364. } else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
  5365. peer_addr = vif->bss_conf.bssid;
  5366. } else {
  5367. peer_addr = vif->addr;
  5368. }
  5369. key->hw_key_idx = key->keyidx;
  5370. if (is_wep) {
  5371. if (cmd == SET_KEY)
  5372. arvif->wep_keys[key->keyidx] = key;
  5373. else
  5374. arvif->wep_keys[key->keyidx] = NULL;
  5375. }
  5376. /* the peer should not disappear in mid-way (unless FW goes awry) since
  5377. * we already hold conf_mutex. we just make sure its there now.
  5378. */
  5379. spin_lock_bh(&ar->data_lock);
  5380. peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
  5381. spin_unlock_bh(&ar->data_lock);
  5382. if (!peer) {
  5383. if (cmd == SET_KEY) {
  5384. ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
  5385. peer_addr);
  5386. ret = -EOPNOTSUPP;
  5387. goto exit;
  5388. } else {
  5389. /* if the peer doesn't exist there is no key to disable anymore */
  5390. goto exit;
  5391. }
  5392. }
  5393. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  5394. flags |= WMI_KEY_PAIRWISE;
  5395. else
  5396. flags |= WMI_KEY_GROUP;
  5397. if (is_wep) {
  5398. if (cmd == DISABLE_KEY)
  5399. ath10k_clear_vdev_key(arvif, key);
  5400. /* When WEP keys are uploaded it's possible that there are
  5401. * stations associated already (e.g. when merging) without any
  5402. * keys. Static WEP needs an explicit per-peer key upload.
  5403. */
  5404. if (vif->type == NL80211_IFTYPE_ADHOC &&
  5405. cmd == SET_KEY)
  5406. ath10k_mac_vif_update_wep_key(arvif, key);
  5407. /* 802.1x never sets the def_wep_key_idx so each set_key()
  5408. * call changes default tx key.
  5409. *
  5410. * Static WEP sets def_wep_key_idx via .set_default_unicast_key
  5411. * after first set_key().
  5412. */
  5413. if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
  5414. flags |= WMI_KEY_TX_USAGE;
  5415. }
  5416. ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
  5417. if (ret) {
  5418. WARN_ON(ret > 0);
  5419. ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
  5420. arvif->vdev_id, peer_addr, ret);
  5421. goto exit;
  5422. }
  5423. /* mac80211 sets static WEP keys as groupwise while firmware requires
  5424. * them to be installed twice as both pairwise and groupwise.
  5425. */
  5426. if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
  5427. flags2 = flags;
  5428. flags2 &= ~WMI_KEY_GROUP;
  5429. flags2 |= WMI_KEY_PAIRWISE;
  5430. ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
  5431. if (ret) {
  5432. WARN_ON(ret > 0);
  5433. ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
  5434. arvif->vdev_id, peer_addr, ret);
  5435. ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
  5436. peer_addr, flags);
  5437. if (ret2) {
  5438. WARN_ON(ret2 > 0);
  5439. ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
  5440. arvif->vdev_id, peer_addr, ret2);
  5441. }
  5442. goto exit;
  5443. }
  5444. }
  5445. ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
  5446. spin_lock_bh(&ar->data_lock);
  5447. peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
  5448. if (peer && cmd == SET_KEY)
  5449. peer->keys[key->keyidx] = key;
  5450. else if (peer && cmd == DISABLE_KEY)
  5451. peer->keys[key->keyidx] = NULL;
  5452. else if (peer == NULL)
  5453. /* impossible unless FW goes crazy */
  5454. ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
  5455. spin_unlock_bh(&ar->data_lock);
  5456. if (sta && sta->tdls)
  5457. ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  5458. ar->wmi.peer_param->authorize, 1);
  5459. else if (sta && cmd == SET_KEY && (key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
  5460. ath10k_wmi_peer_set_param(ar, arvif->vdev_id, peer_addr,
  5461. ar->wmi.peer_param->authorize, 1);
  5462. exit:
  5463. mutex_unlock(&ar->conf_mutex);
  5464. return ret;
  5465. }
  5466. static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
  5467. struct ieee80211_vif *vif,
  5468. int keyidx)
  5469. {
  5470. struct ath10k *ar = hw->priv;
  5471. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  5472. int ret;
  5473. mutex_lock(&arvif->ar->conf_mutex);
  5474. if (arvif->ar->state != ATH10K_STATE_ON)
  5475. goto unlock;
  5476. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
  5477. arvif->vdev_id, keyidx);
  5478. ret = ath10k_wmi_vdev_set_param(arvif->ar,
  5479. arvif->vdev_id,
  5480. arvif->ar->wmi.vdev_param->def_keyid,
  5481. keyidx);
  5482. if (ret) {
  5483. ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
  5484. arvif->vdev_id,
  5485. ret);
  5486. goto unlock;
  5487. }
  5488. arvif->def_wep_key_idx = keyidx;
  5489. unlock:
  5490. mutex_unlock(&arvif->ar->conf_mutex);
  5491. }
  5492. static void ath10k_sta_rc_update_wk(struct work_struct *wk)
  5493. {
  5494. struct ath10k *ar;
  5495. struct ath10k_vif *arvif;
  5496. struct ath10k_sta *arsta;
  5497. struct ieee80211_sta *sta;
  5498. struct cfg80211_chan_def def;
  5499. enum nl80211_band band;
  5500. const u8 *ht_mcs_mask;
  5501. const u16 *vht_mcs_mask;
  5502. u32 changed, bw, nss, smps;
  5503. int err;
  5504. arsta = container_of(wk, struct ath10k_sta, update_wk);
  5505. sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
  5506. arvif = arsta->arvif;
  5507. ar = arvif->ar;
  5508. if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
  5509. return;
  5510. band = def.chan->band;
  5511. ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
  5512. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  5513. spin_lock_bh(&ar->data_lock);
  5514. changed = arsta->changed;
  5515. arsta->changed = 0;
  5516. bw = arsta->bw;
  5517. nss = arsta->nss;
  5518. smps = arsta->smps;
  5519. spin_unlock_bh(&ar->data_lock);
  5520. mutex_lock(&ar->conf_mutex);
  5521. nss = max_t(u32, 1, nss);
  5522. nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
  5523. ath10k_mac_max_vht_nss(vht_mcs_mask)));
  5524. if (changed & IEEE80211_RC_BW_CHANGED) {
  5525. enum wmi_phy_mode mode;
  5526. mode = chan_to_phymode(&def);
  5527. ath10k_dbg(ar, ATH10K_DBG_STA, "mac update sta %pM peer bw %d phymode %d\n",
  5528. sta->addr, bw, mode);
  5529. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  5530. ar->wmi.peer_param->phymode, mode);
  5531. if (err) {
  5532. ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n",
  5533. sta->addr, mode, err);
  5534. goto exit;
  5535. }
  5536. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  5537. ar->wmi.peer_param->chan_width, bw);
  5538. if (err)
  5539. ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
  5540. sta->addr, bw, err);
  5541. }
  5542. if (changed & IEEE80211_RC_NSS_CHANGED) {
  5543. ath10k_dbg(ar, ATH10K_DBG_STA, "mac update sta %pM nss %d\n",
  5544. sta->addr, nss);
  5545. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  5546. ar->wmi.peer_param->nss, nss);
  5547. if (err)
  5548. ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
  5549. sta->addr, nss, err);
  5550. }
  5551. if (changed & IEEE80211_RC_SMPS_CHANGED) {
  5552. ath10k_dbg(ar, ATH10K_DBG_STA, "mac update sta %pM smps %d\n",
  5553. sta->addr, smps);
  5554. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  5555. ar->wmi.peer_param->smps_state, smps);
  5556. if (err)
  5557. ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
  5558. sta->addr, smps, err);
  5559. }
  5560. if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
  5561. ath10k_dbg(ar, ATH10K_DBG_STA, "mac update sta %pM supp rates\n",
  5562. sta->addr);
  5563. err = ath10k_station_assoc(ar, arvif->vif, sta, true);
  5564. if (err)
  5565. ath10k_warn(ar, "failed to reassociate station: %pM\n",
  5566. sta->addr);
  5567. }
  5568. exit:
  5569. mutex_unlock(&ar->conf_mutex);
  5570. }
  5571. static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
  5572. struct ieee80211_sta *sta)
  5573. {
  5574. struct ath10k *ar = arvif->ar;
  5575. lockdep_assert_held(&ar->conf_mutex);
  5576. if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
  5577. return 0;
  5578. if (ar->num_stations >= ar->max_num_stations)
  5579. return -ENOBUFS;
  5580. ar->num_stations++;
  5581. return 0;
  5582. }
  5583. static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
  5584. struct ieee80211_sta *sta)
  5585. {
  5586. struct ath10k *ar = arvif->ar;
  5587. lockdep_assert_held(&ar->conf_mutex);
  5588. if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
  5589. return;
  5590. ar->num_stations--;
  5591. }
  5592. static int ath10k_sta_set_txpwr(struct ieee80211_hw *hw,
  5593. struct ieee80211_vif *vif,
  5594. struct ieee80211_sta *sta)
  5595. {
  5596. struct ath10k *ar = hw->priv;
  5597. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  5598. int ret = 0;
  5599. s16 txpwr;
  5600. if (sta->deflink.txpwr.type == NL80211_TX_POWER_AUTOMATIC) {
  5601. txpwr = 0;
  5602. } else {
  5603. txpwr = sta->deflink.txpwr.power;
  5604. if (!txpwr)
  5605. return -EINVAL;
  5606. }
  5607. if (txpwr > ATH10K_TX_POWER_MAX_VAL || txpwr < ATH10K_TX_POWER_MIN_VAL)
  5608. return -EINVAL;
  5609. mutex_lock(&ar->conf_mutex);
  5610. ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  5611. ar->wmi.peer_param->use_fixed_power, txpwr);
  5612. if (ret) {
  5613. ath10k_warn(ar, "failed to set tx power for station ret: %d\n",
  5614. ret);
  5615. goto out;
  5616. }
  5617. out:
  5618. mutex_unlock(&ar->conf_mutex);
  5619. return ret;
  5620. }
  5621. struct ath10k_mac_iter_tid_conf_data {
  5622. struct ieee80211_vif *curr_vif;
  5623. struct ath10k *ar;
  5624. bool reset_config;
  5625. };
  5626. static bool
  5627. ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
  5628. enum nl80211_band band,
  5629. const struct cfg80211_bitrate_mask *mask,
  5630. int *vht_num_rates)
  5631. {
  5632. int num_rates = 0;
  5633. int i, tmp;
  5634. num_rates += hweight32(mask->control[band].legacy);
  5635. for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
  5636. num_rates += hweight8(mask->control[band].ht_mcs[i]);
  5637. *vht_num_rates = 0;
  5638. for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
  5639. tmp = hweight16(mask->control[band].vht_mcs[i]);
  5640. num_rates += tmp;
  5641. *vht_num_rates += tmp;
  5642. }
  5643. return num_rates == 1;
  5644. }
  5645. static int
  5646. ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
  5647. enum nl80211_band band,
  5648. const struct cfg80211_bitrate_mask *mask,
  5649. u8 *rate, u8 *nss, bool vht_only)
  5650. {
  5651. int rate_idx;
  5652. int i;
  5653. u16 bitrate;
  5654. u8 preamble;
  5655. u8 hw_rate;
  5656. if (vht_only)
  5657. goto next;
  5658. if (hweight32(mask->control[band].legacy) == 1) {
  5659. rate_idx = ffs(mask->control[band].legacy) - 1;
  5660. if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
  5661. rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
  5662. hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value;
  5663. bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate;
  5664. if (ath10k_mac_bitrate_is_cck(bitrate))
  5665. preamble = WMI_RATE_PREAMBLE_CCK;
  5666. else
  5667. preamble = WMI_RATE_PREAMBLE_OFDM;
  5668. *nss = 1;
  5669. *rate = preamble << 6 |
  5670. (*nss - 1) << 4 |
  5671. hw_rate << 0;
  5672. return 0;
  5673. }
  5674. for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
  5675. if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
  5676. *nss = i + 1;
  5677. *rate = WMI_RATE_PREAMBLE_HT << 6 |
  5678. (*nss - 1) << 4 |
  5679. (ffs(mask->control[band].ht_mcs[i]) - 1);
  5680. return 0;
  5681. }
  5682. }
  5683. next:
  5684. for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
  5685. if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
  5686. *nss = i + 1;
  5687. *rate = WMI_RATE_PREAMBLE_VHT << 6 |
  5688. (*nss - 1) << 4 |
  5689. (ffs(mask->control[band].vht_mcs[i]) - 1);
  5690. return 0;
  5691. }
  5692. }
  5693. return -EINVAL;
  5694. }
  5695. static int ath10k_mac_validate_rate_mask(struct ath10k *ar,
  5696. struct ieee80211_sta *sta,
  5697. u32 rate_ctrl_flag, u8 nss)
  5698. {
  5699. struct ieee80211_sta_ht_cap *ht_cap = &sta->deflink.ht_cap;
  5700. struct ieee80211_sta_vht_cap *vht_cap = &sta->deflink.vht_cap;
  5701. if (nss > sta->deflink.rx_nss) {
  5702. ath10k_warn(ar, "Invalid nss field, configured %u limit %u\n",
  5703. nss, sta->deflink.rx_nss);
  5704. return -EINVAL;
  5705. }
  5706. if (ATH10K_HW_PREAMBLE(rate_ctrl_flag) == WMI_RATE_PREAMBLE_VHT) {
  5707. if (!vht_cap->vht_supported) {
  5708. ath10k_warn(ar, "Invalid VHT rate for sta %pM\n",
  5709. sta->addr);
  5710. return -EINVAL;
  5711. }
  5712. } else if (ATH10K_HW_PREAMBLE(rate_ctrl_flag) == WMI_RATE_PREAMBLE_HT) {
  5713. if (!ht_cap->ht_supported || vht_cap->vht_supported) {
  5714. ath10k_warn(ar, "Invalid HT rate for sta %pM\n",
  5715. sta->addr);
  5716. return -EINVAL;
  5717. }
  5718. } else {
  5719. if (ht_cap->ht_supported || vht_cap->vht_supported)
  5720. return -EINVAL;
  5721. }
  5722. return 0;
  5723. }
  5724. static int
  5725. ath10k_mac_tid_bitrate_config(struct ath10k *ar,
  5726. struct ieee80211_vif *vif,
  5727. struct ieee80211_sta *sta,
  5728. u32 *rate_ctrl_flag, u8 *rate_ctrl,
  5729. enum nl80211_tx_rate_setting txrate_type,
  5730. const struct cfg80211_bitrate_mask *mask)
  5731. {
  5732. struct cfg80211_chan_def def;
  5733. enum nl80211_band band;
  5734. u8 nss, rate;
  5735. int vht_num_rates, ret;
  5736. if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
  5737. return -EINVAL;
  5738. if (txrate_type == NL80211_TX_RATE_AUTOMATIC) {
  5739. *rate_ctrl = WMI_TID_CONFIG_RATE_CONTROL_AUTO;
  5740. *rate_ctrl_flag = 0;
  5741. return 0;
  5742. }
  5743. band = def.chan->band;
  5744. if (!ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask,
  5745. &vht_num_rates)) {
  5746. return -EINVAL;
  5747. }
  5748. ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
  5749. &rate, &nss, false);
  5750. if (ret) {
  5751. ath10k_warn(ar, "failed to get single rate: %d\n",
  5752. ret);
  5753. return ret;
  5754. }
  5755. *rate_ctrl_flag = rate;
  5756. if (sta && ath10k_mac_validate_rate_mask(ar, sta, *rate_ctrl_flag, nss))
  5757. return -EINVAL;
  5758. if (txrate_type == NL80211_TX_RATE_FIXED)
  5759. *rate_ctrl = WMI_TID_CONFIG_RATE_CONTROL_FIXED_RATE;
  5760. else if (txrate_type == NL80211_TX_RATE_LIMITED &&
  5761. (test_bit(WMI_SERVICE_EXT_PEER_TID_CONFIGS_SUPPORT,
  5762. ar->wmi.svc_map)))
  5763. *rate_ctrl = WMI_PEER_TID_CONFIG_RATE_UPPER_CAP;
  5764. else
  5765. return -EOPNOTSUPP;
  5766. return 0;
  5767. }
  5768. static int ath10k_mac_set_tid_config(struct ath10k *ar, struct ieee80211_sta *sta,
  5769. struct ieee80211_vif *vif, u32 changed,
  5770. struct wmi_per_peer_per_tid_cfg_arg *arg)
  5771. {
  5772. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  5773. struct ath10k_sta *arsta;
  5774. int ret;
  5775. if (sta) {
  5776. if (!sta->wme)
  5777. return -ENOTSUPP;
  5778. arsta = (struct ath10k_sta *)sta->drv_priv;
  5779. if (changed & BIT(NL80211_TID_CONFIG_ATTR_NOACK)) {
  5780. if ((arsta->retry_long[arg->tid] > 0 ||
  5781. arsta->rate_code[arg->tid] > 0 ||
  5782. arsta->ampdu[arg->tid] ==
  5783. WMI_TID_CONFIG_AGGR_CONTROL_ENABLE) &&
  5784. arg->ack_policy == WMI_PEER_TID_CONFIG_NOACK) {
  5785. changed &= ~BIT(NL80211_TID_CONFIG_ATTR_NOACK);
  5786. arg->ack_policy = 0;
  5787. arg->aggr_control = 0;
  5788. arg->rate_ctrl = 0;
  5789. arg->rcode_flags = 0;
  5790. }
  5791. }
  5792. if (changed & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) {
  5793. if (arsta->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK ||
  5794. arvif->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK) {
  5795. arg->aggr_control = 0;
  5796. changed &= ~BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG);
  5797. }
  5798. }
  5799. if (changed & (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
  5800. BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE))) {
  5801. if (arsta->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK ||
  5802. arvif->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK) {
  5803. arg->rate_ctrl = 0;
  5804. arg->rcode_flags = 0;
  5805. }
  5806. }
  5807. ether_addr_copy(arg->peer_macaddr.addr, sta->addr);
  5808. ret = ath10k_wmi_set_per_peer_per_tid_cfg(ar, arg);
  5809. if (ret)
  5810. return ret;
  5811. /* Store the configured parameters in success case */
  5812. if (changed & BIT(NL80211_TID_CONFIG_ATTR_NOACK)) {
  5813. arsta->noack[arg->tid] = arg->ack_policy;
  5814. arg->ack_policy = 0;
  5815. arg->aggr_control = 0;
  5816. arg->rate_ctrl = 0;
  5817. arg->rcode_flags = 0;
  5818. }
  5819. if (changed & BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG)) {
  5820. arsta->retry_long[arg->tid] = arg->retry_count;
  5821. arg->retry_count = 0;
  5822. }
  5823. if (changed & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) {
  5824. arsta->ampdu[arg->tid] = arg->aggr_control;
  5825. arg->aggr_control = 0;
  5826. }
  5827. if (changed & (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
  5828. BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE))) {
  5829. arsta->rate_ctrl[arg->tid] = arg->rate_ctrl;
  5830. arg->rate_ctrl = 0;
  5831. arg->rcode_flags = 0;
  5832. }
  5833. if (changed & BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL)) {
  5834. arsta->rtscts[arg->tid] = arg->rtscts_ctrl;
  5835. arg->ext_tid_cfg_bitmap = 0;
  5836. }
  5837. } else {
  5838. if (changed & BIT(NL80211_TID_CONFIG_ATTR_NOACK)) {
  5839. if ((arvif->retry_long[arg->tid] ||
  5840. arvif->rate_code[arg->tid] ||
  5841. arvif->ampdu[arg->tid] ==
  5842. WMI_TID_CONFIG_AGGR_CONTROL_ENABLE) &&
  5843. arg->ack_policy == WMI_PEER_TID_CONFIG_NOACK) {
  5844. changed &= ~BIT(NL80211_TID_CONFIG_ATTR_NOACK);
  5845. } else {
  5846. arvif->noack[arg->tid] = arg->ack_policy;
  5847. arvif->ampdu[arg->tid] = arg->aggr_control;
  5848. arvif->rate_ctrl[arg->tid] = arg->rate_ctrl;
  5849. }
  5850. }
  5851. if (changed & BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG)) {
  5852. if (arvif->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK)
  5853. changed &= ~BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG);
  5854. else
  5855. arvif->retry_long[arg->tid] = arg->retry_count;
  5856. }
  5857. if (changed & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) {
  5858. if (arvif->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK)
  5859. changed &= ~BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL);
  5860. else
  5861. arvif->ampdu[arg->tid] = arg->aggr_control;
  5862. }
  5863. if (changed & (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
  5864. BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE))) {
  5865. if (arvif->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK) {
  5866. changed &= ~(BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
  5867. BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE));
  5868. } else {
  5869. arvif->rate_ctrl[arg->tid] = arg->rate_ctrl;
  5870. arvif->rate_code[arg->tid] = arg->rcode_flags;
  5871. }
  5872. }
  5873. if (changed & BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL)) {
  5874. arvif->rtscts[arg->tid] = arg->rtscts_ctrl;
  5875. arg->ext_tid_cfg_bitmap = 0;
  5876. }
  5877. if (changed)
  5878. arvif->tid_conf_changed[arg->tid] |= changed;
  5879. }
  5880. return 0;
  5881. }
  5882. static int
  5883. ath10k_mac_parse_tid_config(struct ath10k *ar,
  5884. struct ieee80211_sta *sta,
  5885. struct ieee80211_vif *vif,
  5886. struct cfg80211_tid_cfg *tid_conf,
  5887. struct wmi_per_peer_per_tid_cfg_arg *arg)
  5888. {
  5889. u32 changed = tid_conf->mask;
  5890. int ret = 0, i = 0;
  5891. if (!changed)
  5892. return -EINVAL;
  5893. while (i < ATH10K_TID_MAX) {
  5894. if (!(tid_conf->tids & BIT(i))) {
  5895. i++;
  5896. continue;
  5897. }
  5898. arg->tid = i;
  5899. if (changed & BIT(NL80211_TID_CONFIG_ATTR_NOACK)) {
  5900. if (tid_conf->noack == NL80211_TID_CONFIG_ENABLE) {
  5901. arg->ack_policy = WMI_PEER_TID_CONFIG_NOACK;
  5902. arg->rate_ctrl =
  5903. WMI_TID_CONFIG_RATE_CONTROL_DEFAULT_LOWEST_RATE;
  5904. arg->aggr_control =
  5905. WMI_TID_CONFIG_AGGR_CONTROL_DISABLE;
  5906. } else {
  5907. arg->ack_policy =
  5908. WMI_PEER_TID_CONFIG_ACK;
  5909. arg->rate_ctrl =
  5910. WMI_TID_CONFIG_RATE_CONTROL_AUTO;
  5911. arg->aggr_control =
  5912. WMI_TID_CONFIG_AGGR_CONTROL_ENABLE;
  5913. }
  5914. }
  5915. if (changed & BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG))
  5916. arg->retry_count = tid_conf->retry_long;
  5917. if (changed & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) {
  5918. if (tid_conf->noack == NL80211_TID_CONFIG_ENABLE)
  5919. arg->aggr_control = WMI_TID_CONFIG_AGGR_CONTROL_ENABLE;
  5920. else
  5921. arg->aggr_control = WMI_TID_CONFIG_AGGR_CONTROL_DISABLE;
  5922. }
  5923. if (changed & (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
  5924. BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE))) {
  5925. ret = ath10k_mac_tid_bitrate_config(ar, vif, sta,
  5926. &arg->rcode_flags,
  5927. &arg->rate_ctrl,
  5928. tid_conf->txrate_type,
  5929. &tid_conf->txrate_mask);
  5930. if (ret) {
  5931. ath10k_warn(ar, "failed to configure bitrate mask %d\n",
  5932. ret);
  5933. arg->rcode_flags = 0;
  5934. arg->rate_ctrl = 0;
  5935. }
  5936. }
  5937. if (changed & BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL)) {
  5938. if (tid_conf->rtscts)
  5939. arg->rtscts_ctrl = tid_conf->rtscts;
  5940. arg->ext_tid_cfg_bitmap = WMI_EXT_TID_RTS_CTS_CONFIG;
  5941. }
  5942. ret = ath10k_mac_set_tid_config(ar, sta, vif, changed, arg);
  5943. if (ret)
  5944. return ret;
  5945. i++;
  5946. }
  5947. return ret;
  5948. }
  5949. static int ath10k_mac_reset_tid_config(struct ath10k *ar,
  5950. struct ieee80211_sta *sta,
  5951. struct ath10k_vif *arvif,
  5952. u8 tids)
  5953. {
  5954. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  5955. struct wmi_per_peer_per_tid_cfg_arg arg;
  5956. int ret = 0, i = 0;
  5957. arg.vdev_id = arvif->vdev_id;
  5958. while (i < ATH10K_TID_MAX) {
  5959. if (!(tids & BIT(i))) {
  5960. i++;
  5961. continue;
  5962. }
  5963. arg.tid = i;
  5964. arg.ack_policy = WMI_PEER_TID_CONFIG_ACK;
  5965. arg.retry_count = ATH10K_MAX_RETRY_COUNT;
  5966. arg.rate_ctrl = WMI_TID_CONFIG_RATE_CONTROL_AUTO;
  5967. arg.aggr_control = WMI_TID_CONFIG_AGGR_CONTROL_ENABLE;
  5968. arg.rtscts_ctrl = WMI_TID_CONFIG_RTSCTS_CONTROL_ENABLE;
  5969. arg.ext_tid_cfg_bitmap = WMI_EXT_TID_RTS_CTS_CONFIG;
  5970. ether_addr_copy(arg.peer_macaddr.addr, sta->addr);
  5971. ret = ath10k_wmi_set_per_peer_per_tid_cfg(ar, &arg);
  5972. if (ret)
  5973. return ret;
  5974. if (!arvif->tids_rst) {
  5975. arsta->retry_long[i] = -1;
  5976. arsta->noack[i] = -1;
  5977. arsta->ampdu[i] = -1;
  5978. arsta->rate_code[i] = -1;
  5979. arsta->rate_ctrl[i] = 0;
  5980. arsta->rtscts[i] = -1;
  5981. } else {
  5982. arvif->retry_long[i] = 0;
  5983. arvif->noack[i] = 0;
  5984. arvif->ampdu[i] = 0;
  5985. arvif->rate_code[i] = 0;
  5986. arvif->rate_ctrl[i] = 0;
  5987. arvif->rtscts[i] = 0;
  5988. }
  5989. i++;
  5990. }
  5991. return ret;
  5992. }
  5993. static void ath10k_sta_tid_cfg_wk(struct work_struct *wk)
  5994. {
  5995. struct wmi_per_peer_per_tid_cfg_arg arg = {};
  5996. struct ieee80211_sta *sta;
  5997. struct ath10k_sta *arsta;
  5998. struct ath10k_vif *arvif;
  5999. struct ath10k *ar;
  6000. bool config_apply;
  6001. int ret, i;
  6002. u32 changed;
  6003. u8 nss;
  6004. arsta = container_of(wk, struct ath10k_sta, tid_config_wk);
  6005. sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
  6006. arvif = arsta->arvif;
  6007. ar = arvif->ar;
  6008. mutex_lock(&ar->conf_mutex);
  6009. if (arvif->tids_rst) {
  6010. ret = ath10k_mac_reset_tid_config(ar, sta, arvif,
  6011. arvif->tids_rst);
  6012. goto exit;
  6013. }
  6014. ether_addr_copy(arg.peer_macaddr.addr, sta->addr);
  6015. for (i = 0; i < ATH10K_TID_MAX; i++) {
  6016. config_apply = false;
  6017. changed = arvif->tid_conf_changed[i];
  6018. if (changed & BIT(NL80211_TID_CONFIG_ATTR_NOACK)) {
  6019. if (arsta->noack[i] != -1) {
  6020. arg.ack_policy = 0;
  6021. } else {
  6022. config_apply = true;
  6023. arg.ack_policy = arvif->noack[i];
  6024. arg.aggr_control = arvif->ampdu[i];
  6025. arg.rate_ctrl = arvif->rate_ctrl[i];
  6026. }
  6027. }
  6028. if (changed & BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG)) {
  6029. if (arsta->retry_long[i] != -1 ||
  6030. arsta->noack[i] == WMI_PEER_TID_CONFIG_NOACK ||
  6031. arvif->noack[i] == WMI_PEER_TID_CONFIG_NOACK) {
  6032. arg.retry_count = 0;
  6033. } else {
  6034. arg.retry_count = arvif->retry_long[i];
  6035. config_apply = true;
  6036. }
  6037. }
  6038. if (changed & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) {
  6039. if (arsta->ampdu[i] != -1 ||
  6040. arsta->noack[i] == WMI_PEER_TID_CONFIG_NOACK ||
  6041. arvif->noack[i] == WMI_PEER_TID_CONFIG_NOACK) {
  6042. arg.aggr_control = 0;
  6043. } else {
  6044. arg.aggr_control = arvif->ampdu[i];
  6045. config_apply = true;
  6046. }
  6047. }
  6048. if (changed & (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
  6049. BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE))) {
  6050. nss = ATH10K_HW_NSS(arvif->rate_code[i]);
  6051. ret = ath10k_mac_validate_rate_mask(ar, sta,
  6052. arvif->rate_code[i],
  6053. nss);
  6054. if (ret &&
  6055. arvif->rate_ctrl[i] > WMI_TID_CONFIG_RATE_CONTROL_AUTO) {
  6056. arg.rate_ctrl = 0;
  6057. arg.rcode_flags = 0;
  6058. }
  6059. if (arsta->rate_ctrl[i] >
  6060. WMI_TID_CONFIG_RATE_CONTROL_AUTO ||
  6061. arsta->noack[i] == WMI_PEER_TID_CONFIG_NOACK ||
  6062. arvif->noack[i] == WMI_PEER_TID_CONFIG_NOACK) {
  6063. arg.rate_ctrl = 0;
  6064. arg.rcode_flags = 0;
  6065. } else {
  6066. arg.rate_ctrl = arvif->rate_ctrl[i];
  6067. arg.rcode_flags = arvif->rate_code[i];
  6068. config_apply = true;
  6069. }
  6070. }
  6071. if (changed & BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL)) {
  6072. if (arsta->rtscts[i]) {
  6073. arg.rtscts_ctrl = 0;
  6074. arg.ext_tid_cfg_bitmap = 0;
  6075. } else {
  6076. arg.rtscts_ctrl = arvif->rtscts[i] - 1;
  6077. arg.ext_tid_cfg_bitmap =
  6078. WMI_EXT_TID_RTS_CTS_CONFIG;
  6079. config_apply = true;
  6080. }
  6081. }
  6082. arg.tid = i;
  6083. if (config_apply) {
  6084. ret = ath10k_wmi_set_per_peer_per_tid_cfg(ar, &arg);
  6085. if (ret)
  6086. ath10k_warn(ar, "failed to set per tid config for sta %pM: %d\n",
  6087. sta->addr, ret);
  6088. }
  6089. arg.ack_policy = 0;
  6090. arg.retry_count = 0;
  6091. arg.aggr_control = 0;
  6092. arg.rate_ctrl = 0;
  6093. arg.rcode_flags = 0;
  6094. }
  6095. exit:
  6096. mutex_unlock(&ar->conf_mutex);
  6097. }
  6098. static void ath10k_mac_vif_stations_tid_conf(void *data,
  6099. struct ieee80211_sta *sta)
  6100. {
  6101. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  6102. struct ath10k_mac_iter_tid_conf_data *iter_data = data;
  6103. struct ieee80211_vif *sta_vif = arsta->arvif->vif;
  6104. if (sta_vif != iter_data->curr_vif || !sta->wme)
  6105. return;
  6106. ieee80211_queue_work(iter_data->ar->hw, &arsta->tid_config_wk);
  6107. }
  6108. static int ath10k_sta_state(struct ieee80211_hw *hw,
  6109. struct ieee80211_vif *vif,
  6110. struct ieee80211_sta *sta,
  6111. enum ieee80211_sta_state old_state,
  6112. enum ieee80211_sta_state new_state)
  6113. {
  6114. struct ath10k *ar = hw->priv;
  6115. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  6116. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  6117. struct ath10k_peer *peer;
  6118. int ret = 0;
  6119. int i;
  6120. if (old_state == IEEE80211_STA_NOTEXIST &&
  6121. new_state == IEEE80211_STA_NONE) {
  6122. memset(arsta, 0, sizeof(*arsta));
  6123. arsta->arvif = arvif;
  6124. arsta->peer_ps_state = WMI_PEER_PS_STATE_DISABLED;
  6125. INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
  6126. INIT_WORK(&arsta->tid_config_wk, ath10k_sta_tid_cfg_wk);
  6127. for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
  6128. ath10k_mac_txq_init(sta->txq[i]);
  6129. }
  6130. /* cancel must be done outside the mutex to avoid deadlock */
  6131. if ((old_state == IEEE80211_STA_NONE &&
  6132. new_state == IEEE80211_STA_NOTEXIST)) {
  6133. cancel_work_sync(&arsta->update_wk);
  6134. cancel_work_sync(&arsta->tid_config_wk);
  6135. }
  6136. mutex_lock(&ar->conf_mutex);
  6137. if (old_state == IEEE80211_STA_NOTEXIST &&
  6138. new_state == IEEE80211_STA_NONE) {
  6139. /*
  6140. * New station addition.
  6141. */
  6142. enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
  6143. u32 num_tdls_stations;
  6144. ath10k_dbg(ar, ATH10K_DBG_STA,
  6145. "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
  6146. arvif->vdev_id, sta->addr,
  6147. ar->num_stations + 1, ar->max_num_stations,
  6148. ar->num_peers + 1, ar->max_num_peers);
  6149. num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
  6150. if (sta->tdls) {
  6151. if (num_tdls_stations >= ar->max_num_tdls_vdevs) {
  6152. ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
  6153. arvif->vdev_id,
  6154. ar->max_num_tdls_vdevs);
  6155. ret = -ELNRNG;
  6156. goto exit;
  6157. }
  6158. peer_type = WMI_PEER_TYPE_TDLS;
  6159. }
  6160. ret = ath10k_mac_inc_num_stations(arvif, sta);
  6161. if (ret) {
  6162. ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
  6163. ar->max_num_stations);
  6164. goto exit;
  6165. }
  6166. if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
  6167. arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats),
  6168. GFP_KERNEL);
  6169. if (!arsta->tx_stats) {
  6170. ath10k_mac_dec_num_stations(arvif, sta);
  6171. ret = -ENOMEM;
  6172. goto exit;
  6173. }
  6174. }
  6175. ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
  6176. sta->addr, peer_type);
  6177. if (ret) {
  6178. ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
  6179. sta->addr, arvif->vdev_id, ret);
  6180. ath10k_mac_dec_num_stations(arvif, sta);
  6181. kfree(arsta->tx_stats);
  6182. goto exit;
  6183. }
  6184. spin_lock_bh(&ar->data_lock);
  6185. peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
  6186. if (!peer) {
  6187. ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
  6188. vif->addr, arvif->vdev_id);
  6189. spin_unlock_bh(&ar->data_lock);
  6190. ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
  6191. ath10k_mac_dec_num_stations(arvif, sta);
  6192. kfree(arsta->tx_stats);
  6193. ret = -ENOENT;
  6194. goto exit;
  6195. }
  6196. arsta->peer_id = find_first_bit(peer->peer_ids,
  6197. ATH10K_MAX_NUM_PEER_IDS);
  6198. spin_unlock_bh(&ar->data_lock);
  6199. if (!sta->tdls)
  6200. goto exit;
  6201. ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
  6202. WMI_TDLS_ENABLE_ACTIVE);
  6203. if (ret) {
  6204. ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
  6205. arvif->vdev_id, ret);
  6206. ath10k_peer_delete(ar, arvif->vdev_id,
  6207. sta->addr);
  6208. ath10k_mac_dec_num_stations(arvif, sta);
  6209. kfree(arsta->tx_stats);
  6210. goto exit;
  6211. }
  6212. ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
  6213. WMI_TDLS_PEER_STATE_PEERING);
  6214. if (ret) {
  6215. ath10k_warn(ar,
  6216. "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
  6217. sta->addr, arvif->vdev_id, ret);
  6218. ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
  6219. ath10k_mac_dec_num_stations(arvif, sta);
  6220. kfree(arsta->tx_stats);
  6221. if (num_tdls_stations != 0)
  6222. goto exit;
  6223. ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
  6224. WMI_TDLS_DISABLE);
  6225. }
  6226. } else if ((old_state == IEEE80211_STA_NONE &&
  6227. new_state == IEEE80211_STA_NOTEXIST)) {
  6228. /*
  6229. * Existing station deletion.
  6230. */
  6231. ath10k_dbg(ar, ATH10K_DBG_STA,
  6232. "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
  6233. arvif->vdev_id, sta->addr, sta);
  6234. if (sta->tdls) {
  6235. ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
  6236. sta,
  6237. WMI_TDLS_PEER_STATE_TEARDOWN);
  6238. if (ret)
  6239. ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
  6240. sta->addr,
  6241. WMI_TDLS_PEER_STATE_TEARDOWN, ret);
  6242. }
  6243. ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
  6244. if (ret)
  6245. ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
  6246. sta->addr, arvif->vdev_id, ret);
  6247. ath10k_mac_dec_num_stations(arvif, sta);
  6248. spin_lock_bh(&ar->data_lock);
  6249. for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
  6250. peer = ar->peer_map[i];
  6251. if (!peer)
  6252. continue;
  6253. if (peer->sta == sta) {
  6254. ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
  6255. sta->addr, peer, i, arvif->vdev_id);
  6256. peer->sta = NULL;
  6257. /* Clean up the peer object as well since we
  6258. * must have failed to do this above.
  6259. */
  6260. ath10k_peer_map_cleanup(ar, peer);
  6261. }
  6262. }
  6263. spin_unlock_bh(&ar->data_lock);
  6264. if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
  6265. kfree(arsta->tx_stats);
  6266. arsta->tx_stats = NULL;
  6267. }
  6268. for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
  6269. ath10k_mac_txq_unref(ar, sta->txq[i]);
  6270. if (!sta->tdls)
  6271. goto exit;
  6272. if (ath10k_mac_tdls_vif_stations_count(hw, vif))
  6273. goto exit;
  6274. /* This was the last tdls peer in current vif */
  6275. ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
  6276. WMI_TDLS_DISABLE);
  6277. if (ret) {
  6278. ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
  6279. arvif->vdev_id, ret);
  6280. }
  6281. } else if (old_state == IEEE80211_STA_AUTH &&
  6282. new_state == IEEE80211_STA_ASSOC &&
  6283. (vif->type == NL80211_IFTYPE_AP ||
  6284. vif->type == NL80211_IFTYPE_MESH_POINT ||
  6285. vif->type == NL80211_IFTYPE_ADHOC)) {
  6286. /*
  6287. * New association.
  6288. */
  6289. ath10k_dbg(ar, ATH10K_DBG_STA, "mac sta %pM associated\n",
  6290. sta->addr);
  6291. ret = ath10k_station_assoc(ar, vif, sta, false);
  6292. if (ret)
  6293. ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
  6294. sta->addr, arvif->vdev_id, ret);
  6295. } else if (old_state == IEEE80211_STA_ASSOC &&
  6296. new_state == IEEE80211_STA_AUTHORIZED &&
  6297. sta->tdls) {
  6298. /*
  6299. * Tdls station authorized.
  6300. */
  6301. ath10k_dbg(ar, ATH10K_DBG_STA, "mac tdls sta %pM authorized\n",
  6302. sta->addr);
  6303. ret = ath10k_station_assoc(ar, vif, sta, false);
  6304. if (ret) {
  6305. ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
  6306. sta->addr, arvif->vdev_id, ret);
  6307. goto exit;
  6308. }
  6309. ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
  6310. WMI_TDLS_PEER_STATE_CONNECTED);
  6311. if (ret)
  6312. ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
  6313. sta->addr, arvif->vdev_id, ret);
  6314. } else if (old_state == IEEE80211_STA_ASSOC &&
  6315. new_state == IEEE80211_STA_AUTH &&
  6316. (vif->type == NL80211_IFTYPE_AP ||
  6317. vif->type == NL80211_IFTYPE_MESH_POINT ||
  6318. vif->type == NL80211_IFTYPE_ADHOC)) {
  6319. /*
  6320. * Disassociation.
  6321. */
  6322. ath10k_dbg(ar, ATH10K_DBG_STA, "mac sta %pM disassociated\n",
  6323. sta->addr);
  6324. ret = ath10k_station_disassoc(ar, vif, sta);
  6325. if (ret)
  6326. ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
  6327. sta->addr, arvif->vdev_id, ret);
  6328. }
  6329. exit:
  6330. mutex_unlock(&ar->conf_mutex);
  6331. return ret;
  6332. }
  6333. static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
  6334. u16 ac, bool enable)
  6335. {
  6336. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  6337. struct wmi_sta_uapsd_auto_trig_arg arg = {};
  6338. u32 prio = 0, acc = 0;
  6339. u32 value = 0;
  6340. int ret = 0;
  6341. lockdep_assert_held(&ar->conf_mutex);
  6342. if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
  6343. return 0;
  6344. switch (ac) {
  6345. case IEEE80211_AC_VO:
  6346. value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
  6347. WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
  6348. prio = 7;
  6349. acc = 3;
  6350. break;
  6351. case IEEE80211_AC_VI:
  6352. value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
  6353. WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
  6354. prio = 5;
  6355. acc = 2;
  6356. break;
  6357. case IEEE80211_AC_BE:
  6358. value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
  6359. WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
  6360. prio = 2;
  6361. acc = 1;
  6362. break;
  6363. case IEEE80211_AC_BK:
  6364. value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
  6365. WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
  6366. prio = 0;
  6367. acc = 0;
  6368. break;
  6369. }
  6370. if (enable)
  6371. arvif->u.sta.uapsd |= value;
  6372. else
  6373. arvif->u.sta.uapsd &= ~value;
  6374. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  6375. WMI_STA_PS_PARAM_UAPSD,
  6376. arvif->u.sta.uapsd);
  6377. if (ret) {
  6378. ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
  6379. goto exit;
  6380. }
  6381. if (arvif->u.sta.uapsd)
  6382. value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
  6383. else
  6384. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  6385. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  6386. WMI_STA_PS_PARAM_RX_WAKE_POLICY,
  6387. value);
  6388. if (ret)
  6389. ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
  6390. ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
  6391. if (ret) {
  6392. ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
  6393. arvif->vdev_id, ret);
  6394. return ret;
  6395. }
  6396. ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
  6397. if (ret) {
  6398. ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
  6399. arvif->vdev_id, ret);
  6400. return ret;
  6401. }
  6402. if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
  6403. test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
  6404. /* Only userspace can make an educated decision when to send
  6405. * trigger frame. The following effectively disables u-UAPSD
  6406. * autotrigger in firmware (which is enabled by default
  6407. * provided the autotrigger service is available).
  6408. */
  6409. arg.wmm_ac = acc;
  6410. arg.user_priority = prio;
  6411. arg.service_interval = 0;
  6412. arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
  6413. arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
  6414. ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
  6415. arvif->bssid, &arg, 1);
  6416. if (ret) {
  6417. ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
  6418. ret);
  6419. return ret;
  6420. }
  6421. }
  6422. exit:
  6423. return ret;
  6424. }
  6425. static int ath10k_conf_tx(struct ieee80211_hw *hw,
  6426. struct ieee80211_vif *vif,
  6427. unsigned int link_id, u16 ac,
  6428. const struct ieee80211_tx_queue_params *params)
  6429. {
  6430. struct ath10k *ar = hw->priv;
  6431. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  6432. struct wmi_wmm_params_arg *p = NULL;
  6433. int ret;
  6434. mutex_lock(&ar->conf_mutex);
  6435. switch (ac) {
  6436. case IEEE80211_AC_VO:
  6437. p = &arvif->wmm_params.ac_vo;
  6438. break;
  6439. case IEEE80211_AC_VI:
  6440. p = &arvif->wmm_params.ac_vi;
  6441. break;
  6442. case IEEE80211_AC_BE:
  6443. p = &arvif->wmm_params.ac_be;
  6444. break;
  6445. case IEEE80211_AC_BK:
  6446. p = &arvif->wmm_params.ac_bk;
  6447. break;
  6448. }
  6449. if (WARN_ON(!p)) {
  6450. ret = -EINVAL;
  6451. goto exit;
  6452. }
  6453. p->cwmin = params->cw_min;
  6454. p->cwmax = params->cw_max;
  6455. p->aifs = params->aifs;
  6456. /*
  6457. * The channel time duration programmed in the HW is in absolute
  6458. * microseconds, while mac80211 gives the txop in units of
  6459. * 32 microseconds.
  6460. */
  6461. p->txop = params->txop * 32;
  6462. if (ar->wmi.ops->gen_vdev_wmm_conf) {
  6463. ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
  6464. &arvif->wmm_params);
  6465. if (ret) {
  6466. ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
  6467. arvif->vdev_id, ret);
  6468. goto exit;
  6469. }
  6470. } else {
  6471. /* This won't work well with multi-interface cases but it's
  6472. * better than nothing.
  6473. */
  6474. ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
  6475. if (ret) {
  6476. ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
  6477. goto exit;
  6478. }
  6479. }
  6480. ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
  6481. if (ret)
  6482. ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
  6483. exit:
  6484. mutex_unlock(&ar->conf_mutex);
  6485. return ret;
  6486. }
  6487. static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
  6488. struct ieee80211_vif *vif,
  6489. struct ieee80211_channel *chan,
  6490. int duration,
  6491. enum ieee80211_roc_type type)
  6492. {
  6493. struct ath10k *ar = hw->priv;
  6494. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  6495. struct wmi_start_scan_arg arg;
  6496. int ret = 0;
  6497. u32 scan_time_msec;
  6498. mutex_lock(&ar->conf_mutex);
  6499. if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
  6500. ret = -EBUSY;
  6501. goto exit;
  6502. }
  6503. spin_lock_bh(&ar->data_lock);
  6504. switch (ar->scan.state) {
  6505. case ATH10K_SCAN_IDLE:
  6506. reinit_completion(&ar->scan.started);
  6507. reinit_completion(&ar->scan.completed);
  6508. reinit_completion(&ar->scan.on_channel);
  6509. ar->scan.state = ATH10K_SCAN_STARTING;
  6510. ar->scan.is_roc = true;
  6511. ar->scan.vdev_id = arvif->vdev_id;
  6512. ar->scan.roc_freq = chan->center_freq;
  6513. ar->scan.roc_notify = true;
  6514. ret = 0;
  6515. break;
  6516. case ATH10K_SCAN_STARTING:
  6517. case ATH10K_SCAN_RUNNING:
  6518. case ATH10K_SCAN_ABORTING:
  6519. ret = -EBUSY;
  6520. break;
  6521. }
  6522. spin_unlock_bh(&ar->data_lock);
  6523. if (ret)
  6524. goto exit;
  6525. scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
  6526. memset(&arg, 0, sizeof(arg));
  6527. ath10k_wmi_start_scan_init(ar, &arg);
  6528. arg.vdev_id = arvif->vdev_id;
  6529. arg.scan_id = ATH10K_SCAN_ID;
  6530. arg.n_channels = 1;
  6531. arg.channels[0] = chan->center_freq;
  6532. arg.dwell_time_active = scan_time_msec;
  6533. arg.dwell_time_passive = scan_time_msec;
  6534. arg.max_scan_time = scan_time_msec;
  6535. arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
  6536. arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
  6537. arg.burst_duration_ms = duration;
  6538. ret = ath10k_start_scan(ar, &arg);
  6539. if (ret) {
  6540. ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
  6541. spin_lock_bh(&ar->data_lock);
  6542. ar->scan.state = ATH10K_SCAN_IDLE;
  6543. spin_unlock_bh(&ar->data_lock);
  6544. goto exit;
  6545. }
  6546. ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
  6547. if (ret == 0) {
  6548. ath10k_warn(ar, "failed to switch to channel for roc scan\n");
  6549. ret = ath10k_scan_stop(ar);
  6550. if (ret)
  6551. ath10k_warn(ar, "failed to stop scan: %d\n", ret);
  6552. ret = -ETIMEDOUT;
  6553. goto exit;
  6554. }
  6555. ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
  6556. msecs_to_jiffies(duration));
  6557. ret = 0;
  6558. exit:
  6559. mutex_unlock(&ar->conf_mutex);
  6560. return ret;
  6561. }
  6562. static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw,
  6563. struct ieee80211_vif *vif)
  6564. {
  6565. struct ath10k *ar = hw->priv;
  6566. mutex_lock(&ar->conf_mutex);
  6567. spin_lock_bh(&ar->data_lock);
  6568. ar->scan.roc_notify = false;
  6569. spin_unlock_bh(&ar->data_lock);
  6570. ath10k_scan_abort(ar);
  6571. mutex_unlock(&ar->conf_mutex);
  6572. cancel_delayed_work_sync(&ar->scan.timeout);
  6573. return 0;
  6574. }
  6575. /*
  6576. * Both RTS and Fragmentation threshold are interface-specific
  6577. * in ath10k, but device-specific in mac80211.
  6578. */
  6579. static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  6580. {
  6581. struct ath10k *ar = hw->priv;
  6582. struct ath10k_vif *arvif;
  6583. int ret = 0;
  6584. mutex_lock(&ar->conf_mutex);
  6585. list_for_each_entry(arvif, &ar->arvifs, list) {
  6586. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
  6587. arvif->vdev_id, value);
  6588. ret = ath10k_mac_set_rts(arvif, value);
  6589. if (ret) {
  6590. ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
  6591. arvif->vdev_id, ret);
  6592. break;
  6593. }
  6594. }
  6595. mutex_unlock(&ar->conf_mutex);
  6596. return ret;
  6597. }
  6598. static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
  6599. {
  6600. /* Even though there's a WMI enum for fragmentation threshold no known
  6601. * firmware actually implements it. Moreover it is not possible to rely
  6602. * frame fragmentation to mac80211 because firmware clears the "more
  6603. * fragments" bit in frame control making it impossible for remote
  6604. * devices to reassemble frames.
  6605. *
  6606. * Hence implement a dummy callback just to say fragmentation isn't
  6607. * supported. This effectively prevents mac80211 from doing frame
  6608. * fragmentation in software.
  6609. */
  6610. return -EOPNOTSUPP;
  6611. }
  6612. void ath10k_mac_wait_tx_complete(struct ath10k *ar)
  6613. {
  6614. bool skip;
  6615. long time_left;
  6616. /* mac80211 doesn't care if we really xmit queued frames or not
  6617. * we'll collect those frames either way if we stop/delete vdevs
  6618. */
  6619. if (ar->state == ATH10K_STATE_WEDGED)
  6620. return;
  6621. time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
  6622. bool empty;
  6623. spin_lock_bh(&ar->htt.tx_lock);
  6624. empty = (ar->htt.num_pending_tx == 0);
  6625. spin_unlock_bh(&ar->htt.tx_lock);
  6626. skip = (ar->state == ATH10K_STATE_WEDGED) ||
  6627. test_bit(ATH10K_FLAG_CRASH_FLUSH,
  6628. &ar->dev_flags);
  6629. (empty || skip);
  6630. }), ATH10K_FLUSH_TIMEOUT_HZ);
  6631. if (time_left == 0 || skip)
  6632. ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
  6633. skip, ar->state, time_left);
  6634. }
  6635. static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  6636. u32 queues, bool drop)
  6637. {
  6638. struct ath10k *ar = hw->priv;
  6639. struct ath10k_vif *arvif;
  6640. u32 bitmap;
  6641. if (drop) {
  6642. if (vif && vif->type == NL80211_IFTYPE_STATION) {
  6643. bitmap = ~(1 << WMI_MGMT_TID);
  6644. list_for_each_entry(arvif, &ar->arvifs, list) {
  6645. if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
  6646. ath10k_wmi_peer_flush(ar, arvif->vdev_id,
  6647. arvif->bssid, bitmap);
  6648. }
  6649. ath10k_htt_flush_tx(&ar->htt);
  6650. }
  6651. return;
  6652. }
  6653. mutex_lock(&ar->conf_mutex);
  6654. ath10k_mac_wait_tx_complete(ar);
  6655. mutex_unlock(&ar->conf_mutex);
  6656. }
  6657. /* TODO: Implement this function properly
  6658. * For now it is needed to reply to Probe Requests in IBSS mode.
  6659. * Probably we need this information from FW.
  6660. */
  6661. static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
  6662. {
  6663. return 1;
  6664. }
  6665. static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
  6666. enum ieee80211_reconfig_type reconfig_type)
  6667. {
  6668. struct ath10k *ar = hw->priv;
  6669. struct ath10k_vif *arvif;
  6670. if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
  6671. return;
  6672. mutex_lock(&ar->conf_mutex);
  6673. /* If device failed to restart it will be in a different state, e.g.
  6674. * ATH10K_STATE_WEDGED
  6675. */
  6676. if (ar->state == ATH10K_STATE_RESTARTED) {
  6677. ath10k_info(ar, "device successfully recovered\n");
  6678. ar->state = ATH10K_STATE_ON;
  6679. ieee80211_wake_queues(ar->hw);
  6680. clear_bit(ATH10K_FLAG_RESTARTING, &ar->dev_flags);
  6681. if (ar->hw_params.hw_restart_disconnect) {
  6682. list_for_each_entry(arvif, &ar->arvifs, list) {
  6683. if (arvif->is_up && arvif->vdev_type == WMI_VDEV_TYPE_STA)
  6684. ieee80211_hw_restart_disconnect(arvif->vif);
  6685. }
  6686. }
  6687. }
  6688. mutex_unlock(&ar->conf_mutex);
  6689. }
  6690. static void
  6691. ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
  6692. struct ieee80211_channel *channel)
  6693. {
  6694. int ret;
  6695. enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
  6696. lockdep_assert_held(&ar->conf_mutex);
  6697. if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
  6698. (ar->rx_channel != channel))
  6699. return;
  6700. if (ar->scan.state != ATH10K_SCAN_IDLE) {
  6701. ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
  6702. return;
  6703. }
  6704. reinit_completion(&ar->bss_survey_done);
  6705. ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
  6706. if (ret) {
  6707. ath10k_warn(ar, "failed to send pdev bss chan info request\n");
  6708. return;
  6709. }
  6710. ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
  6711. if (!ret) {
  6712. ath10k_warn(ar, "bss channel survey timed out\n");
  6713. return;
  6714. }
  6715. }
  6716. static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
  6717. struct survey_info *survey)
  6718. {
  6719. struct ath10k *ar = hw->priv;
  6720. struct ieee80211_supported_band *sband;
  6721. struct survey_info *ar_survey = &ar->survey[idx];
  6722. int ret = 0;
  6723. mutex_lock(&ar->conf_mutex);
  6724. sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
  6725. if (sband && idx >= sband->n_channels) {
  6726. idx -= sband->n_channels;
  6727. sband = NULL;
  6728. }
  6729. if (!sband)
  6730. sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
  6731. if (!sband || idx >= sband->n_channels) {
  6732. ret = -ENOENT;
  6733. goto exit;
  6734. }
  6735. ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
  6736. spin_lock_bh(&ar->data_lock);
  6737. memcpy(survey, ar_survey, sizeof(*survey));
  6738. spin_unlock_bh(&ar->data_lock);
  6739. survey->channel = &sband->channels[idx];
  6740. if (ar->rx_channel == survey->channel)
  6741. survey->filled |= SURVEY_INFO_IN_USE;
  6742. exit:
  6743. mutex_unlock(&ar->conf_mutex);
  6744. return ret;
  6745. }
  6746. static bool
  6747. ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
  6748. enum nl80211_band band,
  6749. const struct cfg80211_bitrate_mask *mask,
  6750. int *nss)
  6751. {
  6752. struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
  6753. u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
  6754. u8 ht_nss_mask = 0;
  6755. u8 vht_nss_mask = 0;
  6756. int i;
  6757. if (mask->control[band].legacy)
  6758. return false;
  6759. for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
  6760. if (mask->control[band].ht_mcs[i] == 0)
  6761. continue;
  6762. else if (mask->control[band].ht_mcs[i] ==
  6763. sband->ht_cap.mcs.rx_mask[i])
  6764. ht_nss_mask |= BIT(i);
  6765. else
  6766. return false;
  6767. }
  6768. for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
  6769. if (mask->control[band].vht_mcs[i] == 0)
  6770. continue;
  6771. else if (mask->control[band].vht_mcs[i] ==
  6772. ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
  6773. vht_nss_mask |= BIT(i);
  6774. else
  6775. return false;
  6776. }
  6777. if (ht_nss_mask != vht_nss_mask)
  6778. return false;
  6779. if (ht_nss_mask == 0)
  6780. return false;
  6781. if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
  6782. return false;
  6783. *nss = fls(ht_nss_mask);
  6784. return true;
  6785. }
  6786. static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
  6787. u8 rate, u8 nss, u8 sgi, u8 ldpc)
  6788. {
  6789. struct ath10k *ar = arvif->ar;
  6790. u32 vdev_param;
  6791. int ret;
  6792. lockdep_assert_held(&ar->conf_mutex);
  6793. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02x nss %u sgi %u\n",
  6794. arvif->vdev_id, rate, nss, sgi);
  6795. vdev_param = ar->wmi.vdev_param->fixed_rate;
  6796. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
  6797. if (ret) {
  6798. ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
  6799. rate, ret);
  6800. return ret;
  6801. }
  6802. vdev_param = ar->wmi.vdev_param->nss;
  6803. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
  6804. if (ret) {
  6805. ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
  6806. return ret;
  6807. }
  6808. vdev_param = ar->wmi.vdev_param->sgi;
  6809. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
  6810. if (ret) {
  6811. ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
  6812. return ret;
  6813. }
  6814. vdev_param = ar->wmi.vdev_param->ldpc;
  6815. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
  6816. if (ret) {
  6817. ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
  6818. return ret;
  6819. }
  6820. return 0;
  6821. }
  6822. static bool
  6823. ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
  6824. enum nl80211_band band,
  6825. const struct cfg80211_bitrate_mask *mask,
  6826. bool allow_pfr)
  6827. {
  6828. int i;
  6829. u16 vht_mcs;
  6830. /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
  6831. * to express all VHT MCS rate masks. Effectively only the following
  6832. * ranges can be used: none, 0-7, 0-8 and 0-9.
  6833. */
  6834. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  6835. vht_mcs = mask->control[band].vht_mcs[i];
  6836. switch (vht_mcs) {
  6837. case 0:
  6838. case BIT(8) - 1:
  6839. case BIT(9) - 1:
  6840. case BIT(10) - 1:
  6841. break;
  6842. default:
  6843. if (!allow_pfr)
  6844. ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
  6845. return false;
  6846. }
  6847. }
  6848. return true;
  6849. }
  6850. static bool ath10k_mac_set_vht_bitrate_mask_fixup(struct ath10k *ar,
  6851. struct ath10k_vif *arvif,
  6852. struct ieee80211_sta *sta)
  6853. {
  6854. int err;
  6855. u8 rate = arvif->vht_pfr;
  6856. /* skip non vht and multiple rate peers */
  6857. if (!sta->deflink.vht_cap.vht_supported || arvif->vht_num_rates != 1)
  6858. return false;
  6859. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  6860. WMI_PEER_PARAM_FIXED_RATE, rate);
  6861. if (err)
  6862. ath10k_warn(ar, "failed to enable STA %pM peer fixed rate: %d\n",
  6863. sta->addr, err);
  6864. return true;
  6865. }
  6866. static void ath10k_mac_set_bitrate_mask_iter(void *data,
  6867. struct ieee80211_sta *sta)
  6868. {
  6869. struct ath10k_vif *arvif = data;
  6870. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  6871. struct ath10k *ar = arvif->ar;
  6872. if (arsta->arvif != arvif)
  6873. return;
  6874. if (ath10k_mac_set_vht_bitrate_mask_fixup(ar, arvif, sta))
  6875. return;
  6876. spin_lock_bh(&ar->data_lock);
  6877. arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
  6878. spin_unlock_bh(&ar->data_lock);
  6879. ieee80211_queue_work(ar->hw, &arsta->update_wk);
  6880. }
  6881. static void ath10k_mac_clr_bitrate_mask_iter(void *data,
  6882. struct ieee80211_sta *sta)
  6883. {
  6884. struct ath10k_vif *arvif = data;
  6885. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  6886. struct ath10k *ar = arvif->ar;
  6887. int err;
  6888. /* clear vht peers only */
  6889. if (arsta->arvif != arvif || !sta->deflink.vht_cap.vht_supported)
  6890. return;
  6891. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  6892. WMI_PEER_PARAM_FIXED_RATE,
  6893. WMI_FIXED_RATE_NONE);
  6894. if (err)
  6895. ath10k_warn(ar, "failed to clear STA %pM peer fixed rate: %d\n",
  6896. sta->addr, err);
  6897. }
  6898. static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
  6899. struct ieee80211_vif *vif,
  6900. const struct cfg80211_bitrate_mask *mask)
  6901. {
  6902. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  6903. struct cfg80211_chan_def def;
  6904. struct ath10k *ar = arvif->ar;
  6905. enum nl80211_band band;
  6906. const u8 *ht_mcs_mask;
  6907. const u16 *vht_mcs_mask;
  6908. u8 rate;
  6909. u8 nss;
  6910. u8 sgi;
  6911. u8 ldpc;
  6912. int single_nss;
  6913. int ret;
  6914. int vht_num_rates, allow_pfr;
  6915. u8 vht_pfr;
  6916. bool update_bitrate_mask = true;
  6917. if (ath10k_mac_vif_chan(vif, &def))
  6918. return -EPERM;
  6919. band = def.chan->band;
  6920. ht_mcs_mask = mask->control[band].ht_mcs;
  6921. vht_mcs_mask = mask->control[band].vht_mcs;
  6922. ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
  6923. sgi = mask->control[band].gi;
  6924. if (sgi == NL80211_TXRATE_FORCE_LGI)
  6925. return -EINVAL;
  6926. allow_pfr = test_bit(ATH10K_FW_FEATURE_PEER_FIXED_RATE,
  6927. ar->normal_mode_fw.fw_file.fw_features);
  6928. if (allow_pfr) {
  6929. mutex_lock(&ar->conf_mutex);
  6930. ieee80211_iterate_stations_atomic(ar->hw,
  6931. ath10k_mac_clr_bitrate_mask_iter,
  6932. arvif);
  6933. mutex_unlock(&ar->conf_mutex);
  6934. }
  6935. if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask,
  6936. &vht_num_rates)) {
  6937. ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
  6938. &rate, &nss,
  6939. false);
  6940. if (ret) {
  6941. ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
  6942. arvif->vdev_id, ret);
  6943. return ret;
  6944. }
  6945. } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
  6946. &single_nss)) {
  6947. rate = WMI_FIXED_RATE_NONE;
  6948. nss = single_nss;
  6949. } else {
  6950. rate = WMI_FIXED_RATE_NONE;
  6951. nss = min(ar->num_rf_chains,
  6952. max(ath10k_mac_max_ht_nss(ht_mcs_mask),
  6953. ath10k_mac_max_vht_nss(vht_mcs_mask)));
  6954. if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask,
  6955. allow_pfr)) {
  6956. u8 vht_nss;
  6957. if (!allow_pfr || vht_num_rates != 1)
  6958. return -EINVAL;
  6959. /* Reach here, firmware supports peer fixed rate and has
  6960. * single vht rate, and don't update vif birate_mask, as
  6961. * the rate only for specific peer.
  6962. */
  6963. ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
  6964. &vht_pfr,
  6965. &vht_nss,
  6966. true);
  6967. update_bitrate_mask = false;
  6968. } else {
  6969. vht_pfr = 0;
  6970. }
  6971. mutex_lock(&ar->conf_mutex);
  6972. if (update_bitrate_mask)
  6973. arvif->bitrate_mask = *mask;
  6974. arvif->vht_num_rates = vht_num_rates;
  6975. arvif->vht_pfr = vht_pfr;
  6976. ieee80211_iterate_stations_atomic(ar->hw,
  6977. ath10k_mac_set_bitrate_mask_iter,
  6978. arvif);
  6979. mutex_unlock(&ar->conf_mutex);
  6980. }
  6981. mutex_lock(&ar->conf_mutex);
  6982. ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
  6983. if (ret) {
  6984. ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
  6985. arvif->vdev_id, ret);
  6986. goto exit;
  6987. }
  6988. exit:
  6989. mutex_unlock(&ar->conf_mutex);
  6990. return ret;
  6991. }
  6992. static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
  6993. struct ieee80211_vif *vif,
  6994. struct ieee80211_sta *sta,
  6995. u32 changed)
  6996. {
  6997. struct ath10k *ar = hw->priv;
  6998. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  6999. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  7000. struct ath10k_peer *peer;
  7001. u32 bw, smps;
  7002. spin_lock_bh(&ar->data_lock);
  7003. peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
  7004. if (!peer) {
  7005. spin_unlock_bh(&ar->data_lock);
  7006. ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
  7007. sta->addr, arvif->vdev_id);
  7008. return;
  7009. }
  7010. ath10k_dbg(ar, ATH10K_DBG_STA,
  7011. "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
  7012. sta->addr, changed, sta->deflink.bandwidth,
  7013. sta->deflink.rx_nss,
  7014. sta->deflink.smps_mode);
  7015. if (changed & IEEE80211_RC_BW_CHANGED) {
  7016. bw = WMI_PEER_CHWIDTH_20MHZ;
  7017. switch (sta->deflink.bandwidth) {
  7018. case IEEE80211_STA_RX_BW_20:
  7019. bw = WMI_PEER_CHWIDTH_20MHZ;
  7020. break;
  7021. case IEEE80211_STA_RX_BW_40:
  7022. bw = WMI_PEER_CHWIDTH_40MHZ;
  7023. break;
  7024. case IEEE80211_STA_RX_BW_80:
  7025. bw = WMI_PEER_CHWIDTH_80MHZ;
  7026. break;
  7027. case IEEE80211_STA_RX_BW_160:
  7028. bw = WMI_PEER_CHWIDTH_160MHZ;
  7029. break;
  7030. default:
  7031. ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
  7032. sta->deflink.bandwidth, sta->addr);
  7033. bw = WMI_PEER_CHWIDTH_20MHZ;
  7034. break;
  7035. }
  7036. arsta->bw = bw;
  7037. }
  7038. if (changed & IEEE80211_RC_NSS_CHANGED)
  7039. arsta->nss = sta->deflink.rx_nss;
  7040. if (changed & IEEE80211_RC_SMPS_CHANGED) {
  7041. smps = WMI_PEER_SMPS_PS_NONE;
  7042. switch (sta->deflink.smps_mode) {
  7043. case IEEE80211_SMPS_AUTOMATIC:
  7044. case IEEE80211_SMPS_OFF:
  7045. smps = WMI_PEER_SMPS_PS_NONE;
  7046. break;
  7047. case IEEE80211_SMPS_STATIC:
  7048. smps = WMI_PEER_SMPS_STATIC;
  7049. break;
  7050. case IEEE80211_SMPS_DYNAMIC:
  7051. smps = WMI_PEER_SMPS_DYNAMIC;
  7052. break;
  7053. case IEEE80211_SMPS_NUM_MODES:
  7054. ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
  7055. sta->deflink.smps_mode, sta->addr);
  7056. smps = WMI_PEER_SMPS_PS_NONE;
  7057. break;
  7058. }
  7059. arsta->smps = smps;
  7060. }
  7061. arsta->changed |= changed;
  7062. spin_unlock_bh(&ar->data_lock);
  7063. ieee80211_queue_work(hw, &arsta->update_wk);
  7064. }
  7065. static void ath10k_offset_tsf(struct ieee80211_hw *hw,
  7066. struct ieee80211_vif *vif, s64 tsf_offset)
  7067. {
  7068. struct ath10k *ar = hw->priv;
  7069. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  7070. u32 offset, vdev_param;
  7071. int ret;
  7072. if (tsf_offset < 0) {
  7073. vdev_param = ar->wmi.vdev_param->dec_tsf;
  7074. offset = -tsf_offset;
  7075. } else {
  7076. vdev_param = ar->wmi.vdev_param->inc_tsf;
  7077. offset = tsf_offset;
  7078. }
  7079. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  7080. vdev_param, offset);
  7081. if (ret && ret != -EOPNOTSUPP)
  7082. ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
  7083. offset, vdev_param, ret);
  7084. }
  7085. static int ath10k_ampdu_action(struct ieee80211_hw *hw,
  7086. struct ieee80211_vif *vif,
  7087. struct ieee80211_ampdu_params *params)
  7088. {
  7089. struct ath10k *ar = hw->priv;
  7090. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  7091. struct ieee80211_sta *sta = params->sta;
  7092. enum ieee80211_ampdu_mlme_action action = params->action;
  7093. u16 tid = params->tid;
  7094. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %u action %d\n",
  7095. arvif->vdev_id, sta->addr, tid, action);
  7096. switch (action) {
  7097. case IEEE80211_AMPDU_RX_START:
  7098. case IEEE80211_AMPDU_RX_STOP:
  7099. /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
  7100. * creation/removal. Do we need to verify this?
  7101. */
  7102. return 0;
  7103. case IEEE80211_AMPDU_TX_START:
  7104. case IEEE80211_AMPDU_TX_STOP_CONT:
  7105. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  7106. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  7107. case IEEE80211_AMPDU_TX_OPERATIONAL:
  7108. /* Firmware offloads Tx aggregation entirely so deny mac80211
  7109. * Tx aggregation requests.
  7110. */
  7111. return -EOPNOTSUPP;
  7112. }
  7113. return -EINVAL;
  7114. }
  7115. static void
  7116. ath10k_mac_update_rx_channel(struct ath10k *ar,
  7117. struct ieee80211_chanctx_conf *ctx,
  7118. struct ieee80211_vif_chanctx_switch *vifs,
  7119. int n_vifs)
  7120. {
  7121. struct cfg80211_chan_def *def = NULL;
  7122. /* Both locks are required because ar->rx_channel is modified. This
  7123. * allows readers to hold either lock.
  7124. */
  7125. lockdep_assert_held(&ar->conf_mutex);
  7126. lockdep_assert_held(&ar->data_lock);
  7127. WARN_ON(ctx && vifs);
  7128. WARN_ON(vifs && !n_vifs);
  7129. /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
  7130. * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
  7131. * ppdu on Rx may reduce performance on low-end systems. It should be
  7132. * possible to make tables/hashmaps to speed the lookup up (be vary of
  7133. * cpu data cache lines though regarding sizes) but to keep the initial
  7134. * implementation simple and less intrusive fallback to the slow lookup
  7135. * only for multi-channel cases. Single-channel cases will remain to
  7136. * use the old channel derival and thus performance should not be
  7137. * affected much.
  7138. */
  7139. rcu_read_lock();
  7140. if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
  7141. ieee80211_iter_chan_contexts_atomic(ar->hw,
  7142. ath10k_mac_get_any_chandef_iter,
  7143. &def);
  7144. if (vifs)
  7145. def = &vifs[0].new_ctx->def;
  7146. ar->rx_channel = def->chan;
  7147. } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
  7148. (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
  7149. /* During driver restart due to firmware assert, since mac80211
  7150. * already has valid channel context for given radio, channel
  7151. * context iteration return num_chanctx > 0. So fix rx_channel
  7152. * when restart is in progress.
  7153. */
  7154. ar->rx_channel = ctx->def.chan;
  7155. } else {
  7156. ar->rx_channel = NULL;
  7157. }
  7158. rcu_read_unlock();
  7159. }
  7160. static void
  7161. ath10k_mac_update_vif_chan(struct ath10k *ar,
  7162. struct ieee80211_vif_chanctx_switch *vifs,
  7163. int n_vifs)
  7164. {
  7165. struct ath10k_vif *arvif;
  7166. int ret;
  7167. int i;
  7168. lockdep_assert_held(&ar->conf_mutex);
  7169. /* First stop monitor interface. Some FW versions crash if there's a
  7170. * lone monitor interface.
  7171. */
  7172. if (ar->monitor_started)
  7173. ath10k_monitor_stop(ar);
  7174. for (i = 0; i < n_vifs; i++) {
  7175. arvif = (void *)vifs[i].vif->drv_priv;
  7176. ath10k_dbg(ar, ATH10K_DBG_MAC,
  7177. "mac chanctx switch vdev_id %i freq %u->%u width %d->%d\n",
  7178. arvif->vdev_id,
  7179. vifs[i].old_ctx->def.chan->center_freq,
  7180. vifs[i].new_ctx->def.chan->center_freq,
  7181. vifs[i].old_ctx->def.width,
  7182. vifs[i].new_ctx->def.width);
  7183. if (WARN_ON(!arvif->is_started))
  7184. continue;
  7185. if (WARN_ON(!arvif->is_up))
  7186. continue;
  7187. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  7188. if (ret) {
  7189. ath10k_warn(ar, "failed to down vdev %d: %d\n",
  7190. arvif->vdev_id, ret);
  7191. continue;
  7192. }
  7193. }
  7194. /* All relevant vdevs are downed and associated channel resources
  7195. * should be available for the channel switch now.
  7196. */
  7197. spin_lock_bh(&ar->data_lock);
  7198. ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
  7199. spin_unlock_bh(&ar->data_lock);
  7200. for (i = 0; i < n_vifs; i++) {
  7201. arvif = (void *)vifs[i].vif->drv_priv;
  7202. if (WARN_ON(!arvif->is_started))
  7203. continue;
  7204. if (WARN_ON(!arvif->is_up))
  7205. continue;
  7206. ret = ath10k_mac_setup_bcn_tmpl(arvif);
  7207. if (ret)
  7208. ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
  7209. ret);
  7210. ret = ath10k_mac_setup_prb_tmpl(arvif);
  7211. if (ret)
  7212. ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
  7213. ret);
  7214. ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
  7215. if (ret) {
  7216. ath10k_warn(ar, "failed to restart vdev %d: %d\n",
  7217. arvif->vdev_id, ret);
  7218. continue;
  7219. }
  7220. ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
  7221. arvif->bssid);
  7222. if (ret) {
  7223. ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
  7224. arvif->vdev_id, ret);
  7225. continue;
  7226. }
  7227. }
  7228. ath10k_monitor_recalc(ar);
  7229. }
  7230. static int
  7231. ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
  7232. struct ieee80211_chanctx_conf *ctx)
  7233. {
  7234. struct ath10k *ar = hw->priv;
  7235. ath10k_dbg(ar, ATH10K_DBG_MAC,
  7236. "mac chanctx add freq %u width %d ptr %pK\n",
  7237. ctx->def.chan->center_freq, ctx->def.width, ctx);
  7238. mutex_lock(&ar->conf_mutex);
  7239. spin_lock_bh(&ar->data_lock);
  7240. ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
  7241. spin_unlock_bh(&ar->data_lock);
  7242. ath10k_recalc_radar_detection(ar);
  7243. ath10k_monitor_recalc(ar);
  7244. mutex_unlock(&ar->conf_mutex);
  7245. return 0;
  7246. }
  7247. static void
  7248. ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
  7249. struct ieee80211_chanctx_conf *ctx)
  7250. {
  7251. struct ath10k *ar = hw->priv;
  7252. ath10k_dbg(ar, ATH10K_DBG_MAC,
  7253. "mac chanctx remove freq %u width %d ptr %pK\n",
  7254. ctx->def.chan->center_freq, ctx->def.width, ctx);
  7255. mutex_lock(&ar->conf_mutex);
  7256. spin_lock_bh(&ar->data_lock);
  7257. ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
  7258. spin_unlock_bh(&ar->data_lock);
  7259. ath10k_recalc_radar_detection(ar);
  7260. ath10k_monitor_recalc(ar);
  7261. mutex_unlock(&ar->conf_mutex);
  7262. }
  7263. struct ath10k_mac_change_chanctx_arg {
  7264. struct ieee80211_chanctx_conf *ctx;
  7265. struct ieee80211_vif_chanctx_switch *vifs;
  7266. int n_vifs;
  7267. int next_vif;
  7268. };
  7269. static void
  7270. ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
  7271. struct ieee80211_vif *vif)
  7272. {
  7273. struct ath10k_mac_change_chanctx_arg *arg = data;
  7274. if (rcu_access_pointer(vif->bss_conf.chanctx_conf) != arg->ctx)
  7275. return;
  7276. arg->n_vifs++;
  7277. }
  7278. static void
  7279. ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
  7280. struct ieee80211_vif *vif)
  7281. {
  7282. struct ath10k_mac_change_chanctx_arg *arg = data;
  7283. struct ieee80211_chanctx_conf *ctx;
  7284. ctx = rcu_access_pointer(vif->bss_conf.chanctx_conf);
  7285. if (ctx != arg->ctx)
  7286. return;
  7287. if (WARN_ON(arg->next_vif == arg->n_vifs))
  7288. return;
  7289. arg->vifs[arg->next_vif].vif = vif;
  7290. arg->vifs[arg->next_vif].old_ctx = ctx;
  7291. arg->vifs[arg->next_vif].new_ctx = ctx;
  7292. arg->next_vif++;
  7293. }
  7294. static void
  7295. ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
  7296. struct ieee80211_chanctx_conf *ctx,
  7297. u32 changed)
  7298. {
  7299. struct ath10k *ar = hw->priv;
  7300. struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
  7301. mutex_lock(&ar->conf_mutex);
  7302. ath10k_dbg(ar, ATH10K_DBG_MAC,
  7303. "mac chanctx change freq %u width %d ptr %pK changed %x\n",
  7304. ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
  7305. /* This shouldn't really happen because channel switching should use
  7306. * switch_vif_chanctx().
  7307. */
  7308. if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
  7309. goto unlock;
  7310. if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
  7311. ieee80211_iterate_active_interfaces_atomic(
  7312. hw,
  7313. ATH10K_ITER_NORMAL_FLAGS,
  7314. ath10k_mac_change_chanctx_cnt_iter,
  7315. &arg);
  7316. if (arg.n_vifs == 0)
  7317. goto radar;
  7318. arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
  7319. GFP_KERNEL);
  7320. if (!arg.vifs)
  7321. goto radar;
  7322. ieee80211_iterate_active_interfaces_atomic(
  7323. hw,
  7324. ATH10K_ITER_NORMAL_FLAGS,
  7325. ath10k_mac_change_chanctx_fill_iter,
  7326. &arg);
  7327. ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
  7328. kfree(arg.vifs);
  7329. }
  7330. radar:
  7331. ath10k_recalc_radar_detection(ar);
  7332. /* FIXME: How to configure Rx chains properly? */
  7333. /* No other actions are actually necessary. Firmware maintains channel
  7334. * definitions per vdev internally and there's no host-side channel
  7335. * context abstraction to configure, e.g. channel width.
  7336. */
  7337. unlock:
  7338. mutex_unlock(&ar->conf_mutex);
  7339. }
  7340. static int
  7341. ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
  7342. struct ieee80211_vif *vif,
  7343. struct ieee80211_bss_conf *link_conf,
  7344. struct ieee80211_chanctx_conf *ctx)
  7345. {
  7346. struct ath10k *ar = hw->priv;
  7347. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  7348. int ret;
  7349. mutex_lock(&ar->conf_mutex);
  7350. ath10k_dbg(ar, ATH10K_DBG_MAC,
  7351. "mac chanctx assign ptr %pK vdev_id %i\n",
  7352. ctx, arvif->vdev_id);
  7353. if (WARN_ON(arvif->is_started)) {
  7354. mutex_unlock(&ar->conf_mutex);
  7355. return -EBUSY;
  7356. }
  7357. ret = ath10k_vdev_start(arvif, &ctx->def);
  7358. if (ret) {
  7359. ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
  7360. arvif->vdev_id, vif->addr,
  7361. ctx->def.chan->center_freq, ret);
  7362. goto err;
  7363. }
  7364. arvif->is_started = true;
  7365. ret = ath10k_mac_vif_setup_ps(arvif);
  7366. if (ret) {
  7367. ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
  7368. arvif->vdev_id, ret);
  7369. goto err_stop;
  7370. }
  7371. if (vif->type == NL80211_IFTYPE_MONITOR) {
  7372. ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
  7373. if (ret) {
  7374. ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
  7375. arvif->vdev_id, ret);
  7376. goto err_stop;
  7377. }
  7378. arvif->is_up = true;
  7379. }
  7380. if (ath10k_mac_can_set_cts_prot(arvif)) {
  7381. ret = ath10k_mac_set_cts_prot(arvif);
  7382. if (ret)
  7383. ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
  7384. arvif->vdev_id, ret);
  7385. }
  7386. if (ath10k_peer_stats_enabled(ar) &&
  7387. ar->hw_params.tx_stats_over_pktlog) {
  7388. ar->pktlog_filter |= ATH10K_PKTLOG_PEER_STATS;
  7389. ret = ath10k_wmi_pdev_pktlog_enable(ar,
  7390. ar->pktlog_filter);
  7391. if (ret) {
  7392. ath10k_warn(ar, "failed to enable pktlog %d\n", ret);
  7393. goto err_stop;
  7394. }
  7395. }
  7396. mutex_unlock(&ar->conf_mutex);
  7397. return 0;
  7398. err_stop:
  7399. ath10k_vdev_stop(arvif);
  7400. arvif->is_started = false;
  7401. ath10k_mac_vif_setup_ps(arvif);
  7402. err:
  7403. mutex_unlock(&ar->conf_mutex);
  7404. return ret;
  7405. }
  7406. static void
  7407. ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
  7408. struct ieee80211_vif *vif,
  7409. struct ieee80211_bss_conf *link_conf,
  7410. struct ieee80211_chanctx_conf *ctx)
  7411. {
  7412. struct ath10k *ar = hw->priv;
  7413. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  7414. int ret;
  7415. mutex_lock(&ar->conf_mutex);
  7416. ath10k_dbg(ar, ATH10K_DBG_MAC,
  7417. "mac chanctx unassign ptr %pK vdev_id %i\n",
  7418. ctx, arvif->vdev_id);
  7419. WARN_ON(!arvif->is_started);
  7420. if (vif->type == NL80211_IFTYPE_MONITOR) {
  7421. WARN_ON(!arvif->is_up);
  7422. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  7423. if (ret)
  7424. ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
  7425. arvif->vdev_id, ret);
  7426. arvif->is_up = false;
  7427. }
  7428. ret = ath10k_vdev_stop(arvif);
  7429. if (ret)
  7430. ath10k_warn(ar, "failed to stop vdev %i: %d\n",
  7431. arvif->vdev_id, ret);
  7432. arvif->is_started = false;
  7433. mutex_unlock(&ar->conf_mutex);
  7434. }
  7435. static int
  7436. ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
  7437. struct ieee80211_vif_chanctx_switch *vifs,
  7438. int n_vifs,
  7439. enum ieee80211_chanctx_switch_mode mode)
  7440. {
  7441. struct ath10k *ar = hw->priv;
  7442. mutex_lock(&ar->conf_mutex);
  7443. ath10k_dbg(ar, ATH10K_DBG_MAC,
  7444. "mac chanctx switch n_vifs %d mode %d\n",
  7445. n_vifs, mode);
  7446. ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
  7447. mutex_unlock(&ar->conf_mutex);
  7448. return 0;
  7449. }
  7450. static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
  7451. struct ieee80211_vif *vif,
  7452. struct ieee80211_sta *sta)
  7453. {
  7454. struct ath10k *ar;
  7455. struct ath10k_peer *peer;
  7456. ar = hw->priv;
  7457. list_for_each_entry(peer, &ar->peers, list)
  7458. if (peer->sta == sta)
  7459. peer->removed = true;
  7460. }
  7461. /* HT MCS parameters with Nss = 1 */
  7462. static const struct ath10k_index_ht_data_rate_type supported_ht_mcs_rate_nss1[] = {
  7463. /* MCS L20 L40 S20 S40 */
  7464. {0, { 65, 135, 72, 150} },
  7465. {1, { 130, 270, 144, 300} },
  7466. {2, { 195, 405, 217, 450} },
  7467. {3, { 260, 540, 289, 600} },
  7468. {4, { 390, 810, 433, 900} },
  7469. {5, { 520, 1080, 578, 1200} },
  7470. {6, { 585, 1215, 650, 1350} },
  7471. {7, { 650, 1350, 722, 1500} }
  7472. };
  7473. /* HT MCS parameters with Nss = 2 */
  7474. static const struct ath10k_index_ht_data_rate_type supported_ht_mcs_rate_nss2[] = {
  7475. /* MCS L20 L40 S20 S40 */
  7476. {0, {130, 270, 144, 300} },
  7477. {1, {260, 540, 289, 600} },
  7478. {2, {390, 810, 433, 900} },
  7479. {3, {520, 1080, 578, 1200} },
  7480. {4, {780, 1620, 867, 1800} },
  7481. {5, {1040, 2160, 1156, 2400} },
  7482. {6, {1170, 2430, 1300, 2700} },
  7483. {7, {1300, 2700, 1444, 3000} }
  7484. };
  7485. /* MCS parameters with Nss = 1 */
  7486. static const struct ath10k_index_vht_data_rate_type supported_vht_mcs_rate_nss1[] = {
  7487. /* MCS L80 S80 L40 S40 L20 S20 */
  7488. {0, {293, 325}, {135, 150}, {65, 72} },
  7489. {1, {585, 650}, {270, 300}, {130, 144} },
  7490. {2, {878, 975}, {405, 450}, {195, 217} },
  7491. {3, {1170, 1300}, {540, 600}, {260, 289} },
  7492. {4, {1755, 1950}, {810, 900}, {390, 433} },
  7493. {5, {2340, 2600}, {1080, 1200}, {520, 578} },
  7494. {6, {2633, 2925}, {1215, 1350}, {585, 650} },
  7495. {7, {2925, 3250}, {1350, 1500}, {650, 722} },
  7496. {8, {3510, 3900}, {1620, 1800}, {780, 867} },
  7497. {9, {3900, 4333}, {1800, 2000}, {780, 867} }
  7498. };
  7499. /*MCS parameters with Nss = 2 */
  7500. static const struct ath10k_index_vht_data_rate_type supported_vht_mcs_rate_nss2[] = {
  7501. /* MCS L80 S80 L40 S40 L20 S20 */
  7502. {0, {585, 650}, {270, 300}, {130, 144} },
  7503. {1, {1170, 1300}, {540, 600}, {260, 289} },
  7504. {2, {1755, 1950}, {810, 900}, {390, 433} },
  7505. {3, {2340, 2600}, {1080, 1200}, {520, 578} },
  7506. {4, {3510, 3900}, {1620, 1800}, {780, 867} },
  7507. {5, {4680, 5200}, {2160, 2400}, {1040, 1156} },
  7508. {6, {5265, 5850}, {2430, 2700}, {1170, 1300} },
  7509. {7, {5850, 6500}, {2700, 3000}, {1300, 1444} },
  7510. {8, {7020, 7800}, {3240, 3600}, {1560, 1733} },
  7511. {9, {7800, 8667}, {3600, 4000}, {1560, 1733} }
  7512. };
  7513. static void ath10k_mac_get_rate_flags_ht(struct ath10k *ar, u32 rate, u8 nss, u8 mcs,
  7514. u8 *flags, u8 *bw)
  7515. {
  7516. struct ath10k_index_ht_data_rate_type *mcs_rate;
  7517. u8 index;
  7518. size_t len_nss1 = ARRAY_SIZE(supported_ht_mcs_rate_nss1);
  7519. size_t len_nss2 = ARRAY_SIZE(supported_ht_mcs_rate_nss2);
  7520. if (mcs >= (len_nss1 + len_nss2)) {
  7521. ath10k_warn(ar, "not supported mcs %d in current rate table", mcs);
  7522. return;
  7523. }
  7524. mcs_rate = (struct ath10k_index_ht_data_rate_type *)
  7525. ((nss == 1) ? &supported_ht_mcs_rate_nss1 :
  7526. &supported_ht_mcs_rate_nss2);
  7527. if (mcs >= len_nss1)
  7528. index = mcs - len_nss1;
  7529. else
  7530. index = mcs;
  7531. if (rate == mcs_rate[index].supported_rate[0]) {
  7532. *bw = RATE_INFO_BW_20;
  7533. } else if (rate == mcs_rate[index].supported_rate[1]) {
  7534. *bw |= RATE_INFO_BW_40;
  7535. } else if (rate == mcs_rate[index].supported_rate[2]) {
  7536. *bw |= RATE_INFO_BW_20;
  7537. *flags |= RATE_INFO_FLAGS_SHORT_GI;
  7538. } else if (rate == mcs_rate[index].supported_rate[3]) {
  7539. *bw |= RATE_INFO_BW_40;
  7540. *flags |= RATE_INFO_FLAGS_SHORT_GI;
  7541. } else {
  7542. ath10k_warn(ar, "invalid ht params rate %d 100kbps nss %d mcs %d",
  7543. rate, nss, mcs);
  7544. }
  7545. }
  7546. static void ath10k_mac_get_rate_flags_vht(struct ath10k *ar, u32 rate, u8 nss, u8 mcs,
  7547. u8 *flags, u8 *bw)
  7548. {
  7549. struct ath10k_index_vht_data_rate_type *mcs_rate;
  7550. mcs_rate = (struct ath10k_index_vht_data_rate_type *)
  7551. ((nss == 1) ? &supported_vht_mcs_rate_nss1 :
  7552. &supported_vht_mcs_rate_nss2);
  7553. if (rate == mcs_rate[mcs].supported_VHT80_rate[0]) {
  7554. *bw = RATE_INFO_BW_80;
  7555. } else if (rate == mcs_rate[mcs].supported_VHT80_rate[1]) {
  7556. *bw = RATE_INFO_BW_80;
  7557. *flags |= RATE_INFO_FLAGS_SHORT_GI;
  7558. } else if (rate == mcs_rate[mcs].supported_VHT40_rate[0]) {
  7559. *bw = RATE_INFO_BW_40;
  7560. } else if (rate == mcs_rate[mcs].supported_VHT40_rate[1]) {
  7561. *bw = RATE_INFO_BW_40;
  7562. *flags |= RATE_INFO_FLAGS_SHORT_GI;
  7563. } else if (rate == mcs_rate[mcs].supported_VHT20_rate[0]) {
  7564. *bw = RATE_INFO_BW_20;
  7565. } else if (rate == mcs_rate[mcs].supported_VHT20_rate[1]) {
  7566. *bw = RATE_INFO_BW_20;
  7567. *flags |= RATE_INFO_FLAGS_SHORT_GI;
  7568. } else {
  7569. ath10k_warn(ar, "invalid vht params rate %d 100kbps nss %d mcs %d",
  7570. rate, nss, mcs);
  7571. }
  7572. }
  7573. static void ath10k_mac_get_rate_flags(struct ath10k *ar, u32 rate,
  7574. enum ath10k_phy_mode mode, u8 nss, u8 mcs,
  7575. u8 *flags, u8 *bw)
  7576. {
  7577. if (mode == ATH10K_PHY_MODE_HT) {
  7578. *flags = RATE_INFO_FLAGS_MCS;
  7579. ath10k_mac_get_rate_flags_ht(ar, rate, nss, mcs, flags, bw);
  7580. } else if (mode == ATH10K_PHY_MODE_VHT) {
  7581. *flags = RATE_INFO_FLAGS_VHT_MCS;
  7582. ath10k_mac_get_rate_flags_vht(ar, rate, nss, mcs, flags, bw);
  7583. }
  7584. }
  7585. static void ath10k_mac_parse_bitrate(struct ath10k *ar, u32 rate_code,
  7586. u32 bitrate_kbps, struct rate_info *rate)
  7587. {
  7588. enum ath10k_phy_mode mode = ATH10K_PHY_MODE_LEGACY;
  7589. enum wmi_rate_preamble preamble = WMI_TLV_GET_HW_RC_PREAM_V1(rate_code);
  7590. u8 nss = WMI_TLV_GET_HW_RC_NSS_V1(rate_code) + 1;
  7591. u8 mcs = WMI_TLV_GET_HW_RC_RATE_V1(rate_code);
  7592. u8 flags = 0, bw = 0;
  7593. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac parse rate code 0x%x bitrate %d kbps\n",
  7594. rate_code, bitrate_kbps);
  7595. if (preamble == WMI_RATE_PREAMBLE_HT)
  7596. mode = ATH10K_PHY_MODE_HT;
  7597. else if (preamble == WMI_RATE_PREAMBLE_VHT)
  7598. mode = ATH10K_PHY_MODE_VHT;
  7599. ath10k_mac_get_rate_flags(ar, bitrate_kbps / 100, mode, nss, mcs, &flags, &bw);
  7600. ath10k_dbg(ar, ATH10K_DBG_MAC,
  7601. "mac parse bitrate preamble %d mode %d nss %d mcs %d flags %x bw %d\n",
  7602. preamble, mode, nss, mcs, flags, bw);
  7603. rate->flags = flags;
  7604. rate->bw = bw;
  7605. rate->legacy = bitrate_kbps / 100;
  7606. rate->nss = nss;
  7607. rate->mcs = mcs;
  7608. }
  7609. static void ath10k_mac_sta_get_peer_stats_info(struct ath10k *ar,
  7610. struct ieee80211_sta *sta,
  7611. struct station_info *sinfo)
  7612. {
  7613. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  7614. struct ath10k_peer *peer;
  7615. unsigned long time_left;
  7616. int ret;
  7617. if (!(ar->hw_params.supports_peer_stats_info &&
  7618. arsta->arvif->vdev_type == WMI_VDEV_TYPE_STA))
  7619. return;
  7620. spin_lock_bh(&ar->data_lock);
  7621. peer = ath10k_peer_find(ar, arsta->arvif->vdev_id, sta->addr);
  7622. spin_unlock_bh(&ar->data_lock);
  7623. if (!peer)
  7624. return;
  7625. reinit_completion(&ar->peer_stats_info_complete);
  7626. ret = ath10k_wmi_request_peer_stats_info(ar,
  7627. arsta->arvif->vdev_id,
  7628. WMI_REQUEST_ONE_PEER_STATS_INFO,
  7629. arsta->arvif->bssid,
  7630. 0);
  7631. if (ret && ret != -EOPNOTSUPP) {
  7632. ath10k_warn(ar, "could not request peer stats info: %d\n", ret);
  7633. return;
  7634. }
  7635. time_left = wait_for_completion_timeout(&ar->peer_stats_info_complete, 3 * HZ);
  7636. if (time_left == 0) {
  7637. ath10k_warn(ar, "timed out waiting peer stats info\n");
  7638. return;
  7639. }
  7640. if (arsta->rx_rate_code != 0 && arsta->rx_bitrate_kbps != 0) {
  7641. ath10k_mac_parse_bitrate(ar, arsta->rx_rate_code,
  7642. arsta->rx_bitrate_kbps,
  7643. &sinfo->rxrate);
  7644. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
  7645. arsta->rx_rate_code = 0;
  7646. arsta->rx_bitrate_kbps = 0;
  7647. }
  7648. if (arsta->tx_rate_code != 0 && arsta->tx_bitrate_kbps != 0) {
  7649. ath10k_mac_parse_bitrate(ar, arsta->tx_rate_code,
  7650. arsta->tx_bitrate_kbps,
  7651. &sinfo->txrate);
  7652. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
  7653. arsta->tx_rate_code = 0;
  7654. arsta->tx_bitrate_kbps = 0;
  7655. }
  7656. }
  7657. static void ath10k_sta_statistics(struct ieee80211_hw *hw,
  7658. struct ieee80211_vif *vif,
  7659. struct ieee80211_sta *sta,
  7660. struct station_info *sinfo)
  7661. {
  7662. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  7663. struct ath10k *ar = arsta->arvif->ar;
  7664. if (!ath10k_peer_stats_enabled(ar))
  7665. return;
  7666. mutex_lock(&ar->conf_mutex);
  7667. ath10k_debug_fw_stats_request(ar);
  7668. mutex_unlock(&ar->conf_mutex);
  7669. sinfo->rx_duration = arsta->rx_duration;
  7670. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
  7671. if (arsta->txrate.legacy || arsta->txrate.nss) {
  7672. if (arsta->txrate.legacy) {
  7673. sinfo->txrate.legacy = arsta->txrate.legacy;
  7674. } else {
  7675. sinfo->txrate.mcs = arsta->txrate.mcs;
  7676. sinfo->txrate.nss = arsta->txrate.nss;
  7677. sinfo->txrate.bw = arsta->txrate.bw;
  7678. }
  7679. sinfo->txrate.flags = arsta->txrate.flags;
  7680. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
  7681. }
  7682. if (ar->htt.disable_tx_comp) {
  7683. sinfo->tx_failed = arsta->tx_failed;
  7684. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
  7685. }
  7686. sinfo->tx_retries = arsta->tx_retries;
  7687. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
  7688. ath10k_mac_sta_get_peer_stats_info(ar, sta, sinfo);
  7689. }
  7690. static int ath10k_mac_op_set_tid_config(struct ieee80211_hw *hw,
  7691. struct ieee80211_vif *vif,
  7692. struct ieee80211_sta *sta,
  7693. struct cfg80211_tid_config *tid_config)
  7694. {
  7695. struct ath10k *ar = hw->priv;
  7696. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  7697. struct ath10k_mac_iter_tid_conf_data data = {};
  7698. struct wmi_per_peer_per_tid_cfg_arg arg = {};
  7699. int ret, i;
  7700. mutex_lock(&ar->conf_mutex);
  7701. arg.vdev_id = arvif->vdev_id;
  7702. arvif->tids_rst = 0;
  7703. memset(arvif->tid_conf_changed, 0, sizeof(arvif->tid_conf_changed));
  7704. for (i = 0; i < tid_config->n_tid_conf; i++) {
  7705. ret = ath10k_mac_parse_tid_config(ar, sta, vif,
  7706. &tid_config->tid_conf[i],
  7707. &arg);
  7708. if (ret)
  7709. goto exit;
  7710. }
  7711. ret = 0;
  7712. if (sta)
  7713. goto exit;
  7714. arvif->tids_rst = 0;
  7715. data.curr_vif = vif;
  7716. data.ar = ar;
  7717. ieee80211_iterate_stations_atomic(hw, ath10k_mac_vif_stations_tid_conf,
  7718. &data);
  7719. exit:
  7720. mutex_unlock(&ar->conf_mutex);
  7721. return ret;
  7722. }
  7723. static int ath10k_mac_op_reset_tid_config(struct ieee80211_hw *hw,
  7724. struct ieee80211_vif *vif,
  7725. struct ieee80211_sta *sta,
  7726. u8 tids)
  7727. {
  7728. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  7729. struct ath10k_mac_iter_tid_conf_data data = {};
  7730. struct ath10k *ar = hw->priv;
  7731. int ret = 0;
  7732. mutex_lock(&ar->conf_mutex);
  7733. if (sta) {
  7734. arvif->tids_rst = 0;
  7735. ret = ath10k_mac_reset_tid_config(ar, sta, arvif, tids);
  7736. goto exit;
  7737. }
  7738. arvif->tids_rst = tids;
  7739. data.curr_vif = vif;
  7740. data.ar = ar;
  7741. ieee80211_iterate_stations_atomic(hw, ath10k_mac_vif_stations_tid_conf,
  7742. &data);
  7743. exit:
  7744. mutex_unlock(&ar->conf_mutex);
  7745. return ret;
  7746. }
  7747. static const struct ieee80211_ops ath10k_ops = {
  7748. .tx = ath10k_mac_op_tx,
  7749. .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
  7750. .start = ath10k_start,
  7751. .stop = ath10k_stop,
  7752. .config = ath10k_config,
  7753. .add_interface = ath10k_add_interface,
  7754. .update_vif_offload = ath10k_update_vif_offload,
  7755. .remove_interface = ath10k_remove_interface,
  7756. .configure_filter = ath10k_configure_filter,
  7757. .bss_info_changed = ath10k_bss_info_changed,
  7758. .set_coverage_class = ath10k_mac_op_set_coverage_class,
  7759. .hw_scan = ath10k_hw_scan,
  7760. .cancel_hw_scan = ath10k_cancel_hw_scan,
  7761. .set_key = ath10k_set_key,
  7762. .set_default_unicast_key = ath10k_set_default_unicast_key,
  7763. .sta_state = ath10k_sta_state,
  7764. .sta_set_txpwr = ath10k_sta_set_txpwr,
  7765. .conf_tx = ath10k_conf_tx,
  7766. .remain_on_channel = ath10k_remain_on_channel,
  7767. .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
  7768. .set_rts_threshold = ath10k_set_rts_threshold,
  7769. .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
  7770. .flush = ath10k_flush,
  7771. .tx_last_beacon = ath10k_tx_last_beacon,
  7772. .set_antenna = ath10k_set_antenna,
  7773. .get_antenna = ath10k_get_antenna,
  7774. .reconfig_complete = ath10k_reconfig_complete,
  7775. .get_survey = ath10k_get_survey,
  7776. .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
  7777. .sta_rc_update = ath10k_sta_rc_update,
  7778. .offset_tsf = ath10k_offset_tsf,
  7779. .ampdu_action = ath10k_ampdu_action,
  7780. .get_et_sset_count = ath10k_debug_get_et_sset_count,
  7781. .get_et_stats = ath10k_debug_get_et_stats,
  7782. .get_et_strings = ath10k_debug_get_et_strings,
  7783. .add_chanctx = ath10k_mac_op_add_chanctx,
  7784. .remove_chanctx = ath10k_mac_op_remove_chanctx,
  7785. .change_chanctx = ath10k_mac_op_change_chanctx,
  7786. .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
  7787. .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
  7788. .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
  7789. .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
  7790. .sta_statistics = ath10k_sta_statistics,
  7791. .set_tid_config = ath10k_mac_op_set_tid_config,
  7792. .reset_tid_config = ath10k_mac_op_reset_tid_config,
  7793. CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
  7794. #ifdef CONFIG_PM
  7795. .suspend = ath10k_wow_op_suspend,
  7796. .resume = ath10k_wow_op_resume,
  7797. .set_wakeup = ath10k_wow_op_set_wakeup,
  7798. #endif
  7799. #ifdef CONFIG_MAC80211_DEBUGFS
  7800. .sta_add_debugfs = ath10k_sta_add_debugfs,
  7801. #endif
  7802. .set_sar_specs = ath10k_mac_set_sar_specs,
  7803. };
  7804. #define CHAN2G(_channel, _freq, _flags) { \
  7805. .band = NL80211_BAND_2GHZ, \
  7806. .hw_value = (_channel), \
  7807. .center_freq = (_freq), \
  7808. .flags = (_flags), \
  7809. .max_antenna_gain = 0, \
  7810. .max_power = 30, \
  7811. }
  7812. #define CHAN5G(_channel, _freq, _flags) { \
  7813. .band = NL80211_BAND_5GHZ, \
  7814. .hw_value = (_channel), \
  7815. .center_freq = (_freq), \
  7816. .flags = (_flags), \
  7817. .max_antenna_gain = 0, \
  7818. .max_power = 30, \
  7819. }
  7820. static const struct ieee80211_channel ath10k_2ghz_channels[] = {
  7821. CHAN2G(1, 2412, 0),
  7822. CHAN2G(2, 2417, 0),
  7823. CHAN2G(3, 2422, 0),
  7824. CHAN2G(4, 2427, 0),
  7825. CHAN2G(5, 2432, 0),
  7826. CHAN2G(6, 2437, 0),
  7827. CHAN2G(7, 2442, 0),
  7828. CHAN2G(8, 2447, 0),
  7829. CHAN2G(9, 2452, 0),
  7830. CHAN2G(10, 2457, 0),
  7831. CHAN2G(11, 2462, 0),
  7832. CHAN2G(12, 2467, 0),
  7833. CHAN2G(13, 2472, 0),
  7834. CHAN2G(14, 2484, 0),
  7835. };
  7836. static const struct ieee80211_channel ath10k_5ghz_channels[] = {
  7837. CHAN5G(36, 5180, 0),
  7838. CHAN5G(40, 5200, 0),
  7839. CHAN5G(44, 5220, 0),
  7840. CHAN5G(48, 5240, 0),
  7841. CHAN5G(52, 5260, 0),
  7842. CHAN5G(56, 5280, 0),
  7843. CHAN5G(60, 5300, 0),
  7844. CHAN5G(64, 5320, 0),
  7845. CHAN5G(100, 5500, 0),
  7846. CHAN5G(104, 5520, 0),
  7847. CHAN5G(108, 5540, 0),
  7848. CHAN5G(112, 5560, 0),
  7849. CHAN5G(116, 5580, 0),
  7850. CHAN5G(120, 5600, 0),
  7851. CHAN5G(124, 5620, 0),
  7852. CHAN5G(128, 5640, 0),
  7853. CHAN5G(132, 5660, 0),
  7854. CHAN5G(136, 5680, 0),
  7855. CHAN5G(140, 5700, 0),
  7856. CHAN5G(144, 5720, 0),
  7857. CHAN5G(149, 5745, 0),
  7858. CHAN5G(153, 5765, 0),
  7859. CHAN5G(157, 5785, 0),
  7860. CHAN5G(161, 5805, 0),
  7861. CHAN5G(165, 5825, 0),
  7862. CHAN5G(169, 5845, 0),
  7863. CHAN5G(173, 5865, 0),
  7864. /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
  7865. /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
  7866. };
  7867. struct ath10k *ath10k_mac_create(size_t priv_size)
  7868. {
  7869. struct ieee80211_hw *hw;
  7870. struct ieee80211_ops *ops;
  7871. struct ath10k *ar;
  7872. ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
  7873. if (!ops)
  7874. return NULL;
  7875. hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
  7876. if (!hw) {
  7877. kfree(ops);
  7878. return NULL;
  7879. }
  7880. ar = hw->priv;
  7881. ar->hw = hw;
  7882. ar->ops = ops;
  7883. return ar;
  7884. }
  7885. void ath10k_mac_destroy(struct ath10k *ar)
  7886. {
  7887. struct ieee80211_ops *ops = ar->ops;
  7888. ieee80211_free_hw(ar->hw);
  7889. kfree(ops);
  7890. }
  7891. static const struct ieee80211_iface_limit ath10k_if_limits[] = {
  7892. {
  7893. .max = 8,
  7894. .types = BIT(NL80211_IFTYPE_STATION)
  7895. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  7896. },
  7897. {
  7898. .max = 3,
  7899. .types = BIT(NL80211_IFTYPE_P2P_GO)
  7900. },
  7901. {
  7902. .max = 1,
  7903. .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
  7904. },
  7905. {
  7906. .max = 7,
  7907. .types = BIT(NL80211_IFTYPE_AP)
  7908. #ifdef CONFIG_MAC80211_MESH
  7909. | BIT(NL80211_IFTYPE_MESH_POINT)
  7910. #endif
  7911. },
  7912. };
  7913. static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
  7914. {
  7915. .max = 8,
  7916. .types = BIT(NL80211_IFTYPE_AP)
  7917. #ifdef CONFIG_MAC80211_MESH
  7918. | BIT(NL80211_IFTYPE_MESH_POINT)
  7919. #endif
  7920. },
  7921. {
  7922. .max = 1,
  7923. .types = BIT(NL80211_IFTYPE_STATION)
  7924. },
  7925. };
  7926. static const struct ieee80211_iface_combination ath10k_if_comb[] = {
  7927. {
  7928. .limits = ath10k_if_limits,
  7929. .n_limits = ARRAY_SIZE(ath10k_if_limits),
  7930. .max_interfaces = 8,
  7931. .num_different_channels = 1,
  7932. .beacon_int_infra_match = true,
  7933. },
  7934. };
  7935. static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
  7936. {
  7937. .limits = ath10k_10x_if_limits,
  7938. .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
  7939. .max_interfaces = 8,
  7940. .num_different_channels = 1,
  7941. .beacon_int_infra_match = true,
  7942. .beacon_int_min_gcd = 1,
  7943. #ifdef CONFIG_ATH10K_DFS_CERTIFIED
  7944. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  7945. BIT(NL80211_CHAN_WIDTH_20) |
  7946. BIT(NL80211_CHAN_WIDTH_40) |
  7947. BIT(NL80211_CHAN_WIDTH_80),
  7948. #endif
  7949. },
  7950. };
  7951. static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
  7952. {
  7953. .max = 2,
  7954. .types = BIT(NL80211_IFTYPE_STATION),
  7955. },
  7956. {
  7957. .max = 2,
  7958. .types = BIT(NL80211_IFTYPE_AP) |
  7959. #ifdef CONFIG_MAC80211_MESH
  7960. BIT(NL80211_IFTYPE_MESH_POINT) |
  7961. #endif
  7962. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  7963. BIT(NL80211_IFTYPE_P2P_GO),
  7964. },
  7965. {
  7966. .max = 1,
  7967. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  7968. },
  7969. };
  7970. static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
  7971. {
  7972. .max = 2,
  7973. .types = BIT(NL80211_IFTYPE_STATION),
  7974. },
  7975. {
  7976. .max = 2,
  7977. .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
  7978. },
  7979. {
  7980. .max = 1,
  7981. .types = BIT(NL80211_IFTYPE_AP) |
  7982. #ifdef CONFIG_MAC80211_MESH
  7983. BIT(NL80211_IFTYPE_MESH_POINT) |
  7984. #endif
  7985. BIT(NL80211_IFTYPE_P2P_GO),
  7986. },
  7987. {
  7988. .max = 1,
  7989. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  7990. },
  7991. };
  7992. static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
  7993. {
  7994. .max = 1,
  7995. .types = BIT(NL80211_IFTYPE_STATION),
  7996. },
  7997. {
  7998. .max = 1,
  7999. .types = BIT(NL80211_IFTYPE_ADHOC),
  8000. },
  8001. };
  8002. /* FIXME: This is not thoroughly tested. These combinations may over- or
  8003. * underestimate hw/fw capabilities.
  8004. */
  8005. static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
  8006. {
  8007. .limits = ath10k_tlv_if_limit,
  8008. .num_different_channels = 1,
  8009. .max_interfaces = 4,
  8010. .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
  8011. },
  8012. {
  8013. .limits = ath10k_tlv_if_limit_ibss,
  8014. .num_different_channels = 1,
  8015. .max_interfaces = 2,
  8016. .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
  8017. },
  8018. };
  8019. static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
  8020. {
  8021. .limits = ath10k_tlv_if_limit,
  8022. .num_different_channels = 1,
  8023. .max_interfaces = 4,
  8024. .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
  8025. },
  8026. {
  8027. .limits = ath10k_tlv_qcs_if_limit,
  8028. .num_different_channels = 2,
  8029. .max_interfaces = 4,
  8030. .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
  8031. },
  8032. {
  8033. .limits = ath10k_tlv_if_limit_ibss,
  8034. .num_different_channels = 1,
  8035. .max_interfaces = 2,
  8036. .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
  8037. },
  8038. };
  8039. static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
  8040. {
  8041. .max = 1,
  8042. .types = BIT(NL80211_IFTYPE_STATION),
  8043. },
  8044. {
  8045. .max = 16,
  8046. .types = BIT(NL80211_IFTYPE_AP)
  8047. #ifdef CONFIG_MAC80211_MESH
  8048. | BIT(NL80211_IFTYPE_MESH_POINT)
  8049. #endif
  8050. },
  8051. };
  8052. static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
  8053. {
  8054. .limits = ath10k_10_4_if_limits,
  8055. .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
  8056. .max_interfaces = 16,
  8057. .num_different_channels = 1,
  8058. .beacon_int_infra_match = true,
  8059. .beacon_int_min_gcd = 1,
  8060. #ifdef CONFIG_ATH10K_DFS_CERTIFIED
  8061. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  8062. BIT(NL80211_CHAN_WIDTH_20) |
  8063. BIT(NL80211_CHAN_WIDTH_40) |
  8064. BIT(NL80211_CHAN_WIDTH_80) |
  8065. BIT(NL80211_CHAN_WIDTH_80P80) |
  8066. BIT(NL80211_CHAN_WIDTH_160),
  8067. #endif
  8068. },
  8069. };
  8070. static const struct
  8071. ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb[] = {
  8072. {
  8073. .limits = ath10k_10_4_if_limits,
  8074. .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
  8075. .max_interfaces = 16,
  8076. .num_different_channels = 1,
  8077. .beacon_int_infra_match = true,
  8078. .beacon_int_min_gcd = 100,
  8079. #ifdef CONFIG_ATH10K_DFS_CERTIFIED
  8080. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  8081. BIT(NL80211_CHAN_WIDTH_20) |
  8082. BIT(NL80211_CHAN_WIDTH_40) |
  8083. BIT(NL80211_CHAN_WIDTH_80) |
  8084. BIT(NL80211_CHAN_WIDTH_80P80) |
  8085. BIT(NL80211_CHAN_WIDTH_160),
  8086. #endif
  8087. },
  8088. };
  8089. static void ath10k_get_arvif_iter(void *data, u8 *mac,
  8090. struct ieee80211_vif *vif)
  8091. {
  8092. struct ath10k_vif_iter *arvif_iter = data;
  8093. struct ath10k_vif *arvif = (void *)vif->drv_priv;
  8094. if (arvif->vdev_id == arvif_iter->vdev_id)
  8095. arvif_iter->arvif = arvif;
  8096. }
  8097. struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
  8098. {
  8099. struct ath10k_vif_iter arvif_iter;
  8100. memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
  8101. arvif_iter.vdev_id = vdev_id;
  8102. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  8103. ATH10K_ITER_RESUME_FLAGS,
  8104. ath10k_get_arvif_iter,
  8105. &arvif_iter);
  8106. if (!arvif_iter.arvif) {
  8107. ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
  8108. return NULL;
  8109. }
  8110. return arvif_iter.arvif;
  8111. }
  8112. #define WRD_METHOD "WRDD"
  8113. #define WRDD_WIFI (0x07)
  8114. static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
  8115. {
  8116. union acpi_object *mcc_pkg;
  8117. union acpi_object *domain_type;
  8118. union acpi_object *mcc_value;
  8119. u32 i;
  8120. if (wrdd->type != ACPI_TYPE_PACKAGE ||
  8121. wrdd->package.count < 2 ||
  8122. wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
  8123. wrdd->package.elements[0].integer.value != 0) {
  8124. ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
  8125. return 0;
  8126. }
  8127. for (i = 1; i < wrdd->package.count; ++i) {
  8128. mcc_pkg = &wrdd->package.elements[i];
  8129. if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
  8130. continue;
  8131. if (mcc_pkg->package.count < 2)
  8132. continue;
  8133. if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
  8134. mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
  8135. continue;
  8136. domain_type = &mcc_pkg->package.elements[0];
  8137. if (domain_type->integer.value != WRDD_WIFI)
  8138. continue;
  8139. mcc_value = &mcc_pkg->package.elements[1];
  8140. return mcc_value->integer.value;
  8141. }
  8142. return 0;
  8143. }
  8144. static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
  8145. {
  8146. acpi_handle root_handle;
  8147. acpi_handle handle;
  8148. struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
  8149. acpi_status status;
  8150. u32 alpha2_code;
  8151. char alpha2[3];
  8152. root_handle = ACPI_HANDLE(ar->dev);
  8153. if (!root_handle)
  8154. return -EOPNOTSUPP;
  8155. status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
  8156. if (ACPI_FAILURE(status)) {
  8157. ath10k_dbg(ar, ATH10K_DBG_BOOT,
  8158. "failed to get wrd method %d\n", status);
  8159. return -EIO;
  8160. }
  8161. status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
  8162. if (ACPI_FAILURE(status)) {
  8163. ath10k_dbg(ar, ATH10K_DBG_BOOT,
  8164. "failed to call wrdc %d\n", status);
  8165. return -EIO;
  8166. }
  8167. alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
  8168. kfree(wrdd.pointer);
  8169. if (!alpha2_code)
  8170. return -EIO;
  8171. alpha2[0] = (alpha2_code >> 8) & 0xff;
  8172. alpha2[1] = (alpha2_code >> 0) & 0xff;
  8173. alpha2[2] = '\0';
  8174. ath10k_dbg(ar, ATH10K_DBG_BOOT,
  8175. "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
  8176. *rd = ath_regd_find_country_by_name(alpha2);
  8177. if (*rd == 0xffff)
  8178. return -EIO;
  8179. *rd |= COUNTRY_ERD_FLAG;
  8180. return 0;
  8181. }
  8182. static int ath10k_mac_init_rd(struct ath10k *ar)
  8183. {
  8184. int ret;
  8185. u16 rd;
  8186. ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
  8187. if (ret) {
  8188. ath10k_dbg(ar, ATH10K_DBG_BOOT,
  8189. "fallback to eeprom programmed regulatory settings\n");
  8190. rd = ar->hw_eeprom_rd;
  8191. }
  8192. ar->ath_common.regulatory.current_rd = rd;
  8193. return 0;
  8194. }
  8195. int ath10k_mac_register(struct ath10k *ar)
  8196. {
  8197. static const u32 cipher_suites[] = {
  8198. WLAN_CIPHER_SUITE_WEP40,
  8199. WLAN_CIPHER_SUITE_WEP104,
  8200. WLAN_CIPHER_SUITE_TKIP,
  8201. WLAN_CIPHER_SUITE_CCMP,
  8202. /* Do not add hardware supported ciphers before this line.
  8203. * Allow software encryption for all chips. Don't forget to
  8204. * update n_cipher_suites below.
  8205. */
  8206. WLAN_CIPHER_SUITE_AES_CMAC,
  8207. WLAN_CIPHER_SUITE_BIP_CMAC_256,
  8208. WLAN_CIPHER_SUITE_BIP_GMAC_128,
  8209. WLAN_CIPHER_SUITE_BIP_GMAC_256,
  8210. /* Only QCA99x0 and QCA4019 variants support GCMP-128, GCMP-256
  8211. * and CCMP-256 in hardware.
  8212. */
  8213. WLAN_CIPHER_SUITE_GCMP,
  8214. WLAN_CIPHER_SUITE_GCMP_256,
  8215. WLAN_CIPHER_SUITE_CCMP_256,
  8216. };
  8217. struct ieee80211_supported_band *band;
  8218. void *channels;
  8219. int ret;
  8220. if (!is_valid_ether_addr(ar->mac_addr)) {
  8221. ath10k_warn(ar, "invalid MAC address; choosing random\n");
  8222. eth_random_addr(ar->mac_addr);
  8223. }
  8224. SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
  8225. SET_IEEE80211_DEV(ar->hw, ar->dev);
  8226. BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
  8227. ARRAY_SIZE(ath10k_5ghz_channels)) !=
  8228. ATH10K_NUM_CHANS);
  8229. if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
  8230. channels = kmemdup(ath10k_2ghz_channels,
  8231. sizeof(ath10k_2ghz_channels),
  8232. GFP_KERNEL);
  8233. if (!channels) {
  8234. ret = -ENOMEM;
  8235. goto err_free;
  8236. }
  8237. band = &ar->mac.sbands[NL80211_BAND_2GHZ];
  8238. band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
  8239. band->channels = channels;
  8240. if (ar->hw_params.cck_rate_map_rev2) {
  8241. band->n_bitrates = ath10k_g_rates_rev2_size;
  8242. band->bitrates = ath10k_g_rates_rev2;
  8243. } else {
  8244. band->n_bitrates = ath10k_g_rates_size;
  8245. band->bitrates = ath10k_g_rates;
  8246. }
  8247. ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
  8248. }
  8249. if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
  8250. channels = kmemdup(ath10k_5ghz_channels,
  8251. sizeof(ath10k_5ghz_channels),
  8252. GFP_KERNEL);
  8253. if (!channels) {
  8254. ret = -ENOMEM;
  8255. goto err_free;
  8256. }
  8257. band = &ar->mac.sbands[NL80211_BAND_5GHZ];
  8258. band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
  8259. band->channels = channels;
  8260. band->n_bitrates = ath10k_a_rates_size;
  8261. band->bitrates = ath10k_a_rates;
  8262. ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
  8263. }
  8264. wiphy_read_of_freq_limits(ar->hw->wiphy);
  8265. ath10k_mac_setup_ht_vht_cap(ar);
  8266. ar->hw->wiphy->interface_modes =
  8267. BIT(NL80211_IFTYPE_STATION) |
  8268. BIT(NL80211_IFTYPE_AP) |
  8269. BIT(NL80211_IFTYPE_MESH_POINT);
  8270. ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
  8271. ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
  8272. if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
  8273. ar->hw->wiphy->interface_modes |=
  8274. BIT(NL80211_IFTYPE_P2P_DEVICE) |
  8275. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  8276. BIT(NL80211_IFTYPE_P2P_GO);
  8277. ieee80211_hw_set(ar->hw, SIGNAL_DBM);
  8278. if (!test_bit(ATH10K_FW_FEATURE_NO_PS,
  8279. ar->running_fw->fw_file.fw_features)) {
  8280. ieee80211_hw_set(ar->hw, SUPPORTS_PS);
  8281. ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
  8282. }
  8283. ieee80211_hw_set(ar->hw, MFP_CAPABLE);
  8284. ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
  8285. ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
  8286. ieee80211_hw_set(ar->hw, AP_LINK_PS);
  8287. ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
  8288. ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
  8289. ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
  8290. ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
  8291. ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
  8292. ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
  8293. ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
  8294. ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
  8295. ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
  8296. if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
  8297. ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
  8298. ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
  8299. ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  8300. if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
  8301. ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
  8302. if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
  8303. ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
  8304. ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
  8305. }
  8306. ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
  8307. ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
  8308. if (test_bit(WMI_SERVICE_NLO, ar->wmi.svc_map)) {
  8309. ar->hw->wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS;
  8310. ar->hw->wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
  8311. ar->hw->wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH;
  8312. ar->hw->wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS;
  8313. ar->hw->wiphy->max_sched_scan_plan_interval =
  8314. WMI_PNO_MAX_SCHED_SCAN_PLAN_INT;
  8315. ar->hw->wiphy->max_sched_scan_plan_iterations =
  8316. WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS;
  8317. ar->hw->wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
  8318. }
  8319. ar->hw->vif_data_size = sizeof(struct ath10k_vif);
  8320. ar->hw->sta_data_size = sizeof(struct ath10k_sta);
  8321. ar->hw->txq_data_size = sizeof(struct ath10k_txq);
  8322. ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
  8323. if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
  8324. ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  8325. /* Firmware delivers WPS/P2P Probe Requests frames to driver so
  8326. * that userspace (e.g. wpa_supplicant/hostapd) can generate
  8327. * correct Probe Responses. This is more of a hack advert..
  8328. */
  8329. ar->hw->wiphy->probe_resp_offload |=
  8330. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  8331. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  8332. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  8333. }
  8334. if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) ||
  8335. test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) {
  8336. ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  8337. if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH, ar->wmi.svc_map))
  8338. ieee80211_hw_set(ar->hw, TDLS_WIDER_BW);
  8339. }
  8340. if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
  8341. ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA);
  8342. if (ath10k_frame_mode == ATH10K_HW_TXRX_ETHERNET) {
  8343. if (ar->wmi.vdev_param->tx_encap_type !=
  8344. WMI_VDEV_PARAM_UNSUPPORTED)
  8345. ieee80211_hw_set(ar->hw, SUPPORTS_TX_ENCAP_OFFLOAD);
  8346. }
  8347. ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  8348. ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  8349. ar->hw->wiphy->max_remain_on_channel_duration = 5000;
  8350. ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  8351. ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
  8352. NL80211_FEATURE_AP_SCAN;
  8353. ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
  8354. ret = ath10k_wow_init(ar);
  8355. if (ret) {
  8356. ath10k_warn(ar, "failed to init wow: %d\n", ret);
  8357. goto err_free;
  8358. }
  8359. wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
  8360. wiphy_ext_feature_set(ar->hw->wiphy,
  8361. NL80211_EXT_FEATURE_SET_SCAN_DWELL);
  8362. wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_AQL);
  8363. if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map) ||
  8364. test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS, ar->wmi.svc_map))
  8365. wiphy_ext_feature_set(ar->hw->wiphy,
  8366. NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
  8367. if (ath10k_peer_stats_enabled(ar) ||
  8368. test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
  8369. wiphy_ext_feature_set(ar->hw->wiphy,
  8370. NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
  8371. if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map))
  8372. wiphy_ext_feature_set(ar->hw->wiphy,
  8373. NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
  8374. if (test_bit(WMI_SERVICE_TX_PWR_PER_PEER, ar->wmi.svc_map))
  8375. wiphy_ext_feature_set(ar->hw->wiphy,
  8376. NL80211_EXT_FEATURE_STA_TX_PWR);
  8377. if (test_bit(WMI_SERVICE_PEER_TID_CONFIGS_SUPPORT, ar->wmi.svc_map)) {
  8378. ar->hw->wiphy->tid_config_support.vif |=
  8379. BIT(NL80211_TID_CONFIG_ATTR_NOACK) |
  8380. BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT) |
  8381. BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG) |
  8382. BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL) |
  8383. BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
  8384. BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE);
  8385. if (test_bit(WMI_SERVICE_EXT_PEER_TID_CONFIGS_SUPPORT,
  8386. ar->wmi.svc_map)) {
  8387. ar->hw->wiphy->tid_config_support.vif |=
  8388. BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL);
  8389. }
  8390. ar->hw->wiphy->tid_config_support.peer =
  8391. ar->hw->wiphy->tid_config_support.vif;
  8392. ar->hw->wiphy->max_data_retry_count = ATH10K_MAX_RETRY_COUNT;
  8393. } else {
  8394. ar->ops->set_tid_config = NULL;
  8395. }
  8396. /*
  8397. * on LL hardware queues are managed entirely by the FW
  8398. * so we only advertise to mac we can do the queues thing
  8399. */
  8400. ar->hw->queues = IEEE80211_MAX_QUEUES;
  8401. /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
  8402. * something that vdev_ids can't reach so that we don't stop the queue
  8403. * accidentally.
  8404. */
  8405. ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
  8406. switch (ar->running_fw->fw_file.wmi_op_version) {
  8407. case ATH10K_FW_WMI_OP_VERSION_MAIN:
  8408. ar->hw->wiphy->iface_combinations = ath10k_if_comb;
  8409. ar->hw->wiphy->n_iface_combinations =
  8410. ARRAY_SIZE(ath10k_if_comb);
  8411. ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
  8412. break;
  8413. case ATH10K_FW_WMI_OP_VERSION_TLV:
  8414. if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
  8415. ar->hw->wiphy->iface_combinations =
  8416. ath10k_tlv_qcs_if_comb;
  8417. ar->hw->wiphy->n_iface_combinations =
  8418. ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
  8419. } else {
  8420. ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
  8421. ar->hw->wiphy->n_iface_combinations =
  8422. ARRAY_SIZE(ath10k_tlv_if_comb);
  8423. }
  8424. ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
  8425. break;
  8426. case ATH10K_FW_WMI_OP_VERSION_10_1:
  8427. case ATH10K_FW_WMI_OP_VERSION_10_2:
  8428. case ATH10K_FW_WMI_OP_VERSION_10_2_4:
  8429. ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
  8430. ar->hw->wiphy->n_iface_combinations =
  8431. ARRAY_SIZE(ath10k_10x_if_comb);
  8432. break;
  8433. case ATH10K_FW_WMI_OP_VERSION_10_4:
  8434. ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
  8435. ar->hw->wiphy->n_iface_combinations =
  8436. ARRAY_SIZE(ath10k_10_4_if_comb);
  8437. if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT,
  8438. ar->wmi.svc_map)) {
  8439. ar->hw->wiphy->iface_combinations =
  8440. ath10k_10_4_bcn_int_if_comb;
  8441. ar->hw->wiphy->n_iface_combinations =
  8442. ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb);
  8443. }
  8444. break;
  8445. case ATH10K_FW_WMI_OP_VERSION_UNSET:
  8446. case ATH10K_FW_WMI_OP_VERSION_MAX:
  8447. WARN_ON(1);
  8448. ret = -EINVAL;
  8449. goto err_free;
  8450. }
  8451. if (ar->hw_params.dynamic_sar_support)
  8452. ar->hw->wiphy->sar_capa = &ath10k_sar_capa;
  8453. if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
  8454. ar->hw->netdev_features = NETIF_F_HW_CSUM;
  8455. if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
  8456. /* Init ath dfs pattern detector */
  8457. ar->ath_common.debug_mask = ATH_DBG_DFS;
  8458. ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
  8459. NL80211_DFS_UNSET);
  8460. if (!ar->dfs_detector)
  8461. ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
  8462. }
  8463. ret = ath10k_mac_init_rd(ar);
  8464. if (ret) {
  8465. ath10k_err(ar, "failed to derive regdom: %d\n", ret);
  8466. goto err_dfs_detector_exit;
  8467. }
  8468. /* Disable set_coverage_class for chipsets that do not support it. */
  8469. if (!ar->hw_params.hw_ops->set_coverage_class)
  8470. ar->ops->set_coverage_class = NULL;
  8471. ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
  8472. ath10k_reg_notifier);
  8473. if (ret) {
  8474. ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
  8475. goto err_dfs_detector_exit;
  8476. }
  8477. if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
  8478. ar->hw->wiphy->features |=
  8479. NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
  8480. }
  8481. ar->hw->wiphy->cipher_suites = cipher_suites;
  8482. /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
  8483. * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
  8484. * from chip specific hw_param table.
  8485. */
  8486. if (!ar->hw_params.n_cipher_suites ||
  8487. ar->hw_params.n_cipher_suites > ARRAY_SIZE(cipher_suites)) {
  8488. ath10k_err(ar, "invalid hw_params.n_cipher_suites %d\n",
  8489. ar->hw_params.n_cipher_suites);
  8490. ar->hw_params.n_cipher_suites = 8;
  8491. }
  8492. ar->hw->wiphy->n_cipher_suites = ar->hw_params.n_cipher_suites;
  8493. wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
  8494. ar->hw->weight_multiplier = ATH10K_AIRTIME_WEIGHT_MULTIPLIER;
  8495. ret = ieee80211_register_hw(ar->hw);
  8496. if (ret) {
  8497. ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
  8498. goto err_dfs_detector_exit;
  8499. }
  8500. if (test_bit(WMI_SERVICE_PER_PACKET_SW_ENCRYPT, ar->wmi.svc_map)) {
  8501. ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
  8502. ar->hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
  8503. }
  8504. if (!ath_is_world_regd(&ar->ath_common.reg_world_copy) &&
  8505. !ath_is_world_regd(&ar->ath_common.regulatory)) {
  8506. ret = regulatory_hint(ar->hw->wiphy,
  8507. ar->ath_common.regulatory.alpha2);
  8508. if (ret)
  8509. goto err_unregister;
  8510. }
  8511. return 0;
  8512. err_unregister:
  8513. ieee80211_unregister_hw(ar->hw);
  8514. err_dfs_detector_exit:
  8515. if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
  8516. ar->dfs_detector->exit(ar->dfs_detector);
  8517. err_free:
  8518. kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
  8519. kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
  8520. SET_IEEE80211_DEV(ar->hw, NULL);
  8521. return ret;
  8522. }
  8523. void ath10k_mac_unregister(struct ath10k *ar)
  8524. {
  8525. ieee80211_unregister_hw(ar->hw);
  8526. if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
  8527. ar->dfs_detector->exit(ar->dfs_detector);
  8528. kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
  8529. kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
  8530. SET_IEEE80211_DEV(ar->hw, NULL);
  8531. }