mac.c 209 KB

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