mac.c 185 KB

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