mac.c 185 KB

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