mac.c 187 KB

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