mac.c 265 KB

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