mac.c 215 KB

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