mac.c 125 KB

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