mac.c 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131
  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. mutex_lock(&ar->conf_mutex);
  2321. memset(arvif, 0, sizeof(*arvif));
  2322. arvif->ar = ar;
  2323. arvif->vif = vif;
  2324. INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
  2325. INIT_LIST_HEAD(&arvif->list);
  2326. if (ar->free_vdev_map == 0) {
  2327. ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
  2328. ret = -EBUSY;
  2329. goto err;
  2330. }
  2331. bit = __ffs64(ar->free_vdev_map);
  2332. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
  2333. bit, ar->free_vdev_map);
  2334. arvif->vdev_id = bit;
  2335. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
  2336. if (ar->p2p)
  2337. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
  2338. switch (vif->type) {
  2339. case NL80211_IFTYPE_UNSPECIFIED:
  2340. case NL80211_IFTYPE_STATION:
  2341. arvif->vdev_type = WMI_VDEV_TYPE_STA;
  2342. if (vif->p2p)
  2343. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
  2344. break;
  2345. case NL80211_IFTYPE_ADHOC:
  2346. arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
  2347. break;
  2348. case NL80211_IFTYPE_AP:
  2349. arvif->vdev_type = WMI_VDEV_TYPE_AP;
  2350. if (vif->p2p)
  2351. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
  2352. break;
  2353. case NL80211_IFTYPE_MONITOR:
  2354. arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
  2355. break;
  2356. default:
  2357. WARN_ON(1);
  2358. break;
  2359. }
  2360. /* Some firmware revisions don't wait for beacon tx completion before
  2361. * sending another SWBA event. This could lead to hardware using old
  2362. * (freed) beacon data in some cases, e.g. tx credit starvation
  2363. * combined with missed TBTT. This is very very rare.
  2364. *
  2365. * On non-IOMMU-enabled hosts this could be a possible security issue
  2366. * because hw could beacon some random data on the air. On
  2367. * IOMMU-enabled hosts DMAR faults would occur in most cases and target
  2368. * device would crash.
  2369. *
  2370. * Since there are no beacon tx completions (implicit nor explicit)
  2371. * propagated to host the only workaround for this is to allocate a
  2372. * DMA-coherent buffer for a lifetime of a vif and use it for all
  2373. * beacon tx commands. Worst case for this approach is some beacons may
  2374. * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
  2375. */
  2376. if (vif->type == NL80211_IFTYPE_ADHOC ||
  2377. vif->type == NL80211_IFTYPE_AP) {
  2378. arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
  2379. IEEE80211_MAX_FRAME_LEN,
  2380. &arvif->beacon_paddr,
  2381. GFP_ATOMIC);
  2382. if (!arvif->beacon_buf) {
  2383. ret = -ENOMEM;
  2384. ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
  2385. ret);
  2386. goto err;
  2387. }
  2388. }
  2389. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
  2390. arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
  2391. arvif->beacon_buf ? "single-buf" : "per-skb");
  2392. ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
  2393. arvif->vdev_subtype, vif->addr);
  2394. if (ret) {
  2395. ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
  2396. arvif->vdev_id, ret);
  2397. goto err;
  2398. }
  2399. ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
  2400. list_add(&arvif->list, &ar->arvifs);
  2401. vdev_param = ar->wmi.vdev_param->def_keyid;
  2402. ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
  2403. arvif->def_wep_key_idx);
  2404. if (ret) {
  2405. ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
  2406. arvif->vdev_id, ret);
  2407. goto err_vdev_delete;
  2408. }
  2409. vdev_param = ar->wmi.vdev_param->tx_encap_type;
  2410. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2411. ATH10K_HW_TXRX_NATIVE_WIFI);
  2412. /* 10.X firmware does not support this VDEV parameter. Do not warn */
  2413. if (ret && ret != -EOPNOTSUPP) {
  2414. ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
  2415. arvif->vdev_id, ret);
  2416. goto err_vdev_delete;
  2417. }
  2418. if (ar->cfg_tx_chainmask) {
  2419. u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
  2420. vdev_param = ar->wmi.vdev_param->nss;
  2421. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2422. nss);
  2423. if (ret) {
  2424. ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
  2425. arvif->vdev_id, ar->cfg_tx_chainmask, nss,
  2426. ret);
  2427. goto err_vdev_delete;
  2428. }
  2429. }
  2430. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  2431. ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
  2432. if (ret) {
  2433. ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
  2434. arvif->vdev_id, ret);
  2435. goto err_vdev_delete;
  2436. }
  2437. ret = ath10k_mac_set_kickout(arvif);
  2438. if (ret) {
  2439. ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
  2440. arvif->vdev_id, ret);
  2441. goto err_peer_delete;
  2442. }
  2443. }
  2444. if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
  2445. param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
  2446. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  2447. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  2448. param, value);
  2449. if (ret) {
  2450. ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
  2451. arvif->vdev_id, ret);
  2452. goto err_peer_delete;
  2453. }
  2454. param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
  2455. value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
  2456. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  2457. param, value);
  2458. if (ret) {
  2459. ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
  2460. arvif->vdev_id, ret);
  2461. goto err_peer_delete;
  2462. }
  2463. param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
  2464. value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
  2465. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  2466. param, value);
  2467. if (ret) {
  2468. ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
  2469. arvif->vdev_id, ret);
  2470. goto err_peer_delete;
  2471. }
  2472. }
  2473. ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
  2474. if (ret) {
  2475. ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
  2476. arvif->vdev_id, ret);
  2477. goto err_peer_delete;
  2478. }
  2479. ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
  2480. if (ret) {
  2481. ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
  2482. arvif->vdev_id, ret);
  2483. goto err_peer_delete;
  2484. }
  2485. arvif->txpower = vif->bss_conf.txpower;
  2486. ret = ath10k_mac_txpower_recalc(ar);
  2487. if (ret) {
  2488. ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
  2489. goto err_peer_delete;
  2490. }
  2491. mutex_unlock(&ar->conf_mutex);
  2492. return 0;
  2493. err_peer_delete:
  2494. if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
  2495. ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
  2496. err_vdev_delete:
  2497. ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
  2498. ar->free_vdev_map |= 1LL << arvif->vdev_id;
  2499. list_del(&arvif->list);
  2500. err:
  2501. if (arvif->beacon_buf) {
  2502. dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
  2503. arvif->beacon_buf, arvif->beacon_paddr);
  2504. arvif->beacon_buf = NULL;
  2505. }
  2506. mutex_unlock(&ar->conf_mutex);
  2507. return ret;
  2508. }
  2509. static void ath10k_remove_interface(struct ieee80211_hw *hw,
  2510. struct ieee80211_vif *vif)
  2511. {
  2512. struct ath10k *ar = hw->priv;
  2513. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2514. int ret;
  2515. cancel_work_sync(&arvif->wep_key_work);
  2516. mutex_lock(&ar->conf_mutex);
  2517. spin_lock_bh(&ar->data_lock);
  2518. ath10k_mac_vif_beacon_cleanup(arvif);
  2519. spin_unlock_bh(&ar->data_lock);
  2520. ret = ath10k_spectral_vif_stop(arvif);
  2521. if (ret)
  2522. ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
  2523. arvif->vdev_id, ret);
  2524. ar->free_vdev_map |= 1LL << arvif->vdev_id;
  2525. list_del(&arvif->list);
  2526. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  2527. ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
  2528. if (ret)
  2529. ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
  2530. arvif->vdev_id, ret);
  2531. kfree(arvif->u.ap.noa_data);
  2532. }
  2533. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
  2534. arvif->vdev_id);
  2535. ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
  2536. if (ret)
  2537. ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
  2538. arvif->vdev_id, ret);
  2539. ath10k_peer_cleanup(ar, arvif->vdev_id);
  2540. mutex_unlock(&ar->conf_mutex);
  2541. }
  2542. /*
  2543. * FIXME: Has to be verified.
  2544. */
  2545. #define SUPPORTED_FILTERS \
  2546. (FIF_PROMISC_IN_BSS | \
  2547. FIF_ALLMULTI | \
  2548. FIF_CONTROL | \
  2549. FIF_PSPOLL | \
  2550. FIF_OTHER_BSS | \
  2551. FIF_BCN_PRBRESP_PROMISC | \
  2552. FIF_PROBE_REQ | \
  2553. FIF_FCSFAIL)
  2554. static void ath10k_configure_filter(struct ieee80211_hw *hw,
  2555. unsigned int changed_flags,
  2556. unsigned int *total_flags,
  2557. u64 multicast)
  2558. {
  2559. struct ath10k *ar = hw->priv;
  2560. int ret;
  2561. mutex_lock(&ar->conf_mutex);
  2562. changed_flags &= SUPPORTED_FILTERS;
  2563. *total_flags &= SUPPORTED_FILTERS;
  2564. ar->filter_flags = *total_flags;
  2565. ret = ath10k_monitor_recalc(ar);
  2566. if (ret)
  2567. ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
  2568. mutex_unlock(&ar->conf_mutex);
  2569. }
  2570. static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
  2571. struct ieee80211_vif *vif,
  2572. struct ieee80211_bss_conf *info,
  2573. u32 changed)
  2574. {
  2575. struct ath10k *ar = hw->priv;
  2576. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2577. int ret = 0;
  2578. u32 vdev_param, pdev_param, slottime, preamble;
  2579. mutex_lock(&ar->conf_mutex);
  2580. if (changed & BSS_CHANGED_IBSS)
  2581. ath10k_control_ibss(arvif, info, vif->addr);
  2582. if (changed & BSS_CHANGED_BEACON_INT) {
  2583. arvif->beacon_interval = info->beacon_int;
  2584. vdev_param = ar->wmi.vdev_param->beacon_interval;
  2585. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2586. arvif->beacon_interval);
  2587. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2588. "mac vdev %d beacon_interval %d\n",
  2589. arvif->vdev_id, arvif->beacon_interval);
  2590. if (ret)
  2591. ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
  2592. arvif->vdev_id, ret);
  2593. }
  2594. if (changed & BSS_CHANGED_BEACON) {
  2595. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2596. "vdev %d set beacon tx mode to staggered\n",
  2597. arvif->vdev_id);
  2598. pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
  2599. ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
  2600. WMI_BEACON_STAGGERED_MODE);
  2601. if (ret)
  2602. ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
  2603. arvif->vdev_id, ret);
  2604. }
  2605. if (changed & BSS_CHANGED_BEACON_INFO) {
  2606. arvif->dtim_period = info->dtim_period;
  2607. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2608. "mac vdev %d dtim_period %d\n",
  2609. arvif->vdev_id, arvif->dtim_period);
  2610. vdev_param = ar->wmi.vdev_param->dtim_period;
  2611. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2612. arvif->dtim_period);
  2613. if (ret)
  2614. ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
  2615. arvif->vdev_id, ret);
  2616. }
  2617. if (changed & BSS_CHANGED_SSID &&
  2618. vif->type == NL80211_IFTYPE_AP) {
  2619. arvif->u.ap.ssid_len = info->ssid_len;
  2620. if (info->ssid_len)
  2621. memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
  2622. arvif->u.ap.hidden_ssid = info->hidden_ssid;
  2623. }
  2624. if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
  2625. ether_addr_copy(arvif->bssid, info->bssid);
  2626. if (changed & BSS_CHANGED_BEACON_ENABLED)
  2627. ath10k_control_beaconing(arvif, info);
  2628. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  2629. arvif->use_cts_prot = info->use_cts_prot;
  2630. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
  2631. arvif->vdev_id, info->use_cts_prot);
  2632. ret = ath10k_recalc_rtscts_prot(arvif);
  2633. if (ret)
  2634. ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
  2635. arvif->vdev_id, ret);
  2636. }
  2637. if (changed & BSS_CHANGED_ERP_SLOT) {
  2638. if (info->use_short_slot)
  2639. slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
  2640. else
  2641. slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
  2642. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
  2643. arvif->vdev_id, slottime);
  2644. vdev_param = ar->wmi.vdev_param->slot_time;
  2645. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2646. slottime);
  2647. if (ret)
  2648. ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
  2649. arvif->vdev_id, ret);
  2650. }
  2651. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  2652. if (info->use_short_preamble)
  2653. preamble = WMI_VDEV_PREAMBLE_SHORT;
  2654. else
  2655. preamble = WMI_VDEV_PREAMBLE_LONG;
  2656. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2657. "mac vdev %d preamble %dn",
  2658. arvif->vdev_id, preamble);
  2659. vdev_param = ar->wmi.vdev_param->preamble;
  2660. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2661. preamble);
  2662. if (ret)
  2663. ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
  2664. arvif->vdev_id, ret);
  2665. }
  2666. if (changed & BSS_CHANGED_ASSOC) {
  2667. if (info->assoc) {
  2668. /* Workaround: Make sure monitor vdev is not running
  2669. * when associating to prevent some firmware revisions
  2670. * (e.g. 10.1 and 10.2) from crashing.
  2671. */
  2672. if (ar->monitor_started)
  2673. ath10k_monitor_stop(ar);
  2674. ath10k_bss_assoc(hw, vif, info);
  2675. ath10k_monitor_recalc(ar);
  2676. } else {
  2677. ath10k_bss_disassoc(hw, vif);
  2678. }
  2679. }
  2680. if (changed & BSS_CHANGED_TXPOWER) {
  2681. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
  2682. arvif->vdev_id, info->txpower);
  2683. arvif->txpower = info->txpower;
  2684. ret = ath10k_mac_txpower_recalc(ar);
  2685. if (ret)
  2686. ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
  2687. }
  2688. mutex_unlock(&ar->conf_mutex);
  2689. }
  2690. static int ath10k_hw_scan(struct ieee80211_hw *hw,
  2691. struct ieee80211_vif *vif,
  2692. struct ieee80211_scan_request *hw_req)
  2693. {
  2694. struct ath10k *ar = hw->priv;
  2695. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2696. struct cfg80211_scan_request *req = &hw_req->req;
  2697. struct wmi_start_scan_arg arg;
  2698. int ret = 0;
  2699. int i;
  2700. mutex_lock(&ar->conf_mutex);
  2701. spin_lock_bh(&ar->data_lock);
  2702. switch (ar->scan.state) {
  2703. case ATH10K_SCAN_IDLE:
  2704. reinit_completion(&ar->scan.started);
  2705. reinit_completion(&ar->scan.completed);
  2706. ar->scan.state = ATH10K_SCAN_STARTING;
  2707. ar->scan.is_roc = false;
  2708. ar->scan.vdev_id = arvif->vdev_id;
  2709. ret = 0;
  2710. break;
  2711. case ATH10K_SCAN_STARTING:
  2712. case ATH10K_SCAN_RUNNING:
  2713. case ATH10K_SCAN_ABORTING:
  2714. ret = -EBUSY;
  2715. break;
  2716. }
  2717. spin_unlock_bh(&ar->data_lock);
  2718. if (ret)
  2719. goto exit;
  2720. memset(&arg, 0, sizeof(arg));
  2721. ath10k_wmi_start_scan_init(ar, &arg);
  2722. arg.vdev_id = arvif->vdev_id;
  2723. arg.scan_id = ATH10K_SCAN_ID;
  2724. if (!req->no_cck)
  2725. arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
  2726. if (req->ie_len) {
  2727. arg.ie_len = req->ie_len;
  2728. memcpy(arg.ie, req->ie, arg.ie_len);
  2729. }
  2730. if (req->n_ssids) {
  2731. arg.n_ssids = req->n_ssids;
  2732. for (i = 0; i < arg.n_ssids; i++) {
  2733. arg.ssids[i].len = req->ssids[i].ssid_len;
  2734. arg.ssids[i].ssid = req->ssids[i].ssid;
  2735. }
  2736. } else {
  2737. arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
  2738. }
  2739. if (req->n_channels) {
  2740. arg.n_channels = req->n_channels;
  2741. for (i = 0; i < arg.n_channels; i++)
  2742. arg.channels[i] = req->channels[i]->center_freq;
  2743. }
  2744. ret = ath10k_start_scan(ar, &arg);
  2745. if (ret) {
  2746. ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
  2747. spin_lock_bh(&ar->data_lock);
  2748. ar->scan.state = ATH10K_SCAN_IDLE;
  2749. spin_unlock_bh(&ar->data_lock);
  2750. }
  2751. exit:
  2752. mutex_unlock(&ar->conf_mutex);
  2753. return ret;
  2754. }
  2755. static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
  2756. struct ieee80211_vif *vif)
  2757. {
  2758. struct ath10k *ar = hw->priv;
  2759. mutex_lock(&ar->conf_mutex);
  2760. ath10k_scan_abort(ar);
  2761. mutex_unlock(&ar->conf_mutex);
  2762. cancel_delayed_work_sync(&ar->scan.timeout);
  2763. }
  2764. static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
  2765. struct ath10k_vif *arvif,
  2766. enum set_key_cmd cmd,
  2767. struct ieee80211_key_conf *key)
  2768. {
  2769. u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
  2770. int ret;
  2771. /* 10.1 firmware branch requires default key index to be set to group
  2772. * key index after installing it. Otherwise FW/HW Txes corrupted
  2773. * frames with multi-vif APs. This is not required for main firmware
  2774. * branch (e.g. 636).
  2775. *
  2776. * FIXME: This has been tested only in AP. It remains unknown if this
  2777. * is required for multi-vif STA interfaces on 10.1 */
  2778. if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
  2779. return;
  2780. if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
  2781. return;
  2782. if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
  2783. return;
  2784. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  2785. return;
  2786. if (cmd != SET_KEY)
  2787. return;
  2788. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  2789. key->keyidx);
  2790. if (ret)
  2791. ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
  2792. arvif->vdev_id, ret);
  2793. }
  2794. static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2795. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  2796. struct ieee80211_key_conf *key)
  2797. {
  2798. struct ath10k *ar = hw->priv;
  2799. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2800. struct ath10k_peer *peer;
  2801. const u8 *peer_addr;
  2802. bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2803. key->cipher == WLAN_CIPHER_SUITE_WEP104;
  2804. int ret = 0;
  2805. if (key->keyidx > WMI_MAX_KEY_INDEX)
  2806. return -ENOSPC;
  2807. mutex_lock(&ar->conf_mutex);
  2808. if (sta)
  2809. peer_addr = sta->addr;
  2810. else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
  2811. peer_addr = vif->bss_conf.bssid;
  2812. else
  2813. peer_addr = vif->addr;
  2814. key->hw_key_idx = key->keyidx;
  2815. /* the peer should not disappear in mid-way (unless FW goes awry) since
  2816. * we already hold conf_mutex. we just make sure its there now. */
  2817. spin_lock_bh(&ar->data_lock);
  2818. peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
  2819. spin_unlock_bh(&ar->data_lock);
  2820. if (!peer) {
  2821. if (cmd == SET_KEY) {
  2822. ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
  2823. peer_addr);
  2824. ret = -EOPNOTSUPP;
  2825. goto exit;
  2826. } else {
  2827. /* if the peer doesn't exist there is no key to disable
  2828. * anymore */
  2829. goto exit;
  2830. }
  2831. }
  2832. if (is_wep) {
  2833. if (cmd == SET_KEY)
  2834. arvif->wep_keys[key->keyidx] = key;
  2835. else
  2836. arvif->wep_keys[key->keyidx] = NULL;
  2837. if (cmd == DISABLE_KEY)
  2838. ath10k_clear_vdev_key(arvif, key);
  2839. }
  2840. ret = ath10k_install_key(arvif, key, cmd, peer_addr);
  2841. if (ret) {
  2842. ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
  2843. arvif->vdev_id, peer_addr, ret);
  2844. goto exit;
  2845. }
  2846. ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
  2847. spin_lock_bh(&ar->data_lock);
  2848. peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
  2849. if (peer && cmd == SET_KEY)
  2850. peer->keys[key->keyidx] = key;
  2851. else if (peer && cmd == DISABLE_KEY)
  2852. peer->keys[key->keyidx] = NULL;
  2853. else if (peer == NULL)
  2854. /* impossible unless FW goes crazy */
  2855. ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
  2856. spin_unlock_bh(&ar->data_lock);
  2857. exit:
  2858. mutex_unlock(&ar->conf_mutex);
  2859. return ret;
  2860. }
  2861. static void ath10k_sta_rc_update_wk(struct work_struct *wk)
  2862. {
  2863. struct ath10k *ar;
  2864. struct ath10k_vif *arvif;
  2865. struct ath10k_sta *arsta;
  2866. struct ieee80211_sta *sta;
  2867. u32 changed, bw, nss, smps;
  2868. int err;
  2869. arsta = container_of(wk, struct ath10k_sta, update_wk);
  2870. sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
  2871. arvif = arsta->arvif;
  2872. ar = arvif->ar;
  2873. spin_lock_bh(&ar->data_lock);
  2874. changed = arsta->changed;
  2875. arsta->changed = 0;
  2876. bw = arsta->bw;
  2877. nss = arsta->nss;
  2878. smps = arsta->smps;
  2879. spin_unlock_bh(&ar->data_lock);
  2880. mutex_lock(&ar->conf_mutex);
  2881. if (changed & IEEE80211_RC_BW_CHANGED) {
  2882. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
  2883. sta->addr, bw);
  2884. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  2885. WMI_PEER_CHAN_WIDTH, bw);
  2886. if (err)
  2887. ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
  2888. sta->addr, bw, err);
  2889. }
  2890. if (changed & IEEE80211_RC_NSS_CHANGED) {
  2891. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
  2892. sta->addr, nss);
  2893. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  2894. WMI_PEER_NSS, nss);
  2895. if (err)
  2896. ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
  2897. sta->addr, nss, err);
  2898. }
  2899. if (changed & IEEE80211_RC_SMPS_CHANGED) {
  2900. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
  2901. sta->addr, smps);
  2902. err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
  2903. WMI_PEER_SMPS_STATE, smps);
  2904. if (err)
  2905. ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
  2906. sta->addr, smps, err);
  2907. }
  2908. if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
  2909. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
  2910. sta->addr);
  2911. err = ath10k_station_assoc(ar, arvif->vif, sta, true);
  2912. if (err)
  2913. ath10k_warn(ar, "failed to reassociate station: %pM\n",
  2914. sta->addr);
  2915. }
  2916. mutex_unlock(&ar->conf_mutex);
  2917. }
  2918. static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
  2919. {
  2920. struct ath10k *ar = arvif->ar;
  2921. lockdep_assert_held(&ar->conf_mutex);
  2922. if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
  2923. arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
  2924. return 0;
  2925. if (ar->num_stations >= ar->max_num_stations)
  2926. return -ENOBUFS;
  2927. ar->num_stations++;
  2928. return 0;
  2929. }
  2930. static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
  2931. {
  2932. struct ath10k *ar = arvif->ar;
  2933. lockdep_assert_held(&ar->conf_mutex);
  2934. if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
  2935. arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
  2936. return;
  2937. ar->num_stations--;
  2938. }
  2939. static int ath10k_sta_state(struct ieee80211_hw *hw,
  2940. struct ieee80211_vif *vif,
  2941. struct ieee80211_sta *sta,
  2942. enum ieee80211_sta_state old_state,
  2943. enum ieee80211_sta_state new_state)
  2944. {
  2945. struct ath10k *ar = hw->priv;
  2946. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2947. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  2948. int ret = 0;
  2949. if (old_state == IEEE80211_STA_NOTEXIST &&
  2950. new_state == IEEE80211_STA_NONE) {
  2951. memset(arsta, 0, sizeof(*arsta));
  2952. arsta->arvif = arvif;
  2953. INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
  2954. }
  2955. /* cancel must be done outside the mutex to avoid deadlock */
  2956. if ((old_state == IEEE80211_STA_NONE &&
  2957. new_state == IEEE80211_STA_NOTEXIST))
  2958. cancel_work_sync(&arsta->update_wk);
  2959. mutex_lock(&ar->conf_mutex);
  2960. if (old_state == IEEE80211_STA_NOTEXIST &&
  2961. new_state == IEEE80211_STA_NONE) {
  2962. /*
  2963. * New station addition.
  2964. */
  2965. ath10k_dbg(ar, ATH10K_DBG_MAC,
  2966. "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
  2967. arvif->vdev_id, sta->addr,
  2968. ar->num_stations + 1, ar->max_num_stations,
  2969. ar->num_peers + 1, ar->max_num_peers);
  2970. ret = ath10k_mac_inc_num_stations(arvif);
  2971. if (ret) {
  2972. ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
  2973. ar->max_num_stations);
  2974. goto exit;
  2975. }
  2976. ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
  2977. if (ret) {
  2978. ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
  2979. sta->addr, arvif->vdev_id, ret);
  2980. ath10k_mac_dec_num_stations(arvif);
  2981. goto exit;
  2982. }
  2983. if (vif->type == NL80211_IFTYPE_STATION) {
  2984. WARN_ON(arvif->is_started);
  2985. ret = ath10k_vdev_start(arvif);
  2986. if (ret) {
  2987. ath10k_warn(ar, "failed to start vdev %i: %d\n",
  2988. arvif->vdev_id, ret);
  2989. WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
  2990. sta->addr));
  2991. ath10k_mac_dec_num_stations(arvif);
  2992. goto exit;
  2993. }
  2994. arvif->is_started = true;
  2995. }
  2996. } else if ((old_state == IEEE80211_STA_NONE &&
  2997. new_state == IEEE80211_STA_NOTEXIST)) {
  2998. /*
  2999. * Existing station deletion.
  3000. */
  3001. ath10k_dbg(ar, ATH10K_DBG_MAC,
  3002. "mac vdev %d peer delete %pM (sta gone)\n",
  3003. arvif->vdev_id, sta->addr);
  3004. if (vif->type == NL80211_IFTYPE_STATION) {
  3005. WARN_ON(!arvif->is_started);
  3006. ret = ath10k_vdev_stop(arvif);
  3007. if (ret)
  3008. ath10k_warn(ar, "failed to stop vdev %i: %d\n",
  3009. arvif->vdev_id, ret);
  3010. arvif->is_started = false;
  3011. }
  3012. ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
  3013. if (ret)
  3014. ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
  3015. sta->addr, arvif->vdev_id, ret);
  3016. ath10k_mac_dec_num_stations(arvif);
  3017. } else if (old_state == IEEE80211_STA_AUTH &&
  3018. new_state == IEEE80211_STA_ASSOC &&
  3019. (vif->type == NL80211_IFTYPE_AP ||
  3020. vif->type == NL80211_IFTYPE_ADHOC)) {
  3021. /*
  3022. * New association.
  3023. */
  3024. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
  3025. sta->addr);
  3026. ret = ath10k_station_assoc(ar, vif, sta, false);
  3027. if (ret)
  3028. ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
  3029. sta->addr, arvif->vdev_id, ret);
  3030. } else if (old_state == IEEE80211_STA_ASSOC &&
  3031. new_state == IEEE80211_STA_AUTH &&
  3032. (vif->type == NL80211_IFTYPE_AP ||
  3033. vif->type == NL80211_IFTYPE_ADHOC)) {
  3034. /*
  3035. * Disassociation.
  3036. */
  3037. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
  3038. sta->addr);
  3039. ret = ath10k_station_disassoc(ar, vif, sta);
  3040. if (ret)
  3041. ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
  3042. sta->addr, arvif->vdev_id, ret);
  3043. }
  3044. exit:
  3045. mutex_unlock(&ar->conf_mutex);
  3046. return ret;
  3047. }
  3048. static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
  3049. u16 ac, bool enable)
  3050. {
  3051. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3052. u32 value = 0;
  3053. int ret = 0;
  3054. lockdep_assert_held(&ar->conf_mutex);
  3055. if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
  3056. return 0;
  3057. switch (ac) {
  3058. case IEEE80211_AC_VO:
  3059. value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
  3060. WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
  3061. break;
  3062. case IEEE80211_AC_VI:
  3063. value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
  3064. WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
  3065. break;
  3066. case IEEE80211_AC_BE:
  3067. value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
  3068. WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
  3069. break;
  3070. case IEEE80211_AC_BK:
  3071. value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
  3072. WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
  3073. break;
  3074. }
  3075. if (enable)
  3076. arvif->u.sta.uapsd |= value;
  3077. else
  3078. arvif->u.sta.uapsd &= ~value;
  3079. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  3080. WMI_STA_PS_PARAM_UAPSD,
  3081. arvif->u.sta.uapsd);
  3082. if (ret) {
  3083. ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
  3084. goto exit;
  3085. }
  3086. if (arvif->u.sta.uapsd)
  3087. value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
  3088. else
  3089. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  3090. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  3091. WMI_STA_PS_PARAM_RX_WAKE_POLICY,
  3092. value);
  3093. if (ret)
  3094. ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
  3095. exit:
  3096. return ret;
  3097. }
  3098. static int ath10k_conf_tx(struct ieee80211_hw *hw,
  3099. struct ieee80211_vif *vif, u16 ac,
  3100. const struct ieee80211_tx_queue_params *params)
  3101. {
  3102. struct ath10k *ar = hw->priv;
  3103. struct wmi_wmm_params_arg *p = NULL;
  3104. int ret;
  3105. mutex_lock(&ar->conf_mutex);
  3106. switch (ac) {
  3107. case IEEE80211_AC_VO:
  3108. p = &ar->wmm_params.ac_vo;
  3109. break;
  3110. case IEEE80211_AC_VI:
  3111. p = &ar->wmm_params.ac_vi;
  3112. break;
  3113. case IEEE80211_AC_BE:
  3114. p = &ar->wmm_params.ac_be;
  3115. break;
  3116. case IEEE80211_AC_BK:
  3117. p = &ar->wmm_params.ac_bk;
  3118. break;
  3119. }
  3120. if (WARN_ON(!p)) {
  3121. ret = -EINVAL;
  3122. goto exit;
  3123. }
  3124. p->cwmin = params->cw_min;
  3125. p->cwmax = params->cw_max;
  3126. p->aifs = params->aifs;
  3127. /*
  3128. * The channel time duration programmed in the HW is in absolute
  3129. * microseconds, while mac80211 gives the txop in units of
  3130. * 32 microseconds.
  3131. */
  3132. p->txop = params->txop * 32;
  3133. /* FIXME: FW accepts wmm params per hw, not per vif */
  3134. ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
  3135. if (ret) {
  3136. ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
  3137. goto exit;
  3138. }
  3139. ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
  3140. if (ret)
  3141. ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
  3142. exit:
  3143. mutex_unlock(&ar->conf_mutex);
  3144. return ret;
  3145. }
  3146. #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
  3147. static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
  3148. struct ieee80211_vif *vif,
  3149. struct ieee80211_channel *chan,
  3150. int duration,
  3151. enum ieee80211_roc_type type)
  3152. {
  3153. struct ath10k *ar = hw->priv;
  3154. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3155. struct wmi_start_scan_arg arg;
  3156. int ret = 0;
  3157. mutex_lock(&ar->conf_mutex);
  3158. spin_lock_bh(&ar->data_lock);
  3159. switch (ar->scan.state) {
  3160. case ATH10K_SCAN_IDLE:
  3161. reinit_completion(&ar->scan.started);
  3162. reinit_completion(&ar->scan.completed);
  3163. reinit_completion(&ar->scan.on_channel);
  3164. ar->scan.state = ATH10K_SCAN_STARTING;
  3165. ar->scan.is_roc = true;
  3166. ar->scan.vdev_id = arvif->vdev_id;
  3167. ar->scan.roc_freq = chan->center_freq;
  3168. ret = 0;
  3169. break;
  3170. case ATH10K_SCAN_STARTING:
  3171. case ATH10K_SCAN_RUNNING:
  3172. case ATH10K_SCAN_ABORTING:
  3173. ret = -EBUSY;
  3174. break;
  3175. }
  3176. spin_unlock_bh(&ar->data_lock);
  3177. if (ret)
  3178. goto exit;
  3179. duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
  3180. memset(&arg, 0, sizeof(arg));
  3181. ath10k_wmi_start_scan_init(ar, &arg);
  3182. arg.vdev_id = arvif->vdev_id;
  3183. arg.scan_id = ATH10K_SCAN_ID;
  3184. arg.n_channels = 1;
  3185. arg.channels[0] = chan->center_freq;
  3186. arg.dwell_time_active = duration;
  3187. arg.dwell_time_passive = duration;
  3188. arg.max_scan_time = 2 * duration;
  3189. arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
  3190. arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
  3191. ret = ath10k_start_scan(ar, &arg);
  3192. if (ret) {
  3193. ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
  3194. spin_lock_bh(&ar->data_lock);
  3195. ar->scan.state = ATH10K_SCAN_IDLE;
  3196. spin_unlock_bh(&ar->data_lock);
  3197. goto exit;
  3198. }
  3199. ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
  3200. if (ret == 0) {
  3201. ath10k_warn(ar, "failed to switch to channel for roc scan\n");
  3202. ret = ath10k_scan_stop(ar);
  3203. if (ret)
  3204. ath10k_warn(ar, "failed to stop scan: %d\n", ret);
  3205. ret = -ETIMEDOUT;
  3206. goto exit;
  3207. }
  3208. ret = 0;
  3209. exit:
  3210. mutex_unlock(&ar->conf_mutex);
  3211. return ret;
  3212. }
  3213. static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
  3214. {
  3215. struct ath10k *ar = hw->priv;
  3216. mutex_lock(&ar->conf_mutex);
  3217. ath10k_scan_abort(ar);
  3218. mutex_unlock(&ar->conf_mutex);
  3219. cancel_delayed_work_sync(&ar->scan.timeout);
  3220. return 0;
  3221. }
  3222. /*
  3223. * Both RTS and Fragmentation threshold are interface-specific
  3224. * in ath10k, but device-specific in mac80211.
  3225. */
  3226. static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  3227. {
  3228. struct ath10k *ar = hw->priv;
  3229. struct ath10k_vif *arvif;
  3230. int ret = 0;
  3231. mutex_lock(&ar->conf_mutex);
  3232. list_for_each_entry(arvif, &ar->arvifs, list) {
  3233. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
  3234. arvif->vdev_id, value);
  3235. ret = ath10k_mac_set_rts(arvif, value);
  3236. if (ret) {
  3237. ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
  3238. arvif->vdev_id, ret);
  3239. break;
  3240. }
  3241. }
  3242. mutex_unlock(&ar->conf_mutex);
  3243. return ret;
  3244. }
  3245. static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
  3246. {
  3247. struct ath10k *ar = hw->priv;
  3248. struct ath10k_vif *arvif;
  3249. int ret = 0;
  3250. mutex_lock(&ar->conf_mutex);
  3251. list_for_each_entry(arvif, &ar->arvifs, list) {
  3252. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
  3253. arvif->vdev_id, value);
  3254. ret = ath10k_mac_set_frag(arvif, value);
  3255. if (ret) {
  3256. ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
  3257. arvif->vdev_id, ret);
  3258. break;
  3259. }
  3260. }
  3261. mutex_unlock(&ar->conf_mutex);
  3262. return ret;
  3263. }
  3264. static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3265. u32 queues, bool drop)
  3266. {
  3267. struct ath10k *ar = hw->priv;
  3268. bool skip;
  3269. int ret;
  3270. /* mac80211 doesn't care if we really xmit queued frames or not
  3271. * we'll collect those frames either way if we stop/delete vdevs */
  3272. if (drop)
  3273. return;
  3274. mutex_lock(&ar->conf_mutex);
  3275. if (ar->state == ATH10K_STATE_WEDGED)
  3276. goto skip;
  3277. ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
  3278. bool empty;
  3279. spin_lock_bh(&ar->htt.tx_lock);
  3280. empty = (ar->htt.num_pending_tx == 0);
  3281. spin_unlock_bh(&ar->htt.tx_lock);
  3282. skip = (ar->state == ATH10K_STATE_WEDGED) ||
  3283. test_bit(ATH10K_FLAG_CRASH_FLUSH,
  3284. &ar->dev_flags);
  3285. (empty || skip);
  3286. }), ATH10K_FLUSH_TIMEOUT_HZ);
  3287. if (ret <= 0 || skip)
  3288. ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
  3289. skip, ar->state, ret);
  3290. skip:
  3291. mutex_unlock(&ar->conf_mutex);
  3292. }
  3293. /* TODO: Implement this function properly
  3294. * For now it is needed to reply to Probe Requests in IBSS mode.
  3295. * Propably we need this information from FW.
  3296. */
  3297. static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
  3298. {
  3299. return 1;
  3300. }
  3301. #ifdef CONFIG_PM
  3302. static int ath10k_suspend(struct ieee80211_hw *hw,
  3303. struct cfg80211_wowlan *wowlan)
  3304. {
  3305. struct ath10k *ar = hw->priv;
  3306. int ret;
  3307. mutex_lock(&ar->conf_mutex);
  3308. ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
  3309. if (ret) {
  3310. if (ret == -ETIMEDOUT)
  3311. goto resume;
  3312. ret = 1;
  3313. goto exit;
  3314. }
  3315. ret = ath10k_hif_suspend(ar);
  3316. if (ret) {
  3317. ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
  3318. goto resume;
  3319. }
  3320. ret = 0;
  3321. goto exit;
  3322. resume:
  3323. ret = ath10k_wmi_pdev_resume_target(ar);
  3324. if (ret)
  3325. ath10k_warn(ar, "failed to resume target: %d\n", ret);
  3326. ret = 1;
  3327. exit:
  3328. mutex_unlock(&ar->conf_mutex);
  3329. return ret;
  3330. }
  3331. static int ath10k_resume(struct ieee80211_hw *hw)
  3332. {
  3333. struct ath10k *ar = hw->priv;
  3334. int ret;
  3335. mutex_lock(&ar->conf_mutex);
  3336. ret = ath10k_hif_resume(ar);
  3337. if (ret) {
  3338. ath10k_warn(ar, "failed to resume hif: %d\n", ret);
  3339. ret = 1;
  3340. goto exit;
  3341. }
  3342. ret = ath10k_wmi_pdev_resume_target(ar);
  3343. if (ret) {
  3344. ath10k_warn(ar, "failed to resume target: %d\n", ret);
  3345. ret = 1;
  3346. goto exit;
  3347. }
  3348. ret = 0;
  3349. exit:
  3350. mutex_unlock(&ar->conf_mutex);
  3351. return ret;
  3352. }
  3353. #endif
  3354. static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
  3355. enum ieee80211_reconfig_type reconfig_type)
  3356. {
  3357. struct ath10k *ar = hw->priv;
  3358. if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
  3359. return;
  3360. mutex_lock(&ar->conf_mutex);
  3361. /* If device failed to restart it will be in a different state, e.g.
  3362. * ATH10K_STATE_WEDGED */
  3363. if (ar->state == ATH10K_STATE_RESTARTED) {
  3364. ath10k_info(ar, "device successfully recovered\n");
  3365. ar->state = ATH10K_STATE_ON;
  3366. ieee80211_wake_queues(ar->hw);
  3367. }
  3368. mutex_unlock(&ar->conf_mutex);
  3369. }
  3370. static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
  3371. struct survey_info *survey)
  3372. {
  3373. struct ath10k *ar = hw->priv;
  3374. struct ieee80211_supported_band *sband;
  3375. struct survey_info *ar_survey = &ar->survey[idx];
  3376. int ret = 0;
  3377. mutex_lock(&ar->conf_mutex);
  3378. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  3379. if (sband && idx >= sband->n_channels) {
  3380. idx -= sband->n_channels;
  3381. sband = NULL;
  3382. }
  3383. if (!sband)
  3384. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  3385. if (!sband || idx >= sband->n_channels) {
  3386. ret = -ENOENT;
  3387. goto exit;
  3388. }
  3389. spin_lock_bh(&ar->data_lock);
  3390. memcpy(survey, ar_survey, sizeof(*survey));
  3391. spin_unlock_bh(&ar->data_lock);
  3392. survey->channel = &sband->channels[idx];
  3393. if (ar->rx_channel == survey->channel)
  3394. survey->filled |= SURVEY_INFO_IN_USE;
  3395. exit:
  3396. mutex_unlock(&ar->conf_mutex);
  3397. return ret;
  3398. }
  3399. /* Helper table for legacy fixed_rate/bitrate_mask */
  3400. static const u8 cck_ofdm_rate[] = {
  3401. /* CCK */
  3402. 3, /* 1Mbps */
  3403. 2, /* 2Mbps */
  3404. 1, /* 5.5Mbps */
  3405. 0, /* 11Mbps */
  3406. /* OFDM */
  3407. 3, /* 6Mbps */
  3408. 7, /* 9Mbps */
  3409. 2, /* 12Mbps */
  3410. 6, /* 18Mbps */
  3411. 1, /* 24Mbps */
  3412. 5, /* 36Mbps */
  3413. 0, /* 48Mbps */
  3414. 4, /* 54Mbps */
  3415. };
  3416. /* Check if only one bit set */
  3417. static int ath10k_check_single_mask(u32 mask)
  3418. {
  3419. int bit;
  3420. bit = ffs(mask);
  3421. if (!bit)
  3422. return 0;
  3423. mask &= ~BIT(bit - 1);
  3424. if (mask)
  3425. return 2;
  3426. return 1;
  3427. }
  3428. static bool
  3429. ath10k_default_bitrate_mask(struct ath10k *ar,
  3430. enum ieee80211_band band,
  3431. const struct cfg80211_bitrate_mask *mask)
  3432. {
  3433. u32 legacy = 0x00ff;
  3434. u8 ht = 0xff, i;
  3435. u16 vht = 0x3ff;
  3436. u16 nrf = ar->num_rf_chains;
  3437. if (ar->cfg_tx_chainmask)
  3438. nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
  3439. switch (band) {
  3440. case IEEE80211_BAND_2GHZ:
  3441. legacy = 0x00fff;
  3442. vht = 0;
  3443. break;
  3444. case IEEE80211_BAND_5GHZ:
  3445. break;
  3446. default:
  3447. return false;
  3448. }
  3449. if (mask->control[band].legacy != legacy)
  3450. return false;
  3451. for (i = 0; i < nrf; i++)
  3452. if (mask->control[band].ht_mcs[i] != ht)
  3453. return false;
  3454. for (i = 0; i < nrf; i++)
  3455. if (mask->control[band].vht_mcs[i] != vht)
  3456. return false;
  3457. return true;
  3458. }
  3459. static bool
  3460. ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
  3461. enum ieee80211_band band,
  3462. u8 *fixed_nss)
  3463. {
  3464. int ht_nss = 0, vht_nss = 0, i;
  3465. /* check legacy */
  3466. if (ath10k_check_single_mask(mask->control[band].legacy))
  3467. return false;
  3468. /* check HT */
  3469. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
  3470. if (mask->control[band].ht_mcs[i] == 0xff)
  3471. continue;
  3472. else if (mask->control[band].ht_mcs[i] == 0x00)
  3473. break;
  3474. return false;
  3475. }
  3476. ht_nss = i;
  3477. /* check VHT */
  3478. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  3479. if (mask->control[band].vht_mcs[i] == 0x03ff)
  3480. continue;
  3481. else if (mask->control[band].vht_mcs[i] == 0x0000)
  3482. break;
  3483. return false;
  3484. }
  3485. vht_nss = i;
  3486. if (ht_nss > 0 && vht_nss > 0)
  3487. return false;
  3488. if (ht_nss)
  3489. *fixed_nss = ht_nss;
  3490. else if (vht_nss)
  3491. *fixed_nss = vht_nss;
  3492. else
  3493. return false;
  3494. return true;
  3495. }
  3496. static bool
  3497. ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
  3498. enum ieee80211_band band,
  3499. enum wmi_rate_preamble *preamble)
  3500. {
  3501. int legacy = 0, ht = 0, vht = 0, i;
  3502. *preamble = WMI_RATE_PREAMBLE_OFDM;
  3503. /* check legacy */
  3504. legacy = ath10k_check_single_mask(mask->control[band].legacy);
  3505. if (legacy > 1)
  3506. return false;
  3507. /* check HT */
  3508. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  3509. ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
  3510. if (ht > 1)
  3511. return false;
  3512. /* check VHT */
  3513. for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
  3514. vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
  3515. if (vht > 1)
  3516. return false;
  3517. /* Currently we support only one fixed_rate */
  3518. if ((legacy + ht + vht) != 1)
  3519. return false;
  3520. if (ht)
  3521. *preamble = WMI_RATE_PREAMBLE_HT;
  3522. else if (vht)
  3523. *preamble = WMI_RATE_PREAMBLE_VHT;
  3524. return true;
  3525. }
  3526. static bool
  3527. ath10k_bitrate_mask_rate(struct ath10k *ar,
  3528. const struct cfg80211_bitrate_mask *mask,
  3529. enum ieee80211_band band,
  3530. u8 *fixed_rate,
  3531. u8 *fixed_nss)
  3532. {
  3533. u8 rate = 0, pream = 0, nss = 0, i;
  3534. enum wmi_rate_preamble preamble;
  3535. /* Check if single rate correct */
  3536. if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
  3537. return false;
  3538. pream = preamble;
  3539. switch (preamble) {
  3540. case WMI_RATE_PREAMBLE_CCK:
  3541. case WMI_RATE_PREAMBLE_OFDM:
  3542. i = ffs(mask->control[band].legacy) - 1;
  3543. if (band == IEEE80211_BAND_2GHZ && i < 4)
  3544. pream = WMI_RATE_PREAMBLE_CCK;
  3545. if (band == IEEE80211_BAND_5GHZ)
  3546. i += 4;
  3547. if (i >= ARRAY_SIZE(cck_ofdm_rate))
  3548. return false;
  3549. rate = cck_ofdm_rate[i];
  3550. break;
  3551. case WMI_RATE_PREAMBLE_HT:
  3552. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  3553. if (mask->control[band].ht_mcs[i])
  3554. break;
  3555. if (i == IEEE80211_HT_MCS_MASK_LEN)
  3556. return false;
  3557. rate = ffs(mask->control[band].ht_mcs[i]) - 1;
  3558. nss = i;
  3559. break;
  3560. case WMI_RATE_PREAMBLE_VHT:
  3561. for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
  3562. if (mask->control[band].vht_mcs[i])
  3563. break;
  3564. if (i == NL80211_VHT_NSS_MAX)
  3565. return false;
  3566. rate = ffs(mask->control[band].vht_mcs[i]) - 1;
  3567. nss = i;
  3568. break;
  3569. }
  3570. *fixed_nss = nss + 1;
  3571. nss <<= 4;
  3572. pream <<= 6;
  3573. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
  3574. pream, nss, rate);
  3575. *fixed_rate = pream | nss | rate;
  3576. return true;
  3577. }
  3578. static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
  3579. const struct cfg80211_bitrate_mask *mask,
  3580. enum ieee80211_band band,
  3581. u8 *fixed_rate,
  3582. u8 *fixed_nss)
  3583. {
  3584. /* First check full NSS mask, if we can simply limit NSS */
  3585. if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
  3586. return true;
  3587. /* Next Check single rate is set */
  3588. return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
  3589. }
  3590. static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
  3591. u8 fixed_rate,
  3592. u8 fixed_nss,
  3593. u8 force_sgi)
  3594. {
  3595. struct ath10k *ar = arvif->ar;
  3596. u32 vdev_param;
  3597. int ret = 0;
  3598. mutex_lock(&ar->conf_mutex);
  3599. if (arvif->fixed_rate == fixed_rate &&
  3600. arvif->fixed_nss == fixed_nss &&
  3601. arvif->force_sgi == force_sgi)
  3602. goto exit;
  3603. if (fixed_rate == WMI_FIXED_RATE_NONE)
  3604. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
  3605. if (force_sgi)
  3606. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
  3607. vdev_param = ar->wmi.vdev_param->fixed_rate;
  3608. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  3609. vdev_param, fixed_rate);
  3610. if (ret) {
  3611. ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
  3612. fixed_rate, ret);
  3613. ret = -EINVAL;
  3614. goto exit;
  3615. }
  3616. arvif->fixed_rate = fixed_rate;
  3617. vdev_param = ar->wmi.vdev_param->nss;
  3618. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  3619. vdev_param, fixed_nss);
  3620. if (ret) {
  3621. ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
  3622. fixed_nss, ret);
  3623. ret = -EINVAL;
  3624. goto exit;
  3625. }
  3626. arvif->fixed_nss = fixed_nss;
  3627. vdev_param = ar->wmi.vdev_param->sgi;
  3628. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
  3629. force_sgi);
  3630. if (ret) {
  3631. ath10k_warn(ar, "failed to set sgi param %d: %d\n",
  3632. force_sgi, ret);
  3633. ret = -EINVAL;
  3634. goto exit;
  3635. }
  3636. arvif->force_sgi = force_sgi;
  3637. exit:
  3638. mutex_unlock(&ar->conf_mutex);
  3639. return ret;
  3640. }
  3641. static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
  3642. struct ieee80211_vif *vif,
  3643. const struct cfg80211_bitrate_mask *mask)
  3644. {
  3645. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3646. struct ath10k *ar = arvif->ar;
  3647. enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
  3648. u8 fixed_rate = WMI_FIXED_RATE_NONE;
  3649. u8 fixed_nss = ar->num_rf_chains;
  3650. u8 force_sgi;
  3651. if (ar->cfg_tx_chainmask)
  3652. fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
  3653. force_sgi = mask->control[band].gi;
  3654. if (force_sgi == NL80211_TXRATE_FORCE_LGI)
  3655. return -EINVAL;
  3656. if (!ath10k_default_bitrate_mask(ar, band, mask)) {
  3657. if (!ath10k_get_fixed_rate_nss(ar, mask, band,
  3658. &fixed_rate,
  3659. &fixed_nss))
  3660. return -EINVAL;
  3661. }
  3662. if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
  3663. ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
  3664. return -EINVAL;
  3665. }
  3666. return ath10k_set_fixed_rate_param(arvif, fixed_rate,
  3667. fixed_nss, force_sgi);
  3668. }
  3669. static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
  3670. struct ieee80211_vif *vif,
  3671. struct ieee80211_sta *sta,
  3672. u32 changed)
  3673. {
  3674. struct ath10k *ar = hw->priv;
  3675. struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
  3676. u32 bw, smps;
  3677. spin_lock_bh(&ar->data_lock);
  3678. ath10k_dbg(ar, ATH10K_DBG_MAC,
  3679. "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
  3680. sta->addr, changed, sta->bandwidth, sta->rx_nss,
  3681. sta->smps_mode);
  3682. if (changed & IEEE80211_RC_BW_CHANGED) {
  3683. bw = WMI_PEER_CHWIDTH_20MHZ;
  3684. switch (sta->bandwidth) {
  3685. case IEEE80211_STA_RX_BW_20:
  3686. bw = WMI_PEER_CHWIDTH_20MHZ;
  3687. break;
  3688. case IEEE80211_STA_RX_BW_40:
  3689. bw = WMI_PEER_CHWIDTH_40MHZ;
  3690. break;
  3691. case IEEE80211_STA_RX_BW_80:
  3692. bw = WMI_PEER_CHWIDTH_80MHZ;
  3693. break;
  3694. case IEEE80211_STA_RX_BW_160:
  3695. ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
  3696. sta->bandwidth, sta->addr);
  3697. bw = WMI_PEER_CHWIDTH_20MHZ;
  3698. break;
  3699. }
  3700. arsta->bw = bw;
  3701. }
  3702. if (changed & IEEE80211_RC_NSS_CHANGED)
  3703. arsta->nss = sta->rx_nss;
  3704. if (changed & IEEE80211_RC_SMPS_CHANGED) {
  3705. smps = WMI_PEER_SMPS_PS_NONE;
  3706. switch (sta->smps_mode) {
  3707. case IEEE80211_SMPS_AUTOMATIC:
  3708. case IEEE80211_SMPS_OFF:
  3709. smps = WMI_PEER_SMPS_PS_NONE;
  3710. break;
  3711. case IEEE80211_SMPS_STATIC:
  3712. smps = WMI_PEER_SMPS_STATIC;
  3713. break;
  3714. case IEEE80211_SMPS_DYNAMIC:
  3715. smps = WMI_PEER_SMPS_DYNAMIC;
  3716. break;
  3717. case IEEE80211_SMPS_NUM_MODES:
  3718. ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
  3719. sta->smps_mode, sta->addr);
  3720. smps = WMI_PEER_SMPS_PS_NONE;
  3721. break;
  3722. }
  3723. arsta->smps = smps;
  3724. }
  3725. arsta->changed |= changed;
  3726. spin_unlock_bh(&ar->data_lock);
  3727. ieee80211_queue_work(hw, &arsta->update_wk);
  3728. }
  3729. static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  3730. {
  3731. /*
  3732. * FIXME: Return 0 for time being. Need to figure out whether FW
  3733. * has the API to fetch 64-bit local TSF
  3734. */
  3735. return 0;
  3736. }
  3737. static int ath10k_ampdu_action(struct ieee80211_hw *hw,
  3738. struct ieee80211_vif *vif,
  3739. enum ieee80211_ampdu_mlme_action action,
  3740. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  3741. u8 buf_size)
  3742. {
  3743. struct ath10k *ar = hw->priv;
  3744. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  3745. ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
  3746. arvif->vdev_id, sta->addr, tid, action);
  3747. switch (action) {
  3748. case IEEE80211_AMPDU_RX_START:
  3749. case IEEE80211_AMPDU_RX_STOP:
  3750. /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
  3751. * creation/removal. Do we need to verify this?
  3752. */
  3753. return 0;
  3754. case IEEE80211_AMPDU_TX_START:
  3755. case IEEE80211_AMPDU_TX_STOP_CONT:
  3756. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  3757. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  3758. case IEEE80211_AMPDU_TX_OPERATIONAL:
  3759. /* Firmware offloads Tx aggregation entirely so deny mac80211
  3760. * Tx aggregation requests.
  3761. */
  3762. return -EOPNOTSUPP;
  3763. }
  3764. return -EINVAL;
  3765. }
  3766. static const struct ieee80211_ops ath10k_ops = {
  3767. .tx = ath10k_tx,
  3768. .start = ath10k_start,
  3769. .stop = ath10k_stop,
  3770. .config = ath10k_config,
  3771. .add_interface = ath10k_add_interface,
  3772. .remove_interface = ath10k_remove_interface,
  3773. .configure_filter = ath10k_configure_filter,
  3774. .bss_info_changed = ath10k_bss_info_changed,
  3775. .hw_scan = ath10k_hw_scan,
  3776. .cancel_hw_scan = ath10k_cancel_hw_scan,
  3777. .set_key = ath10k_set_key,
  3778. .sta_state = ath10k_sta_state,
  3779. .conf_tx = ath10k_conf_tx,
  3780. .remain_on_channel = ath10k_remain_on_channel,
  3781. .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
  3782. .set_rts_threshold = ath10k_set_rts_threshold,
  3783. .set_frag_threshold = ath10k_set_frag_threshold,
  3784. .flush = ath10k_flush,
  3785. .tx_last_beacon = ath10k_tx_last_beacon,
  3786. .set_antenna = ath10k_set_antenna,
  3787. .get_antenna = ath10k_get_antenna,
  3788. .reconfig_complete = ath10k_reconfig_complete,
  3789. .get_survey = ath10k_get_survey,
  3790. .set_bitrate_mask = ath10k_set_bitrate_mask,
  3791. .sta_rc_update = ath10k_sta_rc_update,
  3792. .get_tsf = ath10k_get_tsf,
  3793. .ampdu_action = ath10k_ampdu_action,
  3794. .get_et_sset_count = ath10k_debug_get_et_sset_count,
  3795. .get_et_stats = ath10k_debug_get_et_stats,
  3796. .get_et_strings = ath10k_debug_get_et_strings,
  3797. CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
  3798. #ifdef CONFIG_PM
  3799. .suspend = ath10k_suspend,
  3800. .resume = ath10k_resume,
  3801. #endif
  3802. };
  3803. #define RATETAB_ENT(_rate, _rateid, _flags) { \
  3804. .bitrate = (_rate), \
  3805. .flags = (_flags), \
  3806. .hw_value = (_rateid), \
  3807. }
  3808. #define CHAN2G(_channel, _freq, _flags) { \
  3809. .band = IEEE80211_BAND_2GHZ, \
  3810. .hw_value = (_channel), \
  3811. .center_freq = (_freq), \
  3812. .flags = (_flags), \
  3813. .max_antenna_gain = 0, \
  3814. .max_power = 30, \
  3815. }
  3816. #define CHAN5G(_channel, _freq, _flags) { \
  3817. .band = IEEE80211_BAND_5GHZ, \
  3818. .hw_value = (_channel), \
  3819. .center_freq = (_freq), \
  3820. .flags = (_flags), \
  3821. .max_antenna_gain = 0, \
  3822. .max_power = 30, \
  3823. }
  3824. static const struct ieee80211_channel ath10k_2ghz_channels[] = {
  3825. CHAN2G(1, 2412, 0),
  3826. CHAN2G(2, 2417, 0),
  3827. CHAN2G(3, 2422, 0),
  3828. CHAN2G(4, 2427, 0),
  3829. CHAN2G(5, 2432, 0),
  3830. CHAN2G(6, 2437, 0),
  3831. CHAN2G(7, 2442, 0),
  3832. CHAN2G(8, 2447, 0),
  3833. CHAN2G(9, 2452, 0),
  3834. CHAN2G(10, 2457, 0),
  3835. CHAN2G(11, 2462, 0),
  3836. CHAN2G(12, 2467, 0),
  3837. CHAN2G(13, 2472, 0),
  3838. CHAN2G(14, 2484, 0),
  3839. };
  3840. static const struct ieee80211_channel ath10k_5ghz_channels[] = {
  3841. CHAN5G(36, 5180, 0),
  3842. CHAN5G(40, 5200, 0),
  3843. CHAN5G(44, 5220, 0),
  3844. CHAN5G(48, 5240, 0),
  3845. CHAN5G(52, 5260, 0),
  3846. CHAN5G(56, 5280, 0),
  3847. CHAN5G(60, 5300, 0),
  3848. CHAN5G(64, 5320, 0),
  3849. CHAN5G(100, 5500, 0),
  3850. CHAN5G(104, 5520, 0),
  3851. CHAN5G(108, 5540, 0),
  3852. CHAN5G(112, 5560, 0),
  3853. CHAN5G(116, 5580, 0),
  3854. CHAN5G(120, 5600, 0),
  3855. CHAN5G(124, 5620, 0),
  3856. CHAN5G(128, 5640, 0),
  3857. CHAN5G(132, 5660, 0),
  3858. CHAN5G(136, 5680, 0),
  3859. CHAN5G(140, 5700, 0),
  3860. CHAN5G(149, 5745, 0),
  3861. CHAN5G(153, 5765, 0),
  3862. CHAN5G(157, 5785, 0),
  3863. CHAN5G(161, 5805, 0),
  3864. CHAN5G(165, 5825, 0),
  3865. };
  3866. static struct ieee80211_rate ath10k_rates[] = {
  3867. /* CCK */
  3868. RATETAB_ENT(10, 0x82, 0),
  3869. RATETAB_ENT(20, 0x84, 0),
  3870. RATETAB_ENT(55, 0x8b, 0),
  3871. RATETAB_ENT(110, 0x96, 0),
  3872. /* OFDM */
  3873. RATETAB_ENT(60, 0x0c, 0),
  3874. RATETAB_ENT(90, 0x12, 0),
  3875. RATETAB_ENT(120, 0x18, 0),
  3876. RATETAB_ENT(180, 0x24, 0),
  3877. RATETAB_ENT(240, 0x30, 0),
  3878. RATETAB_ENT(360, 0x48, 0),
  3879. RATETAB_ENT(480, 0x60, 0),
  3880. RATETAB_ENT(540, 0x6c, 0),
  3881. };
  3882. #define ath10k_a_rates (ath10k_rates + 4)
  3883. #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
  3884. #define ath10k_g_rates (ath10k_rates + 0)
  3885. #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
  3886. struct ath10k *ath10k_mac_create(size_t priv_size)
  3887. {
  3888. struct ieee80211_hw *hw;
  3889. struct ath10k *ar;
  3890. hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
  3891. if (!hw)
  3892. return NULL;
  3893. ar = hw->priv;
  3894. ar->hw = hw;
  3895. return ar;
  3896. }
  3897. void ath10k_mac_destroy(struct ath10k *ar)
  3898. {
  3899. ieee80211_free_hw(ar->hw);
  3900. }
  3901. static const struct ieee80211_iface_limit ath10k_if_limits[] = {
  3902. {
  3903. .max = 8,
  3904. .types = BIT(NL80211_IFTYPE_STATION)
  3905. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  3906. },
  3907. {
  3908. .max = 3,
  3909. .types = BIT(NL80211_IFTYPE_P2P_GO)
  3910. },
  3911. {
  3912. .max = 7,
  3913. .types = BIT(NL80211_IFTYPE_AP)
  3914. },
  3915. };
  3916. static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
  3917. {
  3918. .max = 8,
  3919. .types = BIT(NL80211_IFTYPE_AP)
  3920. },
  3921. };
  3922. static const struct ieee80211_iface_combination ath10k_if_comb[] = {
  3923. {
  3924. .limits = ath10k_if_limits,
  3925. .n_limits = ARRAY_SIZE(ath10k_if_limits),
  3926. .max_interfaces = 8,
  3927. .num_different_channels = 1,
  3928. .beacon_int_infra_match = true,
  3929. },
  3930. };
  3931. static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
  3932. {
  3933. .limits = ath10k_10x_if_limits,
  3934. .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
  3935. .max_interfaces = 8,
  3936. .num_different_channels = 1,
  3937. .beacon_int_infra_match = true,
  3938. #ifdef CONFIG_ATH10K_DFS_CERTIFIED
  3939. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  3940. BIT(NL80211_CHAN_WIDTH_20) |
  3941. BIT(NL80211_CHAN_WIDTH_40) |
  3942. BIT(NL80211_CHAN_WIDTH_80),
  3943. #endif
  3944. },
  3945. };
  3946. static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
  3947. {
  3948. struct ieee80211_sta_vht_cap vht_cap = {0};
  3949. u16 mcs_map;
  3950. int i;
  3951. vht_cap.vht_supported = 1;
  3952. vht_cap.cap = ar->vht_cap_info;
  3953. mcs_map = 0;
  3954. for (i = 0; i < 8; i++) {
  3955. if (i < ar->num_rf_chains)
  3956. mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
  3957. else
  3958. mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
  3959. }
  3960. vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  3961. vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  3962. return vht_cap;
  3963. }
  3964. static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
  3965. {
  3966. int i;
  3967. struct ieee80211_sta_ht_cap ht_cap = {0};
  3968. if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
  3969. return ht_cap;
  3970. ht_cap.ht_supported = 1;
  3971. ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  3972. ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  3973. ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  3974. ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
  3975. ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
  3976. if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
  3977. ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  3978. if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
  3979. ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  3980. if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
  3981. u32 smps;
  3982. smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
  3983. smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
  3984. ht_cap.cap |= smps;
  3985. }
  3986. if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
  3987. ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  3988. if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
  3989. u32 stbc;
  3990. stbc = ar->ht_cap_info;
  3991. stbc &= WMI_HT_CAP_RX_STBC;
  3992. stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
  3993. stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
  3994. stbc &= IEEE80211_HT_CAP_RX_STBC;
  3995. ht_cap.cap |= stbc;
  3996. }
  3997. if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
  3998. ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
  3999. if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
  4000. ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
  4001. /* max AMSDU is implicitly taken from vht_cap_info */
  4002. if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
  4003. ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  4004. for (i = 0; i < ar->num_rf_chains; i++)
  4005. ht_cap.mcs.rx_mask[i] = 0xFF;
  4006. ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  4007. return ht_cap;
  4008. }
  4009. static void ath10k_get_arvif_iter(void *data, u8 *mac,
  4010. struct ieee80211_vif *vif)
  4011. {
  4012. struct ath10k_vif_iter *arvif_iter = data;
  4013. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  4014. if (arvif->vdev_id == arvif_iter->vdev_id)
  4015. arvif_iter->arvif = arvif;
  4016. }
  4017. struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
  4018. {
  4019. struct ath10k_vif_iter arvif_iter;
  4020. u32 flags;
  4021. memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
  4022. arvif_iter.vdev_id = vdev_id;
  4023. flags = IEEE80211_IFACE_ITER_RESUME_ALL;
  4024. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  4025. flags,
  4026. ath10k_get_arvif_iter,
  4027. &arvif_iter);
  4028. if (!arvif_iter.arvif) {
  4029. ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
  4030. return NULL;
  4031. }
  4032. return arvif_iter.arvif;
  4033. }
  4034. int ath10k_mac_register(struct ath10k *ar)
  4035. {
  4036. struct ieee80211_supported_band *band;
  4037. struct ieee80211_sta_vht_cap vht_cap;
  4038. struct ieee80211_sta_ht_cap ht_cap;
  4039. void *channels;
  4040. int ret;
  4041. SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
  4042. SET_IEEE80211_DEV(ar->hw, ar->dev);
  4043. ht_cap = ath10k_get_ht_cap(ar);
  4044. vht_cap = ath10k_create_vht_cap(ar);
  4045. if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
  4046. channels = kmemdup(ath10k_2ghz_channels,
  4047. sizeof(ath10k_2ghz_channels),
  4048. GFP_KERNEL);
  4049. if (!channels) {
  4050. ret = -ENOMEM;
  4051. goto err_free;
  4052. }
  4053. band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
  4054. band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
  4055. band->channels = channels;
  4056. band->n_bitrates = ath10k_g_rates_size;
  4057. band->bitrates = ath10k_g_rates;
  4058. band->ht_cap = ht_cap;
  4059. /* vht is not supported in 2.4 GHz */
  4060. ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
  4061. }
  4062. if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
  4063. channels = kmemdup(ath10k_5ghz_channels,
  4064. sizeof(ath10k_5ghz_channels),
  4065. GFP_KERNEL);
  4066. if (!channels) {
  4067. ret = -ENOMEM;
  4068. goto err_free;
  4069. }
  4070. band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
  4071. band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
  4072. band->channels = channels;
  4073. band->n_bitrates = ath10k_a_rates_size;
  4074. band->bitrates = ath10k_a_rates;
  4075. band->ht_cap = ht_cap;
  4076. band->vht_cap = vht_cap;
  4077. ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
  4078. }
  4079. ar->hw->wiphy->interface_modes =
  4080. BIT(NL80211_IFTYPE_STATION) |
  4081. BIT(NL80211_IFTYPE_AP);
  4082. ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
  4083. ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
  4084. if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
  4085. ar->hw->wiphy->interface_modes |=
  4086. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  4087. BIT(NL80211_IFTYPE_P2P_GO);
  4088. ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  4089. IEEE80211_HW_SUPPORTS_PS |
  4090. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  4091. IEEE80211_HW_SUPPORTS_UAPSD |
  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. }