mac.c 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133
  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-ops.h"
  29. /**********/
  30. /* Crypto */
  31. /**********/
  32. static int ath10k_send_key(struct ath10k_vif *arvif,
  33. struct ieee80211_key_conf *key,
  34. enum set_key_cmd cmd,
  35. const u8 *macaddr)
  36. {
  37. struct ath10k *ar = arvif->ar;
  38. struct wmi_vdev_install_key_arg arg = {
  39. .vdev_id = arvif->vdev_id,
  40. .key_idx = key->keyidx,
  41. .key_len = key->keylen,
  42. .key_data = key->key,
  43. .macaddr = macaddr,
  44. };
  45. lockdep_assert_held(&arvif->ar->conf_mutex);
  46. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  47. arg.key_flags = WMI_KEY_PAIRWISE;
  48. else
  49. arg.key_flags = WMI_KEY_GROUP;
  50. switch (key->cipher) {
  51. case WLAN_CIPHER_SUITE_CCMP:
  52. arg.key_cipher = WMI_CIPHER_AES_CCM;
  53. if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
  54. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
  55. else
  56. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  57. break;
  58. case WLAN_CIPHER_SUITE_TKIP:
  59. arg.key_cipher = WMI_CIPHER_TKIP;
  60. arg.key_txmic_len = 8;
  61. arg.key_rxmic_len = 8;
  62. break;
  63. case WLAN_CIPHER_SUITE_WEP40:
  64. case WLAN_CIPHER_SUITE_WEP104:
  65. arg.key_cipher = WMI_CIPHER_WEP;
  66. /* AP/IBSS mode requires self-key to be groupwise
  67. * Otherwise pairwise key must be set */
  68. if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
  69. arg.key_flags = WMI_KEY_PAIRWISE;
  70. break;
  71. default:
  72. ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
  73. return -EOPNOTSUPP;
  74. }
  75. if (cmd == DISABLE_KEY) {
  76. arg.key_cipher = WMI_CIPHER_NONE;
  77. arg.key_data = NULL;
  78. }
  79. return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
  80. }
  81. static int ath10k_install_key(struct ath10k_vif *arvif,
  82. struct ieee80211_key_conf *key,
  83. enum set_key_cmd cmd,
  84. const u8 *macaddr)
  85. {
  86. struct ath10k *ar = arvif->ar;
  87. int ret;
  88. lockdep_assert_held(&ar->conf_mutex);
  89. reinit_completion(&ar->install_key_done);
  90. ret = ath10k_send_key(arvif, key, cmd, macaddr);
  91. if (ret)
  92. return ret;
  93. ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
  94. if (ret == 0)
  95. return -ETIMEDOUT;
  96. return 0;
  97. }
  98. static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
  99. const u8 *addr)
  100. {
  101. struct ath10k *ar = arvif->ar;
  102. struct ath10k_peer *peer;
  103. int ret;
  104. int i;
  105. lockdep_assert_held(&ar->conf_mutex);
  106. spin_lock_bh(&ar->data_lock);
  107. peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
  108. spin_unlock_bh(&ar->data_lock);
  109. if (!peer)
  110. return -ENOENT;
  111. for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
  112. if (arvif->wep_keys[i] == NULL)
  113. continue;
  114. ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
  115. addr);
  116. if (ret)
  117. return ret;
  118. spin_lock_bh(&ar->data_lock);
  119. peer->keys[i] = arvif->wep_keys[i];
  120. spin_unlock_bh(&ar->data_lock);
  121. }
  122. return 0;
  123. }
  124. static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
  125. const u8 *addr)
  126. {
  127. struct ath10k *ar = arvif->ar;
  128. struct ath10k_peer *peer;
  129. int first_errno = 0;
  130. int ret;
  131. int i;
  132. lockdep_assert_held(&ar->conf_mutex);
  133. spin_lock_bh(&ar->data_lock);
  134. peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
  135. spin_unlock_bh(&ar->data_lock);
  136. if (!peer)
  137. return -ENOENT;
  138. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  139. if (peer->keys[i] == NULL)
  140. continue;
  141. ret = ath10k_install_key(arvif, peer->keys[i],
  142. DISABLE_KEY, addr);
  143. if (ret && first_errno == 0)
  144. first_errno = ret;
  145. if (ret)
  146. ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
  147. i, ret);
  148. spin_lock_bh(&ar->data_lock);
  149. peer->keys[i] = NULL;
  150. spin_unlock_bh(&ar->data_lock);
  151. }
  152. return first_errno;
  153. }
  154. bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
  155. u8 keyidx)
  156. {
  157. struct ath10k_peer *peer;
  158. int i;
  159. lockdep_assert_held(&ar->data_lock);
  160. /* We don't know which vdev this peer belongs to,
  161. * since WMI doesn't give us that information.
  162. *
  163. * FIXME: multi-bss needs to be handled.
  164. */
  165. peer = ath10k_peer_find(ar, 0, addr);
  166. if (!peer)
  167. return false;
  168. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  169. if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
  170. return true;
  171. }
  172. return false;
  173. }
  174. static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
  175. struct ieee80211_key_conf *key)
  176. {
  177. struct ath10k *ar = arvif->ar;
  178. struct ath10k_peer *peer;
  179. u8 addr[ETH_ALEN];
  180. int first_errno = 0;
  181. int ret;
  182. int i;
  183. lockdep_assert_held(&ar->conf_mutex);
  184. for (;;) {
  185. /* since ath10k_install_key we can't hold data_lock all the
  186. * time, so we try to remove the keys incrementally */
  187. spin_lock_bh(&ar->data_lock);
  188. i = 0;
  189. list_for_each_entry(peer, &ar->peers, list) {
  190. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  191. if (peer->keys[i] == key) {
  192. ether_addr_copy(addr, peer->addr);
  193. peer->keys[i] = NULL;
  194. break;
  195. }
  196. }
  197. if (i < ARRAY_SIZE(peer->keys))
  198. break;
  199. }
  200. spin_unlock_bh(&ar->data_lock);
  201. if (i == ARRAY_SIZE(peer->keys))
  202. break;
  203. ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
  204. if (ret && first_errno == 0)
  205. first_errno = ret;
  206. if (ret)
  207. ath10k_warn(ar, "failed to remove key for %pM: %d\n",
  208. addr, ret);
  209. }
  210. return first_errno;
  211. }
  212. /*********************/
  213. /* General utilities */
  214. /*********************/
  215. static inline enum wmi_phy_mode
  216. chan_to_phymode(const struct cfg80211_chan_def *chandef)
  217. {
  218. enum wmi_phy_mode phymode = MODE_UNKNOWN;
  219. switch (chandef->chan->band) {
  220. case IEEE80211_BAND_2GHZ:
  221. switch (chandef->width) {
  222. case NL80211_CHAN_WIDTH_20_NOHT:
  223. phymode = MODE_11G;
  224. break;
  225. case NL80211_CHAN_WIDTH_20:
  226. phymode = MODE_11NG_HT20;
  227. break;
  228. case NL80211_CHAN_WIDTH_40:
  229. phymode = MODE_11NG_HT40;
  230. break;
  231. case NL80211_CHAN_WIDTH_5:
  232. case NL80211_CHAN_WIDTH_10:
  233. case NL80211_CHAN_WIDTH_80:
  234. case NL80211_CHAN_WIDTH_80P80:
  235. case NL80211_CHAN_WIDTH_160:
  236. phymode = MODE_UNKNOWN;
  237. break;
  238. }
  239. break;
  240. case IEEE80211_BAND_5GHZ:
  241. switch (chandef->width) {
  242. case NL80211_CHAN_WIDTH_20_NOHT:
  243. phymode = MODE_11A;
  244. break;
  245. case NL80211_CHAN_WIDTH_20:
  246. phymode = MODE_11NA_HT20;
  247. break;
  248. case NL80211_CHAN_WIDTH_40:
  249. phymode = MODE_11NA_HT40;
  250. break;
  251. case NL80211_CHAN_WIDTH_80:
  252. phymode = MODE_11AC_VHT80;
  253. break;
  254. case NL80211_CHAN_WIDTH_5:
  255. case NL80211_CHAN_WIDTH_10:
  256. case NL80211_CHAN_WIDTH_80P80:
  257. case NL80211_CHAN_WIDTH_160:
  258. phymode = MODE_UNKNOWN;
  259. break;
  260. }
  261. break;
  262. default:
  263. break;
  264. }
  265. WARN_ON(phymode == MODE_UNKNOWN);
  266. return phymode;
  267. }
  268. static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
  269. {
  270. /*
  271. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  272. * 0 for no restriction
  273. * 1 for 1/4 us
  274. * 2 for 1/2 us
  275. * 3 for 1 us
  276. * 4 for 2 us
  277. * 5 for 4 us
  278. * 6 for 8 us
  279. * 7 for 16 us
  280. */
  281. switch (mpdudensity) {
  282. case 0:
  283. return 0;
  284. case 1:
  285. case 2:
  286. case 3:
  287. /* Our lower layer calculations limit our precision to
  288. 1 microsecond */
  289. return 1;
  290. case 4:
  291. return 2;
  292. case 5:
  293. return 4;
  294. case 6:
  295. return 8;
  296. case 7:
  297. return 16;
  298. default:
  299. return 0;
  300. }
  301. }
  302. static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
  303. {
  304. int ret;
  305. lockdep_assert_held(&ar->conf_mutex);
  306. if (ar->num_peers >= ar->max_num_peers)
  307. return -ENOBUFS;
  308. ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
  309. if (ret) {
  310. ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
  311. addr, vdev_id, ret);
  312. return ret;
  313. }
  314. ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
  315. if (ret) {
  316. ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
  317. addr, vdev_id, ret);
  318. return ret;
  319. }
  320. ar->num_peers++;
  321. return 0;
  322. }
  323. static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
  324. {
  325. struct ath10k *ar = arvif->ar;
  326. u32 param;
  327. int ret;
  328. param = ar->wmi.pdev_param->sta_kickout_th;
  329. ret = ath10k_wmi_pdev_set_param(ar, param,
  330. ATH10K_KICKOUT_THRESHOLD);
  331. if (ret) {
  332. ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
  333. arvif->vdev_id, ret);
  334. return ret;
  335. }
  336. param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
  337. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
  338. ATH10K_KEEPALIVE_MIN_IDLE);
  339. if (ret) {
  340. ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
  341. arvif->vdev_id, ret);
  342. return ret;
  343. }
  344. param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
  345. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
  346. ATH10K_KEEPALIVE_MAX_IDLE);
  347. if (ret) {
  348. ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
  349. arvif->vdev_id, ret);
  350. return ret;
  351. }
  352. param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
  353. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
  354. ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
  355. if (ret) {
  356. ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
  357. arvif->vdev_id, ret);
  358. return ret;
  359. }
  360. return 0;
  361. }
  362. static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
  363. {
  364. struct ath10k *ar = arvif->ar;
  365. u32 vdev_param;
  366. vdev_param = ar->wmi.vdev_param->rts_threshold;
  367. return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
  368. }
  369. static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
  370. {
  371. struct ath10k *ar = arvif->ar;
  372. u32 vdev_param;
  373. if (value != 0xFFFFFFFF)
  374. value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
  375. ATH10K_FRAGMT_THRESHOLD_MIN,
  376. ATH10K_FRAGMT_THRESHOLD_MAX);
  377. vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
  378. return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
  379. }
  380. static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
  381. {
  382. int ret;
  383. lockdep_assert_held(&ar->conf_mutex);
  384. ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
  385. if (ret)
  386. return ret;
  387. ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
  388. if (ret)
  389. return ret;
  390. ar->num_peers--;
  391. return 0;
  392. }
  393. static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
  394. {
  395. struct ath10k_peer *peer, *tmp;
  396. lockdep_assert_held(&ar->conf_mutex);
  397. spin_lock_bh(&ar->data_lock);
  398. list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
  399. if (peer->vdev_id != vdev_id)
  400. continue;
  401. ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
  402. peer->addr, vdev_id);
  403. list_del(&peer->list);
  404. kfree(peer);
  405. ar->num_peers--;
  406. }
  407. spin_unlock_bh(&ar->data_lock);
  408. }
  409. static void ath10k_peer_cleanup_all(struct ath10k *ar)
  410. {
  411. struct ath10k_peer *peer, *tmp;
  412. lockdep_assert_held(&ar->conf_mutex);
  413. spin_lock_bh(&ar->data_lock);
  414. list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
  415. list_del(&peer->list);
  416. kfree(peer);
  417. }
  418. spin_unlock_bh(&ar->data_lock);
  419. ar->num_peers = 0;
  420. ar->num_stations = 0;
  421. }
  422. /************************/
  423. /* Interface management */
  424. /************************/
  425. void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
  426. {
  427. struct ath10k *ar = arvif->ar;
  428. lockdep_assert_held(&ar->data_lock);
  429. if (!arvif->beacon)
  430. return;
  431. if (!arvif->beacon_buf)
  432. dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
  433. arvif->beacon->len, DMA_TO_DEVICE);
  434. dev_kfree_skb_any(arvif->beacon);
  435. arvif->beacon = NULL;
  436. arvif->beacon_sent = false;
  437. }
  438. static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
  439. {
  440. struct ath10k *ar = arvif->ar;
  441. lockdep_assert_held(&ar->data_lock);
  442. ath10k_mac_vif_beacon_free(arvif);
  443. if (arvif->beacon_buf) {
  444. dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
  445. arvif->beacon_buf, arvif->beacon_paddr);
  446. arvif->beacon_buf = NULL;
  447. }
  448. }
  449. static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
  450. {
  451. int ret;
  452. lockdep_assert_held(&ar->conf_mutex);
  453. if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
  454. return -ESHUTDOWN;
  455. ret = wait_for_completion_timeout(&ar->vdev_setup_done,
  456. ATH10K_VDEV_SETUP_TIMEOUT_HZ);
  457. if (ret == 0)
  458. return -ETIMEDOUT;
  459. return 0;
  460. }
  461. static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
  462. {
  463. struct cfg80211_chan_def *chandef = &ar->chandef;
  464. struct ieee80211_channel *channel = chandef->chan;
  465. struct wmi_vdev_start_request_arg arg = {};
  466. int ret = 0;
  467. lockdep_assert_held(&ar->conf_mutex);
  468. arg.vdev_id = vdev_id;
  469. arg.channel.freq = channel->center_freq;
  470. arg.channel.band_center_freq1 = chandef->center_freq1;
  471. /* TODO setup this dynamically, what in case we
  472. don't have any vifs? */
  473. arg.channel.mode = chan_to_phymode(chandef);
  474. arg.channel.chan_radar =
  475. !!(channel->flags & IEEE80211_CHAN_RADAR);
  476. arg.channel.min_power = 0;
  477. arg.channel.max_power = channel->max_power * 2;
  478. arg.channel.max_reg_power = channel->max_reg_power * 2;
  479. arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
  480. reinit_completion(&ar->vdev_setup_done);
  481. ret = ath10k_wmi_vdev_start(ar, &arg);
  482. if (ret) {
  483. ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
  484. vdev_id, ret);
  485. return ret;
  486. }
  487. ret = ath10k_vdev_setup_sync(ar);
  488. if (ret) {
  489. ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
  490. vdev_id, ret);
  491. return ret;
  492. }
  493. ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
  494. if (ret) {
  495. ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
  496. vdev_id, ret);
  497. goto vdev_stop;
  498. }
  499. ar->monitor_vdev_id = vdev_id;
  500. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
  501. ar->monitor_vdev_id);
  502. return 0;
  503. vdev_stop:
  504. ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
  505. if (ret)
  506. ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
  507. ar->monitor_vdev_id, ret);
  508. return ret;
  509. }
  510. static int ath10k_monitor_vdev_stop(struct ath10k *ar)
  511. {
  512. int ret = 0;
  513. lockdep_assert_held(&ar->conf_mutex);
  514. ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
  515. if (ret)
  516. ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
  517. ar->monitor_vdev_id, ret);
  518. reinit_completion(&ar->vdev_setup_done);
  519. ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
  520. if (ret)
  521. ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
  522. ar->monitor_vdev_id, ret);
  523. ret = ath10k_vdev_setup_sync(ar);
  524. if (ret)
  525. ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
  526. ar->monitor_vdev_id, ret);
  527. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
  528. ar->monitor_vdev_id);
  529. return ret;
  530. }
  531. static int ath10k_monitor_vdev_create(struct ath10k *ar)
  532. {
  533. int bit, ret = 0;
  534. lockdep_assert_held(&ar->conf_mutex);
  535. if (ar->free_vdev_map == 0) {
  536. ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
  537. return -ENOMEM;
  538. }
  539. bit = __ffs64(ar->free_vdev_map);
  540. ar->monitor_vdev_id = bit;
  541. ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
  542. WMI_VDEV_TYPE_MONITOR,
  543. 0, ar->mac_addr);
  544. if (ret) {
  545. ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
  546. ar->monitor_vdev_id, ret);
  547. return ret;
  548. }
  549. ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
  550. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
  551. ar->monitor_vdev_id);
  552. return 0;
  553. }
  554. static int ath10k_monitor_vdev_delete(struct ath10k *ar)
  555. {
  556. int ret = 0;
  557. lockdep_assert_held(&ar->conf_mutex);
  558. ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
  559. if (ret) {
  560. ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
  561. ar->monitor_vdev_id, ret);
  562. return ret;
  563. }
  564. ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
  565. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
  566. ar->monitor_vdev_id);
  567. return ret;
  568. }
  569. static int ath10k_monitor_start(struct ath10k *ar)
  570. {
  571. int ret;
  572. lockdep_assert_held(&ar->conf_mutex);
  573. ret = ath10k_monitor_vdev_create(ar);
  574. if (ret) {
  575. ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
  576. return ret;
  577. }
  578. ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
  579. if (ret) {
  580. ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
  581. ath10k_monitor_vdev_delete(ar);
  582. return ret;
  583. }
  584. ar->monitor_started = true;
  585. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
  586. return 0;
  587. }
  588. static int ath10k_monitor_stop(struct ath10k *ar)
  589. {
  590. int ret;
  591. lockdep_assert_held(&ar->conf_mutex);
  592. ret = ath10k_monitor_vdev_stop(ar);
  593. if (ret) {
  594. ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
  595. return ret;
  596. }
  597. ret = ath10k_monitor_vdev_delete(ar);
  598. if (ret) {
  599. ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
  600. return ret;
  601. }
  602. ar->monitor_started = false;
  603. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
  604. return 0;
  605. }
  606. static int ath10k_monitor_recalc(struct ath10k *ar)
  607. {
  608. bool should_start;
  609. lockdep_assert_held(&ar->conf_mutex);
  610. should_start = ar->monitor ||
  611. ar->filter_flags & FIF_PROMISC_IN_BSS ||
  612. test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  613. ath10k_dbg(ar, ATH10K_DBG_MAC,
  614. "mac monitor recalc started? %d should? %d\n",
  615. ar->monitor_started, should_start);
  616. if (should_start == ar->monitor_started)
  617. return 0;
  618. if (should_start)
  619. return ath10k_monitor_start(ar);
  620. return ath10k_monitor_stop(ar);
  621. }
  622. static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
  623. {
  624. struct ath10k *ar = arvif->ar;
  625. u32 vdev_param, rts_cts = 0;
  626. lockdep_assert_held(&ar->conf_mutex);
  627. vdev_param = ar->wmi.vdev_param->enable_rtscts;
  628. if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
  629. rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
  630. if (arvif->num_legacy_stations > 0)
  631. rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
  632. WMI_RTSCTS_PROFILE);
  633. return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  634. rts_cts);
  635. }
  636. static int ath10k_start_cac(struct ath10k *ar)
  637. {
  638. int ret;
  639. lockdep_assert_held(&ar->conf_mutex);
  640. set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  641. ret = ath10k_monitor_recalc(ar);
  642. if (ret) {
  643. ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
  644. clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  645. return ret;
  646. }
  647. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
  648. ar->monitor_vdev_id);
  649. return 0;
  650. }
  651. static int ath10k_stop_cac(struct ath10k *ar)
  652. {
  653. lockdep_assert_held(&ar->conf_mutex);
  654. /* CAC is not running - do nothing */
  655. if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
  656. return 0;
  657. clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  658. ath10k_monitor_stop(ar);
  659. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
  660. return 0;
  661. }
  662. static void ath10k_recalc_radar_detection(struct ath10k *ar)
  663. {
  664. int ret;
  665. lockdep_assert_held(&ar->conf_mutex);
  666. ath10k_stop_cac(ar);
  667. if (!ar->radar_enabled)
  668. return;
  669. if (ar->num_started_vdevs > 0)
  670. return;
  671. ret = ath10k_start_cac(ar);
  672. if (ret) {
  673. /*
  674. * Not possible to start CAC on current channel so starting
  675. * radiation is not allowed, make this channel DFS_UNAVAILABLE
  676. * by indicating that radar was detected.
  677. */
  678. ath10k_warn(ar, "failed to start CAC: %d\n", ret);
  679. ieee80211_radar_detected(ar->hw);
  680. }
  681. }
  682. static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
  683. {
  684. struct ath10k *ar = arvif->ar;
  685. struct cfg80211_chan_def *chandef = &ar->chandef;
  686. struct wmi_vdev_start_request_arg arg = {};
  687. int ret = 0;
  688. lockdep_assert_held(&ar->conf_mutex);
  689. reinit_completion(&ar->vdev_setup_done);
  690. arg.vdev_id = arvif->vdev_id;
  691. arg.dtim_period = arvif->dtim_period;
  692. arg.bcn_intval = arvif->beacon_interval;
  693. arg.channel.freq = chandef->chan->center_freq;
  694. arg.channel.band_center_freq1 = chandef->center_freq1;
  695. arg.channel.mode = chan_to_phymode(chandef);
  696. arg.channel.min_power = 0;
  697. arg.channel.max_power = chandef->chan->max_power * 2;
  698. arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
  699. arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
  700. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  701. arg.ssid = arvif->u.ap.ssid;
  702. arg.ssid_len = arvif->u.ap.ssid_len;
  703. arg.hidden_ssid = arvif->u.ap.hidden_ssid;
  704. /* For now allow DFS for AP mode */
  705. arg.channel.chan_radar =
  706. !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
  707. } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  708. arg.ssid = arvif->vif->bss_conf.ssid;
  709. arg.ssid_len = arvif->vif->bss_conf.ssid_len;
  710. }
  711. ath10k_dbg(ar, ATH10K_DBG_MAC,
  712. "mac vdev %d start center_freq %d phymode %s\n",
  713. arg.vdev_id, arg.channel.freq,
  714. ath10k_wmi_phymode_str(arg.channel.mode));
  715. if (restart)
  716. ret = ath10k_wmi_vdev_restart(ar, &arg);
  717. else
  718. ret = ath10k_wmi_vdev_start(ar, &arg);
  719. if (ret) {
  720. ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
  721. arg.vdev_id, ret);
  722. return ret;
  723. }
  724. ret = ath10k_vdev_setup_sync(ar);
  725. if (ret) {
  726. ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
  727. arg.vdev_id, ret);
  728. return ret;
  729. }
  730. ar->num_started_vdevs++;
  731. ath10k_recalc_radar_detection(ar);
  732. return ret;
  733. }
  734. static int ath10k_vdev_start(struct ath10k_vif *arvif)
  735. {
  736. return ath10k_vdev_start_restart(arvif, false);
  737. }
  738. static int ath10k_vdev_restart(struct ath10k_vif *arvif)
  739. {
  740. return ath10k_vdev_start_restart(arvif, true);
  741. }
  742. static int ath10k_vdev_stop(struct ath10k_vif *arvif)
  743. {
  744. struct ath10k *ar = arvif->ar;
  745. int ret;
  746. lockdep_assert_held(&ar->conf_mutex);
  747. reinit_completion(&ar->vdev_setup_done);
  748. ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
  749. if (ret) {
  750. ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
  751. arvif->vdev_id, ret);
  752. return ret;
  753. }
  754. ret = ath10k_vdev_setup_sync(ar);
  755. if (ret) {
  756. ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
  757. arvif->vdev_id, ret);
  758. return ret;
  759. }
  760. WARN_ON(ar->num_started_vdevs == 0);
  761. if (ar->num_started_vdevs != 0) {
  762. ar->num_started_vdevs--;
  763. ath10k_recalc_radar_detection(ar);
  764. }
  765. return ret;
  766. }
  767. static void ath10k_control_beaconing(struct ath10k_vif *arvif,
  768. struct ieee80211_bss_conf *info)
  769. {
  770. struct ath10k *ar = arvif->ar;
  771. int ret = 0;
  772. lockdep_assert_held(&arvif->ar->conf_mutex);
  773. if (!info->enable_beacon) {
  774. ath10k_vdev_stop(arvif);
  775. arvif->is_started = false;
  776. arvif->is_up = false;
  777. spin_lock_bh(&arvif->ar->data_lock);
  778. ath10k_mac_vif_beacon_free(arvif);
  779. spin_unlock_bh(&arvif->ar->data_lock);
  780. return;
  781. }
  782. arvif->tx_seq_no = 0x1000;
  783. ret = ath10k_vdev_start(arvif);
  784. if (ret)
  785. return;
  786. arvif->aid = 0;
  787. ether_addr_copy(arvif->bssid, info->bssid);
  788. ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
  789. arvif->bssid);
  790. if (ret) {
  791. ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
  792. arvif->vdev_id, ret);
  793. ath10k_vdev_stop(arvif);
  794. return;
  795. }
  796. arvif->is_started = true;
  797. arvif->is_up = true;
  798. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
  799. }
  800. static void ath10k_control_ibss(struct ath10k_vif *arvif,
  801. struct ieee80211_bss_conf *info,
  802. const u8 self_peer[ETH_ALEN])
  803. {
  804. struct ath10k *ar = arvif->ar;
  805. u32 vdev_param;
  806. int ret = 0;
  807. lockdep_assert_held(&arvif->ar->conf_mutex);
  808. if (!info->ibss_joined) {
  809. ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
  810. if (ret)
  811. ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
  812. self_peer, arvif->vdev_id, ret);
  813. if (is_zero_ether_addr(arvif->bssid))
  814. return;
  815. memset(arvif->bssid, 0, ETH_ALEN);
  816. return;
  817. }
  818. ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
  819. if (ret) {
  820. ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
  821. self_peer, arvif->vdev_id, ret);
  822. return;
  823. }
  824. vdev_param = arvif->ar->wmi.vdev_param->atim_window;
  825. ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
  826. ATH10K_DEFAULT_ATIM);
  827. if (ret)
  828. ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
  829. arvif->vdev_id, ret);
  830. }
  831. /*
  832. * Review this when mac80211 gains per-interface powersave support.
  833. */
  834. static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
  835. {
  836. struct ath10k *ar = arvif->ar;
  837. struct ieee80211_conf *conf = &ar->hw->conf;
  838. enum wmi_sta_powersave_param param;
  839. enum wmi_sta_ps_mode psmode;
  840. int ret;
  841. lockdep_assert_held(&arvif->ar->conf_mutex);
  842. if (arvif->vif->type != NL80211_IFTYPE_STATION)
  843. return 0;
  844. if (conf->flags & IEEE80211_CONF_PS) {
  845. psmode = WMI_STA_PS_MODE_ENABLED;
  846. param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
  847. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
  848. conf->dynamic_ps_timeout);
  849. if (ret) {
  850. ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
  851. arvif->vdev_id, ret);
  852. return ret;
  853. }
  854. } else {
  855. psmode = WMI_STA_PS_MODE_DISABLED;
  856. }
  857. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
  858. arvif->vdev_id, psmode ? "enable" : "disable");
  859. ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
  860. if (ret) {
  861. ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
  862. psmode, arvif->vdev_id, ret);
  863. return ret;
  864. }
  865. return 0;
  866. }
  867. /**********************/
  868. /* Station management */
  869. /**********************/
  870. static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
  871. struct ieee80211_vif *vif)
  872. {
  873. /* Some firmware revisions have unstable STA powersave when listen
  874. * interval is set too high (e.g. 5). The symptoms are firmware doesn't
  875. * generate NullFunc frames properly even if buffered frames have been
  876. * indicated in Beacon TIM. Firmware would seldom wake up to pull
  877. * buffered frames. Often pinging the device from AP would simply fail.
  878. *
  879. * As a workaround set it to 1.
  880. */
  881. if (vif->type == NL80211_IFTYPE_STATION)
  882. return 1;
  883. return ar->hw->conf.listen_interval;
  884. }
  885. static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
  886. struct ieee80211_vif *vif,
  887. struct ieee80211_sta *sta,
  888. struct wmi_peer_assoc_complete_arg *arg)
  889. {
  890. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  891. lockdep_assert_held(&ar->conf_mutex);
  892. ether_addr_copy(arg->addr, sta->addr);
  893. arg->vdev_id = arvif->vdev_id;
  894. arg->peer_aid = sta->aid;
  895. arg->peer_flags |= WMI_PEER_AUTH;
  896. arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
  897. arg->peer_num_spatial_streams = 1;
  898. arg->peer_caps = vif->bss_conf.assoc_capability;
  899. }
  900. static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
  901. struct ieee80211_vif *vif,
  902. struct wmi_peer_assoc_complete_arg *arg)
  903. {
  904. struct ieee80211_bss_conf *info = &vif->bss_conf;
  905. struct cfg80211_bss *bss;
  906. const u8 *rsnie = NULL;
  907. const u8 *wpaie = NULL;
  908. lockdep_assert_held(&ar->conf_mutex);
  909. bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
  910. info->bssid, NULL, 0, 0, 0);
  911. if (bss) {
  912. const struct cfg80211_bss_ies *ies;
  913. rcu_read_lock();
  914. rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
  915. ies = rcu_dereference(bss->ies);
  916. wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
  917. WLAN_OUI_TYPE_MICROSOFT_WPA,
  918. ies->data,
  919. ies->len);
  920. rcu_read_unlock();
  921. cfg80211_put_bss(ar->hw->wiphy, bss);
  922. }
  923. /* FIXME: base on RSN IE/WPA IE is a correct idea? */
  924. if (rsnie || wpaie) {
  925. ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
  926. arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
  927. }
  928. if (wpaie) {
  929. ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
  930. arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
  931. }
  932. }
  933. static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
  934. struct ieee80211_sta *sta,
  935. struct wmi_peer_assoc_complete_arg *arg)
  936. {
  937. struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
  938. const struct ieee80211_supported_band *sband;
  939. const struct ieee80211_rate *rates;
  940. u32 ratemask;
  941. int i;
  942. lockdep_assert_held(&ar->conf_mutex);
  943. sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
  944. ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
  945. rates = sband->bitrates;
  946. rateset->num_rates = 0;
  947. for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
  948. if (!(ratemask & 1))
  949. continue;
  950. rateset->rates[rateset->num_rates] = rates->hw_value;
  951. rateset->num_rates++;
  952. }
  953. }
  954. static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
  955. struct ieee80211_sta *sta,
  956. struct wmi_peer_assoc_complete_arg *arg)
  957. {
  958. const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  959. int i, n;
  960. u32 stbc;
  961. lockdep_assert_held(&ar->conf_mutex);
  962. if (!ht_cap->ht_supported)
  963. return;
  964. arg->peer_flags |= WMI_PEER_HT;
  965. arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  966. ht_cap->ampdu_factor)) - 1;
  967. arg->peer_mpdu_density =
  968. ath10k_parse_mpdudensity(ht_cap->ampdu_density);
  969. arg->peer_ht_caps = ht_cap->cap;
  970. arg->peer_rate_caps |= WMI_RC_HT_FLAG;
  971. if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
  972. arg->peer_flags |= WMI_PEER_LDPC;
  973. if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
  974. arg->peer_flags |= WMI_PEER_40MHZ;
  975. arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
  976. }
  977. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
  978. arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
  979. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
  980. arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
  981. if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
  982. arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
  983. arg->peer_flags |= WMI_PEER_STBC;
  984. }
  985. if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
  986. stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
  987. stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
  988. stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
  989. arg->peer_rate_caps |= stbc;
  990. arg->peer_flags |= WMI_PEER_STBC;
  991. }
  992. if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
  993. arg->peer_rate_caps |= WMI_RC_TS_FLAG;
  994. else if (ht_cap->mcs.rx_mask[1])
  995. arg->peer_rate_caps |= WMI_RC_DS_FLAG;
  996. for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
  997. if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
  998. arg->peer_ht_rates.rates[n++] = i;
  999. /*
  1000. * This is a workaround for HT-enabled STAs which break the spec
  1001. * and have no HT capabilities RX mask (no HT RX MCS map).
  1002. *
  1003. * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
  1004. * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
  1005. *
  1006. * Firmware asserts if such situation occurs.
  1007. */
  1008. if (n == 0) {
  1009. arg->peer_ht_rates.num_rates = 8;
  1010. for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
  1011. arg->peer_ht_rates.rates[i] = i;
  1012. } else {
  1013. arg->peer_ht_rates.num_rates = n;
  1014. arg->peer_num_spatial_streams = sta->rx_nss;
  1015. }
  1016. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
  1017. arg->addr,
  1018. arg->peer_ht_rates.num_rates,
  1019. arg->peer_num_spatial_streams);
  1020. }
  1021. static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
  1022. struct ath10k_vif *arvif,
  1023. struct ieee80211_sta *sta)
  1024. {
  1025. u32 uapsd = 0;
  1026. u32 max_sp = 0;
  1027. int ret = 0;
  1028. lockdep_assert_held(&ar->conf_mutex);
  1029. if (sta->wme && sta->uapsd_queues) {
  1030. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
  1031. sta->uapsd_queues, sta->max_sp);
  1032. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  1033. uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
  1034. WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
  1035. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  1036. uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
  1037. WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
  1038. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  1039. uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
  1040. WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
  1041. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  1042. uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
  1043. WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
  1044. if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
  1045. max_sp = sta->max_sp;
  1046. ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
  1047. sta->addr,
  1048. WMI_AP_PS_PEER_PARAM_UAPSD,
  1049. uapsd);
  1050. if (ret) {
  1051. ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
  1052. arvif->vdev_id, ret);
  1053. return ret;
  1054. }
  1055. ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
  1056. sta->addr,
  1057. WMI_AP_PS_PEER_PARAM_MAX_SP,
  1058. max_sp);
  1059. if (ret) {
  1060. ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
  1061. arvif->vdev_id, ret);
  1062. return ret;
  1063. }
  1064. /* TODO setup this based on STA listen interval and
  1065. beacon interval. Currently we don't know
  1066. sta->listen_interval - mac80211 patch required.
  1067. Currently use 10 seconds */
  1068. ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
  1069. WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
  1070. 10);
  1071. if (ret) {
  1072. ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
  1073. arvif->vdev_id, ret);
  1074. return ret;
  1075. }
  1076. }
  1077. return 0;
  1078. }
  1079. static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
  1080. struct ieee80211_sta *sta,
  1081. struct wmi_peer_assoc_complete_arg *arg)
  1082. {
  1083. const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  1084. u8 ampdu_factor;
  1085. if (!vht_cap->vht_supported)
  1086. return;
  1087. arg->peer_flags |= WMI_PEER_VHT;
  1088. arg->peer_vht_caps = vht_cap->cap;
  1089. ampdu_factor = (vht_cap->cap &
  1090. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
  1091. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  1092. /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
  1093. * zero in VHT IE. Using it would result in degraded throughput.
  1094. * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
  1095. * it if VHT max_mpdu is smaller. */
  1096. arg->peer_max_mpdu = max(arg->peer_max_mpdu,
  1097. (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  1098. ampdu_factor)) - 1);
  1099. if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
  1100. arg->peer_flags |= WMI_PEER_80MHZ;
  1101. arg->peer_vht_rates.rx_max_rate =
  1102. __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
  1103. arg->peer_vht_rates.rx_mcs_set =
  1104. __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  1105. arg->peer_vht_rates.tx_max_rate =
  1106. __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
  1107. arg->peer_vht_rates.tx_mcs_set =
  1108. __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
  1109. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
  1110. sta->addr, arg->peer_max_mpdu, arg->peer_flags);
  1111. }
  1112. static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
  1113. struct ieee80211_vif *vif,
  1114. struct ieee80211_sta *sta,
  1115. struct wmi_peer_assoc_complete_arg *arg)
  1116. {
  1117. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1118. switch (arvif->vdev_type) {
  1119. case WMI_VDEV_TYPE_AP:
  1120. if (sta->wme)
  1121. arg->peer_flags |= WMI_PEER_QOS;
  1122. if (sta->wme && sta->uapsd_queues) {
  1123. arg->peer_flags |= WMI_PEER_APSD;
  1124. arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
  1125. }
  1126. break;
  1127. case WMI_VDEV_TYPE_STA:
  1128. if (vif->bss_conf.qos)
  1129. arg->peer_flags |= WMI_PEER_QOS;
  1130. break;
  1131. default:
  1132. break;
  1133. }
  1134. }
  1135. static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
  1136. struct ieee80211_vif *vif,
  1137. struct ieee80211_sta *sta,
  1138. struct wmi_peer_assoc_complete_arg *arg)
  1139. {
  1140. enum wmi_phy_mode phymode = MODE_UNKNOWN;
  1141. switch (ar->hw->conf.chandef.chan->band) {
  1142. case IEEE80211_BAND_2GHZ:
  1143. if (sta->ht_cap.ht_supported) {
  1144. if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
  1145. phymode = MODE_11NG_HT40;
  1146. else
  1147. phymode = MODE_11NG_HT20;
  1148. } else {
  1149. phymode = MODE_11G;
  1150. }
  1151. break;
  1152. case IEEE80211_BAND_5GHZ:
  1153. /*
  1154. * Check VHT first.
  1155. */
  1156. if (sta->vht_cap.vht_supported) {
  1157. if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
  1158. phymode = MODE_11AC_VHT80;
  1159. else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
  1160. phymode = MODE_11AC_VHT40;
  1161. else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
  1162. phymode = MODE_11AC_VHT20;
  1163. } else if (sta->ht_cap.ht_supported) {
  1164. if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
  1165. phymode = MODE_11NA_HT40;
  1166. else
  1167. phymode = MODE_11NA_HT20;
  1168. } else {
  1169. phymode = MODE_11A;
  1170. }
  1171. break;
  1172. default:
  1173. break;
  1174. }
  1175. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
  1176. sta->addr, ath10k_wmi_phymode_str(phymode));
  1177. arg->peer_phymode = phymode;
  1178. WARN_ON(phymode == MODE_UNKNOWN);
  1179. }
  1180. static int ath10k_peer_assoc_prepare(struct ath10k *ar,
  1181. struct ieee80211_vif *vif,
  1182. struct ieee80211_sta *sta,
  1183. struct wmi_peer_assoc_complete_arg *arg)
  1184. {
  1185. lockdep_assert_held(&ar->conf_mutex);
  1186. memset(arg, 0, sizeof(*arg));
  1187. ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
  1188. ath10k_peer_assoc_h_crypto(ar, vif, arg);
  1189. ath10k_peer_assoc_h_rates(ar, sta, arg);
  1190. ath10k_peer_assoc_h_ht(ar, sta, arg);
  1191. ath10k_peer_assoc_h_vht(ar, sta, arg);
  1192. ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
  1193. ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
  1194. return 0;
  1195. }
  1196. static const u32 ath10k_smps_map[] = {
  1197. [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
  1198. [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
  1199. [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
  1200. [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
  1201. };
  1202. static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
  1203. const u8 *addr,
  1204. const struct ieee80211_sta_ht_cap *ht_cap)
  1205. {
  1206. int smps;
  1207. if (!ht_cap->ht_supported)
  1208. return 0;
  1209. smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
  1210. smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
  1211. if (smps >= ARRAY_SIZE(ath10k_smps_map))
  1212. return -EINVAL;
  1213. return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
  1214. WMI_PEER_SMPS_STATE,
  1215. ath10k_smps_map[smps]);
  1216. }
  1217. /* can be called only in mac80211 callbacks due to `key_count` usage */
  1218. static void ath10k_bss_assoc(struct ieee80211_hw *hw,
  1219. struct ieee80211_vif *vif,
  1220. struct ieee80211_bss_conf *bss_conf)
  1221. {
  1222. struct ath10k *ar = hw->priv;
  1223. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1224. struct ieee80211_sta_ht_cap ht_cap;
  1225. struct wmi_peer_assoc_complete_arg peer_arg;
  1226. struct ieee80211_sta *ap_sta;
  1227. int ret;
  1228. lockdep_assert_held(&ar->conf_mutex);
  1229. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
  1230. arvif->vdev_id, arvif->bssid, arvif->aid);
  1231. rcu_read_lock();
  1232. ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
  1233. if (!ap_sta) {
  1234. ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
  1235. bss_conf->bssid, arvif->vdev_id);
  1236. rcu_read_unlock();
  1237. return;
  1238. }
  1239. /* ap_sta must be accessed only within rcu section which must be left
  1240. * before calling ath10k_setup_peer_smps() which might sleep. */
  1241. ht_cap = ap_sta->ht_cap;
  1242. ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
  1243. if (ret) {
  1244. ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
  1245. bss_conf->bssid, arvif->vdev_id, ret);
  1246. rcu_read_unlock();
  1247. return;
  1248. }
  1249. rcu_read_unlock();
  1250. ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
  1251. if (ret) {
  1252. ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
  1253. bss_conf->bssid, arvif->vdev_id, ret);
  1254. return;
  1255. }
  1256. ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
  1257. if (ret) {
  1258. ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
  1259. arvif->vdev_id, ret);
  1260. return;
  1261. }
  1262. ath10k_dbg(ar, ATH10K_DBG_MAC,
  1263. "mac vdev %d up (associated) bssid %pM aid %d\n",
  1264. arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
  1265. WARN_ON(arvif->is_up);
  1266. arvif->aid = bss_conf->aid;
  1267. ether_addr_copy(arvif->bssid, bss_conf->bssid);
  1268. ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
  1269. if (ret) {
  1270. ath10k_warn(ar, "failed to set vdev %d up: %d\n",
  1271. arvif->vdev_id, ret);
  1272. return;
  1273. }
  1274. arvif->is_up = true;
  1275. }
  1276. static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
  1277. struct ieee80211_vif *vif)
  1278. {
  1279. struct ath10k *ar = hw->priv;
  1280. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1281. int ret;
  1282. lockdep_assert_held(&ar->conf_mutex);
  1283. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
  1284. arvif->vdev_id, arvif->bssid);
  1285. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  1286. if (ret)
  1287. ath10k_warn(ar, "faield to down vdev %i: %d\n",
  1288. arvif->vdev_id, ret);
  1289. arvif->def_wep_key_idx = 0;
  1290. arvif->is_up = false;
  1291. }
  1292. static int ath10k_station_assoc(struct ath10k *ar,
  1293. struct ieee80211_vif *vif,
  1294. struct ieee80211_sta *sta,
  1295. bool reassoc)
  1296. {
  1297. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1298. struct wmi_peer_assoc_complete_arg peer_arg;
  1299. int ret = 0;
  1300. lockdep_assert_held(&ar->conf_mutex);
  1301. ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
  1302. if (ret) {
  1303. ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
  1304. sta->addr, arvif->vdev_id, ret);
  1305. return ret;
  1306. }
  1307. peer_arg.peer_reassoc = reassoc;
  1308. ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
  1309. if (ret) {
  1310. ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
  1311. sta->addr, arvif->vdev_id, ret);
  1312. return ret;
  1313. }
  1314. /* Re-assoc is run only to update supported rates for given station. It
  1315. * doesn't make much sense to reconfigure the peer completely.
  1316. */
  1317. if (!reassoc) {
  1318. ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
  1319. &sta->ht_cap);
  1320. if (ret) {
  1321. ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
  1322. arvif->vdev_id, ret);
  1323. return ret;
  1324. }
  1325. ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
  1326. if (ret) {
  1327. ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
  1328. sta->addr, arvif->vdev_id, ret);
  1329. return ret;
  1330. }
  1331. if (!sta->wme) {
  1332. arvif->num_legacy_stations++;
  1333. ret = ath10k_recalc_rtscts_prot(arvif);
  1334. if (ret) {
  1335. ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  1336. arvif->vdev_id, ret);
  1337. return ret;
  1338. }
  1339. }
  1340. ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
  1341. if (ret) {
  1342. ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
  1343. arvif->vdev_id, ret);
  1344. return ret;
  1345. }
  1346. }
  1347. return ret;
  1348. }
  1349. static int ath10k_station_disassoc(struct ath10k *ar,
  1350. struct ieee80211_vif *vif,
  1351. struct ieee80211_sta *sta)
  1352. {
  1353. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1354. int ret = 0;
  1355. lockdep_assert_held(&ar->conf_mutex);
  1356. if (!sta->wme) {
  1357. arvif->num_legacy_stations--;
  1358. ret = ath10k_recalc_rtscts_prot(arvif);
  1359. if (ret) {
  1360. ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  1361. arvif->vdev_id, ret);
  1362. return ret;
  1363. }
  1364. }
  1365. ret = ath10k_clear_peer_keys(arvif, sta->addr);
  1366. if (ret) {
  1367. ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
  1368. arvif->vdev_id, ret);
  1369. return ret;
  1370. }
  1371. return ret;
  1372. }
  1373. /**************/
  1374. /* Regulatory */
  1375. /**************/
  1376. static int ath10k_update_channel_list(struct ath10k *ar)
  1377. {
  1378. struct ieee80211_hw *hw = ar->hw;
  1379. struct ieee80211_supported_band **bands;
  1380. enum ieee80211_band band;
  1381. struct ieee80211_channel *channel;
  1382. struct wmi_scan_chan_list_arg arg = {0};
  1383. struct wmi_channel_arg *ch;
  1384. bool passive;
  1385. int len;
  1386. int ret;
  1387. int i;
  1388. lockdep_assert_held(&ar->conf_mutex);
  1389. bands = hw->wiphy->bands;
  1390. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1391. if (!bands[band])
  1392. continue;
  1393. for (i = 0; i < bands[band]->n_channels; i++) {
  1394. if (bands[band]->channels[i].flags &
  1395. IEEE80211_CHAN_DISABLED)
  1396. continue;
  1397. arg.n_channels++;
  1398. }
  1399. }
  1400. len = sizeof(struct wmi_channel_arg) * arg.n_channels;
  1401. arg.channels = kzalloc(len, GFP_KERNEL);
  1402. if (!arg.channels)
  1403. return -ENOMEM;
  1404. ch = arg.channels;
  1405. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1406. if (!bands[band])
  1407. continue;
  1408. for (i = 0; i < bands[band]->n_channels; i++) {
  1409. channel = &bands[band]->channels[i];
  1410. if (channel->flags & IEEE80211_CHAN_DISABLED)
  1411. continue;
  1412. ch->allow_ht = true;
  1413. /* FIXME: when should we really allow VHT? */
  1414. ch->allow_vht = true;
  1415. ch->allow_ibss =
  1416. !(channel->flags & IEEE80211_CHAN_NO_IR);
  1417. ch->ht40plus =
  1418. !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
  1419. ch->chan_radar =
  1420. !!(channel->flags & IEEE80211_CHAN_RADAR);
  1421. passive = channel->flags & IEEE80211_CHAN_NO_IR;
  1422. ch->passive = passive;
  1423. ch->freq = channel->center_freq;
  1424. ch->band_center_freq1 = channel->center_freq;
  1425. ch->min_power = 0;
  1426. ch->max_power = channel->max_power * 2;
  1427. ch->max_reg_power = channel->max_reg_power * 2;
  1428. ch->max_antenna_gain = channel->max_antenna_gain * 2;
  1429. ch->reg_class_id = 0; /* FIXME */
  1430. /* FIXME: why use only legacy modes, why not any
  1431. * HT/VHT modes? Would that even make any
  1432. * difference? */
  1433. if (channel->band == IEEE80211_BAND_2GHZ)
  1434. ch->mode = MODE_11G;
  1435. else
  1436. ch->mode = MODE_11A;
  1437. if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
  1438. continue;
  1439. ath10k_dbg(ar, ATH10K_DBG_WMI,
  1440. "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
  1441. ch - arg.channels, arg.n_channels,
  1442. ch->freq, ch->max_power, ch->max_reg_power,
  1443. ch->max_antenna_gain, ch->mode);
  1444. ch++;
  1445. }
  1446. }
  1447. ret = ath10k_wmi_scan_chan_list(ar, &arg);
  1448. kfree(arg.channels);
  1449. return ret;
  1450. }
  1451. static enum wmi_dfs_region
  1452. ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
  1453. {
  1454. switch (dfs_region) {
  1455. case NL80211_DFS_UNSET:
  1456. return WMI_UNINIT_DFS_DOMAIN;
  1457. case NL80211_DFS_FCC:
  1458. return WMI_FCC_DFS_DOMAIN;
  1459. case NL80211_DFS_ETSI:
  1460. return WMI_ETSI_DFS_DOMAIN;
  1461. case NL80211_DFS_JP:
  1462. return WMI_MKK4_DFS_DOMAIN;
  1463. }
  1464. return WMI_UNINIT_DFS_DOMAIN;
  1465. }
  1466. static void ath10k_regd_update(struct ath10k *ar)
  1467. {
  1468. struct reg_dmn_pair_mapping *regpair;
  1469. int ret;
  1470. enum wmi_dfs_region wmi_dfs_reg;
  1471. enum nl80211_dfs_regions nl_dfs_reg;
  1472. lockdep_assert_held(&ar->conf_mutex);
  1473. ret = ath10k_update_channel_list(ar);
  1474. if (ret)
  1475. ath10k_warn(ar, "failed to update channel list: %d\n", ret);
  1476. regpair = ar->ath_common.regulatory.regpair;
  1477. if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
  1478. nl_dfs_reg = ar->dfs_detector->region;
  1479. wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
  1480. } else {
  1481. wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
  1482. }
  1483. /* Target allows setting up per-band regdomain but ath_common provides
  1484. * a combined one only */
  1485. ret = ath10k_wmi_pdev_set_regdomain(ar,
  1486. regpair->reg_domain,
  1487. regpair->reg_domain, /* 2ghz */
  1488. regpair->reg_domain, /* 5ghz */
  1489. regpair->reg_2ghz_ctl,
  1490. regpair->reg_5ghz_ctl,
  1491. wmi_dfs_reg);
  1492. if (ret)
  1493. ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
  1494. }
  1495. static void ath10k_reg_notifier(struct wiphy *wiphy,
  1496. struct regulatory_request *request)
  1497. {
  1498. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  1499. struct ath10k *ar = hw->priv;
  1500. bool result;
  1501. ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
  1502. if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
  1503. ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
  1504. request->dfs_region);
  1505. result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
  1506. request->dfs_region);
  1507. if (!result)
  1508. ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
  1509. request->dfs_region);
  1510. }
  1511. mutex_lock(&ar->conf_mutex);
  1512. if (ar->state == ATH10K_STATE_ON)
  1513. ath10k_regd_update(ar);
  1514. mutex_unlock(&ar->conf_mutex);
  1515. }
  1516. /***************/
  1517. /* TX handlers */
  1518. /***************/
  1519. static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
  1520. {
  1521. if (ieee80211_is_mgmt(hdr->frame_control))
  1522. return HTT_DATA_TX_EXT_TID_MGMT;
  1523. if (!ieee80211_is_data_qos(hdr->frame_control))
  1524. return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
  1525. if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
  1526. return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
  1527. return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
  1528. }
  1529. static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
  1530. {
  1531. if (vif)
  1532. return ath10k_vif_to_arvif(vif)->vdev_id;
  1533. if (ar->monitor_started)
  1534. return ar->monitor_vdev_id;
  1535. ath10k_warn(ar, "failed to resolve vdev id\n");
  1536. return 0;
  1537. }
  1538. /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
  1539. * Control in the header.
  1540. */
  1541. static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
  1542. {
  1543. struct ieee80211_hdr *hdr = (void *)skb->data;
  1544. struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
  1545. u8 *qos_ctl;
  1546. if (!ieee80211_is_data_qos(hdr->frame_control))
  1547. return;
  1548. qos_ctl = ieee80211_get_qos_ctl(hdr);
  1549. memmove(skb->data + IEEE80211_QOS_CTL_LEN,
  1550. skb->data, (void *)qos_ctl - (void *)skb->data);
  1551. skb_pull(skb, IEEE80211_QOS_CTL_LEN);
  1552. /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
  1553. * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
  1554. * used only for CQM purposes (e.g. hostapd station keepalive ping) so
  1555. * it is safe to downgrade to NullFunc.
  1556. */
  1557. if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
  1558. hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  1559. cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
  1560. }
  1561. }
  1562. static void ath10k_tx_wep_key_work(struct work_struct *work)
  1563. {
  1564. struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
  1565. wep_key_work);
  1566. struct ath10k *ar = arvif->ar;
  1567. int ret, keyidx = arvif->def_wep_key_newidx;
  1568. mutex_lock(&arvif->ar->conf_mutex);
  1569. if (arvif->ar->state != ATH10K_STATE_ON)
  1570. goto unlock;
  1571. if (arvif->def_wep_key_idx == keyidx)
  1572. goto unlock;
  1573. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
  1574. arvif->vdev_id, keyidx);
  1575. ret = ath10k_wmi_vdev_set_param(arvif->ar,
  1576. arvif->vdev_id,
  1577. arvif->ar->wmi.vdev_param->def_keyid,
  1578. keyidx);
  1579. if (ret) {
  1580. ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
  1581. arvif->vdev_id,
  1582. ret);
  1583. goto unlock;
  1584. }
  1585. arvif->def_wep_key_idx = keyidx;
  1586. unlock:
  1587. mutex_unlock(&arvif->ar->conf_mutex);
  1588. }
  1589. static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
  1590. struct ieee80211_key_conf *key,
  1591. struct sk_buff *skb)
  1592. {
  1593. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1594. struct ath10k *ar = arvif->ar;
  1595. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1596. if (!ieee80211_has_protected(hdr->frame_control))
  1597. return;
  1598. if (!key)
  1599. return;
  1600. if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
  1601. key->cipher != WLAN_CIPHER_SUITE_WEP104)
  1602. return;
  1603. if (key->keyidx == arvif->def_wep_key_idx)
  1604. return;
  1605. /* FIXME: Most likely a few frames will be TXed with an old key. Simply
  1606. * queueing frames until key index is updated is not an option because
  1607. * sk_buff may need more processing to be done, e.g. offchannel */
  1608. arvif->def_wep_key_newidx = key->keyidx;
  1609. ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
  1610. }
  1611. static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
  1612. struct ieee80211_vif *vif,
  1613. struct sk_buff *skb)
  1614. {
  1615. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1616. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1617. /* This is case only for P2P_GO */
  1618. if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
  1619. arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
  1620. return;
  1621. if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
  1622. spin_lock_bh(&ar->data_lock);
  1623. if (arvif->u.ap.noa_data)
  1624. if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
  1625. GFP_ATOMIC))
  1626. memcpy(skb_put(skb, arvif->u.ap.noa_len),
  1627. arvif->u.ap.noa_data,
  1628. arvif->u.ap.noa_len);
  1629. spin_unlock_bh(&ar->data_lock);
  1630. }
  1631. }
  1632. static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
  1633. {
  1634. /* FIXME: Not really sure since when the behaviour changed. At some
  1635. * point new firmware stopped requiring creation of peer entries for
  1636. * offchannel tx (and actually creating them causes issues with wmi-htc
  1637. * tx credit replenishment and reliability). Assuming it's at least 3.4
  1638. * because that's when the `freq` was introduced to TX_FRM HTT command.
  1639. */
  1640. return !(ar->htt.target_version_major >= 3 &&
  1641. ar->htt.target_version_minor >= 4);
  1642. }
  1643. static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
  1644. {
  1645. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1646. int ret = 0;
  1647. if (ar->htt.target_version_major >= 3) {
  1648. /* Since HTT 3.0 there is no separate mgmt tx command */
  1649. ret = ath10k_htt_tx(&ar->htt, skb);
  1650. goto exit;
  1651. }
  1652. if (ieee80211_is_mgmt(hdr->frame_control)) {
  1653. if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
  1654. ar->fw_features)) {
  1655. if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
  1656. ATH10K_MAX_NUM_MGMT_PENDING) {
  1657. ath10k_warn(ar, "reached WMI management transmit queue limit\n");
  1658. ret = -EBUSY;
  1659. goto exit;
  1660. }
  1661. skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
  1662. ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
  1663. } else {
  1664. ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
  1665. }
  1666. } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
  1667. ar->fw_features) &&
  1668. ieee80211_is_nullfunc(hdr->frame_control)) {
  1669. /* FW does not report tx status properly for NullFunc frames
  1670. * unless they are sent through mgmt tx path. mac80211 sends
  1671. * those frames when it detects link/beacon loss and depends
  1672. * on the tx status to be correct. */
  1673. ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
  1674. } else {
  1675. ret = ath10k_htt_tx(&ar->htt, skb);
  1676. }
  1677. exit:
  1678. if (ret) {
  1679. ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
  1680. ret);
  1681. ieee80211_free_txskb(ar->hw, skb);
  1682. }
  1683. }
  1684. void ath10k_offchan_tx_purge(struct ath10k *ar)
  1685. {
  1686. struct sk_buff *skb;
  1687. for (;;) {
  1688. skb = skb_dequeue(&ar->offchan_tx_queue);
  1689. if (!skb)
  1690. break;
  1691. ieee80211_free_txskb(ar->hw, skb);
  1692. }
  1693. }
  1694. void ath10k_offchan_tx_work(struct work_struct *work)
  1695. {
  1696. struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
  1697. struct ath10k_peer *peer;
  1698. struct ieee80211_hdr *hdr;
  1699. struct sk_buff *skb;
  1700. const u8 *peer_addr;
  1701. int vdev_id;
  1702. int ret;
  1703. /* FW requirement: We must create a peer before FW will send out
  1704. * an offchannel frame. Otherwise the frame will be stuck and
  1705. * never transmitted. We delete the peer upon tx completion.
  1706. * It is unlikely that a peer for offchannel tx will already be
  1707. * present. However it may be in some rare cases so account for that.
  1708. * Otherwise we might remove a legitimate peer and break stuff. */
  1709. for (;;) {
  1710. skb = skb_dequeue(&ar->offchan_tx_queue);
  1711. if (!skb)
  1712. break;
  1713. mutex_lock(&ar->conf_mutex);
  1714. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
  1715. skb);
  1716. hdr = (struct ieee80211_hdr *)skb->data;
  1717. peer_addr = ieee80211_get_DA(hdr);
  1718. vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
  1719. spin_lock_bh(&ar->data_lock);
  1720. peer = ath10k_peer_find(ar, vdev_id, peer_addr);
  1721. spin_unlock_bh(&ar->data_lock);
  1722. if (peer)
  1723. /* FIXME: should this use ath10k_warn()? */
  1724. ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
  1725. peer_addr, vdev_id);
  1726. if (!peer) {
  1727. ret = ath10k_peer_create(ar, vdev_id, peer_addr);
  1728. if (ret)
  1729. ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
  1730. peer_addr, vdev_id, ret);
  1731. }
  1732. spin_lock_bh(&ar->data_lock);
  1733. reinit_completion(&ar->offchan_tx_completed);
  1734. ar->offchan_tx_skb = skb;
  1735. spin_unlock_bh(&ar->data_lock);
  1736. ath10k_tx_htt(ar, skb);
  1737. ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
  1738. 3 * HZ);
  1739. if (ret <= 0)
  1740. ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
  1741. skb);
  1742. if (!peer) {
  1743. ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
  1744. if (ret)
  1745. ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
  1746. peer_addr, vdev_id, ret);
  1747. }
  1748. mutex_unlock(&ar->conf_mutex);
  1749. }
  1750. }
  1751. void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
  1752. {
  1753. struct sk_buff *skb;
  1754. for (;;) {
  1755. skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
  1756. if (!skb)
  1757. break;
  1758. ieee80211_free_txskb(ar->hw, skb);
  1759. }
  1760. }
  1761. void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
  1762. {
  1763. struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
  1764. struct sk_buff *skb;
  1765. int ret;
  1766. for (;;) {
  1767. skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
  1768. if (!skb)
  1769. break;
  1770. ret = ath10k_wmi_mgmt_tx(ar, skb);
  1771. if (ret) {
  1772. ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
  1773. ret);
  1774. ieee80211_free_txskb(ar->hw, skb);
  1775. }
  1776. }
  1777. }
  1778. /************/
  1779. /* Scanning */
  1780. /************/
  1781. void __ath10k_scan_finish(struct ath10k *ar)
  1782. {
  1783. lockdep_assert_held(&ar->data_lock);
  1784. switch (ar->scan.state) {
  1785. case ATH10K_SCAN_IDLE:
  1786. break;
  1787. case ATH10K_SCAN_RUNNING:
  1788. if (ar->scan.is_roc)
  1789. ieee80211_remain_on_channel_expired(ar->hw);
  1790. case ATH10K_SCAN_ABORTING:
  1791. if (!ar->scan.is_roc)
  1792. ieee80211_scan_completed(ar->hw,
  1793. (ar->scan.state ==
  1794. ATH10K_SCAN_ABORTING));
  1795. /* fall through */
  1796. case ATH10K_SCAN_STARTING:
  1797. ar->scan.state = ATH10K_SCAN_IDLE;
  1798. ar->scan_channel = NULL;
  1799. ath10k_offchan_tx_purge(ar);
  1800. cancel_delayed_work(&ar->scan.timeout);
  1801. complete_all(&ar->scan.completed);
  1802. break;
  1803. }
  1804. }
  1805. void ath10k_scan_finish(struct ath10k *ar)
  1806. {
  1807. spin_lock_bh(&ar->data_lock);
  1808. __ath10k_scan_finish(ar);
  1809. spin_unlock_bh(&ar->data_lock);
  1810. }
  1811. static int ath10k_scan_stop(struct ath10k *ar)
  1812. {
  1813. struct wmi_stop_scan_arg arg = {
  1814. .req_id = 1, /* FIXME */
  1815. .req_type = WMI_SCAN_STOP_ONE,
  1816. .u.scan_id = ATH10K_SCAN_ID,
  1817. };
  1818. int ret;
  1819. lockdep_assert_held(&ar->conf_mutex);
  1820. ret = ath10k_wmi_stop_scan(ar, &arg);
  1821. if (ret) {
  1822. ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
  1823. goto out;
  1824. }
  1825. ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
  1826. if (ret == 0) {
  1827. ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
  1828. ret = -ETIMEDOUT;
  1829. } else if (ret > 0) {
  1830. ret = 0;
  1831. }
  1832. out:
  1833. /* Scan state should be updated upon scan completion but in case
  1834. * firmware fails to deliver the event (for whatever reason) it is
  1835. * desired to clean up scan state anyway. Firmware may have just
  1836. * dropped the scan completion event delivery due to transport pipe
  1837. * being overflown with data and/or it can recover on its own before
  1838. * next scan request is submitted.
  1839. */
  1840. spin_lock_bh(&ar->data_lock);
  1841. if (ar->scan.state != ATH10K_SCAN_IDLE)
  1842. __ath10k_scan_finish(ar);
  1843. spin_unlock_bh(&ar->data_lock);
  1844. return ret;
  1845. }
  1846. static void ath10k_scan_abort(struct ath10k *ar)
  1847. {
  1848. int ret;
  1849. lockdep_assert_held(&ar->conf_mutex);
  1850. spin_lock_bh(&ar->data_lock);
  1851. switch (ar->scan.state) {
  1852. case ATH10K_SCAN_IDLE:
  1853. /* This can happen if timeout worker kicked in and called
  1854. * abortion while scan completion was being processed.
  1855. */
  1856. break;
  1857. case ATH10K_SCAN_STARTING:
  1858. case ATH10K_SCAN_ABORTING:
  1859. ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
  1860. ath10k_scan_state_str(ar->scan.state),
  1861. ar->scan.state);
  1862. break;
  1863. case ATH10K_SCAN_RUNNING:
  1864. ar->scan.state = ATH10K_SCAN_ABORTING;
  1865. spin_unlock_bh(&ar->data_lock);
  1866. ret = ath10k_scan_stop(ar);
  1867. if (ret)
  1868. ath10k_warn(ar, "failed to abort scan: %d\n", ret);
  1869. spin_lock_bh(&ar->data_lock);
  1870. break;
  1871. }
  1872. spin_unlock_bh(&ar->data_lock);
  1873. }
  1874. void ath10k_scan_timeout_work(struct work_struct *work)
  1875. {
  1876. struct ath10k *ar = container_of(work, struct ath10k,
  1877. scan.timeout.work);
  1878. mutex_lock(&ar->conf_mutex);
  1879. ath10k_scan_abort(ar);
  1880. mutex_unlock(&ar->conf_mutex);
  1881. }
  1882. static int ath10k_start_scan(struct ath10k *ar,
  1883. const struct wmi_start_scan_arg *arg)
  1884. {
  1885. int ret;
  1886. lockdep_assert_held(&ar->conf_mutex);
  1887. ret = ath10k_wmi_start_scan(ar, arg);
  1888. if (ret)
  1889. return ret;
  1890. ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
  1891. if (ret == 0) {
  1892. ret = ath10k_scan_stop(ar);
  1893. if (ret)
  1894. ath10k_warn(ar, "failed to stop scan: %d\n", ret);
  1895. return -ETIMEDOUT;
  1896. }
  1897. /* Add a 200ms margin to account for event/command processing */
  1898. ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
  1899. msecs_to_jiffies(arg->max_scan_time+200));
  1900. return 0;
  1901. }
  1902. /**********************/
  1903. /* mac80211 callbacks */
  1904. /**********************/
  1905. static void ath10k_tx(struct ieee80211_hw *hw,
  1906. struct ieee80211_tx_control *control,
  1907. struct sk_buff *skb)
  1908. {
  1909. struct ath10k *ar = hw->priv;
  1910. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1911. struct ieee80211_vif *vif = info->control.vif;
  1912. struct ieee80211_key_conf *key = info->control.hw_key;
  1913. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1914. /* We should disable CCK RATE due to P2P */
  1915. if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
  1916. ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
  1917. ATH10K_SKB_CB(skb)->htt.is_offchan = false;
  1918. ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
  1919. ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
  1920. /* it makes no sense to process injected frames like that */
  1921. if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
  1922. ath10k_tx_h_nwifi(hw, skb);
  1923. ath10k_tx_h_update_wep_key(vif, key, skb);
  1924. ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
  1925. ath10k_tx_h_seq_no(vif, skb);
  1926. }
  1927. if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
  1928. spin_lock_bh(&ar->data_lock);
  1929. ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
  1930. ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
  1931. spin_unlock_bh(&ar->data_lock);
  1932. if (ath10k_mac_need_offchan_tx_work(ar)) {
  1933. ATH10K_SKB_CB(skb)->htt.freq = 0;
  1934. ATH10K_SKB_CB(skb)->htt.is_offchan = true;
  1935. ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
  1936. skb);
  1937. skb_queue_tail(&ar->offchan_tx_queue, skb);
  1938. ieee80211_queue_work(hw, &ar->offchan_tx_work);
  1939. return;
  1940. }
  1941. }
  1942. ath10k_tx_htt(ar, skb);
  1943. }
  1944. /* Must not be called with conf_mutex held as workers can use that also. */
  1945. void ath10k_drain_tx(struct ath10k *ar)
  1946. {
  1947. /* make sure rcu-protected mac80211 tx path itself is drained */
  1948. synchronize_net();
  1949. ath10k_offchan_tx_purge(ar);
  1950. ath10k_mgmt_over_wmi_tx_purge(ar);
  1951. cancel_work_sync(&ar->offchan_tx_work);
  1952. cancel_work_sync(&ar->wmi_mgmt_tx_work);
  1953. }
  1954. void ath10k_halt(struct ath10k *ar)
  1955. {
  1956. struct ath10k_vif *arvif;
  1957. lockdep_assert_held(&ar->conf_mutex);
  1958. clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
  1959. ar->filter_flags = 0;
  1960. ar->monitor = false;
  1961. if (ar->monitor_started)
  1962. ath10k_monitor_stop(ar);
  1963. ar->monitor_started = false;
  1964. ath10k_scan_finish(ar);
  1965. ath10k_peer_cleanup_all(ar);
  1966. ath10k_core_stop(ar);
  1967. ath10k_hif_power_down(ar);
  1968. spin_lock_bh(&ar->data_lock);
  1969. list_for_each_entry(arvif, &ar->arvifs, list)
  1970. ath10k_mac_vif_beacon_cleanup(arvif);
  1971. spin_unlock_bh(&ar->data_lock);
  1972. }
  1973. static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  1974. {
  1975. struct ath10k *ar = hw->priv;
  1976. mutex_lock(&ar->conf_mutex);
  1977. if (ar->cfg_tx_chainmask) {
  1978. *tx_ant = ar->cfg_tx_chainmask;
  1979. *rx_ant = ar->cfg_rx_chainmask;
  1980. } else {
  1981. *tx_ant = ar->supp_tx_chainmask;
  1982. *rx_ant = ar->supp_rx_chainmask;
  1983. }
  1984. mutex_unlock(&ar->conf_mutex);
  1985. return 0;
  1986. }
  1987. static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
  1988. {
  1989. /* It is not clear that allowing gaps in chainmask
  1990. * is helpful. Probably it will not do what user
  1991. * is hoping for, so warn in that case.
  1992. */
  1993. if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
  1994. return;
  1995. ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
  1996. dbg, cm);
  1997. }
  1998. static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
  1999. {
  2000. int ret;
  2001. lockdep_assert_held(&ar->conf_mutex);
  2002. ath10k_check_chain_mask(ar, tx_ant, "tx");
  2003. ath10k_check_chain_mask(ar, rx_ant, "rx");
  2004. ar->cfg_tx_chainmask = tx_ant;
  2005. ar->cfg_rx_chainmask = rx_ant;
  2006. if ((ar->state != ATH10K_STATE_ON) &&
  2007. (ar->state != ATH10K_STATE_RESTARTED))
  2008. return 0;
  2009. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
  2010. tx_ant);
  2011. if (ret) {
  2012. ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
  2013. ret, tx_ant);
  2014. return ret;
  2015. }
  2016. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
  2017. rx_ant);
  2018. if (ret) {
  2019. ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
  2020. ret, rx_ant);
  2021. return ret;
  2022. }
  2023. return 0;
  2024. }
  2025. static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  2026. {
  2027. struct ath10k *ar = hw->priv;
  2028. int ret;
  2029. mutex_lock(&ar->conf_mutex);
  2030. ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
  2031. mutex_unlock(&ar->conf_mutex);
  2032. return ret;
  2033. }
  2034. static int ath10k_start(struct ieee80211_hw *hw)
  2035. {
  2036. struct ath10k *ar = hw->priv;
  2037. int ret = 0;
  2038. /*
  2039. * This makes sense only when restarting hw. It is harmless to call
  2040. * uncoditionally. This is necessary to make sure no HTT/WMI tx
  2041. * commands will be submitted while restarting.
  2042. */
  2043. ath10k_drain_tx(ar);
  2044. mutex_lock(&ar->conf_mutex);
  2045. switch (ar->state) {
  2046. case ATH10K_STATE_OFF:
  2047. ar->state = ATH10K_STATE_ON;
  2048. break;
  2049. case ATH10K_STATE_RESTARTING:
  2050. ath10k_halt(ar);
  2051. ar->state = ATH10K_STATE_RESTARTED;
  2052. break;
  2053. case ATH10K_STATE_ON:
  2054. case ATH10K_STATE_RESTARTED:
  2055. case ATH10K_STATE_WEDGED:
  2056. WARN_ON(1);
  2057. ret = -EINVAL;
  2058. goto err;
  2059. case ATH10K_STATE_UTF:
  2060. ret = -EBUSY;
  2061. goto err;
  2062. }
  2063. ret = ath10k_hif_power_up(ar);
  2064. if (ret) {
  2065. ath10k_err(ar, "Could not init hif: %d\n", ret);
  2066. goto err_off;
  2067. }
  2068. ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
  2069. if (ret) {
  2070. ath10k_err(ar, "Could not init core: %d\n", ret);
  2071. goto err_power_down;
  2072. }
  2073. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
  2074. if (ret) {
  2075. ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
  2076. goto err_core_stop;
  2077. }
  2078. ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
  2079. if (ret) {
  2080. ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
  2081. goto err_core_stop;
  2082. }
  2083. if (ar->cfg_tx_chainmask)
  2084. __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
  2085. ar->cfg_rx_chainmask);
  2086. /*
  2087. * By default FW set ARP frames ac to voice (6). In that case ARP
  2088. * exchange is not working properly for UAPSD enabled AP. ARP requests
  2089. * which arrives with access category 0 are processed by network stack
  2090. * and send back with access category 0, but FW changes access category
  2091. * to 6. Set ARP frames access category to best effort (0) solves
  2092. * this problem.
  2093. */
  2094. ret = ath10k_wmi_pdev_set_param(ar,
  2095. ar->wmi.pdev_param->arp_ac_override, 0);
  2096. if (ret) {
  2097. ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
  2098. ret);
  2099. goto err_core_stop;
  2100. }
  2101. ar->num_started_vdevs = 0;
  2102. ath10k_regd_update(ar);
  2103. ath10k_spectral_start(ar);
  2104. mutex_unlock(&ar->conf_mutex);
  2105. return 0;
  2106. err_core_stop:
  2107. ath10k_core_stop(ar);
  2108. err_power_down:
  2109. ath10k_hif_power_down(ar);
  2110. err_off:
  2111. ar->state = ATH10K_STATE_OFF;
  2112. err:
  2113. mutex_unlock(&ar->conf_mutex);
  2114. return ret;
  2115. }
  2116. static void ath10k_stop(struct ieee80211_hw *hw)
  2117. {
  2118. struct ath10k *ar = hw->priv;
  2119. ath10k_drain_tx(ar);
  2120. mutex_lock(&ar->conf_mutex);
  2121. if (ar->state != ATH10K_STATE_OFF) {
  2122. ath10k_halt(ar);
  2123. ar->state = ATH10K_STATE_OFF;
  2124. }
  2125. mutex_unlock(&ar->conf_mutex);
  2126. cancel_delayed_work_sync(&ar->scan.timeout);
  2127. cancel_work_sync(&ar->restart_work);
  2128. }
  2129. static int ath10k_config_ps(struct ath10k *ar)
  2130. {
  2131. struct ath10k_vif *arvif;
  2132. int ret = 0;
  2133. lockdep_assert_held(&ar->conf_mutex);
  2134. list_for_each_entry(arvif, &ar->arvifs, list) {
  2135. ret = ath10k_mac_vif_setup_ps(arvif);
  2136. if (ret) {
  2137. ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
  2138. break;
  2139. }
  2140. }
  2141. return ret;
  2142. }
  2143. static const char *chandef_get_width(enum nl80211_chan_width width)
  2144. {
  2145. switch (width) {
  2146. case NL80211_CHAN_WIDTH_20_NOHT:
  2147. return "20 (noht)";
  2148. case NL80211_CHAN_WIDTH_20:
  2149. return "20";
  2150. case NL80211_CHAN_WIDTH_40:
  2151. return "40";
  2152. case NL80211_CHAN_WIDTH_80:
  2153. return "80";
  2154. case NL80211_CHAN_WIDTH_80P80:
  2155. return "80+80";
  2156. case NL80211_CHAN_WIDTH_160:
  2157. return "160";
  2158. case NL80211_CHAN_WIDTH_5:
  2159. return "5";
  2160. case NL80211_CHAN_WIDTH_10:
  2161. return "10";
  2162. }
  2163. return "?";
  2164. }
  2165. static void ath10k_config_chan(struct ath10k *ar)
  2166. {
  2167. struct ath10k_vif *arvif;
  2168. int ret;
  2169. lockdep_assert_held(&ar->conf_mutex);
  2170. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2171. "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
  2172. ar->chandef.chan->center_freq,
  2173. ar->chandef.center_freq1,
  2174. ar->chandef.center_freq2,
  2175. chandef_get_width(ar->chandef.width));
  2176. /* First stop monitor interface. Some FW versions crash if there's a
  2177. * lone monitor interface. */
  2178. if (ar->monitor_started)
  2179. ath10k_monitor_stop(ar);
  2180. list_for_each_entry(arvif, &ar->arvifs, list) {
  2181. if (!arvif->is_started)
  2182. continue;
  2183. if (!arvif->is_up)
  2184. continue;
  2185. if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
  2186. continue;
  2187. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  2188. if (ret) {
  2189. ath10k_warn(ar, "failed to down vdev %d: %d\n",
  2190. arvif->vdev_id, ret);
  2191. continue;
  2192. }
  2193. }
  2194. /* all vdevs are downed now - attempt to restart and re-up them */
  2195. list_for_each_entry(arvif, &ar->arvifs, list) {
  2196. if (!arvif->is_started)
  2197. continue;
  2198. if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
  2199. continue;
  2200. ret = ath10k_vdev_restart(arvif);
  2201. if (ret) {
  2202. ath10k_warn(ar, "failed to restart vdev %d: %d\n",
  2203. arvif->vdev_id, ret);
  2204. continue;
  2205. }
  2206. if (!arvif->is_up)
  2207. continue;
  2208. ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
  2209. arvif->bssid);
  2210. if (ret) {
  2211. ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
  2212. arvif->vdev_id, ret);
  2213. continue;
  2214. }
  2215. }
  2216. ath10k_monitor_recalc(ar);
  2217. }
  2218. static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
  2219. {
  2220. int ret;
  2221. u32 param;
  2222. lockdep_assert_held(&ar->conf_mutex);
  2223. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
  2224. param = ar->wmi.pdev_param->txpower_limit2g;
  2225. ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
  2226. if (ret) {
  2227. ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
  2228. txpower, ret);
  2229. return ret;
  2230. }
  2231. param = ar->wmi.pdev_param->txpower_limit5g;
  2232. ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
  2233. if (ret) {
  2234. ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
  2235. txpower, ret);
  2236. return ret;
  2237. }
  2238. return 0;
  2239. }
  2240. static int ath10k_mac_txpower_recalc(struct ath10k *ar)
  2241. {
  2242. struct ath10k_vif *arvif;
  2243. int ret, txpower = -1;
  2244. lockdep_assert_held(&ar->conf_mutex);
  2245. list_for_each_entry(arvif, &ar->arvifs, list) {
  2246. WARN_ON(arvif->txpower < 0);
  2247. if (txpower == -1)
  2248. txpower = arvif->txpower;
  2249. else
  2250. txpower = min(txpower, arvif->txpower);
  2251. }
  2252. if (WARN_ON(txpower == -1))
  2253. return -EINVAL;
  2254. ret = ath10k_mac_txpower_setup(ar, txpower);
  2255. if (ret) {
  2256. ath10k_warn(ar, "failed to setup tx power %d: %d\n",
  2257. txpower, ret);
  2258. return ret;
  2259. }
  2260. return 0;
  2261. }
  2262. static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
  2263. {
  2264. struct ath10k *ar = hw->priv;
  2265. struct ieee80211_conf *conf = &hw->conf;
  2266. int ret = 0;
  2267. mutex_lock(&ar->conf_mutex);
  2268. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  2269. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2270. "mac config channel %dMHz flags 0x%x radar %d\n",
  2271. conf->chandef.chan->center_freq,
  2272. conf->chandef.chan->flags,
  2273. conf->radar_enabled);
  2274. spin_lock_bh(&ar->data_lock);
  2275. ar->rx_channel = conf->chandef.chan;
  2276. spin_unlock_bh(&ar->data_lock);
  2277. ar->radar_enabled = conf->radar_enabled;
  2278. ath10k_recalc_radar_detection(ar);
  2279. if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
  2280. ar->chandef = conf->chandef;
  2281. ath10k_config_chan(ar);
  2282. }
  2283. }
  2284. if (changed & IEEE80211_CONF_CHANGE_PS)
  2285. ath10k_config_ps(ar);
  2286. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  2287. ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
  2288. ret = ath10k_monitor_recalc(ar);
  2289. if (ret)
  2290. ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
  2291. }
  2292. mutex_unlock(&ar->conf_mutex);
  2293. return ret;
  2294. }
  2295. static u32 get_nss_from_chainmask(u16 chain_mask)
  2296. {
  2297. if ((chain_mask & 0x15) == 0x15)
  2298. return 4;
  2299. else if ((chain_mask & 0x7) == 0x7)
  2300. return 3;
  2301. else if ((chain_mask & 0x3) == 0x3)
  2302. return 2;
  2303. return 1;
  2304. }
  2305. /*
  2306. * TODO:
  2307. * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
  2308. * because we will send mgmt frames without CCK. This requirement
  2309. * for P2P_FIND/GO_NEG should be handled by checking CCK flag
  2310. * in the TX packet.
  2311. */
  2312. static int ath10k_add_interface(struct ieee80211_hw *hw,
  2313. struct ieee80211_vif *vif)
  2314. {
  2315. struct ath10k *ar = hw->priv;
  2316. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2317. enum wmi_sta_powersave_param param;
  2318. int ret = 0;
  2319. u32 value;
  2320. int bit;
  2321. u32 vdev_param;
  2322. mutex_lock(&ar->conf_mutex);
  2323. memset(arvif, 0, sizeof(*arvif));
  2324. arvif->ar = ar;
  2325. arvif->vif = vif;
  2326. INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
  2327. INIT_LIST_HEAD(&arvif->list);
  2328. if (ar->free_vdev_map == 0) {
  2329. ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
  2330. ret = -EBUSY;
  2331. goto err;
  2332. }
  2333. bit = __ffs64(ar->free_vdev_map);
  2334. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
  2335. bit, ar->free_vdev_map);
  2336. arvif->vdev_id = bit;
  2337. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
  2338. if (ar->p2p)
  2339. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
  2340. switch (vif->type) {
  2341. case NL80211_IFTYPE_UNSPECIFIED:
  2342. case NL80211_IFTYPE_STATION:
  2343. arvif->vdev_type = WMI_VDEV_TYPE_STA;
  2344. if (vif->p2p)
  2345. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
  2346. break;
  2347. case NL80211_IFTYPE_ADHOC:
  2348. arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
  2349. break;
  2350. case NL80211_IFTYPE_AP:
  2351. arvif->vdev_type = WMI_VDEV_TYPE_AP;
  2352. if (vif->p2p)
  2353. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
  2354. break;
  2355. case NL80211_IFTYPE_MONITOR:
  2356. arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
  2357. break;
  2358. default:
  2359. WARN_ON(1);
  2360. break;
  2361. }
  2362. /* Some firmware revisions don't wait for beacon tx completion before
  2363. * sending another SWBA event. This could lead to hardware using old
  2364. * (freed) beacon data in some cases, e.g. tx credit starvation
  2365. * combined with missed TBTT. This is very very rare.
  2366. *
  2367. * On non-IOMMU-enabled hosts this could be a possible security issue
  2368. * because hw could beacon some random data on the air. On
  2369. * IOMMU-enabled hosts DMAR faults would occur in most cases and target
  2370. * device would crash.
  2371. *
  2372. * Since there are no beacon tx completions (implicit nor explicit)
  2373. * propagated to host the only workaround for this is to allocate a
  2374. * DMA-coherent buffer for a lifetime of a vif and use it for all
  2375. * beacon tx commands. Worst case for this approach is some beacons may
  2376. * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
  2377. */
  2378. if (vif->type == NL80211_IFTYPE_ADHOC ||
  2379. vif->type == NL80211_IFTYPE_AP) {
  2380. arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
  2381. IEEE80211_MAX_FRAME_LEN,
  2382. &arvif->beacon_paddr,
  2383. GFP_ATOMIC);
  2384. if (!arvif->beacon_buf) {
  2385. ret = -ENOMEM;
  2386. ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
  2387. ret);
  2388. goto err;
  2389. }
  2390. }
  2391. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
  2392. arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
  2393. arvif->beacon_buf ? "single-buf" : "per-skb");
  2394. ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
  2395. arvif->vdev_subtype, vif->addr);
  2396. if (ret) {
  2397. ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
  2398. arvif->vdev_id, ret);
  2399. goto err;
  2400. }
  2401. ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
  2402. list_add(&arvif->list, &ar->arvifs);
  2403. vdev_param = ar->wmi.vdev_param->def_keyid;
  2404. ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
  2405. arvif->def_wep_key_idx);
  2406. if (ret) {
  2407. ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
  2408. arvif->vdev_id, ret);
  2409. goto err_vdev_delete;
  2410. }
  2411. vdev_param = ar->wmi.vdev_param->tx_encap_type;
  2412. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2413. ATH10K_HW_TXRX_NATIVE_WIFI);
  2414. /* 10.X firmware does not support this VDEV parameter. Do not warn */
  2415. if (ret && ret != -EOPNOTSUPP) {
  2416. ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
  2417. arvif->vdev_id, ret);
  2418. goto err_vdev_delete;
  2419. }
  2420. if (ar->cfg_tx_chainmask) {
  2421. u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
  2422. vdev_param = ar->wmi.vdev_param->nss;
  2423. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2424. nss);
  2425. if (ret) {
  2426. ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
  2427. arvif->vdev_id, ar->cfg_tx_chainmask, nss,
  2428. ret);
  2429. goto err_vdev_delete;
  2430. }
  2431. }
  2432. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  2433. ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
  2434. if (ret) {
  2435. ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
  2436. arvif->vdev_id, ret);
  2437. goto err_vdev_delete;
  2438. }
  2439. ret = ath10k_mac_set_kickout(arvif);
  2440. if (ret) {
  2441. ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
  2442. arvif->vdev_id, ret);
  2443. goto err_peer_delete;
  2444. }
  2445. }
  2446. if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
  2447. param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
  2448. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  2449. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  2450. param, value);
  2451. if (ret) {
  2452. ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
  2453. arvif->vdev_id, ret);
  2454. goto err_peer_delete;
  2455. }
  2456. param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
  2457. value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
  2458. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  2459. param, value);
  2460. if (ret) {
  2461. ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
  2462. arvif->vdev_id, ret);
  2463. goto err_peer_delete;
  2464. }
  2465. param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
  2466. value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
  2467. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  2468. param, value);
  2469. if (ret) {
  2470. ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
  2471. arvif->vdev_id, ret);
  2472. goto err_peer_delete;
  2473. }
  2474. }
  2475. ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
  2476. if (ret) {
  2477. ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
  2478. arvif->vdev_id, ret);
  2479. goto err_peer_delete;
  2480. }
  2481. ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
  2482. if (ret) {
  2483. ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
  2484. arvif->vdev_id, ret);
  2485. goto err_peer_delete;
  2486. }
  2487. arvif->txpower = vif->bss_conf.txpower;
  2488. ret = ath10k_mac_txpower_recalc(ar);
  2489. if (ret) {
  2490. ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
  2491. goto err_peer_delete;
  2492. }
  2493. mutex_unlock(&ar->conf_mutex);
  2494. return 0;
  2495. err_peer_delete:
  2496. if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
  2497. ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
  2498. err_vdev_delete:
  2499. ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
  2500. ar->free_vdev_map |= 1LL << arvif->vdev_id;
  2501. list_del(&arvif->list);
  2502. err:
  2503. if (arvif->beacon_buf) {
  2504. dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
  2505. arvif->beacon_buf, arvif->beacon_paddr);
  2506. arvif->beacon_buf = NULL;
  2507. }
  2508. mutex_unlock(&ar->conf_mutex);
  2509. return ret;
  2510. }
  2511. static void ath10k_remove_interface(struct ieee80211_hw *hw,
  2512. struct ieee80211_vif *vif)
  2513. {
  2514. struct ath10k *ar = hw->priv;
  2515. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2516. int ret;
  2517. cancel_work_sync(&arvif->wep_key_work);
  2518. mutex_lock(&ar->conf_mutex);
  2519. spin_lock_bh(&ar->data_lock);
  2520. ath10k_mac_vif_beacon_cleanup(arvif);
  2521. spin_unlock_bh(&ar->data_lock);
  2522. ret = ath10k_spectral_vif_stop(arvif);
  2523. if (ret)
  2524. ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
  2525. arvif->vdev_id, ret);
  2526. ar->free_vdev_map |= 1LL << arvif->vdev_id;
  2527. list_del(&arvif->list);
  2528. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  2529. ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
  2530. if (ret)
  2531. ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
  2532. arvif->vdev_id, ret);
  2533. kfree(arvif->u.ap.noa_data);
  2534. }
  2535. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
  2536. arvif->vdev_id);
  2537. ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
  2538. if (ret)
  2539. ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
  2540. arvif->vdev_id, ret);
  2541. ath10k_peer_cleanup(ar, arvif->vdev_id);
  2542. mutex_unlock(&ar->conf_mutex);
  2543. }
  2544. /*
  2545. * FIXME: Has to be verified.
  2546. */
  2547. #define SUPPORTED_FILTERS \
  2548. (FIF_PROMISC_IN_BSS | \
  2549. FIF_ALLMULTI | \
  2550. FIF_CONTROL | \
  2551. FIF_PSPOLL | \
  2552. FIF_OTHER_BSS | \
  2553. FIF_BCN_PRBRESP_PROMISC | \
  2554. FIF_PROBE_REQ | \
  2555. FIF_FCSFAIL)
  2556. static void ath10k_configure_filter(struct ieee80211_hw *hw,
  2557. unsigned int changed_flags,
  2558. unsigned int *total_flags,
  2559. u64 multicast)
  2560. {
  2561. struct ath10k *ar = hw->priv;
  2562. int ret;
  2563. mutex_lock(&ar->conf_mutex);
  2564. changed_flags &= SUPPORTED_FILTERS;
  2565. *total_flags &= SUPPORTED_FILTERS;
  2566. ar->filter_flags = *total_flags;
  2567. ret = ath10k_monitor_recalc(ar);
  2568. if (ret)
  2569. ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
  2570. mutex_unlock(&ar->conf_mutex);
  2571. }
  2572. static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
  2573. struct ieee80211_vif *vif,
  2574. struct ieee80211_bss_conf *info,
  2575. u32 changed)
  2576. {
  2577. struct ath10k *ar = hw->priv;
  2578. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2579. int ret = 0;
  2580. u32 vdev_param, pdev_param, slottime, preamble;
  2581. mutex_lock(&ar->conf_mutex);
  2582. if (changed & BSS_CHANGED_IBSS)
  2583. ath10k_control_ibss(arvif, info, vif->addr);
  2584. if (changed & BSS_CHANGED_BEACON_INT) {
  2585. arvif->beacon_interval = info->beacon_int;
  2586. vdev_param = ar->wmi.vdev_param->beacon_interval;
  2587. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2588. arvif->beacon_interval);
  2589. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2590. "mac vdev %d beacon_interval %d\n",
  2591. arvif->vdev_id, arvif->beacon_interval);
  2592. if (ret)
  2593. ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
  2594. arvif->vdev_id, ret);
  2595. }
  2596. if (changed & BSS_CHANGED_BEACON) {
  2597. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2598. "vdev %d set beacon tx mode to staggered\n",
  2599. arvif->vdev_id);
  2600. pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
  2601. ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
  2602. WMI_BEACON_STAGGERED_MODE);
  2603. if (ret)
  2604. ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
  2605. arvif->vdev_id, ret);
  2606. }
  2607. if (changed & BSS_CHANGED_BEACON_INFO) {
  2608. arvif->dtim_period = info->dtim_period;
  2609. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2610. "mac vdev %d dtim_period %d\n",
  2611. arvif->vdev_id, arvif->dtim_period);
  2612. vdev_param = ar->wmi.vdev_param->dtim_period;
  2613. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2614. arvif->dtim_period);
  2615. if (ret)
  2616. ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
  2617. arvif->vdev_id, ret);
  2618. }
  2619. if (changed & BSS_CHANGED_SSID &&
  2620. vif->type == NL80211_IFTYPE_AP) {
  2621. arvif->u.ap.ssid_len = info->ssid_len;
  2622. if (info->ssid_len)
  2623. memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
  2624. arvif->u.ap.hidden_ssid = info->hidden_ssid;
  2625. }
  2626. if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
  2627. ether_addr_copy(arvif->bssid, info->bssid);
  2628. if (changed & BSS_CHANGED_BEACON_ENABLED)
  2629. ath10k_control_beaconing(arvif, info);
  2630. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  2631. arvif->use_cts_prot = info->use_cts_prot;
  2632. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
  2633. arvif->vdev_id, info->use_cts_prot);
  2634. ret = ath10k_recalc_rtscts_prot(arvif);
  2635. if (ret)
  2636. ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  2637. arvif->vdev_id, ret);
  2638. }
  2639. if (changed & BSS_CHANGED_ERP_SLOT) {
  2640. if (info->use_short_slot)
  2641. slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
  2642. else
  2643. slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
  2644. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
  2645. arvif->vdev_id, slottime);
  2646. vdev_param = ar->wmi.vdev_param->slot_time;
  2647. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2648. slottime);
  2649. if (ret)
  2650. ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
  2651. arvif->vdev_id, ret);
  2652. }
  2653. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  2654. if (info->use_short_preamble)
  2655. preamble = WMI_VDEV_PREAMBLE_SHORT;
  2656. else
  2657. preamble = WMI_VDEV_PREAMBLE_LONG;
  2658. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2659. "mac vdev %d preamble %dn",
  2660. arvif->vdev_id, preamble);
  2661. vdev_param = ar->wmi.vdev_param->preamble;
  2662. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2663. preamble);
  2664. if (ret)
  2665. ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
  2666. arvif->vdev_id, ret);
  2667. }
  2668. if (changed & BSS_CHANGED_ASSOC) {
  2669. if (info->assoc) {
  2670. /* Workaround: Make sure monitor vdev is not running
  2671. * when associating to prevent some firmware revisions
  2672. * (e.g. 10.1 and 10.2) from crashing.
  2673. */
  2674. if (ar->monitor_started)
  2675. ath10k_monitor_stop(ar);
  2676. ath10k_bss_assoc(hw, vif, info);
  2677. ath10k_monitor_recalc(ar);
  2678. } else {
  2679. ath10k_bss_disassoc(hw, vif);
  2680. }
  2681. }
  2682. if (changed & BSS_CHANGED_TXPOWER) {
  2683. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
  2684. arvif->vdev_id, info->txpower);
  2685. arvif->txpower = info->txpower;
  2686. ret = ath10k_mac_txpower_recalc(ar);
  2687. if (ret)
  2688. ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
  2689. }
  2690. mutex_unlock(&ar->conf_mutex);
  2691. }
  2692. static int ath10k_hw_scan(struct ieee80211_hw *hw,
  2693. struct ieee80211_vif *vif,
  2694. struct ieee80211_scan_request *hw_req)
  2695. {
  2696. struct ath10k *ar = hw->priv;
  2697. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2698. struct cfg80211_scan_request *req = &hw_req->req;
  2699. struct wmi_start_scan_arg arg;
  2700. int ret = 0;
  2701. int i;
  2702. mutex_lock(&ar->conf_mutex);
  2703. spin_lock_bh(&ar->data_lock);
  2704. switch (ar->scan.state) {
  2705. case ATH10K_SCAN_IDLE:
  2706. reinit_completion(&ar->scan.started);
  2707. reinit_completion(&ar->scan.completed);
  2708. ar->scan.state = ATH10K_SCAN_STARTING;
  2709. ar->scan.is_roc = false;
  2710. ar->scan.vdev_id = arvif->vdev_id;
  2711. ret = 0;
  2712. break;
  2713. case ATH10K_SCAN_STARTING:
  2714. case ATH10K_SCAN_RUNNING:
  2715. case ATH10K_SCAN_ABORTING:
  2716. ret = -EBUSY;
  2717. break;
  2718. }
  2719. spin_unlock_bh(&ar->data_lock);
  2720. if (ret)
  2721. goto exit;
  2722. memset(&arg, 0, sizeof(arg));
  2723. ath10k_wmi_start_scan_init(ar, &arg);
  2724. arg.vdev_id = arvif->vdev_id;
  2725. arg.scan_id = ATH10K_SCAN_ID;
  2726. if (!req->no_cck)
  2727. arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
  2728. if (req->ie_len) {
  2729. arg.ie_len = req->ie_len;
  2730. memcpy(arg.ie, req->ie, arg.ie_len);
  2731. }
  2732. if (req->n_ssids) {
  2733. arg.n_ssids = req->n_ssids;
  2734. for (i = 0; i < arg.n_ssids; i++) {
  2735. arg.ssids[i].len = req->ssids[i].ssid_len;
  2736. arg.ssids[i].ssid = req->ssids[i].ssid;
  2737. }
  2738. } else {
  2739. arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
  2740. }
  2741. if (req->n_channels) {
  2742. arg.n_channels = req->n_channels;
  2743. for (i = 0; i < arg.n_channels; i++)
  2744. arg.channels[i] = req->channels[i]->center_freq;
  2745. }
  2746. ret = ath10k_start_scan(ar, &arg);
  2747. if (ret) {
  2748. ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
  2749. spin_lock_bh(&ar->data_lock);
  2750. ar->scan.state = ATH10K_SCAN_IDLE;
  2751. spin_unlock_bh(&ar->data_lock);
  2752. }
  2753. exit:
  2754. mutex_unlock(&ar->conf_mutex);
  2755. return ret;
  2756. }
  2757. static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
  2758. struct ieee80211_vif *vif)
  2759. {
  2760. struct ath10k *ar = hw->priv;
  2761. mutex_lock(&ar->conf_mutex);
  2762. ath10k_scan_abort(ar);
  2763. mutex_unlock(&ar->conf_mutex);
  2764. cancel_delayed_work_sync(&ar->scan.timeout);
  2765. }
  2766. static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
  2767. struct ath10k_vif *arvif,
  2768. enum set_key_cmd cmd,
  2769. struct ieee80211_key_conf *key)
  2770. {
  2771. u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
  2772. int ret;
  2773. /* 10.1 firmware branch requires default key index to be set to group
  2774. * key index after installing it. Otherwise FW/HW Txes corrupted
  2775. * frames with multi-vif APs. This is not required for main firmware
  2776. * branch (e.g. 636).
  2777. *
  2778. * FIXME: This has been tested only in AP. It remains unknown if this
  2779. * is required for multi-vif STA interfaces on 10.1 */
  2780. if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
  2781. return;
  2782. if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
  2783. return;
  2784. if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
  2785. return;
  2786. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  2787. return;
  2788. if (cmd != SET_KEY)
  2789. return;
  2790. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2791. key->keyidx);
  2792. if (ret)
  2793. ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
  2794. arvif->vdev_id, ret);
  2795. }
  2796. static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2797. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  2798. struct ieee80211_key_conf *key)
  2799. {
  2800. struct ath10k *ar = hw->priv;
  2801. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2802. struct ath10k_peer *peer;
  2803. const u8 *peer_addr;
  2804. bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2805. key->cipher == WLAN_CIPHER_SUITE_WEP104;
  2806. int ret = 0;
  2807. if (key->keyidx > WMI_MAX_KEY_INDEX)
  2808. return -ENOSPC;
  2809. mutex_lock(&ar->conf_mutex);
  2810. if (sta)
  2811. peer_addr = sta->addr;
  2812. else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
  2813. peer_addr = vif->bss_conf.bssid;
  2814. else
  2815. peer_addr = vif->addr;
  2816. key->hw_key_idx = key->keyidx;
  2817. /* the peer should not disappear in mid-way (unless FW goes awry) since
  2818. * we already hold conf_mutex. we just make sure its there now. */
  2819. spin_lock_bh(&ar->data_lock);
  2820. peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
  2821. spin_unlock_bh(&ar->data_lock);
  2822. if (!peer) {
  2823. if (cmd == SET_KEY) {
  2824. ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
  2825. peer_addr);
  2826. ret = -EOPNOTSUPP;
  2827. goto exit;
  2828. } else {
  2829. /* if the peer doesn't exist there is no key to disable
  2830. * anymore */
  2831. goto exit;
  2832. }
  2833. }
  2834. if (is_wep) {
  2835. if (cmd == SET_KEY)
  2836. arvif->wep_keys[key->keyidx] = key;
  2837. else
  2838. arvif->wep_keys[key->keyidx] = NULL;
  2839. if (cmd == DISABLE_KEY)
  2840. ath10k_clear_vdev_key(arvif, key);
  2841. }
  2842. ret = ath10k_install_key(arvif, key, cmd, peer_addr);
  2843. if (ret) {
  2844. ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
  2845. arvif->vdev_id, peer_addr, ret);
  2846. goto exit;
  2847. }
  2848. ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
  2849. spin_lock_bh(&ar->data_lock);
  2850. peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
  2851. if (peer && cmd == SET_KEY)
  2852. peer->keys[key->keyidx] = key;
  2853. else if (peer && cmd == DISABLE_KEY)
  2854. peer->keys[key->keyidx] = NULL;
  2855. else if (peer == NULL)
  2856. /* impossible unless FW goes crazy */
  2857. ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
  2858. spin_unlock_bh(&ar->data_lock);
  2859. exit:
  2860. mutex_unlock(&ar->conf_mutex);
  2861. return ret;
  2862. }
  2863. static void ath10k_sta_rc_update_wk(struct work_struct *wk)
  2864. {
  2865. struct ath10k *ar;
  2866. struct ath10k_vif *arvif;
  2867. struct ath10k_sta *arsta;
  2868. struct ieee80211_sta *sta;
  2869. u32 changed, bw, nss, smps;
  2870. int err;
  2871. arsta = container_of(wk, struct ath10k_sta, update_wk);
  2872. sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
  2873. arvif = arsta->arvif;
  2874. ar = arvif->ar;
  2875. spin_lock_bh(&ar->data_lock);
  2876. changed = arsta->changed;
  2877. arsta->changed = 0;
  2878. bw = arsta->bw;
  2879. nss = arsta->nss;
  2880. smps = arsta->smps;
  2881. spin_unlock_bh(&ar->data_lock);
  2882. mutex_lock(&ar->conf_mutex);
  2883. if (changed & IEEE80211_RC_BW_CHANGED) {
  2884. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
  2885. sta->addr, bw);
  2886. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  2887. WMI_PEER_CHAN_WIDTH, bw);
  2888. if (err)
  2889. ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
  2890. sta->addr, bw, err);
  2891. }
  2892. if (changed & IEEE80211_RC_NSS_CHANGED) {
  2893. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
  2894. sta->addr, nss);
  2895. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  2896. WMI_PEER_NSS, nss);
  2897. if (err)
  2898. ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
  2899. sta->addr, nss, err);
  2900. }
  2901. if (changed & IEEE80211_RC_SMPS_CHANGED) {
  2902. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
  2903. sta->addr, smps);
  2904. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  2905. WMI_PEER_SMPS_STATE, smps);
  2906. if (err)
  2907. ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
  2908. sta->addr, smps, err);
  2909. }
  2910. if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
  2911. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
  2912. sta->addr);
  2913. err = ath10k_station_assoc(ar, arvif->vif, sta, true);
  2914. if (err)
  2915. ath10k_warn(ar, "failed to reassociate station: %pM\n",
  2916. sta->addr);
  2917. }
  2918. mutex_unlock(&ar->conf_mutex);
  2919. }
  2920. static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
  2921. {
  2922. struct ath10k *ar = arvif->ar;
  2923. lockdep_assert_held(&ar->conf_mutex);
  2924. if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
  2925. arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
  2926. return 0;
  2927. if (ar->num_stations >= ar->max_num_stations)
  2928. return -ENOBUFS;
  2929. ar->num_stations++;
  2930. return 0;
  2931. }
  2932. static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
  2933. {
  2934. struct ath10k *ar = arvif->ar;
  2935. lockdep_assert_held(&ar->conf_mutex);
  2936. if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
  2937. arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
  2938. return;
  2939. ar->num_stations--;
  2940. }
  2941. static int ath10k_sta_state(struct ieee80211_hw *hw,
  2942. struct ieee80211_vif *vif,
  2943. struct ieee80211_sta *sta,
  2944. enum ieee80211_sta_state old_state,
  2945. enum ieee80211_sta_state new_state)
  2946. {
  2947. struct ath10k *ar = hw->priv;
  2948. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2949. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  2950. int ret = 0;
  2951. if (old_state == IEEE80211_STA_NOTEXIST &&
  2952. new_state == IEEE80211_STA_NONE) {
  2953. memset(arsta, 0, sizeof(*arsta));
  2954. arsta->arvif = arvif;
  2955. INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
  2956. }
  2957. /* cancel must be done outside the mutex to avoid deadlock */
  2958. if ((old_state == IEEE80211_STA_NONE &&
  2959. new_state == IEEE80211_STA_NOTEXIST))
  2960. cancel_work_sync(&arsta->update_wk);
  2961. mutex_lock(&ar->conf_mutex);
  2962. if (old_state == IEEE80211_STA_NOTEXIST &&
  2963. new_state == IEEE80211_STA_NONE) {
  2964. /*
  2965. * New station addition.
  2966. */
  2967. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2968. "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
  2969. arvif->vdev_id, sta->addr,
  2970. ar->num_stations + 1, ar->max_num_stations,
  2971. ar->num_peers + 1, ar->max_num_peers);
  2972. ret = ath10k_mac_inc_num_stations(arvif);
  2973. if (ret) {
  2974. ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
  2975. ar->max_num_stations);
  2976. goto exit;
  2977. }
  2978. ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
  2979. if (ret) {
  2980. ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
  2981. sta->addr, arvif->vdev_id, ret);
  2982. ath10k_mac_dec_num_stations(arvif);
  2983. goto exit;
  2984. }
  2985. if (vif->type == NL80211_IFTYPE_STATION) {
  2986. WARN_ON(arvif->is_started);
  2987. ret = ath10k_vdev_start(arvif);
  2988. if (ret) {
  2989. ath10k_warn(ar, "failed to start vdev %i: %d\n",
  2990. arvif->vdev_id, ret);
  2991. WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
  2992. sta->addr));
  2993. ath10k_mac_dec_num_stations(arvif);
  2994. goto exit;
  2995. }
  2996. arvif->is_started = true;
  2997. }
  2998. } else if ((old_state == IEEE80211_STA_NONE &&
  2999. new_state == IEEE80211_STA_NOTEXIST)) {
  3000. /*
  3001. * Existing station deletion.
  3002. */
  3003. ath10k_dbg(ar, ATH10K_DBG_MAC,
  3004. "mac vdev %d peer delete %pM (sta gone)\n",
  3005. arvif->vdev_id, sta->addr);
  3006. if (vif->type == NL80211_IFTYPE_STATION) {
  3007. WARN_ON(!arvif->is_started);
  3008. ret = ath10k_vdev_stop(arvif);
  3009. if (ret)
  3010. ath10k_warn(ar, "failed to stop vdev %i: %d\n",
  3011. arvif->vdev_id, ret);
  3012. arvif->is_started = false;
  3013. }
  3014. ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
  3015. if (ret)
  3016. ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
  3017. sta->addr, arvif->vdev_id, ret);
  3018. ath10k_mac_dec_num_stations(arvif);
  3019. } else if (old_state == IEEE80211_STA_AUTH &&
  3020. new_state == IEEE80211_STA_ASSOC &&
  3021. (vif->type == NL80211_IFTYPE_AP ||
  3022. vif->type == NL80211_IFTYPE_ADHOC)) {
  3023. /*
  3024. * New association.
  3025. */
  3026. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
  3027. sta->addr);
  3028. ret = ath10k_station_assoc(ar, vif, sta, false);
  3029. if (ret)
  3030. ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
  3031. sta->addr, arvif->vdev_id, ret);
  3032. } else if (old_state == IEEE80211_STA_ASSOC &&
  3033. new_state == IEEE80211_STA_AUTH &&
  3034. (vif->type == NL80211_IFTYPE_AP ||
  3035. vif->type == NL80211_IFTYPE_ADHOC)) {
  3036. /*
  3037. * Disassociation.
  3038. */
  3039. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
  3040. sta->addr);
  3041. ret = ath10k_station_disassoc(ar, vif, sta);
  3042. if (ret)
  3043. ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
  3044. sta->addr, arvif->vdev_id, ret);
  3045. }
  3046. exit:
  3047. mutex_unlock(&ar->conf_mutex);
  3048. return ret;
  3049. }
  3050. static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
  3051. u16 ac, bool enable)
  3052. {
  3053. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3054. u32 value = 0;
  3055. int ret = 0;
  3056. lockdep_assert_held(&ar->conf_mutex);
  3057. if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
  3058. return 0;
  3059. switch (ac) {
  3060. case IEEE80211_AC_VO:
  3061. value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
  3062. WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
  3063. break;
  3064. case IEEE80211_AC_VI:
  3065. value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
  3066. WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
  3067. break;
  3068. case IEEE80211_AC_BE:
  3069. value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
  3070. WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
  3071. break;
  3072. case IEEE80211_AC_BK:
  3073. value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
  3074. WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
  3075. break;
  3076. }
  3077. if (enable)
  3078. arvif->u.sta.uapsd |= value;
  3079. else
  3080. arvif->u.sta.uapsd &= ~value;
  3081. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  3082. WMI_STA_PS_PARAM_UAPSD,
  3083. arvif->u.sta.uapsd);
  3084. if (ret) {
  3085. ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
  3086. goto exit;
  3087. }
  3088. if (arvif->u.sta.uapsd)
  3089. value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
  3090. else
  3091. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  3092. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  3093. WMI_STA_PS_PARAM_RX_WAKE_POLICY,
  3094. value);
  3095. if (ret)
  3096. ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
  3097. exit:
  3098. return ret;
  3099. }
  3100. static int ath10k_conf_tx(struct ieee80211_hw *hw,
  3101. struct ieee80211_vif *vif, u16 ac,
  3102. const struct ieee80211_tx_queue_params *params)
  3103. {
  3104. struct ath10k *ar = hw->priv;
  3105. struct wmi_wmm_params_arg *p = NULL;
  3106. int ret;
  3107. mutex_lock(&ar->conf_mutex);
  3108. switch (ac) {
  3109. case IEEE80211_AC_VO:
  3110. p = &ar->wmm_params.ac_vo;
  3111. break;
  3112. case IEEE80211_AC_VI:
  3113. p = &ar->wmm_params.ac_vi;
  3114. break;
  3115. case IEEE80211_AC_BE:
  3116. p = &ar->wmm_params.ac_be;
  3117. break;
  3118. case IEEE80211_AC_BK:
  3119. p = &ar->wmm_params.ac_bk;
  3120. break;
  3121. }
  3122. if (WARN_ON(!p)) {
  3123. ret = -EINVAL;
  3124. goto exit;
  3125. }
  3126. p->cwmin = params->cw_min;
  3127. p->cwmax = params->cw_max;
  3128. p->aifs = params->aifs;
  3129. /*
  3130. * The channel time duration programmed in the HW is in absolute
  3131. * microseconds, while mac80211 gives the txop in units of
  3132. * 32 microseconds.
  3133. */
  3134. p->txop = params->txop * 32;
  3135. /* FIXME: FW accepts wmm params per hw, not per vif */
  3136. ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
  3137. if (ret) {
  3138. ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
  3139. goto exit;
  3140. }
  3141. ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
  3142. if (ret)
  3143. ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
  3144. exit:
  3145. mutex_unlock(&ar->conf_mutex);
  3146. return ret;
  3147. }
  3148. #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
  3149. static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
  3150. struct ieee80211_vif *vif,
  3151. struct ieee80211_channel *chan,
  3152. int duration,
  3153. enum ieee80211_roc_type type)
  3154. {
  3155. struct ath10k *ar = hw->priv;
  3156. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3157. struct wmi_start_scan_arg arg;
  3158. int ret = 0;
  3159. mutex_lock(&ar->conf_mutex);
  3160. spin_lock_bh(&ar->data_lock);
  3161. switch (ar->scan.state) {
  3162. case ATH10K_SCAN_IDLE:
  3163. reinit_completion(&ar->scan.started);
  3164. reinit_completion(&ar->scan.completed);
  3165. reinit_completion(&ar->scan.on_channel);
  3166. ar->scan.state = ATH10K_SCAN_STARTING;
  3167. ar->scan.is_roc = true;
  3168. ar->scan.vdev_id = arvif->vdev_id;
  3169. ar->scan.roc_freq = chan->center_freq;
  3170. ret = 0;
  3171. break;
  3172. case ATH10K_SCAN_STARTING:
  3173. case ATH10K_SCAN_RUNNING:
  3174. case ATH10K_SCAN_ABORTING:
  3175. ret = -EBUSY;
  3176. break;
  3177. }
  3178. spin_unlock_bh(&ar->data_lock);
  3179. if (ret)
  3180. goto exit;
  3181. duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
  3182. memset(&arg, 0, sizeof(arg));
  3183. ath10k_wmi_start_scan_init(ar, &arg);
  3184. arg.vdev_id = arvif->vdev_id;
  3185. arg.scan_id = ATH10K_SCAN_ID;
  3186. arg.n_channels = 1;
  3187. arg.channels[0] = chan->center_freq;
  3188. arg.dwell_time_active = duration;
  3189. arg.dwell_time_passive = duration;
  3190. arg.max_scan_time = 2 * duration;
  3191. arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
  3192. arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
  3193. ret = ath10k_start_scan(ar, &arg);
  3194. if (ret) {
  3195. ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
  3196. spin_lock_bh(&ar->data_lock);
  3197. ar->scan.state = ATH10K_SCAN_IDLE;
  3198. spin_unlock_bh(&ar->data_lock);
  3199. goto exit;
  3200. }
  3201. ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
  3202. if (ret == 0) {
  3203. ath10k_warn(ar, "failed to switch to channel for roc scan\n");
  3204. ret = ath10k_scan_stop(ar);
  3205. if (ret)
  3206. ath10k_warn(ar, "failed to stop scan: %d\n", ret);
  3207. ret = -ETIMEDOUT;
  3208. goto exit;
  3209. }
  3210. ret = 0;
  3211. exit:
  3212. mutex_unlock(&ar->conf_mutex);
  3213. return ret;
  3214. }
  3215. static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
  3216. {
  3217. struct ath10k *ar = hw->priv;
  3218. mutex_lock(&ar->conf_mutex);
  3219. ath10k_scan_abort(ar);
  3220. mutex_unlock(&ar->conf_mutex);
  3221. cancel_delayed_work_sync(&ar->scan.timeout);
  3222. return 0;
  3223. }
  3224. /*
  3225. * Both RTS and Fragmentation threshold are interface-specific
  3226. * in ath10k, but device-specific in mac80211.
  3227. */
  3228. static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  3229. {
  3230. struct ath10k *ar = hw->priv;
  3231. struct ath10k_vif *arvif;
  3232. int ret = 0;
  3233. mutex_lock(&ar->conf_mutex);
  3234. list_for_each_entry(arvif, &ar->arvifs, list) {
  3235. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
  3236. arvif->vdev_id, value);
  3237. ret = ath10k_mac_set_rts(arvif, value);
  3238. if (ret) {
  3239. ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
  3240. arvif->vdev_id, ret);
  3241. break;
  3242. }
  3243. }
  3244. mutex_unlock(&ar->conf_mutex);
  3245. return ret;
  3246. }
  3247. static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
  3248. {
  3249. struct ath10k *ar = hw->priv;
  3250. struct ath10k_vif *arvif;
  3251. int ret = 0;
  3252. mutex_lock(&ar->conf_mutex);
  3253. list_for_each_entry(arvif, &ar->arvifs, list) {
  3254. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
  3255. arvif->vdev_id, value);
  3256. ret = ath10k_mac_set_frag(arvif, value);
  3257. if (ret) {
  3258. ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
  3259. arvif->vdev_id, ret);
  3260. break;
  3261. }
  3262. }
  3263. mutex_unlock(&ar->conf_mutex);
  3264. return ret;
  3265. }
  3266. static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3267. u32 queues, bool drop)
  3268. {
  3269. struct ath10k *ar = hw->priv;
  3270. bool skip;
  3271. int ret;
  3272. /* mac80211 doesn't care if we really xmit queued frames or not
  3273. * we'll collect those frames either way if we stop/delete vdevs */
  3274. if (drop)
  3275. return;
  3276. mutex_lock(&ar->conf_mutex);
  3277. if (ar->state == ATH10K_STATE_WEDGED)
  3278. goto skip;
  3279. ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
  3280. bool empty;
  3281. spin_lock_bh(&ar->htt.tx_lock);
  3282. empty = (ar->htt.num_pending_tx == 0);
  3283. spin_unlock_bh(&ar->htt.tx_lock);
  3284. skip = (ar->state == ATH10K_STATE_WEDGED) ||
  3285. test_bit(ATH10K_FLAG_CRASH_FLUSH,
  3286. &ar->dev_flags);
  3287. (empty || skip);
  3288. }), ATH10K_FLUSH_TIMEOUT_HZ);
  3289. if (ret <= 0 || skip)
  3290. ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
  3291. skip, ar->state, ret);
  3292. skip:
  3293. mutex_unlock(&ar->conf_mutex);
  3294. }
  3295. /* TODO: Implement this function properly
  3296. * For now it is needed to reply to Probe Requests in IBSS mode.
  3297. * Propably we need this information from FW.
  3298. */
  3299. static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
  3300. {
  3301. return 1;
  3302. }
  3303. #ifdef CONFIG_PM
  3304. static int ath10k_suspend(struct ieee80211_hw *hw,
  3305. struct cfg80211_wowlan *wowlan)
  3306. {
  3307. struct ath10k *ar = hw->priv;
  3308. int ret;
  3309. mutex_lock(&ar->conf_mutex);
  3310. ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
  3311. if (ret) {
  3312. if (ret == -ETIMEDOUT)
  3313. goto resume;
  3314. ret = 1;
  3315. goto exit;
  3316. }
  3317. ret = ath10k_hif_suspend(ar);
  3318. if (ret) {
  3319. ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
  3320. goto resume;
  3321. }
  3322. ret = 0;
  3323. goto exit;
  3324. resume:
  3325. ret = ath10k_wmi_pdev_resume_target(ar);
  3326. if (ret)
  3327. ath10k_warn(ar, "failed to resume target: %d\n", ret);
  3328. ret = 1;
  3329. exit:
  3330. mutex_unlock(&ar->conf_mutex);
  3331. return ret;
  3332. }
  3333. static int ath10k_resume(struct ieee80211_hw *hw)
  3334. {
  3335. struct ath10k *ar = hw->priv;
  3336. int ret;
  3337. mutex_lock(&ar->conf_mutex);
  3338. ret = ath10k_hif_resume(ar);
  3339. if (ret) {
  3340. ath10k_warn(ar, "failed to resume hif: %d\n", ret);
  3341. ret = 1;
  3342. goto exit;
  3343. }
  3344. ret = ath10k_wmi_pdev_resume_target(ar);
  3345. if (ret) {
  3346. ath10k_warn(ar, "failed to resume target: %d\n", ret);
  3347. ret = 1;
  3348. goto exit;
  3349. }
  3350. ret = 0;
  3351. exit:
  3352. mutex_unlock(&ar->conf_mutex);
  3353. return ret;
  3354. }
  3355. #endif
  3356. static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
  3357. enum ieee80211_reconfig_type reconfig_type)
  3358. {
  3359. struct ath10k *ar = hw->priv;
  3360. if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
  3361. return;
  3362. mutex_lock(&ar->conf_mutex);
  3363. /* If device failed to restart it will be in a different state, e.g.
  3364. * ATH10K_STATE_WEDGED */
  3365. if (ar->state == ATH10K_STATE_RESTARTED) {
  3366. ath10k_info(ar, "device successfully recovered\n");
  3367. ar->state = ATH10K_STATE_ON;
  3368. ieee80211_wake_queues(ar->hw);
  3369. }
  3370. mutex_unlock(&ar->conf_mutex);
  3371. }
  3372. static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
  3373. struct survey_info *survey)
  3374. {
  3375. struct ath10k *ar = hw->priv;
  3376. struct ieee80211_supported_band *sband;
  3377. struct survey_info *ar_survey = &ar->survey[idx];
  3378. int ret = 0;
  3379. mutex_lock(&ar->conf_mutex);
  3380. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  3381. if (sband && idx >= sband->n_channels) {
  3382. idx -= sband->n_channels;
  3383. sband = NULL;
  3384. }
  3385. if (!sband)
  3386. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  3387. if (!sband || idx >= sband->n_channels) {
  3388. ret = -ENOENT;
  3389. goto exit;
  3390. }
  3391. spin_lock_bh(&ar->data_lock);
  3392. memcpy(survey, ar_survey, sizeof(*survey));
  3393. spin_unlock_bh(&ar->data_lock);
  3394. survey->channel = &sband->channels[idx];
  3395. if (ar->rx_channel == survey->channel)
  3396. survey->filled |= SURVEY_INFO_IN_USE;
  3397. exit:
  3398. mutex_unlock(&ar->conf_mutex);
  3399. return ret;
  3400. }
  3401. /* Helper table for legacy fixed_rate/bitrate_mask */
  3402. static const u8 cck_ofdm_rate[] = {
  3403. /* CCK */
  3404. 3, /* 1Mbps */
  3405. 2, /* 2Mbps */
  3406. 1, /* 5.5Mbps */
  3407. 0, /* 11Mbps */
  3408. /* OFDM */
  3409. 3, /* 6Mbps */
  3410. 7, /* 9Mbps */
  3411. 2, /* 12Mbps */
  3412. 6, /* 18Mbps */
  3413. 1, /* 24Mbps */
  3414. 5, /* 36Mbps */
  3415. 0, /* 48Mbps */
  3416. 4, /* 54Mbps */
  3417. };
  3418. /* Check if only one bit set */
  3419. static int ath10k_check_single_mask(u32 mask)
  3420. {
  3421. int bit;
  3422. bit = ffs(mask);
  3423. if (!bit)
  3424. return 0;
  3425. mask &= ~BIT(bit - 1);
  3426. if (mask)
  3427. return 2;
  3428. return 1;
  3429. }
  3430. static bool
  3431. ath10k_default_bitrate_mask(struct ath10k *ar,
  3432. enum ieee80211_band band,
  3433. const struct cfg80211_bitrate_mask *mask)
  3434. {
  3435. u32 legacy = 0x00ff;
  3436. u8 ht = 0xff, i;
  3437. u16 vht = 0x3ff;
  3438. u16 nrf = ar->num_rf_chains;
  3439. if (ar->cfg_tx_chainmask)
  3440. nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
  3441. switch (band) {
  3442. case IEEE80211_BAND_2GHZ:
  3443. legacy = 0x00fff;
  3444. vht = 0;
  3445. break;
  3446. case IEEE80211_BAND_5GHZ:
  3447. break;
  3448. default:
  3449. return false;
  3450. }
  3451. if (mask->control[band].legacy != legacy)
  3452. return false;
  3453. for (i = 0; i < nrf; i++)
  3454. if (mask->control[band].ht_mcs[i] != ht)
  3455. return false;
  3456. for (i = 0; i < nrf; i++)
  3457. if (mask->control[band].vht_mcs[i] != vht)
  3458. return false;
  3459. return true;
  3460. }
  3461. static bool
  3462. ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
  3463. enum ieee80211_band band,
  3464. u8 *fixed_nss)
  3465. {
  3466. int ht_nss = 0, vht_nss = 0, i;
  3467. /* check legacy */
  3468. if (ath10k_check_single_mask(mask->control[band].legacy))
  3469. return false;
  3470. /* check HT */
  3471. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
  3472. if (mask->control[band].ht_mcs[i] == 0xff)
  3473. continue;
  3474. else if (mask->control[band].ht_mcs[i] == 0x00)
  3475. break;
  3476. return false;
  3477. }
  3478. ht_nss = i;
  3479. /* check VHT */
  3480. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  3481. if (mask->control[band].vht_mcs[i] == 0x03ff)
  3482. continue;
  3483. else if (mask->control[band].vht_mcs[i] == 0x0000)
  3484. break;
  3485. return false;
  3486. }
  3487. vht_nss = i;
  3488. if (ht_nss > 0 && vht_nss > 0)
  3489. return false;
  3490. if (ht_nss)
  3491. *fixed_nss = ht_nss;
  3492. else if (vht_nss)
  3493. *fixed_nss = vht_nss;
  3494. else
  3495. return false;
  3496. return true;
  3497. }
  3498. static bool
  3499. ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
  3500. enum ieee80211_band band,
  3501. enum wmi_rate_preamble *preamble)
  3502. {
  3503. int legacy = 0, ht = 0, vht = 0, i;
  3504. *preamble = WMI_RATE_PREAMBLE_OFDM;
  3505. /* check legacy */
  3506. legacy = ath10k_check_single_mask(mask->control[band].legacy);
  3507. if (legacy > 1)
  3508. return false;
  3509. /* check HT */
  3510. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  3511. ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
  3512. if (ht > 1)
  3513. return false;
  3514. /* check VHT */
  3515. for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
  3516. vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
  3517. if (vht > 1)
  3518. return false;
  3519. /* Currently we support only one fixed_rate */
  3520. if ((legacy + ht + vht) != 1)
  3521. return false;
  3522. if (ht)
  3523. *preamble = WMI_RATE_PREAMBLE_HT;
  3524. else if (vht)
  3525. *preamble = WMI_RATE_PREAMBLE_VHT;
  3526. return true;
  3527. }
  3528. static bool
  3529. ath10k_bitrate_mask_rate(struct ath10k *ar,
  3530. const struct cfg80211_bitrate_mask *mask,
  3531. enum ieee80211_band band,
  3532. u8 *fixed_rate,
  3533. u8 *fixed_nss)
  3534. {
  3535. u8 rate = 0, pream = 0, nss = 0, i;
  3536. enum wmi_rate_preamble preamble;
  3537. /* Check if single rate correct */
  3538. if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
  3539. return false;
  3540. pream = preamble;
  3541. switch (preamble) {
  3542. case WMI_RATE_PREAMBLE_CCK:
  3543. case WMI_RATE_PREAMBLE_OFDM:
  3544. i = ffs(mask->control[band].legacy) - 1;
  3545. if (band == IEEE80211_BAND_2GHZ && i < 4)
  3546. pream = WMI_RATE_PREAMBLE_CCK;
  3547. if (band == IEEE80211_BAND_5GHZ)
  3548. i += 4;
  3549. if (i >= ARRAY_SIZE(cck_ofdm_rate))
  3550. return false;
  3551. rate = cck_ofdm_rate[i];
  3552. break;
  3553. case WMI_RATE_PREAMBLE_HT:
  3554. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  3555. if (mask->control[band].ht_mcs[i])
  3556. break;
  3557. if (i == IEEE80211_HT_MCS_MASK_LEN)
  3558. return false;
  3559. rate = ffs(mask->control[band].ht_mcs[i]) - 1;
  3560. nss = i;
  3561. break;
  3562. case WMI_RATE_PREAMBLE_VHT:
  3563. for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
  3564. if (mask->control[band].vht_mcs[i])
  3565. break;
  3566. if (i == NL80211_VHT_NSS_MAX)
  3567. return false;
  3568. rate = ffs(mask->control[band].vht_mcs[i]) - 1;
  3569. nss = i;
  3570. break;
  3571. }
  3572. *fixed_nss = nss + 1;
  3573. nss <<= 4;
  3574. pream <<= 6;
  3575. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
  3576. pream, nss, rate);
  3577. *fixed_rate = pream | nss | rate;
  3578. return true;
  3579. }
  3580. static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
  3581. const struct cfg80211_bitrate_mask *mask,
  3582. enum ieee80211_band band,
  3583. u8 *fixed_rate,
  3584. u8 *fixed_nss)
  3585. {
  3586. /* First check full NSS mask, if we can simply limit NSS */
  3587. if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
  3588. return true;
  3589. /* Next Check single rate is set */
  3590. return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
  3591. }
  3592. static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
  3593. u8 fixed_rate,
  3594. u8 fixed_nss,
  3595. u8 force_sgi)
  3596. {
  3597. struct ath10k *ar = arvif->ar;
  3598. u32 vdev_param;
  3599. int ret = 0;
  3600. mutex_lock(&ar->conf_mutex);
  3601. if (arvif->fixed_rate == fixed_rate &&
  3602. arvif->fixed_nss == fixed_nss &&
  3603. arvif->force_sgi == force_sgi)
  3604. goto exit;
  3605. if (fixed_rate == WMI_FIXED_RATE_NONE)
  3606. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
  3607. if (force_sgi)
  3608. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
  3609. vdev_param = ar->wmi.vdev_param->fixed_rate;
  3610. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  3611. vdev_param, fixed_rate);
  3612. if (ret) {
  3613. ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
  3614. fixed_rate, ret);
  3615. ret = -EINVAL;
  3616. goto exit;
  3617. }
  3618. arvif->fixed_rate = fixed_rate;
  3619. vdev_param = ar->wmi.vdev_param->nss;
  3620. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  3621. vdev_param, fixed_nss);
  3622. if (ret) {
  3623. ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
  3624. fixed_nss, ret);
  3625. ret = -EINVAL;
  3626. goto exit;
  3627. }
  3628. arvif->fixed_nss = fixed_nss;
  3629. vdev_param = ar->wmi.vdev_param->sgi;
  3630. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  3631. force_sgi);
  3632. if (ret) {
  3633. ath10k_warn(ar, "failed to set sgi param %d: %d\n",
  3634. force_sgi, ret);
  3635. ret = -EINVAL;
  3636. goto exit;
  3637. }
  3638. arvif->force_sgi = force_sgi;
  3639. exit:
  3640. mutex_unlock(&ar->conf_mutex);
  3641. return ret;
  3642. }
  3643. static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
  3644. struct ieee80211_vif *vif,
  3645. const struct cfg80211_bitrate_mask *mask)
  3646. {
  3647. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3648. struct ath10k *ar = arvif->ar;
  3649. enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
  3650. u8 fixed_rate = WMI_FIXED_RATE_NONE;
  3651. u8 fixed_nss = ar->num_rf_chains;
  3652. u8 force_sgi;
  3653. if (ar->cfg_tx_chainmask)
  3654. fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
  3655. force_sgi = mask->control[band].gi;
  3656. if (force_sgi == NL80211_TXRATE_FORCE_LGI)
  3657. return -EINVAL;
  3658. if (!ath10k_default_bitrate_mask(ar, band, mask)) {
  3659. if (!ath10k_get_fixed_rate_nss(ar, mask, band,
  3660. &fixed_rate,
  3661. &fixed_nss))
  3662. return -EINVAL;
  3663. }
  3664. if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
  3665. ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
  3666. return -EINVAL;
  3667. }
  3668. return ath10k_set_fixed_rate_param(arvif, fixed_rate,
  3669. fixed_nss, force_sgi);
  3670. }
  3671. static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
  3672. struct ieee80211_vif *vif,
  3673. struct ieee80211_sta *sta,
  3674. u32 changed)
  3675. {
  3676. struct ath10k *ar = hw->priv;
  3677. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  3678. u32 bw, smps;
  3679. spin_lock_bh(&ar->data_lock);
  3680. ath10k_dbg(ar, ATH10K_DBG_MAC,
  3681. "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
  3682. sta->addr, changed, sta->bandwidth, sta->rx_nss,
  3683. sta->smps_mode);
  3684. if (changed & IEEE80211_RC_BW_CHANGED) {
  3685. bw = WMI_PEER_CHWIDTH_20MHZ;
  3686. switch (sta->bandwidth) {
  3687. case IEEE80211_STA_RX_BW_20:
  3688. bw = WMI_PEER_CHWIDTH_20MHZ;
  3689. break;
  3690. case IEEE80211_STA_RX_BW_40:
  3691. bw = WMI_PEER_CHWIDTH_40MHZ;
  3692. break;
  3693. case IEEE80211_STA_RX_BW_80:
  3694. bw = WMI_PEER_CHWIDTH_80MHZ;
  3695. break;
  3696. case IEEE80211_STA_RX_BW_160:
  3697. ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
  3698. sta->bandwidth, sta->addr);
  3699. bw = WMI_PEER_CHWIDTH_20MHZ;
  3700. break;
  3701. }
  3702. arsta->bw = bw;
  3703. }
  3704. if (changed & IEEE80211_RC_NSS_CHANGED)
  3705. arsta->nss = sta->rx_nss;
  3706. if (changed & IEEE80211_RC_SMPS_CHANGED) {
  3707. smps = WMI_PEER_SMPS_PS_NONE;
  3708. switch (sta->smps_mode) {
  3709. case IEEE80211_SMPS_AUTOMATIC:
  3710. case IEEE80211_SMPS_OFF:
  3711. smps = WMI_PEER_SMPS_PS_NONE;
  3712. break;
  3713. case IEEE80211_SMPS_STATIC:
  3714. smps = WMI_PEER_SMPS_STATIC;
  3715. break;
  3716. case IEEE80211_SMPS_DYNAMIC:
  3717. smps = WMI_PEER_SMPS_DYNAMIC;
  3718. break;
  3719. case IEEE80211_SMPS_NUM_MODES:
  3720. ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
  3721. sta->smps_mode, sta->addr);
  3722. smps = WMI_PEER_SMPS_PS_NONE;
  3723. break;
  3724. }
  3725. arsta->smps = smps;
  3726. }
  3727. arsta->changed |= changed;
  3728. spin_unlock_bh(&ar->data_lock);
  3729. ieee80211_queue_work(hw, &arsta->update_wk);
  3730. }
  3731. static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  3732. {
  3733. /*
  3734. * FIXME: Return 0 for time being. Need to figure out whether FW
  3735. * has the API to fetch 64-bit local TSF
  3736. */
  3737. return 0;
  3738. }
  3739. static int ath10k_ampdu_action(struct ieee80211_hw *hw,
  3740. struct ieee80211_vif *vif,
  3741. enum ieee80211_ampdu_mlme_action action,
  3742. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  3743. u8 buf_size)
  3744. {
  3745. struct ath10k *ar = hw->priv;
  3746. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3747. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
  3748. arvif->vdev_id, sta->addr, tid, action);
  3749. switch (action) {
  3750. case IEEE80211_AMPDU_RX_START:
  3751. case IEEE80211_AMPDU_RX_STOP:
  3752. /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
  3753. * creation/removal. Do we need to verify this?
  3754. */
  3755. return 0;
  3756. case IEEE80211_AMPDU_TX_START:
  3757. case IEEE80211_AMPDU_TX_STOP_CONT:
  3758. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  3759. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  3760. case IEEE80211_AMPDU_TX_OPERATIONAL:
  3761. /* Firmware offloads Tx aggregation entirely so deny mac80211
  3762. * Tx aggregation requests.
  3763. */
  3764. return -EOPNOTSUPP;
  3765. }
  3766. return -EINVAL;
  3767. }
  3768. static const struct ieee80211_ops ath10k_ops = {
  3769. .tx = ath10k_tx,
  3770. .start = ath10k_start,
  3771. .stop = ath10k_stop,
  3772. .config = ath10k_config,
  3773. .add_interface = ath10k_add_interface,
  3774. .remove_interface = ath10k_remove_interface,
  3775. .configure_filter = ath10k_configure_filter,
  3776. .bss_info_changed = ath10k_bss_info_changed,
  3777. .hw_scan = ath10k_hw_scan,
  3778. .cancel_hw_scan = ath10k_cancel_hw_scan,
  3779. .set_key = ath10k_set_key,
  3780. .sta_state = ath10k_sta_state,
  3781. .conf_tx = ath10k_conf_tx,
  3782. .remain_on_channel = ath10k_remain_on_channel,
  3783. .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
  3784. .set_rts_threshold = ath10k_set_rts_threshold,
  3785. .set_frag_threshold = ath10k_set_frag_threshold,
  3786. .flush = ath10k_flush,
  3787. .tx_last_beacon = ath10k_tx_last_beacon,
  3788. .set_antenna = ath10k_set_antenna,
  3789. .get_antenna = ath10k_get_antenna,
  3790. .reconfig_complete = ath10k_reconfig_complete,
  3791. .get_survey = ath10k_get_survey,
  3792. .set_bitrate_mask = ath10k_set_bitrate_mask,
  3793. .sta_rc_update = ath10k_sta_rc_update,
  3794. .get_tsf = ath10k_get_tsf,
  3795. .ampdu_action = ath10k_ampdu_action,
  3796. .get_et_sset_count = ath10k_debug_get_et_sset_count,
  3797. .get_et_stats = ath10k_debug_get_et_stats,
  3798. .get_et_strings = ath10k_debug_get_et_strings,
  3799. CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
  3800. #ifdef CONFIG_PM
  3801. .suspend = ath10k_suspend,
  3802. .resume = ath10k_resume,
  3803. #endif
  3804. };
  3805. #define RATETAB_ENT(_rate, _rateid, _flags) { \
  3806. .bitrate = (_rate), \
  3807. .flags = (_flags), \
  3808. .hw_value = (_rateid), \
  3809. }
  3810. #define CHAN2G(_channel, _freq, _flags) { \
  3811. .band = IEEE80211_BAND_2GHZ, \
  3812. .hw_value = (_channel), \
  3813. .center_freq = (_freq), \
  3814. .flags = (_flags), \
  3815. .max_antenna_gain = 0, \
  3816. .max_power = 30, \
  3817. }
  3818. #define CHAN5G(_channel, _freq, _flags) { \
  3819. .band = IEEE80211_BAND_5GHZ, \
  3820. .hw_value = (_channel), \
  3821. .center_freq = (_freq), \
  3822. .flags = (_flags), \
  3823. .max_antenna_gain = 0, \
  3824. .max_power = 30, \
  3825. }
  3826. static const struct ieee80211_channel ath10k_2ghz_channels[] = {
  3827. CHAN2G(1, 2412, 0),
  3828. CHAN2G(2, 2417, 0),
  3829. CHAN2G(3, 2422, 0),
  3830. CHAN2G(4, 2427, 0),
  3831. CHAN2G(5, 2432, 0),
  3832. CHAN2G(6, 2437, 0),
  3833. CHAN2G(7, 2442, 0),
  3834. CHAN2G(8, 2447, 0),
  3835. CHAN2G(9, 2452, 0),
  3836. CHAN2G(10, 2457, 0),
  3837. CHAN2G(11, 2462, 0),
  3838. CHAN2G(12, 2467, 0),
  3839. CHAN2G(13, 2472, 0),
  3840. CHAN2G(14, 2484, 0),
  3841. };
  3842. static const struct ieee80211_channel ath10k_5ghz_channels[] = {
  3843. CHAN5G(36, 5180, 0),
  3844. CHAN5G(40, 5200, 0),
  3845. CHAN5G(44, 5220, 0),
  3846. CHAN5G(48, 5240, 0),
  3847. CHAN5G(52, 5260, 0),
  3848. CHAN5G(56, 5280, 0),
  3849. CHAN5G(60, 5300, 0),
  3850. CHAN5G(64, 5320, 0),
  3851. CHAN5G(100, 5500, 0),
  3852. CHAN5G(104, 5520, 0),
  3853. CHAN5G(108, 5540, 0),
  3854. CHAN5G(112, 5560, 0),
  3855. CHAN5G(116, 5580, 0),
  3856. CHAN5G(120, 5600, 0),
  3857. CHAN5G(124, 5620, 0),
  3858. CHAN5G(128, 5640, 0),
  3859. CHAN5G(132, 5660, 0),
  3860. CHAN5G(136, 5680, 0),
  3861. CHAN5G(140, 5700, 0),
  3862. CHAN5G(149, 5745, 0),
  3863. CHAN5G(153, 5765, 0),
  3864. CHAN5G(157, 5785, 0),
  3865. CHAN5G(161, 5805, 0),
  3866. CHAN5G(165, 5825, 0),
  3867. };
  3868. static struct ieee80211_rate ath10k_rates[] = {
  3869. /* CCK */
  3870. RATETAB_ENT(10, 0x82, 0),
  3871. RATETAB_ENT(20, 0x84, 0),
  3872. RATETAB_ENT(55, 0x8b, 0),
  3873. RATETAB_ENT(110, 0x96, 0),
  3874. /* OFDM */
  3875. RATETAB_ENT(60, 0x0c, 0),
  3876. RATETAB_ENT(90, 0x12, 0),
  3877. RATETAB_ENT(120, 0x18, 0),
  3878. RATETAB_ENT(180, 0x24, 0),
  3879. RATETAB_ENT(240, 0x30, 0),
  3880. RATETAB_ENT(360, 0x48, 0),
  3881. RATETAB_ENT(480, 0x60, 0),
  3882. RATETAB_ENT(540, 0x6c, 0),
  3883. };
  3884. #define ath10k_a_rates (ath10k_rates + 4)
  3885. #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
  3886. #define ath10k_g_rates (ath10k_rates + 0)
  3887. #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
  3888. struct ath10k *ath10k_mac_create(size_t priv_size)
  3889. {
  3890. struct ieee80211_hw *hw;
  3891. struct ath10k *ar;
  3892. hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
  3893. if (!hw)
  3894. return NULL;
  3895. ar = hw->priv;
  3896. ar->hw = hw;
  3897. return ar;
  3898. }
  3899. void ath10k_mac_destroy(struct ath10k *ar)
  3900. {
  3901. ieee80211_free_hw(ar->hw);
  3902. }
  3903. static const struct ieee80211_iface_limit ath10k_if_limits[] = {
  3904. {
  3905. .max = 8,
  3906. .types = BIT(NL80211_IFTYPE_STATION)
  3907. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  3908. },
  3909. {
  3910. .max = 3,
  3911. .types = BIT(NL80211_IFTYPE_P2P_GO)
  3912. },
  3913. {
  3914. .max = 7,
  3915. .types = BIT(NL80211_IFTYPE_AP)
  3916. },
  3917. };
  3918. static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
  3919. {
  3920. .max = 8,
  3921. .types = BIT(NL80211_IFTYPE_AP)
  3922. },
  3923. };
  3924. static const struct ieee80211_iface_combination ath10k_if_comb[] = {
  3925. {
  3926. .limits = ath10k_if_limits,
  3927. .n_limits = ARRAY_SIZE(ath10k_if_limits),
  3928. .max_interfaces = 8,
  3929. .num_different_channels = 1,
  3930. .beacon_int_infra_match = true,
  3931. },
  3932. };
  3933. static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
  3934. {
  3935. .limits = ath10k_10x_if_limits,
  3936. .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
  3937. .max_interfaces = 8,
  3938. .num_different_channels = 1,
  3939. .beacon_int_infra_match = true,
  3940. #ifdef CONFIG_ATH10K_DFS_CERTIFIED
  3941. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  3942. BIT(NL80211_CHAN_WIDTH_20) |
  3943. BIT(NL80211_CHAN_WIDTH_40) |
  3944. BIT(NL80211_CHAN_WIDTH_80),
  3945. #endif
  3946. },
  3947. };
  3948. static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
  3949. {
  3950. struct ieee80211_sta_vht_cap vht_cap = {0};
  3951. u16 mcs_map;
  3952. int i;
  3953. vht_cap.vht_supported = 1;
  3954. vht_cap.cap = ar->vht_cap_info;
  3955. mcs_map = 0;
  3956. for (i = 0; i < 8; i++) {
  3957. if (i < ar->num_rf_chains)
  3958. mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
  3959. else
  3960. mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
  3961. }
  3962. vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  3963. vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  3964. return vht_cap;
  3965. }
  3966. static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
  3967. {
  3968. int i;
  3969. struct ieee80211_sta_ht_cap ht_cap = {0};
  3970. if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
  3971. return ht_cap;
  3972. ht_cap.ht_supported = 1;
  3973. ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  3974. ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  3975. ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  3976. ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
  3977. ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
  3978. if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
  3979. ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  3980. if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
  3981. ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  3982. if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
  3983. u32 smps;
  3984. smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
  3985. smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
  3986. ht_cap.cap |= smps;
  3987. }
  3988. if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
  3989. ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  3990. if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
  3991. u32 stbc;
  3992. stbc = ar->ht_cap_info;
  3993. stbc &= WMI_HT_CAP_RX_STBC;
  3994. stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
  3995. stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
  3996. stbc &= IEEE80211_HT_CAP_RX_STBC;
  3997. ht_cap.cap |= stbc;
  3998. }
  3999. if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
  4000. ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
  4001. if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
  4002. ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
  4003. /* max AMSDU is implicitly taken from vht_cap_info */
  4004. if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
  4005. ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  4006. for (i = 0; i < ar->num_rf_chains; i++)
  4007. ht_cap.mcs.rx_mask[i] = 0xFF;
  4008. ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  4009. return ht_cap;
  4010. }
  4011. static void ath10k_get_arvif_iter(void *data, u8 *mac,
  4012. struct ieee80211_vif *vif)
  4013. {
  4014. struct ath10k_vif_iter *arvif_iter = data;
  4015. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  4016. if (arvif->vdev_id == arvif_iter->vdev_id)
  4017. arvif_iter->arvif = arvif;
  4018. }
  4019. struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
  4020. {
  4021. struct ath10k_vif_iter arvif_iter;
  4022. u32 flags;
  4023. memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
  4024. arvif_iter.vdev_id = vdev_id;
  4025. flags = IEEE80211_IFACE_ITER_RESUME_ALL;
  4026. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  4027. flags,
  4028. ath10k_get_arvif_iter,
  4029. &arvif_iter);
  4030. if (!arvif_iter.arvif) {
  4031. ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
  4032. return NULL;
  4033. }
  4034. return arvif_iter.arvif;
  4035. }
  4036. int ath10k_mac_register(struct ath10k *ar)
  4037. {
  4038. struct ieee80211_supported_band *band;
  4039. struct ieee80211_sta_vht_cap vht_cap;
  4040. struct ieee80211_sta_ht_cap ht_cap;
  4041. void *channels;
  4042. int ret;
  4043. SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
  4044. SET_IEEE80211_DEV(ar->hw, ar->dev);
  4045. ht_cap = ath10k_get_ht_cap(ar);
  4046. vht_cap = ath10k_create_vht_cap(ar);
  4047. if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
  4048. channels = kmemdup(ath10k_2ghz_channels,
  4049. sizeof(ath10k_2ghz_channels),
  4050. GFP_KERNEL);
  4051. if (!channels) {
  4052. ret = -ENOMEM;
  4053. goto err_free;
  4054. }
  4055. band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
  4056. band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
  4057. band->channels = channels;
  4058. band->n_bitrates = ath10k_g_rates_size;
  4059. band->bitrates = ath10k_g_rates;
  4060. band->ht_cap = ht_cap;
  4061. /* vht is not supported in 2.4 GHz */
  4062. ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
  4063. }
  4064. if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
  4065. channels = kmemdup(ath10k_5ghz_channels,
  4066. sizeof(ath10k_5ghz_channels),
  4067. GFP_KERNEL);
  4068. if (!channels) {
  4069. ret = -ENOMEM;
  4070. goto err_free;
  4071. }
  4072. band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
  4073. band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
  4074. band->channels = channels;
  4075. band->n_bitrates = ath10k_a_rates_size;
  4076. band->bitrates = ath10k_a_rates;
  4077. band->ht_cap = ht_cap;
  4078. band->vht_cap = vht_cap;
  4079. ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
  4080. }
  4081. ar->hw->wiphy->interface_modes =
  4082. BIT(NL80211_IFTYPE_STATION) |
  4083. BIT(NL80211_IFTYPE_AP);
  4084. ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
  4085. ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
  4086. if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
  4087. ar->hw->wiphy->interface_modes |=
  4088. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  4089. BIT(NL80211_IFTYPE_P2P_GO);
  4090. ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  4091. IEEE80211_HW_SUPPORTS_PS |
  4092. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  4093. IEEE80211_HW_SUPPORTS_UAPSD |
  4094. IEEE80211_HW_MFP_CAPABLE |
  4095. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  4096. IEEE80211_HW_HAS_RATE_CONTROL |
  4097. IEEE80211_HW_AP_LINK_PS |
  4098. IEEE80211_HW_SPECTRUM_MGMT;
  4099. ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
  4100. if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
  4101. ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
  4102. if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
  4103. ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  4104. ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
  4105. }
  4106. ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
  4107. ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
  4108. ar->hw->vif_data_size = sizeof(struct ath10k_vif);
  4109. ar->hw->sta_data_size = sizeof(struct ath10k_sta);
  4110. ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
  4111. ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  4112. ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  4113. ar->hw->wiphy->max_remain_on_channel_duration = 5000;
  4114. ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  4115. ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
  4116. /*
  4117. * on LL hardware queues are managed entirely by the FW
  4118. * so we only advertise to mac we can do the queues thing
  4119. */
  4120. ar->hw->queues = 4;
  4121. if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
  4122. ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
  4123. ar->hw->wiphy->n_iface_combinations =
  4124. ARRAY_SIZE(ath10k_10x_if_comb);
  4125. } else {
  4126. ar->hw->wiphy->iface_combinations = ath10k_if_comb;
  4127. ar->hw->wiphy->n_iface_combinations =
  4128. ARRAY_SIZE(ath10k_if_comb);
  4129. ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
  4130. }
  4131. ar->hw->netdev_features = NETIF_F_HW_CSUM;
  4132. if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
  4133. /* Init ath dfs pattern detector */
  4134. ar->ath_common.debug_mask = ATH_DBG_DFS;
  4135. ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
  4136. NL80211_DFS_UNSET);
  4137. if (!ar->dfs_detector)
  4138. ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
  4139. }
  4140. ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
  4141. ath10k_reg_notifier);
  4142. if (ret) {
  4143. ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
  4144. goto err_free;
  4145. }
  4146. ret = ieee80211_register_hw(ar->hw);
  4147. if (ret) {
  4148. ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
  4149. goto err_free;
  4150. }
  4151. if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
  4152. ret = regulatory_hint(ar->hw->wiphy,
  4153. ar->ath_common.regulatory.alpha2);
  4154. if (ret)
  4155. goto err_unregister;
  4156. }
  4157. return 0;
  4158. err_unregister:
  4159. ieee80211_unregister_hw(ar->hw);
  4160. err_free:
  4161. kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
  4162. kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
  4163. return ret;
  4164. }
  4165. void ath10k_mac_unregister(struct ath10k *ar)
  4166. {
  4167. ieee80211_unregister_hw(ar->hw);
  4168. if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
  4169. ar->dfs_detector->exit(ar->dfs_detector);
  4170. kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
  4171. kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
  4172. SET_IEEE80211_DEV(ar->hw, NULL);
  4173. }