mac.c 180 KB

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