mac.c 408 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216
  1. // SPDX-License-Identifier: BSD-3-Clause-Clear
  2. /*
  3. * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
  4. * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
  5. */
  6. #include <net/mac80211.h>
  7. #include <net/cfg80211.h>
  8. #include <linux/etherdevice.h>
  9. #include "mac.h"
  10. #include "core.h"
  11. #include "debug.h"
  12. #include "wmi.h"
  13. #include "hw.h"
  14. #include "dp_tx.h"
  15. #include "dp_rx.h"
  16. #include "testmode.h"
  17. #include "peer.h"
  18. #include "debugfs.h"
  19. #include "hif.h"
  20. #include "wow.h"
  21. #include "debugfs_sta.h"
  22. #include "dp.h"
  23. #include "dp_cmn.h"
  24. #define CHAN2G(_channel, _freq, _flags) { \
  25. .band = NL80211_BAND_2GHZ, \
  26. .hw_value = (_channel), \
  27. .center_freq = (_freq), \
  28. .flags = (_flags), \
  29. .max_antenna_gain = 0, \
  30. .max_power = 30, \
  31. }
  32. #define CHAN5G(_channel, _freq, _flags) { \
  33. .band = NL80211_BAND_5GHZ, \
  34. .hw_value = (_channel), \
  35. .center_freq = (_freq), \
  36. .flags = (_flags), \
  37. .max_antenna_gain = 0, \
  38. .max_power = 30, \
  39. }
  40. #define CHAN6G(_channel, _freq, _flags) { \
  41. .band = NL80211_BAND_6GHZ, \
  42. .hw_value = (_channel), \
  43. .center_freq = (_freq), \
  44. .flags = (_flags), \
  45. .max_antenna_gain = 0, \
  46. .max_power = 30, \
  47. }
  48. static const struct ieee80211_channel ath12k_2ghz_channels[] = {
  49. CHAN2G(1, 2412, 0),
  50. CHAN2G(2, 2417, 0),
  51. CHAN2G(3, 2422, 0),
  52. CHAN2G(4, 2427, 0),
  53. CHAN2G(5, 2432, 0),
  54. CHAN2G(6, 2437, 0),
  55. CHAN2G(7, 2442, 0),
  56. CHAN2G(8, 2447, 0),
  57. CHAN2G(9, 2452, 0),
  58. CHAN2G(10, 2457, 0),
  59. CHAN2G(11, 2462, 0),
  60. CHAN2G(12, 2467, 0),
  61. CHAN2G(13, 2472, 0),
  62. CHAN2G(14, 2484, 0),
  63. };
  64. static const struct ieee80211_channel ath12k_5ghz_channels[] = {
  65. CHAN5G(36, 5180, 0),
  66. CHAN5G(40, 5200, 0),
  67. CHAN5G(44, 5220, 0),
  68. CHAN5G(48, 5240, 0),
  69. CHAN5G(52, 5260, 0),
  70. CHAN5G(56, 5280, 0),
  71. CHAN5G(60, 5300, 0),
  72. CHAN5G(64, 5320, 0),
  73. CHAN5G(100, 5500, 0),
  74. CHAN5G(104, 5520, 0),
  75. CHAN5G(108, 5540, 0),
  76. CHAN5G(112, 5560, 0),
  77. CHAN5G(116, 5580, 0),
  78. CHAN5G(120, 5600, 0),
  79. CHAN5G(124, 5620, 0),
  80. CHAN5G(128, 5640, 0),
  81. CHAN5G(132, 5660, 0),
  82. CHAN5G(136, 5680, 0),
  83. CHAN5G(140, 5700, 0),
  84. CHAN5G(144, 5720, 0),
  85. CHAN5G(149, 5745, 0),
  86. CHAN5G(153, 5765, 0),
  87. CHAN5G(157, 5785, 0),
  88. CHAN5G(161, 5805, 0),
  89. CHAN5G(165, 5825, 0),
  90. CHAN5G(169, 5845, 0),
  91. CHAN5G(173, 5865, 0),
  92. };
  93. static const struct ieee80211_channel ath12k_6ghz_channels[] = {
  94. /* Operating Class 136 */
  95. CHAN6G(2, 5935, 0),
  96. /* Operating Classes 131-135 */
  97. CHAN6G(1, 5955, 0),
  98. CHAN6G(5, 5975, 0),
  99. CHAN6G(9, 5995, 0),
  100. CHAN6G(13, 6015, 0),
  101. CHAN6G(17, 6035, 0),
  102. CHAN6G(21, 6055, 0),
  103. CHAN6G(25, 6075, 0),
  104. CHAN6G(29, 6095, 0),
  105. CHAN6G(33, 6115, 0),
  106. CHAN6G(37, 6135, 0),
  107. CHAN6G(41, 6155, 0),
  108. CHAN6G(45, 6175, 0),
  109. CHAN6G(49, 6195, 0),
  110. CHAN6G(53, 6215, 0),
  111. CHAN6G(57, 6235, 0),
  112. CHAN6G(61, 6255, 0),
  113. CHAN6G(65, 6275, 0),
  114. CHAN6G(69, 6295, 0),
  115. CHAN6G(73, 6315, 0),
  116. CHAN6G(77, 6335, 0),
  117. CHAN6G(81, 6355, 0),
  118. CHAN6G(85, 6375, 0),
  119. CHAN6G(89, 6395, 0),
  120. CHAN6G(93, 6415, 0),
  121. CHAN6G(97, 6435, 0),
  122. CHAN6G(101, 6455, 0),
  123. CHAN6G(105, 6475, 0),
  124. CHAN6G(109, 6495, 0),
  125. CHAN6G(113, 6515, 0),
  126. CHAN6G(117, 6535, 0),
  127. CHAN6G(121, 6555, 0),
  128. CHAN6G(125, 6575, 0),
  129. CHAN6G(129, 6595, 0),
  130. CHAN6G(133, 6615, 0),
  131. CHAN6G(137, 6635, 0),
  132. CHAN6G(141, 6655, 0),
  133. CHAN6G(145, 6675, 0),
  134. CHAN6G(149, 6695, 0),
  135. CHAN6G(153, 6715, 0),
  136. CHAN6G(157, 6735, 0),
  137. CHAN6G(161, 6755, 0),
  138. CHAN6G(165, 6775, 0),
  139. CHAN6G(169, 6795, 0),
  140. CHAN6G(173, 6815, 0),
  141. CHAN6G(177, 6835, 0),
  142. CHAN6G(181, 6855, 0),
  143. CHAN6G(185, 6875, 0),
  144. CHAN6G(189, 6895, 0),
  145. CHAN6G(193, 6915, 0),
  146. CHAN6G(197, 6935, 0),
  147. CHAN6G(201, 6955, 0),
  148. CHAN6G(205, 6975, 0),
  149. CHAN6G(209, 6995, 0),
  150. CHAN6G(213, 7015, 0),
  151. CHAN6G(217, 7035, 0),
  152. CHAN6G(221, 7055, 0),
  153. CHAN6G(225, 7075, 0),
  154. CHAN6G(229, 7095, 0),
  155. CHAN6G(233, 7115, 0),
  156. };
  157. static struct ieee80211_rate ath12k_legacy_rates[] = {
  158. { .bitrate = 10,
  159. .hw_value = ATH12K_HW_RATE_CCK_LP_1M },
  160. { .bitrate = 20,
  161. .hw_value = ATH12K_HW_RATE_CCK_LP_2M,
  162. .hw_value_short = ATH12K_HW_RATE_CCK_SP_2M,
  163. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  164. { .bitrate = 55,
  165. .hw_value = ATH12K_HW_RATE_CCK_LP_5_5M,
  166. .hw_value_short = ATH12K_HW_RATE_CCK_SP_5_5M,
  167. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  168. { .bitrate = 110,
  169. .hw_value = ATH12K_HW_RATE_CCK_LP_11M,
  170. .hw_value_short = ATH12K_HW_RATE_CCK_SP_11M,
  171. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  172. { .bitrate = 60, .hw_value = ATH12K_HW_RATE_OFDM_6M },
  173. { .bitrate = 90, .hw_value = ATH12K_HW_RATE_OFDM_9M },
  174. { .bitrate = 120, .hw_value = ATH12K_HW_RATE_OFDM_12M },
  175. { .bitrate = 180, .hw_value = ATH12K_HW_RATE_OFDM_18M },
  176. { .bitrate = 240, .hw_value = ATH12K_HW_RATE_OFDM_24M },
  177. { .bitrate = 360, .hw_value = ATH12K_HW_RATE_OFDM_36M },
  178. { .bitrate = 480, .hw_value = ATH12K_HW_RATE_OFDM_48M },
  179. { .bitrate = 540, .hw_value = ATH12K_HW_RATE_OFDM_54M },
  180. };
  181. static const int
  182. ath12k_phymodes[NUM_NL80211_BANDS][ATH12K_CHAN_WIDTH_NUM] = {
  183. [NL80211_BAND_2GHZ] = {
  184. [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
  185. [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
  186. [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20_2G,
  187. [NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20_2G,
  188. [NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40_2G,
  189. [NL80211_CHAN_WIDTH_80] = MODE_UNKNOWN,
  190. [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN,
  191. [NL80211_CHAN_WIDTH_160] = MODE_UNKNOWN,
  192. [NL80211_CHAN_WIDTH_320] = MODE_UNKNOWN,
  193. },
  194. [NL80211_BAND_5GHZ] = {
  195. [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
  196. [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
  197. [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20,
  198. [NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20,
  199. [NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40,
  200. [NL80211_CHAN_WIDTH_80] = MODE_11BE_EHT80,
  201. [NL80211_CHAN_WIDTH_160] = MODE_11BE_EHT160,
  202. [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN,
  203. [NL80211_CHAN_WIDTH_320] = MODE_11BE_EHT320,
  204. },
  205. [NL80211_BAND_6GHZ] = {
  206. [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
  207. [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
  208. [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20,
  209. [NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20,
  210. [NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40,
  211. [NL80211_CHAN_WIDTH_80] = MODE_11BE_EHT80,
  212. [NL80211_CHAN_WIDTH_160] = MODE_11BE_EHT160,
  213. [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN,
  214. [NL80211_CHAN_WIDTH_320] = MODE_11BE_EHT320,
  215. },
  216. };
  217. const struct htt_rx_ring_tlv_filter ath12k_mac_mon_status_filter_default = {
  218. .rx_filter = HTT_RX_FILTER_TLV_FLAGS_MPDU_START |
  219. HTT_RX_FILTER_TLV_FLAGS_PPDU_END |
  220. HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE |
  221. HTT_RX_FILTER_TLV_FLAGS_PPDU_START_USER_INFO,
  222. .pkt_filter_flags0 = HTT_RX_FP_MGMT_FILTER_FLAGS0,
  223. .pkt_filter_flags1 = HTT_RX_FP_MGMT_FILTER_FLAGS1,
  224. .pkt_filter_flags2 = HTT_RX_FP_CTRL_FILTER_FLASG2,
  225. .pkt_filter_flags3 = HTT_RX_FP_DATA_FILTER_FLASG3 |
  226. HTT_RX_FP_CTRL_FILTER_FLASG3
  227. };
  228. #define ATH12K_MAC_FIRST_OFDM_RATE_IDX 4
  229. #define ath12k_g_rates ath12k_legacy_rates
  230. #define ath12k_g_rates_size (ARRAY_SIZE(ath12k_legacy_rates))
  231. #define ath12k_a_rates (ath12k_legacy_rates + 4)
  232. #define ath12k_a_rates_size (ARRAY_SIZE(ath12k_legacy_rates) - 4)
  233. #define ATH12K_MAC_SCAN_TIMEOUT_MSECS 200 /* in msecs */
  234. static const u32 ath12k_smps_map[] = {
  235. [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
  236. [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
  237. [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
  238. [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
  239. };
  240. static int ath12k_start_vdev_delay(struct ath12k *ar,
  241. struct ath12k_link_vif *arvif);
  242. static void ath12k_mac_stop(struct ath12k *ar);
  243. static int ath12k_mac_vdev_create(struct ath12k *ar, struct ath12k_link_vif *arvif);
  244. static int ath12k_mac_vdev_delete(struct ath12k *ar, struct ath12k_link_vif *arvif);
  245. static const char *ath12k_mac_phymode_str(enum wmi_phy_mode mode)
  246. {
  247. switch (mode) {
  248. case MODE_11A:
  249. return "11a";
  250. case MODE_11G:
  251. return "11g";
  252. case MODE_11B:
  253. return "11b";
  254. case MODE_11GONLY:
  255. return "11gonly";
  256. case MODE_11NA_HT20:
  257. return "11na-ht20";
  258. case MODE_11NG_HT20:
  259. return "11ng-ht20";
  260. case MODE_11NA_HT40:
  261. return "11na-ht40";
  262. case MODE_11NG_HT40:
  263. return "11ng-ht40";
  264. case MODE_11AC_VHT20:
  265. return "11ac-vht20";
  266. case MODE_11AC_VHT40:
  267. return "11ac-vht40";
  268. case MODE_11AC_VHT80:
  269. return "11ac-vht80";
  270. case MODE_11AC_VHT160:
  271. return "11ac-vht160";
  272. case MODE_11AC_VHT80_80:
  273. return "11ac-vht80+80";
  274. case MODE_11AC_VHT20_2G:
  275. return "11ac-vht20-2g";
  276. case MODE_11AC_VHT40_2G:
  277. return "11ac-vht40-2g";
  278. case MODE_11AC_VHT80_2G:
  279. return "11ac-vht80-2g";
  280. case MODE_11AX_HE20:
  281. return "11ax-he20";
  282. case MODE_11AX_HE40:
  283. return "11ax-he40";
  284. case MODE_11AX_HE80:
  285. return "11ax-he80";
  286. case MODE_11AX_HE80_80:
  287. return "11ax-he80+80";
  288. case MODE_11AX_HE160:
  289. return "11ax-he160";
  290. case MODE_11AX_HE20_2G:
  291. return "11ax-he20-2g";
  292. case MODE_11AX_HE40_2G:
  293. return "11ax-he40-2g";
  294. case MODE_11AX_HE80_2G:
  295. return "11ax-he80-2g";
  296. case MODE_11BE_EHT20:
  297. return "11be-eht20";
  298. case MODE_11BE_EHT40:
  299. return "11be-eht40";
  300. case MODE_11BE_EHT80:
  301. return "11be-eht80";
  302. case MODE_11BE_EHT80_80:
  303. return "11be-eht80+80";
  304. case MODE_11BE_EHT160:
  305. return "11be-eht160";
  306. case MODE_11BE_EHT160_160:
  307. return "11be-eht160+160";
  308. case MODE_11BE_EHT320:
  309. return "11be-eht320";
  310. case MODE_11BE_EHT20_2G:
  311. return "11be-eht20-2g";
  312. case MODE_11BE_EHT40_2G:
  313. return "11be-eht40-2g";
  314. case MODE_UNKNOWN:
  315. /* skip */
  316. break;
  317. /* no default handler to allow compiler to check that the
  318. * enum is fully handled
  319. */
  320. }
  321. return "<unknown>";
  322. }
  323. u16 ath12k_mac_he_convert_tones_to_ru_tones(u16 tones)
  324. {
  325. switch (tones) {
  326. case 26:
  327. return RU_26;
  328. case 52:
  329. return RU_52;
  330. case 106:
  331. return RU_106;
  332. case 242:
  333. return RU_242;
  334. case 484:
  335. return RU_484;
  336. case 996:
  337. return RU_996;
  338. case (996 * 2):
  339. return RU_2X996;
  340. default:
  341. return RU_26;
  342. }
  343. }
  344. EXPORT_SYMBOL(ath12k_mac_he_convert_tones_to_ru_tones);
  345. enum nl80211_eht_gi ath12k_mac_eht_gi_to_nl80211_eht_gi(u8 sgi)
  346. {
  347. switch (sgi) {
  348. case RX_MSDU_START_SGI_0_8_US:
  349. return NL80211_RATE_INFO_EHT_GI_0_8;
  350. case RX_MSDU_START_SGI_1_6_US:
  351. return NL80211_RATE_INFO_EHT_GI_1_6;
  352. case RX_MSDU_START_SGI_3_2_US:
  353. return NL80211_RATE_INFO_EHT_GI_3_2;
  354. default:
  355. return NL80211_RATE_INFO_EHT_GI_0_8;
  356. }
  357. }
  358. EXPORT_SYMBOL(ath12k_mac_eht_gi_to_nl80211_eht_gi);
  359. enum nl80211_eht_ru_alloc ath12k_mac_eht_ru_tones_to_nl80211_eht_ru_alloc(u16 ru_tones)
  360. {
  361. switch (ru_tones) {
  362. case 26:
  363. return NL80211_RATE_INFO_EHT_RU_ALLOC_26;
  364. case 52:
  365. return NL80211_RATE_INFO_EHT_RU_ALLOC_52;
  366. case (52 + 26):
  367. return NL80211_RATE_INFO_EHT_RU_ALLOC_52P26;
  368. case 106:
  369. return NL80211_RATE_INFO_EHT_RU_ALLOC_106;
  370. case (106 + 26):
  371. return NL80211_RATE_INFO_EHT_RU_ALLOC_106P26;
  372. case 242:
  373. return NL80211_RATE_INFO_EHT_RU_ALLOC_242;
  374. case 484:
  375. return NL80211_RATE_INFO_EHT_RU_ALLOC_484;
  376. case (484 + 242):
  377. return NL80211_RATE_INFO_EHT_RU_ALLOC_484P242;
  378. case 996:
  379. return NL80211_RATE_INFO_EHT_RU_ALLOC_996;
  380. case (996 + 484):
  381. return NL80211_RATE_INFO_EHT_RU_ALLOC_996P484;
  382. case (996 + 484 + 242):
  383. return NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242;
  384. case (2 * 996):
  385. return NL80211_RATE_INFO_EHT_RU_ALLOC_2x996;
  386. case (2 * 996 + 484):
  387. return NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484;
  388. case (3 * 996):
  389. return NL80211_RATE_INFO_EHT_RU_ALLOC_3x996;
  390. case (3 * 996 + 484):
  391. return NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484;
  392. case (4 * 996):
  393. return NL80211_RATE_INFO_EHT_RU_ALLOC_4x996;
  394. default:
  395. return NL80211_RATE_INFO_EHT_RU_ALLOC_26;
  396. }
  397. }
  398. EXPORT_SYMBOL(ath12k_mac_eht_ru_tones_to_nl80211_eht_ru_alloc);
  399. enum rate_info_bw
  400. ath12k_mac_bw_to_mac80211_bw(enum ath12k_supported_bw bw)
  401. {
  402. u8 ret = RATE_INFO_BW_20;
  403. switch (bw) {
  404. case ATH12K_BW_20:
  405. ret = RATE_INFO_BW_20;
  406. break;
  407. case ATH12K_BW_40:
  408. ret = RATE_INFO_BW_40;
  409. break;
  410. case ATH12K_BW_80:
  411. ret = RATE_INFO_BW_80;
  412. break;
  413. case ATH12K_BW_160:
  414. ret = RATE_INFO_BW_160;
  415. break;
  416. case ATH12K_BW_320:
  417. ret = RATE_INFO_BW_320;
  418. break;
  419. }
  420. return ret;
  421. }
  422. EXPORT_SYMBOL(ath12k_mac_bw_to_mac80211_bw);
  423. enum ath12k_supported_bw ath12k_mac_mac80211_bw_to_ath12k_bw(enum rate_info_bw bw)
  424. {
  425. switch (bw) {
  426. case RATE_INFO_BW_20:
  427. return ATH12K_BW_20;
  428. case RATE_INFO_BW_40:
  429. return ATH12K_BW_40;
  430. case RATE_INFO_BW_80:
  431. return ATH12K_BW_80;
  432. case RATE_INFO_BW_160:
  433. return ATH12K_BW_160;
  434. case RATE_INFO_BW_320:
  435. return ATH12K_BW_320;
  436. default:
  437. return ATH12K_BW_20;
  438. }
  439. }
  440. int ath12k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx,
  441. u16 *rate)
  442. {
  443. /* As default, it is OFDM rates */
  444. int i = ATH12K_MAC_FIRST_OFDM_RATE_IDX;
  445. int max_rates_idx = ath12k_g_rates_size;
  446. if (preamble == WMI_RATE_PREAMBLE_CCK) {
  447. hw_rc &= ~ATH12K_HW_RATECODE_CCK_SHORT_PREAM_MASK;
  448. i = 0;
  449. max_rates_idx = ATH12K_MAC_FIRST_OFDM_RATE_IDX;
  450. }
  451. while (i < max_rates_idx) {
  452. if (hw_rc == ath12k_legacy_rates[i].hw_value) {
  453. *rateidx = i;
  454. *rate = ath12k_legacy_rates[i].bitrate;
  455. return 0;
  456. }
  457. i++;
  458. }
  459. return -EINVAL;
  460. }
  461. EXPORT_SYMBOL(ath12k_mac_hw_ratecode_to_legacy_rate);
  462. u8 ath12k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
  463. u32 bitrate)
  464. {
  465. int i;
  466. for (i = 0; i < sband->n_bitrates; i++)
  467. if (sband->bitrates[i].bitrate == bitrate)
  468. return i;
  469. return 0;
  470. }
  471. static u32
  472. ath12k_mac_max_ht_nss(const u8 *ht_mcs_mask)
  473. {
  474. int nss;
  475. for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
  476. if (ht_mcs_mask[nss])
  477. return nss + 1;
  478. return 1;
  479. }
  480. static u32
  481. ath12k_mac_max_vht_nss(const u16 *vht_mcs_mask)
  482. {
  483. int nss;
  484. for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
  485. if (vht_mcs_mask[nss])
  486. return nss + 1;
  487. return 1;
  488. }
  489. static u32
  490. ath12k_mac_max_he_nss(const u16 he_mcs_mask[NL80211_HE_NSS_MAX])
  491. {
  492. int nss;
  493. for (nss = NL80211_HE_NSS_MAX - 1; nss >= 0; nss--)
  494. if (he_mcs_mask[nss])
  495. return nss + 1;
  496. return 1;
  497. }
  498. static u32
  499. ath12k_mac_max_eht_nss(const u16 eht_mcs_mask[NL80211_EHT_NSS_MAX])
  500. {
  501. int nss;
  502. for (nss = NL80211_EHT_NSS_MAX - 1; nss >= 0; nss--)
  503. if (eht_mcs_mask[nss])
  504. return nss + 1;
  505. return 1;
  506. }
  507. static u32
  508. ath12k_mac_max_eht_mcs_nss(const u8 *eht_mcs, int eht_mcs_set_size)
  509. {
  510. int i;
  511. u8 nss = 0;
  512. for (i = 0; i < eht_mcs_set_size; i++)
  513. nss = max(nss, u8_get_bits(eht_mcs[i], IEEE80211_EHT_MCS_NSS_RX));
  514. return nss;
  515. }
  516. static u8 ath12k_parse_mpdudensity(u8 mpdudensity)
  517. {
  518. /* From IEEE Std 802.11-2020 defined values for "Minimum MPDU Start Spacing":
  519. * 0 for no restriction
  520. * 1 for 1/4 us
  521. * 2 for 1/2 us
  522. * 3 for 1 us
  523. * 4 for 2 us
  524. * 5 for 4 us
  525. * 6 for 8 us
  526. * 7 for 16 us
  527. */
  528. switch (mpdudensity) {
  529. case 0:
  530. return 0;
  531. case 1:
  532. case 2:
  533. case 3:
  534. /* Our lower layer calculations limit our precision to
  535. * 1 microsecond
  536. */
  537. return 1;
  538. case 4:
  539. return 2;
  540. case 5:
  541. return 4;
  542. case 6:
  543. return 8;
  544. case 7:
  545. return 16;
  546. default:
  547. return 0;
  548. }
  549. }
  550. static int ath12k_mac_vif_link_chan(struct ieee80211_vif *vif, u8 link_id,
  551. struct cfg80211_chan_def *def)
  552. {
  553. struct ieee80211_bss_conf *link_conf;
  554. struct ieee80211_chanctx_conf *conf;
  555. rcu_read_lock();
  556. link_conf = rcu_dereference(vif->link_conf[link_id]);
  557. if (!link_conf) {
  558. rcu_read_unlock();
  559. return -ENOLINK;
  560. }
  561. conf = rcu_dereference(link_conf->chanctx_conf);
  562. if (!conf) {
  563. rcu_read_unlock();
  564. return -ENOENT;
  565. }
  566. *def = conf->def;
  567. rcu_read_unlock();
  568. return 0;
  569. }
  570. static struct ath12k_link_vif *
  571. ath12k_mac_get_tx_arvif(struct ath12k_link_vif *arvif,
  572. struct ieee80211_bss_conf *link_conf)
  573. {
  574. struct ieee80211_bss_conf *tx_bss_conf;
  575. struct ath12k *ar = arvif->ar;
  576. struct ath12k_vif *tx_ahvif;
  577. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  578. tx_bss_conf = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy,
  579. link_conf->tx_bss_conf);
  580. if (tx_bss_conf) {
  581. tx_ahvif = ath12k_vif_to_ahvif(tx_bss_conf->vif);
  582. return wiphy_dereference(tx_ahvif->ah->hw->wiphy,
  583. tx_ahvif->link[tx_bss_conf->link_id]);
  584. }
  585. return NULL;
  586. }
  587. static const u8 *ath12k_mac_get_tx_bssid(struct ath12k_link_vif *arvif)
  588. {
  589. struct ieee80211_bss_conf *link_conf;
  590. struct ath12k_link_vif *tx_arvif;
  591. struct ath12k *ar = arvif->ar;
  592. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  593. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  594. if (!link_conf) {
  595. ath12k_warn(ar->ab,
  596. "unable to access bss link conf for link %u required to retrieve transmitting link conf\n",
  597. arvif->link_id);
  598. return NULL;
  599. }
  600. if (link_conf->vif->type == NL80211_IFTYPE_STATION) {
  601. if (link_conf->nontransmitted)
  602. return link_conf->transmitter_bssid;
  603. } else {
  604. tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf);
  605. if (tx_arvif)
  606. return tx_arvif->bssid;
  607. }
  608. return NULL;
  609. }
  610. struct ieee80211_bss_conf *
  611. ath12k_mac_get_link_bss_conf(struct ath12k_link_vif *arvif)
  612. {
  613. struct ieee80211_vif *vif = arvif->ahvif->vif;
  614. struct ieee80211_bss_conf *link_conf;
  615. struct ath12k *ar = arvif->ar;
  616. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  617. if (arvif->link_id >= IEEE80211_MLD_MAX_NUM_LINKS)
  618. return NULL;
  619. link_conf = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy,
  620. vif->link_conf[arvif->link_id]);
  621. return link_conf;
  622. }
  623. static struct ieee80211_link_sta *ath12k_mac_get_link_sta(struct ath12k_link_sta *arsta)
  624. {
  625. struct ath12k_sta *ahsta = arsta->ahsta;
  626. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta);
  627. struct ieee80211_link_sta *link_sta;
  628. lockdep_assert_wiphy(ahsta->ahvif->ah->hw->wiphy);
  629. if (arsta->link_id >= IEEE80211_MLD_MAX_NUM_LINKS)
  630. return NULL;
  631. link_sta = wiphy_dereference(ahsta->ahvif->ah->hw->wiphy,
  632. sta->link[arsta->link_id]);
  633. return link_sta;
  634. }
  635. static bool ath12k_mac_bitrate_is_cck(int bitrate)
  636. {
  637. switch (bitrate) {
  638. case 10:
  639. case 20:
  640. case 55:
  641. case 110:
  642. return true;
  643. }
  644. return false;
  645. }
  646. u8 ath12k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
  647. u8 hw_rate, bool cck)
  648. {
  649. const struct ieee80211_rate *rate;
  650. int i;
  651. for (i = 0; i < sband->n_bitrates; i++) {
  652. rate = &sband->bitrates[i];
  653. if (ath12k_mac_bitrate_is_cck(rate->bitrate) != cck)
  654. continue;
  655. if (rate->hw_value == hw_rate)
  656. return i;
  657. else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
  658. rate->hw_value_short == hw_rate)
  659. return i;
  660. }
  661. return 0;
  662. }
  663. static u8 ath12k_mac_bitrate_to_rate(int bitrate)
  664. {
  665. return DIV_ROUND_UP(bitrate, 5) |
  666. (ath12k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
  667. }
  668. static void ath12k_get_arvif_iter(void *data, u8 *mac,
  669. struct ieee80211_vif *vif)
  670. {
  671. struct ath12k_vif_iter *arvif_iter = data;
  672. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  673. unsigned long links_map = ahvif->links_map;
  674. struct ath12k_link_vif *arvif;
  675. u8 link_id;
  676. for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) {
  677. arvif = rcu_dereference(ahvif->link[link_id]);
  678. if (WARN_ON(!arvif))
  679. continue;
  680. if (!arvif->is_created)
  681. continue;
  682. if (arvif->vdev_id == arvif_iter->vdev_id &&
  683. arvif->ar == arvif_iter->ar) {
  684. arvif_iter->arvif = arvif;
  685. break;
  686. }
  687. }
  688. }
  689. struct ath12k_link_vif *ath12k_mac_get_arvif(struct ath12k *ar, u32 vdev_id)
  690. {
  691. struct ath12k_vif_iter arvif_iter = {};
  692. u32 flags;
  693. /* To use the arvif returned, caller must have held rcu read lock.
  694. */
  695. WARN_ON(!rcu_read_lock_any_held());
  696. arvif_iter.vdev_id = vdev_id;
  697. arvif_iter.ar = ar;
  698. flags = IEEE80211_IFACE_ITER_RESUME_ALL;
  699. ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar),
  700. flags,
  701. ath12k_get_arvif_iter,
  702. &arvif_iter);
  703. if (!arvif_iter.arvif) {
  704. ath12k_warn(ar->ab, "No VIF found for vdev %d\n", vdev_id);
  705. return NULL;
  706. }
  707. return arvif_iter.arvif;
  708. }
  709. struct ath12k_link_vif *ath12k_mac_get_arvif_by_vdev_id(struct ath12k_base *ab,
  710. u32 vdev_id)
  711. {
  712. int i;
  713. struct ath12k_pdev *pdev;
  714. struct ath12k_link_vif *arvif;
  715. for (i = 0; i < ab->num_radios; i++) {
  716. pdev = rcu_dereference(ab->pdevs_active[i]);
  717. if (pdev && pdev->ar &&
  718. (pdev->ar->allocated_vdev_map & (1LL << vdev_id))) {
  719. arvif = ath12k_mac_get_arvif(pdev->ar, vdev_id);
  720. if (arvif)
  721. return arvif;
  722. }
  723. }
  724. return NULL;
  725. }
  726. struct ath12k *ath12k_mac_get_ar_by_vdev_id(struct ath12k_base *ab, u32 vdev_id)
  727. {
  728. int i;
  729. struct ath12k_pdev *pdev;
  730. for (i = 0; i < ab->num_radios; i++) {
  731. pdev = rcu_dereference(ab->pdevs_active[i]);
  732. if (pdev && pdev->ar) {
  733. if (pdev->ar->allocated_vdev_map & (1LL << vdev_id))
  734. return pdev->ar;
  735. }
  736. }
  737. return NULL;
  738. }
  739. struct ath12k *ath12k_mac_get_ar_by_pdev_id(struct ath12k_base *ab, u32 pdev_id)
  740. {
  741. int i;
  742. struct ath12k_pdev *pdev;
  743. if (ab->hw_params->single_pdev_only) {
  744. pdev = rcu_dereference(ab->pdevs_active[0]);
  745. return pdev ? pdev->ar : NULL;
  746. }
  747. if (WARN_ON(pdev_id > ab->num_radios))
  748. return NULL;
  749. for (i = 0; i < ab->num_radios; i++) {
  750. if (ab->fw_mode == ATH12K_FIRMWARE_MODE_FTM)
  751. pdev = &ab->pdevs[i];
  752. else
  753. pdev = rcu_dereference(ab->pdevs_active[i]);
  754. if (pdev && pdev->pdev_id == pdev_id)
  755. return (pdev->ar ? pdev->ar : NULL);
  756. }
  757. return NULL;
  758. }
  759. static bool ath12k_mac_is_ml_arvif(struct ath12k_link_vif *arvif)
  760. {
  761. struct ath12k_vif *ahvif = arvif->ahvif;
  762. lockdep_assert_wiphy(ahvif->ah->hw->wiphy);
  763. if (ahvif->vif->valid_links & BIT(arvif->link_id))
  764. return true;
  765. return false;
  766. }
  767. static struct ath12k *ath12k_mac_get_ar_by_chan(struct ieee80211_hw *hw,
  768. struct ieee80211_channel *channel)
  769. {
  770. struct ath12k_hw *ah = hw->priv;
  771. struct ath12k *ar;
  772. int i;
  773. ar = ah->radio;
  774. if (ah->num_radio == 1)
  775. return ar;
  776. for_each_ar(ah, ar, i) {
  777. if (channel->center_freq >= KHZ_TO_MHZ(ar->freq_range.start_freq) &&
  778. channel->center_freq <= KHZ_TO_MHZ(ar->freq_range.end_freq))
  779. return ar;
  780. }
  781. return NULL;
  782. }
  783. static struct ath12k *ath12k_get_ar_by_ctx(struct ieee80211_hw *hw,
  784. struct ieee80211_chanctx_conf *ctx)
  785. {
  786. if (!ctx)
  787. return NULL;
  788. return ath12k_mac_get_ar_by_chan(hw, ctx->def.chan);
  789. }
  790. struct ath12k *ath12k_get_ar_by_vif(struct ieee80211_hw *hw,
  791. struct ieee80211_vif *vif,
  792. u8 link_id)
  793. {
  794. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  795. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  796. struct ath12k_link_vif *arvif;
  797. lockdep_assert_wiphy(hw->wiphy);
  798. /* If there is one pdev within ah, then we return
  799. * ar directly.
  800. */
  801. if (ah->num_radio == 1)
  802. return ah->radio;
  803. if (!(ahvif->links_map & BIT(link_id)))
  804. return NULL;
  805. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  806. if (arvif && arvif->is_created)
  807. return arvif->ar;
  808. return NULL;
  809. }
  810. void ath12k_mac_get_any_chanctx_conf_iter(struct ieee80211_hw *hw,
  811. struct ieee80211_chanctx_conf *conf,
  812. void *data)
  813. {
  814. struct ath12k_mac_get_any_chanctx_conf_arg *arg = data;
  815. struct ath12k *ctx_ar = ath12k_get_ar_by_ctx(hw, conf);
  816. if (ctx_ar == arg->ar)
  817. arg->chanctx_conf = conf;
  818. }
  819. static struct ath12k_link_vif *ath12k_mac_get_vif_up(struct ath12k *ar)
  820. {
  821. struct ath12k_link_vif *arvif;
  822. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  823. list_for_each_entry(arvif, &ar->arvifs, list) {
  824. if (arvif->is_up)
  825. return arvif;
  826. }
  827. return NULL;
  828. }
  829. static bool ath12k_mac_band_match(enum nl80211_band band1, enum WMI_HOST_WLAN_BAND band2)
  830. {
  831. switch (band1) {
  832. case NL80211_BAND_2GHZ:
  833. if (band2 & WMI_HOST_WLAN_2GHZ_CAP)
  834. return true;
  835. break;
  836. case NL80211_BAND_5GHZ:
  837. case NL80211_BAND_6GHZ:
  838. if (band2 & WMI_HOST_WLAN_5GHZ_CAP)
  839. return true;
  840. break;
  841. default:
  842. return false;
  843. }
  844. return false;
  845. }
  846. static u8 ath12k_mac_get_target_pdev_id_from_vif(struct ath12k_link_vif *arvif)
  847. {
  848. struct ath12k *ar = arvif->ar;
  849. struct ath12k_base *ab = ar->ab;
  850. struct ieee80211_vif *vif = arvif->ahvif->vif;
  851. struct cfg80211_chan_def def;
  852. enum nl80211_band band;
  853. u8 pdev_id = ab->fw_pdev[0].pdev_id;
  854. int i;
  855. if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)))
  856. return pdev_id;
  857. band = def.chan->band;
  858. for (i = 0; i < ab->fw_pdev_count; i++) {
  859. if (ath12k_mac_band_match(band, ab->fw_pdev[i].supported_bands))
  860. return ab->fw_pdev[i].pdev_id;
  861. }
  862. return pdev_id;
  863. }
  864. u8 ath12k_mac_get_target_pdev_id(struct ath12k *ar)
  865. {
  866. struct ath12k_link_vif *arvif;
  867. struct ath12k_base *ab = ar->ab;
  868. if (!ab->hw_params->single_pdev_only)
  869. return ar->pdev->pdev_id;
  870. arvif = ath12k_mac_get_vif_up(ar);
  871. /* fw_pdev array has pdev ids derived from phy capability
  872. * service ready event (pdev_and_hw_link_ids).
  873. * If no vif is active, return default first index.
  874. */
  875. if (!arvif)
  876. return ar->ab->fw_pdev[0].pdev_id;
  877. /* If active vif is found, return the pdev id matching chandef band */
  878. return ath12k_mac_get_target_pdev_id_from_vif(arvif);
  879. }
  880. static void ath12k_pdev_caps_update(struct ath12k *ar)
  881. {
  882. struct ath12k_base *ab = ar->ab;
  883. ar->max_tx_power = ab->target_caps.hw_max_tx_power;
  884. /* FIXME: Set min_tx_power to ab->target_caps.hw_min_tx_power.
  885. * But since the received value in svcrdy is same as hw_max_tx_power,
  886. * we can set ar->min_tx_power to 0 currently until
  887. * this is fixed in firmware
  888. */
  889. ar->min_tx_power = 0;
  890. ar->txpower_limit_2g = ar->max_tx_power;
  891. ar->txpower_limit_5g = ar->max_tx_power;
  892. ar->txpower_scale = WMI_HOST_TP_SCALE_MAX;
  893. }
  894. static int ath12k_mac_txpower_recalc(struct ath12k *ar)
  895. {
  896. struct ath12k_pdev *pdev = ar->pdev;
  897. struct ath12k_link_vif *arvif;
  898. int ret, txpower = -1;
  899. u32 param;
  900. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  901. list_for_each_entry(arvif, &ar->arvifs, list) {
  902. if (arvif->txpower <= 0)
  903. continue;
  904. if (txpower == -1)
  905. txpower = arvif->txpower;
  906. else
  907. txpower = min(txpower, arvif->txpower);
  908. }
  909. if (txpower == -1)
  910. return 0;
  911. /* txpwr is set as 2 units per dBm in FW*/
  912. txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower),
  913. ar->max_tx_power) * 2;
  914. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower to set in hw %d\n",
  915. txpower / 2);
  916. if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2GHZ_CAP) &&
  917. ar->txpower_limit_2g != txpower) {
  918. param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G;
  919. ret = ath12k_wmi_pdev_set_param(ar, param,
  920. txpower, ar->pdev->pdev_id);
  921. if (ret)
  922. goto fail;
  923. ar->txpower_limit_2g = txpower;
  924. }
  925. if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) &&
  926. ar->txpower_limit_5g != txpower) {
  927. param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G;
  928. ret = ath12k_wmi_pdev_set_param(ar, param,
  929. txpower, ar->pdev->pdev_id);
  930. if (ret)
  931. goto fail;
  932. ar->txpower_limit_5g = txpower;
  933. }
  934. return 0;
  935. fail:
  936. ath12k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n",
  937. txpower / 2, param, ret);
  938. return ret;
  939. }
  940. static int ath12k_recalc_rtscts_prot(struct ath12k_link_vif *arvif)
  941. {
  942. struct ath12k *ar = arvif->ar;
  943. u32 vdev_param, rts_cts;
  944. int ret;
  945. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  946. vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS;
  947. /* Enable RTS/CTS protection for sw retries (when legacy stations
  948. * are in BSS) or by default only for second rate series.
  949. * TODO: Check if we need to enable CTS 2 Self in any case
  950. */
  951. rts_cts = WMI_USE_RTS_CTS;
  952. if (arvif->num_legacy_stations > 0)
  953. rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4;
  954. else
  955. rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4;
  956. /* Need not send duplicate param value to firmware */
  957. if (arvif->rtscts_prot_mode == rts_cts)
  958. return 0;
  959. arvif->rtscts_prot_mode = rts_cts;
  960. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
  961. arvif->vdev_id, rts_cts);
  962. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  963. vdev_param, rts_cts);
  964. if (ret)
  965. ath12k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  966. arvif->vdev_id, ret);
  967. return ret;
  968. }
  969. static int ath12k_mac_set_kickout(struct ath12k_link_vif *arvif)
  970. {
  971. struct ath12k *ar = arvif->ar;
  972. u32 param;
  973. int ret;
  974. ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH,
  975. ATH12K_KICKOUT_THRESHOLD,
  976. ar->pdev->pdev_id);
  977. if (ret) {
  978. ath12k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n",
  979. arvif->vdev_id, ret);
  980. return ret;
  981. }
  982. param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS;
  983. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
  984. ATH12K_KEEPALIVE_MIN_IDLE);
  985. if (ret) {
  986. ath12k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n",
  987. arvif->vdev_id, ret);
  988. return ret;
  989. }
  990. param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS;
  991. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
  992. ATH12K_KEEPALIVE_MAX_IDLE);
  993. if (ret) {
  994. ath12k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n",
  995. arvif->vdev_id, ret);
  996. return ret;
  997. }
  998. param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS;
  999. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
  1000. ATH12K_KEEPALIVE_MAX_UNRESPONSIVE);
  1001. if (ret) {
  1002. ath12k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
  1003. arvif->vdev_id, ret);
  1004. return ret;
  1005. }
  1006. return 0;
  1007. }
  1008. static void ath12k_mac_link_sta_rhash_cleanup(void *data, struct ieee80211_sta *sta)
  1009. {
  1010. u8 link_id;
  1011. unsigned long links_map;
  1012. struct ath12k_sta *ahsta;
  1013. struct ath12k *ar = data;
  1014. struct ath12k_link_sta *arsta;
  1015. struct ath12k_link_vif *arvif;
  1016. struct ath12k_base *ab = ar->ab;
  1017. ahsta = ath12k_sta_to_ahsta(sta);
  1018. links_map = ahsta->links_map;
  1019. rcu_read_lock();
  1020. for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) {
  1021. arsta = rcu_dereference(ahsta->link[link_id]);
  1022. if (!arsta)
  1023. continue;
  1024. arvif = arsta->arvif;
  1025. if (!(arvif->ar == ar))
  1026. continue;
  1027. spin_lock_bh(&ab->base_lock);
  1028. ath12k_link_sta_rhash_delete(ab, arsta);
  1029. spin_unlock_bh(&ab->base_lock);
  1030. }
  1031. rcu_read_unlock();
  1032. }
  1033. void ath12k_mac_peer_cleanup_all(struct ath12k *ar)
  1034. {
  1035. struct ath12k_dp_link_peer *peer, *tmp;
  1036. struct ath12k_base *ab = ar->ab;
  1037. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  1038. struct ath12k_link_vif *arvif, *tmp_vif;
  1039. struct ath12k_dp_hw *dp_hw = &ar->ah->dp_hw;
  1040. struct ath12k_dp_peer *dp_peer = NULL;
  1041. u16 peerid_index;
  1042. struct list_head peers;
  1043. INIT_LIST_HEAD(&peers);
  1044. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  1045. spin_lock_bh(&dp->dp_lock);
  1046. list_for_each_entry_safe(peer, tmp, &dp->peers, list) {
  1047. /* Skip Rx TID cleanup for self peer */
  1048. if (peer->sta && peer->dp_peer)
  1049. ath12k_dp_rx_peer_tid_cleanup(ar, peer);
  1050. /* cleanup dp peer */
  1051. spin_lock_bh(&dp_hw->peer_lock);
  1052. dp_peer = peer->dp_peer;
  1053. peerid_index = ath12k_dp_peer_get_peerid_index(dp, peer->peer_id);
  1054. rcu_assign_pointer(dp_peer->link_peers[peer->link_id], NULL);
  1055. rcu_assign_pointer(dp_hw->dp_peers[peerid_index], NULL);
  1056. spin_unlock_bh(&dp_hw->peer_lock);
  1057. ath12k_dp_link_peer_rhash_delete(dp, peer);
  1058. list_move(&peer->list, &peers);
  1059. }
  1060. spin_unlock_bh(&dp->dp_lock);
  1061. synchronize_rcu();
  1062. list_for_each_entry_safe(peer, tmp, &peers, list) {
  1063. ath12k_dp_link_peer_free(peer);
  1064. }
  1065. ar->num_peers = 0;
  1066. ar->num_stations = 0;
  1067. /* Cleanup rhash table maintained for arsta by iterating over sta */
  1068. ieee80211_iterate_stations_mtx(ar->ah->hw, ath12k_mac_link_sta_rhash_cleanup,
  1069. ar);
  1070. /* Delete all the self dp_peers on asserted radio */
  1071. list_for_each_entry_safe_reverse(arvif, tmp_vif, &ar->arvifs, list) {
  1072. if ((arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP) &&
  1073. (arvif->link_id < IEEE80211_MLD_MAX_NUM_LINKS)) {
  1074. ath12k_dp_peer_delete(dp_hw, arvif->bssid, NULL);
  1075. arvif->num_stations = 0;
  1076. }
  1077. }
  1078. }
  1079. void ath12k_mac_dp_peer_cleanup(struct ath12k_hw *ah)
  1080. {
  1081. struct list_head peers;
  1082. struct ath12k_dp_peer *dp_peer, *tmp;
  1083. struct ath12k_dp_hw *dp_hw = &ah->dp_hw;
  1084. INIT_LIST_HEAD(&peers);
  1085. spin_lock_bh(&dp_hw->peer_lock);
  1086. list_for_each_entry_safe(dp_peer, tmp, &dp_hw->dp_peers_list, list) {
  1087. if (dp_peer->is_mlo) {
  1088. rcu_assign_pointer(dp_hw->dp_peers[dp_peer->peer_id], NULL);
  1089. clear_bit(dp_peer->peer_id, ah->free_ml_peer_id_map);
  1090. }
  1091. list_move(&dp_peer->list, &peers);
  1092. }
  1093. spin_unlock_bh(&dp_hw->peer_lock);
  1094. synchronize_rcu();
  1095. list_for_each_entry_safe(dp_peer, tmp, &peers, list) {
  1096. list_del(&dp_peer->list);
  1097. kfree(dp_peer);
  1098. }
  1099. }
  1100. static int ath12k_mac_vdev_setup_sync(struct ath12k *ar)
  1101. {
  1102. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  1103. if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
  1104. return -ESHUTDOWN;
  1105. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "vdev setup timeout %d\n",
  1106. ATH12K_VDEV_SETUP_TIMEOUT_HZ);
  1107. if (!wait_for_completion_timeout(&ar->vdev_setup_done,
  1108. ATH12K_VDEV_SETUP_TIMEOUT_HZ))
  1109. return -ETIMEDOUT;
  1110. return ar->last_wmi_vdev_start_status ? -EINVAL : 0;
  1111. }
  1112. static int ath12k_monitor_vdev_up(struct ath12k *ar, int vdev_id)
  1113. {
  1114. struct ath12k_wmi_vdev_up_params params = {};
  1115. int ret;
  1116. params.vdev_id = vdev_id;
  1117. params.bssid = ar->mac_addr;
  1118. ret = ath12k_wmi_vdev_up(ar, &params);
  1119. if (ret) {
  1120. ath12k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n",
  1121. vdev_id, ret);
  1122. return ret;
  1123. }
  1124. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i started\n",
  1125. vdev_id);
  1126. return 0;
  1127. }
  1128. static int ath12k_mac_monitor_vdev_start(struct ath12k *ar, int vdev_id,
  1129. struct cfg80211_chan_def *chandef)
  1130. {
  1131. struct ieee80211_channel *channel;
  1132. struct wmi_vdev_start_req_arg arg = {};
  1133. struct ath12k_wmi_vdev_up_params params = {};
  1134. int ret;
  1135. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  1136. channel = chandef->chan;
  1137. arg.vdev_id = vdev_id;
  1138. arg.freq = channel->center_freq;
  1139. arg.band_center_freq1 = chandef->center_freq1;
  1140. arg.band_center_freq2 = chandef->center_freq2;
  1141. arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width];
  1142. arg.chan_radar = !!(channel->flags & IEEE80211_CHAN_RADAR);
  1143. arg.min_power = 0;
  1144. arg.max_power = channel->max_power;
  1145. arg.max_reg_power = channel->max_reg_power;
  1146. arg.max_antenna_gain = channel->max_antenna_gain;
  1147. arg.pref_tx_streams = ar->num_tx_chains;
  1148. arg.pref_rx_streams = ar->num_rx_chains;
  1149. arg.punct_bitmap = 0xFFFFFFFF;
  1150. arg.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR);
  1151. reinit_completion(&ar->vdev_setup_done);
  1152. reinit_completion(&ar->vdev_delete_done);
  1153. ret = ath12k_wmi_vdev_start(ar, &arg, false);
  1154. if (ret) {
  1155. ath12k_warn(ar->ab, "failed to request monitor vdev %i start: %d\n",
  1156. vdev_id, ret);
  1157. return ret;
  1158. }
  1159. ret = ath12k_mac_vdev_setup_sync(ar);
  1160. if (ret) {
  1161. ath12k_warn(ar->ab, "failed to synchronize setup for monitor vdev %i start: %d\n",
  1162. vdev_id, ret);
  1163. return ret;
  1164. }
  1165. params.vdev_id = vdev_id;
  1166. params.bssid = ar->mac_addr;
  1167. ret = ath12k_wmi_vdev_up(ar, &params);
  1168. if (ret) {
  1169. ath12k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n",
  1170. vdev_id, ret);
  1171. goto vdev_stop;
  1172. }
  1173. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i started\n",
  1174. vdev_id);
  1175. return 0;
  1176. vdev_stop:
  1177. ret = ath12k_wmi_vdev_stop(ar, vdev_id);
  1178. if (ret)
  1179. ath12k_warn(ar->ab, "failed to stop monitor vdev %i after start failure: %d\n",
  1180. vdev_id, ret);
  1181. return ret;
  1182. }
  1183. static int ath12k_mac_monitor_vdev_stop(struct ath12k *ar)
  1184. {
  1185. int ret;
  1186. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  1187. reinit_completion(&ar->vdev_setup_done);
  1188. ret = ath12k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
  1189. if (ret)
  1190. ath12k_warn(ar->ab, "failed to request monitor vdev %i stop: %d\n",
  1191. ar->monitor_vdev_id, ret);
  1192. ret = ath12k_mac_vdev_setup_sync(ar);
  1193. if (ret)
  1194. ath12k_warn(ar->ab, "failed to synchronize monitor vdev %i stop: %d\n",
  1195. ar->monitor_vdev_id, ret);
  1196. ret = ath12k_wmi_vdev_down(ar, ar->monitor_vdev_id);
  1197. if (ret)
  1198. ath12k_warn(ar->ab, "failed to put down monitor vdev %i: %d\n",
  1199. ar->monitor_vdev_id, ret);
  1200. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i stopped\n",
  1201. ar->monitor_vdev_id);
  1202. return ret;
  1203. }
  1204. static int ath12k_mac_monitor_vdev_delete(struct ath12k *ar)
  1205. {
  1206. int ret;
  1207. unsigned long time_left;
  1208. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  1209. if (!ar->monitor_vdev_created)
  1210. return 0;
  1211. reinit_completion(&ar->vdev_delete_done);
  1212. ret = ath12k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
  1213. if (ret) {
  1214. ath12k_warn(ar->ab, "failed to request wmi monitor vdev %i removal: %d\n",
  1215. ar->monitor_vdev_id, ret);
  1216. return ret;
  1217. }
  1218. time_left = wait_for_completion_timeout(&ar->vdev_delete_done,
  1219. ATH12K_VDEV_DELETE_TIMEOUT_HZ);
  1220. if (time_left == 0) {
  1221. ath12k_warn(ar->ab, "Timeout in receiving vdev delete response\n");
  1222. } else {
  1223. ar->allocated_vdev_map &= ~(1LL << ar->monitor_vdev_id);
  1224. ar->ab->free_vdev_map |= 1LL << (ar->monitor_vdev_id);
  1225. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %d deleted\n",
  1226. ar->monitor_vdev_id);
  1227. ar->num_created_vdevs--;
  1228. ar->monitor_vdev_id = -1;
  1229. ar->monitor_vdev_created = false;
  1230. }
  1231. return ret;
  1232. }
  1233. static int ath12k_mac_monitor_start(struct ath12k *ar)
  1234. {
  1235. struct ath12k_mac_get_any_chanctx_conf_arg arg;
  1236. int ret;
  1237. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  1238. if (ar->monitor_started)
  1239. return 0;
  1240. arg.ar = ar;
  1241. arg.chanctx_conf = NULL;
  1242. ieee80211_iter_chan_contexts_atomic(ath12k_ar_to_hw(ar),
  1243. ath12k_mac_get_any_chanctx_conf_iter,
  1244. &arg);
  1245. if (!arg.chanctx_conf)
  1246. return 0;
  1247. ret = ath12k_mac_monitor_vdev_start(ar, ar->monitor_vdev_id,
  1248. &arg.chanctx_conf->def);
  1249. if (ret) {
  1250. ath12k_warn(ar->ab, "failed to start monitor vdev: %d\n", ret);
  1251. return ret;
  1252. }
  1253. ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, false);
  1254. if (ret) {
  1255. ath12k_warn(ar->ab, "fail to set monitor filter: %d\n", ret);
  1256. return ret;
  1257. }
  1258. ar->monitor_started = true;
  1259. ar->num_started_vdevs++;
  1260. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor started\n");
  1261. return 0;
  1262. }
  1263. static int ath12k_mac_monitor_stop(struct ath12k *ar)
  1264. {
  1265. int ret;
  1266. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  1267. if (!ar->monitor_started)
  1268. return 0;
  1269. ret = ath12k_mac_monitor_vdev_stop(ar);
  1270. if (ret) {
  1271. ath12k_warn(ar->ab, "failed to stop monitor vdev: %d\n", ret);
  1272. return ret;
  1273. }
  1274. ar->monitor_started = false;
  1275. ar->num_started_vdevs--;
  1276. ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, true);
  1277. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor stopped ret %d\n", ret);
  1278. return ret;
  1279. }
  1280. int ath12k_mac_vdev_stop(struct ath12k_link_vif *arvif)
  1281. {
  1282. struct ath12k_vif *ahvif = arvif->ahvif;
  1283. struct ath12k *ar = arvif->ar;
  1284. int ret;
  1285. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  1286. reinit_completion(&ar->vdev_setup_done);
  1287. ret = ath12k_wmi_vdev_stop(ar, arvif->vdev_id);
  1288. if (ret) {
  1289. ath12k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n",
  1290. arvif->vdev_id, ret);
  1291. goto err;
  1292. }
  1293. ret = ath12k_mac_vdev_setup_sync(ar);
  1294. if (ret) {
  1295. ath12k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n",
  1296. arvif->vdev_id, ret);
  1297. goto err;
  1298. }
  1299. WARN_ON(ar->num_started_vdevs == 0);
  1300. ar->num_started_vdevs--;
  1301. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "vdev %pM stopped, vdev_id %d\n",
  1302. ahvif->vif->addr, arvif->vdev_id);
  1303. if (test_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags)) {
  1304. clear_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags);
  1305. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "CAC Stopped for vdev %d\n",
  1306. arvif->vdev_id);
  1307. }
  1308. return 0;
  1309. err:
  1310. return ret;
  1311. }
  1312. int ath12k_mac_op_config(struct ieee80211_hw *hw, int radio_idx, u32 changed)
  1313. {
  1314. return 0;
  1315. }
  1316. EXPORT_SYMBOL(ath12k_mac_op_config);
  1317. static int ath12k_mac_setup_bcn_p2p_ie(struct ath12k_link_vif *arvif,
  1318. struct sk_buff *bcn)
  1319. {
  1320. struct ath12k *ar = arvif->ar;
  1321. struct ieee80211_mgmt *mgmt;
  1322. const u8 *p2p_ie;
  1323. int ret;
  1324. mgmt = (void *)bcn->data;
  1325. p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
  1326. mgmt->u.beacon.variable,
  1327. bcn->len - (mgmt->u.beacon.variable -
  1328. bcn->data));
  1329. if (!p2p_ie) {
  1330. ath12k_warn(ar->ab, "no P2P ie found in beacon\n");
  1331. return -ENOENT;
  1332. }
  1333. ret = ath12k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
  1334. if (ret) {
  1335. ath12k_warn(ar->ab, "failed to submit P2P GO bcn ie for vdev %i: %d\n",
  1336. arvif->vdev_id, ret);
  1337. return ret;
  1338. }
  1339. return 0;
  1340. }
  1341. static int ath12k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
  1342. u8 oui_type, size_t ie_offset)
  1343. {
  1344. const u8 *next, *end;
  1345. size_t len;
  1346. u8 *ie;
  1347. if (WARN_ON(skb->len < ie_offset))
  1348. return -EINVAL;
  1349. ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
  1350. skb->data + ie_offset,
  1351. skb->len - ie_offset);
  1352. if (!ie)
  1353. return -ENOENT;
  1354. len = ie[1] + 2;
  1355. end = skb->data + skb->len;
  1356. next = ie + len;
  1357. if (WARN_ON(next > end))
  1358. return -EINVAL;
  1359. memmove(ie, next, end - next);
  1360. skb_trim(skb, skb->len - len);
  1361. return 0;
  1362. }
  1363. static void ath12k_mac_set_arvif_ies(struct ath12k_link_vif *arvif,
  1364. struct ath12k_link_vif *tx_arvif,
  1365. struct sk_buff *bcn,
  1366. u8 bssid_index, bool *nontx_profile_found)
  1367. {
  1368. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)bcn->data;
  1369. const struct element *elem, *nontx, *index, *nie, *ext_cap_ie;
  1370. const u8 *start, *tail;
  1371. u16 rem_len;
  1372. u8 i;
  1373. start = bcn->data + ieee80211_get_hdrlen_from_skb(bcn) + sizeof(mgmt->u.beacon);
  1374. tail = skb_tail_pointer(bcn);
  1375. rem_len = tail - start;
  1376. arvif->rsnie_present = false;
  1377. arvif->wpaie_present = false;
  1378. if (cfg80211_find_ie(WLAN_EID_RSN, start, rem_len))
  1379. arvif->rsnie_present = true;
  1380. if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, WLAN_OUI_TYPE_MICROSOFT_WPA,
  1381. start, rem_len))
  1382. arvif->wpaie_present = true;
  1383. ext_cap_ie = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, start, rem_len);
  1384. if (ext_cap_ie && ext_cap_ie->datalen >= 11 &&
  1385. (ext_cap_ie->data[10] & WLAN_EXT_CAPA11_BCN_PROTECT))
  1386. tx_arvif->beacon_prot = true;
  1387. /* Return from here for the transmitted profile */
  1388. if (!bssid_index)
  1389. return;
  1390. /* Initial rsnie_present for the nontransmitted profile is set to be same as that
  1391. * of the transmitted profile. It will be changed if security configurations are
  1392. * different.
  1393. */
  1394. *nontx_profile_found = false;
  1395. for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, start, rem_len) {
  1396. /* Fixed minimum MBSSID element length with at least one
  1397. * nontransmitted BSSID profile is 12 bytes as given below;
  1398. * 1 (max BSSID indicator) +
  1399. * 2 (Nontransmitted BSSID profile: Subelement ID + length) +
  1400. * 4 (Nontransmitted BSSID Capabilities: tag + length + info)
  1401. * 2 (Nontransmitted BSSID SSID: tag + length)
  1402. * 3 (Nontransmitted BSSID Index: tag + length + BSSID index
  1403. */
  1404. if (elem->datalen < 12 || elem->data[0] < 1)
  1405. continue; /* Max BSSID indicator must be >=1 */
  1406. for_each_element(nontx, elem->data + 1, elem->datalen - 1) {
  1407. start = nontx->data;
  1408. if (nontx->id != 0 || nontx->datalen < 4)
  1409. continue; /* Invalid nontransmitted profile */
  1410. if (nontx->data[0] != WLAN_EID_NON_TX_BSSID_CAP ||
  1411. nontx->data[1] != 2) {
  1412. continue; /* Missing nontransmitted BSS capabilities */
  1413. }
  1414. if (nontx->data[4] != WLAN_EID_SSID)
  1415. continue; /* Missing SSID for nontransmitted BSS */
  1416. index = cfg80211_find_elem(WLAN_EID_MULTI_BSSID_IDX,
  1417. start, nontx->datalen);
  1418. if (!index || index->datalen < 1 || index->data[0] == 0)
  1419. continue; /* Invalid MBSSID Index element */
  1420. if (index->data[0] == bssid_index) {
  1421. *nontx_profile_found = true;
  1422. /* Check if nontx BSS has beacon protection enabled */
  1423. if (!tx_arvif->beacon_prot) {
  1424. ext_cap_ie =
  1425. cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
  1426. nontx->data,
  1427. nontx->datalen);
  1428. if (ext_cap_ie && ext_cap_ie->datalen >= 11 &&
  1429. (ext_cap_ie->data[10] &
  1430. WLAN_EXT_CAPA11_BCN_PROTECT))
  1431. tx_arvif->beacon_prot = true;
  1432. }
  1433. if (cfg80211_find_ie(WLAN_EID_RSN,
  1434. nontx->data,
  1435. nontx->datalen)) {
  1436. arvif->rsnie_present = true;
  1437. return;
  1438. } else if (!arvif->rsnie_present) {
  1439. return; /* Both tx and nontx BSS are open */
  1440. }
  1441. nie = cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
  1442. nontx->data,
  1443. nontx->datalen);
  1444. if (!nie || nie->datalen < 2)
  1445. return; /* Invalid non-inheritance element */
  1446. for (i = 1; i < nie->datalen - 1; i++) {
  1447. if (nie->data[i] == WLAN_EID_RSN) {
  1448. arvif->rsnie_present = false;
  1449. break;
  1450. }
  1451. }
  1452. return;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. static int ath12k_mac_setup_bcn_tmpl_ema(struct ath12k_link_vif *arvif,
  1458. struct ath12k_link_vif *tx_arvif,
  1459. u8 bssid_index)
  1460. {
  1461. struct ath12k_wmi_bcn_tmpl_ema_arg ema_args;
  1462. struct ieee80211_ema_beacons *beacons;
  1463. bool nontx_profile_found = false;
  1464. int ret = 0;
  1465. u8 i;
  1466. beacons = ieee80211_beacon_get_template_ema_list(ath12k_ar_to_hw(tx_arvif->ar),
  1467. tx_arvif->ahvif->vif,
  1468. tx_arvif->link_id);
  1469. if (!beacons || !beacons->cnt) {
  1470. ath12k_warn(arvif->ar->ab,
  1471. "failed to get ema beacon templates from mac80211\n");
  1472. return -EPERM;
  1473. }
  1474. if (tx_arvif == arvif)
  1475. ath12k_mac_set_arvif_ies(arvif, tx_arvif, beacons->bcn[0].skb, 0, NULL);
  1476. for (i = 0; i < beacons->cnt; i++) {
  1477. if (tx_arvif != arvif && !nontx_profile_found)
  1478. ath12k_mac_set_arvif_ies(arvif, tx_arvif, beacons->bcn[i].skb,
  1479. bssid_index,
  1480. &nontx_profile_found);
  1481. ema_args.bcn_cnt = beacons->cnt;
  1482. ema_args.bcn_index = i;
  1483. ret = ath12k_wmi_bcn_tmpl(tx_arvif, &beacons->bcn[i].offs,
  1484. beacons->bcn[i].skb, &ema_args);
  1485. if (ret) {
  1486. ath12k_warn(tx_arvif->ar->ab,
  1487. "failed to set ema beacon template id %i error %d\n",
  1488. i, ret);
  1489. break;
  1490. }
  1491. }
  1492. if (tx_arvif != arvif && !nontx_profile_found)
  1493. ath12k_warn(arvif->ar->ab,
  1494. "nontransmitted bssid index %u not found in beacon template\n",
  1495. bssid_index);
  1496. ieee80211_beacon_free_ema_list(beacons);
  1497. return ret;
  1498. }
  1499. static int ath12k_mac_setup_bcn_tmpl(struct ath12k_link_vif *arvif)
  1500. {
  1501. struct ath12k_vif *ahvif = arvif->ahvif;
  1502. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif);
  1503. struct ieee80211_bss_conf *link_conf;
  1504. struct ath12k_link_vif *tx_arvif;
  1505. struct ath12k *ar = arvif->ar;
  1506. struct ath12k_base *ab = ar->ab;
  1507. struct ieee80211_mutable_offsets offs = {};
  1508. bool nontx_profile_found = false;
  1509. struct sk_buff *bcn;
  1510. int ret;
  1511. if (ahvif->vdev_type != WMI_VDEV_TYPE_AP)
  1512. return 0;
  1513. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  1514. if (!link_conf) {
  1515. ath12k_warn(ar->ab, "unable to access bss link conf to set bcn tmpl for vif %pM link %u\n",
  1516. vif->addr, arvif->link_id);
  1517. return -ENOLINK;
  1518. }
  1519. tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf);
  1520. if (tx_arvif) {
  1521. if (tx_arvif != arvif && arvif->is_up)
  1522. return 0;
  1523. if (link_conf->ema_ap)
  1524. return ath12k_mac_setup_bcn_tmpl_ema(arvif, tx_arvif,
  1525. link_conf->bssid_index);
  1526. } else {
  1527. tx_arvif = arvif;
  1528. }
  1529. bcn = ieee80211_beacon_get_template(ath12k_ar_to_hw(tx_arvif->ar),
  1530. tx_arvif->ahvif->vif,
  1531. &offs, tx_arvif->link_id);
  1532. if (!bcn) {
  1533. ath12k_warn(ab, "failed to get beacon template from mac80211\n");
  1534. return -EPERM;
  1535. }
  1536. if (tx_arvif == arvif) {
  1537. ath12k_mac_set_arvif_ies(arvif, tx_arvif, bcn, 0, NULL);
  1538. } else {
  1539. ath12k_mac_set_arvif_ies(arvif, tx_arvif, bcn,
  1540. link_conf->bssid_index,
  1541. &nontx_profile_found);
  1542. if (!nontx_profile_found)
  1543. ath12k_warn(ab,
  1544. "nontransmitted profile not found in beacon template\n");
  1545. }
  1546. if (ahvif->vif->type == NL80211_IFTYPE_AP && ahvif->vif->p2p) {
  1547. ret = ath12k_mac_setup_bcn_p2p_ie(arvif, bcn);
  1548. if (ret) {
  1549. ath12k_warn(ab, "failed to setup P2P GO bcn ie: %d\n",
  1550. ret);
  1551. goto free_bcn_skb;
  1552. }
  1553. /* P2P IE is inserted by firmware automatically (as
  1554. * configured above) so remove it from the base beacon
  1555. * template to avoid duplicate P2P IEs in beacon frames.
  1556. */
  1557. ret = ath12k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA,
  1558. WLAN_OUI_TYPE_WFA_P2P,
  1559. offsetof(struct ieee80211_mgmt,
  1560. u.beacon.variable));
  1561. if (ret) {
  1562. ath12k_warn(ab, "failed to remove P2P vendor ie: %d\n",
  1563. ret);
  1564. goto free_bcn_skb;
  1565. }
  1566. }
  1567. ret = ath12k_wmi_bcn_tmpl(arvif, &offs, bcn, NULL);
  1568. if (ret)
  1569. ath12k_warn(ab, "failed to submit beacon template command: %d\n",
  1570. ret);
  1571. free_bcn_skb:
  1572. kfree_skb(bcn);
  1573. return ret;
  1574. }
  1575. static void ath12k_control_beaconing(struct ath12k_link_vif *arvif,
  1576. struct ieee80211_bss_conf *info)
  1577. {
  1578. struct ath12k_wmi_vdev_up_params params = {};
  1579. struct ath12k_vif *ahvif = arvif->ahvif;
  1580. struct ath12k *ar = arvif->ar;
  1581. int ret;
  1582. lockdep_assert_wiphy(ath12k_ar_to_hw(arvif->ar)->wiphy);
  1583. if (!info->enable_beacon) {
  1584. ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id);
  1585. if (ret)
  1586. ath12k_warn(ar->ab, "failed to down vdev_id %i: %d\n",
  1587. arvif->vdev_id, ret);
  1588. arvif->is_up = false;
  1589. return;
  1590. }
  1591. /* Install the beacon template to the FW */
  1592. ret = ath12k_mac_setup_bcn_tmpl(arvif);
  1593. if (ret) {
  1594. ath12k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n",
  1595. ret);
  1596. return;
  1597. }
  1598. ahvif->aid = 0;
  1599. ether_addr_copy(arvif->bssid, info->addr);
  1600. params.vdev_id = arvif->vdev_id;
  1601. params.aid = ahvif->aid;
  1602. params.bssid = arvif->bssid;
  1603. params.tx_bssid = ath12k_mac_get_tx_bssid(arvif);
  1604. if (params.tx_bssid) {
  1605. params.nontx_profile_idx = info->bssid_index;
  1606. params.nontx_profile_cnt = 1 << info->bssid_indicator;
  1607. }
  1608. ret = ath12k_wmi_vdev_up(arvif->ar, &params);
  1609. if (ret) {
  1610. ath12k_warn(ar->ab, "failed to bring up vdev %d: %i\n",
  1611. arvif->vdev_id, ret);
  1612. return;
  1613. }
  1614. arvif->is_up = true;
  1615. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
  1616. }
  1617. static void ath12k_mac_handle_beacon_iter(void *data, u8 *mac,
  1618. struct ieee80211_vif *vif)
  1619. {
  1620. struct sk_buff *skb = data;
  1621. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1622. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  1623. struct ath12k_link_vif *arvif = &ahvif->deflink;
  1624. if (vif->type != NL80211_IFTYPE_STATION || !arvif->is_created)
  1625. return;
  1626. if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
  1627. return;
  1628. cancel_delayed_work(&arvif->connection_loss_work);
  1629. }
  1630. void ath12k_mac_handle_beacon(struct ath12k *ar, struct sk_buff *skb)
  1631. {
  1632. ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar),
  1633. IEEE80211_IFACE_ITER_NORMAL,
  1634. ath12k_mac_handle_beacon_iter,
  1635. skb);
  1636. }
  1637. void ath12k_mac_handle_beacon_miss(struct ath12k *ar,
  1638. struct ath12k_link_vif *arvif)
  1639. {
  1640. struct ieee80211_hw *hw = ath12k_ar_to_hw(ar);
  1641. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  1642. if (!(arvif->is_created && arvif->is_up))
  1643. return;
  1644. ieee80211_beacon_loss(vif);
  1645. /* Firmware doesn't report beacon loss events repeatedly. If AP probe
  1646. * (done by mac80211) succeeds but beacons do not resume then it
  1647. * doesn't make sense to continue operation. Queue connection loss work
  1648. * which can be cancelled when beacon is received.
  1649. */
  1650. ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
  1651. ATH12K_CONNECTION_LOSS_HZ);
  1652. }
  1653. static void ath12k_mac_vif_sta_connection_loss_work(struct work_struct *work)
  1654. {
  1655. struct ath12k_link_vif *arvif = container_of(work, struct ath12k_link_vif,
  1656. connection_loss_work.work);
  1657. struct ieee80211_vif *vif = arvif->ahvif->vif;
  1658. if (!arvif->is_up)
  1659. return;
  1660. ieee80211_connection_loss(vif);
  1661. }
  1662. static void ath12k_peer_assoc_h_basic(struct ath12k *ar,
  1663. struct ath12k_link_vif *arvif,
  1664. struct ath12k_link_sta *arsta,
  1665. struct ath12k_wmi_peer_assoc_arg *arg)
  1666. {
  1667. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  1668. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  1669. struct ieee80211_hw *hw = ath12k_ar_to_hw(ar);
  1670. struct ieee80211_bss_conf *bss_conf;
  1671. u32 aid;
  1672. lockdep_assert_wiphy(hw->wiphy);
  1673. if (vif->type == NL80211_IFTYPE_STATION)
  1674. aid = vif->cfg.aid;
  1675. else
  1676. aid = sta->aid;
  1677. ether_addr_copy(arg->peer_mac, arsta->addr);
  1678. arg->vdev_id = arvif->vdev_id;
  1679. arg->peer_associd = aid;
  1680. arg->auth_flag = true;
  1681. /* TODO: STA WAR in ath10k for listen interval required? */
  1682. arg->peer_listen_intval = hw->conf.listen_interval;
  1683. arg->peer_nss = 1;
  1684. bss_conf = ath12k_mac_get_link_bss_conf(arvif);
  1685. if (!bss_conf) {
  1686. ath12k_warn(ar->ab, "unable to access bss link conf in peer assoc for vif %pM link %u\n",
  1687. vif->addr, arvif->link_id);
  1688. return;
  1689. }
  1690. arg->peer_caps = bss_conf->assoc_capability;
  1691. }
  1692. static void ath12k_peer_assoc_h_crypto(struct ath12k *ar,
  1693. struct ath12k_link_vif *arvif,
  1694. struct ath12k_link_sta *arsta,
  1695. struct ath12k_wmi_peer_assoc_arg *arg)
  1696. {
  1697. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  1698. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  1699. struct ieee80211_bss_conf *info;
  1700. struct cfg80211_chan_def def;
  1701. struct cfg80211_bss *bss;
  1702. struct ieee80211_hw *hw = ath12k_ar_to_hw(ar);
  1703. const u8 *rsnie = NULL;
  1704. const u8 *wpaie = NULL;
  1705. lockdep_assert_wiphy(hw->wiphy);
  1706. info = ath12k_mac_get_link_bss_conf(arvif);
  1707. if (!info) {
  1708. ath12k_warn(ar->ab, "unable to access bss link conf for peer assoc crypto for vif %pM link %u\n",
  1709. vif->addr, arvif->link_id);
  1710. return;
  1711. }
  1712. if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)))
  1713. return;
  1714. bss = cfg80211_get_bss(hw->wiphy, def.chan, info->bssid, NULL, 0,
  1715. IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
  1716. if (arvif->rsnie_present || arvif->wpaie_present) {
  1717. arg->need_ptk_4_way = true;
  1718. if (arvif->wpaie_present)
  1719. arg->need_gtk_2_way = true;
  1720. } else if (bss) {
  1721. const struct cfg80211_bss_ies *ies;
  1722. rcu_read_lock();
  1723. rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
  1724. ies = rcu_dereference(bss->ies);
  1725. wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
  1726. WLAN_OUI_TYPE_MICROSOFT_WPA,
  1727. ies->data,
  1728. ies->len);
  1729. rcu_read_unlock();
  1730. cfg80211_put_bss(hw->wiphy, bss);
  1731. }
  1732. /* FIXME: base on RSN IE/WPA IE is a correct idea? */
  1733. if (rsnie || wpaie) {
  1734. ath12k_dbg(ar->ab, ATH12K_DBG_WMI,
  1735. "%s: rsn ie found\n", __func__);
  1736. arg->need_ptk_4_way = true;
  1737. }
  1738. if (wpaie) {
  1739. ath12k_dbg(ar->ab, ATH12K_DBG_WMI,
  1740. "%s: wpa ie found\n", __func__);
  1741. arg->need_gtk_2_way = true;
  1742. }
  1743. if (sta->mfp) {
  1744. /* TODO: Need to check if FW supports PMF? */
  1745. arg->is_pmf_enabled = true;
  1746. }
  1747. /* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */
  1748. }
  1749. static void ath12k_peer_assoc_h_rates(struct ath12k *ar,
  1750. struct ath12k_link_vif *arvif,
  1751. struct ath12k_link_sta *arsta,
  1752. struct ath12k_wmi_peer_assoc_arg *arg)
  1753. {
  1754. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  1755. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  1756. struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
  1757. struct ieee80211_link_sta *link_sta;
  1758. struct cfg80211_chan_def def;
  1759. const struct ieee80211_supported_band *sband;
  1760. const struct ieee80211_rate *rates;
  1761. struct ieee80211_hw *hw = ath12k_ar_to_hw(ar);
  1762. enum nl80211_band band;
  1763. u32 ratemask;
  1764. u8 rate;
  1765. int i;
  1766. lockdep_assert_wiphy(hw->wiphy);
  1767. if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)))
  1768. return;
  1769. link_sta = ath12k_mac_get_link_sta(arsta);
  1770. if (!link_sta) {
  1771. ath12k_warn(ar->ab, "unable to access link sta in peer assoc rates for sta %pM link %u\n",
  1772. sta->addr, arsta->link_id);
  1773. return;
  1774. }
  1775. band = def.chan->band;
  1776. sband = hw->wiphy->bands[band];
  1777. ratemask = link_sta->supp_rates[band];
  1778. ratemask &= arvif->bitrate_mask.control[band].legacy;
  1779. rates = sband->bitrates;
  1780. rateset->num_rates = 0;
  1781. for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
  1782. if (!(ratemask & 1))
  1783. continue;
  1784. rate = ath12k_mac_bitrate_to_rate(rates->bitrate);
  1785. rateset->rates[rateset->num_rates] = rate;
  1786. rateset->num_rates++;
  1787. }
  1788. }
  1789. static bool
  1790. ath12k_peer_assoc_h_ht_masked(const u8 *ht_mcs_mask)
  1791. {
  1792. int nss;
  1793. for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
  1794. if (ht_mcs_mask[nss])
  1795. return false;
  1796. return true;
  1797. }
  1798. static bool
  1799. ath12k_peer_assoc_h_vht_masked(const u16 *vht_mcs_mask)
  1800. {
  1801. int nss;
  1802. for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
  1803. if (vht_mcs_mask[nss])
  1804. return false;
  1805. return true;
  1806. }
  1807. static void ath12k_peer_assoc_h_ht(struct ath12k *ar,
  1808. struct ath12k_link_vif *arvif,
  1809. struct ath12k_link_sta *arsta,
  1810. struct ath12k_wmi_peer_assoc_arg *arg)
  1811. {
  1812. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  1813. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  1814. const struct ieee80211_sta_ht_cap *ht_cap;
  1815. struct ieee80211_link_sta *link_sta;
  1816. struct cfg80211_chan_def def;
  1817. enum nl80211_band band;
  1818. const u8 *ht_mcs_mask;
  1819. int i, n;
  1820. u8 max_nss;
  1821. u32 stbc;
  1822. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  1823. if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)))
  1824. return;
  1825. link_sta = ath12k_mac_get_link_sta(arsta);
  1826. if (!link_sta) {
  1827. ath12k_warn(ar->ab, "unable to access link sta in peer assoc ht for sta %pM link %u\n",
  1828. sta->addr, arsta->link_id);
  1829. return;
  1830. }
  1831. ht_cap = &link_sta->ht_cap;
  1832. if (!ht_cap->ht_supported)
  1833. return;
  1834. band = def.chan->band;
  1835. ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
  1836. if (ath12k_peer_assoc_h_ht_masked(ht_mcs_mask))
  1837. return;
  1838. arg->ht_flag = true;
  1839. arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  1840. ht_cap->ampdu_factor)) - 1;
  1841. arg->peer_mpdu_density =
  1842. ath12k_parse_mpdudensity(ht_cap->ampdu_density);
  1843. arg->peer_ht_caps = ht_cap->cap;
  1844. arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG;
  1845. if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
  1846. arg->ldpc_flag = true;
  1847. if (link_sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
  1848. arg->bw_40 = true;
  1849. arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG;
  1850. }
  1851. /* As firmware handles these two flags (IEEE80211_HT_CAP_SGI_20
  1852. * and IEEE80211_HT_CAP_SGI_40) for enabling SGI, reset both
  1853. * flags if guard interval is to force Long GI
  1854. */
  1855. if (arvif->bitrate_mask.control[band].gi == NL80211_TXRATE_FORCE_LGI) {
  1856. arg->peer_ht_caps &= ~(IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40);
  1857. } else {
  1858. /* Enable SGI flag if either SGI_20 or SGI_40 is supported */
  1859. if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40))
  1860. arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG;
  1861. }
  1862. if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
  1863. arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG;
  1864. arg->stbc_flag = true;
  1865. }
  1866. if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
  1867. stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
  1868. stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
  1869. stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S;
  1870. arg->peer_rate_caps |= stbc;
  1871. arg->stbc_flag = true;
  1872. }
  1873. if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
  1874. arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG;
  1875. else if (ht_cap->mcs.rx_mask[1])
  1876. arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG;
  1877. for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
  1878. if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
  1879. (ht_mcs_mask[i / 8] & BIT(i % 8))) {
  1880. max_nss = (i / 8) + 1;
  1881. arg->peer_ht_rates.rates[n++] = i;
  1882. }
  1883. /* This is a workaround for HT-enabled STAs which break the spec
  1884. * and have no HT capabilities RX mask (no HT RX MCS map).
  1885. *
  1886. * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
  1887. * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
  1888. *
  1889. * Firmware asserts if such situation occurs.
  1890. */
  1891. if (n == 0) {
  1892. arg->peer_ht_rates.num_rates = 8;
  1893. for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
  1894. arg->peer_ht_rates.rates[i] = i;
  1895. } else {
  1896. arg->peer_ht_rates.num_rates = n;
  1897. arg->peer_nss = min(link_sta->rx_nss, max_nss);
  1898. }
  1899. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
  1900. arg->peer_mac,
  1901. arg->peer_ht_rates.num_rates,
  1902. arg->peer_nss);
  1903. }
  1904. static int ath12k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
  1905. {
  1906. switch ((mcs_map >> (2 * nss)) & 0x3) {
  1907. case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
  1908. case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
  1909. case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
  1910. }
  1911. return 0;
  1912. }
  1913. static u16
  1914. ath12k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
  1915. const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
  1916. {
  1917. int idx_limit;
  1918. int nss;
  1919. u16 mcs_map;
  1920. u16 mcs;
  1921. for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
  1922. mcs_map = ath12k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
  1923. vht_mcs_limit[nss];
  1924. if (mcs_map)
  1925. idx_limit = fls(mcs_map) - 1;
  1926. else
  1927. idx_limit = -1;
  1928. switch (idx_limit) {
  1929. case 0:
  1930. case 1:
  1931. case 2:
  1932. case 3:
  1933. case 4:
  1934. case 5:
  1935. case 6:
  1936. case 7:
  1937. mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
  1938. break;
  1939. case 8:
  1940. mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
  1941. break;
  1942. case 9:
  1943. mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
  1944. break;
  1945. default:
  1946. WARN_ON(1);
  1947. fallthrough;
  1948. case -1:
  1949. mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
  1950. break;
  1951. }
  1952. tx_mcs_set &= ~(0x3 << (nss * 2));
  1953. tx_mcs_set |= mcs << (nss * 2);
  1954. }
  1955. return tx_mcs_set;
  1956. }
  1957. static u8 ath12k_get_nss_160mhz(struct ath12k *ar,
  1958. u8 max_nss)
  1959. {
  1960. u8 nss_ratio_info = ar->pdev->cap.nss_ratio_info;
  1961. u8 max_sup_nss = 0;
  1962. switch (nss_ratio_info) {
  1963. case WMI_NSS_RATIO_1BY2_NSS:
  1964. max_sup_nss = max_nss >> 1;
  1965. break;
  1966. case WMI_NSS_RATIO_3BY4_NSS:
  1967. ath12k_warn(ar->ab, "WMI_NSS_RATIO_3BY4_NSS not supported\n");
  1968. break;
  1969. case WMI_NSS_RATIO_1_NSS:
  1970. max_sup_nss = max_nss;
  1971. break;
  1972. case WMI_NSS_RATIO_2_NSS:
  1973. ath12k_warn(ar->ab, "WMI_NSS_RATIO_2_NSS not supported\n");
  1974. break;
  1975. default:
  1976. ath12k_warn(ar->ab, "invalid nss ratio received from fw: %d\n",
  1977. nss_ratio_info);
  1978. break;
  1979. }
  1980. return max_sup_nss;
  1981. }
  1982. static void ath12k_peer_assoc_h_vht(struct ath12k *ar,
  1983. struct ath12k_link_vif *arvif,
  1984. struct ath12k_link_sta *arsta,
  1985. struct ath12k_wmi_peer_assoc_arg *arg)
  1986. {
  1987. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  1988. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  1989. const struct ieee80211_sta_vht_cap *vht_cap;
  1990. struct ieee80211_link_sta *link_sta;
  1991. struct cfg80211_chan_def def;
  1992. enum nl80211_band band;
  1993. u16 *vht_mcs_mask;
  1994. u8 ampdu_factor;
  1995. u8 max_nss, vht_mcs;
  1996. int i, vht_nss, nss_idx;
  1997. bool user_rate_valid = true;
  1998. u32 rx_nss, tx_nss, nss_160;
  1999. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  2000. if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)))
  2001. return;
  2002. link_sta = ath12k_mac_get_link_sta(arsta);
  2003. if (!link_sta) {
  2004. ath12k_warn(ar->ab, "unable to access link sta in peer assoc vht for sta %pM link %u\n",
  2005. sta->addr, arsta->link_id);
  2006. return;
  2007. }
  2008. vht_cap = &link_sta->vht_cap;
  2009. if (!vht_cap->vht_supported)
  2010. return;
  2011. band = def.chan->band;
  2012. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  2013. if (ath12k_peer_assoc_h_vht_masked(vht_mcs_mask))
  2014. return;
  2015. arg->vht_flag = true;
  2016. /* TODO: similar flags required? */
  2017. arg->vht_capable = true;
  2018. if (def.chan->band == NL80211_BAND_2GHZ)
  2019. arg->vht_ng_flag = true;
  2020. arg->peer_vht_caps = vht_cap->cap;
  2021. ampdu_factor = (vht_cap->cap &
  2022. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
  2023. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  2024. /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
  2025. * zero in VHT IE. Using it would result in degraded throughput.
  2026. * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
  2027. * it if VHT max_mpdu is smaller.
  2028. */
  2029. arg->peer_max_mpdu = max(arg->peer_max_mpdu,
  2030. (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  2031. ampdu_factor)) - 1);
  2032. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80)
  2033. arg->bw_80 = true;
  2034. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160)
  2035. arg->bw_160 = true;
  2036. vht_nss = ath12k_mac_max_vht_nss(vht_mcs_mask);
  2037. if (vht_nss > link_sta->rx_nss) {
  2038. user_rate_valid = false;
  2039. for (nss_idx = link_sta->rx_nss - 1; nss_idx >= 0; nss_idx--) {
  2040. if (vht_mcs_mask[nss_idx]) {
  2041. user_rate_valid = true;
  2042. break;
  2043. }
  2044. }
  2045. }
  2046. if (!user_rate_valid) {
  2047. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  2048. "Setting vht range MCS value to peer supported nss:%d for peer %pM\n",
  2049. link_sta->rx_nss, arsta->addr);
  2050. vht_mcs_mask[link_sta->rx_nss - 1] = vht_mcs_mask[vht_nss - 1];
  2051. }
  2052. /* Calculate peer NSS capability from VHT capabilities if STA
  2053. * supports VHT.
  2054. */
  2055. for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
  2056. vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
  2057. (2 * i) & 3;
  2058. if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED &&
  2059. vht_mcs_mask[i])
  2060. max_nss = i + 1;
  2061. }
  2062. arg->peer_nss = min(link_sta->rx_nss, max_nss);
  2063. arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
  2064. arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  2065. arg->rx_mcs_set = ath12k_peer_assoc_h_vht_limit(arg->rx_mcs_set, vht_mcs_mask);
  2066. arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
  2067. arg->tx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
  2068. /* In QCN9274 platform, VHT MCS rate 10 and 11 is enabled by default.
  2069. * VHT MCS rate 10 and 11 is not supported in 11ac standard.
  2070. * so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode.
  2071. */
  2072. arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK;
  2073. arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11;
  2074. if ((arg->tx_mcs_set & IEEE80211_VHT_MCS_NOT_SUPPORTED) ==
  2075. IEEE80211_VHT_MCS_NOT_SUPPORTED)
  2076. arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  2077. /* TODO: Check */
  2078. arg->tx_max_mcs_nss = 0xFF;
  2079. if (arg->peer_phymode == MODE_11AC_VHT160) {
  2080. tx_nss = ath12k_get_nss_160mhz(ar, max_nss);
  2081. rx_nss = min(arg->peer_nss, tx_nss);
  2082. arg->peer_bw_rxnss_override = ATH12K_BW_NSS_MAP_ENABLE;
  2083. if (!rx_nss) {
  2084. ath12k_warn(ar->ab, "invalid max_nss\n");
  2085. return;
  2086. }
  2087. nss_160 = u32_encode_bits(rx_nss - 1, ATH12K_PEER_RX_NSS_160MHZ);
  2088. arg->peer_bw_rxnss_override |= nss_160;
  2089. }
  2090. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  2091. "mac vht peer %pM max_mpdu %d flags 0x%x nss_override 0x%x\n",
  2092. arsta->addr, arg->peer_max_mpdu, arg->peer_flags,
  2093. arg->peer_bw_rxnss_override);
  2094. }
  2095. static int ath12k_mac_get_max_he_mcs_map(u16 mcs_map, int nss)
  2096. {
  2097. switch ((mcs_map >> (2 * nss)) & 0x3) {
  2098. case IEEE80211_HE_MCS_SUPPORT_0_7: return BIT(8) - 1;
  2099. case IEEE80211_HE_MCS_SUPPORT_0_9: return BIT(10) - 1;
  2100. case IEEE80211_HE_MCS_SUPPORT_0_11: return BIT(12) - 1;
  2101. }
  2102. return 0;
  2103. }
  2104. static u16 ath12k_peer_assoc_h_he_limit(u16 tx_mcs_set,
  2105. const u16 *he_mcs_limit)
  2106. {
  2107. int idx_limit;
  2108. int nss;
  2109. u16 mcs_map;
  2110. u16 mcs;
  2111. for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) {
  2112. mcs_map = ath12k_mac_get_max_he_mcs_map(tx_mcs_set, nss) &
  2113. he_mcs_limit[nss];
  2114. if (mcs_map)
  2115. idx_limit = fls(mcs_map) - 1;
  2116. else
  2117. idx_limit = -1;
  2118. switch (idx_limit) {
  2119. case 0 ... 7:
  2120. mcs = IEEE80211_HE_MCS_SUPPORT_0_7;
  2121. break;
  2122. case 8:
  2123. case 9:
  2124. mcs = IEEE80211_HE_MCS_SUPPORT_0_9;
  2125. break;
  2126. case 10:
  2127. case 11:
  2128. mcs = IEEE80211_HE_MCS_SUPPORT_0_11;
  2129. break;
  2130. default:
  2131. WARN_ON(1);
  2132. fallthrough;
  2133. case -1:
  2134. mcs = IEEE80211_HE_MCS_NOT_SUPPORTED;
  2135. break;
  2136. }
  2137. tx_mcs_set &= ~(0x3 << (nss * 2));
  2138. tx_mcs_set |= mcs << (nss * 2);
  2139. }
  2140. return tx_mcs_set;
  2141. }
  2142. static bool
  2143. ath12k_peer_assoc_h_he_masked(const u16 he_mcs_mask[NL80211_HE_NSS_MAX])
  2144. {
  2145. int nss;
  2146. for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++)
  2147. if (he_mcs_mask[nss])
  2148. return false;
  2149. return true;
  2150. }
  2151. static void ath12k_peer_assoc_h_he(struct ath12k *ar,
  2152. struct ath12k_link_vif *arvif,
  2153. struct ath12k_link_sta *arsta,
  2154. struct ath12k_wmi_peer_assoc_arg *arg)
  2155. {
  2156. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  2157. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  2158. const struct ieee80211_sta_he_cap *he_cap;
  2159. struct ieee80211_bss_conf *link_conf;
  2160. struct ieee80211_link_sta *link_sta;
  2161. struct cfg80211_chan_def def;
  2162. int i;
  2163. u8 ampdu_factor, max_nss;
  2164. u8 rx_mcs_80 = IEEE80211_HE_MCS_NOT_SUPPORTED;
  2165. u8 rx_mcs_160 = IEEE80211_HE_MCS_NOT_SUPPORTED;
  2166. u16 mcs_160_map, mcs_80_map;
  2167. u8 link_id = arvif->link_id;
  2168. bool support_160;
  2169. enum nl80211_band band;
  2170. u16 *he_mcs_mask;
  2171. u8 he_mcs;
  2172. u16 he_tx_mcs = 0, v = 0;
  2173. int he_nss, nss_idx;
  2174. bool user_rate_valid = true;
  2175. u32 rx_nss, tx_nss, nss_160;
  2176. if (WARN_ON(ath12k_mac_vif_link_chan(vif, link_id, &def)))
  2177. return;
  2178. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  2179. if (!link_conf) {
  2180. ath12k_warn(ar->ab, "unable to access bss link conf in peer assoc he for vif %pM link %u",
  2181. vif->addr, link_id);
  2182. return;
  2183. }
  2184. link_sta = ath12k_mac_get_link_sta(arsta);
  2185. if (!link_sta) {
  2186. ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n",
  2187. sta->addr, arsta->link_id);
  2188. return;
  2189. }
  2190. he_cap = &link_sta->he_cap;
  2191. if (!he_cap->has_he)
  2192. return;
  2193. band = def.chan->band;
  2194. he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs;
  2195. if (ath12k_peer_assoc_h_he_masked(he_mcs_mask))
  2196. return;
  2197. arg->he_flag = true;
  2198. support_160 = !!(he_cap->he_cap_elem.phy_cap_info[0] &
  2199. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G);
  2200. /* Supported HE-MCS and NSS Set of peer he_cap is intersection with self he_cp */
  2201. mcs_160_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
  2202. mcs_80_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
  2203. if (support_160) {
  2204. for (i = 7; i >= 0; i--) {
  2205. u8 mcs_160 = (mcs_160_map >> (2 * i)) & 3;
  2206. if (mcs_160 != IEEE80211_HE_MCS_NOT_SUPPORTED) {
  2207. rx_mcs_160 = i + 1;
  2208. break;
  2209. }
  2210. }
  2211. }
  2212. for (i = 7; i >= 0; i--) {
  2213. u8 mcs_80 = (mcs_80_map >> (2 * i)) & 3;
  2214. if (mcs_80 != IEEE80211_HE_MCS_NOT_SUPPORTED) {
  2215. rx_mcs_80 = i + 1;
  2216. break;
  2217. }
  2218. }
  2219. if (support_160)
  2220. max_nss = min(rx_mcs_80, rx_mcs_160);
  2221. else
  2222. max_nss = rx_mcs_80;
  2223. arg->peer_nss = min(link_sta->rx_nss, max_nss);
  2224. memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info,
  2225. sizeof(he_cap->he_cap_elem.mac_cap_info));
  2226. memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info,
  2227. sizeof(he_cap->he_cap_elem.phy_cap_info));
  2228. arg->peer_he_ops = link_conf->he_oper.params;
  2229. /* the top most byte is used to indicate BSS color info */
  2230. arg->peer_he_ops &= 0xffffff;
  2231. /* As per section 26.6.1 IEEE Std 802.11ax‐2022, if the Max AMPDU
  2232. * Exponent Extension in HE cap is zero, use the arg->peer_max_mpdu
  2233. * as calculated while parsing VHT caps(if VHT caps is present)
  2234. * or HT caps (if VHT caps is not present).
  2235. *
  2236. * For non-zero value of Max AMPDU Exponent Extension in HE MAC caps,
  2237. * if a HE STA sends VHT cap and HE cap IE in assoc request then, use
  2238. * MAX_AMPDU_LEN_FACTOR as 20 to calculate max_ampdu length.
  2239. * If a HE STA that does not send VHT cap, but HE and HT cap in assoc
  2240. * request, then use MAX_AMPDU_LEN_FACTOR as 16 to calculate max_ampdu
  2241. * length.
  2242. */
  2243. ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3],
  2244. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK);
  2245. if (ampdu_factor) {
  2246. if (link_sta->vht_cap.vht_supported)
  2247. arg->peer_max_mpdu = (1 << (IEEE80211_HE_VHT_MAX_AMPDU_FACTOR +
  2248. ampdu_factor)) - 1;
  2249. else if (link_sta->ht_cap.ht_supported)
  2250. arg->peer_max_mpdu = (1 << (IEEE80211_HE_HT_MAX_AMPDU_FACTOR +
  2251. ampdu_factor)) - 1;
  2252. }
  2253. if (he_cap->he_cap_elem.phy_cap_info[6] &
  2254. IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
  2255. int bit = 7;
  2256. int nss, ru;
  2257. arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] &
  2258. IEEE80211_PPE_THRES_NSS_MASK;
  2259. arg->peer_ppet.ru_bit_mask =
  2260. (he_cap->ppe_thres[0] &
  2261. IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
  2262. IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
  2263. for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) {
  2264. for (ru = 0; ru < 4; ru++) {
  2265. u32 val = 0;
  2266. int i;
  2267. if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0)
  2268. continue;
  2269. for (i = 0; i < 6; i++) {
  2270. val >>= 1;
  2271. val |= ((he_cap->ppe_thres[bit / 8] >>
  2272. (bit % 8)) & 0x1) << 5;
  2273. bit++;
  2274. }
  2275. arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |=
  2276. val << (ru * 6);
  2277. }
  2278. }
  2279. }
  2280. if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES)
  2281. arg->twt_responder = true;
  2282. if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ)
  2283. arg->twt_requester = true;
  2284. he_nss = ath12k_mac_max_he_nss(he_mcs_mask);
  2285. if (he_nss > link_sta->rx_nss) {
  2286. user_rate_valid = false;
  2287. for (nss_idx = link_sta->rx_nss - 1; nss_idx >= 0; nss_idx--) {
  2288. if (he_mcs_mask[nss_idx]) {
  2289. user_rate_valid = true;
  2290. break;
  2291. }
  2292. }
  2293. }
  2294. if (!user_rate_valid) {
  2295. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  2296. "Setting he range MCS value to peer supported nss:%d for peer %pM\n",
  2297. link_sta->rx_nss, arsta->addr);
  2298. he_mcs_mask[link_sta->rx_nss - 1] = he_mcs_mask[he_nss - 1];
  2299. }
  2300. switch (link_sta->bandwidth) {
  2301. case IEEE80211_STA_RX_BW_160:
  2302. v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
  2303. v = ath12k_peer_assoc_h_he_limit(v, he_mcs_mask);
  2304. arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
  2305. v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160);
  2306. arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
  2307. arg->peer_he_mcs_count++;
  2308. if (!he_tx_mcs)
  2309. he_tx_mcs = v;
  2310. fallthrough;
  2311. default:
  2312. v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
  2313. v = ath12k_peer_assoc_h_he_limit(v, he_mcs_mask);
  2314. arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
  2315. v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80);
  2316. arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
  2317. arg->peer_he_mcs_count++;
  2318. if (!he_tx_mcs)
  2319. he_tx_mcs = v;
  2320. break;
  2321. }
  2322. /* Calculate peer NSS capability from HE capabilities if STA
  2323. * supports HE.
  2324. */
  2325. for (i = 0, max_nss = 0, he_mcs = 0; i < NL80211_HE_NSS_MAX; i++) {
  2326. he_mcs = he_tx_mcs >> (2 * i) & 3;
  2327. /* In case of fixed rates, MCS Range in he_tx_mcs might have
  2328. * unsupported range, with he_mcs_mask set, so check either of them
  2329. * to find nss.
  2330. */
  2331. if (he_mcs != IEEE80211_HE_MCS_NOT_SUPPORTED ||
  2332. he_mcs_mask[i])
  2333. max_nss = i + 1;
  2334. }
  2335. max_nss = min(max_nss, ar->num_tx_chains);
  2336. arg->peer_nss = min(link_sta->rx_nss, max_nss);
  2337. if (arg->peer_phymode == MODE_11AX_HE160) {
  2338. tx_nss = ath12k_get_nss_160mhz(ar, ar->num_tx_chains);
  2339. rx_nss = min(arg->peer_nss, tx_nss);
  2340. arg->peer_nss = min(link_sta->rx_nss, ar->num_rx_chains);
  2341. arg->peer_bw_rxnss_override = ATH12K_BW_NSS_MAP_ENABLE;
  2342. if (!rx_nss) {
  2343. ath12k_warn(ar->ab, "invalid max_nss\n");
  2344. return;
  2345. }
  2346. nss_160 = u32_encode_bits(rx_nss - 1, ATH12K_PEER_RX_NSS_160MHZ);
  2347. arg->peer_bw_rxnss_override |= nss_160;
  2348. }
  2349. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  2350. "mac he peer %pM nss %d mcs cnt %d nss_override 0x%x\n",
  2351. arsta->addr, arg->peer_nss,
  2352. arg->peer_he_mcs_count,
  2353. arg->peer_bw_rxnss_override);
  2354. }
  2355. static void ath12k_peer_assoc_h_he_6ghz(struct ath12k *ar,
  2356. struct ath12k_link_vif *arvif,
  2357. struct ath12k_link_sta *arsta,
  2358. struct ath12k_wmi_peer_assoc_arg *arg)
  2359. {
  2360. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  2361. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  2362. const struct ieee80211_sta_he_cap *he_cap;
  2363. struct ieee80211_link_sta *link_sta;
  2364. struct cfg80211_chan_def def;
  2365. enum nl80211_band band;
  2366. u8 ampdu_factor, mpdu_density;
  2367. if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)))
  2368. return;
  2369. band = def.chan->band;
  2370. link_sta = ath12k_mac_get_link_sta(arsta);
  2371. if (!link_sta) {
  2372. ath12k_warn(ar->ab, "unable to access link sta in peer assoc he 6ghz for sta %pM link %u\n",
  2373. sta->addr, arsta->link_id);
  2374. return;
  2375. }
  2376. he_cap = &link_sta->he_cap;
  2377. if (!arg->he_flag || band != NL80211_BAND_6GHZ || !link_sta->he_6ghz_capa.capa)
  2378. return;
  2379. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40)
  2380. arg->bw_40 = true;
  2381. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80)
  2382. arg->bw_80 = true;
  2383. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160)
  2384. arg->bw_160 = true;
  2385. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_320)
  2386. arg->bw_320 = true;
  2387. arg->peer_he_caps_6ghz = le16_to_cpu(link_sta->he_6ghz_capa.capa);
  2388. mpdu_density = u32_get_bits(arg->peer_he_caps_6ghz,
  2389. IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START);
  2390. arg->peer_mpdu_density = ath12k_parse_mpdudensity(mpdu_density);
  2391. /* From IEEE Std 802.11ax-2021 - Section 10.12.2: An HE STA shall be capable of
  2392. * receiving A-MPDU where the A-MPDU pre-EOF padding length is up to the value
  2393. * indicated by the Maximum A-MPDU Length Exponent Extension field in the HE
  2394. * Capabilities element and the Maximum A-MPDU Length Exponent field in HE 6 GHz
  2395. * Band Capabilities element in the 6 GHz band.
  2396. *
  2397. * Here, we are extracting the Max A-MPDU Exponent Extension from HE caps and
  2398. * factor is the Maximum A-MPDU Length Exponent from HE 6 GHZ Band capability.
  2399. */
  2400. ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3],
  2401. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK) +
  2402. u32_get_bits(arg->peer_he_caps_6ghz,
  2403. IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP);
  2404. arg->peer_max_mpdu = (1u << (IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR +
  2405. ampdu_factor)) - 1;
  2406. }
  2407. static int ath12k_get_smps_from_capa(const struct ieee80211_sta_ht_cap *ht_cap,
  2408. const struct ieee80211_he_6ghz_capa *he_6ghz_capa,
  2409. int *smps)
  2410. {
  2411. if (ht_cap->ht_supported)
  2412. *smps = u16_get_bits(ht_cap->cap, IEEE80211_HT_CAP_SM_PS);
  2413. else
  2414. *smps = le16_get_bits(he_6ghz_capa->capa,
  2415. IEEE80211_HE_6GHZ_CAP_SM_PS);
  2416. if (*smps >= ARRAY_SIZE(ath12k_smps_map))
  2417. return -EINVAL;
  2418. return 0;
  2419. }
  2420. static void ath12k_peer_assoc_h_smps(struct ath12k_link_sta *arsta,
  2421. struct ath12k_wmi_peer_assoc_arg *arg)
  2422. {
  2423. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  2424. const struct ieee80211_he_6ghz_capa *he_6ghz_capa;
  2425. struct ath12k_link_vif *arvif = arsta->arvif;
  2426. const struct ieee80211_sta_ht_cap *ht_cap;
  2427. struct ieee80211_link_sta *link_sta;
  2428. struct ath12k *ar = arvif->ar;
  2429. int smps;
  2430. link_sta = ath12k_mac_get_link_sta(arsta);
  2431. if (!link_sta) {
  2432. ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n",
  2433. sta->addr, arsta->link_id);
  2434. return;
  2435. }
  2436. he_6ghz_capa = &link_sta->he_6ghz_capa;
  2437. ht_cap = &link_sta->ht_cap;
  2438. if (!ht_cap->ht_supported && !he_6ghz_capa->capa)
  2439. return;
  2440. if (ath12k_get_smps_from_capa(ht_cap, he_6ghz_capa, &smps))
  2441. return;
  2442. switch (smps) {
  2443. case WLAN_HT_CAP_SM_PS_STATIC:
  2444. arg->static_mimops_flag = true;
  2445. break;
  2446. case WLAN_HT_CAP_SM_PS_DYNAMIC:
  2447. arg->dynamic_mimops_flag = true;
  2448. break;
  2449. case WLAN_HT_CAP_SM_PS_DISABLED:
  2450. arg->spatial_mux_flag = true;
  2451. break;
  2452. default:
  2453. break;
  2454. }
  2455. }
  2456. static void ath12k_peer_assoc_h_qos(struct ath12k *ar,
  2457. struct ath12k_link_vif *arvif,
  2458. struct ath12k_link_sta *arsta,
  2459. struct ath12k_wmi_peer_assoc_arg *arg)
  2460. {
  2461. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  2462. switch (arvif->ahvif->vdev_type) {
  2463. case WMI_VDEV_TYPE_AP:
  2464. if (sta->wme) {
  2465. /* TODO: Check WME vs QoS */
  2466. arg->is_wme_set = true;
  2467. arg->qos_flag = true;
  2468. }
  2469. if (sta->wme && sta->uapsd_queues) {
  2470. /* TODO: Check WME vs QoS */
  2471. arg->is_wme_set = true;
  2472. arg->apsd_flag = true;
  2473. arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG;
  2474. }
  2475. break;
  2476. case WMI_VDEV_TYPE_STA:
  2477. if (sta->wme) {
  2478. arg->is_wme_set = true;
  2479. arg->qos_flag = true;
  2480. }
  2481. break;
  2482. default:
  2483. break;
  2484. }
  2485. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac peer %pM qos %d\n",
  2486. arsta->addr, arg->qos_flag);
  2487. }
  2488. static int ath12k_peer_assoc_qos_ap(struct ath12k *ar,
  2489. struct ath12k_link_vif *arvif,
  2490. struct ath12k_link_sta *arsta)
  2491. {
  2492. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  2493. struct ath12k_wmi_ap_ps_arg arg;
  2494. u32 max_sp;
  2495. u32 uapsd;
  2496. int ret;
  2497. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  2498. arg.vdev_id = arvif->vdev_id;
  2499. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
  2500. sta->uapsd_queues, sta->max_sp);
  2501. uapsd = 0;
  2502. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  2503. uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
  2504. WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
  2505. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  2506. uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
  2507. WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
  2508. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  2509. uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
  2510. WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
  2511. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  2512. uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
  2513. WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
  2514. max_sp = 0;
  2515. if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
  2516. max_sp = sta->max_sp;
  2517. arg.param = WMI_AP_PS_PEER_PARAM_UAPSD;
  2518. arg.value = uapsd;
  2519. ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg);
  2520. if (ret)
  2521. goto err;
  2522. arg.param = WMI_AP_PS_PEER_PARAM_MAX_SP;
  2523. arg.value = max_sp;
  2524. ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg);
  2525. if (ret)
  2526. goto err;
  2527. /* TODO: revisit during testing */
  2528. arg.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE;
  2529. arg.value = DISABLE_SIFS_RESPONSE_TRIGGER;
  2530. ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg);
  2531. if (ret)
  2532. goto err;
  2533. arg.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD;
  2534. arg.value = DISABLE_SIFS_RESPONSE_TRIGGER;
  2535. ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg);
  2536. if (ret)
  2537. goto err;
  2538. return 0;
  2539. err:
  2540. ath12k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n",
  2541. arg.param, arvif->vdev_id, ret);
  2542. return ret;
  2543. }
  2544. static bool ath12k_mac_sta_has_ofdm_only(struct ieee80211_link_sta *sta)
  2545. {
  2546. return sta->supp_rates[NL80211_BAND_2GHZ] >>
  2547. ATH12K_MAC_FIRST_OFDM_RATE_IDX;
  2548. }
  2549. static enum wmi_phy_mode ath12k_mac_get_phymode_vht(struct ath12k *ar,
  2550. struct ieee80211_link_sta *link_sta)
  2551. {
  2552. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) {
  2553. if (link_sta->vht_cap.cap & (IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
  2554. IEEE80211_VHT_CAP_EXT_NSS_BW_MASK))
  2555. return MODE_11AC_VHT160;
  2556. /* Allow STA to connect even if it does not explicitly advertise 160 MHz
  2557. * support
  2558. */
  2559. return MODE_11AC_VHT160;
  2560. }
  2561. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80)
  2562. return MODE_11AC_VHT80;
  2563. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40)
  2564. return MODE_11AC_VHT40;
  2565. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20)
  2566. return MODE_11AC_VHT20;
  2567. return MODE_UNKNOWN;
  2568. }
  2569. static enum wmi_phy_mode ath12k_mac_get_phymode_he(struct ath12k *ar,
  2570. struct ieee80211_link_sta *link_sta)
  2571. {
  2572. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) {
  2573. if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] &
  2574. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
  2575. return MODE_11AX_HE160;
  2576. return MODE_UNKNOWN;
  2577. }
  2578. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80)
  2579. return MODE_11AX_HE80;
  2580. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40)
  2581. return MODE_11AX_HE40;
  2582. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20)
  2583. return MODE_11AX_HE20;
  2584. return MODE_UNKNOWN;
  2585. }
  2586. static enum wmi_phy_mode ath12k_mac_get_phymode_eht(struct ath12k *ar,
  2587. struct ieee80211_link_sta *link_sta)
  2588. {
  2589. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_320)
  2590. if (link_sta->eht_cap.eht_cap_elem.phy_cap_info[0] &
  2591. IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ)
  2592. return MODE_11BE_EHT320;
  2593. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) {
  2594. if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] &
  2595. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
  2596. return MODE_11BE_EHT160;
  2597. ath12k_warn(ar->ab, "invalid EHT PHY capability info for 160 Mhz: %d\n",
  2598. link_sta->he_cap.he_cap_elem.phy_cap_info[0]);
  2599. return MODE_UNKNOWN;
  2600. }
  2601. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80)
  2602. return MODE_11BE_EHT80;
  2603. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40)
  2604. return MODE_11BE_EHT40;
  2605. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20)
  2606. return MODE_11BE_EHT20;
  2607. return MODE_UNKNOWN;
  2608. }
  2609. static bool
  2610. ath12k_peer_assoc_h_eht_masked(const u16 eht_mcs_mask[NL80211_EHT_NSS_MAX])
  2611. {
  2612. int nss;
  2613. for (nss = 0; nss < NL80211_EHT_NSS_MAX; nss++)
  2614. if (eht_mcs_mask[nss])
  2615. return false;
  2616. return true;
  2617. }
  2618. static void ath12k_peer_assoc_h_phymode(struct ath12k *ar,
  2619. struct ath12k_link_vif *arvif,
  2620. struct ath12k_link_sta *arsta,
  2621. struct ath12k_wmi_peer_assoc_arg *arg)
  2622. {
  2623. struct ieee80211_link_sta *link_sta;
  2624. struct cfg80211_chan_def def;
  2625. enum nl80211_band band;
  2626. const u8 *ht_mcs_mask;
  2627. const u16 *vht_mcs_mask;
  2628. const u16 *he_mcs_mask;
  2629. const u16 *eht_mcs_mask;
  2630. enum wmi_phy_mode phymode = MODE_UNKNOWN;
  2631. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  2632. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  2633. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  2634. if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)))
  2635. return;
  2636. band = def.chan->band;
  2637. ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
  2638. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  2639. he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs;
  2640. eht_mcs_mask = arvif->bitrate_mask.control[band].eht_mcs;
  2641. link_sta = ath12k_mac_get_link_sta(arsta);
  2642. if (!link_sta) {
  2643. ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n",
  2644. sta->addr, arsta->link_id);
  2645. return;
  2646. }
  2647. switch (band) {
  2648. case NL80211_BAND_2GHZ:
  2649. if (link_sta->eht_cap.has_eht &&
  2650. !ath12k_peer_assoc_h_eht_masked(eht_mcs_mask)) {
  2651. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40)
  2652. phymode = MODE_11BE_EHT40_2G;
  2653. else
  2654. phymode = MODE_11BE_EHT20_2G;
  2655. } else if (link_sta->he_cap.has_he &&
  2656. !ath12k_peer_assoc_h_he_masked(he_mcs_mask)) {
  2657. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80)
  2658. phymode = MODE_11AX_HE80_2G;
  2659. else if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40)
  2660. phymode = MODE_11AX_HE40_2G;
  2661. else
  2662. phymode = MODE_11AX_HE20_2G;
  2663. } else if (link_sta->vht_cap.vht_supported &&
  2664. !ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
  2665. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40)
  2666. phymode = MODE_11AC_VHT40;
  2667. else
  2668. phymode = MODE_11AC_VHT20;
  2669. } else if (link_sta->ht_cap.ht_supported &&
  2670. !ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
  2671. if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40)
  2672. phymode = MODE_11NG_HT40;
  2673. else
  2674. phymode = MODE_11NG_HT20;
  2675. } else if (ath12k_mac_sta_has_ofdm_only(link_sta)) {
  2676. phymode = MODE_11G;
  2677. } else {
  2678. phymode = MODE_11B;
  2679. }
  2680. break;
  2681. case NL80211_BAND_5GHZ:
  2682. case NL80211_BAND_6GHZ:
  2683. /* Check EHT first */
  2684. if (link_sta->eht_cap.has_eht) {
  2685. phymode = ath12k_mac_get_phymode_eht(ar, link_sta);
  2686. } else if (link_sta->he_cap.has_he &&
  2687. !ath12k_peer_assoc_h_he_masked(he_mcs_mask)) {
  2688. phymode = ath12k_mac_get_phymode_he(ar, link_sta);
  2689. } else if (link_sta->vht_cap.vht_supported &&
  2690. !ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
  2691. phymode = ath12k_mac_get_phymode_vht(ar, link_sta);
  2692. } else if (link_sta->ht_cap.ht_supported &&
  2693. !ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
  2694. if (link_sta->bandwidth >= IEEE80211_STA_RX_BW_40)
  2695. phymode = MODE_11NA_HT40;
  2696. else
  2697. phymode = MODE_11NA_HT20;
  2698. } else {
  2699. phymode = MODE_11A;
  2700. }
  2701. break;
  2702. default:
  2703. break;
  2704. }
  2705. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac peer %pM phymode %s\n",
  2706. arsta->addr, ath12k_mac_phymode_str(phymode));
  2707. arg->peer_phymode = phymode;
  2708. WARN_ON(phymode == MODE_UNKNOWN);
  2709. }
  2710. #define ATH12K_EHT_MCS_7_ENABLED 0x00FF
  2711. #define ATH12K_EHT_MCS_9_ENABLED 0x0300
  2712. #define ATH12K_EHT_MCS_11_ENABLED 0x0C00
  2713. #define ATH12K_EHT_MCS_13_ENABLED 0x3000
  2714. static void ath12k_mac_set_eht_mcs(u8 rx_tx_mcs7, u8 rx_tx_mcs9,
  2715. u8 rx_tx_mcs11, u8 rx_tx_mcs13,
  2716. u32 *rx_mcs, u32 *tx_mcs,
  2717. const u16 eht_mcs_limit[NL80211_EHT_NSS_MAX])
  2718. {
  2719. int nss;
  2720. u8 mcs_7 = 0, mcs_9 = 0, mcs_11 = 0, mcs_13 = 0;
  2721. u8 peer_mcs_7, peer_mcs_9, peer_mcs_11, peer_mcs_13;
  2722. for (nss = 0; nss < NL80211_EHT_NSS_MAX; nss++) {
  2723. if (eht_mcs_limit[nss] & ATH12K_EHT_MCS_7_ENABLED)
  2724. mcs_7++;
  2725. if (eht_mcs_limit[nss] & ATH12K_EHT_MCS_9_ENABLED)
  2726. mcs_9++;
  2727. if (eht_mcs_limit[nss] & ATH12K_EHT_MCS_11_ENABLED)
  2728. mcs_11++;
  2729. if (eht_mcs_limit[nss] & ATH12K_EHT_MCS_13_ENABLED)
  2730. mcs_13++;
  2731. }
  2732. peer_mcs_7 = u8_get_bits(rx_tx_mcs7, IEEE80211_EHT_MCS_NSS_RX);
  2733. peer_mcs_9 = u8_get_bits(rx_tx_mcs9, IEEE80211_EHT_MCS_NSS_RX);
  2734. peer_mcs_11 = u8_get_bits(rx_tx_mcs11, IEEE80211_EHT_MCS_NSS_RX);
  2735. peer_mcs_13 = u8_get_bits(rx_tx_mcs13, IEEE80211_EHT_MCS_NSS_RX);
  2736. *rx_mcs = u32_encode_bits(min(peer_mcs_7, mcs_7), WMI_EHT_MCS_NSS_0_7) |
  2737. u32_encode_bits(min(peer_mcs_9, mcs_9), WMI_EHT_MCS_NSS_8_9) |
  2738. u32_encode_bits(min(peer_mcs_11, mcs_11), WMI_EHT_MCS_NSS_10_11) |
  2739. u32_encode_bits(min(peer_mcs_13, mcs_13), WMI_EHT_MCS_NSS_12_13);
  2740. peer_mcs_7 = u8_get_bits(rx_tx_mcs7, IEEE80211_EHT_MCS_NSS_TX);
  2741. peer_mcs_9 = u8_get_bits(rx_tx_mcs9, IEEE80211_EHT_MCS_NSS_TX);
  2742. peer_mcs_11 = u8_get_bits(rx_tx_mcs11, IEEE80211_EHT_MCS_NSS_TX);
  2743. peer_mcs_13 = u8_get_bits(rx_tx_mcs13, IEEE80211_EHT_MCS_NSS_TX);
  2744. *tx_mcs = u32_encode_bits(min(peer_mcs_7, mcs_7), WMI_EHT_MCS_NSS_0_7) |
  2745. u32_encode_bits(min(peer_mcs_9, mcs_9), WMI_EHT_MCS_NSS_8_9) |
  2746. u32_encode_bits(min(peer_mcs_11, mcs_11), WMI_EHT_MCS_NSS_10_11) |
  2747. u32_encode_bits(min(peer_mcs_13, mcs_13), WMI_EHT_MCS_NSS_12_13);
  2748. }
  2749. static void ath12k_mac_set_eht_ppe_threshold(const u8 *ppe_thres,
  2750. struct ath12k_wmi_ppe_threshold_arg *ppet)
  2751. {
  2752. u32 bit_pos = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE, val;
  2753. u8 nss, ru, i;
  2754. u8 ppet_bit_len_per_ru = IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE * 2;
  2755. ppet->numss_m1 = u8_get_bits(ppe_thres[0], IEEE80211_EHT_PPE_THRES_NSS_MASK);
  2756. ppet->ru_bit_mask = u16_get_bits(get_unaligned_le16(ppe_thres),
  2757. IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK);
  2758. for (nss = 0; nss <= ppet->numss_m1; nss++) {
  2759. for (ru = 0;
  2760. ru < hweight16(IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK);
  2761. ru++) {
  2762. if ((ppet->ru_bit_mask & BIT(ru)) == 0)
  2763. continue;
  2764. val = 0;
  2765. for (i = 0; i < ppet_bit_len_per_ru; i++) {
  2766. val |= (((ppe_thres[bit_pos / 8] >>
  2767. (bit_pos % 8)) & 0x1) << i);
  2768. bit_pos++;
  2769. }
  2770. ppet->ppet16_ppet8_ru3_ru0[nss] |=
  2771. (val << (ru * ppet_bit_len_per_ru));
  2772. }
  2773. }
  2774. }
  2775. static void ath12k_peer_assoc_h_eht(struct ath12k *ar,
  2776. struct ath12k_link_vif *arvif,
  2777. struct ath12k_link_sta *arsta,
  2778. struct ath12k_wmi_peer_assoc_arg *arg)
  2779. {
  2780. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  2781. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  2782. const struct ieee80211_eht_mcs_nss_supp *own_eht_mcs_nss_supp;
  2783. const struct ieee80211_eht_mcs_nss_supp_20mhz_only *bw_20;
  2784. const struct ieee80211_sta_eht_cap *eht_cap, *own_eht_cap;
  2785. const struct ieee80211_sband_iftype_data *iftd;
  2786. const struct ieee80211_eht_mcs_nss_supp_bw *bw;
  2787. const struct ieee80211_sta_he_cap *he_cap;
  2788. struct ieee80211_link_sta *link_sta;
  2789. struct ieee80211_bss_conf *link_conf;
  2790. struct cfg80211_chan_def def;
  2791. bool user_rate_valid = true;
  2792. enum nl80211_band band;
  2793. int eht_nss, nss_idx;
  2794. u32 *rx_mcs, *tx_mcs;
  2795. u16 *eht_mcs_mask;
  2796. u8 max_nss = 0;
  2797. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  2798. link_sta = ath12k_mac_get_link_sta(arsta);
  2799. if (!link_sta) {
  2800. ath12k_warn(ar->ab, "unable to access link sta in peer assoc eht for sta %pM link %u\n",
  2801. sta->addr, arsta->link_id);
  2802. return;
  2803. }
  2804. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  2805. if (!link_conf) {
  2806. ath12k_warn(ar->ab, "unable to access link_conf in peer assoc eht set\n");
  2807. return;
  2808. }
  2809. eht_cap = &link_sta->eht_cap;
  2810. he_cap = &link_sta->he_cap;
  2811. if (!he_cap->has_he || !eht_cap->has_eht)
  2812. return;
  2813. if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)))
  2814. return;
  2815. band = def.chan->band;
  2816. eht_mcs_mask = arvif->bitrate_mask.control[band].eht_mcs;
  2817. iftd = ieee80211_get_sband_iftype_data(&ar->mac.sbands[band], vif->type);
  2818. if (!iftd) {
  2819. ath12k_warn(ar->ab,
  2820. "unable to access iftype_data in struct ieee80211_supported_band\n");
  2821. return;
  2822. }
  2823. own_eht_cap = &iftd->eht_cap;
  2824. own_eht_mcs_nss_supp = &own_eht_cap->eht_mcs_nss_supp;
  2825. arg->eht_flag = true;
  2826. if ((eht_cap->eht_cap_elem.phy_cap_info[5] &
  2827. IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) &&
  2828. eht_cap->eht_ppe_thres[0] != 0)
  2829. ath12k_mac_set_eht_ppe_threshold(eht_cap->eht_ppe_thres,
  2830. &arg->peer_eht_ppet);
  2831. memcpy(arg->peer_eht_cap_mac, eht_cap->eht_cap_elem.mac_cap_info,
  2832. sizeof(eht_cap->eht_cap_elem.mac_cap_info));
  2833. memcpy(arg->peer_eht_cap_phy, eht_cap->eht_cap_elem.phy_cap_info,
  2834. sizeof(eht_cap->eht_cap_elem.phy_cap_info));
  2835. rx_mcs = arg->peer_eht_rx_mcs_set;
  2836. tx_mcs = arg->peer_eht_tx_mcs_set;
  2837. eht_nss = ath12k_mac_max_eht_mcs_nss((void *)own_eht_mcs_nss_supp,
  2838. sizeof(*own_eht_mcs_nss_supp));
  2839. if (eht_nss > link_sta->rx_nss) {
  2840. user_rate_valid = false;
  2841. for (nss_idx = (link_sta->rx_nss - 1); nss_idx >= 0; nss_idx--) {
  2842. if (eht_mcs_mask[nss_idx]) {
  2843. user_rate_valid = true;
  2844. break;
  2845. }
  2846. }
  2847. }
  2848. if (!user_rate_valid) {
  2849. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  2850. "Setting eht range MCS value to peer supported nss %d for peer %pM\n",
  2851. link_sta->rx_nss, arsta->addr);
  2852. eht_mcs_mask[link_sta->rx_nss - 1] = eht_mcs_mask[eht_nss - 1];
  2853. }
  2854. bw_20 = &eht_cap->eht_mcs_nss_supp.only_20mhz;
  2855. bw = &eht_cap->eht_mcs_nss_supp.bw._80;
  2856. switch (link_sta->bandwidth) {
  2857. case IEEE80211_STA_RX_BW_320:
  2858. bw = &eht_cap->eht_mcs_nss_supp.bw._320;
  2859. ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss,
  2860. bw->rx_tx_mcs9_max_nss,
  2861. bw->rx_tx_mcs11_max_nss,
  2862. bw->rx_tx_mcs13_max_nss,
  2863. &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_320],
  2864. &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_320],
  2865. eht_mcs_mask);
  2866. arg->peer_eht_mcs_count++;
  2867. fallthrough;
  2868. case IEEE80211_STA_RX_BW_160:
  2869. bw = &eht_cap->eht_mcs_nss_supp.bw._160;
  2870. ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss,
  2871. bw->rx_tx_mcs9_max_nss,
  2872. bw->rx_tx_mcs11_max_nss,
  2873. bw->rx_tx_mcs13_max_nss,
  2874. &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_160],
  2875. &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_160],
  2876. eht_mcs_mask);
  2877. arg->peer_eht_mcs_count++;
  2878. fallthrough;
  2879. default:
  2880. if (!(link_sta->he_cap.he_cap_elem.phy_cap_info[0] &
  2881. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL)) {
  2882. bw_20 = &eht_cap->eht_mcs_nss_supp.only_20mhz;
  2883. ath12k_mac_set_eht_mcs(bw_20->rx_tx_mcs7_max_nss,
  2884. bw_20->rx_tx_mcs9_max_nss,
  2885. bw_20->rx_tx_mcs11_max_nss,
  2886. bw_20->rx_tx_mcs13_max_nss,
  2887. &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80],
  2888. &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80],
  2889. eht_mcs_mask);
  2890. } else {
  2891. bw = &eht_cap->eht_mcs_nss_supp.bw._80;
  2892. ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss,
  2893. bw->rx_tx_mcs9_max_nss,
  2894. bw->rx_tx_mcs11_max_nss,
  2895. bw->rx_tx_mcs13_max_nss,
  2896. &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80],
  2897. &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80],
  2898. eht_mcs_mask);
  2899. }
  2900. arg->peer_eht_mcs_count++;
  2901. break;
  2902. }
  2903. arg->punct_bitmap = ~arvif->punct_bitmap;
  2904. arg->eht_disable_mcs15 = link_conf->eht_disable_mcs15;
  2905. if (!(link_sta->he_cap.he_cap_elem.phy_cap_info[0] &
  2906. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL)) {
  2907. if (bw_20->rx_tx_mcs13_max_nss)
  2908. max_nss = max(max_nss, u8_get_bits(bw_20->rx_tx_mcs13_max_nss,
  2909. IEEE80211_EHT_MCS_NSS_RX));
  2910. if (bw_20->rx_tx_mcs11_max_nss)
  2911. max_nss = max(max_nss, u8_get_bits(bw_20->rx_tx_mcs11_max_nss,
  2912. IEEE80211_EHT_MCS_NSS_RX));
  2913. if (bw_20->rx_tx_mcs9_max_nss)
  2914. max_nss = max(max_nss, u8_get_bits(bw_20->rx_tx_mcs9_max_nss,
  2915. IEEE80211_EHT_MCS_NSS_RX));
  2916. if (bw_20->rx_tx_mcs7_max_nss)
  2917. max_nss = max(max_nss, u8_get_bits(bw_20->rx_tx_mcs7_max_nss,
  2918. IEEE80211_EHT_MCS_NSS_RX));
  2919. } else {
  2920. if (bw->rx_tx_mcs13_max_nss)
  2921. max_nss = max(max_nss, u8_get_bits(bw->rx_tx_mcs13_max_nss,
  2922. IEEE80211_EHT_MCS_NSS_RX));
  2923. if (bw->rx_tx_mcs11_max_nss)
  2924. max_nss = max(max_nss, u8_get_bits(bw->rx_tx_mcs11_max_nss,
  2925. IEEE80211_EHT_MCS_NSS_RX));
  2926. if (bw->rx_tx_mcs9_max_nss)
  2927. max_nss = max(max_nss, u8_get_bits(bw->rx_tx_mcs9_max_nss,
  2928. IEEE80211_EHT_MCS_NSS_RX));
  2929. }
  2930. max_nss = min(max_nss, (uint8_t)eht_nss);
  2931. arg->peer_nss = min(link_sta->rx_nss, max_nss);
  2932. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  2933. "mac eht peer %pM nss %d mcs cnt %d ru_punct_bitmap 0x%x\n",
  2934. arsta->addr, arg->peer_nss, arg->peer_eht_mcs_count,
  2935. arg->punct_bitmap);
  2936. }
  2937. static void ath12k_peer_assoc_h_mlo(struct ath12k_link_sta *arsta,
  2938. struct ath12k_wmi_peer_assoc_arg *arg)
  2939. {
  2940. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  2941. struct peer_assoc_mlo_params *ml = &arg->ml;
  2942. struct ath12k_sta *ahsta = arsta->ahsta;
  2943. struct ath12k_link_sta *arsta_p;
  2944. struct ath12k_link_vif *arvif;
  2945. unsigned long links;
  2946. u8 link_id;
  2947. int i;
  2948. if (!sta->mlo || ahsta->ml_peer_id == ATH12K_MLO_PEER_ID_INVALID)
  2949. return;
  2950. ml->enabled = true;
  2951. ml->assoc_link = arsta->is_assoc_link;
  2952. /* For now considering the primary umac based on assoc link */
  2953. ml->primary_umac = arsta->is_assoc_link;
  2954. ml->peer_id_valid = true;
  2955. ml->logical_link_idx_valid = true;
  2956. ether_addr_copy(ml->mld_addr, sta->addr);
  2957. ml->logical_link_idx = arsta->link_idx;
  2958. ml->ml_peer_id = ahsta->ml_peer_id;
  2959. ml->ieee_link_id = arsta->link_id;
  2960. ml->num_partner_links = 0;
  2961. ml->eml_cap = sta->eml_cap;
  2962. links = ahsta->links_map;
  2963. rcu_read_lock();
  2964. i = 0;
  2965. for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
  2966. if (i >= ATH12K_WMI_MLO_MAX_LINKS)
  2967. break;
  2968. arsta_p = rcu_dereference(ahsta->link[link_id]);
  2969. arvif = rcu_dereference(ahsta->ahvif->link[link_id]);
  2970. if (arsta_p == arsta)
  2971. continue;
  2972. if (!arvif->is_started)
  2973. continue;
  2974. ml->partner_info[i].vdev_id = arvif->vdev_id;
  2975. ml->partner_info[i].hw_link_id = arvif->ar->pdev->hw_link_id;
  2976. ml->partner_info[i].assoc_link = arsta_p->is_assoc_link;
  2977. ml->partner_info[i].primary_umac = arsta_p->is_assoc_link;
  2978. ml->partner_info[i].logical_link_idx_valid = true;
  2979. ml->partner_info[i].logical_link_idx = arsta_p->link_idx;
  2980. ml->num_partner_links++;
  2981. i++;
  2982. }
  2983. rcu_read_unlock();
  2984. }
  2985. static void ath12k_peer_assoc_prepare(struct ath12k *ar,
  2986. struct ath12k_link_vif *arvif,
  2987. struct ath12k_link_sta *arsta,
  2988. struct ath12k_wmi_peer_assoc_arg *arg,
  2989. bool reassoc)
  2990. {
  2991. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  2992. memset(arg, 0, sizeof(*arg));
  2993. reinit_completion(&ar->peer_assoc_done);
  2994. arg->peer_new_assoc = !reassoc;
  2995. ath12k_peer_assoc_h_basic(ar, arvif, arsta, arg);
  2996. ath12k_peer_assoc_h_crypto(ar, arvif, arsta, arg);
  2997. ath12k_peer_assoc_h_rates(ar, arvif, arsta, arg);
  2998. ath12k_peer_assoc_h_ht(ar, arvif, arsta, arg);
  2999. ath12k_peer_assoc_h_vht(ar, arvif, arsta, arg);
  3000. ath12k_peer_assoc_h_he(ar, arvif, arsta, arg);
  3001. ath12k_peer_assoc_h_he_6ghz(ar, arvif, arsta, arg);
  3002. ath12k_peer_assoc_h_eht(ar, arvif, arsta, arg);
  3003. ath12k_peer_assoc_h_qos(ar, arvif, arsta, arg);
  3004. ath12k_peer_assoc_h_phymode(ar, arvif, arsta, arg);
  3005. ath12k_peer_assoc_h_smps(arsta, arg);
  3006. ath12k_peer_assoc_h_mlo(arsta, arg);
  3007. arsta->peer_nss = arg->peer_nss;
  3008. /* TODO: amsdu_disable req? */
  3009. }
  3010. static int ath12k_setup_peer_smps(struct ath12k *ar, struct ath12k_link_vif *arvif,
  3011. const u8 *addr,
  3012. const struct ieee80211_sta_ht_cap *ht_cap,
  3013. const struct ieee80211_he_6ghz_capa *he_6ghz_capa)
  3014. {
  3015. int smps, ret = 0;
  3016. if (!ht_cap->ht_supported && !he_6ghz_capa)
  3017. return 0;
  3018. ret = ath12k_get_smps_from_capa(ht_cap, he_6ghz_capa, &smps);
  3019. if (ret < 0)
  3020. return ret;
  3021. return ath12k_wmi_set_peer_param(ar, addr, arvif->vdev_id,
  3022. WMI_PEER_MIMO_PS_STATE,
  3023. ath12k_smps_map[smps]);
  3024. }
  3025. static int ath12k_mac_set_he_txbf_conf(struct ath12k_link_vif *arvif)
  3026. {
  3027. struct ath12k_vif *ahvif = arvif->ahvif;
  3028. struct ath12k *ar = arvif->ar;
  3029. u32 param = WMI_VDEV_PARAM_SET_HEMU_MODE;
  3030. u32 value = 0;
  3031. int ret;
  3032. struct ieee80211_bss_conf *link_conf;
  3033. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  3034. if (!link_conf) {
  3035. ath12k_warn(ar->ab, "unable to access bss link conf in txbf conf\n");
  3036. return -EINVAL;
  3037. }
  3038. if (!link_conf->he_support)
  3039. return 0;
  3040. if (link_conf->he_su_beamformer) {
  3041. value |= u32_encode_bits(HE_SU_BFER_ENABLE, HE_MODE_SU_TX_BFER);
  3042. if (link_conf->he_mu_beamformer &&
  3043. ahvif->vdev_type == WMI_VDEV_TYPE_AP)
  3044. value |= u32_encode_bits(HE_MU_BFER_ENABLE, HE_MODE_MU_TX_BFER);
  3045. }
  3046. if (ahvif->vif->type != NL80211_IFTYPE_MESH_POINT) {
  3047. value |= u32_encode_bits(HE_DL_MUOFDMA_ENABLE, HE_MODE_DL_OFDMA) |
  3048. u32_encode_bits(HE_UL_MUOFDMA_ENABLE, HE_MODE_UL_OFDMA);
  3049. if (link_conf->he_full_ul_mumimo)
  3050. value |= u32_encode_bits(HE_UL_MUMIMO_ENABLE, HE_MODE_UL_MUMIMO);
  3051. if (link_conf->he_su_beamformee)
  3052. value |= u32_encode_bits(HE_SU_BFEE_ENABLE, HE_MODE_SU_TX_BFEE);
  3053. }
  3054. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, value);
  3055. if (ret) {
  3056. ath12k_warn(ar->ab, "failed to set vdev %d HE MU mode: %d\n",
  3057. arvif->vdev_id, ret);
  3058. return ret;
  3059. }
  3060. param = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE;
  3061. value = u32_encode_bits(HE_VHT_SOUNDING_MODE_ENABLE, HE_VHT_SOUNDING_MODE) |
  3062. u32_encode_bits(HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE,
  3063. HE_TRIG_NONTRIG_SOUNDING_MODE);
  3064. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  3065. param, value);
  3066. if (ret) {
  3067. ath12k_warn(ar->ab, "failed to set vdev %d sounding mode: %d\n",
  3068. arvif->vdev_id, ret);
  3069. return ret;
  3070. }
  3071. return 0;
  3072. }
  3073. static int ath12k_mac_vif_recalc_sta_he_txbf(struct ath12k *ar,
  3074. struct ath12k_link_vif *arvif,
  3075. struct ieee80211_sta_he_cap *he_cap,
  3076. int *hemode)
  3077. {
  3078. struct ieee80211_vif *vif = arvif->ahvif->vif;
  3079. struct ieee80211_he_cap_elem he_cap_elem = {};
  3080. struct ieee80211_sta_he_cap *cap_band;
  3081. struct cfg80211_chan_def def;
  3082. u8 link_id = arvif->link_id;
  3083. struct ieee80211_bss_conf *link_conf;
  3084. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  3085. if (!link_conf) {
  3086. ath12k_warn(ar->ab, "unable to access bss link conf in recalc txbf conf\n");
  3087. return -EINVAL;
  3088. }
  3089. if (!link_conf->he_support)
  3090. return 0;
  3091. if (vif->type != NL80211_IFTYPE_STATION)
  3092. return -EINVAL;
  3093. if (WARN_ON(ath12k_mac_vif_link_chan(vif, link_id, &def)))
  3094. return -EINVAL;
  3095. if (def.chan->band == NL80211_BAND_2GHZ)
  3096. cap_band = &ar->mac.iftype[NL80211_BAND_2GHZ][vif->type].he_cap;
  3097. else
  3098. cap_band = &ar->mac.iftype[NL80211_BAND_5GHZ][vif->type].he_cap;
  3099. memcpy(&he_cap_elem, &cap_band->he_cap_elem, sizeof(he_cap_elem));
  3100. *hemode = 0;
  3101. if (HECAP_PHY_SUBFME_GET(he_cap_elem.phy_cap_info)) {
  3102. if (HECAP_PHY_SUBFMR_GET(he_cap->he_cap_elem.phy_cap_info))
  3103. *hemode |= u32_encode_bits(HE_SU_BFEE_ENABLE, HE_MODE_SU_TX_BFEE);
  3104. if (HECAP_PHY_MUBFMR_GET(he_cap->he_cap_elem.phy_cap_info))
  3105. *hemode |= u32_encode_bits(HE_MU_BFEE_ENABLE, HE_MODE_MU_TX_BFEE);
  3106. }
  3107. if (vif->type != NL80211_IFTYPE_MESH_POINT) {
  3108. *hemode |= u32_encode_bits(HE_DL_MUOFDMA_ENABLE, HE_MODE_DL_OFDMA) |
  3109. u32_encode_bits(HE_UL_MUOFDMA_ENABLE, HE_MODE_UL_OFDMA);
  3110. if (HECAP_PHY_ULMUMIMO_GET(he_cap_elem.phy_cap_info))
  3111. if (HECAP_PHY_ULMUMIMO_GET(he_cap->he_cap_elem.phy_cap_info))
  3112. *hemode |= u32_encode_bits(HE_UL_MUMIMO_ENABLE,
  3113. HE_MODE_UL_MUMIMO);
  3114. if (u32_get_bits(*hemode, HE_MODE_MU_TX_BFEE))
  3115. *hemode |= u32_encode_bits(HE_SU_BFEE_ENABLE, HE_MODE_SU_TX_BFEE);
  3116. if (u32_get_bits(*hemode, HE_MODE_MU_TX_BFER))
  3117. *hemode |= u32_encode_bits(HE_SU_BFER_ENABLE, HE_MODE_SU_TX_BFER);
  3118. }
  3119. return 0;
  3120. }
  3121. static int ath12k_mac_set_eht_txbf_conf(struct ath12k_link_vif *arvif)
  3122. {
  3123. struct ath12k_vif *ahvif = arvif->ahvif;
  3124. struct ath12k *ar = arvif->ar;
  3125. u32 param = WMI_VDEV_PARAM_SET_EHT_MU_MODE;
  3126. u32 value = 0;
  3127. int ret;
  3128. struct ieee80211_bss_conf *link_conf;
  3129. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  3130. if (!link_conf) {
  3131. ath12k_warn(ar->ab, "unable to access bss link conf in eht txbf conf\n");
  3132. return -ENOENT;
  3133. }
  3134. if (!link_conf->eht_support)
  3135. return 0;
  3136. if (link_conf->eht_su_beamformer) {
  3137. value |= u32_encode_bits(EHT_SU_BFER_ENABLE, EHT_MODE_SU_TX_BFER);
  3138. if (link_conf->eht_mu_beamformer &&
  3139. ahvif->vdev_type == WMI_VDEV_TYPE_AP)
  3140. value |= u32_encode_bits(EHT_MU_BFER_ENABLE,
  3141. EHT_MODE_MU_TX_BFER) |
  3142. u32_encode_bits(EHT_DL_MUOFDMA_ENABLE,
  3143. EHT_MODE_DL_OFDMA_MUMIMO) |
  3144. u32_encode_bits(EHT_UL_MUOFDMA_ENABLE,
  3145. EHT_MODE_UL_OFDMA_MUMIMO);
  3146. }
  3147. if (ahvif->vif->type != NL80211_IFTYPE_MESH_POINT) {
  3148. value |= u32_encode_bits(EHT_DL_MUOFDMA_ENABLE, EHT_MODE_DL_OFDMA) |
  3149. u32_encode_bits(EHT_UL_MUOFDMA_ENABLE, EHT_MODE_UL_OFDMA);
  3150. if (link_conf->eht_80mhz_full_bw_ul_mumimo)
  3151. value |= u32_encode_bits(EHT_UL_MUMIMO_ENABLE, EHT_MODE_MUMIMO);
  3152. if (link_conf->eht_su_beamformee)
  3153. value |= u32_encode_bits(EHT_SU_BFEE_ENABLE,
  3154. EHT_MODE_SU_TX_BFEE);
  3155. }
  3156. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, value);
  3157. if (ret) {
  3158. ath12k_warn(ar->ab, "failed to set vdev %d EHT MU mode: %d\n",
  3159. arvif->vdev_id, ret);
  3160. return ret;
  3161. }
  3162. return 0;
  3163. }
  3164. static u32 ath12k_mac_ieee80211_sta_bw_to_wmi(struct ath12k *ar,
  3165. struct ieee80211_link_sta *link_sta)
  3166. {
  3167. u32 bw;
  3168. switch (link_sta->bandwidth) {
  3169. case IEEE80211_STA_RX_BW_20:
  3170. bw = WMI_PEER_CHWIDTH_20MHZ;
  3171. break;
  3172. case IEEE80211_STA_RX_BW_40:
  3173. bw = WMI_PEER_CHWIDTH_40MHZ;
  3174. break;
  3175. case IEEE80211_STA_RX_BW_80:
  3176. bw = WMI_PEER_CHWIDTH_80MHZ;
  3177. break;
  3178. case IEEE80211_STA_RX_BW_160:
  3179. bw = WMI_PEER_CHWIDTH_160MHZ;
  3180. break;
  3181. case IEEE80211_STA_RX_BW_320:
  3182. bw = WMI_PEER_CHWIDTH_320MHZ;
  3183. break;
  3184. default:
  3185. ath12k_warn(ar->ab, "Invalid bandwidth %d for link station %pM\n",
  3186. link_sta->bandwidth, link_sta->addr);
  3187. bw = WMI_PEER_CHWIDTH_20MHZ;
  3188. break;
  3189. }
  3190. return bw;
  3191. }
  3192. static void ath12k_bss_assoc(struct ath12k *ar,
  3193. struct ath12k_link_vif *arvif,
  3194. struct ieee80211_bss_conf *bss_conf)
  3195. {
  3196. struct ath12k_vif *ahvif = arvif->ahvif;
  3197. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif);
  3198. struct ath12k_wmi_vdev_up_params params = {};
  3199. struct ieee80211_link_sta *link_sta;
  3200. u8 link_id = bss_conf->link_id;
  3201. struct ath12k_link_sta *arsta;
  3202. struct ieee80211_sta *ap_sta;
  3203. struct ath12k_sta *ahsta;
  3204. struct ath12k_dp_link_peer *peer;
  3205. bool is_auth = false;
  3206. u32 hemode = 0;
  3207. int ret;
  3208. struct ath12k_dp *dp = ath12k_ab_to_dp(ar->ab);
  3209. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  3210. struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) =
  3211. kzalloc_obj(*peer_arg);
  3212. if (!peer_arg)
  3213. return;
  3214. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  3215. "mac vdev %i link id %u assoc bssid %pM aid %d\n",
  3216. arvif->vdev_id, link_id, arvif->bssid, ahvif->aid);
  3217. rcu_read_lock();
  3218. /* During ML connection, cfg.ap_addr has the MLD address. For
  3219. * non-ML connection, it has the BSSID.
  3220. */
  3221. ap_sta = ieee80211_find_sta(vif, vif->cfg.ap_addr);
  3222. if (!ap_sta) {
  3223. ath12k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n",
  3224. vif->cfg.ap_addr, arvif->vdev_id);
  3225. rcu_read_unlock();
  3226. return;
  3227. }
  3228. ahsta = ath12k_sta_to_ahsta(ap_sta);
  3229. arsta = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy,
  3230. ahsta->link[link_id]);
  3231. if (WARN_ON(!arsta)) {
  3232. rcu_read_unlock();
  3233. return;
  3234. }
  3235. link_sta = ath12k_mac_get_link_sta(arsta);
  3236. if (WARN_ON(!link_sta)) {
  3237. rcu_read_unlock();
  3238. return;
  3239. }
  3240. ath12k_peer_assoc_prepare(ar, arvif, arsta, peer_arg, false);
  3241. /* link_sta->he_cap must be protected by rcu_read_lock */
  3242. ret = ath12k_mac_vif_recalc_sta_he_txbf(ar, arvif, &link_sta->he_cap, &hemode);
  3243. if (ret) {
  3244. ath12k_warn(ar->ab, "failed to recalc he txbf for vdev %i on bss %pM: %d\n",
  3245. arvif->vdev_id, bss_conf->bssid, ret);
  3246. rcu_read_unlock();
  3247. return;
  3248. }
  3249. rcu_read_unlock();
  3250. /* keep this before ath12k_wmi_send_peer_assoc_cmd() */
  3251. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  3252. WMI_VDEV_PARAM_SET_HEMU_MODE, hemode);
  3253. if (ret) {
  3254. ath12k_warn(ar->ab, "failed to submit vdev param txbf 0x%x: %d\n",
  3255. hemode, ret);
  3256. return;
  3257. }
  3258. peer_arg->is_assoc = true;
  3259. ret = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg);
  3260. if (ret) {
  3261. ath12k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n",
  3262. bss_conf->bssid, arvif->vdev_id, ret);
  3263. return;
  3264. }
  3265. if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
  3266. ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
  3267. bss_conf->bssid, arvif->vdev_id);
  3268. return;
  3269. }
  3270. ret = ath12k_setup_peer_smps(ar, arvif, bss_conf->bssid,
  3271. &link_sta->ht_cap, &link_sta->he_6ghz_capa);
  3272. if (ret) {
  3273. ath12k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
  3274. arvif->vdev_id, ret);
  3275. return;
  3276. }
  3277. WARN_ON(arvif->is_up);
  3278. ahvif->aid = vif->cfg.aid;
  3279. ether_addr_copy(arvif->bssid, bss_conf->bssid);
  3280. params.vdev_id = arvif->vdev_id;
  3281. params.aid = ahvif->aid;
  3282. params.bssid = arvif->bssid;
  3283. params.tx_bssid = ath12k_mac_get_tx_bssid(arvif);
  3284. if (params.tx_bssid) {
  3285. params.nontx_profile_idx = bss_conf->bssid_index;
  3286. params.nontx_profile_cnt = 1 << bss_conf->bssid_indicator;
  3287. }
  3288. ret = ath12k_wmi_vdev_up(ar, &params);
  3289. if (ret) {
  3290. ath12k_warn(ar->ab, "failed to set vdev %d up: %d\n",
  3291. arvif->vdev_id, ret);
  3292. return;
  3293. }
  3294. arvif->is_up = true;
  3295. arvif->rekey_data.enable_offload = false;
  3296. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  3297. "mac vdev %d up (associated) bssid %pM aid %d\n",
  3298. arvif->vdev_id, bss_conf->bssid, vif->cfg.aid);
  3299. spin_lock_bh(&dp->dp_lock);
  3300. peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id,
  3301. arvif->bssid);
  3302. if (peer && peer->is_authorized)
  3303. is_auth = true;
  3304. spin_unlock_bh(&dp->dp_lock);
  3305. /* Authorize BSS Peer */
  3306. if (is_auth) {
  3307. ret = ath12k_wmi_set_peer_param(ar, arvif->bssid,
  3308. arvif->vdev_id,
  3309. WMI_PEER_AUTHORIZE,
  3310. 1);
  3311. if (ret)
  3312. ath12k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret);
  3313. }
  3314. ret = ath12k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id,
  3315. &bss_conf->he_obss_pd);
  3316. if (ret)
  3317. ath12k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n",
  3318. arvif->vdev_id, ret);
  3319. if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map) &&
  3320. ahvif->vdev_type == WMI_VDEV_TYPE_STA &&
  3321. ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE)
  3322. ath12k_mac_11d_scan_stop_all(ar->ab);
  3323. }
  3324. static void ath12k_bss_disassoc(struct ath12k *ar,
  3325. struct ath12k_link_vif *arvif)
  3326. {
  3327. int ret;
  3328. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  3329. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
  3330. arvif->vdev_id, arvif->bssid);
  3331. ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id);
  3332. if (ret)
  3333. ath12k_warn(ar->ab, "failed to down vdev %i: %d\n",
  3334. arvif->vdev_id, ret);
  3335. arvif->is_up = false;
  3336. memset(&arvif->rekey_data, 0, sizeof(arvif->rekey_data));
  3337. cancel_delayed_work(&arvif->connection_loss_work);
  3338. }
  3339. static u32 ath12k_mac_get_rate_hw_value(int bitrate)
  3340. {
  3341. u32 preamble;
  3342. u16 hw_value;
  3343. int rate;
  3344. size_t i;
  3345. if (ath12k_mac_bitrate_is_cck(bitrate))
  3346. preamble = WMI_RATE_PREAMBLE_CCK;
  3347. else
  3348. preamble = WMI_RATE_PREAMBLE_OFDM;
  3349. for (i = 0; i < ARRAY_SIZE(ath12k_legacy_rates); i++) {
  3350. if (ath12k_legacy_rates[i].bitrate != bitrate)
  3351. continue;
  3352. hw_value = ath12k_legacy_rates[i].hw_value;
  3353. rate = ATH12K_HW_RATE_CODE(hw_value, 0, preamble);
  3354. return rate;
  3355. }
  3356. return -EINVAL;
  3357. }
  3358. static void ath12k_recalculate_mgmt_rate(struct ath12k *ar,
  3359. struct ath12k_link_vif *arvif,
  3360. struct cfg80211_chan_def *def)
  3361. {
  3362. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  3363. struct ieee80211_hw *hw = ath12k_ar_to_hw(ar);
  3364. const struct ieee80211_supported_band *sband;
  3365. struct ieee80211_bss_conf *bss_conf;
  3366. u8 basic_rate_idx;
  3367. int hw_rate_code;
  3368. u32 vdev_param;
  3369. u16 bitrate;
  3370. int ret;
  3371. lockdep_assert_wiphy(hw->wiphy);
  3372. bss_conf = ath12k_mac_get_link_bss_conf(arvif);
  3373. if (!bss_conf) {
  3374. ath12k_warn(ar->ab, "unable to access bss link conf in mgmt rate calc for vif %pM link %u\n",
  3375. vif->addr, arvif->link_id);
  3376. return;
  3377. }
  3378. sband = hw->wiphy->bands[def->chan->band];
  3379. if (bss_conf->basic_rates)
  3380. basic_rate_idx = __ffs(bss_conf->basic_rates);
  3381. else
  3382. basic_rate_idx = 0;
  3383. bitrate = sband->bitrates[basic_rate_idx].bitrate;
  3384. hw_rate_code = ath12k_mac_get_rate_hw_value(bitrate);
  3385. if (hw_rate_code < 0) {
  3386. ath12k_warn(ar->ab, "bitrate not supported %d\n", bitrate);
  3387. return;
  3388. }
  3389. vdev_param = WMI_VDEV_PARAM_MGMT_RATE;
  3390. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
  3391. hw_rate_code);
  3392. if (ret)
  3393. ath12k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret);
  3394. vdev_param = WMI_VDEV_PARAM_BEACON_RATE;
  3395. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
  3396. hw_rate_code);
  3397. if (ret)
  3398. ath12k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret);
  3399. }
  3400. static void ath12k_mac_bcn_tx_event(struct ath12k_link_vif *arvif)
  3401. {
  3402. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  3403. struct ieee80211_bss_conf *link_conf;
  3404. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  3405. if (!link_conf) {
  3406. ath12k_warn(arvif->ar->ab, "failed to get link conf for vdev %u\n",
  3407. arvif->vdev_id);
  3408. return;
  3409. }
  3410. if (link_conf->color_change_active) {
  3411. if (ieee80211_beacon_cntdwn_is_complete(vif, arvif->link_id)) {
  3412. ieee80211_color_change_finish(vif, arvif->link_id);
  3413. return;
  3414. }
  3415. ieee80211_beacon_update_cntdwn(vif, arvif->link_id);
  3416. ath12k_mac_setup_bcn_tmpl(arvif);
  3417. }
  3418. }
  3419. static void ath12k_mac_bcn_tx_work(struct wiphy *wiphy, struct wiphy_work *work)
  3420. {
  3421. struct ath12k_link_vif *arvif = container_of(work, struct ath12k_link_vif,
  3422. bcn_tx_work);
  3423. lockdep_assert_wiphy(wiphy);
  3424. ath12k_mac_bcn_tx_event(arvif);
  3425. }
  3426. static void ath12k_mac_init_arvif(struct ath12k_vif *ahvif,
  3427. struct ath12k_link_vif *arvif, int link_id)
  3428. {
  3429. struct ath12k_hw *ah = ahvif->ah;
  3430. u8 _link_id;
  3431. int i;
  3432. lockdep_assert_wiphy(ah->hw->wiphy);
  3433. if (WARN_ON(!arvif))
  3434. return;
  3435. if (WARN_ON(link_id >= ATH12K_NUM_MAX_LINKS))
  3436. return;
  3437. if (link_id < 0)
  3438. _link_id = 0;
  3439. else
  3440. _link_id = link_id;
  3441. arvif->ahvif = ahvif;
  3442. arvif->link_id = _link_id;
  3443. /* Protects the datapath stats update on a per link basis */
  3444. spin_lock_init(&arvif->link_stats_lock);
  3445. INIT_LIST_HEAD(&arvif->list);
  3446. INIT_DELAYED_WORK(&arvif->connection_loss_work,
  3447. ath12k_mac_vif_sta_connection_loss_work);
  3448. wiphy_work_init(&arvif->bcn_tx_work, ath12k_mac_bcn_tx_work);
  3449. arvif->num_stations = 0;
  3450. for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
  3451. arvif->bitrate_mask.control[i].legacy = 0xffffffff;
  3452. arvif->bitrate_mask.control[i].gi = NL80211_TXRATE_DEFAULT_GI;
  3453. memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
  3454. sizeof(arvif->bitrate_mask.control[i].ht_mcs));
  3455. memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
  3456. sizeof(arvif->bitrate_mask.control[i].vht_mcs));
  3457. memset(arvif->bitrate_mask.control[i].he_mcs, 0xff,
  3458. sizeof(arvif->bitrate_mask.control[i].he_mcs));
  3459. memset(arvif->bitrate_mask.control[i].eht_mcs, 0xff,
  3460. sizeof(arvif->bitrate_mask.control[i].eht_mcs));
  3461. }
  3462. /* Handle MLO related assignments */
  3463. if (link_id >= 0) {
  3464. rcu_assign_pointer(ahvif->link[arvif->link_id], arvif);
  3465. ahvif->links_map |= BIT(_link_id);
  3466. }
  3467. ath12k_generic_dbg(ATH12K_DBG_MAC,
  3468. "mac init link arvif (link_id %d%s) for vif %pM. links_map 0x%x",
  3469. _link_id, (link_id < 0) ? " deflink" : "", ahvif->vif->addr,
  3470. ahvif->links_map);
  3471. }
  3472. static void ath12k_mac_remove_link_interface(struct ieee80211_hw *hw,
  3473. struct ath12k_link_vif *arvif)
  3474. {
  3475. struct ath12k_vif *ahvif = arvif->ahvif;
  3476. struct ath12k_hw *ah = hw->priv;
  3477. struct ath12k *ar = arvif->ar;
  3478. int ret;
  3479. lockdep_assert_wiphy(ah->hw->wiphy);
  3480. cancel_delayed_work_sync(&arvif->connection_loss_work);
  3481. wiphy_work_cancel(ath12k_ar_to_hw(ar)->wiphy, &arvif->bcn_tx_work);
  3482. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac remove link interface (vdev %d link id %d)",
  3483. arvif->vdev_id, arvif->link_id);
  3484. if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map) &&
  3485. ahvif->vdev_type == WMI_VDEV_TYPE_STA &&
  3486. ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE)
  3487. ath12k_mac_11d_scan_stop(ar);
  3488. if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) {
  3489. ret = ath12k_peer_delete(ar, arvif->vdev_id, arvif->bssid);
  3490. if (ret)
  3491. ath12k_warn(ar->ab, "failed to submit AP self-peer removal on vdev %d link id %d: %d",
  3492. arvif->vdev_id, arvif->link_id, ret);
  3493. if (arvif->link_id < IEEE80211_MLD_MAX_NUM_LINKS)
  3494. ath12k_dp_peer_delete(&ah->dp_hw, arvif->bssid, NULL);
  3495. }
  3496. ath12k_mac_vdev_delete(ar, arvif);
  3497. }
  3498. static struct ath12k_link_vif *ath12k_mac_assign_link_vif(struct ath12k_hw *ah,
  3499. struct ieee80211_vif *vif,
  3500. u8 link_id)
  3501. {
  3502. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  3503. struct ath12k_link_vif *arvif;
  3504. lockdep_assert_wiphy(ah->hw->wiphy);
  3505. arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]);
  3506. if (arvif)
  3507. return arvif;
  3508. /* If this is the first link arvif being created for an ML VIF
  3509. * use the preallocated deflink memory except for scan arvifs
  3510. */
  3511. if (!ahvif->links_map && link_id < ATH12K_FIRST_SCAN_LINK) {
  3512. arvif = &ahvif->deflink;
  3513. if (vif->type == NL80211_IFTYPE_STATION)
  3514. arvif->is_sta_assoc_link = true;
  3515. } else {
  3516. arvif = kzalloc_obj(*arvif);
  3517. if (!arvif)
  3518. return NULL;
  3519. }
  3520. ath12k_mac_init_arvif(ahvif, arvif, link_id);
  3521. return arvif;
  3522. }
  3523. static void ath12k_mac_unassign_link_vif(struct ath12k_link_vif *arvif)
  3524. {
  3525. struct ath12k_vif *ahvif = arvif->ahvif;
  3526. struct ath12k_hw *ah = ahvif->ah;
  3527. lockdep_assert_wiphy(ah->hw->wiphy);
  3528. rcu_assign_pointer(ahvif->link[arvif->link_id], NULL);
  3529. synchronize_rcu();
  3530. ahvif->links_map &= ~BIT(arvif->link_id);
  3531. if (arvif != &ahvif->deflink)
  3532. kfree(arvif);
  3533. else
  3534. memset(arvif, 0, sizeof(*arvif));
  3535. }
  3536. int
  3537. ath12k_mac_op_change_vif_links(struct ieee80211_hw *hw,
  3538. struct ieee80211_vif *vif,
  3539. u16 old_links, u16 new_links,
  3540. struct ieee80211_bss_conf *ol[IEEE80211_MLD_MAX_NUM_LINKS])
  3541. {
  3542. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  3543. unsigned long to_remove = old_links & ~new_links;
  3544. unsigned long to_add = ~old_links & new_links;
  3545. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  3546. struct ath12k_link_vif *arvif;
  3547. u8 link_id;
  3548. lockdep_assert_wiphy(hw->wiphy);
  3549. ath12k_generic_dbg(ATH12K_DBG_MAC,
  3550. "mac vif link changed for MLD %pM old_links 0x%x new_links 0x%x\n",
  3551. vif->addr, old_links, new_links);
  3552. for_each_set_bit(link_id, &to_add, IEEE80211_MLD_MAX_NUM_LINKS) {
  3553. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  3554. /* mac80211 wants to add link but driver already has the
  3555. * link. This should not happen ideally.
  3556. */
  3557. if (WARN_ON(arvif))
  3558. return -EINVAL;
  3559. arvif = ath12k_mac_assign_link_vif(ah, vif, link_id);
  3560. if (WARN_ON(!arvif))
  3561. return -EINVAL;
  3562. }
  3563. for_each_set_bit(link_id, &to_remove, IEEE80211_MLD_MAX_NUM_LINKS) {
  3564. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  3565. if (WARN_ON(!arvif))
  3566. return -EINVAL;
  3567. if (!arvif->is_created) {
  3568. ath12k_mac_unassign_link_vif(arvif);
  3569. continue;
  3570. }
  3571. if (WARN_ON(!arvif->ar))
  3572. return -EINVAL;
  3573. ath12k_mac_remove_link_interface(hw, arvif);
  3574. ath12k_mac_unassign_link_vif(arvif);
  3575. }
  3576. return 0;
  3577. }
  3578. EXPORT_SYMBOL(ath12k_mac_op_change_vif_links);
  3579. static int ath12k_mac_fils_discovery(struct ath12k_link_vif *arvif,
  3580. struct ieee80211_bss_conf *info)
  3581. {
  3582. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  3583. struct ath12k *ar = arvif->ar;
  3584. struct ieee80211_hw *hw = ath12k_ar_to_hw(ar);
  3585. struct sk_buff *tmpl;
  3586. int ret;
  3587. u32 interval;
  3588. bool unsol_bcast_probe_resp_enabled = false;
  3589. if (info->fils_discovery.max_interval) {
  3590. interval = info->fils_discovery.max_interval;
  3591. tmpl = ieee80211_get_fils_discovery_tmpl(hw, vif);
  3592. if (tmpl)
  3593. ret = ath12k_wmi_fils_discovery_tmpl(ar, arvif->vdev_id,
  3594. tmpl);
  3595. } else if (info->unsol_bcast_probe_resp_interval) {
  3596. unsol_bcast_probe_resp_enabled = 1;
  3597. interval = info->unsol_bcast_probe_resp_interval;
  3598. tmpl = ieee80211_get_unsol_bcast_probe_resp_tmpl(hw, vif);
  3599. if (tmpl)
  3600. ret = ath12k_wmi_probe_resp_tmpl(ar, arvif->vdev_id,
  3601. tmpl);
  3602. } else { /* Disable */
  3603. return ath12k_wmi_fils_discovery(ar, arvif->vdev_id, 0, false);
  3604. }
  3605. if (!tmpl) {
  3606. ath12k_warn(ar->ab,
  3607. "mac vdev %i failed to retrieve %s template\n",
  3608. arvif->vdev_id, (unsol_bcast_probe_resp_enabled ?
  3609. "unsolicited broadcast probe response" :
  3610. "FILS discovery"));
  3611. return -EPERM;
  3612. }
  3613. kfree_skb(tmpl);
  3614. if (!ret)
  3615. ret = ath12k_wmi_fils_discovery(ar, arvif->vdev_id, interval,
  3616. unsol_bcast_probe_resp_enabled);
  3617. return ret;
  3618. }
  3619. void ath12k_mac_op_vif_cfg_changed(struct ieee80211_hw *hw,
  3620. struct ieee80211_vif *vif,
  3621. u64 changed)
  3622. {
  3623. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  3624. unsigned long links = ahvif->links_map;
  3625. struct ieee80211_bss_conf *info;
  3626. struct ath12k_link_vif *arvif;
  3627. struct ieee80211_sta *sta;
  3628. struct ath12k_sta *ahsta;
  3629. struct ath12k *ar;
  3630. u8 link_id;
  3631. lockdep_assert_wiphy(hw->wiphy);
  3632. if (changed & BSS_CHANGED_SSID && vif->type == NL80211_IFTYPE_AP) {
  3633. ahvif->u.ap.ssid_len = vif->cfg.ssid_len;
  3634. if (vif->cfg.ssid_len)
  3635. memcpy(ahvif->u.ap.ssid, vif->cfg.ssid, vif->cfg.ssid_len);
  3636. }
  3637. if (changed & BSS_CHANGED_ASSOC) {
  3638. if (vif->cfg.assoc) {
  3639. /* only in station mode we can get here, so it's safe
  3640. * to use ap_addr
  3641. */
  3642. rcu_read_lock();
  3643. sta = ieee80211_find_sta(vif, vif->cfg.ap_addr);
  3644. if (!sta) {
  3645. rcu_read_unlock();
  3646. WARN_ONCE(1, "failed to find sta with addr %pM\n",
  3647. vif->cfg.ap_addr);
  3648. return;
  3649. }
  3650. ahsta = ath12k_sta_to_ahsta(sta);
  3651. arvif = wiphy_dereference(hw->wiphy,
  3652. ahvif->link[ahsta->assoc_link_id]);
  3653. rcu_read_unlock();
  3654. ar = arvif->ar;
  3655. /* there is no reason for which an assoc link's
  3656. * bss info does not exist
  3657. */
  3658. info = ath12k_mac_get_link_bss_conf(arvif);
  3659. ath12k_bss_assoc(ar, arvif, info);
  3660. /* exclude assoc link as it is done above */
  3661. links &= ~BIT(ahsta->assoc_link_id);
  3662. }
  3663. for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
  3664. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  3665. if (!arvif || !arvif->ar)
  3666. continue;
  3667. ar = arvif->ar;
  3668. if (vif->cfg.assoc) {
  3669. info = ath12k_mac_get_link_bss_conf(arvif);
  3670. if (!info)
  3671. continue;
  3672. ath12k_bss_assoc(ar, arvif, info);
  3673. } else {
  3674. ath12k_bss_disassoc(ar, arvif);
  3675. }
  3676. }
  3677. }
  3678. }
  3679. EXPORT_SYMBOL(ath12k_mac_op_vif_cfg_changed);
  3680. static void ath12k_mac_vif_setup_ps(struct ath12k_link_vif *arvif)
  3681. {
  3682. struct ath12k *ar = arvif->ar;
  3683. struct ieee80211_vif *vif = arvif->ahvif->vif;
  3684. struct ieee80211_conf *conf = &ath12k_ar_to_hw(ar)->conf;
  3685. enum wmi_sta_powersave_param param;
  3686. struct ieee80211_bss_conf *info;
  3687. enum wmi_sta_ps_mode psmode;
  3688. int ret;
  3689. int timeout;
  3690. bool enable_ps;
  3691. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  3692. if (vif->type != NL80211_IFTYPE_STATION)
  3693. return;
  3694. enable_ps = arvif->ahvif->ps;
  3695. if (enable_ps) {
  3696. psmode = WMI_STA_PS_MODE_ENABLED;
  3697. param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
  3698. timeout = conf->dynamic_ps_timeout;
  3699. if (timeout == 0) {
  3700. info = ath12k_mac_get_link_bss_conf(arvif);
  3701. if (!info) {
  3702. ath12k_warn(ar->ab, "unable to access bss link conf in setup ps for vif %pM link %u\n",
  3703. vif->addr, arvif->link_id);
  3704. return;
  3705. }
  3706. /* firmware doesn't like 0 */
  3707. timeout = ieee80211_tu_to_usec(info->beacon_int) / 1000;
  3708. }
  3709. ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
  3710. timeout);
  3711. if (ret) {
  3712. ath12k_warn(ar->ab, "failed to set inactivity time for vdev %d: %i\n",
  3713. arvif->vdev_id, ret);
  3714. return;
  3715. }
  3716. } else {
  3717. psmode = WMI_STA_PS_MODE_DISABLED;
  3718. }
  3719. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d psmode %s\n",
  3720. arvif->vdev_id, psmode ? "enable" : "disable");
  3721. ret = ath12k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, psmode);
  3722. if (ret)
  3723. ath12k_warn(ar->ab, "failed to set sta power save mode %d for vdev %d: %d\n",
  3724. psmode, arvif->vdev_id, ret);
  3725. }
  3726. static bool ath12k_mac_supports_tpc(struct ath12k *ar, struct ath12k_vif *ahvif,
  3727. const struct cfg80211_chan_def *chandef)
  3728. {
  3729. return ath12k_wmi_supports_6ghz_cc_ext(ar) &&
  3730. test_bit(WMI_TLV_SERVICE_EXT_TPC_REG_SUPPORT, ar->ab->wmi_ab.svc_map) &&
  3731. (ahvif->vdev_type == WMI_VDEV_TYPE_STA ||
  3732. ahvif->vdev_type == WMI_VDEV_TYPE_AP) &&
  3733. ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE &&
  3734. chandef->chan &&
  3735. chandef->chan->band == NL80211_BAND_6GHZ;
  3736. }
  3737. static void ath12k_wmi_vdev_params_up(struct ath12k *ar,
  3738. struct ath12k_link_vif *arvif,
  3739. struct ath12k_link_vif *tx_arvif,
  3740. struct ieee80211_bss_conf *info, u16 aid)
  3741. {
  3742. struct ath12k_wmi_vdev_up_params params = {
  3743. .vdev_id = arvif->vdev_id,
  3744. .aid = aid,
  3745. .bssid = arvif->bssid
  3746. };
  3747. int ret;
  3748. if (tx_arvif) {
  3749. params.tx_bssid = tx_arvif->bssid;
  3750. params.nontx_profile_idx = info->bssid_index;
  3751. params.nontx_profile_cnt = 1 << info->bssid_indicator;
  3752. }
  3753. ret = ath12k_wmi_vdev_up(arvif->ar, &params);
  3754. if (ret)
  3755. ath12k_warn(ar->ab, "failed to bring vdev up %d: %d\n",
  3756. arvif->vdev_id, ret);
  3757. }
  3758. static int ath12k_mac_config_obss_pd(struct ath12k_link_vif *arvif,
  3759. const struct ieee80211_he_obss_pd *he_obss_pd)
  3760. {
  3761. struct ath12k_wmi_obss_pd_arg obss_pd_arg = {};
  3762. u32 srg_bitmap[2], non_srg_bitmap[2];
  3763. struct ath12k *ar = arvif->ar;
  3764. u32 param_id, pdev_id;
  3765. u32 param_val;
  3766. int ret;
  3767. if (ar->ab->hw_params->single_pdev_only)
  3768. pdev_id = ath12k_mac_get_target_pdev_id_from_vif(arvif);
  3769. else
  3770. pdev_id = ar->pdev->pdev_id;
  3771. /* Set and enable SRG/non-SRG OBSS PD threshold */
  3772. param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_THRESHOLD;
  3773. if (ar->monitor_started || !he_obss_pd->enable) {
  3774. ret = ath12k_wmi_pdev_set_param(ar, param_id, 0, pdev_id);
  3775. if (ret)
  3776. ath12k_warn(ar->ab,
  3777. "failed to set OBSS PD threshold for pdev %u: %d\n",
  3778. pdev_id, ret);
  3779. return ret;
  3780. }
  3781. /*
  3782. * This service flag indicates firmware support for SRG/SRP-based
  3783. * spatial reuse. It also specifies whether OBSS PD threshold values
  3784. * should be interpreted as dB (offset) or dBm (absolute) units.
  3785. */
  3786. obss_pd_arg.srp_support = test_bit(WMI_TLV_SERVICE_SRG_SRP_SPATIAL_REUSE_SUPPORT,
  3787. ar->ab->wmi_ab.svc_map);
  3788. if (!(he_obss_pd->sr_ctrl &
  3789. IEEE80211_HE_SPR_NON_SRG_OBSS_PD_SR_DISALLOWED)) {
  3790. if (he_obss_pd->sr_ctrl & IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT)
  3791. obss_pd_arg.non_srg_th = ATH12K_OBSS_PD_MAX_THRESHOLD +
  3792. he_obss_pd->non_srg_max_offset;
  3793. else
  3794. obss_pd_arg.non_srg_th = ATH12K_OBSS_PD_NON_SRG_MAX_THRESHOLD;
  3795. if (!obss_pd_arg.srp_support)
  3796. obss_pd_arg.non_srg_th -= ATH12K_DEFAULT_NOISE_FLOOR;
  3797. obss_pd_arg.non_srg_enabled = true;
  3798. }
  3799. if (he_obss_pd->sr_ctrl & IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT) {
  3800. obss_pd_arg.srg_th = ATH12K_OBSS_PD_MAX_THRESHOLD +
  3801. he_obss_pd->max_offset;
  3802. obss_pd_arg.srg_enabled = true;
  3803. }
  3804. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  3805. "pdev %u OBSS PD sr_ctrl 0x%x srg_th %d dBm non_srg_th %d dBm\n",
  3806. pdev_id, he_obss_pd->sr_ctrl,
  3807. obss_pd_arg.srg_th, obss_pd_arg.non_srg_th);
  3808. param_val = ath12k_wmi_build_obss_pd(&obss_pd_arg);
  3809. ret = ath12k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
  3810. if (ret) {
  3811. ath12k_warn(ar->ab,
  3812. "failed to set OBSS PD threshold for pdev %u: %d\n",
  3813. pdev_id, ret);
  3814. return ret;
  3815. }
  3816. /* Enable OBSS PD for all access category */
  3817. param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_PER_AC;
  3818. param_val = 0xf;
  3819. ret = ath12k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
  3820. if (ret) {
  3821. ath12k_warn(ar->ab,
  3822. "failed to set OBSS PD per ac for pdev %u: %d\n",
  3823. pdev_id, ret);
  3824. return ret;
  3825. }
  3826. /* Set SR prohibit */
  3827. param_id = WMI_PDEV_PARAM_ENABLE_SR_PROHIBIT;
  3828. param_val = !!(he_obss_pd->sr_ctrl &
  3829. IEEE80211_HE_SPR_HESIGA_SR_VAL15_ALLOWED);
  3830. ret = ath12k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
  3831. if (ret) {
  3832. ath12k_warn(ar->ab, "failed to set SR prohibit for pdev %u: %d\n",
  3833. pdev_id, ret);
  3834. return ret;
  3835. }
  3836. if (!obss_pd_arg.srp_support)
  3837. return 0;
  3838. memcpy(srg_bitmap, he_obss_pd->bss_color_bitmap, sizeof(srg_bitmap));
  3839. /* Set SRG BSS color bitmap */
  3840. ret = ath12k_wmi_pdev_set_srg_bss_color_bitmap(ar, pdev_id, srg_bitmap);
  3841. if (ret) {
  3842. ath12k_warn(ar->ab,
  3843. "failed to set SRG bss color bitmap for pdev %u: %d\n",
  3844. pdev_id, ret);
  3845. return ret;
  3846. }
  3847. /* Enable BSS colors for SRG */
  3848. ret = ath12k_wmi_pdev_srg_obss_color_enable_bitmap(ar, pdev_id, srg_bitmap);
  3849. if (ret) {
  3850. ath12k_warn(ar->ab,
  3851. "failed to enable SRG bss color bitmap pdev %u: %d\n",
  3852. pdev_id, ret);
  3853. return ret;
  3854. }
  3855. memcpy(srg_bitmap, he_obss_pd->partial_bssid_bitmap, sizeof(srg_bitmap));
  3856. /* Set SRG partial bssid bitmap */
  3857. ret = ath12k_wmi_pdev_set_srg_partial_bssid_bitmap(ar, pdev_id, srg_bitmap);
  3858. if (ret) {
  3859. ath12k_warn(ar->ab,
  3860. "failed to set SRG partial bssid bitmap for pdev %u: %d\n",
  3861. pdev_id, ret);
  3862. return ret;
  3863. }
  3864. /* Enable partial bssid mask for SRG */
  3865. ret = ath12k_wmi_pdev_srg_obss_bssid_enable_bitmap(ar, pdev_id, srg_bitmap);
  3866. if (ret) {
  3867. ath12k_warn(ar->ab,
  3868. "failed to enable SRG bssid bitmap pdev %u: %d\n",
  3869. pdev_id, ret);
  3870. return ret;
  3871. }
  3872. /*
  3873. * No explicit non-SRG bitmap from mac80211; enable all colors/bssids
  3874. * as non-SRG candidates. Actual SRG members are filtered by SRG bitmaps.
  3875. */
  3876. memset(non_srg_bitmap, 0xff, sizeof(non_srg_bitmap));
  3877. /* Enable BSS colors for non-SRG */
  3878. ret = ath12k_wmi_pdev_non_srg_obss_color_enable_bitmap(ar, pdev_id,
  3879. non_srg_bitmap);
  3880. if (ret) {
  3881. ath12k_warn(ar->ab,
  3882. "failed to enable non SRG color bitmap pdev %u: %d\n",
  3883. pdev_id, ret);
  3884. return ret;
  3885. }
  3886. /* Enable partial bssid mask for non-SRG */
  3887. ret = ath12k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(ar, pdev_id,
  3888. non_srg_bitmap);
  3889. if (ret) {
  3890. ath12k_warn(ar->ab,
  3891. "failed to enable non SRG bssid bitmap pdev %u: %d\n",
  3892. pdev_id, ret);
  3893. return ret;
  3894. }
  3895. return 0;
  3896. }
  3897. static void ath12k_mac_bss_info_changed(struct ath12k *ar,
  3898. struct ath12k_link_vif *arvif,
  3899. struct ieee80211_bss_conf *info,
  3900. u64 changed)
  3901. {
  3902. struct ath12k_vif *ahvif = arvif->ahvif;
  3903. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif);
  3904. struct ieee80211_vif_cfg *vif_cfg = &vif->cfg;
  3905. struct ath12k_link_vif *tx_arvif;
  3906. struct cfg80211_chan_def def;
  3907. u32 param_id, param_value;
  3908. enum nl80211_band band;
  3909. u32 vdev_param;
  3910. int mcast_rate;
  3911. u32 preamble;
  3912. u16 hw_value;
  3913. u16 bitrate;
  3914. u8 rateidx;
  3915. u32 rate;
  3916. int ret;
  3917. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  3918. if (changed & BSS_CHANGED_BEACON_INT) {
  3919. arvif->beacon_interval = info->beacon_int;
  3920. param_id = WMI_VDEV_PARAM_BEACON_INTERVAL;
  3921. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  3922. param_id,
  3923. arvif->beacon_interval);
  3924. if (ret)
  3925. ath12k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n",
  3926. arvif->vdev_id);
  3927. else
  3928. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  3929. "Beacon interval: %d set for VDEV: %d\n",
  3930. arvif->beacon_interval, arvif->vdev_id);
  3931. }
  3932. if (changed & BSS_CHANGED_BEACON) {
  3933. param_id = WMI_PDEV_PARAM_BEACON_TX_MODE;
  3934. param_value = WMI_BEACON_BURST_MODE;
  3935. ret = ath12k_wmi_pdev_set_param(ar, param_id,
  3936. param_value, ar->pdev->pdev_id);
  3937. if (ret)
  3938. ath12k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n",
  3939. arvif->vdev_id);
  3940. else
  3941. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  3942. "Set burst beacon mode for VDEV: %d\n",
  3943. arvif->vdev_id);
  3944. /* In MBSSID case, need to install transmitting VIF's template first */
  3945. ret = ath12k_mac_setup_bcn_tmpl(arvif);
  3946. if (ret)
  3947. ath12k_warn(ar->ab, "failed to update bcn template: %d\n",
  3948. ret);
  3949. if (!arvif->is_csa_in_progress)
  3950. goto skip_vdev_up;
  3951. tx_arvif = ath12k_mac_get_tx_arvif(arvif, info);
  3952. if (tx_arvif && arvif != tx_arvif && tx_arvif->is_csa_in_progress)
  3953. /* skip non tx vif's */
  3954. goto skip_vdev_up;
  3955. ath12k_wmi_vdev_params_up(ar, arvif, tx_arvif, info, ahvif->aid);
  3956. arvif->is_csa_in_progress = false;
  3957. if (tx_arvif && arvif == tx_arvif) {
  3958. struct ath12k_link_vif *arvif_itr;
  3959. list_for_each_entry(arvif_itr, &ar->arvifs, list) {
  3960. if (!arvif_itr->is_csa_in_progress)
  3961. continue;
  3962. ath12k_wmi_vdev_params_up(ar, arvif, tx_arvif,
  3963. info, ahvif->aid);
  3964. arvif_itr->is_csa_in_progress = false;
  3965. }
  3966. }
  3967. }
  3968. skip_vdev_up:
  3969. if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
  3970. arvif->dtim_period = info->dtim_period;
  3971. param_id = WMI_VDEV_PARAM_DTIM_PERIOD;
  3972. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  3973. param_id,
  3974. arvif->dtim_period);
  3975. if (ret)
  3976. ath12k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n",
  3977. arvif->vdev_id, ret);
  3978. else
  3979. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  3980. "DTIM period: %d set for VDEV: %d\n",
  3981. arvif->dtim_period, arvif->vdev_id);
  3982. }
  3983. if (changed & BSS_CHANGED_SSID &&
  3984. vif->type == NL80211_IFTYPE_AP) {
  3985. ahvif->u.ap.ssid_len = vif->cfg.ssid_len;
  3986. if (vif->cfg.ssid_len)
  3987. memcpy(ahvif->u.ap.ssid, vif->cfg.ssid, vif->cfg.ssid_len);
  3988. ahvif->u.ap.hidden_ssid = info->hidden_ssid;
  3989. }
  3990. if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
  3991. ether_addr_copy(arvif->bssid, info->bssid);
  3992. if (changed & BSS_CHANGED_BEACON_ENABLED) {
  3993. if (info->enable_beacon) {
  3994. ret = ath12k_mac_set_he_txbf_conf(arvif);
  3995. if (ret)
  3996. ath12k_warn(ar->ab,
  3997. "failed to set HE TXBF config for vdev: %d\n",
  3998. arvif->vdev_id);
  3999. ret = ath12k_mac_set_eht_txbf_conf(arvif);
  4000. if (ret)
  4001. ath12k_warn(ar->ab,
  4002. "failed to set EHT TXBF config for vdev: %d\n",
  4003. arvif->vdev_id);
  4004. }
  4005. ath12k_control_beaconing(arvif, info);
  4006. if (arvif->is_up && info->he_support &&
  4007. info->he_oper.params) {
  4008. /* TODO: Extend to support 1024 BA Bitmap size */
  4009. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  4010. WMI_VDEV_PARAM_BA_MODE,
  4011. WMI_BA_MODE_BUFFER_SIZE_256);
  4012. if (ret)
  4013. ath12k_warn(ar->ab,
  4014. "failed to set BA BUFFER SIZE 256 for vdev: %d\n",
  4015. arvif->vdev_id);
  4016. param_id = WMI_VDEV_PARAM_HEOPS_0_31;
  4017. param_value = info->he_oper.params;
  4018. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  4019. param_id, param_value);
  4020. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  4021. "he oper param: %x set for VDEV: %d\n",
  4022. param_value, arvif->vdev_id);
  4023. if (ret)
  4024. ath12k_warn(ar->ab, "Failed to set he oper params %x for VDEV %d: %i\n",
  4025. param_value, arvif->vdev_id, ret);
  4026. }
  4027. }
  4028. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  4029. u32 cts_prot;
  4030. cts_prot = !!(info->use_cts_prot);
  4031. param_id = WMI_VDEV_PARAM_PROTECTION_MODE;
  4032. if (arvif->is_started) {
  4033. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  4034. param_id, cts_prot);
  4035. if (ret)
  4036. ath12k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n",
  4037. arvif->vdev_id);
  4038. else
  4039. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n",
  4040. cts_prot, arvif->vdev_id);
  4041. } else {
  4042. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n");
  4043. }
  4044. }
  4045. if (changed & BSS_CHANGED_ERP_SLOT) {
  4046. u32 slottime;
  4047. if (info->use_short_slot)
  4048. slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
  4049. else
  4050. slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
  4051. param_id = WMI_VDEV_PARAM_SLOT_TIME;
  4052. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  4053. param_id, slottime);
  4054. if (ret)
  4055. ath12k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n",
  4056. arvif->vdev_id);
  4057. else
  4058. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  4059. "Set slottime: %d for VDEV: %d\n",
  4060. slottime, arvif->vdev_id);
  4061. }
  4062. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  4063. u32 preamble;
  4064. if (info->use_short_preamble)
  4065. preamble = WMI_VDEV_PREAMBLE_SHORT;
  4066. else
  4067. preamble = WMI_VDEV_PREAMBLE_LONG;
  4068. param_id = WMI_VDEV_PARAM_PREAMBLE;
  4069. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  4070. param_id, preamble);
  4071. if (ret)
  4072. ath12k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n",
  4073. arvif->vdev_id);
  4074. else
  4075. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  4076. "Set preamble: %d for VDEV: %d\n",
  4077. preamble, arvif->vdev_id);
  4078. }
  4079. if (changed & BSS_CHANGED_ASSOC) {
  4080. if (vif->cfg.assoc)
  4081. ath12k_bss_assoc(ar, arvif, info);
  4082. else
  4083. ath12k_bss_disassoc(ar, arvif);
  4084. }
  4085. if (changed & BSS_CHANGED_TXPOWER) {
  4086. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev_id %i txpower %d\n",
  4087. arvif->vdev_id, info->txpower);
  4088. arvif->txpower = info->txpower;
  4089. ath12k_mac_txpower_recalc(ar);
  4090. }
  4091. if (changed & BSS_CHANGED_MCAST_RATE &&
  4092. !ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) {
  4093. band = def.chan->band;
  4094. mcast_rate = info->mcast_rate[band];
  4095. if (mcast_rate > 0) {
  4096. rateidx = mcast_rate - 1;
  4097. } else {
  4098. if (info->basic_rates)
  4099. rateidx = __ffs(info->basic_rates);
  4100. else
  4101. rateidx = 0;
  4102. }
  4103. if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP)
  4104. rateidx += ATH12K_MAC_FIRST_OFDM_RATE_IDX;
  4105. bitrate = ath12k_legacy_rates[rateidx].bitrate;
  4106. hw_value = ath12k_legacy_rates[rateidx].hw_value;
  4107. if (ath12k_mac_bitrate_is_cck(bitrate))
  4108. preamble = WMI_RATE_PREAMBLE_CCK;
  4109. else
  4110. preamble = WMI_RATE_PREAMBLE_OFDM;
  4111. rate = ATH12K_HW_RATE_CODE(hw_value, 0, preamble);
  4112. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  4113. "mac vdev %d mcast_rate %x\n",
  4114. arvif->vdev_id, rate);
  4115. vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE;
  4116. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  4117. vdev_param, rate);
  4118. if (ret)
  4119. ath12k_warn(ar->ab,
  4120. "failed to set mcast rate on vdev %i: %d\n",
  4121. arvif->vdev_id, ret);
  4122. vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE;
  4123. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  4124. vdev_param, rate);
  4125. if (ret)
  4126. ath12k_warn(ar->ab,
  4127. "failed to set bcast rate on vdev %i: %d\n",
  4128. arvif->vdev_id, ret);
  4129. }
  4130. if (changed & BSS_CHANGED_BASIC_RATES &&
  4131. !ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))
  4132. ath12k_recalculate_mgmt_rate(ar, arvif, &def);
  4133. if (changed & BSS_CHANGED_TWT) {
  4134. if (info->twt_requester || info->twt_responder)
  4135. ath12k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id);
  4136. else
  4137. ath12k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id);
  4138. }
  4139. if (changed & BSS_CHANGED_HE_OBSS_PD) {
  4140. if (vif->type == NL80211_IFTYPE_AP)
  4141. ath12k_mac_config_obss_pd(arvif, &info->he_obss_pd);
  4142. else
  4143. ath12k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id,
  4144. &info->he_obss_pd);
  4145. }
  4146. if (changed & BSS_CHANGED_HE_BSS_COLOR) {
  4147. if (vif->type == NL80211_IFTYPE_AP) {
  4148. ret = ath12k_wmi_obss_color_cfg_cmd(ar,
  4149. arvif->vdev_id,
  4150. info->he_bss_color.color,
  4151. ATH12K_BSS_COLOR_AP_PERIODS,
  4152. info->he_bss_color.enabled);
  4153. if (ret)
  4154. ath12k_warn(ar->ab, "failed to set bss color collision on vdev %u: %d\n",
  4155. arvif->vdev_id, ret);
  4156. param_id = WMI_VDEV_PARAM_BSS_COLOR;
  4157. if (info->he_bss_color.enabled)
  4158. param_value = info->he_bss_color.color <<
  4159. IEEE80211_HE_OPERATION_BSS_COLOR_OFFSET;
  4160. else
  4161. param_value = IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED;
  4162. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  4163. param_id,
  4164. param_value);
  4165. if (ret)
  4166. ath12k_warn(ar->ab, "failed to set bss color param on vdev %u: %d\n",
  4167. arvif->vdev_id, ret);
  4168. else
  4169. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "bss color param 0x%x set on vdev %u\n",
  4170. param_value, arvif->vdev_id);
  4171. } else if (vif->type == NL80211_IFTYPE_STATION) {
  4172. ret = ath12k_wmi_send_bss_color_change_enable_cmd(ar,
  4173. arvif->vdev_id,
  4174. 1);
  4175. if (ret)
  4176. ath12k_warn(ar->ab, "failed to enable bss color change on vdev %i: %d\n",
  4177. arvif->vdev_id, ret);
  4178. ret = ath12k_wmi_obss_color_cfg_cmd(ar,
  4179. arvif->vdev_id,
  4180. 0,
  4181. ATH12K_BSS_COLOR_STA_PERIODS,
  4182. 1);
  4183. if (ret)
  4184. ath12k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
  4185. arvif->vdev_id, ret);
  4186. }
  4187. }
  4188. ath12k_mac_fils_discovery(arvif, info);
  4189. if (changed & BSS_CHANGED_PS &&
  4190. ar->ab->hw_params->supports_sta_ps) {
  4191. ahvif->ps = vif_cfg->ps;
  4192. ath12k_mac_vif_setup_ps(arvif);
  4193. }
  4194. }
  4195. static struct ath12k_vif_cache *ath12k_ahvif_get_link_cache(struct ath12k_vif *ahvif,
  4196. u8 link_id)
  4197. {
  4198. if (!ahvif->cache[link_id]) {
  4199. ahvif->cache[link_id] = kzalloc_obj(*ahvif->cache[0]);
  4200. if (ahvif->cache[link_id])
  4201. INIT_LIST_HEAD(&ahvif->cache[link_id]->key_conf.list);
  4202. }
  4203. return ahvif->cache[link_id];
  4204. }
  4205. static void ath12k_ahvif_put_link_key_cache(struct ath12k_vif_cache *cache)
  4206. {
  4207. struct ath12k_key_conf *key_conf, *tmp;
  4208. if (!cache || list_empty(&cache->key_conf.list))
  4209. return;
  4210. list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) {
  4211. list_del(&key_conf->list);
  4212. kfree(key_conf);
  4213. }
  4214. }
  4215. static void ath12k_ahvif_put_link_cache(struct ath12k_vif *ahvif, u8 link_id)
  4216. {
  4217. if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS)
  4218. return;
  4219. ath12k_ahvif_put_link_key_cache(ahvif->cache[link_id]);
  4220. kfree(ahvif->cache[link_id]);
  4221. ahvif->cache[link_id] = NULL;
  4222. }
  4223. void ath12k_mac_op_link_info_changed(struct ieee80211_hw *hw,
  4224. struct ieee80211_vif *vif,
  4225. struct ieee80211_bss_conf *info,
  4226. u64 changed)
  4227. {
  4228. struct ath12k *ar;
  4229. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  4230. struct ath12k_vif_cache *cache;
  4231. struct ath12k_link_vif *arvif;
  4232. u8 link_id = info->link_id;
  4233. lockdep_assert_wiphy(hw->wiphy);
  4234. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  4235. /* if the vdev is not created on a certain radio,
  4236. * cache the info to be updated later on vdev creation
  4237. */
  4238. if (!arvif || !arvif->is_created) {
  4239. cache = ath12k_ahvif_get_link_cache(ahvif, link_id);
  4240. if (!cache)
  4241. return;
  4242. cache->bss_conf_changed |= changed;
  4243. return;
  4244. }
  4245. ar = arvif->ar;
  4246. ath12k_mac_bss_info_changed(ar, arvif, info, changed);
  4247. }
  4248. EXPORT_SYMBOL(ath12k_mac_op_link_info_changed);
  4249. static struct ath12k*
  4250. ath12k_mac_select_scan_device(struct ieee80211_hw *hw,
  4251. struct ieee80211_vif *vif,
  4252. u32 center_freq)
  4253. {
  4254. struct ath12k_hw *ah = hw->priv;
  4255. enum nl80211_band band;
  4256. struct ath12k *ar;
  4257. int i;
  4258. if (ah->num_radio == 1)
  4259. return ah->radio;
  4260. /* Currently mac80211 supports splitting scan requests into
  4261. * multiple scan requests per band.
  4262. * Loop through first channel and determine the scan radio
  4263. * TODO: There could be 5 GHz low/high channels in that case
  4264. * split the hw request and perform multiple scans
  4265. */
  4266. if (center_freq < ATH12K_MIN_5GHZ_FREQ)
  4267. band = NL80211_BAND_2GHZ;
  4268. else if (center_freq < ATH12K_MIN_6GHZ_FREQ)
  4269. band = NL80211_BAND_5GHZ;
  4270. else
  4271. band = NL80211_BAND_6GHZ;
  4272. for_each_ar(ah, ar, i) {
  4273. if (ar->mac.sbands[band].channels &&
  4274. center_freq >= KHZ_TO_MHZ(ar->freq_range.start_freq) &&
  4275. center_freq <= KHZ_TO_MHZ(ar->freq_range.end_freq))
  4276. return ar;
  4277. }
  4278. return NULL;
  4279. }
  4280. void __ath12k_mac_scan_finish(struct ath12k *ar)
  4281. {
  4282. struct ieee80211_hw *hw = ath12k_ar_to_hw(ar);
  4283. lockdep_assert_held(&ar->data_lock);
  4284. switch (ar->scan.state) {
  4285. case ATH12K_SCAN_IDLE:
  4286. break;
  4287. case ATH12K_SCAN_RUNNING:
  4288. case ATH12K_SCAN_ABORTING:
  4289. if (ar->scan.is_roc && ar->scan.roc_notify)
  4290. ieee80211_remain_on_channel_expired(hw);
  4291. fallthrough;
  4292. case ATH12K_SCAN_STARTING:
  4293. cancel_delayed_work(&ar->scan.timeout);
  4294. complete_all(&ar->scan.completed);
  4295. wiphy_work_queue(ar->ah->hw->wiphy, &ar->scan.vdev_clean_wk);
  4296. break;
  4297. }
  4298. }
  4299. void ath12k_mac_scan_finish(struct ath12k *ar)
  4300. {
  4301. spin_lock_bh(&ar->data_lock);
  4302. __ath12k_mac_scan_finish(ar);
  4303. spin_unlock_bh(&ar->data_lock);
  4304. }
  4305. static int ath12k_scan_stop(struct ath12k *ar)
  4306. {
  4307. struct ath12k_wmi_scan_cancel_arg arg = {
  4308. .req_type = WLAN_SCAN_CANCEL_SINGLE,
  4309. .scan_id = ATH12K_SCAN_ID,
  4310. };
  4311. int ret;
  4312. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  4313. /* TODO: Fill other STOP Params */
  4314. arg.pdev_id = ar->pdev->pdev_id;
  4315. ret = ath12k_wmi_send_scan_stop_cmd(ar, &arg);
  4316. if (ret) {
  4317. ath12k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret);
  4318. goto out;
  4319. }
  4320. ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
  4321. if (ret == 0) {
  4322. ath12k_warn(ar->ab,
  4323. "failed to receive scan abort comple: timed out\n");
  4324. ret = -ETIMEDOUT;
  4325. } else if (ret > 0) {
  4326. ret = 0;
  4327. }
  4328. out:
  4329. /* Scan state should be updated in scan completion worker but in
  4330. * case firmware fails to deliver the event (for whatever reason)
  4331. * it is desired to clean up scan state anyway. Firmware may have
  4332. * just dropped the scan completion event delivery due to transport
  4333. * pipe being overflown with data and/or it can recover on its own
  4334. * before next scan request is submitted.
  4335. */
  4336. spin_lock_bh(&ar->data_lock);
  4337. if (ret)
  4338. __ath12k_mac_scan_finish(ar);
  4339. spin_unlock_bh(&ar->data_lock);
  4340. return ret;
  4341. }
  4342. static void ath12k_scan_abort(struct ath12k *ar)
  4343. {
  4344. int ret;
  4345. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  4346. spin_lock_bh(&ar->data_lock);
  4347. switch (ar->scan.state) {
  4348. case ATH12K_SCAN_IDLE:
  4349. /* This can happen if timeout worker kicked in and called
  4350. * abortion while scan completion was being processed.
  4351. */
  4352. break;
  4353. case ATH12K_SCAN_STARTING:
  4354. case ATH12K_SCAN_ABORTING:
  4355. ath12k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n",
  4356. ar->scan.state);
  4357. break;
  4358. case ATH12K_SCAN_RUNNING:
  4359. ar->scan.state = ATH12K_SCAN_ABORTING;
  4360. spin_unlock_bh(&ar->data_lock);
  4361. ret = ath12k_scan_stop(ar);
  4362. if (ret)
  4363. ath12k_warn(ar->ab, "failed to abort scan: %d\n", ret);
  4364. spin_lock_bh(&ar->data_lock);
  4365. break;
  4366. }
  4367. spin_unlock_bh(&ar->data_lock);
  4368. }
  4369. static void ath12k_scan_timeout_work(struct work_struct *work)
  4370. {
  4371. struct ath12k *ar = container_of(work, struct ath12k,
  4372. scan.timeout.work);
  4373. wiphy_lock(ath12k_ar_to_hw(ar)->wiphy);
  4374. ath12k_scan_abort(ar);
  4375. wiphy_unlock(ath12k_ar_to_hw(ar)->wiphy);
  4376. }
  4377. static void ath12k_mac_scan_send_complete(struct ath12k *ar,
  4378. struct cfg80211_scan_info *info)
  4379. {
  4380. struct ath12k_hw *ah = ar->ah;
  4381. struct ath12k *partner_ar;
  4382. int i;
  4383. lockdep_assert_wiphy(ah->hw->wiphy);
  4384. for_each_ar(ah, partner_ar, i)
  4385. if (partner_ar != ar &&
  4386. partner_ar->scan.state == ATH12K_SCAN_RUNNING)
  4387. return;
  4388. ieee80211_scan_completed(ah->hw, info);
  4389. }
  4390. static void ath12k_scan_vdev_clean_work(struct wiphy *wiphy, struct wiphy_work *work)
  4391. {
  4392. struct ath12k *ar = container_of(work, struct ath12k,
  4393. scan.vdev_clean_wk);
  4394. struct ath12k_hw *ah = ar->ah;
  4395. struct ath12k_link_vif *arvif;
  4396. lockdep_assert_wiphy(wiphy);
  4397. arvif = ar->scan.arvif;
  4398. /* The scan vdev has already been deleted. This can occur when a
  4399. * new scan request is made on the same vif with a different
  4400. * frequency, causing the scan arvif to move from one radio to
  4401. * another. Or, scan was abrupted and via remove interface, the
  4402. * arvif is already deleted. Alternatively, if the scan vdev is not
  4403. * being used as an actual vdev, then do not delete it.
  4404. */
  4405. if (!arvif || arvif->is_started)
  4406. goto work_complete;
  4407. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac clean scan vdev (link id %u)",
  4408. arvif->link_id);
  4409. ath12k_mac_remove_link_interface(ah->hw, arvif);
  4410. ath12k_mac_unassign_link_vif(arvif);
  4411. work_complete:
  4412. spin_lock_bh(&ar->data_lock);
  4413. ar->scan.arvif = NULL;
  4414. if (!ar->scan.is_roc) {
  4415. struct cfg80211_scan_info info = {
  4416. .aborted = ((ar->scan.state ==
  4417. ATH12K_SCAN_ABORTING) ||
  4418. (ar->scan.state ==
  4419. ATH12K_SCAN_STARTING)),
  4420. };
  4421. ath12k_mac_scan_send_complete(ar, &info);
  4422. }
  4423. ar->scan.state = ATH12K_SCAN_IDLE;
  4424. ar->scan_channel = NULL;
  4425. ar->scan.roc_freq = 0;
  4426. spin_unlock_bh(&ar->data_lock);
  4427. }
  4428. static int ath12k_start_scan(struct ath12k *ar,
  4429. struct ath12k_wmi_scan_req_arg *arg)
  4430. {
  4431. int ret;
  4432. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  4433. ret = ath12k_wmi_send_scan_start_cmd(ar, arg);
  4434. if (ret)
  4435. return ret;
  4436. ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
  4437. if (ret == 0) {
  4438. ret = ath12k_scan_stop(ar);
  4439. if (ret)
  4440. ath12k_warn(ar->ab, "failed to stop scan: %d\n", ret);
  4441. return -ETIMEDOUT;
  4442. }
  4443. /* If we failed to start the scan, return error code at
  4444. * this point. This is probably due to some issue in the
  4445. * firmware, but no need to wedge the driver due to that...
  4446. */
  4447. spin_lock_bh(&ar->data_lock);
  4448. if (ar->scan.state == ATH12K_SCAN_IDLE) {
  4449. spin_unlock_bh(&ar->data_lock);
  4450. return -EINVAL;
  4451. }
  4452. spin_unlock_bh(&ar->data_lock);
  4453. return 0;
  4454. }
  4455. int ath12k_mac_get_fw_stats(struct ath12k *ar,
  4456. struct ath12k_fw_stats_req_params *param)
  4457. {
  4458. struct ath12k_base *ab = ar->ab;
  4459. struct ath12k_hw *ah = ath12k_ar_to_ah(ar);
  4460. unsigned long time_left;
  4461. int ret;
  4462. guard(mutex)(&ah->hw_mutex);
  4463. if (ah->state != ATH12K_HW_STATE_ON)
  4464. return -ENETDOWN;
  4465. reinit_completion(&ar->fw_stats_complete);
  4466. reinit_completion(&ar->fw_stats_done);
  4467. ret = ath12k_wmi_send_stats_request_cmd(ar, param->stats_id,
  4468. param->vdev_id, param->pdev_id);
  4469. if (ret) {
  4470. ath12k_warn(ab, "failed to request fw stats: %d\n", ret);
  4471. return ret;
  4472. }
  4473. ath12k_dbg(ab, ATH12K_DBG_WMI,
  4474. "get fw stat pdev id %d vdev id %d stats id 0x%x\n",
  4475. param->pdev_id, param->vdev_id, param->stats_id);
  4476. time_left = wait_for_completion_timeout(&ar->fw_stats_complete, 1 * HZ);
  4477. if (!time_left) {
  4478. ath12k_warn(ab, "time out while waiting for get fw stats\n");
  4479. return -ETIMEDOUT;
  4480. }
  4481. /* Firmware sends WMI_UPDATE_STATS_EVENTID back-to-back
  4482. * when stats data buffer limit is reached. fw_stats_complete
  4483. * is completed once host receives first event from firmware, but
  4484. * still there could be more events following. Below is to wait
  4485. * until firmware completes sending all the events.
  4486. */
  4487. time_left = wait_for_completion_timeout(&ar->fw_stats_done, 3 * HZ);
  4488. if (!time_left) {
  4489. ath12k_warn(ab, "time out while waiting for fw stats done\n");
  4490. return -ETIMEDOUT;
  4491. }
  4492. return 0;
  4493. }
  4494. int ath12k_mac_op_get_txpower(struct ieee80211_hw *hw,
  4495. struct ieee80211_vif *vif,
  4496. unsigned int link_id,
  4497. int *dbm)
  4498. {
  4499. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  4500. struct ath12k_fw_stats_req_params params = {};
  4501. struct ath12k_fw_stats_pdev *pdev;
  4502. struct ath12k_hw *ah = hw->priv;
  4503. struct ath12k_link_vif *arvif;
  4504. struct ath12k_base *ab;
  4505. struct ath12k *ar;
  4506. int ret;
  4507. /* Final Tx power is minimum of Target Power, CTL power, Regulatory
  4508. * Power, PSD EIRP Power. We just know the Regulatory power from the
  4509. * regulatory rules obtained. FW knows all these power and sets the min
  4510. * of these. Hence, we request the FW pdev stats in which FW reports
  4511. * the minimum of all vdev's channel Tx power.
  4512. */
  4513. lockdep_assert_wiphy(hw->wiphy);
  4514. arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]);
  4515. if (!arvif || !arvif->ar)
  4516. return -EINVAL;
  4517. ar = arvif->ar;
  4518. ab = ar->ab;
  4519. if (ah->state != ATH12K_HW_STATE_ON)
  4520. goto err_fallback;
  4521. if (test_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags))
  4522. return -EAGAIN;
  4523. /* Limit the requests to Firmware for fetching the tx power */
  4524. if (ar->chan_tx_pwr != ATH12K_PDEV_TX_POWER_INVALID &&
  4525. time_before(jiffies,
  4526. msecs_to_jiffies(ATH12K_PDEV_TX_POWER_REFRESH_TIME_MSECS) +
  4527. ar->last_tx_power_update))
  4528. goto send_tx_power;
  4529. params.pdev_id = ath12k_mac_get_target_pdev_id(ar);
  4530. params.vdev_id = arvif->vdev_id;
  4531. params.stats_id = WMI_REQUEST_PDEV_STAT;
  4532. ret = ath12k_mac_get_fw_stats(ar, &params);
  4533. if (ret) {
  4534. ath12k_warn(ab, "failed to request fw pdev stats: %d\n", ret);
  4535. goto err_fallback;
  4536. }
  4537. spin_lock_bh(&ar->data_lock);
  4538. pdev = list_first_entry_or_null(&ar->fw_stats.pdevs,
  4539. struct ath12k_fw_stats_pdev, list);
  4540. if (!pdev) {
  4541. spin_unlock_bh(&ar->data_lock);
  4542. goto err_fallback;
  4543. }
  4544. /* tx power reported by firmware is in units of 0.5 dBm */
  4545. ar->chan_tx_pwr = pdev->chan_tx_power / 2;
  4546. spin_unlock_bh(&ar->data_lock);
  4547. ar->last_tx_power_update = jiffies;
  4548. ath12k_fw_stats_reset(ar);
  4549. send_tx_power:
  4550. *dbm = ar->chan_tx_pwr;
  4551. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower fetched from firmware %d dBm\n",
  4552. *dbm);
  4553. return 0;
  4554. err_fallback:
  4555. /* We didn't get txpower from FW. Hence, relying on vif->bss_conf.txpower */
  4556. *dbm = vif->bss_conf.txpower;
  4557. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower from firmware NaN, reported %d dBm\n",
  4558. *dbm);
  4559. return 0;
  4560. }
  4561. EXPORT_SYMBOL(ath12k_mac_op_get_txpower);
  4562. static u8
  4563. ath12k_mac_find_link_id_by_ar(struct ath12k_vif *ahvif, struct ath12k *ar)
  4564. {
  4565. struct ath12k_link_vif *arvif;
  4566. struct ath12k_hw *ah = ahvif->ah;
  4567. unsigned long links = ahvif->links_map;
  4568. unsigned long scan_links_map;
  4569. u8 link_id;
  4570. lockdep_assert_wiphy(ah->hw->wiphy);
  4571. for_each_set_bit(link_id, &links, ATH12K_NUM_MAX_LINKS) {
  4572. arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]);
  4573. if (!arvif || !arvif->is_created)
  4574. continue;
  4575. if (ar == arvif->ar)
  4576. return link_id;
  4577. }
  4578. /* input ar is not assigned to any of the links of ML VIF, use next
  4579. * available scan link for scan vdev creation. There are cases where
  4580. * single scan req needs to be split in driver and initiate separate
  4581. * scan requests to firmware based on device.
  4582. */
  4583. /* Unset all non-scan links (0-14) of scan_links_map so that ffs() will
  4584. * choose an available link among scan links (i.e link id >= 15)
  4585. */
  4586. scan_links_map = ~ahvif->links_map & ATH12K_SCAN_LINKS_MASK;
  4587. if (scan_links_map)
  4588. return __ffs(scan_links_map);
  4589. return ATH12K_FIRST_SCAN_LINK;
  4590. }
  4591. static int ath12k_mac_initiate_hw_scan(struct ieee80211_hw *hw,
  4592. struct ieee80211_vif *vif,
  4593. struct ieee80211_scan_request *hw_req,
  4594. int n_channels,
  4595. struct ieee80211_channel **chan_list,
  4596. struct ath12k *ar)
  4597. {
  4598. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  4599. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  4600. struct ath12k_link_vif *arvif;
  4601. struct cfg80211_scan_request *req = &hw_req->req;
  4602. struct ath12k_wmi_scan_req_arg *arg = NULL;
  4603. u8 link_id;
  4604. int ret;
  4605. int i;
  4606. bool create = true;
  4607. lockdep_assert_wiphy(hw->wiphy);
  4608. arvif = &ahvif->deflink;
  4609. /* check if any of the links of ML VIF is already started on
  4610. * radio(ar) corresponding to given scan frequency and use it,
  4611. * if not use scan link (link id >= 15) for scan purpose.
  4612. */
  4613. link_id = ath12k_mac_find_link_id_by_ar(ahvif, ar);
  4614. /* All scan links are occupied. ideally this shouldn't happen as
  4615. * mac80211 won't schedule scan for same band until ongoing scan is
  4616. * completed, don't try to exceed max links just in case if it happens.
  4617. */
  4618. if (link_id >= ATH12K_NUM_MAX_LINKS)
  4619. return -EBUSY;
  4620. arvif = ath12k_mac_assign_link_vif(ah, vif, link_id);
  4621. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac link ID %d selected for scan",
  4622. arvif->link_id);
  4623. /* If the vif is already assigned to a specific vdev of an ar,
  4624. * check whether its already started, vdev which is started
  4625. * are not allowed to switch to a new radio.
  4626. * If the vdev is not started, but was earlier created on a
  4627. * different ar, delete that vdev and create a new one. We don't
  4628. * delete at the scan stop as an optimization to avoid redundant
  4629. * delete-create vdev's for the same ar, in case the request is
  4630. * always on the same band for the vif
  4631. */
  4632. if (arvif->is_created) {
  4633. if (WARN_ON(!arvif->ar))
  4634. return -EINVAL;
  4635. if (ar != arvif->ar && arvif->is_started)
  4636. return -EINVAL;
  4637. if (ar != arvif->ar) {
  4638. ath12k_mac_remove_link_interface(hw, arvif);
  4639. ath12k_mac_unassign_link_vif(arvif);
  4640. } else {
  4641. create = false;
  4642. }
  4643. }
  4644. if (create) {
  4645. /* Previous arvif would've been cleared in radio switch block
  4646. * above, assign arvif again for create.
  4647. */
  4648. arvif = ath12k_mac_assign_link_vif(ah, vif, link_id);
  4649. ret = ath12k_mac_vdev_create(ar, arvif);
  4650. if (ret) {
  4651. ath12k_warn(ar->ab, "unable to create scan vdev %d\n", ret);
  4652. ath12k_mac_unassign_link_vif(arvif);
  4653. return ret;
  4654. }
  4655. }
  4656. spin_lock_bh(&ar->data_lock);
  4657. switch (ar->scan.state) {
  4658. case ATH12K_SCAN_IDLE:
  4659. reinit_completion(&ar->scan.started);
  4660. reinit_completion(&ar->scan.completed);
  4661. ar->scan.state = ATH12K_SCAN_STARTING;
  4662. ar->scan.is_roc = false;
  4663. ar->scan.arvif = arvif;
  4664. ret = 0;
  4665. break;
  4666. case ATH12K_SCAN_STARTING:
  4667. case ATH12K_SCAN_RUNNING:
  4668. case ATH12K_SCAN_ABORTING:
  4669. ret = -EBUSY;
  4670. break;
  4671. }
  4672. spin_unlock_bh(&ar->data_lock);
  4673. if (ret)
  4674. goto exit;
  4675. arg = kzalloc_obj(*arg);
  4676. if (!arg) {
  4677. ret = -ENOMEM;
  4678. goto exit;
  4679. }
  4680. ath12k_wmi_start_scan_init(ar, arg);
  4681. arg->vdev_id = arvif->vdev_id;
  4682. arg->scan_id = ATH12K_SCAN_ID;
  4683. if (req->ie_len) {
  4684. arg->extraie.ptr = kmemdup(req->ie, req->ie_len, GFP_KERNEL);
  4685. if (!arg->extraie.ptr) {
  4686. ret = -ENOMEM;
  4687. goto exit;
  4688. }
  4689. arg->extraie.len = req->ie_len;
  4690. }
  4691. if (req->n_ssids) {
  4692. arg->num_ssids = req->n_ssids;
  4693. for (i = 0; i < arg->num_ssids; i++)
  4694. arg->ssid[i] = req->ssids[i];
  4695. } else {
  4696. arg->scan_f_passive = 1;
  4697. }
  4698. if (n_channels) {
  4699. arg->num_chan = n_channels;
  4700. arg->chan_list = kcalloc(arg->num_chan, sizeof(*arg->chan_list),
  4701. GFP_KERNEL);
  4702. if (!arg->chan_list) {
  4703. ret = -ENOMEM;
  4704. goto exit;
  4705. }
  4706. for (i = 0; i < arg->num_chan; i++)
  4707. arg->chan_list[i] = chan_list[i]->center_freq;
  4708. }
  4709. ret = ath12k_start_scan(ar, arg);
  4710. if (ret) {
  4711. if (ret == -EBUSY)
  4712. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  4713. "scan engine is busy 11d state %d\n", ar->state_11d);
  4714. else
  4715. ath12k_warn(ar->ab, "failed to start hw scan: %d\n", ret);
  4716. spin_lock_bh(&ar->data_lock);
  4717. ar->scan.state = ATH12K_SCAN_IDLE;
  4718. spin_unlock_bh(&ar->data_lock);
  4719. goto exit;
  4720. }
  4721. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac scan started");
  4722. /* Add a margin to account for event/command processing */
  4723. ieee80211_queue_delayed_work(ath12k_ar_to_hw(ar), &ar->scan.timeout,
  4724. msecs_to_jiffies(arg->max_scan_time +
  4725. ATH12K_MAC_SCAN_TIMEOUT_MSECS));
  4726. exit:
  4727. if (arg) {
  4728. kfree(arg->chan_list);
  4729. kfree(arg->extraie.ptr);
  4730. kfree(arg);
  4731. }
  4732. if (ar->state_11d == ATH12K_11D_PREPARING &&
  4733. ahvif->vdev_type == WMI_VDEV_TYPE_STA &&
  4734. ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE)
  4735. ath12k_mac_11d_scan_start(ar, arvif->vdev_id);
  4736. return ret;
  4737. }
  4738. int ath12k_mac_op_hw_scan(struct ieee80211_hw *hw,
  4739. struct ieee80211_vif *vif,
  4740. struct ieee80211_scan_request *hw_req)
  4741. {
  4742. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  4743. struct ieee80211_channel **chan_list, *chan;
  4744. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  4745. unsigned long links_map, link_id;
  4746. struct ath12k_link_vif *arvif;
  4747. struct ath12k *ar, *scan_ar;
  4748. int i, j, ret = 0;
  4749. lockdep_assert_wiphy(hw->wiphy);
  4750. chan_list = kzalloc_objs(*chan_list, hw_req->req.n_channels);
  4751. if (!chan_list)
  4752. return -ENOMEM;
  4753. /* There could be channels that belong to multiple underlying radio
  4754. * in same scan request as mac80211 sees it as single band. In that
  4755. * case split the hw_req based on frequency range and schedule scans to
  4756. * corresponding radio.
  4757. */
  4758. for_each_ar(ah, ar, i) {
  4759. int n_chans = 0;
  4760. for (j = 0; j < hw_req->req.n_channels; j++) {
  4761. chan = hw_req->req.channels[j];
  4762. scan_ar = ath12k_mac_select_scan_device(hw, vif,
  4763. chan->center_freq);
  4764. if (!scan_ar) {
  4765. ath12k_hw_warn(ah, "unable to select scan device for freq %d\n",
  4766. chan->center_freq);
  4767. ret = -EINVAL;
  4768. goto abort;
  4769. }
  4770. if (ar != scan_ar)
  4771. continue;
  4772. chan_list[n_chans++] = chan;
  4773. }
  4774. if (n_chans) {
  4775. ret = ath12k_mac_initiate_hw_scan(hw, vif, hw_req, n_chans,
  4776. chan_list, ar);
  4777. if (ret)
  4778. goto abort;
  4779. }
  4780. }
  4781. abort:
  4782. /* If any of the parallel scans initiated fails, abort all and
  4783. * remove the scan interfaces created. Return complete scan
  4784. * failure as mac80211 assumes this as single scan request.
  4785. */
  4786. if (ret) {
  4787. ath12k_hw_warn(ah, "Scan failed %d , cleanup all scan vdevs\n", ret);
  4788. links_map = ahvif->links_map;
  4789. for_each_set_bit(link_id, &links_map, ATH12K_NUM_MAX_LINKS) {
  4790. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  4791. if (!arvif)
  4792. continue;
  4793. ar = arvif->ar;
  4794. if (ar->scan.arvif == arvif) {
  4795. wiphy_work_cancel(hw->wiphy, &ar->scan.vdev_clean_wk);
  4796. spin_lock_bh(&ar->data_lock);
  4797. ar->scan.arvif = NULL;
  4798. ar->scan.state = ATH12K_SCAN_IDLE;
  4799. ar->scan_channel = NULL;
  4800. ar->scan.roc_freq = 0;
  4801. spin_unlock_bh(&ar->data_lock);
  4802. }
  4803. if (link_id >= ATH12K_FIRST_SCAN_LINK) {
  4804. ath12k_mac_remove_link_interface(hw, arvif);
  4805. ath12k_mac_unassign_link_vif(arvif);
  4806. }
  4807. }
  4808. }
  4809. kfree(chan_list);
  4810. return ret;
  4811. }
  4812. EXPORT_SYMBOL(ath12k_mac_op_hw_scan);
  4813. void ath12k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw,
  4814. struct ieee80211_vif *vif)
  4815. {
  4816. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  4817. unsigned long link_id, links_map = ahvif->links_map;
  4818. struct ath12k_link_vif *arvif;
  4819. struct ath12k *ar;
  4820. lockdep_assert_wiphy(hw->wiphy);
  4821. for_each_set_bit(link_id, &links_map, ATH12K_NUM_MAX_LINKS) {
  4822. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  4823. if (!arvif || !arvif->is_created ||
  4824. arvif->ar->scan.arvif != arvif)
  4825. continue;
  4826. ar = arvif->ar;
  4827. ath12k_scan_abort(ar);
  4828. cancel_delayed_work_sync(&ar->scan.timeout);
  4829. }
  4830. }
  4831. EXPORT_SYMBOL(ath12k_mac_op_cancel_hw_scan);
  4832. static int ath12k_install_key(struct ath12k_link_vif *arvif,
  4833. struct ieee80211_key_conf *key,
  4834. enum set_key_cmd cmd,
  4835. const u8 *macaddr, u32 flags)
  4836. {
  4837. int ret;
  4838. struct ath12k *ar = arvif->ar;
  4839. struct wmi_vdev_install_key_arg arg = {
  4840. .vdev_id = arvif->vdev_id,
  4841. .key_idx = key->keyidx,
  4842. .key_len = key->keylen,
  4843. .key_data = key->key,
  4844. .key_flags = flags,
  4845. .ieee80211_key_cipher = key->cipher,
  4846. .macaddr = macaddr,
  4847. };
  4848. struct ath12k_vif *ahvif = arvif->ahvif;
  4849. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  4850. if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
  4851. return 0;
  4852. if (cmd == DISABLE_KEY) {
  4853. /* TODO: Check if FW expects value other than NONE for del */
  4854. /* arg.key_cipher = WMI_CIPHER_NONE; */
  4855. arg.key_len = 0;
  4856. arg.key_data = NULL;
  4857. goto check_order;
  4858. }
  4859. switch (key->cipher) {
  4860. case WLAN_CIPHER_SUITE_CCMP:
  4861. case WLAN_CIPHER_SUITE_CCMP_256:
  4862. arg.key_cipher = WMI_CIPHER_AES_CCM;
  4863. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
  4864. break;
  4865. case WLAN_CIPHER_SUITE_TKIP:
  4866. arg.key_cipher = WMI_CIPHER_TKIP;
  4867. arg.key_txmic_len = 8;
  4868. arg.key_rxmic_len = 8;
  4869. break;
  4870. case WLAN_CIPHER_SUITE_GCMP:
  4871. case WLAN_CIPHER_SUITE_GCMP_256:
  4872. arg.key_cipher = WMI_CIPHER_AES_GCM;
  4873. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
  4874. break;
  4875. case WLAN_CIPHER_SUITE_AES_CMAC:
  4876. arg.key_cipher = WMI_CIPHER_AES_CMAC;
  4877. break;
  4878. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  4879. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  4880. arg.key_cipher = WMI_CIPHER_AES_GMAC;
  4881. break;
  4882. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  4883. arg.key_cipher = WMI_CIPHER_AES_CMAC;
  4884. break;
  4885. default:
  4886. ath12k_warn(ar->ab, "cipher %d is not supported\n", key->cipher);
  4887. return -EOPNOTSUPP;
  4888. }
  4889. if (test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags))
  4890. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV |
  4891. IEEE80211_KEY_FLAG_RESERVE_TAILROOM;
  4892. check_order:
  4893. if (ahvif->vdev_type == WMI_VDEV_TYPE_STA &&
  4894. arg.key_flags == WMI_KEY_GROUP) {
  4895. if (cmd == SET_KEY) {
  4896. if (arvif->pairwise_key_done) {
  4897. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  4898. "vdev %u pairwise key done, go install group key\n",
  4899. arg.vdev_id);
  4900. goto install;
  4901. } else {
  4902. /* WCN7850 firmware requires pairwise key to be installed
  4903. * before group key. In case group key comes first, cache
  4904. * it and return. Will revisit it once pairwise key gets
  4905. * installed.
  4906. */
  4907. arvif->group_key = arg;
  4908. arvif->group_key_valid = true;
  4909. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  4910. "vdev %u group key before pairwise key, cache and skip\n",
  4911. arg.vdev_id);
  4912. ret = 0;
  4913. goto out;
  4914. }
  4915. } else {
  4916. arvif->group_key_valid = false;
  4917. }
  4918. }
  4919. install:
  4920. reinit_completion(&ar->install_key_done);
  4921. ret = ath12k_wmi_vdev_install_key(arvif->ar, &arg);
  4922. if (ret)
  4923. return ret;
  4924. if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ))
  4925. return -ETIMEDOUT;
  4926. if (ether_addr_equal(arg.macaddr, arvif->bssid))
  4927. ahvif->dp_vif.key_cipher = arg.ieee80211_key_cipher;
  4928. if (ar->install_key_status) {
  4929. ret = -EINVAL;
  4930. goto out;
  4931. }
  4932. if (ahvif->vdev_type == WMI_VDEV_TYPE_STA &&
  4933. arg.key_flags == WMI_KEY_PAIRWISE) {
  4934. if (cmd == SET_KEY) {
  4935. arvif->pairwise_key_done = true;
  4936. if (arvif->group_key_valid) {
  4937. /* Install cached GTK */
  4938. arvif->group_key_valid = false;
  4939. arg = arvif->group_key;
  4940. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  4941. "vdev %u pairwise key done, group key ready, go install\n",
  4942. arg.vdev_id);
  4943. goto install;
  4944. }
  4945. } else {
  4946. arvif->pairwise_key_done = false;
  4947. }
  4948. }
  4949. out:
  4950. if (ret) {
  4951. /* In case of failure userspace may not do DISABLE_KEY
  4952. * but triggers re-connection directly, so manually reset
  4953. * status here.
  4954. */
  4955. arvif->group_key_valid = false;
  4956. arvif->pairwise_key_done = false;
  4957. }
  4958. return ret;
  4959. }
  4960. static int ath12k_clear_peer_keys(struct ath12k_link_vif *arvif,
  4961. const u8 *addr)
  4962. {
  4963. struct ath12k *ar = arvif->ar;
  4964. struct ath12k_base *ab = ar->ab;
  4965. struct ath12k_dp_link_peer *peer;
  4966. int first_errno = 0;
  4967. int ret;
  4968. int i, len;
  4969. u32 flags = 0;
  4970. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  4971. struct ieee80211_key_conf *keys[WMI_MAX_KEY_INDEX + 1] = {};
  4972. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  4973. spin_lock_bh(&dp->dp_lock);
  4974. peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id, addr);
  4975. if (!peer || !peer->dp_peer) {
  4976. spin_unlock_bh(&dp->dp_lock);
  4977. return -ENOENT;
  4978. }
  4979. len = ARRAY_SIZE(peer->dp_peer->keys);
  4980. for (i = 0; i < len; i++) {
  4981. if (!peer->dp_peer->keys[i])
  4982. continue;
  4983. keys[i] = peer->dp_peer->keys[i];
  4984. peer->dp_peer->keys[i] = NULL;
  4985. }
  4986. spin_unlock_bh(&dp->dp_lock);
  4987. for (i = 0; i < len; i++) {
  4988. if (!keys[i])
  4989. continue;
  4990. /* key flags are not required to delete the key */
  4991. ret = ath12k_install_key(arvif, keys[i],
  4992. DISABLE_KEY, addr, flags);
  4993. if (ret < 0 && first_errno == 0)
  4994. first_errno = ret;
  4995. if (ret < 0)
  4996. ath12k_warn(ab, "failed to remove peer key %d: %d\n",
  4997. i, ret);
  4998. }
  4999. return first_errno;
  5000. }
  5001. static int ath12k_mac_set_key(struct ath12k *ar, enum set_key_cmd cmd,
  5002. struct ath12k_link_vif *arvif,
  5003. struct ath12k_link_sta *arsta,
  5004. struct ieee80211_key_conf *key)
  5005. {
  5006. struct ieee80211_sta *sta = NULL;
  5007. struct ath12k_base *ab = ar->ab;
  5008. struct ath12k_dp_link_peer *peer;
  5009. struct ath12k_sta *ahsta;
  5010. const u8 *peer_addr;
  5011. int ret;
  5012. u32 flags = 0;
  5013. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  5014. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5015. if (arsta)
  5016. sta = ath12k_ahsta_to_sta(arsta->ahsta);
  5017. if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ab->dev_flags))
  5018. return 1;
  5019. if (sta)
  5020. peer_addr = arsta->addr;
  5021. else
  5022. peer_addr = arvif->bssid;
  5023. key->hw_key_idx = key->keyidx;
  5024. /* the peer should not disappear in mid-way (unless FW goes awry) since
  5025. * we already hold wiphy lock. we just make sure its there now.
  5026. */
  5027. spin_lock_bh(&dp->dp_lock);
  5028. peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id,
  5029. peer_addr);
  5030. if (!peer || !peer->dp_peer) {
  5031. spin_unlock_bh(&dp->dp_lock);
  5032. if (cmd == SET_KEY) {
  5033. ath12k_warn(ab, "cannot install key for non-existent peer %pM\n",
  5034. peer_addr);
  5035. return -EOPNOTSUPP;
  5036. }
  5037. /* if the peer doesn't exist there is no key to disable
  5038. * anymore
  5039. */
  5040. return 0;
  5041. }
  5042. spin_unlock_bh(&dp->dp_lock);
  5043. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  5044. flags = WMI_KEY_PAIRWISE;
  5045. else
  5046. flags = WMI_KEY_GROUP;
  5047. ret = ath12k_install_key(arvif, key, cmd, peer_addr, flags);
  5048. if (ret) {
  5049. ath12k_warn(ab, "ath12k_install_key failed (%d)\n", ret);
  5050. return ret;
  5051. }
  5052. ret = ath12k_dp_rx_peer_pn_replay_config(arvif, peer_addr, cmd, key);
  5053. if (ret) {
  5054. ath12k_warn(ab, "failed to offload PN replay detection %d\n", ret);
  5055. return ret;
  5056. }
  5057. spin_lock_bh(&dp->dp_lock);
  5058. peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id,
  5059. peer_addr);
  5060. if (peer && peer->dp_peer && cmd == SET_KEY) {
  5061. peer->dp_peer->keys[key->keyidx] = key;
  5062. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
  5063. peer->dp_peer->ucast_keyidx = key->keyidx;
  5064. peer->dp_peer->sec_type =
  5065. ath12k_dp_tx_get_encrypt_type(key->cipher);
  5066. } else {
  5067. peer->dp_peer->mcast_keyidx = key->keyidx;
  5068. peer->dp_peer->sec_type_grp =
  5069. ath12k_dp_tx_get_encrypt_type(key->cipher);
  5070. }
  5071. } else if (peer && peer->dp_peer && cmd == DISABLE_KEY) {
  5072. peer->dp_peer->keys[key->keyidx] = NULL;
  5073. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  5074. peer->dp_peer->ucast_keyidx = 0;
  5075. else
  5076. peer->dp_peer->mcast_keyidx = 0;
  5077. } else if (!peer)
  5078. /* impossible unless FW goes crazy */
  5079. ath12k_warn(ab, "peer %pM disappeared!\n", peer_addr);
  5080. if (sta) {
  5081. ahsta = ath12k_sta_to_ahsta(sta);
  5082. switch (key->cipher) {
  5083. case WLAN_CIPHER_SUITE_TKIP:
  5084. case WLAN_CIPHER_SUITE_CCMP:
  5085. case WLAN_CIPHER_SUITE_CCMP_256:
  5086. case WLAN_CIPHER_SUITE_GCMP:
  5087. case WLAN_CIPHER_SUITE_GCMP_256:
  5088. if (cmd == SET_KEY)
  5089. ahsta->pn_type = HAL_PN_TYPE_WPA;
  5090. else
  5091. ahsta->pn_type = HAL_PN_TYPE_NONE;
  5092. break;
  5093. default:
  5094. ahsta->pn_type = HAL_PN_TYPE_NONE;
  5095. break;
  5096. }
  5097. }
  5098. spin_unlock_bh(&dp->dp_lock);
  5099. return 0;
  5100. }
  5101. static int ath12k_mac_update_key_cache(struct ath12k_vif_cache *cache,
  5102. enum set_key_cmd cmd,
  5103. struct ieee80211_sta *sta,
  5104. struct ieee80211_key_conf *key)
  5105. {
  5106. struct ath12k_key_conf *key_conf, *tmp;
  5107. list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) {
  5108. if (key_conf->key != key)
  5109. continue;
  5110. /* If SET key entry is already present in cache, nothing to do,
  5111. * just return
  5112. */
  5113. if (cmd == SET_KEY)
  5114. return 0;
  5115. /* DEL key for an old SET key which driver hasn't flushed yet.
  5116. */
  5117. list_del(&key_conf->list);
  5118. kfree(key_conf);
  5119. }
  5120. if (cmd == SET_KEY) {
  5121. key_conf = kzalloc_obj(*key_conf);
  5122. if (!key_conf)
  5123. return -ENOMEM;
  5124. key_conf->cmd = cmd;
  5125. key_conf->sta = sta;
  5126. key_conf->key = key;
  5127. list_add_tail(&key_conf->list,
  5128. &cache->key_conf.list);
  5129. }
  5130. return 0;
  5131. }
  5132. int ath12k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  5133. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  5134. struct ieee80211_key_conf *key)
  5135. {
  5136. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  5137. struct ath12k_link_vif *arvif;
  5138. struct ath12k_link_sta *arsta = NULL;
  5139. struct ath12k_vif_cache *cache;
  5140. struct ath12k_sta *ahsta;
  5141. unsigned long links;
  5142. u8 link_id;
  5143. int ret;
  5144. lockdep_assert_wiphy(hw->wiphy);
  5145. /* IGTK needs to be done in host software */
  5146. if (key->keyidx == 4 || key->keyidx == 5)
  5147. return 1;
  5148. if (key->keyidx > WMI_MAX_KEY_INDEX)
  5149. return -ENOSPC;
  5150. if (sta) {
  5151. ahsta = ath12k_sta_to_ahsta(sta);
  5152. /* For an ML STA Pairwise key is same for all associated link Stations,
  5153. * hence do set key for all link STAs which are active.
  5154. */
  5155. if (sta->mlo) {
  5156. links = ahsta->links_map;
  5157. for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
  5158. arvif = wiphy_dereference(hw->wiphy,
  5159. ahvif->link[link_id]);
  5160. arsta = wiphy_dereference(hw->wiphy,
  5161. ahsta->link[link_id]);
  5162. if (WARN_ON(!arvif || !arsta))
  5163. /* arvif and arsta are expected to be valid when
  5164. * STA is present.
  5165. */
  5166. continue;
  5167. ret = ath12k_mac_set_key(arvif->ar, cmd, arvif,
  5168. arsta, key);
  5169. if (ret)
  5170. break;
  5171. }
  5172. return 0;
  5173. }
  5174. arsta = &ahsta->deflink;
  5175. arvif = arsta->arvif;
  5176. if (WARN_ON(!arvif))
  5177. return -EINVAL;
  5178. ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, arsta, key);
  5179. if (ret)
  5180. return ret;
  5181. return 0;
  5182. }
  5183. if (key->link_id >= 0 && key->link_id < IEEE80211_MLD_MAX_NUM_LINKS) {
  5184. link_id = key->link_id;
  5185. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  5186. } else {
  5187. link_id = 0;
  5188. arvif = &ahvif->deflink;
  5189. }
  5190. if (!arvif || !arvif->is_created) {
  5191. cache = ath12k_ahvif_get_link_cache(ahvif, link_id);
  5192. if (!cache)
  5193. return -ENOSPC;
  5194. ret = ath12k_mac_update_key_cache(cache, cmd, sta, key);
  5195. if (ret)
  5196. return ret;
  5197. return 0;
  5198. }
  5199. ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, NULL, key);
  5200. if (ret)
  5201. return ret;
  5202. return 0;
  5203. }
  5204. EXPORT_SYMBOL(ath12k_mac_op_set_key);
  5205. static int
  5206. ath12k_mac_bitrate_mask_num_vht_rates(struct ath12k *ar,
  5207. enum nl80211_band band,
  5208. const struct cfg80211_bitrate_mask *mask)
  5209. {
  5210. int num_rates = 0;
  5211. int i;
  5212. for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
  5213. num_rates += hweight16(mask->control[band].vht_mcs[i]);
  5214. return num_rates;
  5215. }
  5216. static int
  5217. ath12k_mac_bitrate_mask_num_he_rates(struct ath12k *ar,
  5218. enum nl80211_band band,
  5219. const struct cfg80211_bitrate_mask *mask)
  5220. {
  5221. int num_rates = 0;
  5222. int i;
  5223. for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++)
  5224. num_rates += hweight16(mask->control[band].he_mcs[i]);
  5225. return num_rates;
  5226. }
  5227. static int
  5228. ath12k_mac_bitrate_mask_num_eht_rates(struct ath12k *ar,
  5229. enum nl80211_band band,
  5230. const struct cfg80211_bitrate_mask *mask)
  5231. {
  5232. int num_rates = 0;
  5233. int i;
  5234. for (i = 0; i < ARRAY_SIZE(mask->control[band].eht_mcs); i++)
  5235. num_rates += hweight16(mask->control[band].eht_mcs[i]);
  5236. return num_rates;
  5237. }
  5238. static int
  5239. ath12k_mac_set_peer_vht_fixed_rate(struct ath12k_link_vif *arvif,
  5240. struct ath12k_link_sta *arsta,
  5241. const struct cfg80211_bitrate_mask *mask,
  5242. enum nl80211_band band)
  5243. {
  5244. struct ath12k *ar = arvif->ar;
  5245. u8 vht_rate, nss;
  5246. u32 rate_code;
  5247. int ret, i;
  5248. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5249. nss = 0;
  5250. for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
  5251. if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
  5252. nss = i + 1;
  5253. vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1;
  5254. }
  5255. }
  5256. if (!nss) {
  5257. ath12k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM",
  5258. arsta->addr);
  5259. return -EINVAL;
  5260. }
  5261. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  5262. "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates",
  5263. arsta->addr);
  5264. rate_code = ATH12K_HW_RATE_CODE(vht_rate, nss - 1,
  5265. WMI_RATE_PREAMBLE_VHT);
  5266. ret = ath12k_wmi_set_peer_param(ar, arsta->addr,
  5267. arvif->vdev_id,
  5268. WMI_PEER_PARAM_FIXED_RATE,
  5269. rate_code);
  5270. if (ret)
  5271. ath12k_warn(ar->ab,
  5272. "failed to update STA %pM Fixed Rate %d: %d\n",
  5273. arsta->addr, rate_code, ret);
  5274. return ret;
  5275. }
  5276. static int
  5277. ath12k_mac_set_peer_he_fixed_rate(struct ath12k_link_vif *arvif,
  5278. struct ath12k_link_sta *arsta,
  5279. const struct cfg80211_bitrate_mask *mask,
  5280. enum nl80211_band band)
  5281. {
  5282. struct ath12k *ar = arvif->ar;
  5283. u8 he_rate, nss;
  5284. u32 rate_code;
  5285. int ret, i;
  5286. struct ath12k_sta *ahsta = arsta->ahsta;
  5287. struct ieee80211_sta *sta;
  5288. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5289. sta = ath12k_ahsta_to_sta(ahsta);
  5290. nss = 0;
  5291. for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++) {
  5292. if (hweight16(mask->control[band].he_mcs[i]) == 1) {
  5293. nss = i + 1;
  5294. he_rate = ffs(mask->control[band].he_mcs[i]) - 1;
  5295. }
  5296. }
  5297. if (!nss) {
  5298. ath12k_warn(ar->ab, "No single HE Fixed rate found to set for %pM",
  5299. arsta->addr);
  5300. return -EINVAL;
  5301. }
  5302. /* Avoid updating invalid nss as fixed rate*/
  5303. if (nss > sta->deflink.rx_nss)
  5304. return -EINVAL;
  5305. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  5306. "Setting Fixed HE Rate for peer %pM. Device will not switch to any other selected rates",
  5307. arsta->addr);
  5308. rate_code = ATH12K_HW_RATE_CODE(he_rate, nss - 1,
  5309. WMI_RATE_PREAMBLE_HE);
  5310. ret = ath12k_wmi_set_peer_param(ar, arsta->addr,
  5311. arvif->vdev_id,
  5312. WMI_PEER_PARAM_FIXED_RATE,
  5313. rate_code);
  5314. if (ret)
  5315. ath12k_warn(ar->ab,
  5316. "failed to update STA %pM Fixed Rate %d: %d\n",
  5317. arsta->addr, rate_code, ret);
  5318. return ret;
  5319. }
  5320. static int
  5321. ath12k_mac_set_peer_eht_fixed_rate(struct ath12k_link_vif *arvif,
  5322. struct ath12k_link_sta *arsta,
  5323. const struct cfg80211_bitrate_mask *mask,
  5324. enum nl80211_band band)
  5325. {
  5326. struct ath12k_sta *ahsta = arsta->ahsta;
  5327. struct ath12k *ar = arvif->ar;
  5328. struct ieee80211_sta *sta;
  5329. struct ieee80211_link_sta *link_sta;
  5330. u8 eht_rate, nss = 0;
  5331. u32 rate_code;
  5332. int ret, i;
  5333. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5334. sta = ath12k_ahsta_to_sta(ahsta);
  5335. for (i = 0; i < ARRAY_SIZE(mask->control[band].eht_mcs); i++) {
  5336. if (hweight16(mask->control[band].eht_mcs[i]) == 1) {
  5337. nss = i + 1;
  5338. eht_rate = ffs(mask->control[band].eht_mcs[i]) - 1;
  5339. }
  5340. }
  5341. if (!nss) {
  5342. ath12k_warn(ar->ab, "No single EHT Fixed rate found to set for %pM\n",
  5343. arsta->addr);
  5344. return -EINVAL;
  5345. }
  5346. /* Avoid updating invalid nss as fixed rate*/
  5347. link_sta = ath12k_mac_get_link_sta(arsta);
  5348. if (!link_sta || nss > link_sta->rx_nss) {
  5349. ath12k_warn(ar->ab,
  5350. "unable to access link sta for sta %pM link %u or fixed nss of %u is not supported by sta\n",
  5351. sta->addr, arsta->link_id, nss);
  5352. return -EINVAL;
  5353. }
  5354. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  5355. "Setting Fixed EHT Rate for peer %pM. Device will not switch to any other selected rates\n",
  5356. arsta->addr);
  5357. rate_code = ATH12K_HW_RATE_CODE(eht_rate, nss - 1,
  5358. WMI_RATE_PREAMBLE_EHT);
  5359. ret = ath12k_wmi_set_peer_param(ar, arsta->addr,
  5360. arvif->vdev_id,
  5361. WMI_PEER_PARAM_FIXED_RATE,
  5362. rate_code);
  5363. if (ret)
  5364. ath12k_warn(ar->ab,
  5365. "failed to update STA %pM Fixed Rate %d: %d\n",
  5366. arsta->addr, rate_code, ret);
  5367. return ret;
  5368. }
  5369. static int ath12k_mac_station_assoc(struct ath12k *ar,
  5370. struct ath12k_link_vif *arvif,
  5371. struct ath12k_link_sta *arsta,
  5372. bool reassoc)
  5373. {
  5374. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  5375. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  5376. struct ieee80211_link_sta *link_sta;
  5377. int ret;
  5378. struct cfg80211_chan_def def;
  5379. enum nl80211_band band;
  5380. struct cfg80211_bitrate_mask *mask;
  5381. u8 num_vht_rates, num_he_rates, num_eht_rates;
  5382. u8 link_id = arvif->link_id;
  5383. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5384. if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)))
  5385. return -EPERM;
  5386. if (WARN_ON(!rcu_access_pointer(sta->link[link_id])))
  5387. return -EINVAL;
  5388. band = def.chan->band;
  5389. mask = &arvif->bitrate_mask;
  5390. struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) =
  5391. kzalloc_obj(*peer_arg);
  5392. if (!peer_arg)
  5393. return -ENOMEM;
  5394. ath12k_peer_assoc_prepare(ar, arvif, arsta, peer_arg, reassoc);
  5395. if (peer_arg->peer_nss < 1) {
  5396. ath12k_warn(ar->ab,
  5397. "invalid peer NSS %d\n", peer_arg->peer_nss);
  5398. return -EINVAL;
  5399. }
  5400. peer_arg->is_assoc = true;
  5401. ret = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg);
  5402. if (ret) {
  5403. ath12k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
  5404. arsta->addr, arvif->vdev_id, ret);
  5405. return ret;
  5406. }
  5407. if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
  5408. ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
  5409. arsta->addr, arvif->vdev_id);
  5410. return -ETIMEDOUT;
  5411. }
  5412. num_vht_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask);
  5413. num_he_rates = ath12k_mac_bitrate_mask_num_he_rates(ar, band, mask);
  5414. num_eht_rates = ath12k_mac_bitrate_mask_num_eht_rates(ar, band, mask);
  5415. /* If single VHT/HE/EHT rate is configured (by set_bitrate_mask()),
  5416. * peer_assoc will disable VHT/HE/EHT. This is now enabled by a peer
  5417. * specific fixed param.
  5418. * Note that all other rates and NSS will be disabled for this peer.
  5419. */
  5420. link_sta = ath12k_mac_get_link_sta(arsta);
  5421. if (!link_sta) {
  5422. ath12k_warn(ar->ab, "unable to access link sta in station assoc\n");
  5423. return -EINVAL;
  5424. }
  5425. spin_lock_bh(&ar->data_lock);
  5426. arsta->bw = ath12k_mac_ieee80211_sta_bw_to_wmi(ar, link_sta);
  5427. arsta->bw_prev = link_sta->bandwidth;
  5428. spin_unlock_bh(&ar->data_lock);
  5429. if (link_sta->vht_cap.vht_supported && num_vht_rates == 1) {
  5430. ret = ath12k_mac_set_peer_vht_fixed_rate(arvif, arsta, mask, band);
  5431. } else if (link_sta->he_cap.has_he && num_he_rates == 1) {
  5432. ret = ath12k_mac_set_peer_he_fixed_rate(arvif, arsta, mask, band);
  5433. if (ret)
  5434. return ret;
  5435. } else if (link_sta->eht_cap.has_eht && num_eht_rates == 1) {
  5436. ret = ath12k_mac_set_peer_eht_fixed_rate(arvif, arsta, mask, band);
  5437. if (ret)
  5438. return ret;
  5439. }
  5440. /* Re-assoc is run only to update supported rates for given station. It
  5441. * doesn't make much sense to reconfigure the peer completely.
  5442. */
  5443. if (reassoc)
  5444. return 0;
  5445. ret = ath12k_setup_peer_smps(ar, arvif, arsta->addr,
  5446. &link_sta->ht_cap, &link_sta->he_6ghz_capa);
  5447. if (ret) {
  5448. ath12k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
  5449. arvif->vdev_id, ret);
  5450. return ret;
  5451. }
  5452. if (!sta->wme) {
  5453. arvif->num_legacy_stations++;
  5454. ret = ath12k_recalc_rtscts_prot(arvif);
  5455. if (ret)
  5456. return ret;
  5457. }
  5458. if (sta->wme && sta->uapsd_queues) {
  5459. ret = ath12k_peer_assoc_qos_ap(ar, arvif, arsta);
  5460. if (ret) {
  5461. ath12k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n",
  5462. arsta->addr, arvif->vdev_id, ret);
  5463. return ret;
  5464. }
  5465. }
  5466. return 0;
  5467. }
  5468. static int ath12k_mac_station_disassoc(struct ath12k *ar,
  5469. struct ath12k_link_vif *arvif,
  5470. struct ath12k_link_sta *arsta)
  5471. {
  5472. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  5473. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5474. if (!sta->wme) {
  5475. arvif->num_legacy_stations--;
  5476. return ath12k_recalc_rtscts_prot(arvif);
  5477. }
  5478. return 0;
  5479. }
  5480. static void ath12k_sta_rc_update_wk(struct wiphy *wiphy, struct wiphy_work *wk)
  5481. {
  5482. struct ieee80211_link_sta *link_sta;
  5483. struct ath12k *ar;
  5484. struct ath12k_link_vif *arvif;
  5485. struct ieee80211_sta *sta;
  5486. struct cfg80211_chan_def def;
  5487. enum nl80211_band band;
  5488. const u8 *ht_mcs_mask;
  5489. const u16 *vht_mcs_mask;
  5490. const u16 *he_mcs_mask;
  5491. const u16 *eht_mcs_mask;
  5492. u32 changed, bw, nss, mac_nss, smps, bw_prev;
  5493. int err, num_vht_rates, num_he_rates, num_eht_rates;
  5494. const struct cfg80211_bitrate_mask *mask;
  5495. enum wmi_phy_mode peer_phymode;
  5496. struct ath12k_link_sta *arsta;
  5497. struct ieee80211_vif *vif;
  5498. lockdep_assert_wiphy(wiphy);
  5499. arsta = container_of(wk, struct ath12k_link_sta, update_wk);
  5500. sta = ath12k_ahsta_to_sta(arsta->ahsta);
  5501. arvif = arsta->arvif;
  5502. vif = ath12k_ahvif_to_vif(arvif->ahvif);
  5503. ar = arvif->ar;
  5504. if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)))
  5505. return;
  5506. band = def.chan->band;
  5507. ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
  5508. vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
  5509. he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs;
  5510. eht_mcs_mask = arvif->bitrate_mask.control[band].eht_mcs;
  5511. spin_lock_bh(&ar->data_lock);
  5512. changed = arsta->changed;
  5513. arsta->changed = 0;
  5514. bw = arsta->bw;
  5515. bw_prev = arsta->bw_prev;
  5516. nss = arsta->nss;
  5517. smps = arsta->smps;
  5518. spin_unlock_bh(&ar->data_lock);
  5519. nss = max_t(u32, 1, nss);
  5520. mac_nss = max3(ath12k_mac_max_ht_nss(ht_mcs_mask),
  5521. ath12k_mac_max_vht_nss(vht_mcs_mask),
  5522. ath12k_mac_max_he_nss(he_mcs_mask));
  5523. mac_nss = max(mac_nss, ath12k_mac_max_eht_nss(eht_mcs_mask));
  5524. nss = min(nss, mac_nss);
  5525. struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) =
  5526. kzalloc_obj(*peer_arg);
  5527. if (!peer_arg)
  5528. return;
  5529. if (changed & IEEE80211_RC_BW_CHANGED) {
  5530. ath12k_peer_assoc_h_phymode(ar, arvif, arsta, peer_arg);
  5531. peer_phymode = peer_arg->peer_phymode;
  5532. if (bw > bw_prev) {
  5533. /* Phymode shows maximum supported channel width, if we
  5534. * upgrade bandwidth then due to sanity check of firmware,
  5535. * we have to send WMI_PEER_PHYMODE followed by
  5536. * WMI_PEER_CHWIDTH
  5537. */
  5538. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac bandwidth upgrade for sta %pM new %d old %d\n",
  5539. arsta->addr, bw, bw_prev);
  5540. err = ath12k_wmi_set_peer_param(ar, arsta->addr,
  5541. arvif->vdev_id, WMI_PEER_PHYMODE,
  5542. peer_phymode);
  5543. if (err) {
  5544. ath12k_warn(ar->ab, "failed to update STA %pM to peer phymode %d: %d\n",
  5545. arsta->addr, peer_phymode, err);
  5546. return;
  5547. }
  5548. err = ath12k_wmi_set_peer_param(ar, arsta->addr,
  5549. arvif->vdev_id, WMI_PEER_CHWIDTH,
  5550. bw);
  5551. if (err)
  5552. ath12k_warn(ar->ab, "failed to update STA %pM to peer bandwidth %d: %d\n",
  5553. arsta->addr, bw, err);
  5554. } else {
  5555. /* When we downgrade bandwidth this will conflict with phymode
  5556. * and cause to trigger firmware crash. In this case we send
  5557. * WMI_PEER_CHWIDTH followed by WMI_PEER_PHYMODE
  5558. */
  5559. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac bandwidth downgrade for sta %pM new %d old %d\n",
  5560. arsta->addr, bw, bw_prev);
  5561. err = ath12k_wmi_set_peer_param(ar, arsta->addr,
  5562. arvif->vdev_id, WMI_PEER_CHWIDTH,
  5563. bw);
  5564. if (err) {
  5565. ath12k_warn(ar->ab, "failed to update STA %pM peer to bandwidth %d: %d\n",
  5566. arsta->addr, bw, err);
  5567. return;
  5568. }
  5569. err = ath12k_wmi_set_peer_param(ar, arsta->addr,
  5570. arvif->vdev_id, WMI_PEER_PHYMODE,
  5571. peer_phymode);
  5572. if (err)
  5573. ath12k_warn(ar->ab, "failed to update STA %pM to peer phymode %d: %d\n",
  5574. arsta->addr, peer_phymode, err);
  5575. }
  5576. }
  5577. if (changed & IEEE80211_RC_NSS_CHANGED) {
  5578. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac update sta %pM nss %d\n",
  5579. arsta->addr, nss);
  5580. err = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id,
  5581. WMI_PEER_NSS, nss);
  5582. if (err)
  5583. ath12k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n",
  5584. arsta->addr, nss, err);
  5585. }
  5586. if (changed & IEEE80211_RC_SMPS_CHANGED) {
  5587. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac update sta %pM smps %d\n",
  5588. arsta->addr, smps);
  5589. err = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id,
  5590. WMI_PEER_MIMO_PS_STATE, smps);
  5591. if (err)
  5592. ath12k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n",
  5593. arsta->addr, smps, err);
  5594. }
  5595. if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
  5596. mask = &arvif->bitrate_mask;
  5597. num_vht_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band,
  5598. mask);
  5599. num_he_rates = ath12k_mac_bitrate_mask_num_he_rates(ar, band,
  5600. mask);
  5601. num_eht_rates = ath12k_mac_bitrate_mask_num_eht_rates(ar, band,
  5602. mask);
  5603. /* Peer_assoc_prepare will reject vht rates in
  5604. * bitrate_mask if its not available in range format and
  5605. * sets vht tx_rateset as unsupported. So multiple VHT MCS
  5606. * setting(eg. MCS 4,5,6) per peer is not supported here.
  5607. * But, Single rate in VHT mask can be set as per-peer
  5608. * fixed rate. But even if any HT rates are configured in
  5609. * the bitrate mask, device will not switch to those rates
  5610. * when per-peer Fixed rate is set.
  5611. * TODO: Check RATEMASK_CMDID to support auto rates selection
  5612. * across HT/VHT and for multiple VHT MCS support.
  5613. */
  5614. link_sta = ath12k_mac_get_link_sta(arsta);
  5615. if (!link_sta) {
  5616. ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n",
  5617. sta->addr, arsta->link_id);
  5618. return;
  5619. }
  5620. if (link_sta->vht_cap.vht_supported && num_vht_rates == 1) {
  5621. ath12k_mac_set_peer_vht_fixed_rate(arvif, arsta, mask,
  5622. band);
  5623. } else if (link_sta->he_cap.has_he && num_he_rates == 1) {
  5624. ath12k_mac_set_peer_he_fixed_rate(arvif, arsta, mask, band);
  5625. } else if (link_sta->eht_cap.has_eht && num_eht_rates == 1) {
  5626. err = ath12k_mac_set_peer_eht_fixed_rate(arvif, arsta,
  5627. mask, band);
  5628. if (err) {
  5629. ath12k_warn(ar->ab,
  5630. "failed to set peer EHT fixed rate for STA %pM ret %d\n",
  5631. arsta->addr, err);
  5632. return;
  5633. }
  5634. } else {
  5635. /* If the peer is non-VHT/HE/EHT or no fixed VHT/HE/EHT
  5636. * rate is provided in the new bitrate mask we set the
  5637. * other rates using peer_assoc command. Also clear
  5638. * the peer fixed rate settings as it has higher proprity
  5639. * than peer assoc
  5640. */
  5641. err = ath12k_wmi_set_peer_param(ar, arsta->addr,
  5642. arvif->vdev_id,
  5643. WMI_PEER_PARAM_FIXED_RATE,
  5644. WMI_FIXED_RATE_NONE);
  5645. if (err)
  5646. ath12k_warn(ar->ab,
  5647. "failed to disable peer fixed rate for STA %pM ret %d\n",
  5648. arsta->addr, err);
  5649. ath12k_peer_assoc_prepare(ar, arvif, arsta,
  5650. peer_arg, true);
  5651. peer_arg->is_assoc = false;
  5652. err = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg);
  5653. if (err)
  5654. ath12k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
  5655. arsta->addr, arvif->vdev_id, err);
  5656. if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ))
  5657. ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
  5658. arsta->addr, arvif->vdev_id);
  5659. }
  5660. }
  5661. }
  5662. static void ath12k_mac_free_unassign_link_sta(struct ath12k_hw *ah,
  5663. struct ath12k_sta *ahsta,
  5664. u8 link_id)
  5665. {
  5666. struct ath12k_link_sta *arsta;
  5667. lockdep_assert_wiphy(ah->hw->wiphy);
  5668. if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
  5669. return;
  5670. arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]);
  5671. if (WARN_ON(!arsta))
  5672. return;
  5673. ahsta->links_map &= ~BIT(link_id);
  5674. rcu_assign_pointer(ahsta->link[link_id], NULL);
  5675. synchronize_rcu();
  5676. if (arsta == &ahsta->deflink) {
  5677. arsta->link_id = ATH12K_INVALID_LINK_ID;
  5678. arsta->ahsta = NULL;
  5679. arsta->arvif = NULL;
  5680. return;
  5681. }
  5682. kfree(arsta);
  5683. }
  5684. static int ath12k_mac_inc_num_stations(struct ath12k_link_vif *arvif,
  5685. struct ath12k_link_sta *arsta)
  5686. {
  5687. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  5688. struct ath12k *ar = arvif->ar;
  5689. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5690. if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
  5691. return 0;
  5692. if (ar->num_stations >= ar->max_num_stations)
  5693. return -ENOBUFS;
  5694. ar->num_stations++;
  5695. arvif->num_stations++;
  5696. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  5697. "mac station %pM connected to vdev %u num_stations %u\n",
  5698. arsta->addr, arvif->vdev_id, arvif->num_stations);
  5699. return 0;
  5700. }
  5701. static void ath12k_mac_dec_num_stations(struct ath12k_link_vif *arvif,
  5702. struct ath12k_link_sta *arsta)
  5703. {
  5704. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  5705. struct ath12k *ar = arvif->ar;
  5706. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5707. if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
  5708. return;
  5709. ar->num_stations--;
  5710. if (arvif->num_stations) {
  5711. arvif->num_stations--;
  5712. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  5713. "mac station %pM disconnected from vdev %u num_stations %u\n",
  5714. arsta->addr, arvif->vdev_id, arvif->num_stations);
  5715. } else {
  5716. ath12k_warn(ar->ab,
  5717. "mac station %pM disconnect for vdev %u without any connected station\n",
  5718. arsta->addr, arvif->vdev_id);
  5719. }
  5720. }
  5721. static void ath12k_mac_station_post_remove(struct ath12k *ar,
  5722. struct ath12k_link_vif *arvif,
  5723. struct ath12k_link_sta *arsta)
  5724. {
  5725. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  5726. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  5727. struct ath12k_dp_link_peer *peer;
  5728. struct ath12k_dp *dp = ath12k_ab_to_dp(ar->ab);
  5729. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5730. ath12k_mac_dec_num_stations(arvif, arsta);
  5731. spin_lock_bh(&dp->dp_lock);
  5732. peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id,
  5733. arsta->addr);
  5734. if (peer && peer->sta == sta) {
  5735. ath12k_warn(ar->ab, "Found peer entry %pM n vdev %i after it was supposedly removed\n",
  5736. vif->addr, arvif->vdev_id);
  5737. peer->sta = NULL;
  5738. ath12k_dp_link_peer_free(peer);
  5739. ar->num_peers--;
  5740. }
  5741. spin_unlock_bh(&dp->dp_lock);
  5742. }
  5743. static int ath12k_mac_station_unauthorize(struct ath12k *ar,
  5744. struct ath12k_link_vif *arvif,
  5745. struct ath12k_link_sta *arsta)
  5746. {
  5747. struct ath12k_dp_link_peer *peer;
  5748. int ret;
  5749. struct ath12k_dp *dp = ath12k_ab_to_dp(ar->ab);
  5750. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5751. spin_lock_bh(&dp->dp_lock);
  5752. peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id,
  5753. arsta->addr);
  5754. if (peer)
  5755. peer->is_authorized = false;
  5756. spin_unlock_bh(&dp->dp_lock);
  5757. /* Driver must clear the keys during the state change from
  5758. * IEEE80211_STA_AUTHORIZED to IEEE80211_STA_ASSOC, since after
  5759. * returning from here, mac80211 is going to delete the keys
  5760. * in __sta_info_destroy_part2(). This will ensure that the driver does
  5761. * not retain stale key references after mac80211 deletes the keys.
  5762. */
  5763. ret = ath12k_clear_peer_keys(arvif, arsta->addr);
  5764. if (ret) {
  5765. ath12k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n",
  5766. arvif->vdev_id, ret);
  5767. return ret;
  5768. }
  5769. return 0;
  5770. }
  5771. static int ath12k_mac_station_authorize(struct ath12k *ar,
  5772. struct ath12k_link_vif *arvif,
  5773. struct ath12k_link_sta *arsta)
  5774. {
  5775. struct ath12k_dp_link_peer *peer;
  5776. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  5777. int ret;
  5778. struct ath12k_dp *dp = ath12k_ab_to_dp(ar->ab);
  5779. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5780. spin_lock_bh(&dp->dp_lock);
  5781. peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id,
  5782. arsta->addr);
  5783. if (peer)
  5784. peer->is_authorized = true;
  5785. spin_unlock_bh(&dp->dp_lock);
  5786. if (vif->type == NL80211_IFTYPE_STATION && arvif->is_up) {
  5787. ret = ath12k_wmi_set_peer_param(ar, arsta->addr,
  5788. arvif->vdev_id,
  5789. WMI_PEER_AUTHORIZE,
  5790. 1);
  5791. if (ret) {
  5792. ath12k_warn(ar->ab, "Unable to authorize peer %pM vdev %d: %d\n",
  5793. arsta->addr, arvif->vdev_id, ret);
  5794. return ret;
  5795. }
  5796. }
  5797. return 0;
  5798. }
  5799. static int ath12k_mac_station_remove(struct ath12k *ar,
  5800. struct ath12k_link_vif *arvif,
  5801. struct ath12k_link_sta *arsta)
  5802. {
  5803. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  5804. struct ath12k_vif *ahvif = arvif->ahvif;
  5805. int ret = 0;
  5806. struct ath12k_link_sta *temp_arsta;
  5807. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5808. wiphy_work_cancel(ar->ah->hw->wiphy, &arsta->update_wk);
  5809. if (ahvif->vdev_type == WMI_VDEV_TYPE_STA) {
  5810. ath12k_bss_disassoc(ar, arvif);
  5811. ret = ath12k_mac_vdev_stop(arvif);
  5812. if (ret)
  5813. ath12k_warn(ar->ab, "failed to stop vdev %i: %d\n",
  5814. arvif->vdev_id, ret);
  5815. }
  5816. if (sta->mlo)
  5817. return ret;
  5818. ath12k_dp_peer_cleanup(ar, arvif->vdev_id, arsta->addr);
  5819. ret = ath12k_peer_delete(ar, arvif->vdev_id, arsta->addr);
  5820. if (ret)
  5821. ath12k_warn(ar->ab, "Failed to delete peer: %pM for VDEV: %d\n",
  5822. arsta->addr, arvif->vdev_id);
  5823. else
  5824. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "Removed peer: %pM for VDEV: %d\n",
  5825. arsta->addr, arvif->vdev_id);
  5826. ath12k_mac_station_post_remove(ar, arvif, arsta);
  5827. spin_lock_bh(&ar->ab->base_lock);
  5828. /* To handle roaming and split phy scenario */
  5829. temp_arsta = ath12k_link_sta_find_by_addr(ar->ab, arsta->addr);
  5830. if (temp_arsta && temp_arsta->arvif->ar == ar)
  5831. ath12k_link_sta_rhash_delete(ar->ab, arsta);
  5832. spin_unlock_bh(&ar->ab->base_lock);
  5833. if (sta->valid_links)
  5834. ath12k_mac_free_unassign_link_sta(ahvif->ah,
  5835. arsta->ahsta, arsta->link_id);
  5836. return ret;
  5837. }
  5838. static int ath12k_mac_station_add(struct ath12k *ar,
  5839. struct ath12k_link_vif *arvif,
  5840. struct ath12k_link_sta *arsta)
  5841. {
  5842. struct ath12k_base *ab = ar->ab;
  5843. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  5844. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta);
  5845. struct ath12k_wmi_peer_create_arg peer_param = {};
  5846. int ret;
  5847. struct ath12k_link_sta *temp_arsta;
  5848. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  5849. ret = ath12k_mac_inc_num_stations(arvif, arsta);
  5850. if (ret) {
  5851. ath12k_warn(ab, "refusing to associate station: too many connected already (%d)\n",
  5852. ar->max_num_stations);
  5853. goto exit;
  5854. }
  5855. spin_lock_bh(&ab->base_lock);
  5856. /*
  5857. * In case of Split PHY and roaming scenario, pdev idx
  5858. * might differ but both the pdev will share same rhash
  5859. * table. In that case update the rhash table if link_sta is
  5860. * already present
  5861. */
  5862. temp_arsta = ath12k_link_sta_find_by_addr(ab, arsta->addr);
  5863. if (temp_arsta && temp_arsta->arvif->ar != ar)
  5864. ath12k_link_sta_rhash_delete(ab, temp_arsta);
  5865. ret = ath12k_link_sta_rhash_add(ab, arsta);
  5866. spin_unlock_bh(&ab->base_lock);
  5867. if (ret) {
  5868. ath12k_warn(ab, "Failed to add arsta: %pM to hash table, ret: %d",
  5869. arsta->addr, ret);
  5870. goto dec_num_station;
  5871. }
  5872. peer_param.vdev_id = arvif->vdev_id;
  5873. peer_param.peer_addr = arsta->addr;
  5874. peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
  5875. peer_param.ml_enabled = sta->mlo;
  5876. ret = ath12k_peer_create(ar, arvif, sta, &peer_param);
  5877. if (ret) {
  5878. ath12k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n",
  5879. arsta->addr, arvif->vdev_id);
  5880. goto free_peer;
  5881. }
  5882. ath12k_dbg(ab, ATH12K_DBG_MAC, "Added peer: %pM for VDEV: %d\n",
  5883. arsta->addr, arvif->vdev_id);
  5884. if (ieee80211_vif_is_mesh(vif)) {
  5885. ret = ath12k_wmi_set_peer_param(ar, arsta->addr,
  5886. arvif->vdev_id,
  5887. WMI_PEER_USE_4ADDR, 1);
  5888. if (ret) {
  5889. ath12k_warn(ab, "failed to STA %pM 4addr capability: %d\n",
  5890. arsta->addr, ret);
  5891. goto free_peer;
  5892. }
  5893. }
  5894. ret = ath12k_dp_peer_setup(ar, arvif->vdev_id, arsta->addr);
  5895. if (ret) {
  5896. ath12k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n",
  5897. arsta->addr, arvif->vdev_id, ret);
  5898. goto free_peer;
  5899. }
  5900. if (ab->hw_params->vdev_start_delay &&
  5901. !arvif->is_started &&
  5902. arvif->ahvif->vdev_type != WMI_VDEV_TYPE_AP) {
  5903. ret = ath12k_start_vdev_delay(ar, arvif);
  5904. if (ret) {
  5905. ath12k_warn(ab, "failed to delay vdev start: %d\n", ret);
  5906. goto free_peer;
  5907. }
  5908. }
  5909. return 0;
  5910. free_peer:
  5911. ath12k_peer_delete(ar, arvif->vdev_id, arsta->addr);
  5912. spin_lock_bh(&ab->base_lock);
  5913. ath12k_link_sta_rhash_delete(ab, arsta);
  5914. spin_unlock_bh(&ab->base_lock);
  5915. dec_num_station:
  5916. ath12k_mac_dec_num_stations(arvif, arsta);
  5917. exit:
  5918. return ret;
  5919. }
  5920. static int ath12k_mac_assign_link_sta(struct ath12k_hw *ah,
  5921. struct ath12k_sta *ahsta,
  5922. struct ath12k_link_sta *arsta,
  5923. struct ath12k_vif *ahvif,
  5924. u8 link_id)
  5925. {
  5926. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta);
  5927. struct ieee80211_link_sta *link_sta;
  5928. struct ath12k_link_vif *arvif;
  5929. lockdep_assert_wiphy(ah->hw->wiphy);
  5930. if (!arsta || link_id >= IEEE80211_MLD_MAX_NUM_LINKS)
  5931. return -EINVAL;
  5932. arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]);
  5933. if (!arvif)
  5934. return -EINVAL;
  5935. memset(arsta, 0, sizeof(*arsta));
  5936. link_sta = wiphy_dereference(ah->hw->wiphy, sta->link[link_id]);
  5937. if (!link_sta)
  5938. return -EINVAL;
  5939. ether_addr_copy(arsta->addr, link_sta->addr);
  5940. /* logical index of the link sta in order of creation */
  5941. arsta->link_idx = ahsta->num_peer++;
  5942. arsta->link_id = link_id;
  5943. ahsta->links_map |= BIT(arsta->link_id);
  5944. arsta->arvif = arvif;
  5945. arsta->ahsta = ahsta;
  5946. ahsta->ahvif = ahvif;
  5947. wiphy_work_init(&arsta->update_wk, ath12k_sta_rc_update_wk);
  5948. rcu_assign_pointer(ahsta->link[link_id], arsta);
  5949. return 0;
  5950. }
  5951. static void ath12k_mac_ml_station_remove(struct ath12k_vif *ahvif,
  5952. struct ath12k_sta *ahsta)
  5953. {
  5954. struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta);
  5955. struct ath12k_hw *ah = ahvif->ah;
  5956. struct ath12k_link_vif *arvif;
  5957. struct ath12k_link_sta *arsta;
  5958. unsigned long links;
  5959. struct ath12k *ar;
  5960. u8 link_id;
  5961. lockdep_assert_wiphy(ah->hw->wiphy);
  5962. ath12k_peer_mlo_link_peers_delete(ahvif, ahsta);
  5963. /* validate link station removal and clear arsta links */
  5964. links = ahsta->links_map;
  5965. for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
  5966. arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]);
  5967. arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]);
  5968. if (!arvif || !arsta)
  5969. continue;
  5970. ar = arvif->ar;
  5971. ath12k_mac_station_post_remove(ar, arvif, arsta);
  5972. spin_lock_bh(&ar->ab->base_lock);
  5973. ath12k_link_sta_rhash_delete(ar->ab, arsta);
  5974. spin_unlock_bh(&ar->ab->base_lock);
  5975. ath12k_mac_free_unassign_link_sta(ah, ahsta, link_id);
  5976. }
  5977. if (sta->mlo) {
  5978. clear_bit(ahsta->ml_peer_id, ah->free_ml_peer_id_map);
  5979. ahsta->ml_peer_id = ATH12K_MLO_PEER_ID_INVALID;
  5980. }
  5981. }
  5982. static int ath12k_mac_handle_link_sta_state(struct ieee80211_hw *hw,
  5983. struct ath12k_link_vif *arvif,
  5984. struct ath12k_link_sta *arsta,
  5985. enum ieee80211_sta_state old_state,
  5986. enum ieee80211_sta_state new_state)
  5987. {
  5988. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  5989. struct ieee80211_bss_conf *link_conf;
  5990. struct ath12k *ar = arvif->ar;
  5991. struct ath12k_reg_info *reg_info;
  5992. struct ath12k_base *ab = ar->ab;
  5993. int ret = 0;
  5994. lockdep_assert_wiphy(hw->wiphy);
  5995. ath12k_dbg(ab, ATH12K_DBG_MAC, "mac handle link %u sta %pM state %d -> %d\n",
  5996. arsta->link_id, arsta->addr, old_state, new_state);
  5997. /* IEEE80211_STA_NONE -> IEEE80211_STA_NOTEXIST: Remove the station
  5998. * from driver
  5999. */
  6000. if ((old_state == IEEE80211_STA_NONE &&
  6001. new_state == IEEE80211_STA_NOTEXIST)) {
  6002. ret = ath12k_mac_station_remove(ar, arvif, arsta);
  6003. if (ret) {
  6004. ath12k_warn(ab, "Failed to remove station: %pM for VDEV: %d\n",
  6005. arsta->addr, arvif->vdev_id);
  6006. goto exit;
  6007. }
  6008. }
  6009. /* IEEE80211_STA_NOTEXIST -> IEEE80211_STA_NONE: Add new station to driver */
  6010. if (old_state == IEEE80211_STA_NOTEXIST &&
  6011. new_state == IEEE80211_STA_NONE) {
  6012. ret = ath12k_mac_station_add(ar, arvif, arsta);
  6013. if (ret)
  6014. ath12k_warn(ab, "Failed to add station: %pM for VDEV: %d\n",
  6015. arsta->addr, arvif->vdev_id);
  6016. /* IEEE80211_STA_AUTH -> IEEE80211_STA_ASSOC: Send station assoc command for
  6017. * peer associated to AP/Mesh/ADHOC vif type.
  6018. */
  6019. } else if (old_state == IEEE80211_STA_AUTH &&
  6020. new_state == IEEE80211_STA_ASSOC &&
  6021. (vif->type == NL80211_IFTYPE_AP ||
  6022. vif->type == NL80211_IFTYPE_MESH_POINT ||
  6023. vif->type == NL80211_IFTYPE_ADHOC)) {
  6024. ret = ath12k_mac_station_assoc(ar, arvif, arsta, false);
  6025. if (ret)
  6026. ath12k_warn(ab, "Failed to associate station: %pM\n",
  6027. arsta->addr);
  6028. /* IEEE80211_STA_ASSOC -> IEEE80211_STA_AUTHORIZED: set peer status as
  6029. * authorized
  6030. */
  6031. } else if (old_state == IEEE80211_STA_ASSOC &&
  6032. new_state == IEEE80211_STA_AUTHORIZED) {
  6033. ret = ath12k_mac_station_authorize(ar, arvif, arsta);
  6034. if (ret) {
  6035. ath12k_warn(ab, "Failed to authorize station: %pM\n",
  6036. arsta->addr);
  6037. goto exit;
  6038. }
  6039. if (ath12k_wmi_supports_6ghz_cc_ext(ar) &&
  6040. arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA) {
  6041. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  6042. reg_info = ab->reg_info[ar->pdev_idx];
  6043. ath12k_dbg(ab, ATH12K_DBG_MAC, "connection done, update reg rules\n");
  6044. ath12k_hw_to_ah(hw)->regd_updated = false;
  6045. ath12k_reg_handle_chan_list(ab, reg_info, arvif->ahvif->vdev_type,
  6046. link_conf->power_type);
  6047. }
  6048. /* IEEE80211_STA_AUTHORIZED -> IEEE80211_STA_ASSOC: station may be in removal,
  6049. * deauthorize it.
  6050. */
  6051. } else if (old_state == IEEE80211_STA_AUTHORIZED &&
  6052. new_state == IEEE80211_STA_ASSOC) {
  6053. ath12k_mac_station_unauthorize(ar, arvif, arsta);
  6054. /* IEEE80211_STA_ASSOC -> IEEE80211_STA_AUTH: disassoc peer connected to
  6055. * AP/mesh/ADHOC vif type.
  6056. */
  6057. } else if (old_state == IEEE80211_STA_ASSOC &&
  6058. new_state == IEEE80211_STA_AUTH &&
  6059. (vif->type == NL80211_IFTYPE_AP ||
  6060. vif->type == NL80211_IFTYPE_MESH_POINT ||
  6061. vif->type == NL80211_IFTYPE_ADHOC)) {
  6062. ret = ath12k_mac_station_disassoc(ar, arvif, arsta);
  6063. if (ret)
  6064. ath12k_warn(ab, "Failed to disassociate station: %pM\n",
  6065. arsta->addr);
  6066. }
  6067. exit:
  6068. return ret;
  6069. }
  6070. static bool ath12k_mac_is_freq_on_mac(struct ath12k_hw_mode_freq_range_arg *freq_range,
  6071. u32 freq, u8 mac_id)
  6072. {
  6073. return (freq >= freq_range[mac_id].low_2ghz_freq &&
  6074. freq <= freq_range[mac_id].high_2ghz_freq) ||
  6075. (freq >= freq_range[mac_id].low_5ghz_freq &&
  6076. freq <= freq_range[mac_id].high_5ghz_freq);
  6077. }
  6078. static bool
  6079. ath12k_mac_2_freq_same_mac_in_freq_range(struct ath12k_base *ab,
  6080. struct ath12k_hw_mode_freq_range_arg *freq_range,
  6081. u32 freq_link1, u32 freq_link2)
  6082. {
  6083. u8 i;
  6084. for (i = 0; i < MAX_RADIOS; i++) {
  6085. if (ath12k_mac_is_freq_on_mac(freq_range, freq_link1, i) &&
  6086. ath12k_mac_is_freq_on_mac(freq_range, freq_link2, i))
  6087. return true;
  6088. }
  6089. return false;
  6090. }
  6091. static bool ath12k_mac_is_hw_dbs_capable(struct ath12k_base *ab)
  6092. {
  6093. return test_bit(WMI_TLV_SERVICE_DUAL_BAND_SIMULTANEOUS_SUPPORT,
  6094. ab->wmi_ab.svc_map) &&
  6095. ab->wmi_ab.hw_mode_info.support_dbs;
  6096. }
  6097. static bool ath12k_mac_2_freq_same_mac_in_dbs(struct ath12k_base *ab,
  6098. u32 freq_link1, u32 freq_link2)
  6099. {
  6100. struct ath12k_hw_mode_freq_range_arg *freq_range;
  6101. if (!ath12k_mac_is_hw_dbs_capable(ab))
  6102. return true;
  6103. freq_range = ab->wmi_ab.hw_mode_info.freq_range_caps[ATH12K_HW_MODE_DBS];
  6104. return ath12k_mac_2_freq_same_mac_in_freq_range(ab, freq_range,
  6105. freq_link1, freq_link2);
  6106. }
  6107. static bool ath12k_mac_is_hw_sbs_capable(struct ath12k_base *ab)
  6108. {
  6109. return test_bit(WMI_TLV_SERVICE_DUAL_BAND_SIMULTANEOUS_SUPPORT,
  6110. ab->wmi_ab.svc_map) &&
  6111. ab->wmi_ab.hw_mode_info.support_sbs;
  6112. }
  6113. static bool ath12k_mac_2_freq_same_mac_in_sbs(struct ath12k_base *ab,
  6114. u32 freq_link1, u32 freq_link2)
  6115. {
  6116. struct ath12k_hw_mode_info *info = &ab->wmi_ab.hw_mode_info;
  6117. struct ath12k_hw_mode_freq_range_arg *sbs_uppr_share;
  6118. struct ath12k_hw_mode_freq_range_arg *sbs_low_share;
  6119. struct ath12k_hw_mode_freq_range_arg *sbs_range;
  6120. if (!ath12k_mac_is_hw_sbs_capable(ab))
  6121. return true;
  6122. if (ab->wmi_ab.sbs_lower_band_end_freq) {
  6123. sbs_uppr_share = info->freq_range_caps[ATH12K_HW_MODE_SBS_UPPER_SHARE];
  6124. sbs_low_share = info->freq_range_caps[ATH12K_HW_MODE_SBS_LOWER_SHARE];
  6125. return ath12k_mac_2_freq_same_mac_in_freq_range(ab, sbs_low_share,
  6126. freq_link1, freq_link2) ||
  6127. ath12k_mac_2_freq_same_mac_in_freq_range(ab, sbs_uppr_share,
  6128. freq_link1, freq_link2);
  6129. }
  6130. sbs_range = info->freq_range_caps[ATH12K_HW_MODE_SBS];
  6131. return ath12k_mac_2_freq_same_mac_in_freq_range(ab, sbs_range,
  6132. freq_link1, freq_link2);
  6133. }
  6134. static bool ath12k_mac_freqs_on_same_mac(struct ath12k_base *ab,
  6135. u32 freq_link1, u32 freq_link2)
  6136. {
  6137. return ath12k_mac_2_freq_same_mac_in_dbs(ab, freq_link1, freq_link2) &&
  6138. ath12k_mac_2_freq_same_mac_in_sbs(ab, freq_link1, freq_link2);
  6139. }
  6140. static int ath12k_mac_mlo_sta_set_link_active(struct ath12k_base *ab,
  6141. enum wmi_mlo_link_force_reason reason,
  6142. enum wmi_mlo_link_force_mode mode,
  6143. u8 *mlo_vdev_id_lst,
  6144. u8 num_mlo_vdev,
  6145. u8 *mlo_inactive_vdev_lst,
  6146. u8 num_mlo_inactive_vdev)
  6147. {
  6148. struct wmi_mlo_link_set_active_arg param = {};
  6149. u32 entry_idx, entry_offset, vdev_idx;
  6150. u8 vdev_id;
  6151. param.reason = reason;
  6152. param.force_mode = mode;
  6153. for (vdev_idx = 0; vdev_idx < num_mlo_vdev; vdev_idx++) {
  6154. vdev_id = mlo_vdev_id_lst[vdev_idx];
  6155. entry_idx = vdev_id / 32;
  6156. entry_offset = vdev_id % 32;
  6157. if (entry_idx >= WMI_MLO_LINK_NUM_SZ) {
  6158. ath12k_warn(ab, "Invalid entry_idx %d num_mlo_vdev %d vdev %d",
  6159. entry_idx, num_mlo_vdev, vdev_id);
  6160. return -EINVAL;
  6161. }
  6162. param.vdev_bitmap[entry_idx] |= 1 << entry_offset;
  6163. /* update entry number if entry index changed */
  6164. if (param.num_vdev_bitmap < entry_idx + 1)
  6165. param.num_vdev_bitmap = entry_idx + 1;
  6166. }
  6167. ath12k_dbg(ab, ATH12K_DBG_MAC,
  6168. "num_vdev_bitmap %d vdev_bitmap[0] = 0x%x, vdev_bitmap[1] = 0x%x",
  6169. param.num_vdev_bitmap, param.vdev_bitmap[0], param.vdev_bitmap[1]);
  6170. if (mode == WMI_MLO_LINK_FORCE_MODE_ACTIVE_INACTIVE) {
  6171. for (vdev_idx = 0; vdev_idx < num_mlo_inactive_vdev; vdev_idx++) {
  6172. vdev_id = mlo_inactive_vdev_lst[vdev_idx];
  6173. entry_idx = vdev_id / 32;
  6174. entry_offset = vdev_id % 32;
  6175. if (entry_idx >= WMI_MLO_LINK_NUM_SZ) {
  6176. ath12k_warn(ab, "Invalid entry_idx %d num_mlo_vdev %d vdev %d",
  6177. entry_idx, num_mlo_inactive_vdev, vdev_id);
  6178. return -EINVAL;
  6179. }
  6180. param.inactive_vdev_bitmap[entry_idx] |= 1 << entry_offset;
  6181. /* update entry number if entry index changed */
  6182. if (param.num_inactive_vdev_bitmap < entry_idx + 1)
  6183. param.num_inactive_vdev_bitmap = entry_idx + 1;
  6184. }
  6185. ath12k_dbg(ab, ATH12K_DBG_MAC,
  6186. "num_vdev_bitmap %d inactive_vdev_bitmap[0] = 0x%x, inactive_vdev_bitmap[1] = 0x%x",
  6187. param.num_inactive_vdev_bitmap,
  6188. param.inactive_vdev_bitmap[0],
  6189. param.inactive_vdev_bitmap[1]);
  6190. }
  6191. if (mode == WMI_MLO_LINK_FORCE_MODE_ACTIVE_LINK_NUM ||
  6192. mode == WMI_MLO_LINK_FORCE_MODE_INACTIVE_LINK_NUM) {
  6193. param.num_link_entry = 1;
  6194. param.link_num[0].num_of_link = num_mlo_vdev - 1;
  6195. }
  6196. return ath12k_wmi_send_mlo_link_set_active_cmd(ab, &param);
  6197. }
  6198. static int ath12k_mac_mlo_sta_update_link_active(struct ath12k_base *ab,
  6199. struct ieee80211_hw *hw,
  6200. struct ath12k_vif *ahvif)
  6201. {
  6202. u8 mlo_vdev_id_lst[IEEE80211_MLD_MAX_NUM_LINKS] = {};
  6203. u32 mlo_freq_list[IEEE80211_MLD_MAX_NUM_LINKS] = {};
  6204. unsigned long links = ahvif->links_map;
  6205. enum wmi_mlo_link_force_reason reason;
  6206. struct ieee80211_chanctx_conf *conf;
  6207. enum wmi_mlo_link_force_mode mode;
  6208. struct ieee80211_bss_conf *info;
  6209. struct ath12k_link_vif *arvif;
  6210. u8 num_mlo_vdev = 0;
  6211. u8 link_id;
  6212. for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
  6213. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  6214. /* make sure vdev is created on this device */
  6215. if (!arvif || !arvif->is_created || arvif->ar->ab != ab)
  6216. continue;
  6217. info = ath12k_mac_get_link_bss_conf(arvif);
  6218. conf = wiphy_dereference(hw->wiphy, info->chanctx_conf);
  6219. mlo_freq_list[num_mlo_vdev] = conf->def.chan->center_freq;
  6220. mlo_vdev_id_lst[num_mlo_vdev] = arvif->vdev_id;
  6221. num_mlo_vdev++;
  6222. }
  6223. /* It is not allowed to activate more links than a single device
  6224. * supported. Something goes wrong if we reach here.
  6225. */
  6226. if (num_mlo_vdev > ATH12K_NUM_MAX_ACTIVE_LINKS_PER_DEVICE) {
  6227. WARN_ON_ONCE(1);
  6228. return -EINVAL;
  6229. }
  6230. /* if 2 links are established and both link channels fall on the
  6231. * same hardware MAC, send command to firmware to deactivate one
  6232. * of them.
  6233. */
  6234. if (num_mlo_vdev == 2 &&
  6235. ath12k_mac_freqs_on_same_mac(ab, mlo_freq_list[0],
  6236. mlo_freq_list[1])) {
  6237. mode = WMI_MLO_LINK_FORCE_MODE_INACTIVE_LINK_NUM;
  6238. reason = WMI_MLO_LINK_FORCE_REASON_NEW_CONNECT;
  6239. return ath12k_mac_mlo_sta_set_link_active(ab, reason, mode,
  6240. mlo_vdev_id_lst, num_mlo_vdev,
  6241. NULL, 0);
  6242. }
  6243. return 0;
  6244. }
  6245. static bool ath12k_mac_are_sbs_chan(struct ath12k_base *ab, u32 freq_1, u32 freq_2)
  6246. {
  6247. if (!ath12k_mac_is_hw_sbs_capable(ab))
  6248. return false;
  6249. if (ath12k_is_2ghz_channel_freq(freq_1) ||
  6250. ath12k_is_2ghz_channel_freq(freq_2))
  6251. return false;
  6252. return !ath12k_mac_2_freq_same_mac_in_sbs(ab, freq_1, freq_2);
  6253. }
  6254. static bool ath12k_mac_are_dbs_chan(struct ath12k_base *ab, u32 freq_1, u32 freq_2)
  6255. {
  6256. if (!ath12k_mac_is_hw_dbs_capable(ab))
  6257. return false;
  6258. return !ath12k_mac_2_freq_same_mac_in_dbs(ab, freq_1, freq_2);
  6259. }
  6260. static int ath12k_mac_select_links(struct ath12k_base *ab,
  6261. struct ieee80211_vif *vif,
  6262. struct ieee80211_hw *hw,
  6263. u16 *selected_links)
  6264. {
  6265. unsigned long useful_links = ieee80211_vif_usable_links(vif);
  6266. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  6267. u8 num_useful_links = hweight_long(useful_links);
  6268. struct ieee80211_chanctx_conf *chanctx;
  6269. struct ath12k_link_vif *assoc_arvif;
  6270. u32 assoc_link_freq, partner_freq;
  6271. u16 sbs_links = 0, dbs_links = 0;
  6272. struct ieee80211_bss_conf *info;
  6273. struct ieee80211_channel *chan;
  6274. struct ieee80211_sta *sta;
  6275. struct ath12k_sta *ahsta;
  6276. u8 link_id;
  6277. /* activate all useful links if less than max supported */
  6278. if (num_useful_links <= ATH12K_NUM_MAX_ACTIVE_LINKS_PER_DEVICE) {
  6279. *selected_links = useful_links;
  6280. return 0;
  6281. }
  6282. /* only in station mode we can get here, so it's safe
  6283. * to use ap_addr
  6284. */
  6285. rcu_read_lock();
  6286. sta = ieee80211_find_sta(vif, vif->cfg.ap_addr);
  6287. if (!sta) {
  6288. rcu_read_unlock();
  6289. ath12k_warn(ab, "failed to find sta with addr %pM\n", vif->cfg.ap_addr);
  6290. return -EINVAL;
  6291. }
  6292. ahsta = ath12k_sta_to_ahsta(sta);
  6293. assoc_arvif = wiphy_dereference(hw->wiphy, ahvif->link[ahsta->assoc_link_id]);
  6294. info = ath12k_mac_get_link_bss_conf(assoc_arvif);
  6295. chanctx = rcu_dereference(info->chanctx_conf);
  6296. assoc_link_freq = chanctx->def.chan->center_freq;
  6297. rcu_read_unlock();
  6298. ath12k_dbg(ab, ATH12K_DBG_MAC, "assoc link %u freq %u\n",
  6299. assoc_arvif->link_id, assoc_link_freq);
  6300. /* assoc link is already activated and has to be kept active,
  6301. * only need to select a partner link from others.
  6302. */
  6303. useful_links &= ~BIT(assoc_arvif->link_id);
  6304. for_each_set_bit(link_id, &useful_links, IEEE80211_MLD_MAX_NUM_LINKS) {
  6305. info = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]);
  6306. if (!info) {
  6307. ath12k_warn(ab, "failed to get link info for link: %u\n",
  6308. link_id);
  6309. return -ENOLINK;
  6310. }
  6311. chan = info->chanreq.oper.chan;
  6312. if (!chan) {
  6313. ath12k_warn(ab, "failed to get chan for link: %u\n", link_id);
  6314. return -EINVAL;
  6315. }
  6316. partner_freq = chan->center_freq;
  6317. if (ath12k_mac_are_sbs_chan(ab, assoc_link_freq, partner_freq)) {
  6318. sbs_links |= BIT(link_id);
  6319. ath12k_dbg(ab, ATH12K_DBG_MAC, "new SBS link %u freq %u\n",
  6320. link_id, partner_freq);
  6321. continue;
  6322. }
  6323. if (ath12k_mac_are_dbs_chan(ab, assoc_link_freq, partner_freq)) {
  6324. dbs_links |= BIT(link_id);
  6325. ath12k_dbg(ab, ATH12K_DBG_MAC, "new DBS link %u freq %u\n",
  6326. link_id, partner_freq);
  6327. continue;
  6328. }
  6329. ath12k_dbg(ab, ATH12K_DBG_MAC, "non DBS/SBS link %u freq %u\n",
  6330. link_id, partner_freq);
  6331. }
  6332. /* choose the first candidate no matter how many is in the list */
  6333. if (sbs_links)
  6334. link_id = __ffs(sbs_links);
  6335. else if (dbs_links)
  6336. link_id = __ffs(dbs_links);
  6337. else
  6338. link_id = ffs(useful_links) - 1;
  6339. ath12k_dbg(ab, ATH12K_DBG_MAC, "select partner link %u\n", link_id);
  6340. *selected_links = BIT(assoc_arvif->link_id) | BIT(link_id);
  6341. return 0;
  6342. }
  6343. int ath12k_mac_op_sta_state(struct ieee80211_hw *hw,
  6344. struct ieee80211_vif *vif,
  6345. struct ieee80211_sta *sta,
  6346. enum ieee80211_sta_state old_state,
  6347. enum ieee80211_sta_state new_state)
  6348. {
  6349. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  6350. struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta);
  6351. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  6352. struct ath12k_base *prev_ab = NULL, *ab;
  6353. struct ath12k_link_vif *arvif;
  6354. struct ath12k_link_sta *arsta;
  6355. unsigned long valid_links;
  6356. u16 selected_links = 0;
  6357. u8 link_id = 0, i;
  6358. struct ath12k *ar;
  6359. int ret = -EINVAL;
  6360. struct ath12k_dp_peer_create_params dp_params = {};
  6361. lockdep_assert_wiphy(hw->wiphy);
  6362. if (ieee80211_vif_is_mld(vif) && sta->valid_links) {
  6363. WARN_ON(!sta->mlo && hweight16(sta->valid_links) != 1);
  6364. link_id = ffs(sta->valid_links) - 1;
  6365. }
  6366. /* IEEE80211_STA_NOTEXIST -> IEEE80211_STA_NONE:
  6367. * New station add received. If this is a ML station then
  6368. * ahsta->links_map will be zero and sta->valid_links will be 1.
  6369. * Assign default link to the first link sta.
  6370. */
  6371. if (old_state == IEEE80211_STA_NOTEXIST &&
  6372. new_state == IEEE80211_STA_NONE) {
  6373. memset(ahsta, 0, sizeof(*ahsta));
  6374. arsta = &ahsta->deflink;
  6375. /* ML sta */
  6376. if (sta->mlo && !ahsta->links_map &&
  6377. (hweight16(sta->valid_links) == 1)) {
  6378. ahsta->ml_peer_id = ath12k_peer_ml_alloc(ah);
  6379. if (ahsta->ml_peer_id == ATH12K_MLO_PEER_ID_INVALID) {
  6380. ath12k_hw_warn(ah, "unable to allocate ML peer id for sta %pM",
  6381. sta->addr);
  6382. goto exit;
  6383. }
  6384. dp_params.is_mlo = true;
  6385. dp_params.peer_id = ahsta->ml_peer_id | ATH12K_PEER_ML_ID_VALID;
  6386. }
  6387. dp_params.sta = sta;
  6388. if (vif->type == NL80211_IFTYPE_AP)
  6389. dp_params.ucast_ra_only = true;
  6390. ret = ath12k_dp_peer_create(&ah->dp_hw, sta->addr, &dp_params);
  6391. if (ret) {
  6392. ath12k_hw_warn(ah, "unable to create ath12k_dp_peer for sta %pM, ret: %d",
  6393. sta->addr, ret);
  6394. goto ml_peer_id_clear;
  6395. }
  6396. ret = ath12k_mac_assign_link_sta(ah, ahsta, arsta, ahvif,
  6397. link_id);
  6398. if (ret) {
  6399. ath12k_hw_warn(ah, "unable assign link %d for sta %pM",
  6400. link_id, sta->addr);
  6401. goto peer_delete;
  6402. }
  6403. /* above arsta will get memset, hence do this after assign
  6404. * link sta
  6405. */
  6406. if (sta->mlo) {
  6407. /* For station mode, arvif->is_sta_assoc_link has been set when
  6408. * vdev starts. Make sure the arvif/arsta pair have same setting
  6409. */
  6410. if (vif->type == NL80211_IFTYPE_STATION &&
  6411. !arsta->arvif->is_sta_assoc_link) {
  6412. ath12k_hw_warn(ah, "failed to verify assoc link setting with link id %u\n",
  6413. link_id);
  6414. ret = -EINVAL;
  6415. goto exit;
  6416. }
  6417. arsta->is_assoc_link = true;
  6418. ahsta->assoc_link_id = link_id;
  6419. }
  6420. }
  6421. /* In the ML station scenario, activate all partner links once the
  6422. * client is transitioning to the associated state.
  6423. *
  6424. * FIXME: Ideally, this activation should occur when the client
  6425. * transitions to the authorized state. However, there are some
  6426. * issues with handling this in the firmware. Until the firmware
  6427. * can manage it properly, activate the links when the client is
  6428. * about to move to the associated state.
  6429. */
  6430. if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION &&
  6431. old_state == IEEE80211_STA_AUTH && new_state == IEEE80211_STA_ASSOC) {
  6432. /* TODO: for now only do link selection for single device
  6433. * MLO case. Other cases would be handled in the future.
  6434. */
  6435. ab = ah->radio[0].ab;
  6436. if (ab->ag->num_devices == 1) {
  6437. ret = ath12k_mac_select_links(ab, vif, hw, &selected_links);
  6438. if (ret) {
  6439. ath12k_warn(ab,
  6440. "failed to get selected links: %d\n", ret);
  6441. goto exit;
  6442. }
  6443. } else {
  6444. selected_links = ieee80211_vif_usable_links(vif);
  6445. }
  6446. ieee80211_set_active_links(vif, selected_links);
  6447. }
  6448. /* Handle all the other state transitions in generic way */
  6449. valid_links = ahsta->links_map;
  6450. for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) {
  6451. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  6452. arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_id]);
  6453. /* some assumptions went wrong! */
  6454. if (WARN_ON(!arvif || !arsta))
  6455. continue;
  6456. /* vdev might be in deleted */
  6457. if (WARN_ON(!arvif->ar))
  6458. continue;
  6459. ret = ath12k_mac_handle_link_sta_state(hw, arvif, arsta,
  6460. old_state, new_state);
  6461. if (ret) {
  6462. ath12k_hw_warn(ah, "unable to move link sta %d of sta %pM from state %d to %d",
  6463. link_id, arsta->addr, old_state, new_state);
  6464. if (old_state == IEEE80211_STA_NOTEXIST &&
  6465. new_state == IEEE80211_STA_NONE)
  6466. goto peer_delete;
  6467. else
  6468. goto exit;
  6469. }
  6470. }
  6471. if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION &&
  6472. old_state == IEEE80211_STA_ASSOC && new_state == IEEE80211_STA_AUTHORIZED) {
  6473. for_each_ar(ah, ar, i) {
  6474. ab = ar->ab;
  6475. if (prev_ab == ab)
  6476. continue;
  6477. ret = ath12k_mac_mlo_sta_update_link_active(ab, hw, ahvif);
  6478. if (ret) {
  6479. ath12k_warn(ab,
  6480. "failed to update link active state on connect %d\n",
  6481. ret);
  6482. goto exit;
  6483. }
  6484. prev_ab = ab;
  6485. }
  6486. }
  6487. /* IEEE80211_STA_NONE -> IEEE80211_STA_NOTEXIST:
  6488. * Remove the station from driver (handle ML sta here since that
  6489. * needs special handling. Normal sta will be handled in generic
  6490. * handler below
  6491. */
  6492. if (old_state == IEEE80211_STA_NONE &&
  6493. new_state == IEEE80211_STA_NOTEXIST) {
  6494. if (sta->mlo)
  6495. ath12k_mac_ml_station_remove(ahvif, ahsta);
  6496. ath12k_dp_peer_delete(&ah->dp_hw, sta->addr, sta);
  6497. }
  6498. ret = 0;
  6499. goto exit;
  6500. peer_delete:
  6501. ath12k_dp_peer_delete(&ah->dp_hw, sta->addr, sta);
  6502. ml_peer_id_clear:
  6503. if (sta->mlo) {
  6504. clear_bit(ahsta->ml_peer_id, ah->free_ml_peer_id_map);
  6505. ahsta->ml_peer_id = ATH12K_MLO_PEER_ID_INVALID;
  6506. }
  6507. exit:
  6508. /* update the state if everything went well */
  6509. if (!ret)
  6510. ahsta->state = new_state;
  6511. return ret;
  6512. }
  6513. EXPORT_SYMBOL(ath12k_mac_op_sta_state);
  6514. int ath12k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw,
  6515. struct ieee80211_vif *vif,
  6516. struct ieee80211_sta *sta)
  6517. {
  6518. struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta);
  6519. struct ath12k *ar;
  6520. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  6521. struct ath12k_link_vif *arvif;
  6522. struct ath12k_link_sta *arsta;
  6523. u8 link_id;
  6524. int ret;
  6525. s16 txpwr;
  6526. lockdep_assert_wiphy(hw->wiphy);
  6527. /* TODO: use link id from mac80211 once that's implemented */
  6528. link_id = 0;
  6529. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  6530. arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_id]);
  6531. if (sta->deflink.txpwr.type == NL80211_TX_POWER_AUTOMATIC) {
  6532. txpwr = 0;
  6533. } else {
  6534. txpwr = sta->deflink.txpwr.power;
  6535. if (!txpwr) {
  6536. ret = -EINVAL;
  6537. goto out;
  6538. }
  6539. }
  6540. if (txpwr > ATH12K_TX_POWER_MAX_VAL || txpwr < ATH12K_TX_POWER_MIN_VAL) {
  6541. ret = -EINVAL;
  6542. goto out;
  6543. }
  6544. ar = arvif->ar;
  6545. ret = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id,
  6546. WMI_PEER_USE_FIXED_PWR, txpwr);
  6547. if (ret) {
  6548. ath12k_warn(ar->ab, "failed to set tx power for station ret: %d\n",
  6549. ret);
  6550. goto out;
  6551. }
  6552. out:
  6553. return ret;
  6554. }
  6555. EXPORT_SYMBOL(ath12k_mac_op_sta_set_txpwr);
  6556. void ath12k_mac_op_link_sta_rc_update(struct ieee80211_hw *hw,
  6557. struct ieee80211_vif *vif,
  6558. struct ieee80211_link_sta *link_sta,
  6559. u32 changed)
  6560. {
  6561. struct ieee80211_sta *sta = link_sta->sta;
  6562. struct ath12k *ar;
  6563. struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta);
  6564. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  6565. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  6566. struct ath12k_link_sta *arsta;
  6567. struct ath12k_link_vif *arvif;
  6568. struct ath12k_dp_link_peer *peer;
  6569. u32 bw, smps;
  6570. struct ath12k_dp *dp;
  6571. rcu_read_lock();
  6572. arvif = rcu_dereference(ahvif->link[link_sta->link_id]);
  6573. if (!arvif) {
  6574. ath12k_hw_warn(ah, "mac sta rc update failed to fetch link vif on link id %u for peer %pM\n",
  6575. link_sta->link_id, sta->addr);
  6576. rcu_read_unlock();
  6577. return;
  6578. }
  6579. ar = arvif->ar;
  6580. dp = ath12k_ab_to_dp(ar->ab);
  6581. arsta = rcu_dereference(ahsta->link[link_sta->link_id]);
  6582. if (!arsta) {
  6583. rcu_read_unlock();
  6584. ath12k_warn(ar->ab, "mac sta rc update failed to fetch link sta on link id %u for peer %pM\n",
  6585. link_sta->link_id, sta->addr);
  6586. return;
  6587. }
  6588. spin_lock_bh(&dp->dp_lock);
  6589. peer = ath12k_dp_link_peer_find_by_vdev_and_addr(dp, arvif->vdev_id,
  6590. arsta->addr);
  6591. if (!peer) {
  6592. spin_unlock_bh(&dp->dp_lock);
  6593. rcu_read_unlock();
  6594. ath12k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n",
  6595. arsta->addr, arvif->vdev_id);
  6596. return;
  6597. }
  6598. spin_unlock_bh(&dp->dp_lock);
  6599. if (arsta->link_id >= IEEE80211_MLD_MAX_NUM_LINKS) {
  6600. rcu_read_unlock();
  6601. return;
  6602. }
  6603. link_sta = rcu_dereference(sta->link[arsta->link_id]);
  6604. if (!link_sta) {
  6605. rcu_read_unlock();
  6606. ath12k_warn(ar->ab, "unable to access link sta in rc update for sta %pM link %u\n",
  6607. sta->addr, arsta->link_id);
  6608. return;
  6609. }
  6610. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  6611. "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
  6612. arsta->addr, changed, link_sta->bandwidth, link_sta->rx_nss,
  6613. link_sta->smps_mode);
  6614. spin_lock_bh(&ar->data_lock);
  6615. if (changed & IEEE80211_RC_BW_CHANGED) {
  6616. bw = ath12k_mac_ieee80211_sta_bw_to_wmi(ar, link_sta);
  6617. arsta->bw_prev = arsta->bw;
  6618. arsta->bw = bw;
  6619. }
  6620. if (changed & IEEE80211_RC_NSS_CHANGED)
  6621. arsta->nss = link_sta->rx_nss;
  6622. if (changed & IEEE80211_RC_SMPS_CHANGED) {
  6623. smps = WMI_PEER_SMPS_PS_NONE;
  6624. switch (link_sta->smps_mode) {
  6625. case IEEE80211_SMPS_AUTOMATIC:
  6626. case IEEE80211_SMPS_OFF:
  6627. smps = WMI_PEER_SMPS_PS_NONE;
  6628. break;
  6629. case IEEE80211_SMPS_STATIC:
  6630. smps = WMI_PEER_SMPS_STATIC;
  6631. break;
  6632. case IEEE80211_SMPS_DYNAMIC:
  6633. smps = WMI_PEER_SMPS_DYNAMIC;
  6634. break;
  6635. default:
  6636. ath12k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM link %u\n",
  6637. link_sta->smps_mode, arsta->addr, link_sta->link_id);
  6638. smps = WMI_PEER_SMPS_PS_NONE;
  6639. break;
  6640. }
  6641. arsta->smps = smps;
  6642. }
  6643. arsta->changed |= changed;
  6644. spin_unlock_bh(&ar->data_lock);
  6645. wiphy_work_queue(hw->wiphy, &arsta->update_wk);
  6646. rcu_read_unlock();
  6647. }
  6648. EXPORT_SYMBOL(ath12k_mac_op_link_sta_rc_update);
  6649. static struct ath12k_link_sta *ath12k_mac_alloc_assign_link_sta(struct ath12k_hw *ah,
  6650. struct ath12k_sta *ahsta,
  6651. struct ath12k_vif *ahvif,
  6652. u8 link_id)
  6653. {
  6654. struct ath12k_link_sta *arsta;
  6655. int ret;
  6656. lockdep_assert_wiphy(ah->hw->wiphy);
  6657. if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS)
  6658. return NULL;
  6659. arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]);
  6660. if (arsta)
  6661. return NULL;
  6662. arsta = kmalloc_obj(*arsta);
  6663. if (!arsta)
  6664. return NULL;
  6665. ret = ath12k_mac_assign_link_sta(ah, ahsta, arsta, ahvif, link_id);
  6666. if (ret) {
  6667. kfree(arsta);
  6668. return NULL;
  6669. }
  6670. return arsta;
  6671. }
  6672. int ath12k_mac_op_change_sta_links(struct ieee80211_hw *hw,
  6673. struct ieee80211_vif *vif,
  6674. struct ieee80211_sta *sta,
  6675. u16 old_links, u16 new_links)
  6676. {
  6677. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  6678. struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta);
  6679. struct ath12k_hw *ah = hw->priv;
  6680. struct ath12k_link_vif *arvif;
  6681. struct ath12k_link_sta *arsta;
  6682. unsigned long valid_links;
  6683. struct ath12k *ar;
  6684. u8 link_id;
  6685. int ret;
  6686. lockdep_assert_wiphy(hw->wiphy);
  6687. if (!sta->valid_links)
  6688. return -EINVAL;
  6689. /* Firmware does not support removal of one of link stas. All sta
  6690. * would be removed during ML STA delete in sta_state(), hence link
  6691. * sta removal is not handled here.
  6692. */
  6693. if (new_links < old_links)
  6694. return 0;
  6695. if (ahsta->ml_peer_id == ATH12K_MLO_PEER_ID_INVALID) {
  6696. ath12k_hw_warn(ah, "unable to add link for ml sta %pM", sta->addr);
  6697. return -EINVAL;
  6698. }
  6699. /* this op is expected only after initial sta insertion with default link */
  6700. if (WARN_ON(ahsta->links_map == 0))
  6701. return -EINVAL;
  6702. valid_links = new_links;
  6703. for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) {
  6704. if (ahsta->links_map & BIT(link_id))
  6705. continue;
  6706. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  6707. arsta = ath12k_mac_alloc_assign_link_sta(ah, ahsta, ahvif, link_id);
  6708. if (!arvif || !arsta) {
  6709. ath12k_hw_warn(ah, "Failed to alloc/assign link sta");
  6710. continue;
  6711. }
  6712. ar = arvif->ar;
  6713. if (!ar)
  6714. continue;
  6715. ret = ath12k_mac_station_add(ar, arvif, arsta);
  6716. if (ret) {
  6717. ath12k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n",
  6718. arsta->addr, arvif->vdev_id);
  6719. ath12k_mac_free_unassign_link_sta(ah, ahsta, link_id);
  6720. return ret;
  6721. }
  6722. }
  6723. return 0;
  6724. }
  6725. EXPORT_SYMBOL(ath12k_mac_op_change_sta_links);
  6726. bool ath12k_mac_op_can_activate_links(struct ieee80211_hw *hw,
  6727. struct ieee80211_vif *vif,
  6728. u16 active_links)
  6729. {
  6730. /* TODO: Handle recovery case */
  6731. return true;
  6732. }
  6733. EXPORT_SYMBOL(ath12k_mac_op_can_activate_links);
  6734. static int ath12k_conf_tx_uapsd(struct ath12k_link_vif *arvif,
  6735. u16 ac, bool enable)
  6736. {
  6737. struct ath12k *ar = arvif->ar;
  6738. struct ath12k_vif *ahvif = arvif->ahvif;
  6739. u32 value;
  6740. int ret;
  6741. if (ahvif->vdev_type != WMI_VDEV_TYPE_STA)
  6742. return 0;
  6743. switch (ac) {
  6744. case IEEE80211_AC_VO:
  6745. value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
  6746. WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
  6747. break;
  6748. case IEEE80211_AC_VI:
  6749. value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
  6750. WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
  6751. break;
  6752. case IEEE80211_AC_BE:
  6753. value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
  6754. WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
  6755. break;
  6756. case IEEE80211_AC_BK:
  6757. value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
  6758. WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
  6759. break;
  6760. }
  6761. if (enable)
  6762. ahvif->u.sta.uapsd |= value;
  6763. else
  6764. ahvif->u.sta.uapsd &= ~value;
  6765. ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  6766. WMI_STA_PS_PARAM_UAPSD,
  6767. ahvif->u.sta.uapsd);
  6768. if (ret) {
  6769. ath12k_warn(ar->ab, "could not set uapsd params %d\n", ret);
  6770. goto exit;
  6771. }
  6772. if (ahvif->u.sta.uapsd)
  6773. value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
  6774. else
  6775. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  6776. ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  6777. WMI_STA_PS_PARAM_RX_WAKE_POLICY,
  6778. value);
  6779. if (ret)
  6780. ath12k_warn(ar->ab, "could not set rx wake param %d\n", ret);
  6781. exit:
  6782. return ret;
  6783. }
  6784. static int ath12k_mac_conf_tx(struct ath12k_link_vif *arvif, u16 ac,
  6785. const struct ieee80211_tx_queue_params *params)
  6786. {
  6787. struct wmi_wmm_params_arg *p = NULL;
  6788. struct ath12k *ar = arvif->ar;
  6789. struct ath12k_base *ab = ar->ab;
  6790. int ret;
  6791. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  6792. switch (ac) {
  6793. case IEEE80211_AC_VO:
  6794. p = &arvif->wmm_params.ac_vo;
  6795. break;
  6796. case IEEE80211_AC_VI:
  6797. p = &arvif->wmm_params.ac_vi;
  6798. break;
  6799. case IEEE80211_AC_BE:
  6800. p = &arvif->wmm_params.ac_be;
  6801. break;
  6802. case IEEE80211_AC_BK:
  6803. p = &arvif->wmm_params.ac_bk;
  6804. break;
  6805. }
  6806. if (WARN_ON(!p)) {
  6807. ret = -EINVAL;
  6808. goto exit;
  6809. }
  6810. p->cwmin = params->cw_min;
  6811. p->cwmax = params->cw_max;
  6812. p->aifs = params->aifs;
  6813. p->txop = params->txop;
  6814. ret = ath12k_wmi_send_wmm_update_cmd(ar, arvif->vdev_id,
  6815. &arvif->wmm_params);
  6816. if (ret) {
  6817. ath12k_warn(ab, "pdev idx %d failed to set wmm params: %d\n",
  6818. ar->pdev_idx, ret);
  6819. goto exit;
  6820. }
  6821. ret = ath12k_conf_tx_uapsd(arvif, ac, params->uapsd);
  6822. if (ret)
  6823. ath12k_warn(ab, "pdev idx %d failed to set sta uapsd: %d\n",
  6824. ar->pdev_idx, ret);
  6825. exit:
  6826. return ret;
  6827. }
  6828. int ath12k_mac_op_conf_tx(struct ieee80211_hw *hw,
  6829. struct ieee80211_vif *vif,
  6830. unsigned int link_id, u16 ac,
  6831. const struct ieee80211_tx_queue_params *params)
  6832. {
  6833. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  6834. struct ath12k_link_vif *arvif;
  6835. struct ath12k_vif_cache *cache;
  6836. int ret;
  6837. lockdep_assert_wiphy(hw->wiphy);
  6838. if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS)
  6839. return -EINVAL;
  6840. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  6841. if (!arvif || !arvif->is_created) {
  6842. cache = ath12k_ahvif_get_link_cache(ahvif, link_id);
  6843. if (!cache)
  6844. return -ENOSPC;
  6845. cache->tx_conf.changed = true;
  6846. cache->tx_conf.ac = ac;
  6847. cache->tx_conf.tx_queue_params = *params;
  6848. return 0;
  6849. }
  6850. ret = ath12k_mac_conf_tx(arvif, ac, params);
  6851. return ret;
  6852. }
  6853. EXPORT_SYMBOL(ath12k_mac_op_conf_tx);
  6854. static struct ieee80211_sta_ht_cap
  6855. ath12k_create_ht_cap(struct ath12k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask)
  6856. {
  6857. int i;
  6858. struct ieee80211_sta_ht_cap ht_cap = {};
  6859. u32 ar_vht_cap = ar->pdev->cap.vht_cap;
  6860. if (!(ar_ht_cap & WMI_HT_CAP_ENABLED))
  6861. return ht_cap;
  6862. ht_cap.ht_supported = 1;
  6863. ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  6864. ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  6865. ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  6866. ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
  6867. ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
  6868. if (ar_ht_cap & WMI_HT_CAP_HT20_SGI)
  6869. ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  6870. if (ar_ht_cap & WMI_HT_CAP_HT40_SGI)
  6871. ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  6872. if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) {
  6873. u32 smps;
  6874. smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
  6875. smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
  6876. ht_cap.cap |= smps;
  6877. }
  6878. if (ar_ht_cap & WMI_HT_CAP_TX_STBC)
  6879. ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  6880. if (ar_ht_cap & WMI_HT_CAP_RX_STBC) {
  6881. u32 stbc;
  6882. stbc = ar_ht_cap;
  6883. stbc &= WMI_HT_CAP_RX_STBC;
  6884. stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
  6885. stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
  6886. stbc &= IEEE80211_HT_CAP_RX_STBC;
  6887. ht_cap.cap |= stbc;
  6888. }
  6889. if (ar_ht_cap & WMI_HT_CAP_RX_LDPC)
  6890. ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
  6891. if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT)
  6892. ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
  6893. if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
  6894. ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  6895. for (i = 0; i < ar->num_rx_chains; i++) {
  6896. if (rate_cap_rx_chainmask & BIT(i))
  6897. ht_cap.mcs.rx_mask[i] = 0xFF;
  6898. }
  6899. ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  6900. return ht_cap;
  6901. }
  6902. static int ath12k_mac_set_txbf_conf(struct ath12k_link_vif *arvif)
  6903. {
  6904. u32 value = 0;
  6905. struct ath12k *ar = arvif->ar;
  6906. struct ath12k_vif *ahvif = arvif->ahvif;
  6907. int nsts;
  6908. int sound_dim;
  6909. u32 vht_cap = ar->pdev->cap.vht_cap;
  6910. u32 vdev_param = WMI_VDEV_PARAM_TXBF;
  6911. if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) {
  6912. nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
  6913. nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
  6914. value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
  6915. }
  6916. if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) {
  6917. sound_dim = vht_cap &
  6918. IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
  6919. sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
  6920. if (sound_dim > (ar->num_tx_chains - 1))
  6921. sound_dim = ar->num_tx_chains - 1;
  6922. value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
  6923. }
  6924. if (!value)
  6925. return 0;
  6926. if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) {
  6927. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
  6928. if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) &&
  6929. ahvif->vdev_type == WMI_VDEV_TYPE_AP)
  6930. value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
  6931. }
  6932. if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) {
  6933. value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
  6934. if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) &&
  6935. ahvif->vdev_type == WMI_VDEV_TYPE_STA)
  6936. value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
  6937. }
  6938. return ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  6939. vdev_param, value);
  6940. }
  6941. static void ath12k_set_vht_txbf_cap(struct ath12k *ar, u32 *vht_cap)
  6942. {
  6943. bool subfer, subfee;
  6944. int sound_dim = 0;
  6945. subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE));
  6946. subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE));
  6947. if (ar->num_tx_chains < 2) {
  6948. *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
  6949. subfer = false;
  6950. }
  6951. /* If SU Beaformer is not set, then disable MU Beamformer Capability */
  6952. if (!subfer)
  6953. *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
  6954. /* If SU Beaformee is not set, then disable MU Beamformee Capability */
  6955. if (!subfee)
  6956. *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
  6957. sound_dim = u32_get_bits(*vht_cap,
  6958. IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
  6959. *vht_cap = u32_replace_bits(*vht_cap, 0,
  6960. IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
  6961. /* TODO: Need to check invalid STS and Sound_dim values set by FW? */
  6962. /* Enable Sounding Dimension Field only if SU BF is enabled */
  6963. if (subfer) {
  6964. if (sound_dim > (ar->num_tx_chains - 1))
  6965. sound_dim = ar->num_tx_chains - 1;
  6966. *vht_cap = u32_replace_bits(*vht_cap, sound_dim,
  6967. IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
  6968. }
  6969. /* Use the STS advertised by FW unless SU Beamformee is not supported*/
  6970. if (!subfee)
  6971. *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
  6972. }
  6973. static struct ieee80211_sta_vht_cap
  6974. ath12k_create_vht_cap(struct ath12k *ar, u32 rate_cap_tx_chainmask,
  6975. u32 rate_cap_rx_chainmask)
  6976. {
  6977. struct ieee80211_sta_vht_cap vht_cap = {};
  6978. u16 txmcs_map, rxmcs_map;
  6979. int i;
  6980. vht_cap.vht_supported = 1;
  6981. vht_cap.cap = ar->pdev->cap.vht_cap;
  6982. ath12k_set_vht_txbf_cap(ar, &vht_cap.cap);
  6983. /* 80P80 is not supported */
  6984. vht_cap.cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  6985. rxmcs_map = 0;
  6986. txmcs_map = 0;
  6987. for (i = 0; i < 8; i++) {
  6988. if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i))
  6989. txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
  6990. else
  6991. txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
  6992. if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i))
  6993. rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
  6994. else
  6995. rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
  6996. }
  6997. if (rate_cap_tx_chainmask <= 1)
  6998. vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
  6999. vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map);
  7000. vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map);
  7001. /* Check if the HW supports 1:1 NSS ratio and reset
  7002. * EXT NSS BW Support field to 0 to indicate 1:1 ratio
  7003. */
  7004. if (ar->pdev->cap.nss_ratio_info == WMI_NSS_RATIO_1_NSS)
  7005. vht_cap.cap &= ~IEEE80211_VHT_CAP_EXT_NSS_BW_MASK;
  7006. return vht_cap;
  7007. }
  7008. static void ath12k_mac_setup_ht_vht_cap(struct ath12k *ar,
  7009. struct ath12k_pdev_cap *cap,
  7010. u32 *ht_cap_info)
  7011. {
  7012. struct ieee80211_supported_band *band;
  7013. u32 rate_cap_tx_chainmask;
  7014. u32 rate_cap_rx_chainmask;
  7015. u32 ht_cap;
  7016. rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift;
  7017. rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift;
  7018. if (cap->supported_bands & WMI_HOST_WLAN_2GHZ_CAP) {
  7019. band = &ar->mac.sbands[NL80211_BAND_2GHZ];
  7020. ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info;
  7021. if (ht_cap_info)
  7022. *ht_cap_info = ht_cap;
  7023. band->ht_cap = ath12k_create_ht_cap(ar, ht_cap,
  7024. rate_cap_rx_chainmask);
  7025. }
  7026. if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP &&
  7027. (ar->ab->hw_params->single_pdev_only ||
  7028. !ar->supports_6ghz)) {
  7029. band = &ar->mac.sbands[NL80211_BAND_5GHZ];
  7030. ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info;
  7031. if (ht_cap_info)
  7032. *ht_cap_info = ht_cap;
  7033. band->ht_cap = ath12k_create_ht_cap(ar, ht_cap,
  7034. rate_cap_rx_chainmask);
  7035. band->vht_cap = ath12k_create_vht_cap(ar, rate_cap_tx_chainmask,
  7036. rate_cap_rx_chainmask);
  7037. }
  7038. }
  7039. static int ath12k_check_chain_mask(struct ath12k *ar, u32 ant, bool is_tx_ant)
  7040. {
  7041. /* TODO: Check the request chainmask against the supported
  7042. * chainmask table which is advertised in extented_service_ready event
  7043. */
  7044. return 0;
  7045. }
  7046. static void ath12k_gen_ppe_thresh(struct ath12k_wmi_ppe_threshold_arg *fw_ppet,
  7047. u8 *he_ppet)
  7048. {
  7049. int nss, ru;
  7050. u8 bit = 7;
  7051. he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK;
  7052. he_ppet[0] |= (fw_ppet->ru_bit_mask <<
  7053. IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) &
  7054. IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK;
  7055. for (nss = 0; nss <= fw_ppet->numss_m1; nss++) {
  7056. for (ru = 0; ru < 4; ru++) {
  7057. u8 val;
  7058. int i;
  7059. if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0)
  7060. continue;
  7061. val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) &
  7062. 0x3f;
  7063. val = ((val >> 3) & 0x7) | ((val & 0x7) << 3);
  7064. for (i = 5; i >= 0; i--) {
  7065. he_ppet[bit / 8] |=
  7066. ((val >> i) & 0x1) << ((bit % 8));
  7067. bit++;
  7068. }
  7069. }
  7070. }
  7071. }
  7072. static void
  7073. ath12k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem)
  7074. {
  7075. u8 m;
  7076. m = IEEE80211_HE_MAC_CAP0_TWT_RES |
  7077. IEEE80211_HE_MAC_CAP0_TWT_REQ;
  7078. he_cap_elem->mac_cap_info[0] &= ~m;
  7079. m = IEEE80211_HE_MAC_CAP2_TRS |
  7080. IEEE80211_HE_MAC_CAP2_BCAST_TWT |
  7081. IEEE80211_HE_MAC_CAP2_MU_CASCADING;
  7082. he_cap_elem->mac_cap_info[2] &= ~m;
  7083. m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED |
  7084. IEEE80211_HE_MAC_CAP2_BCAST_TWT |
  7085. IEEE80211_HE_MAC_CAP2_MU_CASCADING;
  7086. he_cap_elem->mac_cap_info[3] &= ~m;
  7087. m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG |
  7088. IEEE80211_HE_MAC_CAP4_BQR;
  7089. he_cap_elem->mac_cap_info[4] &= ~m;
  7090. m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECTIVE_TRANSMISSION |
  7091. IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU |
  7092. IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING |
  7093. IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX;
  7094. he_cap_elem->mac_cap_info[5] &= ~m;
  7095. m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
  7096. IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
  7097. he_cap_elem->phy_cap_info[2] &= ~m;
  7098. m = IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU |
  7099. IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK |
  7100. IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK;
  7101. he_cap_elem->phy_cap_info[3] &= ~m;
  7102. m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
  7103. he_cap_elem->phy_cap_info[4] &= ~m;
  7104. m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
  7105. he_cap_elem->phy_cap_info[5] &= ~m;
  7106. m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
  7107. IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB |
  7108. IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
  7109. IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
  7110. he_cap_elem->phy_cap_info[6] &= ~m;
  7111. m = IEEE80211_HE_PHY_CAP7_PSR_BASED_SR |
  7112. IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP |
  7113. IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ |
  7114. IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ;
  7115. he_cap_elem->phy_cap_info[7] &= ~m;
  7116. m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
  7117. IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
  7118. IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
  7119. IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU;
  7120. he_cap_elem->phy_cap_info[8] &= ~m;
  7121. m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
  7122. IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
  7123. IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
  7124. IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
  7125. IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
  7126. IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
  7127. he_cap_elem->phy_cap_info[9] &= ~m;
  7128. }
  7129. static __le16 ath12k_mac_setup_he_6ghz_cap(struct ath12k_pdev_cap *pcap,
  7130. struct ath12k_band_cap *bcap)
  7131. {
  7132. u8 val;
  7133. bcap->he_6ghz_capa = IEEE80211_HT_MPDU_DENSITY_NONE;
  7134. if (bcap->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
  7135. bcap->he_6ghz_capa |=
  7136. u32_encode_bits(WLAN_HT_CAP_SM_PS_DYNAMIC,
  7137. IEEE80211_HE_6GHZ_CAP_SM_PS);
  7138. else
  7139. bcap->he_6ghz_capa |=
  7140. u32_encode_bits(WLAN_HT_CAP_SM_PS_DISABLED,
  7141. IEEE80211_HE_6GHZ_CAP_SM_PS);
  7142. val = u32_get_bits(pcap->vht_cap,
  7143. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
  7144. bcap->he_6ghz_capa |=
  7145. u32_encode_bits(val, IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP);
  7146. val = u32_get_bits(pcap->vht_cap,
  7147. IEEE80211_VHT_CAP_MAX_MPDU_MASK);
  7148. bcap->he_6ghz_capa |=
  7149. u32_encode_bits(val, IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN);
  7150. if (pcap->vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN)
  7151. bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
  7152. if (pcap->vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN)
  7153. bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS;
  7154. return cpu_to_le16(bcap->he_6ghz_capa);
  7155. }
  7156. static void ath12k_mac_set_hemcsmap(struct ath12k *ar,
  7157. struct ath12k_pdev_cap *cap,
  7158. struct ieee80211_sta_he_cap *he_cap)
  7159. {
  7160. struct ieee80211_he_mcs_nss_supp *mcs_nss = &he_cap->he_mcs_nss_supp;
  7161. u8 maxtxnss_160 = ath12k_get_nss_160mhz(ar, ar->num_tx_chains);
  7162. u8 maxrxnss_160 = ath12k_get_nss_160mhz(ar, ar->num_rx_chains);
  7163. u16 txmcs_map_160 = 0, rxmcs_map_160 = 0;
  7164. u16 txmcs_map = 0, rxmcs_map = 0;
  7165. u32 i;
  7166. for (i = 0; i < 8; i++) {
  7167. if (i < ar->num_tx_chains &&
  7168. (ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift) & BIT(i))
  7169. txmcs_map |= IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2);
  7170. else
  7171. txmcs_map |= IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2);
  7172. if (i < ar->num_rx_chains &&
  7173. (ar->cfg_rx_chainmask >> cap->tx_chain_mask_shift) & BIT(i))
  7174. rxmcs_map |= IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2);
  7175. else
  7176. rxmcs_map |= IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2);
  7177. if (i < maxtxnss_160 &&
  7178. (ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift) & BIT(i))
  7179. txmcs_map_160 |= IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2);
  7180. else
  7181. txmcs_map_160 |= IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2);
  7182. if (i < maxrxnss_160 &&
  7183. (ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift) & BIT(i))
  7184. rxmcs_map_160 |= IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2);
  7185. else
  7186. rxmcs_map_160 |= IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2);
  7187. }
  7188. mcs_nss->rx_mcs_80 = cpu_to_le16(rxmcs_map & 0xffff);
  7189. mcs_nss->tx_mcs_80 = cpu_to_le16(txmcs_map & 0xffff);
  7190. mcs_nss->rx_mcs_160 = cpu_to_le16(rxmcs_map_160 & 0xffff);
  7191. mcs_nss->tx_mcs_160 = cpu_to_le16(txmcs_map_160 & 0xffff);
  7192. }
  7193. static void ath12k_mac_copy_he_cap(struct ath12k *ar,
  7194. struct ath12k_band_cap *band_cap,
  7195. int iftype, u8 num_tx_chains,
  7196. struct ieee80211_sta_he_cap *he_cap)
  7197. {
  7198. struct ieee80211_he_cap_elem *he_cap_elem = &he_cap->he_cap_elem;
  7199. he_cap->has_he = true;
  7200. memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info,
  7201. sizeof(he_cap_elem->mac_cap_info));
  7202. memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info,
  7203. sizeof(he_cap_elem->phy_cap_info));
  7204. he_cap_elem->mac_cap_info[1] &=
  7205. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK;
  7206. he_cap_elem->phy_cap_info[0] &=
  7207. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G |
  7208. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  7209. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
  7210. /* 80PLUS80 is not supported */
  7211. he_cap_elem->phy_cap_info[0] &=
  7212. ~IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G;
  7213. he_cap_elem->phy_cap_info[5] &=
  7214. ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK;
  7215. he_cap_elem->phy_cap_info[5] |= num_tx_chains - 1;
  7216. switch (iftype) {
  7217. case NL80211_IFTYPE_AP:
  7218. he_cap_elem->mac_cap_info[2] &=
  7219. ~IEEE80211_HE_MAC_CAP2_BCAST_TWT;
  7220. he_cap_elem->phy_cap_info[3] &=
  7221. ~IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK;
  7222. he_cap_elem->phy_cap_info[9] |=
  7223. IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
  7224. break;
  7225. case NL80211_IFTYPE_STATION:
  7226. he_cap_elem->mac_cap_info[0] &= ~IEEE80211_HE_MAC_CAP0_TWT_RES;
  7227. he_cap_elem->mac_cap_info[0] |= IEEE80211_HE_MAC_CAP0_TWT_REQ;
  7228. he_cap_elem->phy_cap_info[9] |=
  7229. IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU;
  7230. break;
  7231. case NL80211_IFTYPE_MESH_POINT:
  7232. ath12k_mac_filter_he_cap_mesh(he_cap_elem);
  7233. break;
  7234. }
  7235. ath12k_mac_set_hemcsmap(ar, &ar->pdev->cap, he_cap);
  7236. memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
  7237. if (he_cap_elem->phy_cap_info[6] &
  7238. IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
  7239. ath12k_gen_ppe_thresh(&band_cap->he_ppet, he_cap->ppe_thres);
  7240. }
  7241. static void
  7242. ath12k_mac_copy_eht_mcs_nss(struct ath12k_band_cap *band_cap,
  7243. struct ieee80211_eht_mcs_nss_supp *mcs_nss,
  7244. const struct ieee80211_he_cap_elem *he_cap,
  7245. const struct ieee80211_eht_cap_elem_fixed *eht_cap)
  7246. {
  7247. if ((he_cap->phy_cap_info[0] &
  7248. (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G |
  7249. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  7250. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
  7251. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)) == 0)
  7252. memcpy(&mcs_nss->only_20mhz, &band_cap->eht_mcs_20_only,
  7253. sizeof(struct ieee80211_eht_mcs_nss_supp_20mhz_only));
  7254. if (he_cap->phy_cap_info[0] &
  7255. (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G |
  7256. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G))
  7257. memcpy(&mcs_nss->bw._80, &band_cap->eht_mcs_80,
  7258. sizeof(struct ieee80211_eht_mcs_nss_supp_bw));
  7259. if (he_cap->phy_cap_info[0] &
  7260. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
  7261. memcpy(&mcs_nss->bw._160, &band_cap->eht_mcs_160,
  7262. sizeof(struct ieee80211_eht_mcs_nss_supp_bw));
  7263. if (eht_cap->phy_cap_info[0] & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ)
  7264. memcpy(&mcs_nss->bw._320, &band_cap->eht_mcs_320,
  7265. sizeof(struct ieee80211_eht_mcs_nss_supp_bw));
  7266. }
  7267. static void ath12k_mac_copy_eht_ppe_thresh(struct ath12k_wmi_ppe_threshold_arg *fw_ppet,
  7268. struct ieee80211_sta_eht_cap *cap)
  7269. {
  7270. u16 bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE;
  7271. u8 i, nss, ru, ppet_bit_len_per_ru = IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE * 2;
  7272. u8p_replace_bits(&cap->eht_ppe_thres[0], fw_ppet->numss_m1,
  7273. IEEE80211_EHT_PPE_THRES_NSS_MASK);
  7274. u16p_replace_bits((u16 *)&cap->eht_ppe_thres[0], fw_ppet->ru_bit_mask,
  7275. IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK);
  7276. for (nss = 0; nss <= fw_ppet->numss_m1; nss++) {
  7277. for (ru = 0;
  7278. ru < hweight16(IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK);
  7279. ru++) {
  7280. u32 val = 0;
  7281. if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0)
  7282. continue;
  7283. u32p_replace_bits(&val, fw_ppet->ppet16_ppet8_ru3_ru0[nss] >>
  7284. (ru * ppet_bit_len_per_ru),
  7285. GENMASK(ppet_bit_len_per_ru - 1, 0));
  7286. for (i = 0; i < ppet_bit_len_per_ru; i++) {
  7287. cap->eht_ppe_thres[bit / 8] |=
  7288. (((val >> i) & 0x1) << ((bit % 8)));
  7289. bit++;
  7290. }
  7291. }
  7292. }
  7293. }
  7294. static void
  7295. ath12k_mac_filter_eht_cap_mesh(struct ieee80211_eht_cap_elem_fixed
  7296. *eht_cap_elem)
  7297. {
  7298. u8 m;
  7299. m = IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS;
  7300. eht_cap_elem->mac_cap_info[0] &= ~m;
  7301. m = IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO;
  7302. eht_cap_elem->phy_cap_info[0] &= ~m;
  7303. m = IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
  7304. IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
  7305. IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
  7306. IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK;
  7307. eht_cap_elem->phy_cap_info[3] &= ~m;
  7308. m = IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
  7309. IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
  7310. IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
  7311. IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI;
  7312. eht_cap_elem->phy_cap_info[4] &= ~m;
  7313. m = IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
  7314. IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
  7315. IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
  7316. IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK;
  7317. eht_cap_elem->phy_cap_info[5] &= ~m;
  7318. m = IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK;
  7319. eht_cap_elem->phy_cap_info[6] &= ~m;
  7320. m = IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
  7321. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
  7322. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ |
  7323. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
  7324. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
  7325. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ;
  7326. eht_cap_elem->phy_cap_info[7] &= ~m;
  7327. }
  7328. static void ath12k_mac_copy_eht_cap(struct ath12k *ar,
  7329. struct ath12k_band_cap *band_cap,
  7330. struct ieee80211_he_cap_elem *he_cap_elem,
  7331. int iftype,
  7332. struct ieee80211_sta_eht_cap *eht_cap)
  7333. {
  7334. struct ieee80211_eht_cap_elem_fixed *eht_cap_elem = &eht_cap->eht_cap_elem;
  7335. memset(eht_cap, 0, sizeof(struct ieee80211_sta_eht_cap));
  7336. if (!(test_bit(WMI_TLV_SERVICE_11BE, ar->ab->wmi_ab.svc_map)) ||
  7337. ath12k_acpi_get_disable_11be(ar->ab))
  7338. return;
  7339. eht_cap->has_eht = true;
  7340. memcpy(eht_cap_elem->mac_cap_info, band_cap->eht_cap_mac_info,
  7341. sizeof(eht_cap_elem->mac_cap_info));
  7342. memcpy(eht_cap_elem->phy_cap_info, band_cap->eht_cap_phy_info,
  7343. sizeof(eht_cap_elem->phy_cap_info));
  7344. switch (iftype) {
  7345. case NL80211_IFTYPE_AP:
  7346. eht_cap_elem->phy_cap_info[0] &=
  7347. ~IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ;
  7348. eht_cap_elem->phy_cap_info[4] &=
  7349. ~IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO;
  7350. eht_cap_elem->phy_cap_info[5] &=
  7351. ~IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP;
  7352. break;
  7353. case NL80211_IFTYPE_STATION:
  7354. eht_cap_elem->phy_cap_info[7] &=
  7355. ~(IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
  7356. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
  7357. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ);
  7358. eht_cap_elem->phy_cap_info[7] &=
  7359. ~(IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
  7360. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
  7361. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ);
  7362. break;
  7363. case NL80211_IFTYPE_MESH_POINT:
  7364. ath12k_mac_filter_eht_cap_mesh(eht_cap_elem);
  7365. break;
  7366. default:
  7367. break;
  7368. }
  7369. ath12k_mac_copy_eht_mcs_nss(band_cap, &eht_cap->eht_mcs_nss_supp,
  7370. he_cap_elem, eht_cap_elem);
  7371. if (eht_cap_elem->phy_cap_info[5] &
  7372. IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT)
  7373. ath12k_mac_copy_eht_ppe_thresh(&band_cap->eht_ppet, eht_cap);
  7374. }
  7375. static int ath12k_mac_copy_sband_iftype_data(struct ath12k *ar,
  7376. struct ath12k_pdev_cap *cap,
  7377. struct ieee80211_sband_iftype_data *data,
  7378. int band)
  7379. {
  7380. struct ath12k_band_cap *band_cap = &cap->band[band];
  7381. int i, idx = 0;
  7382. for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
  7383. struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap;
  7384. switch (i) {
  7385. case NL80211_IFTYPE_STATION:
  7386. case NL80211_IFTYPE_AP:
  7387. case NL80211_IFTYPE_MESH_POINT:
  7388. break;
  7389. default:
  7390. continue;
  7391. }
  7392. data[idx].types_mask = BIT(i);
  7393. ath12k_mac_copy_he_cap(ar, band_cap, i, ar->num_tx_chains, he_cap);
  7394. if (band == NL80211_BAND_6GHZ) {
  7395. data[idx].he_6ghz_capa.capa =
  7396. ath12k_mac_setup_he_6ghz_cap(cap, band_cap);
  7397. }
  7398. ath12k_mac_copy_eht_cap(ar, band_cap, &he_cap->he_cap_elem, i,
  7399. &data[idx].eht_cap);
  7400. idx++;
  7401. }
  7402. return idx;
  7403. }
  7404. static void ath12k_mac_setup_sband_iftype_data(struct ath12k *ar,
  7405. struct ath12k_pdev_cap *cap)
  7406. {
  7407. struct ieee80211_supported_band *sband;
  7408. enum nl80211_band band;
  7409. int count;
  7410. if (cap->supported_bands & WMI_HOST_WLAN_2GHZ_CAP) {
  7411. band = NL80211_BAND_2GHZ;
  7412. count = ath12k_mac_copy_sband_iftype_data(ar, cap,
  7413. ar->mac.iftype[band],
  7414. band);
  7415. sband = &ar->mac.sbands[band];
  7416. _ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band],
  7417. count);
  7418. }
  7419. if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP) {
  7420. band = NL80211_BAND_5GHZ;
  7421. count = ath12k_mac_copy_sband_iftype_data(ar, cap,
  7422. ar->mac.iftype[band],
  7423. band);
  7424. sband = &ar->mac.sbands[band];
  7425. _ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band],
  7426. count);
  7427. }
  7428. if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP &&
  7429. ar->supports_6ghz) {
  7430. band = NL80211_BAND_6GHZ;
  7431. count = ath12k_mac_copy_sband_iftype_data(ar, cap,
  7432. ar->mac.iftype[band],
  7433. band);
  7434. sband = &ar->mac.sbands[band];
  7435. _ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band],
  7436. count);
  7437. }
  7438. }
  7439. static int __ath12k_set_antenna(struct ath12k *ar, u32 tx_ant, u32 rx_ant)
  7440. {
  7441. struct ath12k_hw *ah = ath12k_ar_to_ah(ar);
  7442. int ret;
  7443. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  7444. if (ath12k_check_chain_mask(ar, tx_ant, true))
  7445. return -EINVAL;
  7446. if (ath12k_check_chain_mask(ar, rx_ant, false))
  7447. return -EINVAL;
  7448. /* Since we advertised the max cap of all radios combined during wiphy
  7449. * registration, ensure we don't set the antenna config higher than the
  7450. * limits
  7451. */
  7452. tx_ant = min_t(u32, tx_ant, ar->pdev->cap.tx_chain_mask);
  7453. rx_ant = min_t(u32, rx_ant, ar->pdev->cap.rx_chain_mask);
  7454. ar->cfg_tx_chainmask = tx_ant;
  7455. ar->cfg_rx_chainmask = rx_ant;
  7456. if (ah->state != ATH12K_HW_STATE_ON &&
  7457. ah->state != ATH12K_HW_STATE_RESTARTED)
  7458. return 0;
  7459. ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK,
  7460. tx_ant, ar->pdev->pdev_id);
  7461. if (ret) {
  7462. ath12k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n",
  7463. ret, tx_ant);
  7464. return ret;
  7465. }
  7466. ar->num_tx_chains = hweight32(tx_ant);
  7467. ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK,
  7468. rx_ant, ar->pdev->pdev_id);
  7469. if (ret) {
  7470. ath12k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n",
  7471. ret, rx_ant);
  7472. return ret;
  7473. }
  7474. ar->num_rx_chains = hweight32(rx_ant);
  7475. /* Reload HT/VHT/HE capability */
  7476. ath12k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL);
  7477. ath12k_mac_setup_sband_iftype_data(ar, &ar->pdev->cap);
  7478. return 0;
  7479. }
  7480. static void ath12k_mgmt_over_wmi_tx_drop(struct ath12k *ar, struct sk_buff *skb)
  7481. {
  7482. int num_mgmt;
  7483. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  7484. ieee80211_free_txskb(ath12k_ar_to_hw(ar), skb);
  7485. num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx);
  7486. if (num_mgmt < 0)
  7487. WARN_ON_ONCE(1);
  7488. if (!num_mgmt)
  7489. wake_up(&ar->txmgmt_empty_waitq);
  7490. }
  7491. static void ath12k_mac_tx_mgmt_free(struct ath12k *ar, int buf_id)
  7492. {
  7493. struct sk_buff *msdu;
  7494. struct ieee80211_tx_info *info;
  7495. spin_lock_bh(&ar->txmgmt_idr_lock);
  7496. msdu = idr_remove(&ar->txmgmt_idr, buf_id);
  7497. spin_unlock_bh(&ar->txmgmt_idr_lock);
  7498. if (!msdu)
  7499. return;
  7500. dma_unmap_single(ar->ab->dev, ATH12K_SKB_CB(msdu)->paddr, msdu->len,
  7501. DMA_TO_DEVICE);
  7502. info = IEEE80211_SKB_CB(msdu);
  7503. memset(&info->status, 0, sizeof(info->status));
  7504. ath12k_mgmt_over_wmi_tx_drop(ar, msdu);
  7505. }
  7506. int ath12k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx)
  7507. {
  7508. struct ath12k *ar = ctx;
  7509. ath12k_mac_tx_mgmt_free(ar, buf_id);
  7510. return 0;
  7511. }
  7512. static int ath12k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx)
  7513. {
  7514. struct ieee80211_vif *vif = ctx;
  7515. struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb);
  7516. struct ath12k *ar = skb_cb->ar;
  7517. if (skb_cb->vif == vif)
  7518. ath12k_mac_tx_mgmt_free(ar, buf_id);
  7519. return 0;
  7520. }
  7521. static int ath12k_mac_mgmt_tx_wmi(struct ath12k *ar, struct ath12k_link_vif *arvif,
  7522. struct sk_buff *skb)
  7523. {
  7524. struct ath12k_base *ab = ar->ab;
  7525. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  7526. struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb);
  7527. struct ieee80211_tx_info *info;
  7528. enum hal_encrypt_type enctype;
  7529. unsigned int mic_len;
  7530. dma_addr_t paddr;
  7531. int buf_id;
  7532. int ret;
  7533. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  7534. skb_cb->ar = ar;
  7535. spin_lock_bh(&ar->txmgmt_idr_lock);
  7536. buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0,
  7537. ATH12K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC);
  7538. spin_unlock_bh(&ar->txmgmt_idr_lock);
  7539. if (buf_id < 0)
  7540. return -ENOSPC;
  7541. info = IEEE80211_SKB_CB(skb);
  7542. if ((skb_cb->flags & ATH12K_SKB_CIPHER_SET) &&
  7543. !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) {
  7544. if ((ieee80211_is_action(hdr->frame_control) ||
  7545. ieee80211_is_deauth(hdr->frame_control) ||
  7546. ieee80211_is_disassoc(hdr->frame_control)) &&
  7547. ieee80211_has_protected(hdr->frame_control)) {
  7548. enctype = ath12k_dp_tx_get_encrypt_type(skb_cb->cipher);
  7549. mic_len = ath12k_dp_rx_crypto_mic_len(ab->dp, enctype);
  7550. skb_put(skb, mic_len);
  7551. }
  7552. }
  7553. paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE);
  7554. if (dma_mapping_error(ab->dev, paddr)) {
  7555. ath12k_warn(ab, "failed to DMA map mgmt Tx buffer\n");
  7556. ret = -EIO;
  7557. goto err_free_idr;
  7558. }
  7559. skb_cb->paddr = paddr;
  7560. ret = ath12k_wmi_mgmt_send(arvif, buf_id, skb);
  7561. if (ret) {
  7562. ath12k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret);
  7563. goto err_unmap_buf;
  7564. }
  7565. return 0;
  7566. err_unmap_buf:
  7567. dma_unmap_single(ab->dev, skb_cb->paddr,
  7568. skb->len, DMA_TO_DEVICE);
  7569. err_free_idr:
  7570. spin_lock_bh(&ar->txmgmt_idr_lock);
  7571. idr_remove(&ar->txmgmt_idr, buf_id);
  7572. spin_unlock_bh(&ar->txmgmt_idr_lock);
  7573. return ret;
  7574. }
  7575. static void ath12k_mgmt_over_wmi_tx_purge(struct ath12k *ar)
  7576. {
  7577. struct sk_buff *skb;
  7578. while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL)
  7579. ath12k_mgmt_over_wmi_tx_drop(ar, skb);
  7580. }
  7581. static int ath12k_mac_mgmt_action_frame_fill_elem_data(struct ath12k_link_vif *arvif,
  7582. struct sk_buff *skb)
  7583. {
  7584. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  7585. u8 category, *buf, iv_len, action_code, dialog_token;
  7586. struct ieee80211_bss_conf *link_conf;
  7587. struct ieee80211_chanctx_conf *conf;
  7588. int cur_tx_power, max_tx_power;
  7589. struct ath12k *ar = arvif->ar;
  7590. struct ieee80211_hw *hw = ath12k_ar_to_hw(ar);
  7591. struct wiphy *wiphy = hw->wiphy;
  7592. struct ath12k_skb_cb *skb_cb;
  7593. struct ieee80211_mgmt *mgmt;
  7594. unsigned int remaining_len;
  7595. bool has_protected;
  7596. lockdep_assert_wiphy(wiphy);
  7597. /* make sure category field is present */
  7598. if (skb->len < IEEE80211_MIN_ACTION_SIZE)
  7599. return -EINVAL;
  7600. remaining_len = skb->len - IEEE80211_MIN_ACTION_SIZE;
  7601. has_protected = ieee80211_has_protected(hdr->frame_control);
  7602. /* In case of SW crypto and hdr protected (PMF), packet will already be encrypted,
  7603. * we can't put in data in this case
  7604. */
  7605. if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags) &&
  7606. has_protected)
  7607. return 0;
  7608. mgmt = (struct ieee80211_mgmt *)hdr;
  7609. buf = (u8 *)&mgmt->u.action;
  7610. /* FCTL_PROTECTED frame might have extra space added for HDR_LEN. Offset that
  7611. * many bytes if it is there
  7612. */
  7613. if (has_protected) {
  7614. skb_cb = ATH12K_SKB_CB(skb);
  7615. switch (skb_cb->cipher) {
  7616. /* Cipher suite having flag %IEEE80211_KEY_FLAG_GENERATE_IV_MGMT set in
  7617. * key needs to be processed. See ath12k_install_key()
  7618. */
  7619. case WLAN_CIPHER_SUITE_CCMP:
  7620. case WLAN_CIPHER_SUITE_CCMP_256:
  7621. case WLAN_CIPHER_SUITE_GCMP:
  7622. case WLAN_CIPHER_SUITE_GCMP_256:
  7623. iv_len = IEEE80211_CCMP_HDR_LEN;
  7624. break;
  7625. case WLAN_CIPHER_SUITE_TKIP:
  7626. iv_len = 0;
  7627. break;
  7628. default:
  7629. return -EINVAL;
  7630. }
  7631. if (remaining_len < iv_len)
  7632. return -EINVAL;
  7633. buf += iv_len;
  7634. remaining_len -= iv_len;
  7635. }
  7636. category = *buf++;
  7637. /* category code is already taken care in %IEEE80211_MIN_ACTION_SIZE hence
  7638. * no need to adjust remaining_len
  7639. */
  7640. switch (category) {
  7641. case WLAN_CATEGORY_RADIO_MEASUREMENT:
  7642. /* need action code and dialog token */
  7643. if (remaining_len < 2)
  7644. return -EINVAL;
  7645. /* Packet Format:
  7646. * Action Code | Dialog Token | Variable Len (based on Action Code)
  7647. */
  7648. action_code = *buf++;
  7649. dialog_token = *buf++;
  7650. remaining_len -= 2;
  7651. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  7652. if (!link_conf) {
  7653. ath12k_warn(ar->ab,
  7654. "failed to get bss link conf for vdev %d in RM handling\n",
  7655. arvif->vdev_id);
  7656. return -EINVAL;
  7657. }
  7658. conf = wiphy_dereference(wiphy, link_conf->chanctx_conf);
  7659. if (!conf)
  7660. return -ENOENT;
  7661. cur_tx_power = link_conf->txpower;
  7662. max_tx_power = min(conf->def.chan->max_reg_power,
  7663. (int)ar->max_tx_power / 2);
  7664. ath12k_mac_op_get_txpower(hw, arvif->ahvif->vif, arvif->link_id,
  7665. &cur_tx_power);
  7666. switch (action_code) {
  7667. case WLAN_RM_ACTION_LINK_MEASUREMENT_REQUEST:
  7668. /* need variable fields to be present in len */
  7669. if (remaining_len < 2)
  7670. return -EINVAL;
  7671. /* Variable length format as defined in IEEE 802.11-2024,
  7672. * Figure 9-1187-Link Measurement Request frame Action field
  7673. * format.
  7674. * Transmit Power | Max Tx Power
  7675. * We fill both of these.
  7676. */
  7677. *buf++ = cur_tx_power;
  7678. *buf = max_tx_power;
  7679. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  7680. "RRM: Link Measurement Req dialog_token %u cur_tx_power %d max_tx_power %d\n",
  7681. dialog_token, cur_tx_power, max_tx_power);
  7682. break;
  7683. case WLAN_RM_ACTION_LINK_MEASUREMENT_REPORT:
  7684. /* need variable fields to be present in len */
  7685. if (remaining_len < 3)
  7686. return -EINVAL;
  7687. /* Variable length format as defined in IEEE 802.11-2024,
  7688. * Figure 9-1188-Link Measurement Report frame Action field format
  7689. * TPC Report | Variable Fields
  7690. *
  7691. * TPC Report Format:
  7692. * Element ID | Len | Tx Power | Link Margin
  7693. *
  7694. * We fill Tx power in the TPC Report (2nd index)
  7695. */
  7696. buf[2] = cur_tx_power;
  7697. /* TODO: At present, Link margin data is not present so can't
  7698. * really fill it now. Once it is available, it can be added
  7699. * here
  7700. */
  7701. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  7702. "RRM: Link Measurement Report dialog_token %u cur_tx_power %d\n",
  7703. dialog_token, cur_tx_power);
  7704. break;
  7705. default:
  7706. return -EINVAL;
  7707. }
  7708. break;
  7709. default:
  7710. /* nothing to fill */
  7711. return 0;
  7712. }
  7713. return 0;
  7714. }
  7715. static int ath12k_mac_mgmt_frame_fill_elem_data(struct ath12k_link_vif *arvif,
  7716. struct sk_buff *skb)
  7717. {
  7718. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  7719. if (!ieee80211_is_action(hdr->frame_control))
  7720. return 0;
  7721. return ath12k_mac_mgmt_action_frame_fill_elem_data(arvif, skb);
  7722. }
  7723. static void ath12k_mgmt_over_wmi_tx_work(struct wiphy *wiphy, struct wiphy_work *work)
  7724. {
  7725. struct ath12k *ar = container_of(work, struct ath12k, wmi_mgmt_tx_work);
  7726. struct ath12k_hw *ah = ar->ah;
  7727. struct ath12k_skb_cb *skb_cb;
  7728. struct ath12k_vif *ahvif;
  7729. struct ath12k_link_vif *arvif;
  7730. struct sk_buff *skb;
  7731. int ret;
  7732. lockdep_assert_wiphy(wiphy);
  7733. while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) {
  7734. skb_cb = ATH12K_SKB_CB(skb);
  7735. if (!skb_cb->vif) {
  7736. ath12k_warn(ar->ab, "no vif found for mgmt frame\n");
  7737. ath12k_mgmt_over_wmi_tx_drop(ar, skb);
  7738. continue;
  7739. }
  7740. ahvif = ath12k_vif_to_ahvif(skb_cb->vif);
  7741. if (!(ahvif->links_map & BIT(skb_cb->link_id))) {
  7742. ath12k_warn(ar->ab,
  7743. "invalid linkid %u in mgmt over wmi tx with linkmap 0x%x\n",
  7744. skb_cb->link_id, ahvif->links_map);
  7745. ath12k_mgmt_over_wmi_tx_drop(ar, skb);
  7746. continue;
  7747. }
  7748. arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[skb_cb->link_id]);
  7749. if (ar->allocated_vdev_map & (1LL << arvif->vdev_id)) {
  7750. /* Fill in the data which is required to be filled by the driver
  7751. * For example: Max Tx power in Link Measurement Request/Report
  7752. */
  7753. ret = ath12k_mac_mgmt_frame_fill_elem_data(arvif, skb);
  7754. if (ret) {
  7755. /* If we couldn't fill the data due to any reason,
  7756. * let's not discard transmitting the packet.
  7757. * For example: Software crypto and PMF case
  7758. */
  7759. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  7760. "Failed to fill the required data for the mgmt packet err %d\n",
  7761. ret);
  7762. }
  7763. ret = ath12k_mac_mgmt_tx_wmi(ar, arvif, skb);
  7764. if (ret) {
  7765. ath12k_warn(ar->ab, "failed to tx mgmt frame, vdev_id %d :%d\n",
  7766. arvif->vdev_id, ret);
  7767. ath12k_mgmt_over_wmi_tx_drop(ar, skb);
  7768. }
  7769. } else {
  7770. ath12k_warn(ar->ab,
  7771. "dropping mgmt frame for vdev %d link %u is_started %d\n",
  7772. arvif->vdev_id,
  7773. skb_cb->link_id,
  7774. arvif->is_started);
  7775. ath12k_mgmt_over_wmi_tx_drop(ar, skb);
  7776. }
  7777. }
  7778. }
  7779. int ath12k_mac_mgmt_tx(struct ath12k *ar, struct sk_buff *skb,
  7780. bool is_prb_rsp)
  7781. {
  7782. struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
  7783. if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
  7784. return -ESHUTDOWN;
  7785. /* Drop probe response packets when the pending management tx
  7786. * count has reached a certain threshold, so as to prioritize
  7787. * other mgmt packets like auth and assoc to be sent on time
  7788. * for establishing successful connections.
  7789. */
  7790. if (is_prb_rsp &&
  7791. atomic_read(&ar->num_pending_mgmt_tx) > ATH12K_PRB_RSP_DROP_THRESHOLD) {
  7792. ath12k_warn(ar->ab,
  7793. "dropping probe response as pending queue is almost full\n");
  7794. return -ENOSPC;
  7795. }
  7796. if (skb_queue_len_lockless(q) >= ATH12K_TX_MGMT_NUM_PENDING_MAX) {
  7797. ath12k_warn(ar->ab, "mgmt tx queue is full\n");
  7798. return -ENOSPC;
  7799. }
  7800. skb_queue_tail(q, skb);
  7801. atomic_inc(&ar->num_pending_mgmt_tx);
  7802. wiphy_work_queue(ath12k_ar_to_hw(ar)->wiphy, &ar->wmi_mgmt_tx_work);
  7803. return 0;
  7804. }
  7805. EXPORT_SYMBOL(ath12k_mac_mgmt_tx);
  7806. void ath12k_mac_add_p2p_noa_ie(struct ath12k *ar,
  7807. struct ieee80211_vif *vif,
  7808. struct sk_buff *skb,
  7809. bool is_prb_rsp)
  7810. {
  7811. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  7812. if (likely(!is_prb_rsp))
  7813. return;
  7814. spin_lock_bh(&ar->data_lock);
  7815. if (ahvif->u.ap.noa_data &&
  7816. !pskb_expand_head(skb, 0, ahvif->u.ap.noa_len,
  7817. GFP_ATOMIC))
  7818. skb_put_data(skb, ahvif->u.ap.noa_data,
  7819. ahvif->u.ap.noa_len);
  7820. spin_unlock_bh(&ar->data_lock);
  7821. }
  7822. EXPORT_SYMBOL(ath12k_mac_add_p2p_noa_ie);
  7823. /* Note: called under rcu_read_lock() */
  7824. void ath12k_mlo_mcast_update_tx_link_address(struct ieee80211_vif *vif,
  7825. u8 link_id, struct sk_buff *skb,
  7826. u32 info_flags)
  7827. {
  7828. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  7829. struct ieee80211_bss_conf *bss_conf;
  7830. if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP)
  7831. return;
  7832. bss_conf = rcu_dereference(vif->link_conf[link_id]);
  7833. if (bss_conf)
  7834. ether_addr_copy(hdr->addr2, bss_conf->addr);
  7835. }
  7836. EXPORT_SYMBOL(ath12k_mlo_mcast_update_tx_link_address);
  7837. /* Note: called under rcu_read_lock() */
  7838. u8 ath12k_mac_get_tx_link(struct ieee80211_sta *sta, struct ieee80211_vif *vif,
  7839. u8 link, struct sk_buff *skb, u32 info_flags)
  7840. {
  7841. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  7842. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  7843. struct ieee80211_link_sta *link_sta;
  7844. struct ieee80211_bss_conf *bss_conf;
  7845. struct ath12k_sta *ahsta;
  7846. /* Use the link id passed or the default vif link */
  7847. if (!sta) {
  7848. if (link != IEEE80211_LINK_UNSPECIFIED)
  7849. return link;
  7850. return ahvif->deflink.link_id;
  7851. }
  7852. ahsta = ath12k_sta_to_ahsta(sta);
  7853. /* Below translation ensures we pass proper A2 & A3 for non ML clients.
  7854. * Also it assumes for now support only for MLO AP in this path
  7855. */
  7856. if (!sta->mlo) {
  7857. link = ahsta->deflink.link_id;
  7858. if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP)
  7859. return link;
  7860. bss_conf = rcu_dereference(vif->link_conf[link]);
  7861. if (bss_conf) {
  7862. ether_addr_copy(hdr->addr2, bss_conf->addr);
  7863. if (!ieee80211_has_tods(hdr->frame_control) &&
  7864. !ieee80211_has_fromds(hdr->frame_control))
  7865. ether_addr_copy(hdr->addr3, bss_conf->addr);
  7866. }
  7867. return link;
  7868. }
  7869. /* enqueue eth enacap & data frames on primary link, FW does link
  7870. * selection and address translation.
  7871. */
  7872. if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP ||
  7873. ieee80211_is_data(hdr->frame_control))
  7874. return ahsta->assoc_link_id;
  7875. /* 802.11 frame cases */
  7876. if (link == IEEE80211_LINK_UNSPECIFIED)
  7877. link = ahsta->deflink.link_id;
  7878. if (!ieee80211_is_mgmt(hdr->frame_control))
  7879. return link;
  7880. /* Perform address conversion for ML STA Tx */
  7881. bss_conf = rcu_dereference(vif->link_conf[link]);
  7882. link_sta = rcu_dereference(sta->link[link]);
  7883. if (bss_conf && link_sta) {
  7884. ether_addr_copy(hdr->addr1, link_sta->addr);
  7885. ether_addr_copy(hdr->addr2, bss_conf->addr);
  7886. if (vif->type == NL80211_IFTYPE_STATION && bss_conf->bssid)
  7887. ether_addr_copy(hdr->addr3, bss_conf->bssid);
  7888. else if (vif->type == NL80211_IFTYPE_AP)
  7889. ether_addr_copy(hdr->addr3, bss_conf->addr);
  7890. return link;
  7891. }
  7892. if (bss_conf) {
  7893. /* In certain cases where a ML sta associated and added subset of
  7894. * links on which the ML AP is active, but now sends some frame
  7895. * (ex. Probe request) on a different link which is active in our
  7896. * MLD but was not added during previous association, we can
  7897. * still honor the Tx to that ML STA via the requested link.
  7898. * The control would reach here in such case only when that link
  7899. * address is same as the MLD address or in worst case clients
  7900. * used MLD address at TA wrongly which would have helped
  7901. * identify the ML sta object and pass it here.
  7902. * If the link address of that STA is different from MLD address,
  7903. * then the sta object would be NULL and control won't reach
  7904. * here but return at the start of the function itself with !sta
  7905. * check. Also this would not need any translation at hdr->addr1
  7906. * from MLD to link address since the RA is the MLD address
  7907. * (same as that link address ideally) already.
  7908. */
  7909. ether_addr_copy(hdr->addr2, bss_conf->addr);
  7910. if (vif->type == NL80211_IFTYPE_STATION && bss_conf->bssid)
  7911. ether_addr_copy(hdr->addr3, bss_conf->bssid);
  7912. else if (vif->type == NL80211_IFTYPE_AP)
  7913. ether_addr_copy(hdr->addr3, bss_conf->addr);
  7914. }
  7915. return link;
  7916. }
  7917. EXPORT_SYMBOL(ath12k_mac_get_tx_link);
  7918. void ath12k_mac_drain_tx(struct ath12k *ar)
  7919. {
  7920. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  7921. /* make sure rcu-protected mac80211 tx path itself is drained */
  7922. synchronize_net();
  7923. wiphy_work_cancel(ath12k_ar_to_hw(ar)->wiphy, &ar->wmi_mgmt_tx_work);
  7924. ath12k_mgmt_over_wmi_tx_purge(ar);
  7925. }
  7926. static int ath12k_mac_config_mon_status_default(struct ath12k *ar, bool enable)
  7927. {
  7928. struct htt_rx_ring_tlv_filter tlv_filter = {};
  7929. struct ath12k_base *ab = ar->ab;
  7930. u32 ring_id, i;
  7931. int ret = 0;
  7932. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  7933. if (!ab->hw_params->rxdma1_enable)
  7934. return ret;
  7935. if (enable) {
  7936. tlv_filter = ath12k_mac_mon_status_filter_default;
  7937. if (ath12k_debugfs_rx_filter(ar))
  7938. tlv_filter.rx_filter = ath12k_debugfs_rx_filter(ar);
  7939. } else {
  7940. tlv_filter.rxmon_disable = true;
  7941. }
  7942. for (i = 0; i < ab->hw_params->num_rxdma_per_pdev; i++) {
  7943. ring_id = ar->dp.rxdma_mon_dst_ring[i].ring_id;
  7944. ret = ath12k_dp_tx_htt_rx_filter_setup(ab, ring_id,
  7945. ar->dp.mac_id + i,
  7946. HAL_RXDMA_MONITOR_DST,
  7947. DP_RXDMA_REFILL_RING_SIZE,
  7948. &tlv_filter);
  7949. if (ret) {
  7950. ath12k_err(ab,
  7951. "failed to setup filter for monitor buf %d\n",
  7952. ret);
  7953. }
  7954. }
  7955. return ret;
  7956. }
  7957. static int ath12k_mac_start(struct ath12k *ar)
  7958. {
  7959. struct ath12k_hw *ah = ar->ah;
  7960. struct ath12k_base *ab = ar->ab;
  7961. struct ath12k_pdev *pdev = ar->pdev;
  7962. int ret;
  7963. lockdep_assert_held(&ah->hw_mutex);
  7964. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  7965. ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS,
  7966. 1, pdev->pdev_id);
  7967. if (ret) {
  7968. ath12k_err(ab, "failed to enable PMF QOS: %d\n", ret);
  7969. goto err;
  7970. }
  7971. ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1,
  7972. pdev->pdev_id);
  7973. if (ret) {
  7974. ath12k_err(ab, "failed to enable dynamic bw: %d\n", ret);
  7975. goto err;
  7976. }
  7977. ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
  7978. 0, pdev->pdev_id);
  7979. if (ret) {
  7980. ath12k_err(ab, "failed to set ac override for ARP: %d\n",
  7981. ret);
  7982. goto err;
  7983. }
  7984. ret = ath12k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id);
  7985. if (ret) {
  7986. ath12k_err(ab, "failed to offload radar detection: %d\n",
  7987. ret);
  7988. goto err;
  7989. }
  7990. ret = ath12k_dp_tx_htt_h2t_ppdu_stats_req(ar,
  7991. HTT_PPDU_STATS_TAG_DEFAULT);
  7992. if (ret) {
  7993. ath12k_err(ab, "failed to req ppdu stats: %d\n", ret);
  7994. goto err;
  7995. }
  7996. ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE,
  7997. 1, pdev->pdev_id);
  7998. if (ret) {
  7999. ath12k_err(ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret);
  8000. goto err;
  8001. }
  8002. __ath12k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
  8003. /* TODO: Do we need to enable ANI? */
  8004. ret = ath12k_reg_update_chan_list(ar, false);
  8005. /* The ar state alone can be turned off for non supported country
  8006. * without returning the error value. As we need to update the channel
  8007. * for the next ar.
  8008. */
  8009. if (ret) {
  8010. if (ret == -EINVAL)
  8011. ret = 0;
  8012. goto err;
  8013. }
  8014. ar->num_started_vdevs = 0;
  8015. ar->num_created_vdevs = 0;
  8016. ar->num_peers = 0;
  8017. ar->allocated_vdev_map = 0;
  8018. ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID;
  8019. /* Configure monitor status ring with default rx_filter to get rx status
  8020. * such as rssi, rx_duration.
  8021. */
  8022. ret = ath12k_mac_config_mon_status_default(ar, true);
  8023. if (ret && (ret != -EOPNOTSUPP)) {
  8024. ath12k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n",
  8025. ret);
  8026. goto err;
  8027. }
  8028. if (ret == -EOPNOTSUPP)
  8029. ath12k_dbg(ab, ATH12K_DBG_MAC,
  8030. "monitor status config is not yet supported");
  8031. /* Configure the hash seed for hash based reo dest ring selection */
  8032. ath12k_wmi_pdev_lro_cfg(ar, ar->pdev->pdev_id);
  8033. /* allow device to enter IMPS */
  8034. if (ab->hw_params->idle_ps) {
  8035. ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_IDLE_PS_CONFIG,
  8036. 1, pdev->pdev_id);
  8037. if (ret) {
  8038. ath12k_err(ab, "failed to enable idle ps: %d\n", ret);
  8039. goto err;
  8040. }
  8041. }
  8042. rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx],
  8043. &ab->pdevs[ar->pdev_idx]);
  8044. return 0;
  8045. err:
  8046. return ret;
  8047. }
  8048. static void ath12k_drain_tx(struct ath12k_hw *ah)
  8049. {
  8050. struct ath12k *ar;
  8051. int i;
  8052. lockdep_assert_wiphy(ah->hw->wiphy);
  8053. for_each_ar(ah, ar, i)
  8054. ath12k_mac_drain_tx(ar);
  8055. }
  8056. int ath12k_mac_op_start(struct ieee80211_hw *hw)
  8057. {
  8058. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  8059. struct ath12k *ar;
  8060. int ret, i;
  8061. if (ath12k_ftm_mode)
  8062. return -EPERM;
  8063. lockdep_assert_wiphy(hw->wiphy);
  8064. ath12k_drain_tx(ah);
  8065. guard(mutex)(&ah->hw_mutex);
  8066. switch (ah->state) {
  8067. case ATH12K_HW_STATE_OFF:
  8068. ah->state = ATH12K_HW_STATE_ON;
  8069. break;
  8070. case ATH12K_HW_STATE_RESTARTING:
  8071. ah->state = ATH12K_HW_STATE_RESTARTED;
  8072. break;
  8073. case ATH12K_HW_STATE_RESTARTED:
  8074. case ATH12K_HW_STATE_WEDGED:
  8075. case ATH12K_HW_STATE_ON:
  8076. case ATH12K_HW_STATE_TM:
  8077. ah->state = ATH12K_HW_STATE_OFF;
  8078. WARN_ON(1);
  8079. return -EINVAL;
  8080. }
  8081. for_each_ar(ah, ar, i) {
  8082. ret = ath12k_mac_start(ar);
  8083. if (ret) {
  8084. ah->state = ATH12K_HW_STATE_OFF;
  8085. ath12k_err(ar->ab, "fail to start mac operations in pdev idx %d ret %d\n",
  8086. ar->pdev_idx, ret);
  8087. goto fail_start;
  8088. }
  8089. }
  8090. return 0;
  8091. fail_start:
  8092. for (; i > 0; i--) {
  8093. ar = ath12k_ah_to_ar(ah, i - 1);
  8094. ath12k_mac_stop(ar);
  8095. }
  8096. return ret;
  8097. }
  8098. EXPORT_SYMBOL(ath12k_mac_op_start);
  8099. int ath12k_mac_rfkill_config(struct ath12k *ar)
  8100. {
  8101. struct ath12k_base *ab = ar->ab;
  8102. u32 param;
  8103. int ret;
  8104. if (ab->hw_params->rfkill_pin == 0)
  8105. return -EOPNOTSUPP;
  8106. ath12k_dbg(ab, ATH12K_DBG_MAC,
  8107. "mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d",
  8108. ab->hw_params->rfkill_pin, ab->hw_params->rfkill_cfg,
  8109. ab->hw_params->rfkill_on_level);
  8110. param = u32_encode_bits(ab->hw_params->rfkill_on_level,
  8111. WMI_RFKILL_CFG_RADIO_LEVEL) |
  8112. u32_encode_bits(ab->hw_params->rfkill_pin,
  8113. WMI_RFKILL_CFG_GPIO_PIN_NUM) |
  8114. u32_encode_bits(ab->hw_params->rfkill_cfg,
  8115. WMI_RFKILL_CFG_PIN_AS_GPIO);
  8116. ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_HW_RFKILL_CONFIG,
  8117. param, ar->pdev->pdev_id);
  8118. if (ret) {
  8119. ath12k_warn(ab,
  8120. "failed to set rfkill config 0x%x: %d\n",
  8121. param, ret);
  8122. return ret;
  8123. }
  8124. return 0;
  8125. }
  8126. int ath12k_mac_rfkill_enable_radio(struct ath12k *ar, bool enable)
  8127. {
  8128. enum wmi_rfkill_enable_radio param;
  8129. int ret;
  8130. if (enable)
  8131. param = WMI_RFKILL_ENABLE_RADIO_ON;
  8132. else
  8133. param = WMI_RFKILL_ENABLE_RADIO_OFF;
  8134. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac %d rfkill enable %d",
  8135. ar->pdev_idx, param);
  8136. ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RFKILL_ENABLE,
  8137. param, ar->pdev->pdev_id);
  8138. if (ret) {
  8139. ath12k_warn(ar->ab, "failed to set rfkill enable param %d: %d\n",
  8140. param, ret);
  8141. return ret;
  8142. }
  8143. return 0;
  8144. }
  8145. static void ath12k_mac_stop(struct ath12k *ar)
  8146. {
  8147. struct ath12k_pdev_dp *dp_pdev = &ar->dp;
  8148. struct ath12k_hw *ah = ar->ah;
  8149. struct htt_ppdu_stats_info *ppdu_stats, *tmp;
  8150. struct ath12k_wmi_scan_chan_list_arg *arg;
  8151. int ret;
  8152. lockdep_assert_held(&ah->hw_mutex);
  8153. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  8154. ret = ath12k_mac_config_mon_status_default(ar, false);
  8155. if (ret && (ret != -EOPNOTSUPP))
  8156. ath12k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n",
  8157. ret);
  8158. clear_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags);
  8159. cancel_delayed_work_sync(&ar->scan.timeout);
  8160. wiphy_work_cancel(ath12k_ar_to_hw(ar)->wiphy, &ar->scan.vdev_clean_wk);
  8161. cancel_work_sync(&ar->regd_channel_update_work);
  8162. cancel_work_sync(&ar->regd_update_work);
  8163. cancel_work_sync(&ar->ab->rfkill_work);
  8164. cancel_work_sync(&ar->ab->update_11d_work);
  8165. ar->state_11d = ATH12K_11D_IDLE;
  8166. complete(&ar->completed_11d_scan);
  8167. spin_lock_bh(&dp_pdev->ppdu_list_lock);
  8168. list_for_each_entry_safe(ppdu_stats, tmp, &dp_pdev->ppdu_stats_info, list) {
  8169. list_del(&ppdu_stats->list);
  8170. kfree(ppdu_stats);
  8171. }
  8172. spin_unlock_bh(&dp_pdev->ppdu_list_lock);
  8173. spin_lock_bh(&ar->data_lock);
  8174. while ((arg = list_first_entry_or_null(&ar->regd_channel_update_queue,
  8175. struct ath12k_wmi_scan_chan_list_arg,
  8176. list))) {
  8177. list_del(&arg->list);
  8178. kfree(arg);
  8179. }
  8180. spin_unlock_bh(&ar->data_lock);
  8181. rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL);
  8182. synchronize_rcu();
  8183. atomic_set(&ar->num_pending_mgmt_tx, 0);
  8184. }
  8185. void ath12k_mac_op_stop(struct ieee80211_hw *hw, bool suspend)
  8186. {
  8187. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  8188. struct ath12k *ar;
  8189. int i;
  8190. lockdep_assert_wiphy(hw->wiphy);
  8191. ath12k_drain_tx(ah);
  8192. mutex_lock(&ah->hw_mutex);
  8193. ah->state = ATH12K_HW_STATE_OFF;
  8194. for_each_ar(ah, ar, i)
  8195. ath12k_mac_stop(ar);
  8196. mutex_unlock(&ah->hw_mutex);
  8197. }
  8198. EXPORT_SYMBOL(ath12k_mac_op_stop);
  8199. static u8
  8200. ath12k_mac_get_vdev_stats_id(struct ath12k_link_vif *arvif)
  8201. {
  8202. struct ath12k_base *ab = arvif->ar->ab;
  8203. u8 vdev_stats_id = 0;
  8204. do {
  8205. if (ab->free_vdev_stats_id_map & (1LL << vdev_stats_id)) {
  8206. vdev_stats_id++;
  8207. if (vdev_stats_id >= ATH12K_MAX_VDEV_STATS_ID) {
  8208. vdev_stats_id = ATH12K_INVAL_VDEV_STATS_ID;
  8209. break;
  8210. }
  8211. } else {
  8212. ab->free_vdev_stats_id_map |= (1LL << vdev_stats_id);
  8213. break;
  8214. }
  8215. } while (vdev_stats_id);
  8216. arvif->vdev_stats_id = vdev_stats_id;
  8217. return vdev_stats_id;
  8218. }
  8219. static int ath12k_mac_setup_vdev_params_mbssid(struct ath12k_link_vif *arvif,
  8220. u32 *flags, u32 *tx_vdev_id)
  8221. {
  8222. struct ath12k_vif *ahvif = arvif->ahvif;
  8223. struct ieee80211_bss_conf *link_conf;
  8224. struct ath12k *ar = arvif->ar;
  8225. struct ath12k_link_vif *tx_arvif;
  8226. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  8227. if (!link_conf) {
  8228. ath12k_warn(ar->ab, "unable to access bss link conf in set mbssid params for vif %pM link %u\n",
  8229. ahvif->vif->addr, arvif->link_id);
  8230. return -ENOLINK;
  8231. }
  8232. tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf);
  8233. if (!tx_arvif)
  8234. return 0;
  8235. if (link_conf->nontransmitted) {
  8236. if (ath12k_ar_to_hw(ar)->wiphy !=
  8237. ath12k_ar_to_hw(tx_arvif->ar)->wiphy)
  8238. return -EINVAL;
  8239. *flags = WMI_VDEV_MBSSID_FLAGS_NON_TRANSMIT_AP;
  8240. *tx_vdev_id = tx_arvif->vdev_id;
  8241. } else if (tx_arvif == arvif) {
  8242. *flags = WMI_VDEV_MBSSID_FLAGS_TRANSMIT_AP;
  8243. } else {
  8244. return -EINVAL;
  8245. }
  8246. if (link_conf->ema_ap)
  8247. *flags |= WMI_VDEV_MBSSID_FLAGS_EMA_MODE;
  8248. return 0;
  8249. }
  8250. static int ath12k_mac_setup_vdev_create_arg(struct ath12k_link_vif *arvif,
  8251. struct ath12k_wmi_vdev_create_arg *arg)
  8252. {
  8253. struct ath12k *ar = arvif->ar;
  8254. struct ath12k_pdev *pdev = ar->pdev;
  8255. struct ath12k_vif *ahvif = arvif->ahvif;
  8256. int ret;
  8257. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  8258. arg->if_id = arvif->vdev_id;
  8259. arg->type = ahvif->vdev_type;
  8260. arg->subtype = ahvif->vdev_subtype;
  8261. arg->pdev_id = pdev->pdev_id;
  8262. arg->mbssid_flags = WMI_VDEV_MBSSID_FLAGS_NON_MBSSID_AP;
  8263. arg->mbssid_tx_vdev_id = 0;
  8264. if (!test_bit(WMI_TLV_SERVICE_MBSS_PARAM_IN_VDEV_START_SUPPORT,
  8265. ar->ab->wmi_ab.svc_map)) {
  8266. ret = ath12k_mac_setup_vdev_params_mbssid(arvif,
  8267. &arg->mbssid_flags,
  8268. &arg->mbssid_tx_vdev_id);
  8269. if (ret)
  8270. return ret;
  8271. }
  8272. if (pdev->cap.supported_bands & WMI_HOST_WLAN_2GHZ_CAP) {
  8273. arg->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains;
  8274. arg->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains;
  8275. }
  8276. if (pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) {
  8277. arg->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains;
  8278. arg->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains;
  8279. }
  8280. if (pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP &&
  8281. ar->supports_6ghz) {
  8282. arg->chains[NL80211_BAND_6GHZ].tx = ar->num_tx_chains;
  8283. arg->chains[NL80211_BAND_6GHZ].rx = ar->num_rx_chains;
  8284. }
  8285. arg->if_stats_id = ath12k_mac_get_vdev_stats_id(arvif);
  8286. if (ath12k_mac_is_ml_arvif(arvif)) {
  8287. if (hweight16(ahvif->vif->valid_links) > ATH12K_WMI_MLO_MAX_LINKS) {
  8288. ath12k_warn(ar->ab, "too many MLO links during setting up vdev: %d",
  8289. ahvif->vif->valid_links);
  8290. return -EINVAL;
  8291. }
  8292. ether_addr_copy(arg->mld_addr, ahvif->vif->addr);
  8293. }
  8294. return 0;
  8295. }
  8296. static void ath12k_mac_update_vif_offload(struct ath12k_link_vif *arvif)
  8297. {
  8298. struct ath12k_vif *ahvif = arvif->ahvif;
  8299. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif);
  8300. struct ath12k *ar = arvif->ar;
  8301. struct ath12k_base *ab = ar->ab;
  8302. u32 param_id, param_value;
  8303. int ret;
  8304. param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE;
  8305. if (vif->type != NL80211_IFTYPE_STATION &&
  8306. vif->type != NL80211_IFTYPE_AP)
  8307. vif->offload_flags &= ~(IEEE80211_OFFLOAD_ENCAP_ENABLED |
  8308. IEEE80211_OFFLOAD_DECAP_ENABLED);
  8309. if (vif->offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
  8310. ahvif->dp_vif.tx_encap_type = ATH12K_HW_TXRX_ETHERNET;
  8311. else if (test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags))
  8312. ahvif->dp_vif.tx_encap_type = ATH12K_HW_TXRX_RAW;
  8313. else
  8314. ahvif->dp_vif.tx_encap_type = ATH12K_HW_TXRX_NATIVE_WIFI;
  8315. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  8316. param_id, ahvif->dp_vif.tx_encap_type);
  8317. if (ret) {
  8318. ath12k_warn(ab, "failed to set vdev %d tx encap mode: %d\n",
  8319. arvif->vdev_id, ret);
  8320. vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
  8321. }
  8322. param_id = WMI_VDEV_PARAM_RX_DECAP_TYPE;
  8323. if (vif->offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED)
  8324. param_value = ATH12K_HW_TXRX_ETHERNET;
  8325. else if (test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags))
  8326. param_value = ATH12K_HW_TXRX_RAW;
  8327. else
  8328. param_value = ATH12K_HW_TXRX_NATIVE_WIFI;
  8329. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  8330. param_id, param_value);
  8331. if (ret) {
  8332. ath12k_warn(ab, "failed to set vdev %d rx decap mode: %d\n",
  8333. arvif->vdev_id, ret);
  8334. vif->offload_flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED;
  8335. }
  8336. }
  8337. void ath12k_mac_op_update_vif_offload(struct ieee80211_hw *hw,
  8338. struct ieee80211_vif *vif)
  8339. {
  8340. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  8341. struct ath12k_link_vif *arvif;
  8342. unsigned long links;
  8343. int link_id;
  8344. lockdep_assert_wiphy(hw->wiphy);
  8345. if (vif->valid_links) {
  8346. links = vif->valid_links;
  8347. for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
  8348. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  8349. if (!(arvif && arvif->ar))
  8350. continue;
  8351. ath12k_mac_update_vif_offload(arvif);
  8352. }
  8353. return;
  8354. }
  8355. ath12k_mac_update_vif_offload(&ahvif->deflink);
  8356. }
  8357. EXPORT_SYMBOL(ath12k_mac_op_update_vif_offload);
  8358. static bool ath12k_mac_vif_ap_active_any(struct ath12k_base *ab)
  8359. {
  8360. struct ath12k *ar;
  8361. struct ath12k_pdev *pdev;
  8362. struct ath12k_link_vif *arvif;
  8363. int i;
  8364. for (i = 0; i < ab->num_radios; i++) {
  8365. pdev = &ab->pdevs[i];
  8366. ar = pdev->ar;
  8367. list_for_each_entry(arvif, &ar->arvifs, list) {
  8368. if (arvif->is_up &&
  8369. arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP)
  8370. return true;
  8371. }
  8372. }
  8373. return false;
  8374. }
  8375. void ath12k_mac_11d_scan_start(struct ath12k *ar, u32 vdev_id)
  8376. {
  8377. struct wmi_11d_scan_start_arg arg;
  8378. int ret;
  8379. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  8380. if (ar->regdom_set_by_user)
  8381. goto fin;
  8382. if (ar->vdev_id_11d_scan != ATH12K_11D_INVALID_VDEV_ID)
  8383. goto fin;
  8384. if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map))
  8385. goto fin;
  8386. if (ath12k_mac_vif_ap_active_any(ar->ab))
  8387. goto fin;
  8388. arg.vdev_id = vdev_id;
  8389. arg.start_interval_msec = 0;
  8390. arg.scan_period_msec = ATH12K_SCAN_11D_INTERVAL;
  8391. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  8392. "mac start 11d scan for vdev %d\n", vdev_id);
  8393. ret = ath12k_wmi_send_11d_scan_start_cmd(ar, &arg);
  8394. if (ret) {
  8395. ath12k_warn(ar->ab, "failed to start 11d scan vdev %d ret: %d\n",
  8396. vdev_id, ret);
  8397. } else {
  8398. ar->vdev_id_11d_scan = vdev_id;
  8399. if (ar->state_11d == ATH12K_11D_PREPARING)
  8400. ar->state_11d = ATH12K_11D_RUNNING;
  8401. }
  8402. fin:
  8403. if (ar->state_11d == ATH12K_11D_PREPARING) {
  8404. ar->state_11d = ATH12K_11D_IDLE;
  8405. complete(&ar->completed_11d_scan);
  8406. }
  8407. }
  8408. void ath12k_mac_11d_scan_stop(struct ath12k *ar)
  8409. {
  8410. int ret;
  8411. u32 vdev_id;
  8412. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  8413. if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map))
  8414. return;
  8415. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac stop 11d for vdev %d\n",
  8416. ar->vdev_id_11d_scan);
  8417. if (ar->state_11d == ATH12K_11D_PREPARING) {
  8418. ar->state_11d = ATH12K_11D_IDLE;
  8419. complete(&ar->completed_11d_scan);
  8420. }
  8421. if (ar->vdev_id_11d_scan != ATH12K_11D_INVALID_VDEV_ID) {
  8422. vdev_id = ar->vdev_id_11d_scan;
  8423. ret = ath12k_wmi_send_11d_scan_stop_cmd(ar, vdev_id);
  8424. if (ret) {
  8425. ath12k_warn(ar->ab,
  8426. "failed to stopt 11d scan vdev %d ret: %d\n",
  8427. vdev_id, ret);
  8428. } else {
  8429. ar->vdev_id_11d_scan = ATH12K_11D_INVALID_VDEV_ID;
  8430. ar->state_11d = ATH12K_11D_IDLE;
  8431. complete(&ar->completed_11d_scan);
  8432. }
  8433. }
  8434. }
  8435. void ath12k_mac_11d_scan_stop_all(struct ath12k_base *ab)
  8436. {
  8437. struct ath12k *ar;
  8438. struct ath12k_pdev *pdev;
  8439. int i;
  8440. ath12k_dbg(ab, ATH12K_DBG_MAC, "mac stop soc 11d scan\n");
  8441. for (i = 0; i < ab->num_radios; i++) {
  8442. pdev = &ab->pdevs[i];
  8443. ar = pdev->ar;
  8444. ath12k_mac_11d_scan_stop(ar);
  8445. }
  8446. }
  8447. static void ath12k_mac_determine_vdev_type(struct ieee80211_vif *vif,
  8448. struct ath12k_vif *ahvif)
  8449. {
  8450. ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
  8451. switch (vif->type) {
  8452. case NL80211_IFTYPE_UNSPECIFIED:
  8453. case NL80211_IFTYPE_STATION:
  8454. ahvif->vdev_type = WMI_VDEV_TYPE_STA;
  8455. if (vif->p2p)
  8456. ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
  8457. break;
  8458. case NL80211_IFTYPE_MESH_POINT:
  8459. ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S;
  8460. fallthrough;
  8461. case NL80211_IFTYPE_AP:
  8462. ahvif->vdev_type = WMI_VDEV_TYPE_AP;
  8463. if (vif->p2p)
  8464. ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
  8465. break;
  8466. case NL80211_IFTYPE_MONITOR:
  8467. ahvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
  8468. break;
  8469. case NL80211_IFTYPE_P2P_DEVICE:
  8470. ahvif->vdev_type = WMI_VDEV_TYPE_STA;
  8471. ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
  8472. break;
  8473. default:
  8474. WARN_ON(1);
  8475. break;
  8476. }
  8477. }
  8478. int ath12k_mac_vdev_create(struct ath12k *ar, struct ath12k_link_vif *arvif)
  8479. {
  8480. struct ath12k_hw *ah = ar->ah;
  8481. struct ath12k_base *ab = ar->ab;
  8482. struct ieee80211_hw *hw = ah->hw;
  8483. struct ath12k_vif *ahvif = arvif->ahvif;
  8484. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif);
  8485. struct ath12k_wmi_vdev_create_arg vdev_arg = {};
  8486. struct ath12k_wmi_peer_create_arg peer_param = {};
  8487. struct ieee80211_bss_conf *link_conf = NULL;
  8488. u32 param_id, param_value;
  8489. u16 nss;
  8490. int i;
  8491. int ret, vdev_id;
  8492. u8 link_id;
  8493. struct ath12k_dp_link_vif *dp_link_vif = NULL;
  8494. struct ath12k_dp_peer_create_params params = {};
  8495. bool dp_peer_created = false;
  8496. lockdep_assert_wiphy(hw->wiphy);
  8497. /* In NO_VIRTUAL_MONITOR, its necessary to restrict only one monitor
  8498. * interface in each radio
  8499. */
  8500. if (vif->type == NL80211_IFTYPE_MONITOR && ar->monitor_vdev_created)
  8501. return -EINVAL;
  8502. if (ar->num_created_vdevs >= TARGET_NUM_VDEVS(ab)) {
  8503. ath12k_warn(ab, "failed to create vdev, reached max vdev limit %d\n",
  8504. TARGET_NUM_VDEVS(ab));
  8505. return -ENOSPC;
  8506. }
  8507. link_id = arvif->link_id;
  8508. if (link_id < IEEE80211_MLD_MAX_NUM_LINKS) {
  8509. link_conf = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]);
  8510. if (!link_conf) {
  8511. ath12k_warn(ar->ab, "unable to access bss link conf in vdev create for vif %pM link %u\n",
  8512. vif->addr, arvif->link_id);
  8513. return -ENOLINK;
  8514. }
  8515. }
  8516. if (link_conf)
  8517. memcpy(arvif->bssid, link_conf->addr, ETH_ALEN);
  8518. else
  8519. memcpy(arvif->bssid, vif->addr, ETH_ALEN);
  8520. arvif->ar = ar;
  8521. vdev_id = __ffs64(ab->free_vdev_map);
  8522. arvif->vdev_id = vdev_id;
  8523. if (vif->type == NL80211_IFTYPE_MONITOR)
  8524. ar->monitor_vdev_id = vdev_id;
  8525. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev create id %d type %d subtype %d map %llx\n",
  8526. arvif->vdev_id, ahvif->vdev_type, ahvif->vdev_subtype,
  8527. ab->free_vdev_map);
  8528. vif->cab_queue = arvif->vdev_id % (ATH12K_HW_MAX_QUEUES - 1);
  8529. for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
  8530. vif->hw_queue[i] = i % (ATH12K_HW_MAX_QUEUES - 1);
  8531. ret = ath12k_mac_setup_vdev_create_arg(arvif, &vdev_arg);
  8532. if (ret) {
  8533. ath12k_warn(ab, "failed to create vdev parameters %d: %d\n",
  8534. arvif->vdev_id, ret);
  8535. goto err;
  8536. }
  8537. ret = ath12k_wmi_vdev_create(ar, arvif->bssid, &vdev_arg);
  8538. if (ret) {
  8539. ath12k_warn(ab, "failed to create WMI vdev %d: %d\n",
  8540. arvif->vdev_id, ret);
  8541. return ret;
  8542. }
  8543. ar->num_created_vdevs++;
  8544. arvif->is_created = true;
  8545. ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM created, vdev_id %d\n",
  8546. vif->addr, arvif->vdev_id);
  8547. ar->allocated_vdev_map |= 1LL << arvif->vdev_id;
  8548. ab->free_vdev_map &= ~(1LL << arvif->vdev_id);
  8549. spin_lock_bh(&ar->data_lock);
  8550. list_add(&arvif->list, &ar->arvifs);
  8551. spin_unlock_bh(&ar->data_lock);
  8552. ath12k_mac_update_vif_offload(arvif);
  8553. nss = hweight32(ar->cfg_tx_chainmask) ? : 1;
  8554. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  8555. WMI_VDEV_PARAM_NSS, nss);
  8556. if (ret) {
  8557. ath12k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n",
  8558. arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret);
  8559. goto err_vdev_del;
  8560. }
  8561. dp_link_vif = ath12k_dp_vif_to_dp_link_vif(&ahvif->dp_vif, arvif->link_id);
  8562. dp_link_vif->vdev_id = arvif->vdev_id;
  8563. dp_link_vif->lmac_id = ar->lmac_id;
  8564. dp_link_vif->pdev_idx = ar->pdev_idx;
  8565. switch (ahvif->vdev_type) {
  8566. case WMI_VDEV_TYPE_AP:
  8567. params.ucast_ra_only = true;
  8568. if (arvif->link_id < IEEE80211_MLD_MAX_NUM_LINKS) {
  8569. ret = ath12k_dp_peer_create(&ah->dp_hw, arvif->bssid, &params);
  8570. if (ret) {
  8571. ath12k_warn(ab, "failed to vdev %d create dp_peer for AP: %d\n",
  8572. arvif->vdev_id, ret);
  8573. goto err_vdev_del;
  8574. }
  8575. dp_peer_created = true;
  8576. }
  8577. peer_param.vdev_id = arvif->vdev_id;
  8578. peer_param.peer_addr = arvif->bssid;
  8579. peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
  8580. ret = ath12k_peer_create(ar, arvif, NULL, &peer_param);
  8581. if (ret) {
  8582. ath12k_warn(ab, "failed to vdev %d create peer for AP: %d\n",
  8583. arvif->vdev_id, ret);
  8584. goto err_dp_peer_del;
  8585. }
  8586. ret = ath12k_mac_set_kickout(arvif);
  8587. if (ret) {
  8588. ath12k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n",
  8589. arvif->vdev_id, ret);
  8590. goto err_peer_del;
  8591. }
  8592. ath12k_mac_11d_scan_stop_all(ar->ab);
  8593. break;
  8594. case WMI_VDEV_TYPE_STA:
  8595. param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
  8596. param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  8597. ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  8598. param_id, param_value);
  8599. if (ret) {
  8600. ath12k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n",
  8601. arvif->vdev_id, ret);
  8602. goto err_peer_del;
  8603. }
  8604. param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
  8605. param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
  8606. ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  8607. param_id, param_value);
  8608. if (ret) {
  8609. ath12k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n",
  8610. arvif->vdev_id, ret);
  8611. goto err_peer_del;
  8612. }
  8613. param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT;
  8614. param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
  8615. ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  8616. param_id, param_value);
  8617. if (ret) {
  8618. ath12k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n",
  8619. arvif->vdev_id, ret);
  8620. goto err_peer_del;
  8621. }
  8622. ret = ath12k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, false);
  8623. if (ret) {
  8624. ath12k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n",
  8625. arvif->vdev_id, ret);
  8626. goto err_peer_del;
  8627. }
  8628. if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ab->wmi_ab.svc_map) &&
  8629. ahvif->vdev_type == WMI_VDEV_TYPE_STA &&
  8630. ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) {
  8631. reinit_completion(&ar->completed_11d_scan);
  8632. ar->state_11d = ATH12K_11D_PREPARING;
  8633. }
  8634. break;
  8635. case WMI_VDEV_TYPE_MONITOR:
  8636. ar->monitor_vdev_created = true;
  8637. break;
  8638. default:
  8639. break;
  8640. }
  8641. if (link_conf)
  8642. arvif->txpower = link_conf->txpower;
  8643. else
  8644. arvif->txpower = NL80211_TX_POWER_AUTOMATIC;
  8645. ret = ath12k_mac_txpower_recalc(ar);
  8646. if (ret)
  8647. goto err_peer_del;
  8648. param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
  8649. param_value = hw->wiphy->rts_threshold;
  8650. ar->rts_threshold = param_value;
  8651. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  8652. param_id, param_value);
  8653. if (ret) {
  8654. ath12k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n",
  8655. arvif->vdev_id, ret);
  8656. }
  8657. ath12k_dp_vdev_tx_attach(ar, arvif);
  8658. return ret;
  8659. err_peer_del:
  8660. if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) {
  8661. reinit_completion(&ar->peer_delete_done);
  8662. ret = ath12k_wmi_send_peer_delete_cmd(ar, arvif->bssid,
  8663. arvif->vdev_id);
  8664. if (ret) {
  8665. ath12k_warn(ar->ab, "failed to delete peer vdev_id %d addr %pM\n",
  8666. arvif->vdev_id, arvif->bssid);
  8667. goto err;
  8668. }
  8669. ret = ath12k_wait_for_peer_delete_done(ar, arvif->vdev_id,
  8670. arvif->bssid);
  8671. if (ret)
  8672. goto err_vdev_del;
  8673. ar->num_peers--;
  8674. }
  8675. err_dp_peer_del:
  8676. if (dp_peer_created)
  8677. ath12k_dp_peer_delete(&ah->dp_hw, arvif->bssid, NULL);
  8678. err_vdev_del:
  8679. if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
  8680. ar->monitor_vdev_id = -1;
  8681. ar->monitor_vdev_created = false;
  8682. }
  8683. ath12k_wmi_vdev_delete(ar, arvif->vdev_id);
  8684. ar->num_created_vdevs--;
  8685. arvif->is_created = false;
  8686. arvif->ar = NULL;
  8687. ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
  8688. ab->free_vdev_map |= 1LL << arvif->vdev_id;
  8689. ab->free_vdev_stats_id_map &= ~(1LL << arvif->vdev_stats_id);
  8690. spin_lock_bh(&ar->data_lock);
  8691. list_del(&arvif->list);
  8692. spin_unlock_bh(&ar->data_lock);
  8693. err:
  8694. arvif->ar = NULL;
  8695. return ret;
  8696. }
  8697. static void ath12k_mac_vif_flush_key_cache(struct ath12k_link_vif *arvif)
  8698. {
  8699. struct ath12k_key_conf *key_conf, *tmp;
  8700. struct ath12k_vif *ahvif = arvif->ahvif;
  8701. struct ath12k_hw *ah = ahvif->ah;
  8702. struct ath12k_sta *ahsta;
  8703. struct ath12k_link_sta *arsta;
  8704. struct ath12k_vif_cache *cache = ahvif->cache[arvif->link_id];
  8705. int ret;
  8706. lockdep_assert_wiphy(ah->hw->wiphy);
  8707. list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) {
  8708. arsta = NULL;
  8709. if (key_conf->sta) {
  8710. ahsta = ath12k_sta_to_ahsta(key_conf->sta);
  8711. arsta = wiphy_dereference(ah->hw->wiphy,
  8712. ahsta->link[arvif->link_id]);
  8713. if (!arsta)
  8714. goto free_cache;
  8715. }
  8716. ret = ath12k_mac_set_key(arvif->ar, key_conf->cmd,
  8717. arvif, arsta,
  8718. key_conf->key);
  8719. if (ret)
  8720. ath12k_warn(arvif->ar->ab, "unable to apply set key param to vdev %d ret %d\n",
  8721. arvif->vdev_id, ret);
  8722. free_cache:
  8723. list_del(&key_conf->list);
  8724. kfree(key_conf);
  8725. }
  8726. }
  8727. static void ath12k_mac_vif_cache_flush(struct ath12k *ar, struct ath12k_link_vif *arvif)
  8728. {
  8729. struct ath12k_vif *ahvif = arvif->ahvif;
  8730. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif);
  8731. struct ath12k_vif_cache *cache = ahvif->cache[arvif->link_id];
  8732. struct ath12k_base *ab = ar->ab;
  8733. struct ieee80211_bss_conf *link_conf;
  8734. int ret;
  8735. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  8736. if (!cache)
  8737. return;
  8738. if (cache->tx_conf.changed) {
  8739. ret = ath12k_mac_conf_tx(arvif, cache->tx_conf.ac,
  8740. &cache->tx_conf.tx_queue_params);
  8741. if (ret)
  8742. ath12k_warn(ab,
  8743. "unable to apply tx config parameters to vdev %d\n",
  8744. ret);
  8745. }
  8746. if (cache->bss_conf_changed) {
  8747. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  8748. if (!link_conf) {
  8749. ath12k_warn(ar->ab, "unable to access bss link conf in cache flush for vif %pM link %u\n",
  8750. vif->addr, arvif->link_id);
  8751. return;
  8752. }
  8753. ath12k_mac_bss_info_changed(ar, arvif, link_conf,
  8754. cache->bss_conf_changed);
  8755. }
  8756. if (!list_empty(&cache->key_conf.list))
  8757. ath12k_mac_vif_flush_key_cache(arvif);
  8758. ath12k_ahvif_put_link_cache(ahvif, arvif->link_id);
  8759. }
  8760. static struct ath12k *ath12k_mac_assign_vif_to_vdev(struct ieee80211_hw *hw,
  8761. struct ath12k_link_vif *arvif,
  8762. struct ieee80211_chanctx_conf *ctx)
  8763. {
  8764. struct ath12k_vif *ahvif = arvif->ahvif;
  8765. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif);
  8766. struct ath12k_link_vif *scan_arvif;
  8767. struct ath12k_hw *ah = hw->priv;
  8768. struct ath12k *ar;
  8769. struct ath12k_base *ab;
  8770. u8 link_id = arvif->link_id, scan_link_id;
  8771. unsigned long scan_link_map;
  8772. int ret;
  8773. lockdep_assert_wiphy(hw->wiphy);
  8774. if (ah->num_radio == 1)
  8775. ar = ah->radio;
  8776. else if (ctx)
  8777. ar = ath12k_get_ar_by_ctx(hw, ctx);
  8778. else
  8779. return NULL;
  8780. if (!ar)
  8781. return NULL;
  8782. /* cleanup the scan vdev if we are done scan on that ar
  8783. * and now we want to create for actual usage.
  8784. */
  8785. if (ieee80211_vif_is_mld(vif)) {
  8786. scan_link_map = ahvif->links_map & ATH12K_SCAN_LINKS_MASK;
  8787. for_each_set_bit(scan_link_id, &scan_link_map, ATH12K_NUM_MAX_LINKS) {
  8788. scan_arvif = wiphy_dereference(hw->wiphy,
  8789. ahvif->link[scan_link_id]);
  8790. if (scan_arvif && scan_arvif->ar == ar) {
  8791. ar->scan.arvif = NULL;
  8792. ath12k_mac_remove_link_interface(hw, scan_arvif);
  8793. ath12k_mac_unassign_link_vif(scan_arvif);
  8794. break;
  8795. }
  8796. }
  8797. }
  8798. if (arvif->ar) {
  8799. /* This is not expected really */
  8800. if (WARN_ON(!arvif->is_created)) {
  8801. arvif->ar = NULL;
  8802. return NULL;
  8803. }
  8804. if (ah->num_radio == 1)
  8805. return arvif->ar;
  8806. /* This can happen as scan vdev gets created during multiple scans
  8807. * across different radios before a vdev is brought up in
  8808. * a certain radio.
  8809. */
  8810. if (ar != arvif->ar) {
  8811. if (WARN_ON(arvif->is_started))
  8812. return NULL;
  8813. ath12k_mac_remove_link_interface(hw, arvif);
  8814. ath12k_mac_unassign_link_vif(arvif);
  8815. }
  8816. }
  8817. ab = ar->ab;
  8818. /* Assign arvif again here since previous radio switch block
  8819. * would've unassigned and cleared it.
  8820. */
  8821. arvif = ath12k_mac_assign_link_vif(ah, vif, link_id);
  8822. if (vif->type == NL80211_IFTYPE_AP &&
  8823. ar->num_peers > (ar->max_num_peers - 1)) {
  8824. ath12k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n");
  8825. goto unlock;
  8826. }
  8827. if (arvif->is_created)
  8828. goto flush;
  8829. ret = ath12k_mac_vdev_create(ar, arvif);
  8830. if (ret) {
  8831. ath12k_warn(ab, "failed to create vdev %pM ret %d", vif->addr, ret);
  8832. goto unlock;
  8833. }
  8834. flush:
  8835. /* If the vdev is created during channel assign and not during
  8836. * add_interface(), Apply any parameters for the vdev which were received
  8837. * after add_interface, corresponding to this vif.
  8838. */
  8839. ath12k_mac_vif_cache_flush(ar, arvif);
  8840. unlock:
  8841. return arvif->ar;
  8842. }
  8843. int ath12k_mac_op_add_interface(struct ieee80211_hw *hw,
  8844. struct ieee80211_vif *vif)
  8845. {
  8846. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  8847. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  8848. struct ath12k_reg_info *reg_info;
  8849. struct ath12k_link_vif *arvif;
  8850. struct ath12k_base *ab;
  8851. struct ath12k *ar;
  8852. int i;
  8853. lockdep_assert_wiphy(hw->wiphy);
  8854. memset(ahvif, 0, sizeof(*ahvif));
  8855. ahvif->ah = ah;
  8856. ahvif->vif = vif;
  8857. arvif = &ahvif->deflink;
  8858. ath12k_mac_init_arvif(ahvif, arvif, -1);
  8859. /* Allocate Default Queue now and reassign during actual vdev create */
  8860. vif->cab_queue = ATH12K_HW_DEFAULT_QUEUE;
  8861. for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
  8862. vif->hw_queue[i] = ATH12K_HW_DEFAULT_QUEUE;
  8863. vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
  8864. ath12k_mac_determine_vdev_type(vif, ahvif);
  8865. for_each_ar(ah, ar, i) {
  8866. if (!ath12k_wmi_supports_6ghz_cc_ext(ar))
  8867. continue;
  8868. ab = ar->ab;
  8869. reg_info = ab->reg_info[ar->pdev_idx];
  8870. ath12k_dbg(ab, ATH12K_DBG_MAC, "interface added to change reg rules\n");
  8871. ah->regd_updated = false;
  8872. ath12k_reg_handle_chan_list(ab, reg_info, ahvif->vdev_type,
  8873. IEEE80211_REG_UNSET_AP);
  8874. break;
  8875. }
  8876. /* Defer vdev creation until assign_chanctx or hw_scan is initiated as driver
  8877. * will not know if this interface is an ML vif at this point.
  8878. */
  8879. return 0;
  8880. }
  8881. EXPORT_SYMBOL(ath12k_mac_op_add_interface);
  8882. static void ath12k_mac_vif_unref(struct ath12k_dp *dp, struct ieee80211_vif *vif)
  8883. {
  8884. struct ath12k_tx_desc_info *tx_desc_info;
  8885. struct ath12k_skb_cb *skb_cb;
  8886. struct sk_buff *skb;
  8887. int i;
  8888. for (i = 0; i < ATH12K_HW_MAX_QUEUES; i++) {
  8889. spin_lock_bh(&dp->tx_desc_lock[i]);
  8890. list_for_each_entry(tx_desc_info, &dp->tx_desc_used_list[i],
  8891. list) {
  8892. skb = tx_desc_info->skb;
  8893. if (!skb)
  8894. continue;
  8895. skb_cb = ATH12K_SKB_CB(skb);
  8896. if (skb_cb->vif == vif)
  8897. skb_cb->vif = NULL;
  8898. }
  8899. spin_unlock_bh(&dp->tx_desc_lock[i]);
  8900. }
  8901. }
  8902. static int ath12k_mac_vdev_delete(struct ath12k *ar, struct ath12k_link_vif *arvif)
  8903. {
  8904. struct ath12k_vif *ahvif = arvif->ahvif;
  8905. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif);
  8906. struct ath12k_dp_link_vif *dp_link_vif;
  8907. struct ath12k_base *ab = ar->ab;
  8908. unsigned long time_left;
  8909. int ret;
  8910. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  8911. reinit_completion(&ar->vdev_delete_done);
  8912. ret = ath12k_wmi_vdev_delete(ar, arvif->vdev_id);
  8913. if (ret) {
  8914. ath12k_warn(ab, "failed to delete WMI vdev %d: %d\n",
  8915. arvif->vdev_id, ret);
  8916. goto err_vdev_del;
  8917. }
  8918. time_left = wait_for_completion_timeout(&ar->vdev_delete_done,
  8919. ATH12K_VDEV_DELETE_TIMEOUT_HZ);
  8920. if (time_left == 0) {
  8921. ath12k_warn(ab, "Timeout in receiving vdev delete response\n");
  8922. goto err_vdev_del;
  8923. }
  8924. ab->free_vdev_map |= 1LL << arvif->vdev_id;
  8925. ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
  8926. ar->num_created_vdevs--;
  8927. if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
  8928. ar->monitor_vdev_id = -1;
  8929. ar->monitor_vdev_created = false;
  8930. }
  8931. ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM deleted, vdev_id %d\n",
  8932. vif->addr, arvif->vdev_id);
  8933. err_vdev_del:
  8934. spin_lock_bh(&ar->data_lock);
  8935. list_del(&arvif->list);
  8936. spin_unlock_bh(&ar->data_lock);
  8937. ath12k_peer_cleanup(ar, arvif->vdev_id);
  8938. ath12k_ahvif_put_link_cache(ahvif, arvif->link_id);
  8939. idr_for_each(&ar->txmgmt_idr,
  8940. ath12k_mac_vif_txmgmt_idr_remove, vif);
  8941. ath12k_mac_vif_unref(ath12k_ab_to_dp(ab), vif);
  8942. dp_link_vif = ath12k_dp_vif_to_dp_link_vif(&ahvif->dp_vif, arvif->link_id);
  8943. ath12k_dp_tx_put_bank_profile(ath12k_ab_to_dp(ab), dp_link_vif->bank_id);
  8944. /* Recalc txpower for remaining vdev */
  8945. ath12k_mac_txpower_recalc(ar);
  8946. /* TODO: recal traffic pause state based on the available vdevs */
  8947. arvif->is_created = false;
  8948. arvif->ar = NULL;
  8949. return ret;
  8950. }
  8951. void ath12k_mac_op_remove_interface(struct ieee80211_hw *hw,
  8952. struct ieee80211_vif *vif)
  8953. {
  8954. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  8955. struct ath12k_link_vif *arvif;
  8956. struct ath12k *ar;
  8957. u8 link_id;
  8958. lockdep_assert_wiphy(hw->wiphy);
  8959. for (link_id = 0; link_id < ATH12K_NUM_MAX_LINKS; link_id++) {
  8960. /* if we cached some config but never received assign chanctx,
  8961. * free the allocated cache.
  8962. */
  8963. ath12k_ahvif_put_link_cache(ahvif, link_id);
  8964. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  8965. if (!arvif || !arvif->is_created)
  8966. continue;
  8967. ar = arvif->ar;
  8968. /* Scan abortion is in progress since before this, cancel_hw_scan()
  8969. * is expected to be executed. Since link is anyways going to be removed
  8970. * now, just cancel the worker and send the scan aborted to user space
  8971. */
  8972. if (ar->scan.arvif == arvif) {
  8973. wiphy_work_cancel(hw->wiphy, &ar->scan.vdev_clean_wk);
  8974. spin_lock_bh(&ar->data_lock);
  8975. ar->scan.arvif = NULL;
  8976. if (!ar->scan.is_roc) {
  8977. struct cfg80211_scan_info info = {
  8978. .aborted = true,
  8979. };
  8980. ath12k_mac_scan_send_complete(ar, &info);
  8981. }
  8982. ar->scan.state = ATH12K_SCAN_IDLE;
  8983. ar->scan_channel = NULL;
  8984. ar->scan.roc_freq = 0;
  8985. spin_unlock_bh(&ar->data_lock);
  8986. }
  8987. ath12k_mac_remove_link_interface(hw, arvif);
  8988. ath12k_mac_unassign_link_vif(arvif);
  8989. }
  8990. }
  8991. EXPORT_SYMBOL(ath12k_mac_op_remove_interface);
  8992. /* FIXME: Has to be verified. */
  8993. #define SUPPORTED_FILTERS \
  8994. (FIF_ALLMULTI | \
  8995. FIF_CONTROL | \
  8996. FIF_PSPOLL | \
  8997. FIF_OTHER_BSS | \
  8998. FIF_BCN_PRBRESP_PROMISC | \
  8999. FIF_PROBE_REQ | \
  9000. FIF_FCSFAIL)
  9001. void ath12k_mac_op_configure_filter(struct ieee80211_hw *hw,
  9002. unsigned int changed_flags,
  9003. unsigned int *total_flags,
  9004. u64 multicast)
  9005. {
  9006. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  9007. struct ath12k *ar;
  9008. lockdep_assert_wiphy(hw->wiphy);
  9009. ar = ath12k_ah_to_ar(ah, 0);
  9010. *total_flags &= SUPPORTED_FILTERS;
  9011. ar->filter_flags = *total_flags;
  9012. }
  9013. EXPORT_SYMBOL(ath12k_mac_op_configure_filter);
  9014. int ath12k_mac_op_get_antenna(struct ieee80211_hw *hw, int radio_idx,
  9015. u32 *tx_ant, u32 *rx_ant)
  9016. {
  9017. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  9018. int antennas_rx = 0, antennas_tx = 0;
  9019. struct ath12k *ar;
  9020. int i;
  9021. lockdep_assert_wiphy(hw->wiphy);
  9022. for_each_ar(ah, ar, i) {
  9023. antennas_rx = max_t(u32, antennas_rx, ar->cfg_rx_chainmask);
  9024. antennas_tx = max_t(u32, antennas_tx, ar->cfg_tx_chainmask);
  9025. }
  9026. *tx_ant = antennas_tx;
  9027. *rx_ant = antennas_rx;
  9028. return 0;
  9029. }
  9030. EXPORT_SYMBOL(ath12k_mac_op_get_antenna);
  9031. int ath12k_mac_op_set_antenna(struct ieee80211_hw *hw, int radio_idx,
  9032. u32 tx_ant, u32 rx_ant)
  9033. {
  9034. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  9035. struct ath12k *ar;
  9036. int ret = 0;
  9037. int i;
  9038. lockdep_assert_wiphy(hw->wiphy);
  9039. for_each_ar(ah, ar, i) {
  9040. ret = __ath12k_set_antenna(ar, tx_ant, rx_ant);
  9041. if (ret)
  9042. break;
  9043. }
  9044. return ret;
  9045. }
  9046. EXPORT_SYMBOL(ath12k_mac_op_set_antenna);
  9047. static int ath12k_mac_ampdu_action(struct ieee80211_hw *hw,
  9048. struct ieee80211_vif *vif,
  9049. struct ieee80211_ampdu_params *params,
  9050. u8 link_id)
  9051. {
  9052. struct ath12k *ar;
  9053. int ret = -EINVAL;
  9054. lockdep_assert_wiphy(hw->wiphy);
  9055. ar = ath12k_get_ar_by_vif(hw, vif, link_id);
  9056. if (!ar)
  9057. return -EINVAL;
  9058. switch (params->action) {
  9059. case IEEE80211_AMPDU_RX_START:
  9060. ret = ath12k_dp_rx_ampdu_start(ar, params, link_id);
  9061. break;
  9062. case IEEE80211_AMPDU_RX_STOP:
  9063. ret = ath12k_dp_rx_ampdu_stop(ar, params, link_id);
  9064. break;
  9065. case IEEE80211_AMPDU_TX_START:
  9066. case IEEE80211_AMPDU_TX_STOP_CONT:
  9067. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  9068. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  9069. case IEEE80211_AMPDU_TX_OPERATIONAL:
  9070. /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211
  9071. * Tx aggregation requests.
  9072. */
  9073. ret = -EOPNOTSUPP;
  9074. break;
  9075. }
  9076. if (ret)
  9077. ath12k_warn(ar->ab, "unable to perform ampdu action %d for vif %pM link %u ret %d\n",
  9078. params->action, vif->addr, link_id, ret);
  9079. return ret;
  9080. }
  9081. int ath12k_mac_op_ampdu_action(struct ieee80211_hw *hw,
  9082. struct ieee80211_vif *vif,
  9083. struct ieee80211_ampdu_params *params)
  9084. {
  9085. struct ieee80211_sta *sta = params->sta;
  9086. struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta);
  9087. unsigned long links_map = ahsta->links_map;
  9088. int ret = -EINVAL;
  9089. u8 link_id;
  9090. lockdep_assert_wiphy(hw->wiphy);
  9091. if (WARN_ON(!links_map))
  9092. return ret;
  9093. for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) {
  9094. ret = ath12k_mac_ampdu_action(hw, vif, params, link_id);
  9095. if (ret)
  9096. return ret;
  9097. }
  9098. return 0;
  9099. }
  9100. EXPORT_SYMBOL(ath12k_mac_op_ampdu_action);
  9101. int ath12k_mac_op_add_chanctx(struct ieee80211_hw *hw,
  9102. struct ieee80211_chanctx_conf *ctx)
  9103. {
  9104. struct ath12k *ar;
  9105. struct ath12k_base *ab;
  9106. lockdep_assert_wiphy(hw->wiphy);
  9107. ar = ath12k_get_ar_by_ctx(hw, ctx);
  9108. if (!ar)
  9109. return -EINVAL;
  9110. ab = ar->ab;
  9111. ath12k_dbg(ab, ATH12K_DBG_MAC,
  9112. "mac chanctx add freq %u width %d ptr %p\n",
  9113. ctx->def.chan->center_freq, ctx->def.width, ctx);
  9114. spin_lock_bh(&ar->data_lock);
  9115. /* TODO: In case of multiple channel context, populate rx_channel from
  9116. * Rx PPDU desc information.
  9117. */
  9118. ar->rx_channel = ctx->def.chan;
  9119. spin_unlock_bh(&ar->data_lock);
  9120. ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID;
  9121. return 0;
  9122. }
  9123. EXPORT_SYMBOL(ath12k_mac_op_add_chanctx);
  9124. void ath12k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
  9125. struct ieee80211_chanctx_conf *ctx)
  9126. {
  9127. struct ath12k *ar;
  9128. struct ath12k_base *ab;
  9129. lockdep_assert_wiphy(hw->wiphy);
  9130. ar = ath12k_get_ar_by_ctx(hw, ctx);
  9131. if (!ar)
  9132. return;
  9133. ab = ar->ab;
  9134. ath12k_dbg(ab, ATH12K_DBG_MAC,
  9135. "mac chanctx remove freq %u width %d ptr %p\n",
  9136. ctx->def.chan->center_freq, ctx->def.width, ctx);
  9137. spin_lock_bh(&ar->data_lock);
  9138. /* TODO: In case of there is one more channel context left, populate
  9139. * rx_channel with the channel of that remaining channel context.
  9140. */
  9141. ar->rx_channel = NULL;
  9142. spin_unlock_bh(&ar->data_lock);
  9143. ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID;
  9144. }
  9145. EXPORT_SYMBOL(ath12k_mac_op_remove_chanctx);
  9146. static enum wmi_phy_mode
  9147. ath12k_mac_check_down_grade_phy_mode(struct ath12k *ar,
  9148. enum wmi_phy_mode mode,
  9149. enum nl80211_band band,
  9150. enum nl80211_iftype type)
  9151. {
  9152. struct ieee80211_sta_eht_cap *eht_cap = NULL;
  9153. enum wmi_phy_mode down_mode;
  9154. int n = ar->mac.sbands[band].n_iftype_data;
  9155. int i;
  9156. struct ieee80211_sband_iftype_data *data;
  9157. if (mode < MODE_11BE_EHT20)
  9158. return mode;
  9159. data = ar->mac.iftype[band];
  9160. for (i = 0; i < n; i++) {
  9161. if (data[i].types_mask & BIT(type)) {
  9162. eht_cap = &data[i].eht_cap;
  9163. break;
  9164. }
  9165. }
  9166. if (eht_cap && eht_cap->has_eht)
  9167. return mode;
  9168. switch (mode) {
  9169. case MODE_11BE_EHT20:
  9170. down_mode = MODE_11AX_HE20;
  9171. break;
  9172. case MODE_11BE_EHT40:
  9173. down_mode = MODE_11AX_HE40;
  9174. break;
  9175. case MODE_11BE_EHT80:
  9176. down_mode = MODE_11AX_HE80;
  9177. break;
  9178. case MODE_11BE_EHT80_80:
  9179. down_mode = MODE_11AX_HE80_80;
  9180. break;
  9181. case MODE_11BE_EHT160:
  9182. case MODE_11BE_EHT160_160:
  9183. case MODE_11BE_EHT320:
  9184. down_mode = MODE_11AX_HE160;
  9185. break;
  9186. case MODE_11BE_EHT20_2G:
  9187. down_mode = MODE_11AX_HE20_2G;
  9188. break;
  9189. case MODE_11BE_EHT40_2G:
  9190. down_mode = MODE_11AX_HE40_2G;
  9191. break;
  9192. default:
  9193. down_mode = mode;
  9194. break;
  9195. }
  9196. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  9197. "mac vdev start phymode %s downgrade to %s\n",
  9198. ath12k_mac_phymode_str(mode),
  9199. ath12k_mac_phymode_str(down_mode));
  9200. return down_mode;
  9201. }
  9202. static void
  9203. ath12k_mac_mlo_get_vdev_args(struct ath12k_link_vif *arvif,
  9204. struct wmi_ml_arg *ml_arg)
  9205. {
  9206. struct ath12k_vif *ahvif = arvif->ahvif;
  9207. struct wmi_ml_partner_info *partner_info;
  9208. struct ieee80211_bss_conf *link_conf;
  9209. struct ath12k_link_vif *arvif_p;
  9210. unsigned long links;
  9211. u8 link_id;
  9212. lockdep_assert_wiphy(ahvif->ah->hw->wiphy);
  9213. if (!ath12k_mac_is_ml_arvif(arvif))
  9214. return;
  9215. if (hweight16(ahvif->vif->valid_links) > ATH12K_WMI_MLO_MAX_LINKS)
  9216. return;
  9217. ml_arg->enabled = true;
  9218. /* Driver always add a new link via VDEV START, FW takes
  9219. * care of internally adding this link to existing
  9220. * link vdevs which are advertised as partners below
  9221. */
  9222. ml_arg->link_add = true;
  9223. ml_arg->assoc_link = arvif->is_sta_assoc_link;
  9224. partner_info = ml_arg->partner_info;
  9225. links = ahvif->links_map;
  9226. for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
  9227. arvif_p = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]);
  9228. if (WARN_ON(!arvif_p))
  9229. continue;
  9230. if (arvif == arvif_p)
  9231. continue;
  9232. if (!arvif_p->is_created)
  9233. continue;
  9234. link_conf = wiphy_dereference(ahvif->ah->hw->wiphy,
  9235. ahvif->vif->link_conf[arvif_p->link_id]);
  9236. if (!link_conf)
  9237. continue;
  9238. partner_info->vdev_id = arvif_p->vdev_id;
  9239. partner_info->hw_link_id = arvif_p->ar->pdev->hw_link_id;
  9240. ether_addr_copy(partner_info->addr, link_conf->addr);
  9241. ml_arg->num_partner_links++;
  9242. partner_info++;
  9243. }
  9244. }
  9245. static int
  9246. ath12k_mac_vdev_start_restart(struct ath12k_link_vif *arvif,
  9247. struct ieee80211_chanctx_conf *ctx,
  9248. bool restart)
  9249. {
  9250. struct ath12k *ar = arvif->ar;
  9251. struct ath12k_base *ab = ar->ab;
  9252. struct wmi_vdev_start_req_arg arg = {};
  9253. const struct cfg80211_chan_def *chandef = &ctx->def;
  9254. struct ieee80211_hw *hw = ath12k_ar_to_hw(ar);
  9255. struct ath12k_vif *ahvif = arvif->ahvif;
  9256. struct ieee80211_bss_conf *link_conf;
  9257. unsigned int dfs_cac_time;
  9258. int ret;
  9259. lockdep_assert_wiphy(hw->wiphy);
  9260. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  9261. if (!link_conf) {
  9262. ath12k_warn(ar->ab, "unable to access bss link conf in vdev start for vif %pM link %u\n",
  9263. ahvif->vif->addr, arvif->link_id);
  9264. return -ENOLINK;
  9265. }
  9266. reinit_completion(&ar->vdev_setup_done);
  9267. arg.vdev_id = arvif->vdev_id;
  9268. arg.dtim_period = arvif->dtim_period;
  9269. arg.bcn_intval = arvif->beacon_interval;
  9270. arg.punct_bitmap = ~arvif->punct_bitmap;
  9271. arg.freq = chandef->chan->center_freq;
  9272. arg.band_center_freq1 = chandef->center_freq1;
  9273. arg.band_center_freq2 = chandef->center_freq2;
  9274. arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width];
  9275. arg.mode = ath12k_mac_check_down_grade_phy_mode(ar, arg.mode,
  9276. chandef->chan->band,
  9277. ahvif->vif->type);
  9278. arg.min_power = 0;
  9279. arg.max_power = chandef->chan->max_power;
  9280. arg.max_reg_power = chandef->chan->max_reg_power;
  9281. arg.max_antenna_gain = chandef->chan->max_antenna_gain;
  9282. arg.pref_tx_streams = ar->num_tx_chains;
  9283. arg.pref_rx_streams = ar->num_rx_chains;
  9284. arg.mbssid_flags = WMI_VDEV_MBSSID_FLAGS_NON_MBSSID_AP;
  9285. arg.mbssid_tx_vdev_id = 0;
  9286. if (test_bit(WMI_TLV_SERVICE_MBSS_PARAM_IN_VDEV_START_SUPPORT,
  9287. ar->ab->wmi_ab.svc_map)) {
  9288. ret = ath12k_mac_setup_vdev_params_mbssid(arvif,
  9289. &arg.mbssid_flags,
  9290. &arg.mbssid_tx_vdev_id);
  9291. if (ret)
  9292. return ret;
  9293. }
  9294. if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) {
  9295. arg.ssid = ahvif->u.ap.ssid;
  9296. arg.ssid_len = ahvif->u.ap.ssid_len;
  9297. arg.hidden_ssid = ahvif->u.ap.hidden_ssid;
  9298. /* For now allow DFS for AP mode */
  9299. arg.chan_radar = !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
  9300. arg.freq2_radar = ctx->radar_enabled;
  9301. arg.passive = arg.chan_radar;
  9302. spin_lock_bh(&ab->base_lock);
  9303. arg.regdomain = ar->ab->dfs_region;
  9304. spin_unlock_bh(&ab->base_lock);
  9305. /* TODO: Notify if secondary 80Mhz also needs radar detection */
  9306. }
  9307. arg.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR);
  9308. if (!restart)
  9309. ath12k_mac_mlo_get_vdev_args(arvif, &arg.ml);
  9310. ath12k_dbg(ab, ATH12K_DBG_MAC,
  9311. "mac vdev %d start center_freq %d phymode %s punct_bitmap 0x%x\n",
  9312. arg.vdev_id, arg.freq,
  9313. ath12k_mac_phymode_str(arg.mode), arg.punct_bitmap);
  9314. ret = ath12k_wmi_vdev_start(ar, &arg, restart);
  9315. if (ret) {
  9316. ath12k_warn(ar->ab, "failed to %s WMI vdev %i\n",
  9317. restart ? "restart" : "start", arg.vdev_id);
  9318. return ret;
  9319. }
  9320. ret = ath12k_mac_vdev_setup_sync(ar);
  9321. if (ret) {
  9322. ath12k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n",
  9323. arg.vdev_id, restart ? "restart" : "start", ret);
  9324. return ret;
  9325. }
  9326. /* TODO: For now we only set TPC power here. However when
  9327. * channel changes, say CSA, it should be updated again.
  9328. */
  9329. if (ath12k_mac_supports_tpc(ar, ahvif, chandef)) {
  9330. ath12k_mac_fill_reg_tpc_info(ar, arvif, ctx);
  9331. ath12k_wmi_send_vdev_set_tpc_power(ar, arvif->vdev_id,
  9332. &arvif->reg_tpc_info);
  9333. }
  9334. ar->num_started_vdevs++;
  9335. ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM started, vdev_id %d\n",
  9336. ahvif->vif->addr, arvif->vdev_id);
  9337. /* Enable CAC Running Flag in the driver by checking all sub-channel's DFS
  9338. * state as NL80211_DFS_USABLE which indicates CAC needs to be
  9339. * done before channel usage. This flag is used to drop rx packets.
  9340. * during CAC.
  9341. */
  9342. /* TODO: Set the flag for other interface types as required */
  9343. if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP && ctx->radar_enabled &&
  9344. cfg80211_chandef_dfs_usable(hw->wiphy, chandef)) {
  9345. set_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags);
  9346. dfs_cac_time = cfg80211_chandef_dfs_cac_time(hw->wiphy, chandef);
  9347. ath12k_dbg(ab, ATH12K_DBG_MAC,
  9348. "CAC started dfs_cac_time %u center_freq %d center_freq1 %d for vdev %d\n",
  9349. dfs_cac_time, arg.freq, arg.band_center_freq1, arg.vdev_id);
  9350. }
  9351. ret = ath12k_mac_set_txbf_conf(arvif);
  9352. if (ret)
  9353. ath12k_warn(ab, "failed to set txbf conf for vdev %d: %d\n",
  9354. arvif->vdev_id, ret);
  9355. return 0;
  9356. }
  9357. static int ath12k_mac_vdev_start(struct ath12k_link_vif *arvif,
  9358. struct ieee80211_chanctx_conf *ctx)
  9359. {
  9360. return ath12k_mac_vdev_start_restart(arvif, ctx, false);
  9361. }
  9362. static int ath12k_mac_vdev_restart(struct ath12k_link_vif *arvif,
  9363. struct ieee80211_chanctx_conf *ctx)
  9364. {
  9365. return ath12k_mac_vdev_start_restart(arvif, ctx, true);
  9366. }
  9367. struct ath12k_mac_change_chanctx_arg {
  9368. struct ieee80211_chanctx_conf *ctx;
  9369. struct ieee80211_vif_chanctx_switch *vifs;
  9370. int n_vifs;
  9371. int next_vif;
  9372. struct ath12k *ar;
  9373. };
  9374. static void
  9375. ath12k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
  9376. struct ieee80211_vif *vif)
  9377. {
  9378. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  9379. struct ath12k_mac_change_chanctx_arg *arg = data;
  9380. struct ieee80211_bss_conf *link_conf;
  9381. struct ath12k_link_vif *arvif;
  9382. unsigned long links_map;
  9383. u8 link_id;
  9384. lockdep_assert_wiphy(ahvif->ah->hw->wiphy);
  9385. links_map = ahvif->links_map;
  9386. for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) {
  9387. arvif = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]);
  9388. if (WARN_ON(!arvif))
  9389. continue;
  9390. if (!arvif->is_created || arvif->ar != arg->ar)
  9391. continue;
  9392. link_conf = wiphy_dereference(ahvif->ah->hw->wiphy,
  9393. vif->link_conf[link_id]);
  9394. if (WARN_ON(!link_conf))
  9395. continue;
  9396. if (rcu_access_pointer(link_conf->chanctx_conf) != arg->ctx)
  9397. continue;
  9398. arg->n_vifs++;
  9399. }
  9400. }
  9401. static void
  9402. ath12k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
  9403. struct ieee80211_vif *vif)
  9404. {
  9405. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  9406. struct ath12k_mac_change_chanctx_arg *arg = data;
  9407. struct ieee80211_bss_conf *link_conf;
  9408. struct ieee80211_chanctx_conf *ctx;
  9409. struct ath12k_link_vif *arvif;
  9410. unsigned long links_map;
  9411. u8 link_id;
  9412. lockdep_assert_wiphy(ahvif->ah->hw->wiphy);
  9413. links_map = ahvif->links_map;
  9414. for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) {
  9415. arvif = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]);
  9416. if (WARN_ON(!arvif))
  9417. continue;
  9418. if (!arvif->is_created || arvif->ar != arg->ar)
  9419. continue;
  9420. link_conf = wiphy_dereference(ahvif->ah->hw->wiphy,
  9421. vif->link_conf[arvif->link_id]);
  9422. if (WARN_ON(!link_conf))
  9423. continue;
  9424. ctx = rcu_access_pointer(link_conf->chanctx_conf);
  9425. if (ctx != arg->ctx)
  9426. continue;
  9427. if (WARN_ON(arg->next_vif == arg->n_vifs))
  9428. return;
  9429. arg->vifs[arg->next_vif].vif = vif;
  9430. arg->vifs[arg->next_vif].old_ctx = ctx;
  9431. arg->vifs[arg->next_vif].new_ctx = ctx;
  9432. arg->vifs[arg->next_vif].link_conf = link_conf;
  9433. arg->next_vif++;
  9434. }
  9435. }
  9436. static u32 ath12k_mac_nlwidth_to_wmiwidth(enum nl80211_chan_width width)
  9437. {
  9438. switch (width) {
  9439. case NL80211_CHAN_WIDTH_20:
  9440. return WMI_CHAN_WIDTH_20;
  9441. case NL80211_CHAN_WIDTH_40:
  9442. return WMI_CHAN_WIDTH_40;
  9443. case NL80211_CHAN_WIDTH_80:
  9444. return WMI_CHAN_WIDTH_80;
  9445. case NL80211_CHAN_WIDTH_160:
  9446. return WMI_CHAN_WIDTH_160;
  9447. case NL80211_CHAN_WIDTH_80P80:
  9448. return WMI_CHAN_WIDTH_80P80;
  9449. case NL80211_CHAN_WIDTH_5:
  9450. return WMI_CHAN_WIDTH_5;
  9451. case NL80211_CHAN_WIDTH_10:
  9452. return WMI_CHAN_WIDTH_10;
  9453. case NL80211_CHAN_WIDTH_320:
  9454. return WMI_CHAN_WIDTH_320;
  9455. default:
  9456. WARN_ON(1);
  9457. return WMI_CHAN_WIDTH_20;
  9458. }
  9459. }
  9460. static int ath12k_mac_update_peer_puncturing_width(struct ath12k *ar,
  9461. struct ath12k_link_vif *arvif,
  9462. struct cfg80211_chan_def def)
  9463. {
  9464. u32 param_id, param_value;
  9465. int ret;
  9466. if (arvif->ahvif->vdev_type != WMI_VDEV_TYPE_STA)
  9467. return 0;
  9468. param_id = WMI_PEER_CHWIDTH_PUNCTURE_20MHZ_BITMAP;
  9469. param_value = ath12k_mac_nlwidth_to_wmiwidth(def.width) |
  9470. u32_encode_bits((~def.punctured),
  9471. WMI_PEER_PUNCTURE_BITMAP);
  9472. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  9473. "punctured bitmap %02x width %d vdev %d\n",
  9474. def.punctured, def.width, arvif->vdev_id);
  9475. ret = ath12k_wmi_set_peer_param(ar, arvif->bssid,
  9476. arvif->vdev_id, param_id,
  9477. param_value);
  9478. return ret;
  9479. }
  9480. static void
  9481. ath12k_mac_update_vif_chan(struct ath12k *ar,
  9482. struct ieee80211_vif_chanctx_switch *vifs,
  9483. int n_vifs)
  9484. {
  9485. struct ath12k_wmi_vdev_up_params params = {};
  9486. struct ieee80211_bss_conf *link_conf;
  9487. struct ath12k_base *ab = ar->ab;
  9488. struct ath12k_link_vif *arvif;
  9489. struct ieee80211_vif *vif;
  9490. struct ath12k_vif *ahvif;
  9491. u8 link_id;
  9492. int ret;
  9493. int i;
  9494. bool monitor_vif = false;
  9495. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  9496. for (i = 0; i < n_vifs; i++) {
  9497. vif = vifs[i].vif;
  9498. ahvif = ath12k_vif_to_ahvif(vif);
  9499. link_conf = vifs[i].link_conf;
  9500. link_id = link_conf->link_id;
  9501. arvif = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy,
  9502. ahvif->link[link_id]);
  9503. if (vif->type == NL80211_IFTYPE_MONITOR) {
  9504. monitor_vif = true;
  9505. continue;
  9506. }
  9507. ath12k_dbg(ab, ATH12K_DBG_MAC,
  9508. "mac chanctx switch vdev_id %i freq %u->%u width %d->%d\n",
  9509. arvif->vdev_id,
  9510. vifs[i].old_ctx->def.chan->center_freq,
  9511. vifs[i].new_ctx->def.chan->center_freq,
  9512. vifs[i].old_ctx->def.width,
  9513. vifs[i].new_ctx->def.width);
  9514. if (WARN_ON(!arvif->is_started))
  9515. continue;
  9516. arvif->punct_bitmap = vifs[i].new_ctx->def.punctured;
  9517. /* Firmware expect vdev_restart only if vdev is up.
  9518. * If vdev is down then it expect vdev_stop->vdev_start.
  9519. */
  9520. if (arvif->is_up) {
  9521. ret = ath12k_mac_vdev_restart(arvif, vifs[i].new_ctx);
  9522. if (ret) {
  9523. ath12k_warn(ab, "failed to restart vdev %d: %d\n",
  9524. arvif->vdev_id, ret);
  9525. continue;
  9526. }
  9527. } else {
  9528. ret = ath12k_mac_vdev_stop(arvif);
  9529. if (ret) {
  9530. ath12k_warn(ab, "failed to stop vdev %d: %d\n",
  9531. arvif->vdev_id, ret);
  9532. continue;
  9533. }
  9534. ret = ath12k_mac_vdev_start(arvif, vifs[i].new_ctx);
  9535. if (ret)
  9536. ath12k_warn(ab, "failed to start vdev %d: %d\n",
  9537. arvif->vdev_id, ret);
  9538. continue;
  9539. }
  9540. ret = ath12k_mac_update_peer_puncturing_width(arvif->ar, arvif,
  9541. vifs[i].new_ctx->def);
  9542. if (ret) {
  9543. ath12k_warn(ar->ab,
  9544. "failed to update puncturing bitmap %02x and width %d: %d\n",
  9545. vifs[i].new_ctx->def.punctured,
  9546. vifs[i].new_ctx->def.width, ret);
  9547. continue;
  9548. }
  9549. /* Defer VDEV bring-up during CSA to avoid installing stale
  9550. * beacon templates. The beacon content is updated only
  9551. * after CSA finalize, so we mark CSA in progress and skip
  9552. * VDEV_UP for now. It will be handled later in
  9553. * bss_info_changed().
  9554. */
  9555. if (link_conf->csa_active &&
  9556. arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP) {
  9557. arvif->is_csa_in_progress = true;
  9558. continue;
  9559. }
  9560. ret = ath12k_mac_setup_bcn_tmpl(arvif);
  9561. if (ret)
  9562. ath12k_warn(ab, "failed to update bcn tmpl during csa: %d\n",
  9563. ret);
  9564. memset(&params, 0, sizeof(params));
  9565. params.vdev_id = arvif->vdev_id;
  9566. params.aid = ahvif->aid;
  9567. params.bssid = arvif->bssid;
  9568. params.tx_bssid = ath12k_mac_get_tx_bssid(arvif);
  9569. if (params.tx_bssid) {
  9570. params.nontx_profile_idx = link_conf->bssid_index;
  9571. params.nontx_profile_cnt = 1 << link_conf->bssid_indicator;
  9572. }
  9573. ret = ath12k_wmi_vdev_up(arvif->ar, &params);
  9574. if (ret) {
  9575. ath12k_warn(ab, "failed to bring vdev up %d: %d\n",
  9576. arvif->vdev_id, ret);
  9577. continue;
  9578. }
  9579. }
  9580. /* Restart the internal monitor vdev on new channel */
  9581. if (!monitor_vif && ar->monitor_vdev_created) {
  9582. if (!ath12k_mac_monitor_stop(ar))
  9583. ath12k_mac_monitor_start(ar);
  9584. }
  9585. }
  9586. static void
  9587. ath12k_mac_update_active_vif_chan(struct ath12k *ar,
  9588. struct ieee80211_chanctx_conf *ctx)
  9589. {
  9590. struct ath12k_mac_change_chanctx_arg arg = { .ctx = ctx, .ar = ar };
  9591. struct ieee80211_hw *hw = ath12k_ar_to_hw(ar);
  9592. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  9593. ieee80211_iterate_active_interfaces_atomic(hw,
  9594. IEEE80211_IFACE_ITER_NORMAL,
  9595. ath12k_mac_change_chanctx_cnt_iter,
  9596. &arg);
  9597. if (arg.n_vifs == 0)
  9598. return;
  9599. arg.vifs = kzalloc_objs(arg.vifs[0], arg.n_vifs);
  9600. if (!arg.vifs)
  9601. return;
  9602. ieee80211_iterate_active_interfaces_atomic(hw,
  9603. IEEE80211_IFACE_ITER_NORMAL,
  9604. ath12k_mac_change_chanctx_fill_iter,
  9605. &arg);
  9606. ath12k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
  9607. kfree(arg.vifs);
  9608. }
  9609. void ath12k_mac_op_change_chanctx(struct ieee80211_hw *hw,
  9610. struct ieee80211_chanctx_conf *ctx,
  9611. u32 changed)
  9612. {
  9613. struct ath12k *ar;
  9614. struct ath12k_base *ab;
  9615. lockdep_assert_wiphy(hw->wiphy);
  9616. ar = ath12k_get_ar_by_ctx(hw, ctx);
  9617. if (!ar)
  9618. return;
  9619. ab = ar->ab;
  9620. ath12k_dbg(ab, ATH12K_DBG_MAC,
  9621. "mac chanctx change freq %u width %d ptr %p changed %x\n",
  9622. ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
  9623. /* This shouldn't really happen because channel switching should use
  9624. * switch_vif_chanctx().
  9625. */
  9626. if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
  9627. return;
  9628. if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH ||
  9629. changed & IEEE80211_CHANCTX_CHANGE_RADAR ||
  9630. changed & IEEE80211_CHANCTX_CHANGE_PUNCTURING)
  9631. ath12k_mac_update_active_vif_chan(ar, ctx);
  9632. /* TODO: Recalc radar detection */
  9633. }
  9634. EXPORT_SYMBOL(ath12k_mac_op_change_chanctx);
  9635. static int ath12k_start_vdev_delay(struct ath12k *ar,
  9636. struct ath12k_link_vif *arvif)
  9637. {
  9638. struct ath12k_base *ab = ar->ab;
  9639. struct ath12k_vif *ahvif = arvif->ahvif;
  9640. struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif);
  9641. struct ieee80211_chanctx_conf *chanctx;
  9642. struct ieee80211_bss_conf *link_conf;
  9643. int ret;
  9644. if (WARN_ON(arvif->is_started))
  9645. return -EBUSY;
  9646. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  9647. if (!link_conf) {
  9648. ath12k_warn(ab, "failed to get link conf for vdev %u\n", arvif->vdev_id);
  9649. return -EINVAL;
  9650. }
  9651. chanctx = wiphy_dereference(ath12k_ar_to_hw(arvif->ar)->wiphy,
  9652. link_conf->chanctx_conf);
  9653. ret = ath12k_mac_vdev_start(arvif, chanctx);
  9654. if (ret) {
  9655. ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
  9656. arvif->vdev_id, vif->addr,
  9657. chanctx->def.chan->center_freq, ret);
  9658. return ret;
  9659. }
  9660. if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
  9661. ret = ath12k_monitor_vdev_up(ar, arvif->vdev_id);
  9662. if (ret) {
  9663. ath12k_warn(ab, "failed put monitor up: %d\n", ret);
  9664. return ret;
  9665. }
  9666. }
  9667. arvif->is_started = true;
  9668. /* TODO: Setup ps and cts/rts protection */
  9669. return 0;
  9670. }
  9671. static u8 ath12k_mac_get_num_pwr_levels(struct cfg80211_chan_def *chan_def)
  9672. {
  9673. if (chan_def->chan->flags & IEEE80211_CHAN_PSD) {
  9674. switch (chan_def->width) {
  9675. case NL80211_CHAN_WIDTH_20:
  9676. return 1;
  9677. case NL80211_CHAN_WIDTH_40:
  9678. return 2;
  9679. case NL80211_CHAN_WIDTH_80:
  9680. return 4;
  9681. case NL80211_CHAN_WIDTH_160:
  9682. return 8;
  9683. case NL80211_CHAN_WIDTH_320:
  9684. return 16;
  9685. default:
  9686. return 1;
  9687. }
  9688. } else {
  9689. switch (chan_def->width) {
  9690. case NL80211_CHAN_WIDTH_20:
  9691. return 1;
  9692. case NL80211_CHAN_WIDTH_40:
  9693. return 2;
  9694. case NL80211_CHAN_WIDTH_80:
  9695. return 3;
  9696. case NL80211_CHAN_WIDTH_160:
  9697. return 4;
  9698. case NL80211_CHAN_WIDTH_320:
  9699. return 5;
  9700. default:
  9701. return 1;
  9702. }
  9703. }
  9704. }
  9705. static u16 ath12k_mac_get_6ghz_start_frequency(struct cfg80211_chan_def *chan_def)
  9706. {
  9707. u16 diff_seq;
  9708. /* It is to get the lowest channel number's center frequency of the chan.
  9709. * For example,
  9710. * bandwidth=40 MHz, center frequency is 5965, lowest channel is 1
  9711. * with center frequency 5955, its diff is 5965 - 5955 = 10.
  9712. * bandwidth=80 MHz, center frequency is 5985, lowest channel is 1
  9713. * with center frequency 5955, its diff is 5985 - 5955 = 30.
  9714. * bandwidth=160 MHz, center frequency is 6025, lowest channel is 1
  9715. * with center frequency 5955, its diff is 6025 - 5955 = 70.
  9716. * bandwidth=320 MHz, center frequency is 6105, lowest channel is 1
  9717. * with center frequency 5955, its diff is 6105 - 5955 = 70.
  9718. */
  9719. switch (chan_def->width) {
  9720. case NL80211_CHAN_WIDTH_320:
  9721. diff_seq = 150;
  9722. break;
  9723. case NL80211_CHAN_WIDTH_160:
  9724. diff_seq = 70;
  9725. break;
  9726. case NL80211_CHAN_WIDTH_80:
  9727. diff_seq = 30;
  9728. break;
  9729. case NL80211_CHAN_WIDTH_40:
  9730. diff_seq = 10;
  9731. break;
  9732. default:
  9733. diff_seq = 0;
  9734. }
  9735. return chan_def->center_freq1 - diff_seq;
  9736. }
  9737. static u16 ath12k_mac_get_seg_freq(struct cfg80211_chan_def *chan_def,
  9738. u16 start_seq, u8 seq)
  9739. {
  9740. u16 seg_seq;
  9741. /* It is to get the center frequency of the specific bandwidth.
  9742. * start_seq means the lowest channel number's center frequency.
  9743. * seq 0/1/2/3 means 20 MHz/40 MHz/80 MHz/160 MHz.
  9744. * For example,
  9745. * lowest channel is 1, its center frequency 5955,
  9746. * center frequency is 5955 when bandwidth=20 MHz, its diff is 5955 - 5955 = 0.
  9747. * lowest channel is 1, its center frequency 5955,
  9748. * center frequency is 5965 when bandwidth=40 MHz, its diff is 5965 - 5955 = 10.
  9749. * lowest channel is 1, its center frequency 5955,
  9750. * center frequency is 5985 when bandwidth=80 MHz, its diff is 5985 - 5955 = 30.
  9751. * lowest channel is 1, its center frequency 5955,
  9752. * center frequency is 6025 when bandwidth=160 MHz, its diff is 6025 - 5955 = 70.
  9753. */
  9754. seg_seq = 10 * (BIT(seq) - 1);
  9755. return seg_seq + start_seq;
  9756. }
  9757. static void ath12k_mac_get_psd_channel(struct ath12k *ar,
  9758. u16 step_freq,
  9759. u16 *start_freq,
  9760. u16 *center_freq,
  9761. u8 i,
  9762. struct ieee80211_channel **temp_chan,
  9763. s8 *tx_power)
  9764. {
  9765. /* It is to get the center frequency for each 20 MHz.
  9766. * For example, if the chan is 160 MHz and center frequency is 6025,
  9767. * then it include 8 channels, they are 1/5/9/13/17/21/25/29,
  9768. * channel number 1's center frequency is 5955, it is parameter start_freq.
  9769. * parameter i is the step of the 8 channels. i is 0~7 for the 8 channels.
  9770. * the channel 1/5/9/13/17/21/25/29 maps i=0/1/2/3/4/5/6/7,
  9771. * and maps its center frequency is 5955/5975/5995/6015/6035/6055/6075/6095,
  9772. * the gap is 20 for each channel, parameter step_freq means the gap.
  9773. * after get the center frequency of each channel, it is easy to find the
  9774. * struct ieee80211_channel of it and get the max_reg_power.
  9775. */
  9776. *center_freq = *start_freq + i * step_freq;
  9777. *temp_chan = ieee80211_get_channel(ar->ah->hw->wiphy, *center_freq);
  9778. *tx_power = (*temp_chan)->max_reg_power;
  9779. }
  9780. static void ath12k_mac_get_eirp_power(struct ath12k *ar,
  9781. u16 *start_freq,
  9782. u16 *center_freq,
  9783. u8 i,
  9784. struct ieee80211_channel **temp_chan,
  9785. struct cfg80211_chan_def *def,
  9786. s8 *tx_power)
  9787. {
  9788. /* It is to get the center frequency for 20 MHz/40 MHz/80 MHz/
  9789. * 160 MHz bandwidth, and then plus 10 to the center frequency,
  9790. * it is the center frequency of a channel number.
  9791. * For example, when configured channel number is 1.
  9792. * center frequency is 5965 when bandwidth=40 MHz, after plus 10, it is 5975,
  9793. * then it is channel number 5.
  9794. * center frequency is 5985 when bandwidth=80 MHz, after plus 10, it is 5995,
  9795. * then it is channel number 9.
  9796. * center frequency is 6025 when bandwidth=160 MHz, after plus 10, it is 6035,
  9797. * then it is channel number 17.
  9798. * after get the center frequency of each channel, it is easy to find the
  9799. * struct ieee80211_channel of it and get the max_reg_power.
  9800. */
  9801. *center_freq = ath12k_mac_get_seg_freq(def, *start_freq, i);
  9802. /* For the 20 MHz, its center frequency is same with same channel */
  9803. if (i != 0)
  9804. *center_freq += 10;
  9805. *temp_chan = ieee80211_get_channel(ar->ah->hw->wiphy, *center_freq);
  9806. *tx_power = (*temp_chan)->max_reg_power;
  9807. }
  9808. void ath12k_mac_fill_reg_tpc_info(struct ath12k *ar,
  9809. struct ath12k_link_vif *arvif,
  9810. struct ieee80211_chanctx_conf *ctx)
  9811. {
  9812. struct ath12k_base *ab = ar->ab;
  9813. struct ath12k_reg_tpc_power_info *reg_tpc_info = &arvif->reg_tpc_info;
  9814. struct ieee80211_bss_conf *bss_conf = ath12k_mac_get_link_bss_conf(arvif);
  9815. struct ieee80211_channel *chan, *temp_chan;
  9816. u8 pwr_lvl_idx, num_pwr_levels, pwr_reduction;
  9817. bool is_psd_power = false, is_tpe_present = false;
  9818. s8 max_tx_power[ATH12K_NUM_PWR_LEVELS], psd_power, tx_power;
  9819. s8 eirp_power = 0;
  9820. struct ath12k_vif *ahvif = arvif->ahvif;
  9821. u16 start_freq, center_freq;
  9822. u8 reg_6ghz_power_mode;
  9823. chan = ctx->def.chan;
  9824. start_freq = ath12k_mac_get_6ghz_start_frequency(&ctx->def);
  9825. pwr_reduction = bss_conf->pwr_reduction;
  9826. if (arvif->reg_tpc_info.num_pwr_levels) {
  9827. is_tpe_present = true;
  9828. num_pwr_levels = arvif->reg_tpc_info.num_pwr_levels;
  9829. } else {
  9830. num_pwr_levels = ath12k_mac_get_num_pwr_levels(&ctx->def);
  9831. }
  9832. for (pwr_lvl_idx = 0; pwr_lvl_idx < num_pwr_levels; pwr_lvl_idx++) {
  9833. /* STA received TPE IE*/
  9834. if (is_tpe_present) {
  9835. /* local power is PSD power*/
  9836. if (chan->flags & IEEE80211_CHAN_PSD) {
  9837. /* Connecting AP is psd power */
  9838. if (reg_tpc_info->is_psd_power) {
  9839. is_psd_power = true;
  9840. ath12k_mac_get_psd_channel(ar, 20,
  9841. &start_freq,
  9842. &center_freq,
  9843. pwr_lvl_idx,
  9844. &temp_chan,
  9845. &tx_power);
  9846. psd_power = temp_chan->psd;
  9847. eirp_power = tx_power;
  9848. max_tx_power[pwr_lvl_idx] =
  9849. min_t(s8,
  9850. psd_power,
  9851. reg_tpc_info->tpe[pwr_lvl_idx]);
  9852. /* Connecting AP is not psd power */
  9853. } else {
  9854. ath12k_mac_get_eirp_power(ar,
  9855. &start_freq,
  9856. &center_freq,
  9857. pwr_lvl_idx,
  9858. &temp_chan,
  9859. &ctx->def,
  9860. &tx_power);
  9861. psd_power = temp_chan->psd;
  9862. /* convert psd power to EIRP power based
  9863. * on channel width
  9864. */
  9865. tx_power =
  9866. min_t(s8, tx_power,
  9867. psd_power + 13 + pwr_lvl_idx * 3);
  9868. max_tx_power[pwr_lvl_idx] =
  9869. min_t(s8,
  9870. tx_power,
  9871. reg_tpc_info->tpe[pwr_lvl_idx]);
  9872. }
  9873. /* local power is not PSD power */
  9874. } else {
  9875. /* Connecting AP is psd power */
  9876. if (reg_tpc_info->is_psd_power) {
  9877. is_psd_power = true;
  9878. ath12k_mac_get_psd_channel(ar, 20,
  9879. &start_freq,
  9880. &center_freq,
  9881. pwr_lvl_idx,
  9882. &temp_chan,
  9883. &tx_power);
  9884. eirp_power = tx_power;
  9885. max_tx_power[pwr_lvl_idx] =
  9886. reg_tpc_info->tpe[pwr_lvl_idx];
  9887. /* Connecting AP is not psd power */
  9888. } else {
  9889. ath12k_mac_get_eirp_power(ar,
  9890. &start_freq,
  9891. &center_freq,
  9892. pwr_lvl_idx,
  9893. &temp_chan,
  9894. &ctx->def,
  9895. &tx_power);
  9896. max_tx_power[pwr_lvl_idx] =
  9897. min_t(s8,
  9898. tx_power,
  9899. reg_tpc_info->tpe[pwr_lvl_idx]);
  9900. }
  9901. }
  9902. /* STA not received TPE IE */
  9903. } else {
  9904. /* local power is PSD power*/
  9905. if (chan->flags & IEEE80211_CHAN_PSD) {
  9906. is_psd_power = true;
  9907. ath12k_mac_get_psd_channel(ar, 20,
  9908. &start_freq,
  9909. &center_freq,
  9910. pwr_lvl_idx,
  9911. &temp_chan,
  9912. &tx_power);
  9913. psd_power = temp_chan->psd;
  9914. eirp_power = tx_power;
  9915. max_tx_power[pwr_lvl_idx] = psd_power;
  9916. } else {
  9917. ath12k_mac_get_eirp_power(ar,
  9918. &start_freq,
  9919. &center_freq,
  9920. pwr_lvl_idx,
  9921. &temp_chan,
  9922. &ctx->def,
  9923. &tx_power);
  9924. max_tx_power[pwr_lvl_idx] = tx_power;
  9925. }
  9926. }
  9927. if (is_psd_power) {
  9928. /* If AP local power constraint is present */
  9929. if (pwr_reduction)
  9930. eirp_power = eirp_power - pwr_reduction;
  9931. /* If firmware updated max tx power is non zero, then take
  9932. * the min of firmware updated ap tx power
  9933. * and max power derived from above mentioned parameters.
  9934. */
  9935. ath12k_dbg(ab, ATH12K_DBG_MAC,
  9936. "eirp power : %d firmware report power : %d\n",
  9937. eirp_power, ar->max_allowed_tx_power);
  9938. /* Firmware reports lower max_allowed_tx_power during vdev
  9939. * start response. In case of 6 GHz, firmware is not aware
  9940. * of EIRP power unless driver sets EIRP power through WMI
  9941. * TPC command. So radio which does not support idle power
  9942. * save can set maximum calculated EIRP power directly to
  9943. * firmware through TPC command without min comparison with
  9944. * vdev start response's max_allowed_tx_power.
  9945. */
  9946. if (ar->max_allowed_tx_power && ab->hw_params->idle_ps)
  9947. eirp_power = min_t(s8,
  9948. eirp_power,
  9949. ar->max_allowed_tx_power);
  9950. } else {
  9951. /* If AP local power constraint is present */
  9952. if (pwr_reduction)
  9953. max_tx_power[pwr_lvl_idx] =
  9954. max_tx_power[pwr_lvl_idx] - pwr_reduction;
  9955. /* If firmware updated max tx power is non zero, then take
  9956. * the min of firmware updated ap tx power
  9957. * and max power derived from above mentioned parameters.
  9958. */
  9959. if (ar->max_allowed_tx_power && ab->hw_params->idle_ps)
  9960. max_tx_power[pwr_lvl_idx] =
  9961. min_t(s8,
  9962. max_tx_power[pwr_lvl_idx],
  9963. ar->max_allowed_tx_power);
  9964. }
  9965. reg_tpc_info->chan_power_info[pwr_lvl_idx].chan_cfreq = center_freq;
  9966. reg_tpc_info->chan_power_info[pwr_lvl_idx].tx_power =
  9967. max_tx_power[pwr_lvl_idx];
  9968. }
  9969. reg_tpc_info->num_pwr_levels = num_pwr_levels;
  9970. reg_tpc_info->is_psd_power = is_psd_power;
  9971. reg_tpc_info->eirp_power = eirp_power;
  9972. if (ahvif->vdev_type == WMI_VDEV_TYPE_STA)
  9973. reg_6ghz_power_mode = bss_conf->power_type;
  9974. else
  9975. /* For now, LPI is the only supported AP power mode */
  9976. reg_6ghz_power_mode = IEEE80211_REG_LPI_AP;
  9977. reg_tpc_info->ap_power_type =
  9978. ath12k_reg_ap_pwr_convert(reg_6ghz_power_mode);
  9979. }
  9980. static void ath12k_mac_parse_tx_pwr_env(struct ath12k *ar,
  9981. struct ath12k_link_vif *arvif)
  9982. {
  9983. struct ieee80211_bss_conf *bss_conf = ath12k_mac_get_link_bss_conf(arvif);
  9984. struct ath12k_reg_tpc_power_info *tpc_info = &arvif->reg_tpc_info;
  9985. struct ieee80211_parsed_tpe_eirp *local_non_psd, *reg_non_psd;
  9986. struct ieee80211_parsed_tpe_psd *local_psd, *reg_psd;
  9987. struct ieee80211_parsed_tpe *tpe = &bss_conf->tpe;
  9988. enum wmi_reg_6g_client_type client_type;
  9989. struct ath12k_reg_info *reg_info;
  9990. struct ath12k_base *ab = ar->ab;
  9991. bool psd_valid, non_psd_valid;
  9992. int i;
  9993. reg_info = ab->reg_info[ar->pdev_idx];
  9994. client_type = reg_info->client_type;
  9995. local_psd = &tpe->psd_local[client_type];
  9996. reg_psd = &tpe->psd_reg_client[client_type];
  9997. local_non_psd = &tpe->max_local[client_type];
  9998. reg_non_psd = &tpe->max_reg_client[client_type];
  9999. psd_valid = local_psd->valid | reg_psd->valid;
  10000. non_psd_valid = local_non_psd->valid | reg_non_psd->valid;
  10001. if (!psd_valid && !non_psd_valid) {
  10002. ath12k_warn(ab,
  10003. "no transmit power envelope match client power type %d\n",
  10004. client_type);
  10005. return;
  10006. }
  10007. if (psd_valid) {
  10008. tpc_info->is_psd_power = true;
  10009. tpc_info->num_pwr_levels = max(local_psd->count,
  10010. reg_psd->count);
  10011. tpc_info->num_pwr_levels =
  10012. min3(tpc_info->num_pwr_levels,
  10013. IEEE80211_TPE_PSD_ENTRIES_320MHZ,
  10014. ATH12K_NUM_PWR_LEVELS);
  10015. for (i = 0; i < tpc_info->num_pwr_levels; i++) {
  10016. tpc_info->tpe[i] = min(local_psd->power[i],
  10017. reg_psd->power[i]) / 2;
  10018. ath12k_dbg(ab, ATH12K_DBG_MAC,
  10019. "TPE PSD power[%d] : %d\n",
  10020. i, tpc_info->tpe[i]);
  10021. }
  10022. } else {
  10023. tpc_info->is_psd_power = false;
  10024. tpc_info->eirp_power = 0;
  10025. tpc_info->num_pwr_levels = max(local_non_psd->count,
  10026. reg_non_psd->count);
  10027. tpc_info->num_pwr_levels =
  10028. min3(tpc_info->num_pwr_levels,
  10029. IEEE80211_TPE_EIRP_ENTRIES_320MHZ,
  10030. ATH12K_NUM_PWR_LEVELS);
  10031. for (i = 0; i < tpc_info->num_pwr_levels; i++) {
  10032. tpc_info->tpe[i] = min(local_non_psd->power[i],
  10033. reg_non_psd->power[i]) / 2;
  10034. ath12k_dbg(ab, ATH12K_DBG_MAC,
  10035. "non PSD power[%d] : %d\n",
  10036. i, tpc_info->tpe[i]);
  10037. }
  10038. }
  10039. }
  10040. int
  10041. ath12k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
  10042. struct ieee80211_vif *vif,
  10043. struct ieee80211_bss_conf *link_conf,
  10044. struct ieee80211_chanctx_conf *ctx)
  10045. {
  10046. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  10047. struct ath12k *ar;
  10048. struct ath12k_base *ab;
  10049. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  10050. u8 link_id = link_conf->link_id;
  10051. struct ath12k_link_vif *arvif;
  10052. int ret;
  10053. lockdep_assert_wiphy(hw->wiphy);
  10054. /* For multi radio wiphy, the vdev was not created during add_interface
  10055. * create now since we have a channel ctx now to assign to a specific ar/fw
  10056. */
  10057. arvif = ath12k_mac_assign_link_vif(ah, vif, link_id);
  10058. if (!arvif) {
  10059. WARN_ON(1);
  10060. return -ENOMEM;
  10061. }
  10062. ar = ath12k_mac_assign_vif_to_vdev(hw, arvif, ctx);
  10063. if (!ar) {
  10064. ath12k_hw_warn(ah, "failed to assign chanctx for vif %pM link id %u link vif is already started",
  10065. vif->addr, link_id);
  10066. return -EINVAL;
  10067. }
  10068. ab = ar->ab;
  10069. ath12k_dbg(ab, ATH12K_DBG_MAC,
  10070. "mac chanctx assign ptr %p vdev_id %i\n",
  10071. ctx, arvif->vdev_id);
  10072. if (ath12k_wmi_supports_6ghz_cc_ext(ar) &&
  10073. ctx->def.chan->band == NL80211_BAND_6GHZ &&
  10074. ahvif->vdev_type == WMI_VDEV_TYPE_STA)
  10075. ath12k_mac_parse_tx_pwr_env(ar, arvif);
  10076. arvif->punct_bitmap = ctx->def.punctured;
  10077. /* for some targets bss peer must be created before vdev_start */
  10078. if (ab->hw_params->vdev_start_delay &&
  10079. ahvif->vdev_type != WMI_VDEV_TYPE_AP &&
  10080. ahvif->vdev_type != WMI_VDEV_TYPE_MONITOR &&
  10081. !ath12k_dp_link_peer_exist_by_vdev_id(ath12k_ab_to_dp(ab), arvif->vdev_id)) {
  10082. ret = 0;
  10083. goto out;
  10084. }
  10085. if (WARN_ON(arvif->is_started)) {
  10086. ret = -EBUSY;
  10087. goto out;
  10088. }
  10089. if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
  10090. ret = ath12k_mac_monitor_start(ar);
  10091. if (ret) {
  10092. ath12k_mac_monitor_vdev_delete(ar);
  10093. goto out;
  10094. }
  10095. arvif->is_started = true;
  10096. goto out;
  10097. }
  10098. ret = ath12k_mac_vdev_start(arvif, ctx);
  10099. if (ret) {
  10100. ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
  10101. arvif->vdev_id, vif->addr,
  10102. ctx->def.chan->center_freq, ret);
  10103. goto out;
  10104. }
  10105. arvif->is_started = true;
  10106. /* TODO: Setup ps and cts/rts protection */
  10107. out:
  10108. return ret;
  10109. }
  10110. EXPORT_SYMBOL(ath12k_mac_op_assign_vif_chanctx);
  10111. void
  10112. ath12k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
  10113. struct ieee80211_vif *vif,
  10114. struct ieee80211_bss_conf *link_conf,
  10115. struct ieee80211_chanctx_conf *ctx)
  10116. {
  10117. struct ath12k *ar;
  10118. struct ath12k_base *ab;
  10119. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  10120. struct ath12k_link_vif *arvif;
  10121. u8 link_id = link_conf->link_id;
  10122. int ret;
  10123. lockdep_assert_wiphy(hw->wiphy);
  10124. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  10125. /* The vif is expected to be attached to an ar's VDEV.
  10126. * We leave the vif/vdev in this function as is
  10127. * and not delete the vdev symmetric to assign_vif_chanctx()
  10128. * the VDEV will be deleted and unassigned either during
  10129. * remove_interface() or when there is a change in channel
  10130. * that moves the vif to a new ar
  10131. */
  10132. if (!arvif || !arvif->is_created)
  10133. return;
  10134. ar = arvif->ar;
  10135. ab = ar->ab;
  10136. ath12k_dbg(ab, ATH12K_DBG_MAC,
  10137. "mac chanctx unassign ptr %p vdev_id %i\n",
  10138. ctx, arvif->vdev_id);
  10139. WARN_ON(!arvif->is_started);
  10140. if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
  10141. ret = ath12k_mac_monitor_stop(ar);
  10142. if (ret)
  10143. return;
  10144. arvif->is_started = false;
  10145. }
  10146. if (ahvif->vdev_type != WMI_VDEV_TYPE_STA &&
  10147. ahvif->vdev_type != WMI_VDEV_TYPE_MONITOR) {
  10148. ath12k_bss_disassoc(ar, arvif);
  10149. ret = ath12k_mac_vdev_stop(arvif);
  10150. if (ret)
  10151. ath12k_warn(ab, "failed to stop vdev %i: %d\n",
  10152. arvif->vdev_id, ret);
  10153. }
  10154. arvif->is_started = false;
  10155. if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ab->wmi_ab.svc_map) &&
  10156. ahvif->vdev_type == WMI_VDEV_TYPE_STA &&
  10157. ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE &&
  10158. ar->state_11d != ATH12K_11D_PREPARING) {
  10159. reinit_completion(&ar->completed_11d_scan);
  10160. ar->state_11d = ATH12K_11D_PREPARING;
  10161. }
  10162. if (ar->scan.arvif == arvif && ar->scan.state == ATH12K_SCAN_RUNNING) {
  10163. ath12k_scan_abort(ar);
  10164. ar->scan.arvif = NULL;
  10165. }
  10166. }
  10167. EXPORT_SYMBOL(ath12k_mac_op_unassign_vif_chanctx);
  10168. int
  10169. ath12k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
  10170. struct ieee80211_vif_chanctx_switch *vifs,
  10171. int n_vifs,
  10172. enum ieee80211_chanctx_switch_mode mode)
  10173. {
  10174. struct ath12k *ar;
  10175. lockdep_assert_wiphy(hw->wiphy);
  10176. ar = ath12k_get_ar_by_ctx(hw, vifs->old_ctx);
  10177. if (!ar)
  10178. return -EINVAL;
  10179. /* Switching channels across radio is not allowed */
  10180. if (ar != ath12k_get_ar_by_ctx(hw, vifs->new_ctx))
  10181. return -EINVAL;
  10182. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  10183. "mac chanctx switch n_vifs %d mode %d\n",
  10184. n_vifs, mode);
  10185. ath12k_mac_update_vif_chan(ar, vifs, n_vifs);
  10186. return 0;
  10187. }
  10188. EXPORT_SYMBOL(ath12k_mac_op_switch_vif_chanctx);
  10189. static int
  10190. ath12k_set_vdev_param_to_all_vifs(struct ath12k *ar, int param, u32 value)
  10191. {
  10192. struct ath12k_link_vif *arvif;
  10193. int ret = 0;
  10194. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  10195. list_for_each_entry(arvif, &ar->arvifs, list) {
  10196. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "setting mac vdev %d param %d value %d\n",
  10197. param, arvif->vdev_id, value);
  10198. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  10199. param, value);
  10200. if (ret) {
  10201. ath12k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n",
  10202. param, arvif->vdev_id, ret);
  10203. break;
  10204. }
  10205. }
  10206. return ret;
  10207. }
  10208. /* mac80211 stores device specific RTS/Fragmentation threshold value,
  10209. * this is set interface specific to firmware from ath12k driver
  10210. */
  10211. int ath12k_mac_op_set_rts_threshold(struct ieee80211_hw *hw,
  10212. int radio_idx, u32 value)
  10213. {
  10214. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  10215. struct wiphy *wiphy = hw->wiphy;
  10216. struct ath12k *ar;
  10217. int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
  10218. int ret = 0, ret_err, i;
  10219. lockdep_assert_wiphy(hw->wiphy);
  10220. if (radio_idx >= wiphy->n_radio || radio_idx < -1)
  10221. return -EINVAL;
  10222. if (radio_idx != -1) {
  10223. /* Update RTS threshold in specified radio */
  10224. ar = ath12k_ah_to_ar(ah, radio_idx);
  10225. ret = ath12k_set_vdev_param_to_all_vifs(ar, param_id, value);
  10226. if (ret) {
  10227. ath12k_warn(ar->ab,
  10228. "failed to set RTS config for all vdevs of pdev %d",
  10229. ar->pdev->pdev_id);
  10230. return ret;
  10231. }
  10232. ar->rts_threshold = value;
  10233. return 0;
  10234. }
  10235. /* Radio_index passed is -1, so set RTS threshold for all radios. */
  10236. for_each_ar(ah, ar, i) {
  10237. ret = ath12k_set_vdev_param_to_all_vifs(ar, param_id, value);
  10238. if (ret) {
  10239. ath12k_warn(ar->ab, "failed to set RTS config for all vdevs of pdev %d",
  10240. ar->pdev->pdev_id);
  10241. break;
  10242. }
  10243. }
  10244. if (!ret) {
  10245. /* Setting new RTS threshold for vdevs of all radios passed, so update
  10246. * the RTS threshold value for all radios
  10247. */
  10248. for_each_ar(ah, ar, i)
  10249. ar->rts_threshold = value;
  10250. return 0;
  10251. }
  10252. /* RTS threshold config failed, revert to the previous RTS threshold */
  10253. for (i = i - 1; i >= 0; i--) {
  10254. ar = ath12k_ah_to_ar(ah, i);
  10255. ret_err = ath12k_set_vdev_param_to_all_vifs(ar, param_id,
  10256. ar->rts_threshold);
  10257. if (ret_err)
  10258. ath12k_warn(ar->ab,
  10259. "failed to restore RTS threshold for all vdevs of pdev %d",
  10260. ar->pdev->pdev_id);
  10261. }
  10262. return ret;
  10263. }
  10264. EXPORT_SYMBOL(ath12k_mac_op_set_rts_threshold);
  10265. int ath12k_mac_op_set_frag_threshold(struct ieee80211_hw *hw,
  10266. int radio_idx, u32 value)
  10267. {
  10268. /* Even though there's a WMI vdev param for fragmentation threshold no
  10269. * known firmware actually implements it. Moreover it is not possible to
  10270. * rely frame fragmentation to mac80211 because firmware clears the
  10271. * "more fragments" bit in frame control making it impossible for remote
  10272. * devices to reassemble frames.
  10273. *
  10274. * Hence implement a dummy callback just to say fragmentation isn't
  10275. * supported. This effectively prevents mac80211 from doing frame
  10276. * fragmentation in software.
  10277. */
  10278. lockdep_assert_wiphy(hw->wiphy);
  10279. return -EOPNOTSUPP;
  10280. }
  10281. EXPORT_SYMBOL(ath12k_mac_op_set_frag_threshold);
  10282. static int ath12k_mac_flush(struct ath12k *ar)
  10283. {
  10284. long time_left;
  10285. int ret = 0;
  10286. time_left = wait_event_timeout(ar->dp.tx_empty_waitq,
  10287. (atomic_read(&ar->dp.num_tx_pending) == 0),
  10288. ATH12K_FLUSH_TIMEOUT);
  10289. if (time_left == 0) {
  10290. ath12k_warn(ar->ab,
  10291. "failed to flush transmit queue, data pkts pending %d\n",
  10292. atomic_read(&ar->dp.num_tx_pending));
  10293. ret = -ETIMEDOUT;
  10294. }
  10295. time_left = wait_event_timeout(ar->txmgmt_empty_waitq,
  10296. (atomic_read(&ar->num_pending_mgmt_tx) == 0),
  10297. ATH12K_FLUSH_TIMEOUT);
  10298. if (time_left == 0) {
  10299. ath12k_warn(ar->ab,
  10300. "failed to flush mgmt transmit queue, mgmt pkts pending %d\n",
  10301. atomic_read(&ar->num_pending_mgmt_tx));
  10302. ret = -ETIMEDOUT;
  10303. }
  10304. return ret;
  10305. }
  10306. int ath12k_mac_wait_tx_complete(struct ath12k *ar)
  10307. {
  10308. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  10309. ath12k_mac_drain_tx(ar);
  10310. return ath12k_mac_flush(ar);
  10311. }
  10312. void ath12k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  10313. u32 queues, bool drop)
  10314. {
  10315. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  10316. struct ath12k_link_vif *arvif;
  10317. struct ath12k_vif *ahvif;
  10318. unsigned long links;
  10319. struct ath12k *ar;
  10320. u8 link_id;
  10321. int i;
  10322. lockdep_assert_wiphy(hw->wiphy);
  10323. if (drop)
  10324. return;
  10325. for_each_ar(ah, ar, i)
  10326. wiphy_work_flush(hw->wiphy, &ar->wmi_mgmt_tx_work);
  10327. /* vif can be NULL when flush() is considered for hw */
  10328. if (!vif) {
  10329. for_each_ar(ah, ar, i)
  10330. ath12k_mac_flush(ar);
  10331. return;
  10332. }
  10333. ahvif = ath12k_vif_to_ahvif(vif);
  10334. links = ahvif->links_map;
  10335. for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
  10336. arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
  10337. if (!(arvif && arvif->ar))
  10338. continue;
  10339. ath12k_mac_flush(arvif->ar);
  10340. }
  10341. }
  10342. EXPORT_SYMBOL(ath12k_mac_op_flush);
  10343. static int
  10344. ath12k_mac_bitrate_mask_num_ht_rates(struct ath12k *ar,
  10345. enum nl80211_band band,
  10346. const struct cfg80211_bitrate_mask *mask)
  10347. {
  10348. int num_rates = 0;
  10349. int i;
  10350. for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
  10351. num_rates += hweight16(mask->control[band].ht_mcs[i]);
  10352. return num_rates;
  10353. }
  10354. static bool
  10355. ath12k_mac_has_single_legacy_rate(struct ath12k *ar,
  10356. enum nl80211_band band,
  10357. const struct cfg80211_bitrate_mask *mask)
  10358. {
  10359. int num_rates = 0;
  10360. num_rates = hweight32(mask->control[band].legacy);
  10361. if (ath12k_mac_bitrate_mask_num_ht_rates(ar, band, mask))
  10362. return false;
  10363. if (ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask))
  10364. return false;
  10365. if (ath12k_mac_bitrate_mask_num_he_rates(ar, band, mask))
  10366. return false;
  10367. if (ath12k_mac_bitrate_mask_num_eht_rates(ar, band, mask))
  10368. return false;
  10369. return num_rates == 1;
  10370. }
  10371. static __le16
  10372. ath12k_mac_get_tx_mcs_map(const struct ieee80211_sta_he_cap *he_cap)
  10373. {
  10374. if (he_cap->he_cap_elem.phy_cap_info[0] &
  10375. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
  10376. return he_cap->he_mcs_nss_supp.tx_mcs_160;
  10377. return he_cap->he_mcs_nss_supp.tx_mcs_80;
  10378. }
  10379. static bool
  10380. ath12k_mac_bitrate_mask_get_single_nss(struct ath12k *ar,
  10381. struct ieee80211_vif *vif,
  10382. enum nl80211_band band,
  10383. const struct cfg80211_bitrate_mask *mask,
  10384. int *nss)
  10385. {
  10386. struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
  10387. u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
  10388. const struct ieee80211_sband_iftype_data *data;
  10389. const struct ieee80211_sta_he_cap *he_cap;
  10390. u16 he_mcs_map = 0;
  10391. u16 eht_mcs_map = 0;
  10392. u8 ht_nss_mask = 0;
  10393. u8 vht_nss_mask = 0;
  10394. u8 he_nss_mask = 0;
  10395. u8 eht_nss_mask = 0;
  10396. u8 mcs_nss_len;
  10397. int i;
  10398. /* No need to consider legacy here. Basic rates are always present
  10399. * in bitrate mask
  10400. */
  10401. for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
  10402. if (mask->control[band].ht_mcs[i] == 0)
  10403. continue;
  10404. else if (mask->control[band].ht_mcs[i] ==
  10405. sband->ht_cap.mcs.rx_mask[i])
  10406. ht_nss_mask |= BIT(i);
  10407. else
  10408. return false;
  10409. }
  10410. for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
  10411. if (mask->control[band].vht_mcs[i] == 0)
  10412. continue;
  10413. else if (mask->control[band].vht_mcs[i] ==
  10414. ath12k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
  10415. vht_nss_mask |= BIT(i);
  10416. else
  10417. return false;
  10418. }
  10419. he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif);
  10420. if (!he_cap)
  10421. return false;
  10422. he_mcs_map = le16_to_cpu(ath12k_mac_get_tx_mcs_map(he_cap));
  10423. for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++) {
  10424. if (mask->control[band].he_mcs[i] == 0)
  10425. continue;
  10426. if (mask->control[band].he_mcs[i] ==
  10427. ath12k_mac_get_max_he_mcs_map(he_mcs_map, i))
  10428. he_nss_mask |= BIT(i);
  10429. else
  10430. return false;
  10431. }
  10432. data = ieee80211_get_sband_iftype_data(sband, vif->type);
  10433. mcs_nss_len = ieee80211_eht_mcs_nss_size(&data->he_cap.he_cap_elem,
  10434. &data->eht_cap.eht_cap_elem,
  10435. false);
  10436. if (mcs_nss_len == 4) {
  10437. /* 20 MHz only STA case */
  10438. const struct ieee80211_eht_mcs_nss_supp_20mhz_only *eht_mcs_nss =
  10439. &data->eht_cap.eht_mcs_nss_supp.only_20mhz;
  10440. if (eht_mcs_nss->rx_tx_mcs13_max_nss)
  10441. eht_mcs_map = 0x1fff;
  10442. else if (eht_mcs_nss->rx_tx_mcs11_max_nss)
  10443. eht_mcs_map = 0x07ff;
  10444. else if (eht_mcs_nss->rx_tx_mcs9_max_nss)
  10445. eht_mcs_map = 0x01ff;
  10446. else
  10447. eht_mcs_map = 0x007f;
  10448. } else {
  10449. const struct ieee80211_eht_mcs_nss_supp_bw *eht_mcs_nss;
  10450. switch (mcs_nss_len) {
  10451. case 9:
  10452. eht_mcs_nss = &data->eht_cap.eht_mcs_nss_supp.bw._320;
  10453. break;
  10454. case 6:
  10455. eht_mcs_nss = &data->eht_cap.eht_mcs_nss_supp.bw._160;
  10456. break;
  10457. case 3:
  10458. eht_mcs_nss = &data->eht_cap.eht_mcs_nss_supp.bw._80;
  10459. break;
  10460. default:
  10461. return false;
  10462. }
  10463. if (eht_mcs_nss->rx_tx_mcs13_max_nss)
  10464. eht_mcs_map = 0x1fff;
  10465. else if (eht_mcs_nss->rx_tx_mcs11_max_nss)
  10466. eht_mcs_map = 0x7ff;
  10467. else
  10468. eht_mcs_map = 0x1ff;
  10469. }
  10470. for (i = 0; i < ARRAY_SIZE(mask->control[band].eht_mcs); i++) {
  10471. if (mask->control[band].eht_mcs[i] == 0)
  10472. continue;
  10473. if (mask->control[band].eht_mcs[i] < eht_mcs_map)
  10474. eht_nss_mask |= BIT(i);
  10475. else
  10476. return false;
  10477. }
  10478. if (ht_nss_mask != vht_nss_mask || ht_nss_mask != he_nss_mask ||
  10479. ht_nss_mask != eht_nss_mask)
  10480. return false;
  10481. if (ht_nss_mask == 0)
  10482. return false;
  10483. if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
  10484. return false;
  10485. *nss = fls(ht_nss_mask);
  10486. return true;
  10487. }
  10488. static int
  10489. ath12k_mac_get_single_legacy_rate(struct ath12k *ar,
  10490. enum nl80211_band band,
  10491. const struct cfg80211_bitrate_mask *mask,
  10492. u32 *rate, u8 *nss)
  10493. {
  10494. int rate_idx;
  10495. u16 bitrate;
  10496. u8 preamble;
  10497. u8 hw_rate;
  10498. if (hweight32(mask->control[band].legacy) != 1)
  10499. return -EINVAL;
  10500. rate_idx = ffs(mask->control[band].legacy) - 1;
  10501. if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ)
  10502. rate_idx += ATH12K_MAC_FIRST_OFDM_RATE_IDX;
  10503. hw_rate = ath12k_legacy_rates[rate_idx].hw_value;
  10504. bitrate = ath12k_legacy_rates[rate_idx].bitrate;
  10505. if (ath12k_mac_bitrate_is_cck(bitrate))
  10506. preamble = WMI_RATE_PREAMBLE_CCK;
  10507. else
  10508. preamble = WMI_RATE_PREAMBLE_OFDM;
  10509. *nss = 1;
  10510. *rate = ATH12K_HW_RATE_CODE(hw_rate, 0, preamble);
  10511. return 0;
  10512. }
  10513. static int
  10514. ath12k_mac_set_fixed_rate_gi_ltf(struct ath12k_link_vif *arvif, u8 gi, u8 ltf,
  10515. u32 param)
  10516. {
  10517. struct ath12k *ar = arvif->ar;
  10518. int ret;
  10519. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  10520. /* 0.8 = 0, 1.6 = 2 and 3.2 = 3. */
  10521. if (gi && gi != 0xFF)
  10522. gi += 1;
  10523. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  10524. WMI_VDEV_PARAM_SGI, gi);
  10525. if (ret) {
  10526. ath12k_warn(ar->ab, "failed to set GI:%d, error:%d\n",
  10527. gi, ret);
  10528. return ret;
  10529. }
  10530. if (param == WMI_VDEV_PARAM_HE_LTF) {
  10531. /* HE values start from 1 */
  10532. if (ltf != 0xFF)
  10533. ltf += 1;
  10534. } else {
  10535. /* EHT values start from 5 */
  10536. if (ltf != 0xFF)
  10537. ltf += 4;
  10538. }
  10539. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  10540. param, ltf);
  10541. if (ret) {
  10542. ath12k_warn(ar->ab, "failed to set LTF:%d, error:%d\n",
  10543. ltf, ret);
  10544. return ret;
  10545. }
  10546. return 0;
  10547. }
  10548. static int
  10549. ath12k_mac_set_auto_rate_gi_ltf(struct ath12k_link_vif *arvif, u16 gi, u8 ltf)
  10550. {
  10551. struct ath12k *ar = arvif->ar;
  10552. int ret;
  10553. u32 ar_gi_ltf;
  10554. if (gi != 0xFF) {
  10555. switch (gi) {
  10556. case ATH12K_RATE_INFO_GI_0_8:
  10557. gi = WMI_AUTORATE_800NS_GI;
  10558. break;
  10559. case ATH12K_RATE_INFO_GI_1_6:
  10560. gi = WMI_AUTORATE_1600NS_GI;
  10561. break;
  10562. case ATH12K_RATE_INFO_GI_3_2:
  10563. gi = WMI_AUTORATE_3200NS_GI;
  10564. break;
  10565. default:
  10566. ath12k_warn(ar->ab, "Invalid GI\n");
  10567. return -EINVAL;
  10568. }
  10569. }
  10570. if (ltf != 0xFF) {
  10571. switch (ltf) {
  10572. case ATH12K_RATE_INFO_1XLTF:
  10573. ltf = WMI_AUTORATE_LTF_1X;
  10574. break;
  10575. case ATH12K_RATE_INFO_2XLTF:
  10576. ltf = WMI_AUTORATE_LTF_2X;
  10577. break;
  10578. case ATH12K_RATE_INFO_4XLTF:
  10579. ltf = WMI_AUTORATE_LTF_4X;
  10580. break;
  10581. default:
  10582. ath12k_warn(ar->ab, "Invalid LTF\n");
  10583. return -EINVAL;
  10584. }
  10585. }
  10586. ar_gi_ltf = gi | ltf;
  10587. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  10588. WMI_VDEV_PARAM_AUTORATE_MISC_CFG,
  10589. ar_gi_ltf);
  10590. if (ret) {
  10591. ath12k_warn(ar->ab,
  10592. "failed to set autorate GI:%u, LTF:%u params, error:%d\n",
  10593. gi, ltf, ret);
  10594. return ret;
  10595. }
  10596. return 0;
  10597. }
  10598. static u32 ath12k_mac_nlgi_to_wmigi(enum nl80211_txrate_gi gi)
  10599. {
  10600. switch (gi) {
  10601. case NL80211_TXRATE_DEFAULT_GI:
  10602. return WMI_GI_400_NS;
  10603. case NL80211_TXRATE_FORCE_LGI:
  10604. return WMI_GI_800_NS;
  10605. default:
  10606. return WMI_GI_400_NS;
  10607. }
  10608. }
  10609. static int ath12k_mac_set_rate_params(struct ath12k_link_vif *arvif,
  10610. u32 rate, u8 nss, u8 sgi, u8 ldpc,
  10611. u8 he_gi, u8 he_ltf, bool he_fixed_rate,
  10612. u8 eht_gi, u8 eht_ltf,
  10613. bool eht_fixed_rate)
  10614. {
  10615. struct ieee80211_bss_conf *link_conf;
  10616. struct ath12k *ar = arvif->ar;
  10617. bool he_support, eht_support, gi_ltf_set = false;
  10618. u32 vdev_param;
  10619. u32 param_value;
  10620. int ret;
  10621. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  10622. link_conf = ath12k_mac_get_link_bss_conf(arvif);
  10623. if (!link_conf)
  10624. return -EINVAL;
  10625. he_support = link_conf->he_support;
  10626. eht_support = link_conf->eht_support;
  10627. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  10628. "mac set rate params vdev %i rate 0x%02x nss 0x%02x sgi 0x%02x ldpc 0x%02x\n",
  10629. arvif->vdev_id, rate, nss, sgi, ldpc);
  10630. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  10631. "he_gi 0x%02x he_ltf 0x%02x he_fixed_rate %d\n", he_gi,
  10632. he_ltf, he_fixed_rate);
  10633. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  10634. "eht_gi 0x%02x eht_ltf 0x%02x eht_fixed_rate %d\n",
  10635. eht_gi, eht_ltf, eht_fixed_rate);
  10636. if (!he_support && !eht_support) {
  10637. vdev_param = WMI_VDEV_PARAM_FIXED_RATE;
  10638. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  10639. vdev_param, rate);
  10640. if (ret) {
  10641. ath12k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n",
  10642. rate, ret);
  10643. return ret;
  10644. }
  10645. }
  10646. vdev_param = WMI_VDEV_PARAM_NSS;
  10647. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  10648. vdev_param, nss);
  10649. if (ret) {
  10650. ath12k_warn(ar->ab, "failed to set nss param %d: %d\n",
  10651. nss, ret);
  10652. return ret;
  10653. }
  10654. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  10655. WMI_VDEV_PARAM_LDPC, ldpc);
  10656. if (ret) {
  10657. ath12k_warn(ar->ab, "failed to set ldpc param %d: %d\n",
  10658. ldpc, ret);
  10659. return ret;
  10660. }
  10661. if (eht_support) {
  10662. if (eht_fixed_rate)
  10663. ret = ath12k_mac_set_fixed_rate_gi_ltf(arvif, eht_gi, eht_ltf,
  10664. WMI_VDEV_PARAM_EHT_LTF);
  10665. else
  10666. ret = ath12k_mac_set_auto_rate_gi_ltf(arvif, eht_gi, eht_ltf);
  10667. if (ret) {
  10668. ath12k_warn(ar->ab,
  10669. "failed to set EHT LTF/GI params %d/%d: %d\n",
  10670. eht_gi, eht_ltf, ret);
  10671. return ret;
  10672. }
  10673. gi_ltf_set = true;
  10674. }
  10675. if (he_support) {
  10676. if (he_fixed_rate)
  10677. ret = ath12k_mac_set_fixed_rate_gi_ltf(arvif, he_gi, he_ltf,
  10678. WMI_VDEV_PARAM_HE_LTF);
  10679. else
  10680. ret = ath12k_mac_set_auto_rate_gi_ltf(arvif, he_gi, he_ltf);
  10681. if (ret)
  10682. return ret;
  10683. gi_ltf_set = true;
  10684. }
  10685. if (!gi_ltf_set) {
  10686. vdev_param = WMI_VDEV_PARAM_SGI;
  10687. param_value = ath12k_mac_nlgi_to_wmigi(sgi);
  10688. ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
  10689. vdev_param, param_value);
  10690. if (ret) {
  10691. ath12k_warn(ar->ab, "failed to set sgi param %d: %d\n",
  10692. sgi, ret);
  10693. return ret;
  10694. }
  10695. }
  10696. return 0;
  10697. }
  10698. static bool
  10699. ath12k_mac_vht_mcs_range_present(struct ath12k *ar,
  10700. enum nl80211_band band,
  10701. const struct cfg80211_bitrate_mask *mask)
  10702. {
  10703. int i;
  10704. u16 vht_mcs;
  10705. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  10706. vht_mcs = mask->control[band].vht_mcs[i];
  10707. switch (vht_mcs) {
  10708. case 0:
  10709. case BIT(8) - 1:
  10710. case BIT(9) - 1:
  10711. case BIT(10) - 1:
  10712. break;
  10713. default:
  10714. return false;
  10715. }
  10716. }
  10717. return true;
  10718. }
  10719. static bool
  10720. ath12k_mac_he_mcs_range_present(struct ath12k *ar,
  10721. enum nl80211_band band,
  10722. const struct cfg80211_bitrate_mask *mask)
  10723. {
  10724. int i;
  10725. u16 he_mcs;
  10726. for (i = 0; i < NL80211_HE_NSS_MAX; i++) {
  10727. he_mcs = mask->control[band].he_mcs[i];
  10728. switch (he_mcs) {
  10729. case 0:
  10730. case BIT(8) - 1:
  10731. case BIT(10) - 1:
  10732. case BIT(12) - 1:
  10733. break;
  10734. default:
  10735. return false;
  10736. }
  10737. }
  10738. return true;
  10739. }
  10740. static bool
  10741. ath12k_mac_eht_mcs_range_present(struct ath12k *ar,
  10742. enum nl80211_band band,
  10743. const struct cfg80211_bitrate_mask *mask)
  10744. {
  10745. u16 eht_mcs;
  10746. int i;
  10747. for (i = 0; i < NL80211_EHT_NSS_MAX; i++) {
  10748. eht_mcs = mask->control[band].eht_mcs[i];
  10749. switch (eht_mcs) {
  10750. case 0:
  10751. case BIT(8) - 1:
  10752. case BIT(10) - 1:
  10753. case BIT(12) - 1:
  10754. case BIT(14) - 1:
  10755. break;
  10756. case BIT(15) - 1:
  10757. case BIT(16) - 1:
  10758. case BIT(16) - BIT(14) - 1:
  10759. if (i != 0)
  10760. return false;
  10761. break;
  10762. default:
  10763. return false;
  10764. }
  10765. }
  10766. return true;
  10767. }
  10768. static void ath12k_mac_set_bitrate_mask_iter(void *data,
  10769. struct ieee80211_sta *sta)
  10770. {
  10771. struct ath12k_link_vif *arvif = data;
  10772. struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta);
  10773. struct ath12k_link_sta *arsta;
  10774. struct ath12k *ar = arvif->ar;
  10775. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  10776. arsta = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy,
  10777. ahsta->link[arvif->link_id]);
  10778. if (!arsta || arsta->arvif != arvif)
  10779. return;
  10780. spin_lock_bh(&ar->data_lock);
  10781. arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
  10782. spin_unlock_bh(&ar->data_lock);
  10783. wiphy_work_queue(ath12k_ar_to_hw(ar)->wiphy, &arsta->update_wk);
  10784. }
  10785. static void ath12k_mac_disable_peer_fixed_rate(void *data,
  10786. struct ieee80211_sta *sta)
  10787. {
  10788. struct ath12k_link_vif *arvif = data;
  10789. struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta);
  10790. struct ath12k_link_sta *arsta;
  10791. struct ath12k *ar = arvif->ar;
  10792. int ret;
  10793. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  10794. arsta = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy,
  10795. ahsta->link[arvif->link_id]);
  10796. if (!arsta || arsta->arvif != arvif)
  10797. return;
  10798. ret = ath12k_wmi_set_peer_param(ar, arsta->addr,
  10799. arvif->vdev_id,
  10800. WMI_PEER_PARAM_FIXED_RATE,
  10801. WMI_FIXED_RATE_NONE);
  10802. if (ret)
  10803. ath12k_warn(ar->ab,
  10804. "failed to disable peer fixed rate for STA %pM ret %d\n",
  10805. arsta->addr, ret);
  10806. }
  10807. static bool
  10808. ath12k_mac_validate_fixed_rate_settings(struct ath12k *ar, enum nl80211_band band,
  10809. const struct cfg80211_bitrate_mask *mask,
  10810. unsigned int link_id)
  10811. {
  10812. bool eht_fixed_rate = false, he_fixed_rate = false, vht_fixed_rate = false;
  10813. const u16 *vht_mcs_mask, *he_mcs_mask, *eht_mcs_mask;
  10814. struct ieee80211_link_sta *link_sta;
  10815. struct ath12k_dp_link_peer *peer, *tmp;
  10816. u8 vht_nss, he_nss, eht_nss;
  10817. int ret = true;
  10818. struct ath12k_base *ab = ar->ab;
  10819. struct ath12k_dp *dp = ath12k_ab_to_dp(ab);
  10820. vht_mcs_mask = mask->control[band].vht_mcs;
  10821. he_mcs_mask = mask->control[band].he_mcs;
  10822. eht_mcs_mask = mask->control[band].eht_mcs;
  10823. if (ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask) == 1)
  10824. vht_fixed_rate = true;
  10825. if (ath12k_mac_bitrate_mask_num_he_rates(ar, band, mask) == 1)
  10826. he_fixed_rate = true;
  10827. if (ath12k_mac_bitrate_mask_num_eht_rates(ar, band, mask) == 1)
  10828. eht_fixed_rate = true;
  10829. if (!vht_fixed_rate && !he_fixed_rate && !eht_fixed_rate)
  10830. return true;
  10831. vht_nss = ath12k_mac_max_vht_nss(vht_mcs_mask);
  10832. he_nss = ath12k_mac_max_he_nss(he_mcs_mask);
  10833. eht_nss = ath12k_mac_max_eht_nss(eht_mcs_mask);
  10834. rcu_read_lock();
  10835. spin_lock_bh(&dp->dp_lock);
  10836. list_for_each_entry_safe(peer, tmp, &dp->peers, list) {
  10837. if (peer->sta) {
  10838. link_sta = rcu_dereference(peer->sta->link[link_id]);
  10839. if (!link_sta) {
  10840. ret = false;
  10841. goto exit;
  10842. }
  10843. if (vht_fixed_rate && (!link_sta->vht_cap.vht_supported ||
  10844. link_sta->rx_nss < vht_nss)) {
  10845. ret = false;
  10846. goto exit;
  10847. }
  10848. if (he_fixed_rate && (!link_sta->he_cap.has_he ||
  10849. link_sta->rx_nss < he_nss)) {
  10850. ret = false;
  10851. goto exit;
  10852. }
  10853. if (eht_fixed_rate && (!link_sta->eht_cap.has_eht ||
  10854. link_sta->rx_nss < eht_nss)) {
  10855. ret = false;
  10856. goto exit;
  10857. }
  10858. }
  10859. }
  10860. exit:
  10861. spin_unlock_bh(&dp->dp_lock);
  10862. rcu_read_unlock();
  10863. return ret;
  10864. }
  10865. int
  10866. ath12k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
  10867. struct ieee80211_vif *vif,
  10868. const struct cfg80211_bitrate_mask *mask)
  10869. {
  10870. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  10871. struct ath12k_link_vif *arvif;
  10872. struct cfg80211_chan_def def;
  10873. struct ath12k *ar;
  10874. enum nl80211_band band;
  10875. const u8 *ht_mcs_mask;
  10876. const u16 *vht_mcs_mask;
  10877. const u16 *he_mcs_mask;
  10878. const u16 *eht_mcs_mask;
  10879. u8 he_ltf = 0;
  10880. u8 he_gi = 0;
  10881. u8 eht_ltf = 0, eht_gi = 0;
  10882. u32 rate;
  10883. u8 nss, mac_nss;
  10884. u8 sgi;
  10885. u8 ldpc;
  10886. int single_nss;
  10887. int ret;
  10888. int num_rates;
  10889. bool he_fixed_rate = false;
  10890. bool eht_fixed_rate = false;
  10891. lockdep_assert_wiphy(hw->wiphy);
  10892. arvif = &ahvif->deflink;
  10893. ar = arvif->ar;
  10894. if (ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) {
  10895. ret = -EPERM;
  10896. goto out;
  10897. }
  10898. band = def.chan->band;
  10899. ht_mcs_mask = mask->control[band].ht_mcs;
  10900. vht_mcs_mask = mask->control[band].vht_mcs;
  10901. he_mcs_mask = mask->control[band].he_mcs;
  10902. eht_mcs_mask = mask->control[band].eht_mcs;
  10903. ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
  10904. sgi = mask->control[band].gi;
  10905. if (sgi == NL80211_TXRATE_FORCE_SGI) {
  10906. ret = -EINVAL;
  10907. goto out;
  10908. }
  10909. he_gi = mask->control[band].he_gi;
  10910. he_ltf = mask->control[band].he_ltf;
  10911. eht_gi = mask->control[band].eht_gi;
  10912. eht_ltf = mask->control[band].eht_ltf;
  10913. /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it
  10914. * requires passing at least one of used basic rates along with them.
  10915. * Fixed rate setting across different preambles(legacy, HT, VHT) is
  10916. * not supported by the FW. Hence use of FIXED_RATE vdev param is not
  10917. * suitable for setting single HT/VHT rates.
  10918. * But, there could be a single basic rate passed from userspace which
  10919. * can be done through the FIXED_RATE param.
  10920. */
  10921. if (ath12k_mac_has_single_legacy_rate(ar, band, mask)) {
  10922. ret = ath12k_mac_get_single_legacy_rate(ar, band, mask, &rate,
  10923. &nss);
  10924. if (ret) {
  10925. ath12k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n",
  10926. arvif->vdev_id, ret);
  10927. goto out;
  10928. }
  10929. ieee80211_iterate_stations_mtx(hw,
  10930. ath12k_mac_disable_peer_fixed_rate,
  10931. arvif);
  10932. } else if (ath12k_mac_bitrate_mask_get_single_nss(ar, vif, band, mask,
  10933. &single_nss)) {
  10934. rate = WMI_FIXED_RATE_NONE;
  10935. nss = single_nss;
  10936. arvif->bitrate_mask = *mask;
  10937. ieee80211_iterate_stations_atomic(hw,
  10938. ath12k_mac_set_bitrate_mask_iter,
  10939. arvif);
  10940. } else {
  10941. rate = WMI_FIXED_RATE_NONE;
  10942. if (!ath12k_mac_validate_fixed_rate_settings(ar, band,
  10943. mask, arvif->link_id))
  10944. ath12k_warn(ar->ab,
  10945. "failed to update fixed rate settings due to mcs/nss incompatibility\n");
  10946. mac_nss = max(max3(ath12k_mac_max_ht_nss(ht_mcs_mask),
  10947. ath12k_mac_max_vht_nss(vht_mcs_mask),
  10948. ath12k_mac_max_he_nss(he_mcs_mask)),
  10949. ath12k_mac_max_eht_nss(eht_mcs_mask));
  10950. nss = min_t(u32, ar->num_tx_chains, mac_nss);
  10951. /* If multiple rates across different preambles are given
  10952. * we can reconfigure this info with all peers using PEER_ASSOC
  10953. * command with the below exception cases.
  10954. * - Single VHT Rate : peer_assoc command accommodates only MCS
  10955. * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211
  10956. * mandates passing basic rates along with HT/VHT rates, FW
  10957. * doesn't allow switching from VHT to Legacy. Hence instead of
  10958. * setting legacy and VHT rates using RATEMASK_CMD vdev cmd,
  10959. * we could set this VHT rate as peer fixed rate param, which
  10960. * will override FIXED rate and FW rate control algorithm.
  10961. * If single VHT rate is passed along with HT rates, we select
  10962. * the VHT rate as fixed rate for vht peers.
  10963. * - Multiple VHT Rates : When Multiple VHT rates are given,this
  10964. * can be set using RATEMASK CMD which uses FW rate-ctl alg.
  10965. * TODO: Setting multiple VHT MCS and replacing peer_assoc with
  10966. * RATEMASK_CMDID can cover all use cases of setting rates
  10967. * across multiple preambles and rates within same type.
  10968. * But requires more validation of the command at this point.
  10969. */
  10970. num_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band,
  10971. mask);
  10972. if (!ath12k_mac_vht_mcs_range_present(ar, band, mask) &&
  10973. num_rates > 1) {
  10974. /* TODO: Handle multiple VHT MCS values setting using
  10975. * RATEMASK CMD
  10976. */
  10977. ath12k_warn(ar->ab,
  10978. "Setting more than one MCS Value in bitrate mask not supported\n");
  10979. ret = -EINVAL;
  10980. goto out;
  10981. }
  10982. num_rates = ath12k_mac_bitrate_mask_num_he_rates(ar, band, mask);
  10983. if (num_rates == 1)
  10984. he_fixed_rate = true;
  10985. if (!ath12k_mac_he_mcs_range_present(ar, band, mask) &&
  10986. num_rates > 1) {
  10987. ath12k_warn(ar->ab,
  10988. "Setting more than one HE MCS Value in bitrate mask not supported\n");
  10989. ret = -EINVAL;
  10990. goto out;
  10991. }
  10992. num_rates = ath12k_mac_bitrate_mask_num_eht_rates(ar, band,
  10993. mask);
  10994. if (num_rates == 1)
  10995. eht_fixed_rate = true;
  10996. if (!ath12k_mac_eht_mcs_range_present(ar, band, mask) &&
  10997. num_rates > 1) {
  10998. ath12k_warn(ar->ab,
  10999. "Setting more than one EHT MCS Value in bitrate mask not supported\n");
  11000. ret = -EINVAL;
  11001. goto out;
  11002. }
  11003. ieee80211_iterate_stations_mtx(hw,
  11004. ath12k_mac_disable_peer_fixed_rate,
  11005. arvif);
  11006. arvif->bitrate_mask = *mask;
  11007. ieee80211_iterate_stations_mtx(hw,
  11008. ath12k_mac_set_bitrate_mask_iter,
  11009. arvif);
  11010. }
  11011. ret = ath12k_mac_set_rate_params(arvif, rate, nss, sgi, ldpc, he_gi,
  11012. he_ltf, he_fixed_rate, eht_gi, eht_ltf,
  11013. eht_fixed_rate);
  11014. if (ret) {
  11015. ath12k_warn(ar->ab, "failed to set rate params on vdev %i: %d\n",
  11016. arvif->vdev_id, ret);
  11017. }
  11018. out:
  11019. return ret;
  11020. }
  11021. EXPORT_SYMBOL(ath12k_mac_op_set_bitrate_mask);
  11022. void
  11023. ath12k_mac_op_reconfig_complete(struct ieee80211_hw *hw,
  11024. enum ieee80211_reconfig_type reconfig_type)
  11025. {
  11026. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  11027. struct ath12k *ar;
  11028. struct ath12k_base *ab;
  11029. struct ath12k_vif *ahvif;
  11030. struct ath12k_link_vif *arvif;
  11031. int recovery_count, i;
  11032. lockdep_assert_wiphy(hw->wiphy);
  11033. if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
  11034. return;
  11035. guard(mutex)(&ah->hw_mutex);
  11036. if (ah->state != ATH12K_HW_STATE_RESTARTED)
  11037. return;
  11038. ah->state = ATH12K_HW_STATE_ON;
  11039. ieee80211_wake_queues(hw);
  11040. for_each_ar(ah, ar, i) {
  11041. ab = ar->ab;
  11042. ath12k_warn(ar->ab, "pdev %d successfully recovered\n",
  11043. ar->pdev->pdev_id);
  11044. if (ar->ab->hw_params->current_cc_support &&
  11045. ar->alpha2[0] != 0 && ar->alpha2[1] != 0) {
  11046. struct wmi_set_current_country_arg arg = {};
  11047. memcpy(&arg.alpha2, ar->alpha2, 2);
  11048. reinit_completion(&ar->regd_update_completed);
  11049. ath12k_wmi_send_set_current_country_cmd(ar, &arg);
  11050. }
  11051. if (ab->is_reset) {
  11052. recovery_count = atomic_inc_return(&ab->recovery_count);
  11053. ath12k_dbg(ab, ATH12K_DBG_BOOT, "recovery count %d\n",
  11054. recovery_count);
  11055. /* When there are multiple radios in an SOC,
  11056. * the recovery has to be done for each radio
  11057. */
  11058. if (recovery_count == ab->num_radios) {
  11059. atomic_dec(&ab->reset_count);
  11060. complete(&ab->reset_complete);
  11061. ab->is_reset = false;
  11062. atomic_set(&ab->fail_cont_count, 0);
  11063. ath12k_dbg(ab, ATH12K_DBG_BOOT, "reset success\n");
  11064. }
  11065. }
  11066. list_for_each_entry(arvif, &ar->arvifs, list) {
  11067. ahvif = arvif->ahvif;
  11068. ath12k_dbg(ab, ATH12K_DBG_BOOT,
  11069. "reconfig cipher %d up %d vdev type %d\n",
  11070. ahvif->dp_vif.key_cipher,
  11071. arvif->is_up,
  11072. ahvif->vdev_type);
  11073. /* After trigger disconnect, then upper layer will
  11074. * trigger connect again, then the PN number of
  11075. * upper layer will be reset to keep up with AP
  11076. * side, hence PN number mismatch will not happen.
  11077. */
  11078. if (arvif->is_up &&
  11079. ahvif->vdev_type == WMI_VDEV_TYPE_STA &&
  11080. ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) {
  11081. ieee80211_hw_restart_disconnect(ahvif->vif);
  11082. ath12k_dbg(ab, ATH12K_DBG_BOOT,
  11083. "restart disconnect\n");
  11084. }
  11085. }
  11086. }
  11087. }
  11088. EXPORT_SYMBOL(ath12k_mac_op_reconfig_complete);
  11089. static void
  11090. ath12k_mac_update_bss_chan_survey(struct ath12k *ar,
  11091. struct ieee80211_channel *channel)
  11092. {
  11093. int ret;
  11094. enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
  11095. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  11096. if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) ||
  11097. ar->rx_channel != channel)
  11098. return;
  11099. if (ar->scan.state != ATH12K_SCAN_IDLE) {
  11100. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  11101. "ignoring bss chan info req while scanning..\n");
  11102. return;
  11103. }
  11104. reinit_completion(&ar->bss_survey_done);
  11105. ret = ath12k_wmi_pdev_bss_chan_info_request(ar, type);
  11106. if (ret) {
  11107. ath12k_warn(ar->ab, "failed to send pdev bss chan info request\n");
  11108. return;
  11109. }
  11110. ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
  11111. if (ret == 0)
  11112. ath12k_warn(ar->ab, "bss channel survey timed out\n");
  11113. }
  11114. int ath12k_mac_op_get_survey(struct ieee80211_hw *hw, int idx,
  11115. struct survey_info *survey)
  11116. {
  11117. struct ath12k *ar;
  11118. struct ieee80211_supported_band *sband;
  11119. struct survey_info *ar_survey;
  11120. lockdep_assert_wiphy(hw->wiphy);
  11121. if (idx >= ATH12K_NUM_CHANS)
  11122. return -ENOENT;
  11123. sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
  11124. if (sband && idx >= sband->n_channels) {
  11125. idx -= sband->n_channels;
  11126. sband = NULL;
  11127. }
  11128. if (!sband)
  11129. sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
  11130. if (sband && idx >= sband->n_channels) {
  11131. idx -= sband->n_channels;
  11132. sband = NULL;
  11133. }
  11134. if (!sband)
  11135. sband = hw->wiphy->bands[NL80211_BAND_6GHZ];
  11136. if (!sband || idx >= sband->n_channels)
  11137. return -ENOENT;
  11138. ar = ath12k_mac_get_ar_by_chan(hw, &sband->channels[idx]);
  11139. if (!ar) {
  11140. if (sband->channels[idx].flags & IEEE80211_CHAN_DISABLED) {
  11141. memset(survey, 0, sizeof(*survey));
  11142. return 0;
  11143. }
  11144. return -ENOENT;
  11145. }
  11146. ar_survey = &ar->survey[idx];
  11147. ath12k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
  11148. spin_lock_bh(&ar->data_lock);
  11149. memcpy(survey, ar_survey, sizeof(*survey));
  11150. spin_unlock_bh(&ar->data_lock);
  11151. survey->channel = &sband->channels[idx];
  11152. if (ar->rx_channel == survey->channel)
  11153. survey->filled |= SURVEY_INFO_IN_USE;
  11154. return 0;
  11155. }
  11156. EXPORT_SYMBOL(ath12k_mac_op_get_survey);
  11157. static void ath12k_mac_put_chain_rssi(struct station_info *sinfo,
  11158. struct ath12k_link_sta *arsta)
  11159. {
  11160. s8 rssi;
  11161. int i;
  11162. for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
  11163. sinfo->chains &= ~BIT(i);
  11164. rssi = arsta->chain_signal[i];
  11165. if (rssi != ATH12K_DEFAULT_NOISE_FLOOR &&
  11166. rssi != ATH12K_INVALID_RSSI_FULL &&
  11167. rssi != ATH12K_INVALID_RSSI_EMPTY &&
  11168. rssi != 0) {
  11169. sinfo->chain_signal[i] = rssi;
  11170. sinfo->chains |= BIT(i);
  11171. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
  11172. }
  11173. }
  11174. }
  11175. void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw,
  11176. struct ieee80211_vif *vif,
  11177. struct ieee80211_sta *sta,
  11178. struct station_info *sinfo)
  11179. {
  11180. struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta);
  11181. struct ath12k_dp_link_peer_rate_info rate_info = {};
  11182. struct ath12k_fw_stats_req_params params = {};
  11183. struct ath12k_dp_link_peer *peer;
  11184. struct ath12k_link_sta *arsta;
  11185. s8 signal, noise_floor;
  11186. struct ath12k_dp *dp;
  11187. struct ath12k *ar;
  11188. bool db2dbm;
  11189. lockdep_assert_wiphy(hw->wiphy);
  11190. arsta = &ahsta->deflink;
  11191. ar = ath12k_get_ar_by_vif(hw, vif, arsta->link_id);
  11192. if (!ar)
  11193. return;
  11194. dp = ath12k_ab_to_dp(ar->ab);
  11195. ath12k_dp_link_peer_get_sta_rate_info_stats(dp, arsta->addr, &rate_info);
  11196. db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT,
  11197. ar->ab->wmi_ab.svc_map);
  11198. sinfo->rx_duration = rate_info.rx_duration;
  11199. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
  11200. sinfo->tx_duration = rate_info.tx_duration;
  11201. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
  11202. if (rate_info.txrate.legacy || rate_info.txrate.nss) {
  11203. if (rate_info.txrate.legacy) {
  11204. sinfo->txrate.legacy = rate_info.txrate.legacy;
  11205. } else {
  11206. sinfo->txrate.mcs = rate_info.txrate.mcs;
  11207. sinfo->txrate.nss = rate_info.txrate.nss;
  11208. sinfo->txrate.bw = rate_info.txrate.bw;
  11209. sinfo->txrate.he_gi = rate_info.txrate.he_gi;
  11210. sinfo->txrate.he_dcm = rate_info.txrate.he_dcm;
  11211. sinfo->txrate.he_ru_alloc = rate_info.txrate.he_ru_alloc;
  11212. sinfo->txrate.eht_gi = rate_info.txrate.eht_gi;
  11213. sinfo->txrate.eht_ru_alloc = rate_info.txrate.eht_ru_alloc;
  11214. }
  11215. sinfo->txrate.flags = rate_info.txrate.flags;
  11216. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
  11217. }
  11218. /* TODO: Use real NF instead of default one. */
  11219. signal = rate_info.rssi_comb;
  11220. params.pdev_id = ath12k_mac_get_target_pdev_id(ar);
  11221. params.vdev_id = 0;
  11222. params.stats_id = WMI_REQUEST_VDEV_STAT;
  11223. if (!signal &&
  11224. ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA &&
  11225. !(ath12k_mac_get_fw_stats(ar, &params))) {
  11226. signal = arsta->rssi_beacon;
  11227. ath12k_fw_stats_reset(ar);
  11228. }
  11229. params.stats_id = WMI_REQUEST_RSSI_PER_CHAIN_STAT;
  11230. if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) &&
  11231. ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA &&
  11232. !(ath12k_mac_get_fw_stats(ar, &params))) {
  11233. ath12k_mac_put_chain_rssi(sinfo, arsta);
  11234. ath12k_fw_stats_reset(ar);
  11235. }
  11236. spin_lock_bh(&ar->data_lock);
  11237. noise_floor = ath12k_pdev_get_noise_floor(ar);
  11238. spin_unlock_bh(&ar->data_lock);
  11239. if (signal) {
  11240. sinfo->signal = db2dbm ? signal : signal + noise_floor;
  11241. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
  11242. }
  11243. sinfo->signal_avg = rate_info.signal_avg;
  11244. if (!db2dbm)
  11245. sinfo->signal_avg += noise_floor;
  11246. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
  11247. spin_lock_bh(&dp->dp_lock);
  11248. peer = ath12k_dp_link_peer_find_by_addr(dp, arsta->addr);
  11249. if (!peer) {
  11250. spin_unlock_bh(&dp->dp_lock);
  11251. return;
  11252. }
  11253. sinfo->tx_retries = peer->tx_retry_count;
  11254. sinfo->tx_failed = peer->tx_retry_failed;
  11255. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
  11256. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
  11257. spin_unlock_bh(&dp->dp_lock);
  11258. }
  11259. EXPORT_SYMBOL(ath12k_mac_op_sta_statistics);
  11260. void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw,
  11261. struct ieee80211_vif *vif,
  11262. struct ieee80211_link_sta *link_sta,
  11263. struct link_station_info *link_sinfo)
  11264. {
  11265. struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(link_sta->sta);
  11266. struct ath12k_fw_stats_req_params params = {};
  11267. struct ath12k_dp_link_peer *peer;
  11268. struct ath12k_link_sta *arsta;
  11269. struct ath12k *ar;
  11270. s8 signal;
  11271. bool db2dbm;
  11272. lockdep_assert_wiphy(hw->wiphy);
  11273. arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_sta->link_id]);
  11274. if (!arsta)
  11275. return;
  11276. ar = ath12k_get_ar_by_vif(hw, vif, arsta->link_id);
  11277. if (!ar)
  11278. return;
  11279. db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT,
  11280. ar->ab->wmi_ab.svc_map);
  11281. spin_lock_bh(&ar->ab->dp->dp_lock);
  11282. peer = ath12k_dp_link_peer_find_by_addr(ar->ab->dp, arsta->addr);
  11283. if (!peer) {
  11284. spin_unlock_bh(&ar->ab->dp->dp_lock);
  11285. return;
  11286. }
  11287. link_sinfo->rx_duration = peer->rx_duration;
  11288. link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
  11289. link_sinfo->tx_duration = peer->tx_duration;
  11290. link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
  11291. if (peer->txrate.legacy || peer->txrate.nss) {
  11292. if (peer->txrate.legacy) {
  11293. link_sinfo->txrate.legacy = peer->txrate.legacy;
  11294. } else {
  11295. link_sinfo->txrate.mcs = peer->txrate.mcs;
  11296. link_sinfo->txrate.nss = peer->txrate.nss;
  11297. link_sinfo->txrate.bw = peer->txrate.bw;
  11298. link_sinfo->txrate.he_gi = peer->txrate.he_gi;
  11299. link_sinfo->txrate.he_dcm = peer->txrate.he_dcm;
  11300. link_sinfo->txrate.he_ru_alloc =
  11301. peer->txrate.he_ru_alloc;
  11302. link_sinfo->txrate.eht_gi = peer->txrate.eht_gi;
  11303. link_sinfo->txrate.eht_ru_alloc =
  11304. peer->txrate.eht_ru_alloc;
  11305. }
  11306. link_sinfo->txrate.flags = peer->txrate.flags;
  11307. link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
  11308. }
  11309. link_sinfo->signal_avg = ewma_avg_rssi_read(&peer->avg_rssi);
  11310. if (!db2dbm)
  11311. link_sinfo->signal_avg += ATH12K_DEFAULT_NOISE_FLOOR;
  11312. link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
  11313. link_sinfo->tx_retries = peer->tx_retry_count;
  11314. link_sinfo->tx_failed = peer->tx_retry_failed;
  11315. link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
  11316. link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
  11317. /* TODO: Use real NF instead of default one. */
  11318. signal = peer->rssi_comb;
  11319. spin_unlock_bh(&ar->ab->dp->dp_lock);
  11320. if (!signal && ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA) {
  11321. params.pdev_id = ath12k_mac_get_target_pdev_id(ar);
  11322. params.vdev_id = 0;
  11323. params.stats_id = WMI_REQUEST_VDEV_STAT;
  11324. if (!ath12k_mac_get_fw_stats(ar, &params)) {
  11325. signal = arsta->rssi_beacon;
  11326. ath12k_fw_stats_reset(ar);
  11327. }
  11328. }
  11329. if (signal) {
  11330. link_sinfo->signal =
  11331. db2dbm ? signal : signal + ATH12K_DEFAULT_NOISE_FLOOR;
  11332. link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
  11333. }
  11334. }
  11335. EXPORT_SYMBOL(ath12k_mac_op_link_sta_statistics);
  11336. int ath12k_mac_op_cancel_remain_on_channel(struct ieee80211_hw *hw,
  11337. struct ieee80211_vif *vif)
  11338. {
  11339. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  11340. struct ath12k *ar;
  11341. ar = ath12k_ah_to_ar(ah, 0);
  11342. lockdep_assert_wiphy(hw->wiphy);
  11343. spin_lock_bh(&ar->data_lock);
  11344. ar->scan.roc_notify = false;
  11345. spin_unlock_bh(&ar->data_lock);
  11346. ath12k_scan_abort(ar);
  11347. cancel_delayed_work_sync(&ar->scan.timeout);
  11348. wiphy_work_flush(hw->wiphy, &ar->scan.vdev_clean_wk);
  11349. return 0;
  11350. }
  11351. EXPORT_SYMBOL(ath12k_mac_op_cancel_remain_on_channel);
  11352. int ath12k_mac_op_remain_on_channel(struct ieee80211_hw *hw,
  11353. struct ieee80211_vif *vif,
  11354. struct ieee80211_channel *chan,
  11355. int duration,
  11356. enum ieee80211_roc_type type)
  11357. {
  11358. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  11359. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  11360. struct ath12k_link_vif *arvif;
  11361. struct ath12k *ar;
  11362. u32 scan_time_msec;
  11363. bool create = true;
  11364. u8 link_id;
  11365. int ret;
  11366. lockdep_assert_wiphy(hw->wiphy);
  11367. ar = ath12k_mac_select_scan_device(hw, vif, chan->center_freq);
  11368. if (!ar)
  11369. return -EINVAL;
  11370. /* check if any of the links of ML VIF is already started on
  11371. * radio(ar) corresponding to given scan frequency and use it,
  11372. * if not use deflink(link 0) for scan purpose.
  11373. */
  11374. link_id = ath12k_mac_find_link_id_by_ar(ahvif, ar);
  11375. arvif = ath12k_mac_assign_link_vif(ah, vif, link_id);
  11376. /* If the vif is already assigned to a specific vdev of an ar,
  11377. * check whether its already started, vdev which is started
  11378. * are not allowed to switch to a new radio.
  11379. * If the vdev is not started, but was earlier created on a
  11380. * different ar, delete that vdev and create a new one. We don't
  11381. * delete at the scan stop as an optimization to avoid redundant
  11382. * delete-create vdev's for the same ar, in case the request is
  11383. * always on the same band for the vif
  11384. */
  11385. if (arvif->is_created) {
  11386. if (WARN_ON(!arvif->ar))
  11387. return -EINVAL;
  11388. if (ar != arvif->ar && arvif->is_started)
  11389. return -EBUSY;
  11390. if (ar != arvif->ar) {
  11391. ath12k_mac_remove_link_interface(hw, arvif);
  11392. ath12k_mac_unassign_link_vif(arvif);
  11393. } else {
  11394. create = false;
  11395. }
  11396. }
  11397. if (create) {
  11398. arvif = ath12k_mac_assign_link_vif(ah, vif, link_id);
  11399. ret = ath12k_mac_vdev_create(ar, arvif);
  11400. if (ret) {
  11401. ath12k_warn(ar->ab, "unable to create scan vdev for roc: %d\n",
  11402. ret);
  11403. ath12k_mac_unassign_link_vif(arvif);
  11404. return ret;
  11405. }
  11406. }
  11407. spin_lock_bh(&ar->data_lock);
  11408. switch (ar->scan.state) {
  11409. case ATH12K_SCAN_IDLE:
  11410. reinit_completion(&ar->scan.started);
  11411. reinit_completion(&ar->scan.completed);
  11412. reinit_completion(&ar->scan.on_channel);
  11413. ar->scan.state = ATH12K_SCAN_STARTING;
  11414. ar->scan.is_roc = true;
  11415. ar->scan.arvif = arvif;
  11416. ar->scan.roc_freq = chan->center_freq;
  11417. ar->scan.roc_notify = true;
  11418. ret = 0;
  11419. break;
  11420. case ATH12K_SCAN_STARTING:
  11421. case ATH12K_SCAN_RUNNING:
  11422. case ATH12K_SCAN_ABORTING:
  11423. ret = -EBUSY;
  11424. break;
  11425. }
  11426. spin_unlock_bh(&ar->data_lock);
  11427. if (ret)
  11428. return ret;
  11429. scan_time_msec = hw->wiphy->max_remain_on_channel_duration * 2;
  11430. struct ath12k_wmi_scan_req_arg *arg __free(kfree) =
  11431. kzalloc_obj(*arg);
  11432. if (!arg)
  11433. return -ENOMEM;
  11434. ath12k_wmi_start_scan_init(ar, arg);
  11435. arg->num_chan = 1;
  11436. u32 *chan_list __free(kfree) = kcalloc(arg->num_chan, sizeof(*chan_list),
  11437. GFP_KERNEL);
  11438. if (!chan_list)
  11439. return -ENOMEM;
  11440. arg->chan_list = chan_list;
  11441. arg->vdev_id = arvif->vdev_id;
  11442. arg->scan_id = ATH12K_SCAN_ID;
  11443. arg->chan_list[0] = chan->center_freq;
  11444. arg->dwell_time_active = scan_time_msec;
  11445. arg->dwell_time_passive = scan_time_msec;
  11446. arg->max_scan_time = scan_time_msec;
  11447. arg->scan_f_passive = 1;
  11448. arg->burst_duration = duration;
  11449. ret = ath12k_start_scan(ar, arg);
  11450. if (ret) {
  11451. ath12k_warn(ar->ab, "failed to start roc scan: %d\n", ret);
  11452. spin_lock_bh(&ar->data_lock);
  11453. ar->scan.state = ATH12K_SCAN_IDLE;
  11454. spin_unlock_bh(&ar->data_lock);
  11455. return ret;
  11456. }
  11457. ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
  11458. if (ret == 0) {
  11459. ath12k_warn(ar->ab, "failed to switch to channel for roc scan\n");
  11460. ret = ath12k_scan_stop(ar);
  11461. if (ret)
  11462. ath12k_warn(ar->ab, "failed to stop scan: %d\n", ret);
  11463. return -ETIMEDOUT;
  11464. }
  11465. ieee80211_queue_delayed_work(hw, &ar->scan.timeout,
  11466. msecs_to_jiffies(duration));
  11467. return 0;
  11468. }
  11469. EXPORT_SYMBOL(ath12k_mac_op_remain_on_channel);
  11470. void ath12k_mac_op_set_rekey_data(struct ieee80211_hw *hw,
  11471. struct ieee80211_vif *vif,
  11472. struct cfg80211_gtk_rekey_data *data)
  11473. {
  11474. struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
  11475. struct ath12k_rekey_data *rekey_data;
  11476. struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
  11477. struct ath12k *ar = ath12k_ah_to_ar(ah, 0);
  11478. struct ath12k_link_vif *arvif;
  11479. lockdep_assert_wiphy(hw->wiphy);
  11480. arvif = &ahvif->deflink;
  11481. rekey_data = &arvif->rekey_data;
  11482. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac set rekey data vdev %d\n",
  11483. arvif->vdev_id);
  11484. memcpy(rekey_data->kck, data->kck, NL80211_KCK_LEN);
  11485. memcpy(rekey_data->kek, data->kek, NL80211_KEK_LEN);
  11486. /* The supplicant works on big-endian, the firmware expects it on
  11487. * little endian.
  11488. */
  11489. rekey_data->replay_ctr = get_unaligned_be64(data->replay_ctr);
  11490. arvif->rekey_data.enable_offload = true;
  11491. ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "kck", NULL,
  11492. rekey_data->kck, NL80211_KCK_LEN);
  11493. ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "kek", NULL,
  11494. rekey_data->kck, NL80211_KEK_LEN);
  11495. ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "replay ctr", NULL,
  11496. &rekey_data->replay_ctr, sizeof(rekey_data->replay_ctr));
  11497. }
  11498. EXPORT_SYMBOL(ath12k_mac_op_set_rekey_data);
  11499. void ath12k_mac_update_freq_range(struct ath12k *ar,
  11500. u32 freq_low, u32 freq_high)
  11501. {
  11502. if (!(freq_low && freq_high))
  11503. return;
  11504. if (ar->freq_range.start_freq || ar->freq_range.end_freq) {
  11505. ar->freq_range.start_freq = min(ar->freq_range.start_freq,
  11506. MHZ_TO_KHZ(freq_low));
  11507. ar->freq_range.end_freq = max(ar->freq_range.end_freq,
  11508. MHZ_TO_KHZ(freq_high));
  11509. } else {
  11510. ar->freq_range.start_freq = MHZ_TO_KHZ(freq_low);
  11511. ar->freq_range.end_freq = MHZ_TO_KHZ(freq_high);
  11512. }
  11513. ath12k_dbg(ar->ab, ATH12K_DBG_MAC,
  11514. "mac pdev %u freq limit updated. New range %u->%u MHz\n",
  11515. ar->pdev->pdev_id, KHZ_TO_MHZ(ar->freq_range.start_freq),
  11516. KHZ_TO_MHZ(ar->freq_range.end_freq));
  11517. }
  11518. static void ath12k_mac_update_ch_list(struct ath12k *ar,
  11519. struct ieee80211_supported_band *band,
  11520. u32 freq_low, u32 freq_high)
  11521. {
  11522. int i;
  11523. if (!(freq_low && freq_high))
  11524. return;
  11525. for (i = 0; i < band->n_channels; i++) {
  11526. if (band->channels[i].center_freq < freq_low ||
  11527. band->channels[i].center_freq > freq_high)
  11528. band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
  11529. }
  11530. }
  11531. static u32 ath12k_get_phy_id(struct ath12k *ar, u32 band)
  11532. {
  11533. struct ath12k_pdev *pdev = ar->pdev;
  11534. struct ath12k_pdev_cap *pdev_cap = &pdev->cap;
  11535. if (band == WMI_HOST_WLAN_2GHZ_CAP)
  11536. return pdev_cap->band[NL80211_BAND_2GHZ].phy_id;
  11537. if (band == WMI_HOST_WLAN_5GHZ_CAP)
  11538. return pdev_cap->band[NL80211_BAND_5GHZ].phy_id;
  11539. ath12k_warn(ar->ab, "unsupported phy cap:%d\n", band);
  11540. return 0;
  11541. }
  11542. static int ath12k_mac_update_band(struct ath12k *ar,
  11543. struct ieee80211_supported_band *orig_band,
  11544. struct ieee80211_supported_band *new_band)
  11545. {
  11546. int i;
  11547. if (!orig_band || !new_band)
  11548. return -EINVAL;
  11549. if (orig_band->band != new_band->band)
  11550. return -EINVAL;
  11551. for (i = 0; i < new_band->n_channels; i++) {
  11552. if (new_band->channels[i].flags & IEEE80211_CHAN_DISABLED)
  11553. continue;
  11554. /* An enabled channel in new_band should not be already enabled
  11555. * in the orig_band
  11556. */
  11557. if (WARN_ON(!(orig_band->channels[i].flags &
  11558. IEEE80211_CHAN_DISABLED)))
  11559. return -EINVAL;
  11560. orig_band->channels[i].flags &= ~IEEE80211_CHAN_DISABLED;
  11561. }
  11562. return 0;
  11563. }
  11564. static int ath12k_mac_setup_channels_rates(struct ath12k *ar,
  11565. u32 supported_bands,
  11566. struct ieee80211_supported_band *bands[])
  11567. {
  11568. struct ieee80211_supported_band *band;
  11569. struct ath12k_wmi_hal_reg_capabilities_ext_arg *reg_cap;
  11570. struct ath12k_base *ab = ar->ab;
  11571. u32 phy_id, freq_low, freq_high;
  11572. struct ath12k_hw *ah = ar->ah;
  11573. void *channels;
  11574. int ret;
  11575. BUILD_BUG_ON((ARRAY_SIZE(ath12k_2ghz_channels) +
  11576. ARRAY_SIZE(ath12k_5ghz_channels) +
  11577. ARRAY_SIZE(ath12k_6ghz_channels)) !=
  11578. ATH12K_NUM_CHANS);
  11579. reg_cap = &ab->hal_reg_cap[ar->pdev_idx];
  11580. if (supported_bands & WMI_HOST_WLAN_2GHZ_CAP) {
  11581. channels = kmemdup(ath12k_2ghz_channels,
  11582. sizeof(ath12k_2ghz_channels),
  11583. GFP_KERNEL);
  11584. if (!channels)
  11585. return -ENOMEM;
  11586. band = &ar->mac.sbands[NL80211_BAND_2GHZ];
  11587. band->band = NL80211_BAND_2GHZ;
  11588. band->n_channels = ARRAY_SIZE(ath12k_2ghz_channels);
  11589. band->channels = channels;
  11590. band->n_bitrates = ath12k_g_rates_size;
  11591. band->bitrates = ath12k_g_rates;
  11592. if (ab->hw_params->single_pdev_only) {
  11593. phy_id = ath12k_get_phy_id(ar, WMI_HOST_WLAN_2GHZ_CAP);
  11594. reg_cap = &ab->hal_reg_cap[phy_id];
  11595. }
  11596. freq_low = max(reg_cap->low_2ghz_chan,
  11597. ab->reg_freq_2ghz.start_freq);
  11598. freq_high = min(reg_cap->high_2ghz_chan,
  11599. ab->reg_freq_2ghz.end_freq);
  11600. ath12k_mac_update_ch_list(ar, band,
  11601. reg_cap->low_2ghz_chan,
  11602. reg_cap->high_2ghz_chan);
  11603. ath12k_mac_update_freq_range(ar, freq_low, freq_high);
  11604. if (!bands[NL80211_BAND_2GHZ]) {
  11605. bands[NL80211_BAND_2GHZ] = band;
  11606. } else {
  11607. /* Split mac in same band under same wiphy */
  11608. ret = ath12k_mac_update_band(ar, bands[NL80211_BAND_2GHZ], band);
  11609. if (ret) {
  11610. kfree(channels);
  11611. band->channels = NULL;
  11612. return ret;
  11613. }
  11614. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac pdev %u identified as 2 GHz split mac with start freq %d end freq %d",
  11615. ar->pdev->pdev_id,
  11616. KHZ_TO_MHZ(ar->freq_range.start_freq),
  11617. KHZ_TO_MHZ(ar->freq_range.end_freq));
  11618. }
  11619. }
  11620. if (supported_bands & WMI_HOST_WLAN_5GHZ_CAP) {
  11621. if (reg_cap->high_5ghz_chan >= ATH12K_MIN_6GHZ_FREQ) {
  11622. channels = kmemdup(ath12k_6ghz_channels,
  11623. sizeof(ath12k_6ghz_channels), GFP_KERNEL);
  11624. if (!channels) {
  11625. kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
  11626. return -ENOMEM;
  11627. }
  11628. ar->supports_6ghz = true;
  11629. band = &ar->mac.sbands[NL80211_BAND_6GHZ];
  11630. band->band = NL80211_BAND_6GHZ;
  11631. band->n_channels = ARRAY_SIZE(ath12k_6ghz_channels);
  11632. band->channels = channels;
  11633. band->n_bitrates = ath12k_a_rates_size;
  11634. band->bitrates = ath12k_a_rates;
  11635. freq_low = max(reg_cap->low_5ghz_chan,
  11636. ab->reg_freq_6ghz.start_freq);
  11637. freq_high = min(reg_cap->high_5ghz_chan,
  11638. ab->reg_freq_6ghz.end_freq);
  11639. ath12k_mac_update_ch_list(ar, band,
  11640. reg_cap->low_5ghz_chan,
  11641. reg_cap->high_5ghz_chan);
  11642. ath12k_mac_update_freq_range(ar, freq_low, freq_high);
  11643. ah->use_6ghz_regd = true;
  11644. if (!bands[NL80211_BAND_6GHZ]) {
  11645. bands[NL80211_BAND_6GHZ] = band;
  11646. } else {
  11647. /* Split mac in same band under same wiphy */
  11648. ret = ath12k_mac_update_band(ar,
  11649. bands[NL80211_BAND_6GHZ],
  11650. band);
  11651. if (ret) {
  11652. kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
  11653. ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL;
  11654. kfree(channels);
  11655. band->channels = NULL;
  11656. return ret;
  11657. }
  11658. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac pdev %u identified as 6 GHz split mac with start freq %d end freq %d",
  11659. ar->pdev->pdev_id,
  11660. KHZ_TO_MHZ(ar->freq_range.start_freq),
  11661. KHZ_TO_MHZ(ar->freq_range.end_freq));
  11662. }
  11663. }
  11664. if (reg_cap->low_5ghz_chan < ATH12K_MIN_6GHZ_FREQ) {
  11665. channels = kmemdup(ath12k_5ghz_channels,
  11666. sizeof(ath12k_5ghz_channels),
  11667. GFP_KERNEL);
  11668. if (!channels) {
  11669. kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
  11670. kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
  11671. return -ENOMEM;
  11672. }
  11673. band = &ar->mac.sbands[NL80211_BAND_5GHZ];
  11674. band->band = NL80211_BAND_5GHZ;
  11675. band->n_channels = ARRAY_SIZE(ath12k_5ghz_channels);
  11676. band->channels = channels;
  11677. band->n_bitrates = ath12k_a_rates_size;
  11678. band->bitrates = ath12k_a_rates;
  11679. if (ab->hw_params->single_pdev_only) {
  11680. phy_id = ath12k_get_phy_id(ar, WMI_HOST_WLAN_5GHZ_CAP);
  11681. reg_cap = &ab->hal_reg_cap[phy_id];
  11682. }
  11683. freq_low = max(reg_cap->low_5ghz_chan,
  11684. ab->reg_freq_5ghz.start_freq);
  11685. freq_high = min(reg_cap->high_5ghz_chan,
  11686. ab->reg_freq_5ghz.end_freq);
  11687. ath12k_mac_update_ch_list(ar, band,
  11688. reg_cap->low_5ghz_chan,
  11689. reg_cap->high_5ghz_chan);
  11690. ath12k_mac_update_freq_range(ar, freq_low, freq_high);
  11691. if (!bands[NL80211_BAND_5GHZ]) {
  11692. bands[NL80211_BAND_5GHZ] = band;
  11693. } else {
  11694. /* Split mac in same band under same wiphy */
  11695. ret = ath12k_mac_update_band(ar,
  11696. bands[NL80211_BAND_5GHZ],
  11697. band);
  11698. if (ret) {
  11699. kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
  11700. ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL;
  11701. kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
  11702. ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL;
  11703. kfree(channels);
  11704. band->channels = NULL;
  11705. return ret;
  11706. }
  11707. ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac pdev %u identified as 5 GHz split mac with start freq %d end freq %d",
  11708. ar->pdev->pdev_id,
  11709. KHZ_TO_MHZ(ar->freq_range.start_freq),
  11710. KHZ_TO_MHZ(ar->freq_range.end_freq));
  11711. }
  11712. }
  11713. }
  11714. return 0;
  11715. }
  11716. static u16 ath12k_mac_get_ifmodes(struct ath12k_hw *ah)
  11717. {
  11718. struct ath12k *ar;
  11719. int i;
  11720. u16 interface_modes = U16_MAX;
  11721. for_each_ar(ah, ar, i)
  11722. interface_modes &= ar->ab->hw_params->interface_modes;
  11723. return interface_modes == U16_MAX ? 0 : interface_modes;
  11724. }
  11725. static bool ath12k_mac_is_iface_mode_enable(struct ath12k_hw *ah,
  11726. enum nl80211_iftype type)
  11727. {
  11728. struct ath12k *ar;
  11729. int i;
  11730. u16 interface_modes, mode = 0;
  11731. bool is_enable = false;
  11732. if (type == NL80211_IFTYPE_MESH_POINT) {
  11733. if (IS_ENABLED(CONFIG_MAC80211_MESH))
  11734. mode = BIT(type);
  11735. } else {
  11736. mode = BIT(type);
  11737. }
  11738. for_each_ar(ah, ar, i) {
  11739. interface_modes = ar->ab->hw_params->interface_modes;
  11740. if (interface_modes & mode) {
  11741. is_enable = true;
  11742. break;
  11743. }
  11744. }
  11745. return is_enable;
  11746. }
  11747. static int
  11748. ath12k_mac_setup_radio_iface_comb(struct ath12k *ar,
  11749. struct ieee80211_iface_combination *comb)
  11750. {
  11751. u16 interface_modes = ar->ab->hw_params->interface_modes;
  11752. struct ieee80211_iface_limit *limits;
  11753. int n_limits, max_interfaces;
  11754. bool ap, mesh, p2p;
  11755. ap = interface_modes & BIT(NL80211_IFTYPE_AP);
  11756. p2p = interface_modes & BIT(NL80211_IFTYPE_P2P_DEVICE);
  11757. mesh = IS_ENABLED(CONFIG_MAC80211_MESH) &&
  11758. (interface_modes & BIT(NL80211_IFTYPE_MESH_POINT));
  11759. if ((ap || mesh) && !p2p) {
  11760. n_limits = 2;
  11761. max_interfaces = 16;
  11762. } else if (p2p) {
  11763. n_limits = 3;
  11764. if (ap || mesh)
  11765. max_interfaces = 16;
  11766. else
  11767. max_interfaces = 3;
  11768. } else {
  11769. n_limits = 1;
  11770. max_interfaces = 1;
  11771. }
  11772. limits = kzalloc_objs(*limits, n_limits);
  11773. if (!limits)
  11774. return -ENOMEM;
  11775. limits[0].max = 1;
  11776. limits[0].types |= BIT(NL80211_IFTYPE_STATION);
  11777. if (ap || mesh || p2p)
  11778. limits[1].max = max_interfaces;
  11779. if (ap)
  11780. limits[1].types |= BIT(NL80211_IFTYPE_AP);
  11781. if (mesh)
  11782. limits[1].types |= BIT(NL80211_IFTYPE_MESH_POINT);
  11783. if (p2p) {
  11784. limits[1].types |= BIT(NL80211_IFTYPE_P2P_CLIENT) |
  11785. BIT(NL80211_IFTYPE_P2P_GO);
  11786. limits[2].max = 1;
  11787. limits[2].types |= BIT(NL80211_IFTYPE_P2P_DEVICE);
  11788. }
  11789. comb[0].limits = limits;
  11790. comb[0].n_limits = n_limits;
  11791. comb[0].max_interfaces = max_interfaces;
  11792. comb[0].beacon_int_infra_match = true;
  11793. comb[0].beacon_int_min_gcd = 100;
  11794. comb[0].num_different_channels = 1;
  11795. comb[0].radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  11796. BIT(NL80211_CHAN_WIDTH_20) |
  11797. BIT(NL80211_CHAN_WIDTH_40) |
  11798. BIT(NL80211_CHAN_WIDTH_80) |
  11799. BIT(NL80211_CHAN_WIDTH_160);
  11800. return 0;
  11801. }
  11802. static int
  11803. ath12k_mac_setup_global_iface_comb(struct ath12k_hw *ah,
  11804. struct wiphy_radio *radio,
  11805. u8 n_radio,
  11806. struct ieee80211_iface_combination *comb)
  11807. {
  11808. const struct ieee80211_iface_combination *iter_comb;
  11809. struct ieee80211_iface_limit *limits;
  11810. int i, j, n_limits;
  11811. bool ap, mesh, p2p;
  11812. if (!n_radio)
  11813. return 0;
  11814. ap = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_AP);
  11815. p2p = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_P2P_DEVICE);
  11816. mesh = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_MESH_POINT);
  11817. if ((ap || mesh) && !p2p)
  11818. n_limits = 2;
  11819. else if (p2p)
  11820. n_limits = 3;
  11821. else
  11822. n_limits = 1;
  11823. limits = kzalloc_objs(*limits, n_limits);
  11824. if (!limits)
  11825. return -ENOMEM;
  11826. for (i = 0; i < n_radio; i++) {
  11827. iter_comb = radio[i].iface_combinations;
  11828. for (j = 0; j < iter_comb->n_limits && j < n_limits; j++) {
  11829. limits[j].types |= iter_comb->limits[j].types;
  11830. limits[j].max += iter_comb->limits[j].max;
  11831. }
  11832. comb->max_interfaces += iter_comb->max_interfaces;
  11833. comb->num_different_channels += iter_comb->num_different_channels;
  11834. comb->radar_detect_widths |= iter_comb->radar_detect_widths;
  11835. }
  11836. comb->limits = limits;
  11837. comb->n_limits = n_limits;
  11838. comb->beacon_int_infra_match = true;
  11839. comb->beacon_int_min_gcd = 100;
  11840. return 0;
  11841. }
  11842. static
  11843. void ath12k_mac_cleanup_iface_comb(const struct ieee80211_iface_combination *iface_comb)
  11844. {
  11845. kfree(iface_comb[0].limits);
  11846. kfree(iface_comb);
  11847. }
  11848. static void ath12k_mac_cleanup_iface_combinations(struct ath12k_hw *ah)
  11849. {
  11850. struct wiphy *wiphy = ah->hw->wiphy;
  11851. const struct wiphy_radio *radio;
  11852. int i;
  11853. if (wiphy->n_radio > 0) {
  11854. radio = wiphy->radio;
  11855. for (i = 0; i < wiphy->n_radio; i++)
  11856. ath12k_mac_cleanup_iface_comb(radio[i].iface_combinations);
  11857. kfree(wiphy->radio);
  11858. }
  11859. ath12k_mac_cleanup_iface_comb(wiphy->iface_combinations);
  11860. }
  11861. static int ath12k_mac_setup_iface_combinations(struct ath12k_hw *ah)
  11862. {
  11863. struct ieee80211_iface_combination *combinations, *comb;
  11864. struct wiphy *wiphy = ah->hw->wiphy;
  11865. struct wiphy_radio *radio;
  11866. int n_combinations = 1;
  11867. struct ath12k *ar;
  11868. int i, ret;
  11869. if (ah->num_radio == 1) {
  11870. ar = &ah->radio[0];
  11871. if (ar->ab->hw_params->single_pdev_only)
  11872. n_combinations = 2;
  11873. combinations = kzalloc_objs(*combinations, n_combinations);
  11874. if (!combinations)
  11875. return -ENOMEM;
  11876. ret = ath12k_mac_setup_radio_iface_comb(ar, combinations);
  11877. if (ret) {
  11878. ath12k_hw_warn(ah, "failed to setup radio interface combinations for one radio: %d",
  11879. ret);
  11880. goto err_free_combinations;
  11881. }
  11882. if (ar->ab->hw_params->single_pdev_only) {
  11883. comb = combinations + 1;
  11884. memcpy(comb, combinations, sizeof(*comb));
  11885. comb->num_different_channels = 2;
  11886. comb->radar_detect_widths = 0;
  11887. }
  11888. goto out;
  11889. }
  11890. combinations = kzalloc_objs(*combinations, n_combinations);
  11891. if (!combinations)
  11892. return -ENOMEM;
  11893. /* there are multiple radios */
  11894. radio = kzalloc_objs(*radio, ah->num_radio);
  11895. if (!radio) {
  11896. ret = -ENOMEM;
  11897. goto err_free_combinations;
  11898. }
  11899. for_each_ar(ah, ar, i) {
  11900. comb = kzalloc_obj(*comb);
  11901. if (!comb) {
  11902. ret = -ENOMEM;
  11903. goto err_free_radios;
  11904. }
  11905. ret = ath12k_mac_setup_radio_iface_comb(ar, comb);
  11906. if (ret) {
  11907. ath12k_hw_warn(ah, "failed to setup radio interface combinations for radio %d: %d",
  11908. i, ret);
  11909. kfree(comb);
  11910. goto err_free_radios;
  11911. }
  11912. radio[i].freq_range = &ar->freq_range;
  11913. radio[i].n_freq_range = 1;
  11914. radio[i].iface_combinations = comb;
  11915. radio[i].n_iface_combinations = 1;
  11916. }
  11917. ret = ath12k_mac_setup_global_iface_comb(ah, radio, ah->num_radio, combinations);
  11918. if (ret) {
  11919. ath12k_hw_warn(ah, "failed to setup global interface combinations: %d",
  11920. ret);
  11921. goto err_free_all_radios;
  11922. }
  11923. wiphy->radio = radio;
  11924. wiphy->n_radio = ah->num_radio;
  11925. out:
  11926. wiphy->iface_combinations = combinations;
  11927. wiphy->n_iface_combinations = n_combinations;
  11928. return 0;
  11929. err_free_all_radios:
  11930. i = ah->num_radio;
  11931. err_free_radios:
  11932. while (i--)
  11933. ath12k_mac_cleanup_iface_comb(radio[i].iface_combinations);
  11934. kfree(radio);
  11935. err_free_combinations:
  11936. kfree(combinations);
  11937. return ret;
  11938. }
  11939. static const u8 ath12k_if_types_ext_capa[] = {
  11940. [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
  11941. [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
  11942. [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
  11943. };
  11944. static const u8 ath12k_if_types_ext_capa_sta[] = {
  11945. [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
  11946. [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
  11947. [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
  11948. [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
  11949. };
  11950. static const u8 ath12k_if_types_ext_capa_ap[] = {
  11951. [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
  11952. [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
  11953. [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
  11954. [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT,
  11955. [10] = WLAN_EXT_CAPA11_EMA_SUPPORT,
  11956. };
  11957. static struct wiphy_iftype_ext_capab ath12k_iftypes_ext_capa[] = {
  11958. {
  11959. .extended_capabilities = ath12k_if_types_ext_capa,
  11960. .extended_capabilities_mask = ath12k_if_types_ext_capa,
  11961. .extended_capabilities_len = sizeof(ath12k_if_types_ext_capa),
  11962. }, {
  11963. .iftype = NL80211_IFTYPE_STATION,
  11964. .extended_capabilities = ath12k_if_types_ext_capa_sta,
  11965. .extended_capabilities_mask = ath12k_if_types_ext_capa_sta,
  11966. .extended_capabilities_len =
  11967. sizeof(ath12k_if_types_ext_capa_sta),
  11968. }, {
  11969. .iftype = NL80211_IFTYPE_AP,
  11970. .extended_capabilities = ath12k_if_types_ext_capa_ap,
  11971. .extended_capabilities_mask = ath12k_if_types_ext_capa_ap,
  11972. .extended_capabilities_len =
  11973. sizeof(ath12k_if_types_ext_capa_ap),
  11974. .eml_capabilities = 0,
  11975. .mld_capa_and_ops = 0,
  11976. },
  11977. };
  11978. static void ath12k_mac_cleanup_unregister(struct ath12k *ar)
  11979. {
  11980. idr_for_each(&ar->txmgmt_idr, ath12k_mac_tx_mgmt_pending_free, ar);
  11981. idr_destroy(&ar->txmgmt_idr);
  11982. kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
  11983. kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
  11984. kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
  11985. }
  11986. static void ath12k_mac_hw_unregister(struct ath12k_hw *ah)
  11987. {
  11988. struct ieee80211_hw *hw = ah->hw;
  11989. struct ath12k *ar;
  11990. int i;
  11991. for_each_ar(ah, ar, i) {
  11992. cancel_work_sync(&ar->regd_channel_update_work);
  11993. cancel_work_sync(&ar->regd_update_work);
  11994. ath12k_debugfs_unregister(ar);
  11995. ath12k_fw_stats_reset(ar);
  11996. }
  11997. ieee80211_unregister_hw(hw);
  11998. for_each_ar(ah, ar, i)
  11999. ath12k_mac_cleanup_unregister(ar);
  12000. ath12k_mac_cleanup_iface_combinations(ah);
  12001. SET_IEEE80211_DEV(hw, NULL);
  12002. }
  12003. static int ath12k_mac_setup_register(struct ath12k *ar,
  12004. u32 *ht_cap,
  12005. struct ieee80211_supported_band *bands[])
  12006. {
  12007. struct ath12k_pdev_cap *cap = &ar->pdev->cap;
  12008. int ret;
  12009. init_waitqueue_head(&ar->txmgmt_empty_waitq);
  12010. idr_init(&ar->txmgmt_idr);
  12011. spin_lock_init(&ar->txmgmt_idr_lock);
  12012. ath12k_pdev_caps_update(ar);
  12013. ret = ath12k_mac_setup_channels_rates(ar,
  12014. cap->supported_bands,
  12015. bands);
  12016. if (ret)
  12017. return ret;
  12018. ath12k_mac_setup_ht_vht_cap(ar, cap, ht_cap);
  12019. ath12k_mac_setup_sband_iftype_data(ar, cap);
  12020. ar->max_num_stations = ath12k_core_get_max_station_per_radio(ar->ab);
  12021. ar->max_num_peers = ath12k_core_get_max_peers_per_radio(ar->ab);
  12022. ar->rssi_info.min_nf_dbm = ATH12K_DEFAULT_NOISE_FLOOR;
  12023. ar->rssi_info.temp_offset = 0;
  12024. ar->rssi_info.noise_floor = ar->rssi_info.min_nf_dbm + ar->rssi_info.temp_offset;
  12025. return 0;
  12026. }
  12027. static int ath12k_mac_hw_register(struct ath12k_hw *ah)
  12028. {
  12029. struct ieee80211_hw *hw = ah->hw;
  12030. struct wiphy *wiphy = hw->wiphy;
  12031. struct ath12k *ar = ath12k_ah_to_ar(ah, 0);
  12032. struct ath12k_base *ab = ar->ab;
  12033. struct ath12k_pdev *pdev;
  12034. struct ath12k_pdev_cap *cap;
  12035. static const u32 cipher_suites[] = {
  12036. WLAN_CIPHER_SUITE_TKIP,
  12037. WLAN_CIPHER_SUITE_CCMP,
  12038. WLAN_CIPHER_SUITE_AES_CMAC,
  12039. WLAN_CIPHER_SUITE_BIP_CMAC_256,
  12040. WLAN_CIPHER_SUITE_BIP_GMAC_128,
  12041. WLAN_CIPHER_SUITE_BIP_GMAC_256,
  12042. WLAN_CIPHER_SUITE_GCMP,
  12043. WLAN_CIPHER_SUITE_GCMP_256,
  12044. WLAN_CIPHER_SUITE_CCMP_256,
  12045. };
  12046. int ret, i, j;
  12047. u32 ht_cap = U32_MAX, antennas_rx = 0, antennas_tx = 0;
  12048. bool is_6ghz = false, is_raw_mode = false, is_monitor_disable = false;
  12049. u8 *mac_addr = NULL;
  12050. u8 mbssid_max_interfaces = 0;
  12051. wiphy->max_ap_assoc_sta = 0;
  12052. for_each_ar(ah, ar, i) {
  12053. u32 ht_cap_info = 0;
  12054. pdev = ar->pdev;
  12055. if (ar->ab->pdevs_macaddr_valid) {
  12056. ether_addr_copy(ar->mac_addr, pdev->mac_addr);
  12057. } else {
  12058. ether_addr_copy(ar->mac_addr, ar->ab->mac_addr);
  12059. ar->mac_addr[4] += ar->pdev_idx;
  12060. }
  12061. ret = ath12k_mac_setup_register(ar, &ht_cap_info, hw->wiphy->bands);
  12062. if (ret)
  12063. goto err_cleanup_unregister;
  12064. /* 6 GHz does not support HT Cap, hence do not consider it */
  12065. if (!ar->supports_6ghz)
  12066. ht_cap &= ht_cap_info;
  12067. wiphy->max_ap_assoc_sta += ar->max_num_stations;
  12068. /* Advertise the max antenna support of all radios, driver can handle
  12069. * per pdev specific antenna setting based on pdev cap when antenna
  12070. * changes are made
  12071. */
  12072. cap = &pdev->cap;
  12073. antennas_rx = max_t(u32, antennas_rx, cap->rx_chain_mask);
  12074. antennas_tx = max_t(u32, antennas_tx, cap->tx_chain_mask);
  12075. if (ar->supports_6ghz)
  12076. is_6ghz = true;
  12077. if (test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags))
  12078. is_raw_mode = true;
  12079. if (!ar->ab->hw_params->supports_monitor)
  12080. is_monitor_disable = true;
  12081. if (i == 0)
  12082. mac_addr = ar->mac_addr;
  12083. else
  12084. mac_addr = ab->mac_addr;
  12085. mbssid_max_interfaces += TARGET_NUM_VDEVS(ar->ab);
  12086. }
  12087. wiphy->available_antennas_rx = antennas_rx;
  12088. wiphy->available_antennas_tx = antennas_tx;
  12089. SET_IEEE80211_PERM_ADDR(hw, mac_addr);
  12090. SET_IEEE80211_DEV(hw, ab->dev);
  12091. ret = ath12k_mac_setup_iface_combinations(ah);
  12092. if (ret) {
  12093. ath12k_err(ab, "failed to setup interface combinations: %d\n", ret);
  12094. goto err_complete_cleanup_unregister;
  12095. }
  12096. wiphy->interface_modes = ath12k_mac_get_ifmodes(ah);
  12097. if (ah->num_radio == 1 &&
  12098. wiphy->bands[NL80211_BAND_2GHZ] &&
  12099. wiphy->bands[NL80211_BAND_5GHZ] &&
  12100. wiphy->bands[NL80211_BAND_6GHZ])
  12101. ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
  12102. ieee80211_hw_set(hw, SIGNAL_DBM);
  12103. ieee80211_hw_set(hw, SUPPORTS_PS);
  12104. ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
  12105. ieee80211_hw_set(hw, MFP_CAPABLE);
  12106. ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
  12107. ieee80211_hw_set(hw, HAS_RATE_CONTROL);
  12108. ieee80211_hw_set(hw, AP_LINK_PS);
  12109. ieee80211_hw_set(hw, SPECTRUM_MGMT);
  12110. ieee80211_hw_set(hw, CONNECTION_MONITOR);
  12111. ieee80211_hw_set(hw, SUPPORTS_PER_STA_GTK);
  12112. ieee80211_hw_set(hw, CHANCTX_STA_CSA);
  12113. ieee80211_hw_set(hw, QUEUE_CONTROL);
  12114. ieee80211_hw_set(hw, SUPPORTS_TX_FRAG);
  12115. ieee80211_hw_set(hw, REPORTS_LOW_ACK);
  12116. ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR);
  12117. if (test_bit(WMI_TLV_SERVICE_ETH_OFFLOAD, ar->wmi->wmi_ab->svc_map)) {
  12118. ieee80211_hw_set(hw, SUPPORTS_TX_ENCAP_OFFLOAD);
  12119. ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD);
  12120. }
  12121. if (cap->nss_ratio_enabled)
  12122. ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
  12123. if ((ht_cap & WMI_HT_CAP_ENABLED) || is_6ghz) {
  12124. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  12125. ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
  12126. ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
  12127. ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
  12128. ieee80211_hw_set(hw, USES_RSS);
  12129. }
  12130. wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
  12131. wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  12132. /* TODO: Check if HT capability advertised from firmware is different
  12133. * for each band for a dual band capable radio. It will be tricky to
  12134. * handle it when the ht capability different for each band.
  12135. */
  12136. if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS ||
  12137. (is_6ghz && ab->hw_params->supports_dynamic_smps_6ghz))
  12138. wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
  12139. wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
  12140. wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
  12141. hw->max_listen_interval = ATH12K_MAX_HW_LISTEN_INTERVAL;
  12142. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  12143. wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  12144. wiphy->max_remain_on_channel_duration = 5000;
  12145. wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  12146. wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
  12147. NL80211_FEATURE_AP_SCAN;
  12148. wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
  12149. /* MLO is not yet supported so disable Wireless Extensions for now
  12150. * to make sure ath12k users don't use it. This flag can be removed
  12151. * once WIPHY_FLAG_SUPPORTS_MLO is enabled.
  12152. */
  12153. wiphy->flags |= WIPHY_FLAG_DISABLE_WEXT;
  12154. /* Copy over MLO related capabilities received from
  12155. * WMI_SERVICE_READY_EXT2_EVENT if single_chip_mlo_supp is set.
  12156. */
  12157. if (ab->ag->mlo_capable) {
  12158. ath12k_iftypes_ext_capa[2].eml_capabilities = cap->eml_cap;
  12159. ath12k_iftypes_ext_capa[2].mld_capa_and_ops = cap->mld_cap;
  12160. wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
  12161. ieee80211_hw_set(hw, MLO_MCAST_MULTI_LINK_TX);
  12162. }
  12163. hw->queues = ATH12K_HW_MAX_QUEUES;
  12164. wiphy->tx_queue_len = ATH12K_QUEUE_LEN;
  12165. hw->offchannel_tx_hw_queue = ATH12K_HW_MAX_QUEUES - 1;
  12166. hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_EHT;
  12167. hw->vif_data_size = sizeof(struct ath12k_vif);
  12168. hw->sta_data_size = sizeof(struct ath12k_sta);
  12169. hw->extra_tx_headroom = ab->hw_params->iova_mask;
  12170. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
  12171. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);
  12172. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
  12173. if (test_bit(WMI_TLV_SERVICE_BSS_COLOR_OFFLOAD,
  12174. ab->wmi_ab.svc_map)) {
  12175. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BSS_COLOR);
  12176. ieee80211_hw_set(hw, DETECTS_COLOR_COLLISION);
  12177. }
  12178. wiphy->cipher_suites = cipher_suites;
  12179. wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  12180. wiphy->iftype_ext_capab = ath12k_iftypes_ext_capa;
  12181. wiphy->num_iftype_ext_capab = ARRAY_SIZE(ath12k_iftypes_ext_capa);
  12182. wiphy->mbssid_max_interfaces = mbssid_max_interfaces;
  12183. wiphy->ema_max_profile_periodicity = TARGET_EMA_MAX_PROFILE_PERIOD;
  12184. ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
  12185. if (is_6ghz) {
  12186. wiphy_ext_feature_set(wiphy,
  12187. NL80211_EXT_FEATURE_FILS_DISCOVERY);
  12188. wiphy_ext_feature_set(wiphy,
  12189. NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP);
  12190. }
  12191. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_PUNCT);
  12192. if (test_bit(WMI_TLV_SERVICE_BEACON_PROTECTION_SUPPORT, ab->wmi_ab.svc_map))
  12193. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_BEACON_PROTECTION);
  12194. ath12k_reg_init(hw);
  12195. if (!is_raw_mode) {
  12196. hw->netdev_features = NETIF_F_HW_CSUM;
  12197. ieee80211_hw_set(hw, SW_CRYPTO_CONTROL);
  12198. ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
  12199. }
  12200. if (test_bit(WMI_TLV_SERVICE_NLO, ar->wmi->wmi_ab->svc_map)) {
  12201. wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS;
  12202. wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
  12203. wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH;
  12204. wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS;
  12205. wiphy->max_sched_scan_plan_interval =
  12206. WMI_PNO_MAX_SCHED_SCAN_PLAN_INT;
  12207. wiphy->max_sched_scan_plan_iterations =
  12208. WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS;
  12209. wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
  12210. }
  12211. ret = ath12k_wow_init(ar);
  12212. if (ret) {
  12213. ath12k_warn(ar->ab, "failed to init wow: %d\n", ret);
  12214. goto err_cleanup_if_combs;
  12215. }
  12216. /* Boot-time regulatory updates have already been processed.
  12217. * Mark them as complete now, because after registration,
  12218. * cfg80211 will notify us again if there are any pending hints.
  12219. * We need to wait for those hints to be processed, so it's
  12220. * important to mark the boot-time updates as complete before
  12221. * proceeding with registration.
  12222. */
  12223. for_each_ar(ah, ar, i)
  12224. complete_all(&ar->regd_update_completed);
  12225. ret = ieee80211_register_hw(hw);
  12226. if (ret) {
  12227. ath12k_err(ab, "ieee80211 registration failed: %d\n", ret);
  12228. goto err_cleanup_if_combs;
  12229. }
  12230. if (is_monitor_disable)
  12231. /* There's a race between calling ieee80211_register_hw()
  12232. * and here where the monitor mode is enabled for a little
  12233. * while. But that time is so short and in practice it doesn't make
  12234. * a difference in real life.
  12235. */
  12236. wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MONITOR);
  12237. for_each_ar(ah, ar, i) {
  12238. /* Apply the regd received during initialization */
  12239. ret = ath12k_regd_update(ar, true);
  12240. if (ret) {
  12241. ath12k_err(ar->ab, "ath12k regd update failed: %d\n", ret);
  12242. goto err_unregister_hw;
  12243. }
  12244. if (ar->ab->hw_params->current_cc_support && ab->new_alpha2[0]) {
  12245. struct wmi_set_current_country_arg current_cc = {};
  12246. memcpy(&current_cc.alpha2, ab->new_alpha2, 2);
  12247. memcpy(&ar->alpha2, ab->new_alpha2, 2);
  12248. reinit_completion(&ar->regd_update_completed);
  12249. ret = ath12k_wmi_send_set_current_country_cmd(ar, &current_cc);
  12250. if (ret)
  12251. ath12k_warn(ar->ab,
  12252. "failed set cc code for mac register: %d\n",
  12253. ret);
  12254. }
  12255. ath12k_fw_stats_init(ar);
  12256. ath12k_debugfs_register(ar);
  12257. }
  12258. return 0;
  12259. err_unregister_hw:
  12260. for_each_ar(ah, ar, i)
  12261. ath12k_debugfs_unregister(ar);
  12262. ieee80211_unregister_hw(hw);
  12263. err_cleanup_if_combs:
  12264. ath12k_mac_cleanup_iface_combinations(ah);
  12265. err_complete_cleanup_unregister:
  12266. i = ah->num_radio;
  12267. err_cleanup_unregister:
  12268. for (j = 0; j < i; j++) {
  12269. ar = ath12k_ah_to_ar(ah, j);
  12270. ath12k_mac_cleanup_unregister(ar);
  12271. }
  12272. SET_IEEE80211_DEV(hw, NULL);
  12273. return ret;
  12274. }
  12275. static void ath12k_mac_setup(struct ath12k *ar)
  12276. {
  12277. struct ath12k_base *ab = ar->ab;
  12278. struct ath12k_pdev *pdev = ar->pdev;
  12279. u8 pdev_idx = ar->pdev_idx;
  12280. ar->lmac_id = ath12k_hw_get_mac_from_pdev_id(ab->hw_params, pdev_idx);
  12281. ar->wmi = &ab->wmi_ab.wmi[pdev_idx];
  12282. /* FIXME: wmi[0] is already initialized during attach,
  12283. * Should we do this again?
  12284. */
  12285. ath12k_wmi_pdev_attach(ab, pdev_idx);
  12286. ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask;
  12287. ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask;
  12288. ar->num_tx_chains = hweight32(pdev->cap.tx_chain_mask);
  12289. ar->num_rx_chains = hweight32(pdev->cap.rx_chain_mask);
  12290. ar->scan.arvif = NULL;
  12291. ar->vdev_id_11d_scan = ATH12K_11D_INVALID_VDEV_ID;
  12292. spin_lock_init(&ar->data_lock);
  12293. spin_lock_init(&ar->dp.ppdu_list_lock);
  12294. INIT_LIST_HEAD(&ar->arvifs);
  12295. INIT_LIST_HEAD(&ar->dp.ppdu_stats_info);
  12296. init_completion(&ar->vdev_setup_done);
  12297. init_completion(&ar->vdev_delete_done);
  12298. init_completion(&ar->peer_assoc_done);
  12299. init_completion(&ar->peer_delete_done);
  12300. init_completion(&ar->install_key_done);
  12301. init_completion(&ar->bss_survey_done);
  12302. init_completion(&ar->scan.started);
  12303. init_completion(&ar->scan.completed);
  12304. init_completion(&ar->scan.on_channel);
  12305. init_completion(&ar->mlo_setup_done);
  12306. init_completion(&ar->completed_11d_scan);
  12307. init_completion(&ar->regd_update_completed);
  12308. INIT_DELAYED_WORK(&ar->scan.timeout, ath12k_scan_timeout_work);
  12309. wiphy_work_init(&ar->scan.vdev_clean_wk, ath12k_scan_vdev_clean_work);
  12310. INIT_WORK(&ar->regd_channel_update_work, ath12k_regd_update_chan_list_work);
  12311. INIT_LIST_HEAD(&ar->regd_channel_update_queue);
  12312. INIT_WORK(&ar->regd_update_work, ath12k_regd_update_work);
  12313. wiphy_work_init(&ar->wmi_mgmt_tx_work, ath12k_mgmt_over_wmi_tx_work);
  12314. skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
  12315. ar->monitor_vdev_id = -1;
  12316. ar->monitor_vdev_created = false;
  12317. ar->monitor_started = false;
  12318. }
  12319. static int __ath12k_mac_mlo_setup(struct ath12k *ar)
  12320. {
  12321. u8 num_link = 0, partner_link_id[ATH12K_GROUP_MAX_RADIO] = {};
  12322. struct ath12k_base *partner_ab, *ab = ar->ab;
  12323. struct ath12k_hw_group *ag = ab->ag;
  12324. struct wmi_mlo_setup_arg mlo = {};
  12325. struct ath12k_pdev *pdev;
  12326. unsigned long time_left;
  12327. int i, j, ret;
  12328. lockdep_assert_held(&ag->mutex);
  12329. reinit_completion(&ar->mlo_setup_done);
  12330. for (i = 0; i < ag->num_devices; i++) {
  12331. partner_ab = ag->ab[i];
  12332. for (j = 0; j < partner_ab->num_radios; j++) {
  12333. pdev = &partner_ab->pdevs[j];
  12334. /* Avoid the self link */
  12335. if (ar == pdev->ar)
  12336. continue;
  12337. partner_link_id[num_link] = pdev->hw_link_id;
  12338. num_link++;
  12339. ath12k_dbg(ab, ATH12K_DBG_MAC, "device %d pdev %d hw_link_id %d num_link %d\n",
  12340. i, j, pdev->hw_link_id, num_link);
  12341. }
  12342. }
  12343. if (num_link == 0)
  12344. return 0;
  12345. mlo.group_id = cpu_to_le32(ag->id);
  12346. mlo.partner_link_id = partner_link_id;
  12347. mlo.num_partner_links = num_link;
  12348. ar->mlo_setup_status = 0;
  12349. ath12k_dbg(ab, ATH12K_DBG_MAC, "group id %d num_link %d\n", ag->id, num_link);
  12350. ret = ath12k_wmi_mlo_setup(ar, &mlo);
  12351. if (ret) {
  12352. ath12k_err(ab, "failed to send setup MLO WMI command for pdev %d: %d\n",
  12353. ar->pdev_idx, ret);
  12354. return ret;
  12355. }
  12356. time_left = wait_for_completion_timeout(&ar->mlo_setup_done,
  12357. WMI_MLO_CMD_TIMEOUT_HZ);
  12358. if (!time_left || ar->mlo_setup_status)
  12359. return ar->mlo_setup_status ? : -ETIMEDOUT;
  12360. ath12k_dbg(ab, ATH12K_DBG_MAC, "mlo setup done for pdev %d\n", ar->pdev_idx);
  12361. return 0;
  12362. }
  12363. static int __ath12k_mac_mlo_teardown(struct ath12k *ar)
  12364. {
  12365. struct ath12k_base *ab = ar->ab;
  12366. int ret;
  12367. u8 num_link;
  12368. if (test_bit(ATH12K_FLAG_RECOVERY, &ab->dev_flags))
  12369. return 0;
  12370. num_link = ath12k_get_num_partner_link(ar);
  12371. if (num_link == 0)
  12372. return 0;
  12373. ret = ath12k_wmi_mlo_teardown(ar);
  12374. if (ret) {
  12375. ath12k_warn(ab, "failed to send MLO teardown WMI command for pdev %d: %d\n",
  12376. ar->pdev_idx, ret);
  12377. return ret;
  12378. }
  12379. ath12k_dbg(ab, ATH12K_DBG_MAC, "mlo teardown for pdev %d\n", ar->pdev_idx);
  12380. return 0;
  12381. }
  12382. int ath12k_mac_mlo_setup(struct ath12k_hw_group *ag)
  12383. {
  12384. struct ath12k_hw *ah;
  12385. struct ath12k *ar;
  12386. int ret;
  12387. int i, j;
  12388. for (i = 0; i < ag->num_hw; i++) {
  12389. ah = ag->ah[i];
  12390. if (!ah)
  12391. continue;
  12392. for_each_ar(ah, ar, j) {
  12393. ar = &ah->radio[j];
  12394. ret = __ath12k_mac_mlo_setup(ar);
  12395. if (ret) {
  12396. ath12k_err(ar->ab, "failed to setup MLO: %d\n", ret);
  12397. goto err_setup;
  12398. }
  12399. }
  12400. }
  12401. return 0;
  12402. err_setup:
  12403. for (i = i - 1; i >= 0; i--) {
  12404. ah = ag->ah[i];
  12405. if (!ah)
  12406. continue;
  12407. for (j = j - 1; j >= 0; j--) {
  12408. ar = &ah->radio[j];
  12409. if (!ar)
  12410. continue;
  12411. __ath12k_mac_mlo_teardown(ar);
  12412. }
  12413. }
  12414. return ret;
  12415. }
  12416. void ath12k_mac_mlo_teardown(struct ath12k_hw_group *ag)
  12417. {
  12418. struct ath12k_hw *ah;
  12419. struct ath12k *ar;
  12420. int ret, i, j;
  12421. for (i = 0; i < ag->num_hw; i++) {
  12422. ah = ag->ah[i];
  12423. if (!ah)
  12424. continue;
  12425. for_each_ar(ah, ar, j) {
  12426. ar = &ah->radio[j];
  12427. ret = __ath12k_mac_mlo_teardown(ar);
  12428. if (ret) {
  12429. ath12k_err(ar->ab, "failed to teardown MLO: %d\n", ret);
  12430. break;
  12431. }
  12432. }
  12433. }
  12434. }
  12435. int ath12k_mac_register(struct ath12k_hw_group *ag)
  12436. {
  12437. struct ath12k_hw *ah;
  12438. int i;
  12439. int ret;
  12440. for (i = 0; i < ag->num_hw; i++) {
  12441. ah = ath12k_ag_to_ah(ag, i);
  12442. ret = ath12k_mac_hw_register(ah);
  12443. if (ret)
  12444. goto err;
  12445. }
  12446. return 0;
  12447. err:
  12448. for (i = i - 1; i >= 0; i--) {
  12449. ah = ath12k_ag_to_ah(ag, i);
  12450. if (!ah)
  12451. continue;
  12452. ath12k_mac_hw_unregister(ah);
  12453. }
  12454. return ret;
  12455. }
  12456. void ath12k_mac_unregister(struct ath12k_hw_group *ag)
  12457. {
  12458. struct ath12k_hw *ah;
  12459. int i;
  12460. for (i = ag->num_hw - 1; i >= 0; i--) {
  12461. ah = ath12k_ag_to_ah(ag, i);
  12462. if (!ah)
  12463. continue;
  12464. ath12k_mac_hw_unregister(ah);
  12465. }
  12466. }
  12467. static void ath12k_mac_hw_destroy(struct ath12k_hw *ah)
  12468. {
  12469. ieee80211_free_hw(ah->hw);
  12470. }
  12471. static struct ath12k_hw *ath12k_mac_hw_allocate(struct ath12k_hw_group *ag,
  12472. struct ath12k_pdev_map *pdev_map,
  12473. u8 num_pdev_map)
  12474. {
  12475. struct ieee80211_hw *hw;
  12476. struct ath12k *ar;
  12477. struct ath12k_base *ab;
  12478. struct ath12k_pdev *pdev;
  12479. struct ath12k_hw *ah;
  12480. int i;
  12481. u8 pdev_idx;
  12482. hw = ieee80211_alloc_hw(struct_size(ah, radio, num_pdev_map),
  12483. pdev_map->ab->ath12k_ops);
  12484. if (!hw)
  12485. return NULL;
  12486. ah = ath12k_hw_to_ah(hw);
  12487. ah->hw = hw;
  12488. ah->num_radio = num_pdev_map;
  12489. mutex_init(&ah->hw_mutex);
  12490. spin_lock_init(&ah->dp_hw.peer_lock);
  12491. INIT_LIST_HEAD(&ah->dp_hw.dp_peers_list);
  12492. for (i = 0; i < num_pdev_map; i++) {
  12493. ab = pdev_map[i].ab;
  12494. pdev_idx = pdev_map[i].pdev_idx;
  12495. pdev = &ab->pdevs[pdev_idx];
  12496. ar = ath12k_ah_to_ar(ah, i);
  12497. ar->ah = ah;
  12498. ar->ab = ab;
  12499. ar->hw_link_id = pdev->hw_link_id;
  12500. ar->pdev = pdev;
  12501. ar->pdev_idx = pdev_idx;
  12502. pdev->ar = ar;
  12503. ag->hw_links[ar->hw_link_id].device_id = ab->device_id;
  12504. ag->hw_links[ar->hw_link_id].pdev_idx = pdev_idx;
  12505. ath12k_mac_setup(ar);
  12506. ath12k_dp_pdev_pre_alloc(ar);
  12507. }
  12508. return ah;
  12509. }
  12510. void ath12k_mac_destroy(struct ath12k_hw_group *ag)
  12511. {
  12512. struct ath12k_pdev *pdev;
  12513. struct ath12k_base *ab = ag->ab[0];
  12514. int i, j;
  12515. struct ath12k_hw *ah;
  12516. for (i = 0; i < ag->num_devices; i++) {
  12517. ab = ag->ab[i];
  12518. if (!ab)
  12519. continue;
  12520. for (j = 0; j < ab->num_radios; j++) {
  12521. pdev = &ab->pdevs[j];
  12522. if (!pdev->ar)
  12523. continue;
  12524. pdev->ar = NULL;
  12525. }
  12526. }
  12527. for (i = 0; i < ag->num_hw; i++) {
  12528. ah = ath12k_ag_to_ah(ag, i);
  12529. if (!ah)
  12530. continue;
  12531. ath12k_mac_hw_destroy(ah);
  12532. ath12k_ag_set_ah(ag, i, NULL);
  12533. }
  12534. }
  12535. static void ath12k_mac_set_device_defaults(struct ath12k_base *ab)
  12536. {
  12537. int total_vdev;
  12538. /* Initialize channel counters frequency value in hertz */
  12539. ab->cc_freq_hz = 320000;
  12540. total_vdev = ab->num_radios * TARGET_NUM_VDEVS(ab);
  12541. ab->free_vdev_map = (1LL << total_vdev) - 1;
  12542. }
  12543. int ath12k_mac_allocate(struct ath12k_hw_group *ag)
  12544. {
  12545. struct ath12k_pdev_map pdev_map[ATH12K_GROUP_MAX_RADIO];
  12546. int mac_id, device_id, total_radio, num_hw;
  12547. struct ath12k_base *ab;
  12548. struct ath12k_hw *ah;
  12549. int ret, i, j;
  12550. u8 radio_per_hw;
  12551. total_radio = 0;
  12552. for (i = 0; i < ag->num_devices; i++) {
  12553. ab = ag->ab[i];
  12554. if (!ab)
  12555. continue;
  12556. ath12k_debugfs_pdev_create(ab);
  12557. ath12k_mac_set_device_defaults(ab);
  12558. total_radio += ab->num_radios;
  12559. }
  12560. if (!total_radio)
  12561. return -EINVAL;
  12562. if (WARN_ON(total_radio > ATH12K_GROUP_MAX_RADIO))
  12563. return -ENOSPC;
  12564. /* All pdev get combined and register as single wiphy based on
  12565. * hardware group which participate in multi-link operation else
  12566. * each pdev get register separately.
  12567. */
  12568. if (ag->mlo_capable)
  12569. radio_per_hw = total_radio;
  12570. else
  12571. radio_per_hw = 1;
  12572. num_hw = total_radio / radio_per_hw;
  12573. ag->num_hw = 0;
  12574. device_id = 0;
  12575. mac_id = 0;
  12576. for (i = 0; i < num_hw; i++) {
  12577. for (j = 0; j < radio_per_hw; j++) {
  12578. if (device_id >= ag->num_devices || !ag->ab[device_id]) {
  12579. ret = -ENOSPC;
  12580. goto err;
  12581. }
  12582. ab = ag->ab[device_id];
  12583. pdev_map[j].ab = ab;
  12584. pdev_map[j].pdev_idx = mac_id;
  12585. mac_id++;
  12586. /* If mac_id falls beyond the current device MACs then
  12587. * move to next device
  12588. */
  12589. if (mac_id >= ab->num_radios) {
  12590. mac_id = 0;
  12591. device_id++;
  12592. }
  12593. }
  12594. ab = pdev_map->ab;
  12595. ah = ath12k_mac_hw_allocate(ag, pdev_map, radio_per_hw);
  12596. if (!ah) {
  12597. ath12k_warn(ab, "failed to allocate mac80211 hw device for hw_idx %d\n",
  12598. i);
  12599. ret = -ENOMEM;
  12600. goto err;
  12601. }
  12602. ah->dev = ab->dev;
  12603. ag->ah[i] = ah;
  12604. ag->num_hw++;
  12605. }
  12606. return 0;
  12607. err:
  12608. for (i = i - 1; i >= 0; i--) {
  12609. ah = ath12k_ag_to_ah(ag, i);
  12610. if (!ah)
  12611. continue;
  12612. ath12k_mac_hw_destroy(ah);
  12613. ath12k_ag_set_ah(ag, i, NULL);
  12614. }
  12615. return ret;
  12616. }
  12617. int ath12k_mac_vif_set_keepalive(struct ath12k_link_vif *arvif,
  12618. enum wmi_sta_keepalive_method method,
  12619. u32 interval)
  12620. {
  12621. struct wmi_sta_keepalive_arg arg = {};
  12622. struct ath12k *ar = arvif->ar;
  12623. int ret;
  12624. lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy);
  12625. if (arvif->ahvif->vdev_type != WMI_VDEV_TYPE_STA)
  12626. return 0;
  12627. if (!test_bit(WMI_TLV_SERVICE_STA_KEEP_ALIVE, ar->ab->wmi_ab.svc_map))
  12628. return 0;
  12629. arg.vdev_id = arvif->vdev_id;
  12630. arg.enabled = 1;
  12631. arg.method = method;
  12632. arg.interval = interval;
  12633. ret = ath12k_wmi_sta_keepalive(ar, &arg);
  12634. if (ret) {
  12635. ath12k_warn(ar->ab, "failed to set keepalive on vdev %i: %d\n",
  12636. arvif->vdev_id, ret);
  12637. return ret;
  12638. }
  12639. return 0;
  12640. }