mac.c 175 KB

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