mac.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419
  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. /**********/
  27. /* Crypto */
  28. /**********/
  29. static int ath10k_send_key(struct ath10k_vif *arvif,
  30. struct ieee80211_key_conf *key,
  31. enum set_key_cmd cmd,
  32. const u8 *macaddr)
  33. {
  34. struct wmi_vdev_install_key_arg arg = {
  35. .vdev_id = arvif->vdev_id,
  36. .key_idx = key->keyidx,
  37. .key_len = key->keylen,
  38. .key_data = key->key,
  39. .macaddr = macaddr,
  40. };
  41. lockdep_assert_held(&arvif->ar->conf_mutex);
  42. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  43. arg.key_flags = WMI_KEY_PAIRWISE;
  44. else
  45. arg.key_flags = WMI_KEY_GROUP;
  46. switch (key->cipher) {
  47. case WLAN_CIPHER_SUITE_CCMP:
  48. arg.key_cipher = WMI_CIPHER_AES_CCM;
  49. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
  50. break;
  51. case WLAN_CIPHER_SUITE_TKIP:
  52. arg.key_cipher = WMI_CIPHER_TKIP;
  53. arg.key_txmic_len = 8;
  54. arg.key_rxmic_len = 8;
  55. break;
  56. case WLAN_CIPHER_SUITE_WEP40:
  57. case WLAN_CIPHER_SUITE_WEP104:
  58. arg.key_cipher = WMI_CIPHER_WEP;
  59. /* AP/IBSS mode requires self-key to be groupwise
  60. * Otherwise pairwise key must be set */
  61. if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
  62. arg.key_flags = WMI_KEY_PAIRWISE;
  63. break;
  64. default:
  65. ath10k_warn("cipher %d is not supported\n", key->cipher);
  66. return -EOPNOTSUPP;
  67. }
  68. if (cmd == DISABLE_KEY) {
  69. arg.key_cipher = WMI_CIPHER_NONE;
  70. arg.key_data = NULL;
  71. }
  72. return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
  73. }
  74. static int ath10k_install_key(struct ath10k_vif *arvif,
  75. struct ieee80211_key_conf *key,
  76. enum set_key_cmd cmd,
  77. const u8 *macaddr)
  78. {
  79. struct ath10k *ar = arvif->ar;
  80. int ret;
  81. lockdep_assert_held(&ar->conf_mutex);
  82. INIT_COMPLETION(ar->install_key_done);
  83. ret = ath10k_send_key(arvif, key, cmd, macaddr);
  84. if (ret)
  85. return ret;
  86. ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
  87. if (ret == 0)
  88. return -ETIMEDOUT;
  89. return 0;
  90. }
  91. static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
  92. const u8 *addr)
  93. {
  94. struct ath10k *ar = arvif->ar;
  95. struct ath10k_peer *peer;
  96. int ret;
  97. int i;
  98. lockdep_assert_held(&ar->conf_mutex);
  99. spin_lock_bh(&ar->data_lock);
  100. peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
  101. spin_unlock_bh(&ar->data_lock);
  102. if (!peer)
  103. return -ENOENT;
  104. for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
  105. if (arvif->wep_keys[i] == NULL)
  106. continue;
  107. ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
  108. addr);
  109. if (ret)
  110. return ret;
  111. peer->keys[i] = arvif->wep_keys[i];
  112. }
  113. return 0;
  114. }
  115. static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
  116. const u8 *addr)
  117. {
  118. struct ath10k *ar = arvif->ar;
  119. struct ath10k_peer *peer;
  120. int first_errno = 0;
  121. int ret;
  122. int i;
  123. lockdep_assert_held(&ar->conf_mutex);
  124. spin_lock_bh(&ar->data_lock);
  125. peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
  126. spin_unlock_bh(&ar->data_lock);
  127. if (!peer)
  128. return -ENOENT;
  129. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  130. if (peer->keys[i] == NULL)
  131. continue;
  132. ret = ath10k_install_key(arvif, peer->keys[i],
  133. DISABLE_KEY, addr);
  134. if (ret && first_errno == 0)
  135. first_errno = ret;
  136. if (ret)
  137. ath10k_warn("could not remove peer wep key %d (%d)\n",
  138. i, ret);
  139. peer->keys[i] = NULL;
  140. }
  141. return first_errno;
  142. }
  143. static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
  144. struct ieee80211_key_conf *key)
  145. {
  146. struct ath10k *ar = arvif->ar;
  147. struct ath10k_peer *peer;
  148. u8 addr[ETH_ALEN];
  149. int first_errno = 0;
  150. int ret;
  151. int i;
  152. lockdep_assert_held(&ar->conf_mutex);
  153. for (;;) {
  154. /* since ath10k_install_key we can't hold data_lock all the
  155. * time, so we try to remove the keys incrementally */
  156. spin_lock_bh(&ar->data_lock);
  157. i = 0;
  158. list_for_each_entry(peer, &ar->peers, list) {
  159. for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
  160. if (peer->keys[i] == key) {
  161. memcpy(addr, peer->addr, ETH_ALEN);
  162. peer->keys[i] = NULL;
  163. break;
  164. }
  165. }
  166. if (i < ARRAY_SIZE(peer->keys))
  167. break;
  168. }
  169. spin_unlock_bh(&ar->data_lock);
  170. if (i == ARRAY_SIZE(peer->keys))
  171. break;
  172. ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
  173. if (ret && first_errno == 0)
  174. first_errno = ret;
  175. if (ret)
  176. ath10k_warn("could not remove key for %pM\n", addr);
  177. }
  178. return first_errno;
  179. }
  180. /*********************/
  181. /* General utilities */
  182. /*********************/
  183. static inline enum wmi_phy_mode
  184. chan_to_phymode(const struct cfg80211_chan_def *chandef)
  185. {
  186. enum wmi_phy_mode phymode = MODE_UNKNOWN;
  187. switch (chandef->chan->band) {
  188. case IEEE80211_BAND_2GHZ:
  189. switch (chandef->width) {
  190. case NL80211_CHAN_WIDTH_20_NOHT:
  191. phymode = MODE_11G;
  192. break;
  193. case NL80211_CHAN_WIDTH_20:
  194. phymode = MODE_11NG_HT20;
  195. break;
  196. case NL80211_CHAN_WIDTH_40:
  197. phymode = MODE_11NG_HT40;
  198. break;
  199. case NL80211_CHAN_WIDTH_5:
  200. case NL80211_CHAN_WIDTH_10:
  201. case NL80211_CHAN_WIDTH_80:
  202. case NL80211_CHAN_WIDTH_80P80:
  203. case NL80211_CHAN_WIDTH_160:
  204. phymode = MODE_UNKNOWN;
  205. break;
  206. }
  207. break;
  208. case IEEE80211_BAND_5GHZ:
  209. switch (chandef->width) {
  210. case NL80211_CHAN_WIDTH_20_NOHT:
  211. phymode = MODE_11A;
  212. break;
  213. case NL80211_CHAN_WIDTH_20:
  214. phymode = MODE_11NA_HT20;
  215. break;
  216. case NL80211_CHAN_WIDTH_40:
  217. phymode = MODE_11NA_HT40;
  218. break;
  219. case NL80211_CHAN_WIDTH_80:
  220. phymode = MODE_11AC_VHT80;
  221. break;
  222. case NL80211_CHAN_WIDTH_5:
  223. case NL80211_CHAN_WIDTH_10:
  224. case NL80211_CHAN_WIDTH_80P80:
  225. case NL80211_CHAN_WIDTH_160:
  226. phymode = MODE_UNKNOWN;
  227. break;
  228. }
  229. break;
  230. default:
  231. break;
  232. }
  233. WARN_ON(phymode == MODE_UNKNOWN);
  234. return phymode;
  235. }
  236. static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
  237. {
  238. /*
  239. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  240. * 0 for no restriction
  241. * 1 for 1/4 us
  242. * 2 for 1/2 us
  243. * 3 for 1 us
  244. * 4 for 2 us
  245. * 5 for 4 us
  246. * 6 for 8 us
  247. * 7 for 16 us
  248. */
  249. switch (mpdudensity) {
  250. case 0:
  251. return 0;
  252. case 1:
  253. case 2:
  254. case 3:
  255. /* Our lower layer calculations limit our precision to
  256. 1 microsecond */
  257. return 1;
  258. case 4:
  259. return 2;
  260. case 5:
  261. return 4;
  262. case 6:
  263. return 8;
  264. case 7:
  265. return 16;
  266. default:
  267. return 0;
  268. }
  269. }
  270. static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
  271. {
  272. int ret;
  273. lockdep_assert_held(&ar->conf_mutex);
  274. ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
  275. if (ret)
  276. return ret;
  277. ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
  278. if (ret)
  279. return ret;
  280. return 0;
  281. }
  282. static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
  283. {
  284. if (value != 0xFFFFFFFF)
  285. value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
  286. ATH10K_RTS_MAX);
  287. return ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
  288. WMI_VDEV_PARAM_RTS_THRESHOLD,
  289. value);
  290. }
  291. static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
  292. {
  293. if (value != 0xFFFFFFFF)
  294. value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
  295. ATH10K_FRAGMT_THRESHOLD_MIN,
  296. ATH10K_FRAGMT_THRESHOLD_MAX);
  297. return ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
  298. WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
  299. value);
  300. }
  301. static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
  302. {
  303. int ret;
  304. lockdep_assert_held(&ar->conf_mutex);
  305. ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
  306. if (ret)
  307. return ret;
  308. ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
  309. if (ret)
  310. return ret;
  311. return 0;
  312. }
  313. static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
  314. {
  315. struct ath10k_peer *peer, *tmp;
  316. lockdep_assert_held(&ar->conf_mutex);
  317. spin_lock_bh(&ar->data_lock);
  318. list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
  319. if (peer->vdev_id != vdev_id)
  320. continue;
  321. ath10k_warn("removing stale peer %pM from vdev_id %d\n",
  322. peer->addr, vdev_id);
  323. list_del(&peer->list);
  324. kfree(peer);
  325. }
  326. spin_unlock_bh(&ar->data_lock);
  327. }
  328. static void ath10k_peer_cleanup_all(struct ath10k *ar)
  329. {
  330. struct ath10k_peer *peer, *tmp;
  331. lockdep_assert_held(&ar->conf_mutex);
  332. spin_lock_bh(&ar->data_lock);
  333. list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
  334. list_del(&peer->list);
  335. kfree(peer);
  336. }
  337. spin_unlock_bh(&ar->data_lock);
  338. }
  339. /************************/
  340. /* Interface management */
  341. /************************/
  342. static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
  343. {
  344. int ret;
  345. lockdep_assert_held(&ar->conf_mutex);
  346. ret = wait_for_completion_timeout(&ar->vdev_setup_done,
  347. ATH10K_VDEV_SETUP_TIMEOUT_HZ);
  348. if (ret == 0)
  349. return -ETIMEDOUT;
  350. return 0;
  351. }
  352. static int ath10k_vdev_start(struct ath10k_vif *arvif)
  353. {
  354. struct ath10k *ar = arvif->ar;
  355. struct ieee80211_conf *conf = &ar->hw->conf;
  356. struct ieee80211_channel *channel = conf->chandef.chan;
  357. struct wmi_vdev_start_request_arg arg = {};
  358. int ret = 0;
  359. lockdep_assert_held(&ar->conf_mutex);
  360. INIT_COMPLETION(ar->vdev_setup_done);
  361. arg.vdev_id = arvif->vdev_id;
  362. arg.dtim_period = arvif->dtim_period;
  363. arg.bcn_intval = arvif->beacon_interval;
  364. arg.channel.freq = channel->center_freq;
  365. arg.channel.band_center_freq1 = conf->chandef.center_freq1;
  366. arg.channel.mode = chan_to_phymode(&conf->chandef);
  367. arg.channel.min_power = channel->max_power * 3;
  368. arg.channel.max_power = channel->max_power * 4;
  369. arg.channel.max_reg_power = channel->max_reg_power * 4;
  370. arg.channel.max_antenna_gain = channel->max_antenna_gain;
  371. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  372. arg.ssid = arvif->u.ap.ssid;
  373. arg.ssid_len = arvif->u.ap.ssid_len;
  374. arg.hidden_ssid = arvif->u.ap.hidden_ssid;
  375. } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
  376. arg.ssid = arvif->vif->bss_conf.ssid;
  377. arg.ssid_len = arvif->vif->bss_conf.ssid_len;
  378. }
  379. ath10k_dbg(ATH10K_DBG_MAC,
  380. "mac vdev %d start center_freq %d phymode %s\n",
  381. arg.vdev_id, arg.channel.freq,
  382. ath10k_wmi_phymode_str(arg.channel.mode));
  383. ret = ath10k_wmi_vdev_start(ar, &arg);
  384. if (ret) {
  385. ath10k_warn("WMI vdev start failed: ret %d\n", ret);
  386. return ret;
  387. }
  388. ret = ath10k_vdev_setup_sync(ar);
  389. if (ret) {
  390. ath10k_warn("vdev setup failed %d\n", ret);
  391. return ret;
  392. }
  393. return ret;
  394. }
  395. static int ath10k_vdev_stop(struct ath10k_vif *arvif)
  396. {
  397. struct ath10k *ar = arvif->ar;
  398. int ret;
  399. lockdep_assert_held(&ar->conf_mutex);
  400. INIT_COMPLETION(ar->vdev_setup_done);
  401. ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
  402. if (ret) {
  403. ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
  404. return ret;
  405. }
  406. ret = ath10k_vdev_setup_sync(ar);
  407. if (ret) {
  408. ath10k_warn("vdev setup failed %d\n", ret);
  409. return ret;
  410. }
  411. return ret;
  412. }
  413. static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
  414. {
  415. struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
  416. struct wmi_vdev_start_request_arg arg = {};
  417. int ret = 0;
  418. lockdep_assert_held(&ar->conf_mutex);
  419. arg.vdev_id = vdev_id;
  420. arg.channel.freq = channel->center_freq;
  421. arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
  422. /* TODO setup this dynamically, what in case we
  423. don't have any vifs? */
  424. arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
  425. arg.channel.min_power = channel->max_power * 3;
  426. arg.channel.max_power = channel->max_power * 4;
  427. arg.channel.max_reg_power = channel->max_reg_power * 4;
  428. arg.channel.max_antenna_gain = channel->max_antenna_gain;
  429. ret = ath10k_wmi_vdev_start(ar, &arg);
  430. if (ret) {
  431. ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
  432. return ret;
  433. }
  434. ret = ath10k_vdev_setup_sync(ar);
  435. if (ret) {
  436. ath10k_warn("Monitor vdev setup failed %d\n", ret);
  437. return ret;
  438. }
  439. ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
  440. if (ret) {
  441. ath10k_warn("Monitor vdev up failed: %d\n", ret);
  442. goto vdev_stop;
  443. }
  444. ar->monitor_vdev_id = vdev_id;
  445. ar->monitor_enabled = true;
  446. return 0;
  447. vdev_stop:
  448. ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
  449. if (ret)
  450. ath10k_warn("Monitor vdev stop failed: %d\n", ret);
  451. return ret;
  452. }
  453. static int ath10k_monitor_stop(struct ath10k *ar)
  454. {
  455. int ret = 0;
  456. lockdep_assert_held(&ar->conf_mutex);
  457. /* For some reasons, ath10k_wmi_vdev_down() here couse
  458. * often ath10k_wmi_vdev_stop() to fail. Next we could
  459. * not run monitor vdev and driver reload
  460. * required. Don't see such problems we skip
  461. * ath10k_wmi_vdev_down() here.
  462. */
  463. ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
  464. if (ret)
  465. ath10k_warn("Monitor vdev stop failed: %d\n", ret);
  466. ret = ath10k_vdev_setup_sync(ar);
  467. if (ret)
  468. ath10k_warn("Monitor_down sync failed: %d\n", ret);
  469. ar->monitor_enabled = false;
  470. return ret;
  471. }
  472. static int ath10k_monitor_create(struct ath10k *ar)
  473. {
  474. int bit, ret = 0;
  475. lockdep_assert_held(&ar->conf_mutex);
  476. if (ar->monitor_present) {
  477. ath10k_warn("Monitor mode already enabled\n");
  478. return 0;
  479. }
  480. bit = ffs(ar->free_vdev_map);
  481. if (bit == 0) {
  482. ath10k_warn("No free VDEV slots\n");
  483. return -ENOMEM;
  484. }
  485. ar->monitor_vdev_id = bit - 1;
  486. ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
  487. ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
  488. WMI_VDEV_TYPE_MONITOR,
  489. 0, ar->mac_addr);
  490. if (ret) {
  491. ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
  492. goto vdev_fail;
  493. }
  494. ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
  495. ar->monitor_vdev_id);
  496. ar->monitor_present = true;
  497. return 0;
  498. vdev_fail:
  499. /*
  500. * Restore the ID to the global map.
  501. */
  502. ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
  503. return ret;
  504. }
  505. static int ath10k_monitor_destroy(struct ath10k *ar)
  506. {
  507. int ret = 0;
  508. lockdep_assert_held(&ar->conf_mutex);
  509. if (!ar->monitor_present)
  510. return 0;
  511. ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
  512. if (ret) {
  513. ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
  514. return ret;
  515. }
  516. ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
  517. ar->monitor_present = false;
  518. ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
  519. ar->monitor_vdev_id);
  520. return ret;
  521. }
  522. static void ath10k_control_beaconing(struct ath10k_vif *arvif,
  523. struct ieee80211_bss_conf *info)
  524. {
  525. int ret = 0;
  526. lockdep_assert_held(&arvif->ar->conf_mutex);
  527. if (!info->enable_beacon) {
  528. ath10k_vdev_stop(arvif);
  529. return;
  530. }
  531. arvif->tx_seq_no = 0x1000;
  532. ret = ath10k_vdev_start(arvif);
  533. if (ret)
  534. return;
  535. ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
  536. if (ret) {
  537. ath10k_warn("Failed to bring up VDEV: %d\n",
  538. arvif->vdev_id);
  539. return;
  540. }
  541. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
  542. }
  543. static void ath10k_control_ibss(struct ath10k_vif *arvif,
  544. struct ieee80211_bss_conf *info,
  545. const u8 self_peer[ETH_ALEN])
  546. {
  547. int ret = 0;
  548. lockdep_assert_held(&arvif->ar->conf_mutex);
  549. if (!info->ibss_joined) {
  550. ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
  551. if (ret)
  552. ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
  553. self_peer, arvif->vdev_id, ret);
  554. if (is_zero_ether_addr(arvif->u.ibss.bssid))
  555. return;
  556. ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
  557. arvif->u.ibss.bssid);
  558. if (ret) {
  559. ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
  560. arvif->u.ibss.bssid, arvif->vdev_id, ret);
  561. return;
  562. }
  563. memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
  564. return;
  565. }
  566. ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
  567. if (ret) {
  568. ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
  569. self_peer, arvif->vdev_id, ret);
  570. return;
  571. }
  572. ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
  573. WMI_VDEV_PARAM_ATIM_WINDOW,
  574. ATH10K_DEFAULT_ATIM);
  575. if (ret)
  576. ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
  577. arvif->vdev_id, ret);
  578. }
  579. /*
  580. * Review this when mac80211 gains per-interface powersave support.
  581. */
  582. static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  583. {
  584. struct ath10k_generic_iter *ar_iter = data;
  585. struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
  586. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  587. enum wmi_sta_powersave_param param;
  588. enum wmi_sta_ps_mode psmode;
  589. int ret;
  590. lockdep_assert_held(&arvif->ar->conf_mutex);
  591. if (vif->type != NL80211_IFTYPE_STATION)
  592. return;
  593. if (conf->flags & IEEE80211_CONF_PS) {
  594. psmode = WMI_STA_PS_MODE_ENABLED;
  595. param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
  596. ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
  597. arvif->vdev_id,
  598. param,
  599. conf->dynamic_ps_timeout);
  600. if (ret) {
  601. ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
  602. arvif->vdev_id);
  603. return;
  604. }
  605. ar_iter->ret = ret;
  606. } else {
  607. psmode = WMI_STA_PS_MODE_DISABLED;
  608. }
  609. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
  610. arvif->vdev_id, psmode ? "enable" : "disable");
  611. ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
  612. psmode);
  613. if (ar_iter->ret)
  614. ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
  615. psmode, arvif->vdev_id);
  616. }
  617. /**********************/
  618. /* Station management */
  619. /**********************/
  620. static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
  621. struct ath10k_vif *arvif,
  622. struct ieee80211_sta *sta,
  623. struct ieee80211_bss_conf *bss_conf,
  624. struct wmi_peer_assoc_complete_arg *arg)
  625. {
  626. lockdep_assert_held(&ar->conf_mutex);
  627. memcpy(arg->addr, sta->addr, ETH_ALEN);
  628. arg->vdev_id = arvif->vdev_id;
  629. arg->peer_aid = sta->aid;
  630. arg->peer_flags |= WMI_PEER_AUTH;
  631. if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
  632. /*
  633. * Seems FW have problems with Power Save in STA
  634. * mode when we setup this parameter to high (eg. 5).
  635. * Often we see that FW don't send NULL (with clean P flags)
  636. * frame even there is info about buffered frames in beacons.
  637. * Sometimes we have to wait more than 10 seconds before FW
  638. * will wakeup. Often sending one ping from AP to our device
  639. * just fail (more than 50%).
  640. *
  641. * Seems setting this FW parameter to 1 couse FW
  642. * will check every beacon and will wakup immediately
  643. * after detection buffered data.
  644. */
  645. arg->peer_listen_intval = 1;
  646. else
  647. arg->peer_listen_intval = ar->hw->conf.listen_interval;
  648. arg->peer_num_spatial_streams = 1;
  649. /*
  650. * The assoc capabilities are available only in managed mode.
  651. */
  652. if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
  653. arg->peer_caps = bss_conf->assoc_capability;
  654. }
  655. static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
  656. struct ath10k_vif *arvif,
  657. struct wmi_peer_assoc_complete_arg *arg)
  658. {
  659. struct ieee80211_vif *vif = arvif->vif;
  660. struct ieee80211_bss_conf *info = &vif->bss_conf;
  661. struct cfg80211_bss *bss;
  662. const u8 *rsnie = NULL;
  663. const u8 *wpaie = NULL;
  664. lockdep_assert_held(&ar->conf_mutex);
  665. bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
  666. info->bssid, NULL, 0, 0, 0);
  667. if (bss) {
  668. const struct cfg80211_bss_ies *ies;
  669. rcu_read_lock();
  670. rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
  671. ies = rcu_dereference(bss->ies);
  672. wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
  673. WLAN_OUI_TYPE_MICROSOFT_WPA,
  674. ies->data,
  675. ies->len);
  676. rcu_read_unlock();
  677. cfg80211_put_bss(ar->hw->wiphy, bss);
  678. }
  679. /* FIXME: base on RSN IE/WPA IE is a correct idea? */
  680. if (rsnie || wpaie) {
  681. ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
  682. arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
  683. }
  684. if (wpaie) {
  685. ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
  686. arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
  687. }
  688. }
  689. static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
  690. struct ieee80211_sta *sta,
  691. struct wmi_peer_assoc_complete_arg *arg)
  692. {
  693. struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
  694. const struct ieee80211_supported_band *sband;
  695. const struct ieee80211_rate *rates;
  696. u32 ratemask;
  697. int i;
  698. lockdep_assert_held(&ar->conf_mutex);
  699. sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
  700. ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
  701. rates = sband->bitrates;
  702. rateset->num_rates = 0;
  703. for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
  704. if (!(ratemask & 1))
  705. continue;
  706. rateset->rates[rateset->num_rates] = rates->hw_value;
  707. rateset->num_rates++;
  708. }
  709. }
  710. static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
  711. struct ieee80211_sta *sta,
  712. struct wmi_peer_assoc_complete_arg *arg)
  713. {
  714. const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  715. int smps;
  716. int i, n;
  717. lockdep_assert_held(&ar->conf_mutex);
  718. if (!ht_cap->ht_supported)
  719. return;
  720. arg->peer_flags |= WMI_PEER_HT;
  721. arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  722. ht_cap->ampdu_factor)) - 1;
  723. arg->peer_mpdu_density =
  724. ath10k_parse_mpdudensity(ht_cap->ampdu_density);
  725. arg->peer_ht_caps = ht_cap->cap;
  726. arg->peer_rate_caps |= WMI_RC_HT_FLAG;
  727. if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
  728. arg->peer_flags |= WMI_PEER_LDPC;
  729. if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
  730. arg->peer_flags |= WMI_PEER_40MHZ;
  731. arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
  732. }
  733. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
  734. arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
  735. if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
  736. arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
  737. if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
  738. arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
  739. arg->peer_flags |= WMI_PEER_STBC;
  740. }
  741. if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
  742. u32 stbc;
  743. stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
  744. stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
  745. stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
  746. arg->peer_rate_caps |= stbc;
  747. arg->peer_flags |= WMI_PEER_STBC;
  748. }
  749. smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
  750. smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
  751. if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
  752. arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
  753. arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
  754. } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
  755. arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
  756. arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
  757. }
  758. if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
  759. arg->peer_rate_caps |= WMI_RC_TS_FLAG;
  760. else if (ht_cap->mcs.rx_mask[1])
  761. arg->peer_rate_caps |= WMI_RC_DS_FLAG;
  762. for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
  763. if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
  764. arg->peer_ht_rates.rates[n++] = i;
  765. arg->peer_ht_rates.num_rates = n;
  766. arg->peer_num_spatial_streams = max((n+7) / 8, 1);
  767. ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
  768. arg->addr,
  769. arg->peer_ht_rates.num_rates,
  770. arg->peer_num_spatial_streams);
  771. }
  772. static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
  773. struct ath10k_vif *arvif,
  774. struct ieee80211_sta *sta,
  775. struct ieee80211_bss_conf *bss_conf,
  776. struct wmi_peer_assoc_complete_arg *arg)
  777. {
  778. u32 uapsd = 0;
  779. u32 max_sp = 0;
  780. lockdep_assert_held(&ar->conf_mutex);
  781. if (sta->wme)
  782. arg->peer_flags |= WMI_PEER_QOS;
  783. if (sta->wme && sta->uapsd_queues) {
  784. ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
  785. sta->uapsd_queues, sta->max_sp);
  786. arg->peer_flags |= WMI_PEER_APSD;
  787. arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
  788. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  789. uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
  790. WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
  791. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  792. uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
  793. WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
  794. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  795. uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
  796. WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
  797. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  798. uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
  799. WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
  800. if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
  801. max_sp = sta->max_sp;
  802. ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
  803. sta->addr,
  804. WMI_AP_PS_PEER_PARAM_UAPSD,
  805. uapsd);
  806. ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
  807. sta->addr,
  808. WMI_AP_PS_PEER_PARAM_MAX_SP,
  809. max_sp);
  810. /* TODO setup this based on STA listen interval and
  811. beacon interval. Currently we don't know
  812. sta->listen_interval - mac80211 patch required.
  813. Currently use 10 seconds */
  814. ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
  815. sta->addr,
  816. WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
  817. 10);
  818. }
  819. }
  820. static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
  821. struct ath10k_vif *arvif,
  822. struct ieee80211_sta *sta,
  823. struct ieee80211_bss_conf *bss_conf,
  824. struct wmi_peer_assoc_complete_arg *arg)
  825. {
  826. if (bss_conf->qos)
  827. arg->peer_flags |= WMI_PEER_QOS;
  828. }
  829. static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
  830. struct ieee80211_sta *sta,
  831. struct wmi_peer_assoc_complete_arg *arg)
  832. {
  833. const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
  834. if (!vht_cap->vht_supported)
  835. return;
  836. arg->peer_flags |= WMI_PEER_VHT;
  837. arg->peer_vht_caps = vht_cap->cap;
  838. if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
  839. arg->peer_flags |= WMI_PEER_80MHZ;
  840. arg->peer_vht_rates.rx_max_rate =
  841. __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
  842. arg->peer_vht_rates.rx_mcs_set =
  843. __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
  844. arg->peer_vht_rates.tx_max_rate =
  845. __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
  846. arg->peer_vht_rates.tx_mcs_set =
  847. __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
  848. ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
  849. sta->addr, arg->peer_max_mpdu, arg->peer_flags);
  850. }
  851. static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
  852. struct ath10k_vif *arvif,
  853. struct ieee80211_sta *sta,
  854. struct ieee80211_bss_conf *bss_conf,
  855. struct wmi_peer_assoc_complete_arg *arg)
  856. {
  857. switch (arvif->vdev_type) {
  858. case WMI_VDEV_TYPE_AP:
  859. ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
  860. break;
  861. case WMI_VDEV_TYPE_STA:
  862. ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
  863. break;
  864. default:
  865. break;
  866. }
  867. }
  868. static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
  869. struct ath10k_vif *arvif,
  870. struct ieee80211_sta *sta,
  871. struct wmi_peer_assoc_complete_arg *arg)
  872. {
  873. enum wmi_phy_mode phymode = MODE_UNKNOWN;
  874. switch (ar->hw->conf.chandef.chan->band) {
  875. case IEEE80211_BAND_2GHZ:
  876. if (sta->ht_cap.ht_supported) {
  877. if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
  878. phymode = MODE_11NG_HT40;
  879. else
  880. phymode = MODE_11NG_HT20;
  881. } else {
  882. phymode = MODE_11G;
  883. }
  884. break;
  885. case IEEE80211_BAND_5GHZ:
  886. /*
  887. * Check VHT first.
  888. */
  889. if (sta->vht_cap.vht_supported) {
  890. if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
  891. phymode = MODE_11AC_VHT80;
  892. else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
  893. phymode = MODE_11AC_VHT40;
  894. else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
  895. phymode = MODE_11AC_VHT20;
  896. } else if (sta->ht_cap.ht_supported) {
  897. if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
  898. phymode = MODE_11NA_HT40;
  899. else
  900. phymode = MODE_11NA_HT20;
  901. } else {
  902. phymode = MODE_11A;
  903. }
  904. break;
  905. default:
  906. break;
  907. }
  908. ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
  909. sta->addr, ath10k_wmi_phymode_str(phymode));
  910. arg->peer_phymode = phymode;
  911. WARN_ON(phymode == MODE_UNKNOWN);
  912. }
  913. static int ath10k_peer_assoc(struct ath10k *ar,
  914. struct ath10k_vif *arvif,
  915. struct ieee80211_sta *sta,
  916. struct ieee80211_bss_conf *bss_conf)
  917. {
  918. struct wmi_peer_assoc_complete_arg arg;
  919. lockdep_assert_held(&ar->conf_mutex);
  920. memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
  921. ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
  922. ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
  923. ath10k_peer_assoc_h_rates(ar, sta, &arg);
  924. ath10k_peer_assoc_h_ht(ar, sta, &arg);
  925. ath10k_peer_assoc_h_vht(ar, sta, &arg);
  926. ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
  927. ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
  928. return ath10k_wmi_peer_assoc(ar, &arg);
  929. }
  930. /* can be called only in mac80211 callbacks due to `key_count` usage */
  931. static void ath10k_bss_assoc(struct ieee80211_hw *hw,
  932. struct ieee80211_vif *vif,
  933. struct ieee80211_bss_conf *bss_conf)
  934. {
  935. struct ath10k *ar = hw->priv;
  936. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  937. struct ieee80211_sta *ap_sta;
  938. int ret;
  939. lockdep_assert_held(&ar->conf_mutex);
  940. rcu_read_lock();
  941. ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
  942. if (!ap_sta) {
  943. ath10k_warn("Failed to find station entry for %pM\n",
  944. bss_conf->bssid);
  945. rcu_read_unlock();
  946. return;
  947. }
  948. ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
  949. if (ret) {
  950. ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
  951. rcu_read_unlock();
  952. return;
  953. }
  954. rcu_read_unlock();
  955. ath10k_dbg(ATH10K_DBG_MAC,
  956. "mac vdev %d up (associated) bssid %pM aid %d\n",
  957. arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
  958. ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
  959. bss_conf->bssid);
  960. if (ret)
  961. ath10k_warn("VDEV: %d up failed: ret %d\n",
  962. arvif->vdev_id, ret);
  963. }
  964. /*
  965. * FIXME: flush TIDs
  966. */
  967. static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
  968. struct ieee80211_vif *vif)
  969. {
  970. struct ath10k *ar = hw->priv;
  971. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  972. int ret;
  973. lockdep_assert_held(&ar->conf_mutex);
  974. /*
  975. * For some reason, calling VDEV-DOWN before VDEV-STOP
  976. * makes the FW to send frames via HTT after disassociation.
  977. * No idea why this happens, even though VDEV-DOWN is supposed
  978. * to be analogous to link down, so just stop the VDEV.
  979. */
  980. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
  981. arvif->vdev_id);
  982. /* FIXME: check return value */
  983. ret = ath10k_vdev_stop(arvif);
  984. /*
  985. * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
  986. * report beacons from previously associated network through HTT.
  987. * This in turn would spam mac80211 WARN_ON if we bring down all
  988. * interfaces as it expects there is no rx when no interface is
  989. * running.
  990. */
  991. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
  992. /* FIXME: why don't we print error if wmi call fails? */
  993. ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
  994. arvif->def_wep_key_index = 0;
  995. }
  996. static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
  997. struct ieee80211_sta *sta)
  998. {
  999. int ret = 0;
  1000. lockdep_assert_held(&ar->conf_mutex);
  1001. ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
  1002. if (ret) {
  1003. ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
  1004. return ret;
  1005. }
  1006. ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
  1007. if (ret) {
  1008. ath10k_warn("could not install peer wep keys (%d)\n", ret);
  1009. return ret;
  1010. }
  1011. return ret;
  1012. }
  1013. static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
  1014. struct ieee80211_sta *sta)
  1015. {
  1016. int ret = 0;
  1017. lockdep_assert_held(&ar->conf_mutex);
  1018. ret = ath10k_clear_peer_keys(arvif, sta->addr);
  1019. if (ret) {
  1020. ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
  1021. return ret;
  1022. }
  1023. return ret;
  1024. }
  1025. /**************/
  1026. /* Regulatory */
  1027. /**************/
  1028. static int ath10k_update_channel_list(struct ath10k *ar)
  1029. {
  1030. struct ieee80211_hw *hw = ar->hw;
  1031. struct ieee80211_supported_band **bands;
  1032. enum ieee80211_band band;
  1033. struct ieee80211_channel *channel;
  1034. struct wmi_scan_chan_list_arg arg = {0};
  1035. struct wmi_channel_arg *ch;
  1036. bool passive;
  1037. int len;
  1038. int ret;
  1039. int i;
  1040. lockdep_assert_held(&ar->conf_mutex);
  1041. bands = hw->wiphy->bands;
  1042. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1043. if (!bands[band])
  1044. continue;
  1045. for (i = 0; i < bands[band]->n_channels; i++) {
  1046. if (bands[band]->channels[i].flags &
  1047. IEEE80211_CHAN_DISABLED)
  1048. continue;
  1049. arg.n_channels++;
  1050. }
  1051. }
  1052. len = sizeof(struct wmi_channel_arg) * arg.n_channels;
  1053. arg.channels = kzalloc(len, GFP_KERNEL);
  1054. if (!arg.channels)
  1055. return -ENOMEM;
  1056. ch = arg.channels;
  1057. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1058. if (!bands[band])
  1059. continue;
  1060. for (i = 0; i < bands[band]->n_channels; i++) {
  1061. channel = &bands[band]->channels[i];
  1062. if (channel->flags & IEEE80211_CHAN_DISABLED)
  1063. continue;
  1064. ch->allow_ht = true;
  1065. /* FIXME: when should we really allow VHT? */
  1066. ch->allow_vht = true;
  1067. ch->allow_ibss =
  1068. !(channel->flags & IEEE80211_CHAN_NO_IBSS);
  1069. ch->ht40plus =
  1070. !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
  1071. passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
  1072. ch->passive = passive;
  1073. ch->freq = channel->center_freq;
  1074. ch->min_power = channel->max_power * 3;
  1075. ch->max_power = channel->max_power * 4;
  1076. ch->max_reg_power = channel->max_reg_power * 4;
  1077. ch->max_antenna_gain = channel->max_antenna_gain;
  1078. ch->reg_class_id = 0; /* FIXME */
  1079. /* FIXME: why use only legacy modes, why not any
  1080. * HT/VHT modes? Would that even make any
  1081. * difference? */
  1082. if (channel->band == IEEE80211_BAND_2GHZ)
  1083. ch->mode = MODE_11G;
  1084. else
  1085. ch->mode = MODE_11A;
  1086. if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
  1087. continue;
  1088. ath10k_dbg(ATH10K_DBG_WMI,
  1089. "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
  1090. ch - arg.channels, arg.n_channels,
  1091. ch->freq, ch->max_power, ch->max_reg_power,
  1092. ch->max_antenna_gain, ch->mode);
  1093. ch++;
  1094. }
  1095. }
  1096. ret = ath10k_wmi_scan_chan_list(ar, &arg);
  1097. kfree(arg.channels);
  1098. return ret;
  1099. }
  1100. static void ath10k_regd_update(struct ath10k *ar)
  1101. {
  1102. struct reg_dmn_pair_mapping *regpair;
  1103. int ret;
  1104. lockdep_assert_held(&ar->conf_mutex);
  1105. ret = ath10k_update_channel_list(ar);
  1106. if (ret)
  1107. ath10k_warn("could not update channel list (%d)\n", ret);
  1108. regpair = ar->ath_common.regulatory.regpair;
  1109. /* Target allows setting up per-band regdomain but ath_common provides
  1110. * a combined one only */
  1111. ret = ath10k_wmi_pdev_set_regdomain(ar,
  1112. regpair->regDmnEnum,
  1113. regpair->regDmnEnum, /* 2ghz */
  1114. regpair->regDmnEnum, /* 5ghz */
  1115. regpair->reg_2ghz_ctl,
  1116. regpair->reg_5ghz_ctl);
  1117. if (ret)
  1118. ath10k_warn("could not set pdev regdomain (%d)\n", ret);
  1119. }
  1120. static void ath10k_reg_notifier(struct wiphy *wiphy,
  1121. struct regulatory_request *request)
  1122. {
  1123. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  1124. struct ath10k *ar = hw->priv;
  1125. ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
  1126. mutex_lock(&ar->conf_mutex);
  1127. if (ar->state == ATH10K_STATE_ON)
  1128. ath10k_regd_update(ar);
  1129. mutex_unlock(&ar->conf_mutex);
  1130. }
  1131. /***************/
  1132. /* TX handlers */
  1133. /***************/
  1134. /*
  1135. * Frames sent to the FW have to be in "Native Wifi" format.
  1136. * Strip the QoS field from the 802.11 header.
  1137. */
  1138. static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
  1139. struct ieee80211_tx_control *control,
  1140. struct sk_buff *skb)
  1141. {
  1142. struct ieee80211_hdr *hdr = (void *)skb->data;
  1143. u8 *qos_ctl;
  1144. if (!ieee80211_is_data_qos(hdr->frame_control))
  1145. return;
  1146. qos_ctl = ieee80211_get_qos_ctl(hdr);
  1147. memmove(skb->data + IEEE80211_QOS_CTL_LEN,
  1148. skb->data, (void *)qos_ctl - (void *)skb->data);
  1149. skb_pull(skb, IEEE80211_QOS_CTL_LEN);
  1150. }
  1151. static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
  1152. {
  1153. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1154. struct ieee80211_vif *vif = info->control.vif;
  1155. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1156. struct ath10k *ar = arvif->ar;
  1157. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1158. struct ieee80211_key_conf *key = info->control.hw_key;
  1159. int ret;
  1160. if (!ieee80211_has_protected(hdr->frame_control))
  1161. return;
  1162. if (!key)
  1163. return;
  1164. if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
  1165. key->cipher != WLAN_CIPHER_SUITE_WEP104)
  1166. return;
  1167. if (key->keyidx == arvif->def_wep_key_index)
  1168. return;
  1169. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d keyidx %d\n",
  1170. arvif->vdev_id, key->keyidx);
  1171. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  1172. WMI_VDEV_PARAM_DEF_KEYID,
  1173. key->keyidx);
  1174. if (ret) {
  1175. ath10k_warn("could not update wep keyidx (%d)\n", ret);
  1176. return;
  1177. }
  1178. arvif->def_wep_key_index = key->keyidx;
  1179. }
  1180. static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
  1181. {
  1182. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1183. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1184. struct ieee80211_vif *vif = info->control.vif;
  1185. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1186. /* This is case only for P2P_GO */
  1187. if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
  1188. arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
  1189. return;
  1190. if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
  1191. spin_lock_bh(&ar->data_lock);
  1192. if (arvif->u.ap.noa_data)
  1193. if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
  1194. GFP_ATOMIC))
  1195. memcpy(skb_put(skb, arvif->u.ap.noa_len),
  1196. arvif->u.ap.noa_data,
  1197. arvif->u.ap.noa_len);
  1198. spin_unlock_bh(&ar->data_lock);
  1199. }
  1200. }
  1201. static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
  1202. {
  1203. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1204. int ret;
  1205. if (ar->htt.target_version_major >= 3) {
  1206. /* Since HTT 3.0 there is no separate mgmt tx command */
  1207. ret = ath10k_htt_tx(&ar->htt, skb);
  1208. goto exit;
  1209. }
  1210. if (ieee80211_is_mgmt(hdr->frame_control))
  1211. ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
  1212. else if (ieee80211_is_nullfunc(hdr->frame_control))
  1213. /* FW does not report tx status properly for NullFunc frames
  1214. * unless they are sent through mgmt tx path. mac80211 sends
  1215. * those frames when it detects link/beacon loss and depends on
  1216. * the tx status to be correct. */
  1217. ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
  1218. else
  1219. ret = ath10k_htt_tx(&ar->htt, skb);
  1220. exit:
  1221. if (ret) {
  1222. ath10k_warn("tx failed (%d). dropping packet.\n", ret);
  1223. ieee80211_free_txskb(ar->hw, skb);
  1224. }
  1225. }
  1226. void ath10k_offchan_tx_purge(struct ath10k *ar)
  1227. {
  1228. struct sk_buff *skb;
  1229. for (;;) {
  1230. skb = skb_dequeue(&ar->offchan_tx_queue);
  1231. if (!skb)
  1232. break;
  1233. ieee80211_free_txskb(ar->hw, skb);
  1234. }
  1235. }
  1236. void ath10k_offchan_tx_work(struct work_struct *work)
  1237. {
  1238. struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
  1239. struct ath10k_peer *peer;
  1240. struct ieee80211_hdr *hdr;
  1241. struct sk_buff *skb;
  1242. const u8 *peer_addr;
  1243. int vdev_id;
  1244. int ret;
  1245. /* FW requirement: We must create a peer before FW will send out
  1246. * an offchannel frame. Otherwise the frame will be stuck and
  1247. * never transmitted. We delete the peer upon tx completion.
  1248. * It is unlikely that a peer for offchannel tx will already be
  1249. * present. However it may be in some rare cases so account for that.
  1250. * Otherwise we might remove a legitimate peer and break stuff. */
  1251. for (;;) {
  1252. skb = skb_dequeue(&ar->offchan_tx_queue);
  1253. if (!skb)
  1254. break;
  1255. mutex_lock(&ar->conf_mutex);
  1256. ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
  1257. skb);
  1258. hdr = (struct ieee80211_hdr *)skb->data;
  1259. peer_addr = ieee80211_get_DA(hdr);
  1260. vdev_id = ATH10K_SKB_CB(skb)->htt.vdev_id;
  1261. spin_lock_bh(&ar->data_lock);
  1262. peer = ath10k_peer_find(ar, vdev_id, peer_addr);
  1263. spin_unlock_bh(&ar->data_lock);
  1264. if (peer)
  1265. /* FIXME: should this use ath10k_warn()? */
  1266. ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
  1267. peer_addr, vdev_id);
  1268. if (!peer) {
  1269. ret = ath10k_peer_create(ar, vdev_id, peer_addr);
  1270. if (ret)
  1271. ath10k_warn("peer %pM on vdev %d not created (%d)\n",
  1272. peer_addr, vdev_id, ret);
  1273. }
  1274. spin_lock_bh(&ar->data_lock);
  1275. INIT_COMPLETION(ar->offchan_tx_completed);
  1276. ar->offchan_tx_skb = skb;
  1277. spin_unlock_bh(&ar->data_lock);
  1278. ath10k_tx_htt(ar, skb);
  1279. ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
  1280. 3 * HZ);
  1281. if (ret <= 0)
  1282. ath10k_warn("timed out waiting for offchannel skb %p\n",
  1283. skb);
  1284. if (!peer) {
  1285. ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
  1286. if (ret)
  1287. ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
  1288. peer_addr, vdev_id, ret);
  1289. }
  1290. mutex_unlock(&ar->conf_mutex);
  1291. }
  1292. }
  1293. /************/
  1294. /* Scanning */
  1295. /************/
  1296. /*
  1297. * This gets called if we dont get a heart-beat during scan.
  1298. * This may indicate the FW has hung and we need to abort the
  1299. * scan manually to prevent cancel_hw_scan() from deadlocking
  1300. */
  1301. void ath10k_reset_scan(unsigned long ptr)
  1302. {
  1303. struct ath10k *ar = (struct ath10k *)ptr;
  1304. spin_lock_bh(&ar->data_lock);
  1305. if (!ar->scan.in_progress) {
  1306. spin_unlock_bh(&ar->data_lock);
  1307. return;
  1308. }
  1309. ath10k_warn("scan timeout. resetting. fw issue?\n");
  1310. if (ar->scan.is_roc)
  1311. ieee80211_remain_on_channel_expired(ar->hw);
  1312. else
  1313. ieee80211_scan_completed(ar->hw, 1 /* aborted */);
  1314. ar->scan.in_progress = false;
  1315. complete_all(&ar->scan.completed);
  1316. spin_unlock_bh(&ar->data_lock);
  1317. }
  1318. static int ath10k_abort_scan(struct ath10k *ar)
  1319. {
  1320. struct wmi_stop_scan_arg arg = {
  1321. .req_id = 1, /* FIXME */
  1322. .req_type = WMI_SCAN_STOP_ONE,
  1323. .u.scan_id = ATH10K_SCAN_ID,
  1324. };
  1325. int ret;
  1326. lockdep_assert_held(&ar->conf_mutex);
  1327. del_timer_sync(&ar->scan.timeout);
  1328. spin_lock_bh(&ar->data_lock);
  1329. if (!ar->scan.in_progress) {
  1330. spin_unlock_bh(&ar->data_lock);
  1331. return 0;
  1332. }
  1333. ar->scan.aborting = true;
  1334. spin_unlock_bh(&ar->data_lock);
  1335. ret = ath10k_wmi_stop_scan(ar, &arg);
  1336. if (ret) {
  1337. ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
  1338. spin_lock_bh(&ar->data_lock);
  1339. ar->scan.in_progress = false;
  1340. ath10k_offchan_tx_purge(ar);
  1341. spin_unlock_bh(&ar->data_lock);
  1342. return -EIO;
  1343. }
  1344. ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
  1345. if (ret == 0)
  1346. ath10k_warn("timed out while waiting for scan to stop\n");
  1347. /* scan completion may be done right after we timeout here, so let's
  1348. * check the in_progress and tell mac80211 scan is completed. if we
  1349. * don't do that and FW fails to send us scan completion indication
  1350. * then userspace won't be able to scan anymore */
  1351. ret = 0;
  1352. spin_lock_bh(&ar->data_lock);
  1353. if (ar->scan.in_progress) {
  1354. ath10k_warn("could not stop scan. its still in progress\n");
  1355. ar->scan.in_progress = false;
  1356. ath10k_offchan_tx_purge(ar);
  1357. ret = -ETIMEDOUT;
  1358. }
  1359. spin_unlock_bh(&ar->data_lock);
  1360. return ret;
  1361. }
  1362. static int ath10k_start_scan(struct ath10k *ar,
  1363. const struct wmi_start_scan_arg *arg)
  1364. {
  1365. int ret;
  1366. lockdep_assert_held(&ar->conf_mutex);
  1367. ret = ath10k_wmi_start_scan(ar, arg);
  1368. if (ret)
  1369. return ret;
  1370. ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
  1371. if (ret == 0) {
  1372. ath10k_abort_scan(ar);
  1373. return ret;
  1374. }
  1375. /* the scan can complete earlier, before we even
  1376. * start the timer. in that case the timer handler
  1377. * checks ar->scan.in_progress and bails out if its
  1378. * false. Add a 200ms margin to account event/command
  1379. * processing. */
  1380. mod_timer(&ar->scan.timeout, jiffies +
  1381. msecs_to_jiffies(arg->max_scan_time+200));
  1382. return 0;
  1383. }
  1384. /**********************/
  1385. /* mac80211 callbacks */
  1386. /**********************/
  1387. static void ath10k_tx(struct ieee80211_hw *hw,
  1388. struct ieee80211_tx_control *control,
  1389. struct sk_buff *skb)
  1390. {
  1391. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1392. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1393. struct ath10k *ar = hw->priv;
  1394. struct ath10k_vif *arvif = NULL;
  1395. u32 vdev_id = 0;
  1396. u8 tid;
  1397. if (info->control.vif) {
  1398. arvif = ath10k_vif_to_arvif(info->control.vif);
  1399. vdev_id = arvif->vdev_id;
  1400. } else if (ar->monitor_enabled) {
  1401. vdev_id = ar->monitor_vdev_id;
  1402. }
  1403. /* We should disable CCK RATE due to P2P */
  1404. if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
  1405. ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
  1406. /* we must calculate tid before we apply qos workaround
  1407. * as we'd lose the qos control field */
  1408. tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
  1409. if (ieee80211_is_mgmt(hdr->frame_control)) {
  1410. tid = HTT_DATA_TX_EXT_TID_MGMT;
  1411. } else if (ieee80211_is_data_qos(hdr->frame_control) &&
  1412. is_unicast_ether_addr(ieee80211_get_DA(hdr))) {
  1413. u8 *qc = ieee80211_get_qos_ctl(hdr);
  1414. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  1415. }
  1416. /* it makes no sense to process injected frames like that */
  1417. if (info->control.vif &&
  1418. info->control.vif->type != NL80211_IFTYPE_MONITOR) {
  1419. ath10k_tx_h_qos_workaround(hw, control, skb);
  1420. ath10k_tx_h_update_wep_key(skb);
  1421. ath10k_tx_h_add_p2p_noa_ie(ar, skb);
  1422. ath10k_tx_h_seq_no(skb);
  1423. }
  1424. ATH10K_SKB_CB(skb)->htt.is_offchan = false;
  1425. ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id;
  1426. ATH10K_SKB_CB(skb)->htt.tid = tid;
  1427. if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
  1428. spin_lock_bh(&ar->data_lock);
  1429. ATH10K_SKB_CB(skb)->htt.is_offchan = true;
  1430. ATH10K_SKB_CB(skb)->htt.vdev_id = ar->scan.vdev_id;
  1431. spin_unlock_bh(&ar->data_lock);
  1432. ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
  1433. skb_queue_tail(&ar->offchan_tx_queue, skb);
  1434. ieee80211_queue_work(hw, &ar->offchan_tx_work);
  1435. return;
  1436. }
  1437. ath10k_tx_htt(ar, skb);
  1438. }
  1439. /*
  1440. * Initialize various parameters with default vaules.
  1441. */
  1442. void ath10k_halt(struct ath10k *ar)
  1443. {
  1444. lockdep_assert_held(&ar->conf_mutex);
  1445. del_timer_sync(&ar->scan.timeout);
  1446. ath10k_offchan_tx_purge(ar);
  1447. ath10k_peer_cleanup_all(ar);
  1448. ath10k_core_stop(ar);
  1449. ath10k_hif_power_down(ar);
  1450. spin_lock_bh(&ar->data_lock);
  1451. if (ar->scan.in_progress) {
  1452. del_timer(&ar->scan.timeout);
  1453. ar->scan.in_progress = false;
  1454. ieee80211_scan_completed(ar->hw, true);
  1455. }
  1456. spin_unlock_bh(&ar->data_lock);
  1457. }
  1458. static int ath10k_start(struct ieee80211_hw *hw)
  1459. {
  1460. struct ath10k *ar = hw->priv;
  1461. int ret = 0;
  1462. mutex_lock(&ar->conf_mutex);
  1463. if (ar->state != ATH10K_STATE_OFF &&
  1464. ar->state != ATH10K_STATE_RESTARTING) {
  1465. ret = -EINVAL;
  1466. goto exit;
  1467. }
  1468. ret = ath10k_hif_power_up(ar);
  1469. if (ret) {
  1470. ath10k_err("could not init hif (%d)\n", ret);
  1471. ar->state = ATH10K_STATE_OFF;
  1472. goto exit;
  1473. }
  1474. ret = ath10k_core_start(ar);
  1475. if (ret) {
  1476. ath10k_err("could not init core (%d)\n", ret);
  1477. ath10k_hif_power_down(ar);
  1478. ar->state = ATH10K_STATE_OFF;
  1479. goto exit;
  1480. }
  1481. if (ar->state == ATH10K_STATE_OFF)
  1482. ar->state = ATH10K_STATE_ON;
  1483. else if (ar->state == ATH10K_STATE_RESTARTING)
  1484. ar->state = ATH10K_STATE_RESTARTED;
  1485. ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 1);
  1486. if (ret)
  1487. ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
  1488. ret);
  1489. ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 0);
  1490. if (ret)
  1491. ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
  1492. ret);
  1493. ath10k_regd_update(ar);
  1494. exit:
  1495. mutex_unlock(&ar->conf_mutex);
  1496. return 0;
  1497. }
  1498. static void ath10k_stop(struct ieee80211_hw *hw)
  1499. {
  1500. struct ath10k *ar = hw->priv;
  1501. mutex_lock(&ar->conf_mutex);
  1502. if (ar->state == ATH10K_STATE_ON ||
  1503. ar->state == ATH10K_STATE_RESTARTED ||
  1504. ar->state == ATH10K_STATE_WEDGED)
  1505. ath10k_halt(ar);
  1506. ar->state = ATH10K_STATE_OFF;
  1507. mutex_unlock(&ar->conf_mutex);
  1508. cancel_work_sync(&ar->offchan_tx_work);
  1509. cancel_work_sync(&ar->restart_work);
  1510. }
  1511. static void ath10k_config_ps(struct ath10k *ar)
  1512. {
  1513. struct ath10k_generic_iter ar_iter;
  1514. lockdep_assert_held(&ar->conf_mutex);
  1515. /* During HW reconfiguration mac80211 reports all interfaces that were
  1516. * running until reconfiguration was started. Since FW doesn't have any
  1517. * vdevs at this point we must not iterate over this interface list.
  1518. * This setting will be updated upon add_interface(). */
  1519. if (ar->state == ATH10K_STATE_RESTARTED)
  1520. return;
  1521. memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
  1522. ar_iter.ar = ar;
  1523. ieee80211_iterate_active_interfaces_atomic(
  1524. ar->hw, IEEE80211_IFACE_ITER_NORMAL,
  1525. ath10k_ps_iter, &ar_iter);
  1526. if (ar_iter.ret)
  1527. ath10k_warn("failed to set ps config (%d)\n", ar_iter.ret);
  1528. }
  1529. static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
  1530. {
  1531. struct ath10k *ar = hw->priv;
  1532. struct ieee80211_conf *conf = &hw->conf;
  1533. int ret = 0;
  1534. mutex_lock(&ar->conf_mutex);
  1535. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  1536. ath10k_dbg(ATH10K_DBG_MAC, "mac config channel %d mhz\n",
  1537. conf->chandef.chan->center_freq);
  1538. spin_lock_bh(&ar->data_lock);
  1539. ar->rx_channel = conf->chandef.chan;
  1540. spin_unlock_bh(&ar->data_lock);
  1541. }
  1542. if (changed & IEEE80211_CONF_CHANGE_PS)
  1543. ath10k_config_ps(ar);
  1544. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  1545. if (conf->flags & IEEE80211_CONF_MONITOR)
  1546. ret = ath10k_monitor_create(ar);
  1547. else
  1548. ret = ath10k_monitor_destroy(ar);
  1549. }
  1550. mutex_unlock(&ar->conf_mutex);
  1551. return ret;
  1552. }
  1553. /*
  1554. * TODO:
  1555. * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
  1556. * because we will send mgmt frames without CCK. This requirement
  1557. * for P2P_FIND/GO_NEG should be handled by checking CCK flag
  1558. * in the TX packet.
  1559. */
  1560. static int ath10k_add_interface(struct ieee80211_hw *hw,
  1561. struct ieee80211_vif *vif)
  1562. {
  1563. struct ath10k *ar = hw->priv;
  1564. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1565. enum wmi_sta_powersave_param param;
  1566. int ret = 0;
  1567. u32 value;
  1568. int bit;
  1569. mutex_lock(&ar->conf_mutex);
  1570. memset(arvif, 0, sizeof(*arvif));
  1571. arvif->ar = ar;
  1572. arvif->vif = vif;
  1573. if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
  1574. ath10k_warn("Only one monitor interface allowed\n");
  1575. ret = -EBUSY;
  1576. goto exit;
  1577. }
  1578. bit = ffs(ar->free_vdev_map);
  1579. if (bit == 0) {
  1580. ret = -EBUSY;
  1581. goto exit;
  1582. }
  1583. arvif->vdev_id = bit - 1;
  1584. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
  1585. ar->free_vdev_map &= ~(1 << arvif->vdev_id);
  1586. if (ar->p2p)
  1587. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
  1588. switch (vif->type) {
  1589. case NL80211_IFTYPE_UNSPECIFIED:
  1590. case NL80211_IFTYPE_STATION:
  1591. arvif->vdev_type = WMI_VDEV_TYPE_STA;
  1592. if (vif->p2p)
  1593. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
  1594. break;
  1595. case NL80211_IFTYPE_ADHOC:
  1596. arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
  1597. break;
  1598. case NL80211_IFTYPE_AP:
  1599. arvif->vdev_type = WMI_VDEV_TYPE_AP;
  1600. if (vif->p2p)
  1601. arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
  1602. break;
  1603. case NL80211_IFTYPE_MONITOR:
  1604. arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
  1605. break;
  1606. default:
  1607. WARN_ON(1);
  1608. break;
  1609. }
  1610. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
  1611. arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
  1612. ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
  1613. arvif->vdev_subtype, vif->addr);
  1614. if (ret) {
  1615. ath10k_warn("WMI vdev create failed: ret %d\n", ret);
  1616. goto exit;
  1617. }
  1618. ret = ath10k_wmi_vdev_set_param(ar, 0, WMI_VDEV_PARAM_DEF_KEYID,
  1619. arvif->def_wep_key_index);
  1620. if (ret)
  1621. ath10k_warn("Failed to set default keyid: %d\n", ret);
  1622. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  1623. WMI_VDEV_PARAM_TX_ENCAP_TYPE,
  1624. ATH10K_HW_TXRX_NATIVE_WIFI);
  1625. if (ret)
  1626. ath10k_warn("Failed to set TX encap: %d\n", ret);
  1627. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  1628. ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
  1629. if (ret) {
  1630. ath10k_warn("Failed to create peer for AP: %d\n", ret);
  1631. goto exit;
  1632. }
  1633. }
  1634. if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
  1635. param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
  1636. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  1637. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  1638. param, value);
  1639. if (ret)
  1640. ath10k_warn("Failed to set RX wake policy: %d\n", ret);
  1641. param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
  1642. value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
  1643. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  1644. param, value);
  1645. if (ret)
  1646. ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
  1647. param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
  1648. value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
  1649. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  1650. param, value);
  1651. if (ret)
  1652. ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
  1653. }
  1654. ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
  1655. if (ret)
  1656. ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
  1657. arvif->vdev_id, ret);
  1658. ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
  1659. if (ret)
  1660. ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
  1661. arvif->vdev_id, ret);
  1662. if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
  1663. ar->monitor_present = true;
  1664. exit:
  1665. mutex_unlock(&ar->conf_mutex);
  1666. return ret;
  1667. }
  1668. static void ath10k_remove_interface(struct ieee80211_hw *hw,
  1669. struct ieee80211_vif *vif)
  1670. {
  1671. struct ath10k *ar = hw->priv;
  1672. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1673. int ret;
  1674. mutex_lock(&ar->conf_mutex);
  1675. spin_lock_bh(&ar->data_lock);
  1676. if (arvif->beacon) {
  1677. dev_kfree_skb_any(arvif->beacon);
  1678. arvif->beacon = NULL;
  1679. }
  1680. spin_unlock_bh(&ar->data_lock);
  1681. ar->free_vdev_map |= 1 << (arvif->vdev_id);
  1682. if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
  1683. ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
  1684. if (ret)
  1685. ath10k_warn("Failed to remove peer for AP: %d\n", ret);
  1686. kfree(arvif->u.ap.noa_data);
  1687. }
  1688. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
  1689. arvif->vdev_id);
  1690. ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
  1691. if (ret)
  1692. ath10k_warn("WMI vdev delete failed: %d\n", ret);
  1693. if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
  1694. ar->monitor_present = false;
  1695. ath10k_peer_cleanup(ar, arvif->vdev_id);
  1696. mutex_unlock(&ar->conf_mutex);
  1697. }
  1698. /*
  1699. * FIXME: Has to be verified.
  1700. */
  1701. #define SUPPORTED_FILTERS \
  1702. (FIF_PROMISC_IN_BSS | \
  1703. FIF_ALLMULTI | \
  1704. FIF_CONTROL | \
  1705. FIF_PSPOLL | \
  1706. FIF_OTHER_BSS | \
  1707. FIF_BCN_PRBRESP_PROMISC | \
  1708. FIF_PROBE_REQ | \
  1709. FIF_FCSFAIL)
  1710. static void ath10k_configure_filter(struct ieee80211_hw *hw,
  1711. unsigned int changed_flags,
  1712. unsigned int *total_flags,
  1713. u64 multicast)
  1714. {
  1715. struct ath10k *ar = hw->priv;
  1716. int ret;
  1717. mutex_lock(&ar->conf_mutex);
  1718. changed_flags &= SUPPORTED_FILTERS;
  1719. *total_flags &= SUPPORTED_FILTERS;
  1720. ar->filter_flags = *total_flags;
  1721. if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
  1722. !ar->monitor_enabled) {
  1723. ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
  1724. ar->monitor_vdev_id);
  1725. ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
  1726. if (ret)
  1727. ath10k_warn("Unable to start monitor mode\n");
  1728. } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
  1729. ar->monitor_enabled) {
  1730. ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
  1731. ar->monitor_vdev_id);
  1732. ret = ath10k_monitor_stop(ar);
  1733. if (ret)
  1734. ath10k_warn("Unable to stop monitor mode\n");
  1735. }
  1736. mutex_unlock(&ar->conf_mutex);
  1737. }
  1738. static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
  1739. struct ieee80211_vif *vif,
  1740. struct ieee80211_bss_conf *info,
  1741. u32 changed)
  1742. {
  1743. struct ath10k *ar = hw->priv;
  1744. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1745. int ret = 0;
  1746. mutex_lock(&ar->conf_mutex);
  1747. if (changed & BSS_CHANGED_IBSS)
  1748. ath10k_control_ibss(arvif, info, vif->addr);
  1749. if (changed & BSS_CHANGED_BEACON_INT) {
  1750. arvif->beacon_interval = info->beacon_int;
  1751. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  1752. WMI_VDEV_PARAM_BEACON_INTERVAL,
  1753. arvif->beacon_interval);
  1754. ath10k_dbg(ATH10K_DBG_MAC,
  1755. "mac vdev %d beacon_interval %d\n",
  1756. arvif->vdev_id, arvif->beacon_interval);
  1757. if (ret)
  1758. ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
  1759. arvif->vdev_id);
  1760. }
  1761. if (changed & BSS_CHANGED_BEACON) {
  1762. ath10k_dbg(ATH10K_DBG_MAC,
  1763. "vdev %d set beacon tx mode to staggered\n",
  1764. arvif->vdev_id);
  1765. ret = ath10k_wmi_pdev_set_param(ar,
  1766. WMI_PDEV_PARAM_BEACON_TX_MODE,
  1767. WMI_BEACON_STAGGERED_MODE);
  1768. if (ret)
  1769. ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
  1770. arvif->vdev_id);
  1771. }
  1772. if (changed & BSS_CHANGED_BEACON_INFO) {
  1773. arvif->dtim_period = info->dtim_period;
  1774. ath10k_dbg(ATH10K_DBG_MAC,
  1775. "mac vdev %d dtim_period %d\n",
  1776. arvif->vdev_id, arvif->dtim_period);
  1777. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  1778. WMI_VDEV_PARAM_DTIM_PERIOD,
  1779. arvif->dtim_period);
  1780. if (ret)
  1781. ath10k_warn("Failed to set dtim period for VDEV: %d\n",
  1782. arvif->vdev_id);
  1783. }
  1784. if (changed & BSS_CHANGED_SSID &&
  1785. vif->type == NL80211_IFTYPE_AP) {
  1786. arvif->u.ap.ssid_len = info->ssid_len;
  1787. if (info->ssid_len)
  1788. memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
  1789. arvif->u.ap.hidden_ssid = info->hidden_ssid;
  1790. }
  1791. if (changed & BSS_CHANGED_BSSID) {
  1792. if (!is_zero_ether_addr(info->bssid)) {
  1793. ath10k_dbg(ATH10K_DBG_MAC,
  1794. "mac vdev %d create peer %pM\n",
  1795. arvif->vdev_id, info->bssid);
  1796. ret = ath10k_peer_create(ar, arvif->vdev_id,
  1797. info->bssid);
  1798. if (ret)
  1799. ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
  1800. info->bssid, arvif->vdev_id);
  1801. if (vif->type == NL80211_IFTYPE_STATION) {
  1802. /*
  1803. * this is never erased as we it for crypto key
  1804. * clearing; this is FW requirement
  1805. */
  1806. memcpy(arvif->u.sta.bssid, info->bssid,
  1807. ETH_ALEN);
  1808. ath10k_dbg(ATH10K_DBG_MAC,
  1809. "mac vdev %d start %pM\n",
  1810. arvif->vdev_id, info->bssid);
  1811. /* FIXME: check return value */
  1812. ret = ath10k_vdev_start(arvif);
  1813. }
  1814. /*
  1815. * Mac80211 does not keep IBSS bssid when leaving IBSS,
  1816. * so driver need to store it. It is needed when leaving
  1817. * IBSS in order to remove BSSID peer.
  1818. */
  1819. if (vif->type == NL80211_IFTYPE_ADHOC)
  1820. memcpy(arvif->u.ibss.bssid, info->bssid,
  1821. ETH_ALEN);
  1822. }
  1823. }
  1824. if (changed & BSS_CHANGED_BEACON_ENABLED)
  1825. ath10k_control_beaconing(arvif, info);
  1826. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  1827. u32 cts_prot;
  1828. if (info->use_cts_prot)
  1829. cts_prot = 1;
  1830. else
  1831. cts_prot = 0;
  1832. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
  1833. arvif->vdev_id, cts_prot);
  1834. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  1835. WMI_VDEV_PARAM_ENABLE_RTSCTS,
  1836. cts_prot);
  1837. if (ret)
  1838. ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
  1839. arvif->vdev_id);
  1840. }
  1841. if (changed & BSS_CHANGED_ERP_SLOT) {
  1842. u32 slottime;
  1843. if (info->use_short_slot)
  1844. slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
  1845. else
  1846. slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
  1847. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
  1848. arvif->vdev_id, slottime);
  1849. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  1850. WMI_VDEV_PARAM_SLOT_TIME,
  1851. slottime);
  1852. if (ret)
  1853. ath10k_warn("Failed to set erp slot for VDEV: %d\n",
  1854. arvif->vdev_id);
  1855. }
  1856. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  1857. u32 preamble;
  1858. if (info->use_short_preamble)
  1859. preamble = WMI_VDEV_PREAMBLE_SHORT;
  1860. else
  1861. preamble = WMI_VDEV_PREAMBLE_LONG;
  1862. ath10k_dbg(ATH10K_DBG_MAC,
  1863. "mac vdev %d preamble %dn",
  1864. arvif->vdev_id, preamble);
  1865. ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
  1866. WMI_VDEV_PARAM_PREAMBLE,
  1867. preamble);
  1868. if (ret)
  1869. ath10k_warn("Failed to set preamble for VDEV: %d\n",
  1870. arvif->vdev_id);
  1871. }
  1872. if (changed & BSS_CHANGED_ASSOC) {
  1873. if (info->assoc)
  1874. ath10k_bss_assoc(hw, vif, info);
  1875. }
  1876. mutex_unlock(&ar->conf_mutex);
  1877. }
  1878. static int ath10k_hw_scan(struct ieee80211_hw *hw,
  1879. struct ieee80211_vif *vif,
  1880. struct cfg80211_scan_request *req)
  1881. {
  1882. struct ath10k *ar = hw->priv;
  1883. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1884. struct wmi_start_scan_arg arg;
  1885. int ret = 0;
  1886. int i;
  1887. mutex_lock(&ar->conf_mutex);
  1888. spin_lock_bh(&ar->data_lock);
  1889. if (ar->scan.in_progress) {
  1890. spin_unlock_bh(&ar->data_lock);
  1891. ret = -EBUSY;
  1892. goto exit;
  1893. }
  1894. INIT_COMPLETION(ar->scan.started);
  1895. INIT_COMPLETION(ar->scan.completed);
  1896. ar->scan.in_progress = true;
  1897. ar->scan.aborting = false;
  1898. ar->scan.is_roc = false;
  1899. ar->scan.vdev_id = arvif->vdev_id;
  1900. spin_unlock_bh(&ar->data_lock);
  1901. memset(&arg, 0, sizeof(arg));
  1902. ath10k_wmi_start_scan_init(ar, &arg);
  1903. arg.vdev_id = arvif->vdev_id;
  1904. arg.scan_id = ATH10K_SCAN_ID;
  1905. if (!req->no_cck)
  1906. arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
  1907. if (req->ie_len) {
  1908. arg.ie_len = req->ie_len;
  1909. memcpy(arg.ie, req->ie, arg.ie_len);
  1910. }
  1911. if (req->n_ssids) {
  1912. arg.n_ssids = req->n_ssids;
  1913. for (i = 0; i < arg.n_ssids; i++) {
  1914. arg.ssids[i].len = req->ssids[i].ssid_len;
  1915. arg.ssids[i].ssid = req->ssids[i].ssid;
  1916. }
  1917. } else {
  1918. arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
  1919. }
  1920. if (req->n_channels) {
  1921. arg.n_channels = req->n_channels;
  1922. for (i = 0; i < arg.n_channels; i++)
  1923. arg.channels[i] = req->channels[i]->center_freq;
  1924. }
  1925. ret = ath10k_start_scan(ar, &arg);
  1926. if (ret) {
  1927. ath10k_warn("could not start hw scan (%d)\n", ret);
  1928. spin_lock_bh(&ar->data_lock);
  1929. ar->scan.in_progress = false;
  1930. spin_unlock_bh(&ar->data_lock);
  1931. }
  1932. exit:
  1933. mutex_unlock(&ar->conf_mutex);
  1934. return ret;
  1935. }
  1936. static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
  1937. struct ieee80211_vif *vif)
  1938. {
  1939. struct ath10k *ar = hw->priv;
  1940. int ret;
  1941. mutex_lock(&ar->conf_mutex);
  1942. ret = ath10k_abort_scan(ar);
  1943. if (ret) {
  1944. ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
  1945. ret);
  1946. ieee80211_scan_completed(hw, 1 /* aborted */);
  1947. }
  1948. mutex_unlock(&ar->conf_mutex);
  1949. }
  1950. static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1951. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1952. struct ieee80211_key_conf *key)
  1953. {
  1954. struct ath10k *ar = hw->priv;
  1955. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  1956. struct ath10k_peer *peer;
  1957. const u8 *peer_addr;
  1958. bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  1959. key->cipher == WLAN_CIPHER_SUITE_WEP104;
  1960. int ret = 0;
  1961. if (key->keyidx > WMI_MAX_KEY_INDEX)
  1962. return -ENOSPC;
  1963. mutex_lock(&ar->conf_mutex);
  1964. if (sta)
  1965. peer_addr = sta->addr;
  1966. else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
  1967. peer_addr = vif->bss_conf.bssid;
  1968. else
  1969. peer_addr = vif->addr;
  1970. key->hw_key_idx = key->keyidx;
  1971. /* the peer should not disappear in mid-way (unless FW goes awry) since
  1972. * we already hold conf_mutex. we just make sure its there now. */
  1973. spin_lock_bh(&ar->data_lock);
  1974. peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
  1975. spin_unlock_bh(&ar->data_lock);
  1976. if (!peer) {
  1977. if (cmd == SET_KEY) {
  1978. ath10k_warn("cannot install key for non-existent peer %pM\n",
  1979. peer_addr);
  1980. ret = -EOPNOTSUPP;
  1981. goto exit;
  1982. } else {
  1983. /* if the peer doesn't exist there is no key to disable
  1984. * anymore */
  1985. goto exit;
  1986. }
  1987. }
  1988. if (is_wep) {
  1989. if (cmd == SET_KEY)
  1990. arvif->wep_keys[key->keyidx] = key;
  1991. else
  1992. arvif->wep_keys[key->keyidx] = NULL;
  1993. if (cmd == DISABLE_KEY)
  1994. ath10k_clear_vdev_key(arvif, key);
  1995. }
  1996. ret = ath10k_install_key(arvif, key, cmd, peer_addr);
  1997. if (ret) {
  1998. ath10k_warn("ath10k_install_key failed (%d)\n", ret);
  1999. goto exit;
  2000. }
  2001. spin_lock_bh(&ar->data_lock);
  2002. peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
  2003. if (peer && cmd == SET_KEY)
  2004. peer->keys[key->keyidx] = key;
  2005. else if (peer && cmd == DISABLE_KEY)
  2006. peer->keys[key->keyidx] = NULL;
  2007. else if (peer == NULL)
  2008. /* impossible unless FW goes crazy */
  2009. ath10k_warn("peer %pM disappeared!\n", peer_addr);
  2010. spin_unlock_bh(&ar->data_lock);
  2011. exit:
  2012. mutex_unlock(&ar->conf_mutex);
  2013. return ret;
  2014. }
  2015. static int ath10k_sta_state(struct ieee80211_hw *hw,
  2016. struct ieee80211_vif *vif,
  2017. struct ieee80211_sta *sta,
  2018. enum ieee80211_sta_state old_state,
  2019. enum ieee80211_sta_state new_state)
  2020. {
  2021. struct ath10k *ar = hw->priv;
  2022. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2023. int ret = 0;
  2024. mutex_lock(&ar->conf_mutex);
  2025. if (old_state == IEEE80211_STA_NOTEXIST &&
  2026. new_state == IEEE80211_STA_NONE &&
  2027. vif->type != NL80211_IFTYPE_STATION) {
  2028. /*
  2029. * New station addition.
  2030. */
  2031. ath10k_dbg(ATH10K_DBG_MAC,
  2032. "mac vdev %d peer create %pM (new sta)\n",
  2033. arvif->vdev_id, sta->addr);
  2034. ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
  2035. if (ret)
  2036. ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
  2037. sta->addr, arvif->vdev_id);
  2038. } else if ((old_state == IEEE80211_STA_NONE &&
  2039. new_state == IEEE80211_STA_NOTEXIST)) {
  2040. /*
  2041. * Existing station deletion.
  2042. */
  2043. ath10k_dbg(ATH10K_DBG_MAC,
  2044. "mac vdev %d peer delete %pM (sta gone)\n",
  2045. arvif->vdev_id, sta->addr);
  2046. ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
  2047. if (ret)
  2048. ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
  2049. sta->addr, arvif->vdev_id);
  2050. if (vif->type == NL80211_IFTYPE_STATION)
  2051. ath10k_bss_disassoc(hw, vif);
  2052. } else if (old_state == IEEE80211_STA_AUTH &&
  2053. new_state == IEEE80211_STA_ASSOC &&
  2054. (vif->type == NL80211_IFTYPE_AP ||
  2055. vif->type == NL80211_IFTYPE_ADHOC)) {
  2056. /*
  2057. * New association.
  2058. */
  2059. ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
  2060. sta->addr);
  2061. ret = ath10k_station_assoc(ar, arvif, sta);
  2062. if (ret)
  2063. ath10k_warn("Failed to associate station: %pM\n",
  2064. sta->addr);
  2065. } else if (old_state == IEEE80211_STA_ASSOC &&
  2066. new_state == IEEE80211_STA_AUTH &&
  2067. (vif->type == NL80211_IFTYPE_AP ||
  2068. vif->type == NL80211_IFTYPE_ADHOC)) {
  2069. /*
  2070. * Disassociation.
  2071. */
  2072. ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
  2073. sta->addr);
  2074. ret = ath10k_station_disassoc(ar, arvif, sta);
  2075. if (ret)
  2076. ath10k_warn("Failed to disassociate station: %pM\n",
  2077. sta->addr);
  2078. }
  2079. mutex_unlock(&ar->conf_mutex);
  2080. return ret;
  2081. }
  2082. static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
  2083. u16 ac, bool enable)
  2084. {
  2085. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2086. u32 value = 0;
  2087. int ret = 0;
  2088. lockdep_assert_held(&ar->conf_mutex);
  2089. if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
  2090. return 0;
  2091. switch (ac) {
  2092. case IEEE80211_AC_VO:
  2093. value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
  2094. WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
  2095. break;
  2096. case IEEE80211_AC_VI:
  2097. value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
  2098. WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
  2099. break;
  2100. case IEEE80211_AC_BE:
  2101. value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
  2102. WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
  2103. break;
  2104. case IEEE80211_AC_BK:
  2105. value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
  2106. WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
  2107. break;
  2108. }
  2109. if (enable)
  2110. arvif->u.sta.uapsd |= value;
  2111. else
  2112. arvif->u.sta.uapsd &= ~value;
  2113. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  2114. WMI_STA_PS_PARAM_UAPSD,
  2115. arvif->u.sta.uapsd);
  2116. if (ret) {
  2117. ath10k_warn("could not set uapsd params %d\n", ret);
  2118. goto exit;
  2119. }
  2120. if (arvif->u.sta.uapsd)
  2121. value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
  2122. else
  2123. value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
  2124. ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
  2125. WMI_STA_PS_PARAM_RX_WAKE_POLICY,
  2126. value);
  2127. if (ret)
  2128. ath10k_warn("could not set rx wake param %d\n", ret);
  2129. exit:
  2130. return ret;
  2131. }
  2132. static int ath10k_conf_tx(struct ieee80211_hw *hw,
  2133. struct ieee80211_vif *vif, u16 ac,
  2134. const struct ieee80211_tx_queue_params *params)
  2135. {
  2136. struct ath10k *ar = hw->priv;
  2137. struct wmi_wmm_params_arg *p = NULL;
  2138. int ret;
  2139. mutex_lock(&ar->conf_mutex);
  2140. switch (ac) {
  2141. case IEEE80211_AC_VO:
  2142. p = &ar->wmm_params.ac_vo;
  2143. break;
  2144. case IEEE80211_AC_VI:
  2145. p = &ar->wmm_params.ac_vi;
  2146. break;
  2147. case IEEE80211_AC_BE:
  2148. p = &ar->wmm_params.ac_be;
  2149. break;
  2150. case IEEE80211_AC_BK:
  2151. p = &ar->wmm_params.ac_bk;
  2152. break;
  2153. }
  2154. if (WARN_ON(!p)) {
  2155. ret = -EINVAL;
  2156. goto exit;
  2157. }
  2158. p->cwmin = params->cw_min;
  2159. p->cwmax = params->cw_max;
  2160. p->aifs = params->aifs;
  2161. /*
  2162. * The channel time duration programmed in the HW is in absolute
  2163. * microseconds, while mac80211 gives the txop in units of
  2164. * 32 microseconds.
  2165. */
  2166. p->txop = params->txop * 32;
  2167. /* FIXME: FW accepts wmm params per hw, not per vif */
  2168. ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
  2169. if (ret) {
  2170. ath10k_warn("could not set wmm params %d\n", ret);
  2171. goto exit;
  2172. }
  2173. ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
  2174. if (ret)
  2175. ath10k_warn("could not set sta uapsd %d\n", ret);
  2176. exit:
  2177. mutex_unlock(&ar->conf_mutex);
  2178. return ret;
  2179. }
  2180. #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
  2181. static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
  2182. struct ieee80211_vif *vif,
  2183. struct ieee80211_channel *chan,
  2184. int duration,
  2185. enum ieee80211_roc_type type)
  2186. {
  2187. struct ath10k *ar = hw->priv;
  2188. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2189. struct wmi_start_scan_arg arg;
  2190. int ret;
  2191. mutex_lock(&ar->conf_mutex);
  2192. spin_lock_bh(&ar->data_lock);
  2193. if (ar->scan.in_progress) {
  2194. spin_unlock_bh(&ar->data_lock);
  2195. ret = -EBUSY;
  2196. goto exit;
  2197. }
  2198. INIT_COMPLETION(ar->scan.started);
  2199. INIT_COMPLETION(ar->scan.completed);
  2200. INIT_COMPLETION(ar->scan.on_channel);
  2201. ar->scan.in_progress = true;
  2202. ar->scan.aborting = false;
  2203. ar->scan.is_roc = true;
  2204. ar->scan.vdev_id = arvif->vdev_id;
  2205. ar->scan.roc_freq = chan->center_freq;
  2206. spin_unlock_bh(&ar->data_lock);
  2207. memset(&arg, 0, sizeof(arg));
  2208. ath10k_wmi_start_scan_init(ar, &arg);
  2209. arg.vdev_id = arvif->vdev_id;
  2210. arg.scan_id = ATH10K_SCAN_ID;
  2211. arg.n_channels = 1;
  2212. arg.channels[0] = chan->center_freq;
  2213. arg.dwell_time_active = duration;
  2214. arg.dwell_time_passive = duration;
  2215. arg.max_scan_time = 2 * duration;
  2216. arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
  2217. arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
  2218. ret = ath10k_start_scan(ar, &arg);
  2219. if (ret) {
  2220. ath10k_warn("could not start roc scan (%d)\n", ret);
  2221. spin_lock_bh(&ar->data_lock);
  2222. ar->scan.in_progress = false;
  2223. spin_unlock_bh(&ar->data_lock);
  2224. goto exit;
  2225. }
  2226. ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
  2227. if (ret == 0) {
  2228. ath10k_warn("could not switch to channel for roc scan\n");
  2229. ath10k_abort_scan(ar);
  2230. ret = -ETIMEDOUT;
  2231. goto exit;
  2232. }
  2233. ret = 0;
  2234. exit:
  2235. mutex_unlock(&ar->conf_mutex);
  2236. return ret;
  2237. }
  2238. static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
  2239. {
  2240. struct ath10k *ar = hw->priv;
  2241. mutex_lock(&ar->conf_mutex);
  2242. ath10k_abort_scan(ar);
  2243. mutex_unlock(&ar->conf_mutex);
  2244. return 0;
  2245. }
  2246. /*
  2247. * Both RTS and Fragmentation threshold are interface-specific
  2248. * in ath10k, but device-specific in mac80211.
  2249. */
  2250. static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  2251. {
  2252. struct ath10k_generic_iter *ar_iter = data;
  2253. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2254. u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
  2255. lockdep_assert_held(&arvif->ar->conf_mutex);
  2256. /* During HW reconfiguration mac80211 reports all interfaces that were
  2257. * running until reconfiguration was started. Since FW doesn't have any
  2258. * vdevs at this point we must not iterate over this interface list.
  2259. * This setting will be updated upon add_interface(). */
  2260. if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
  2261. return;
  2262. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts_threshold %d\n",
  2263. arvif->vdev_id, rts);
  2264. ar_iter->ret = ath10k_mac_set_rts(arvif, rts);
  2265. if (ar_iter->ret)
  2266. ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
  2267. arvif->vdev_id);
  2268. }
  2269. static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  2270. {
  2271. struct ath10k_generic_iter ar_iter;
  2272. struct ath10k *ar = hw->priv;
  2273. memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
  2274. ar_iter.ar = ar;
  2275. mutex_lock(&ar->conf_mutex);
  2276. ieee80211_iterate_active_interfaces_atomic(
  2277. hw, IEEE80211_IFACE_ITER_NORMAL,
  2278. ath10k_set_rts_iter, &ar_iter);
  2279. mutex_unlock(&ar->conf_mutex);
  2280. return ar_iter.ret;
  2281. }
  2282. static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  2283. {
  2284. struct ath10k_generic_iter *ar_iter = data;
  2285. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2286. u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
  2287. lockdep_assert_held(&arvif->ar->conf_mutex);
  2288. /* During HW reconfiguration mac80211 reports all interfaces that were
  2289. * running until reconfiguration was started. Since FW doesn't have any
  2290. * vdevs at this point we must not iterate over this interface list.
  2291. * This setting will be updated upon add_interface(). */
  2292. if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
  2293. return;
  2294. ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation_threshold %d\n",
  2295. arvif->vdev_id, frag);
  2296. ar_iter->ret = ath10k_mac_set_frag(arvif, frag);
  2297. if (ar_iter->ret)
  2298. ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
  2299. arvif->vdev_id);
  2300. }
  2301. static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
  2302. {
  2303. struct ath10k_generic_iter ar_iter;
  2304. struct ath10k *ar = hw->priv;
  2305. memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
  2306. ar_iter.ar = ar;
  2307. mutex_lock(&ar->conf_mutex);
  2308. ieee80211_iterate_active_interfaces_atomic(
  2309. hw, IEEE80211_IFACE_ITER_NORMAL,
  2310. ath10k_set_frag_iter, &ar_iter);
  2311. mutex_unlock(&ar->conf_mutex);
  2312. return ar_iter.ret;
  2313. }
  2314. static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
  2315. {
  2316. struct ath10k *ar = hw->priv;
  2317. bool skip;
  2318. int ret;
  2319. /* mac80211 doesn't care if we really xmit queued frames or not
  2320. * we'll collect those frames either way if we stop/delete vdevs */
  2321. if (drop)
  2322. return;
  2323. mutex_lock(&ar->conf_mutex);
  2324. if (ar->state == ATH10K_STATE_WEDGED)
  2325. goto skip;
  2326. ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
  2327. bool empty;
  2328. spin_lock_bh(&ar->htt.tx_lock);
  2329. empty = (ar->htt.num_pending_tx == 0);
  2330. spin_unlock_bh(&ar->htt.tx_lock);
  2331. skip = (ar->state == ATH10K_STATE_WEDGED);
  2332. (empty || skip);
  2333. }), ATH10K_FLUSH_TIMEOUT_HZ);
  2334. if (ret <= 0 || skip)
  2335. ath10k_warn("tx not flushed\n");
  2336. skip:
  2337. mutex_unlock(&ar->conf_mutex);
  2338. }
  2339. /* TODO: Implement this function properly
  2340. * For now it is needed to reply to Probe Requests in IBSS mode.
  2341. * Propably we need this information from FW.
  2342. */
  2343. static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
  2344. {
  2345. return 1;
  2346. }
  2347. #ifdef CONFIG_PM
  2348. static int ath10k_suspend(struct ieee80211_hw *hw,
  2349. struct cfg80211_wowlan *wowlan)
  2350. {
  2351. struct ath10k *ar = hw->priv;
  2352. int ret;
  2353. ar->is_target_paused = false;
  2354. ret = ath10k_wmi_pdev_suspend_target(ar);
  2355. if (ret) {
  2356. ath10k_warn("could not suspend target (%d)\n", ret);
  2357. return 1;
  2358. }
  2359. ret = wait_event_interruptible_timeout(ar->event_queue,
  2360. ar->is_target_paused == true,
  2361. 1 * HZ);
  2362. if (ret < 0) {
  2363. ath10k_warn("suspend interrupted (%d)\n", ret);
  2364. goto resume;
  2365. } else if (ret == 0) {
  2366. ath10k_warn("suspend timed out - target pause event never came\n");
  2367. goto resume;
  2368. }
  2369. ret = ath10k_hif_suspend(ar);
  2370. if (ret) {
  2371. ath10k_warn("could not suspend hif (%d)\n", ret);
  2372. goto resume;
  2373. }
  2374. return 0;
  2375. resume:
  2376. ret = ath10k_wmi_pdev_resume_target(ar);
  2377. if (ret)
  2378. ath10k_warn("could not resume target (%d)\n", ret);
  2379. return 1;
  2380. }
  2381. static int ath10k_resume(struct ieee80211_hw *hw)
  2382. {
  2383. struct ath10k *ar = hw->priv;
  2384. int ret;
  2385. ret = ath10k_hif_resume(ar);
  2386. if (ret) {
  2387. ath10k_warn("could not resume hif (%d)\n", ret);
  2388. return 1;
  2389. }
  2390. ret = ath10k_wmi_pdev_resume_target(ar);
  2391. if (ret) {
  2392. ath10k_warn("could not resume target (%d)\n", ret);
  2393. return 1;
  2394. }
  2395. return 0;
  2396. }
  2397. #endif
  2398. static void ath10k_restart_complete(struct ieee80211_hw *hw)
  2399. {
  2400. struct ath10k *ar = hw->priv;
  2401. mutex_lock(&ar->conf_mutex);
  2402. /* If device failed to restart it will be in a different state, e.g.
  2403. * ATH10K_STATE_WEDGED */
  2404. if (ar->state == ATH10K_STATE_RESTARTED) {
  2405. ath10k_info("device successfully recovered\n");
  2406. ar->state = ATH10K_STATE_ON;
  2407. }
  2408. mutex_unlock(&ar->conf_mutex);
  2409. }
  2410. static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
  2411. struct survey_info *survey)
  2412. {
  2413. struct ath10k *ar = hw->priv;
  2414. struct ieee80211_supported_band *sband;
  2415. struct survey_info *ar_survey = &ar->survey[idx];
  2416. int ret = 0;
  2417. mutex_lock(&ar->conf_mutex);
  2418. sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
  2419. if (sband && idx >= sband->n_channels) {
  2420. idx -= sband->n_channels;
  2421. sband = NULL;
  2422. }
  2423. if (!sband)
  2424. sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
  2425. if (!sband || idx >= sband->n_channels) {
  2426. ret = -ENOENT;
  2427. goto exit;
  2428. }
  2429. spin_lock_bh(&ar->data_lock);
  2430. memcpy(survey, ar_survey, sizeof(*survey));
  2431. spin_unlock_bh(&ar->data_lock);
  2432. survey->channel = &sband->channels[idx];
  2433. exit:
  2434. mutex_unlock(&ar->conf_mutex);
  2435. return ret;
  2436. }
  2437. static const struct ieee80211_ops ath10k_ops = {
  2438. .tx = ath10k_tx,
  2439. .start = ath10k_start,
  2440. .stop = ath10k_stop,
  2441. .config = ath10k_config,
  2442. .add_interface = ath10k_add_interface,
  2443. .remove_interface = ath10k_remove_interface,
  2444. .configure_filter = ath10k_configure_filter,
  2445. .bss_info_changed = ath10k_bss_info_changed,
  2446. .hw_scan = ath10k_hw_scan,
  2447. .cancel_hw_scan = ath10k_cancel_hw_scan,
  2448. .set_key = ath10k_set_key,
  2449. .sta_state = ath10k_sta_state,
  2450. .conf_tx = ath10k_conf_tx,
  2451. .remain_on_channel = ath10k_remain_on_channel,
  2452. .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
  2453. .set_rts_threshold = ath10k_set_rts_threshold,
  2454. .set_frag_threshold = ath10k_set_frag_threshold,
  2455. .flush = ath10k_flush,
  2456. .tx_last_beacon = ath10k_tx_last_beacon,
  2457. .restart_complete = ath10k_restart_complete,
  2458. .get_survey = ath10k_get_survey,
  2459. #ifdef CONFIG_PM
  2460. .suspend = ath10k_suspend,
  2461. .resume = ath10k_resume,
  2462. #endif
  2463. };
  2464. #define RATETAB_ENT(_rate, _rateid, _flags) { \
  2465. .bitrate = (_rate), \
  2466. .flags = (_flags), \
  2467. .hw_value = (_rateid), \
  2468. }
  2469. #define CHAN2G(_channel, _freq, _flags) { \
  2470. .band = IEEE80211_BAND_2GHZ, \
  2471. .hw_value = (_channel), \
  2472. .center_freq = (_freq), \
  2473. .flags = (_flags), \
  2474. .max_antenna_gain = 0, \
  2475. .max_power = 30, \
  2476. }
  2477. #define CHAN5G(_channel, _freq, _flags) { \
  2478. .band = IEEE80211_BAND_5GHZ, \
  2479. .hw_value = (_channel), \
  2480. .center_freq = (_freq), \
  2481. .flags = (_flags), \
  2482. .max_antenna_gain = 0, \
  2483. .max_power = 30, \
  2484. }
  2485. static const struct ieee80211_channel ath10k_2ghz_channels[] = {
  2486. CHAN2G(1, 2412, 0),
  2487. CHAN2G(2, 2417, 0),
  2488. CHAN2G(3, 2422, 0),
  2489. CHAN2G(4, 2427, 0),
  2490. CHAN2G(5, 2432, 0),
  2491. CHAN2G(6, 2437, 0),
  2492. CHAN2G(7, 2442, 0),
  2493. CHAN2G(8, 2447, 0),
  2494. CHAN2G(9, 2452, 0),
  2495. CHAN2G(10, 2457, 0),
  2496. CHAN2G(11, 2462, 0),
  2497. CHAN2G(12, 2467, 0),
  2498. CHAN2G(13, 2472, 0),
  2499. CHAN2G(14, 2484, 0),
  2500. };
  2501. static const struct ieee80211_channel ath10k_5ghz_channels[] = {
  2502. CHAN5G(36, 5180, 0),
  2503. CHAN5G(40, 5200, 0),
  2504. CHAN5G(44, 5220, 0),
  2505. CHAN5G(48, 5240, 0),
  2506. CHAN5G(52, 5260, 0),
  2507. CHAN5G(56, 5280, 0),
  2508. CHAN5G(60, 5300, 0),
  2509. CHAN5G(64, 5320, 0),
  2510. CHAN5G(100, 5500, 0),
  2511. CHAN5G(104, 5520, 0),
  2512. CHAN5G(108, 5540, 0),
  2513. CHAN5G(112, 5560, 0),
  2514. CHAN5G(116, 5580, 0),
  2515. CHAN5G(120, 5600, 0),
  2516. CHAN5G(124, 5620, 0),
  2517. CHAN5G(128, 5640, 0),
  2518. CHAN5G(132, 5660, 0),
  2519. CHAN5G(136, 5680, 0),
  2520. CHAN5G(140, 5700, 0),
  2521. CHAN5G(149, 5745, 0),
  2522. CHAN5G(153, 5765, 0),
  2523. CHAN5G(157, 5785, 0),
  2524. CHAN5G(161, 5805, 0),
  2525. CHAN5G(165, 5825, 0),
  2526. };
  2527. static struct ieee80211_rate ath10k_rates[] = {
  2528. /* CCK */
  2529. RATETAB_ENT(10, 0x82, 0),
  2530. RATETAB_ENT(20, 0x84, 0),
  2531. RATETAB_ENT(55, 0x8b, 0),
  2532. RATETAB_ENT(110, 0x96, 0),
  2533. /* OFDM */
  2534. RATETAB_ENT(60, 0x0c, 0),
  2535. RATETAB_ENT(90, 0x12, 0),
  2536. RATETAB_ENT(120, 0x18, 0),
  2537. RATETAB_ENT(180, 0x24, 0),
  2538. RATETAB_ENT(240, 0x30, 0),
  2539. RATETAB_ENT(360, 0x48, 0),
  2540. RATETAB_ENT(480, 0x60, 0),
  2541. RATETAB_ENT(540, 0x6c, 0),
  2542. };
  2543. #define ath10k_a_rates (ath10k_rates + 4)
  2544. #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
  2545. #define ath10k_g_rates (ath10k_rates + 0)
  2546. #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
  2547. struct ath10k *ath10k_mac_create(void)
  2548. {
  2549. struct ieee80211_hw *hw;
  2550. struct ath10k *ar;
  2551. hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
  2552. if (!hw)
  2553. return NULL;
  2554. ar = hw->priv;
  2555. ar->hw = hw;
  2556. return ar;
  2557. }
  2558. void ath10k_mac_destroy(struct ath10k *ar)
  2559. {
  2560. ieee80211_free_hw(ar->hw);
  2561. }
  2562. static const struct ieee80211_iface_limit ath10k_if_limits[] = {
  2563. {
  2564. .max = 8,
  2565. .types = BIT(NL80211_IFTYPE_STATION)
  2566. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  2567. },
  2568. {
  2569. .max = 3,
  2570. .types = BIT(NL80211_IFTYPE_P2P_GO)
  2571. },
  2572. {
  2573. .max = 7,
  2574. .types = BIT(NL80211_IFTYPE_AP)
  2575. },
  2576. };
  2577. static const struct ieee80211_iface_combination ath10k_if_comb = {
  2578. .limits = ath10k_if_limits,
  2579. .n_limits = ARRAY_SIZE(ath10k_if_limits),
  2580. .max_interfaces = 8,
  2581. .num_different_channels = 1,
  2582. .beacon_int_infra_match = true,
  2583. };
  2584. static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
  2585. {
  2586. struct ieee80211_sta_vht_cap vht_cap = {0};
  2587. u16 mcs_map;
  2588. int i;
  2589. vht_cap.vht_supported = 1;
  2590. vht_cap.cap = ar->vht_cap_info;
  2591. mcs_map = 0;
  2592. for (i = 0; i < 8; i++) {
  2593. if (i < ar->num_rf_chains)
  2594. mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
  2595. else
  2596. mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
  2597. }
  2598. vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  2599. vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  2600. return vht_cap;
  2601. }
  2602. static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
  2603. {
  2604. int i;
  2605. struct ieee80211_sta_ht_cap ht_cap = {0};
  2606. if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
  2607. return ht_cap;
  2608. ht_cap.ht_supported = 1;
  2609. ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  2610. ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  2611. ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  2612. ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
  2613. ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
  2614. if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
  2615. ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  2616. if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
  2617. ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  2618. if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
  2619. u32 smps;
  2620. smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
  2621. smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
  2622. ht_cap.cap |= smps;
  2623. }
  2624. if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
  2625. ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  2626. if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
  2627. u32 stbc;
  2628. stbc = ar->ht_cap_info;
  2629. stbc &= WMI_HT_CAP_RX_STBC;
  2630. stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
  2631. stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
  2632. stbc &= IEEE80211_HT_CAP_RX_STBC;
  2633. ht_cap.cap |= stbc;
  2634. }
  2635. if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
  2636. ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
  2637. if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
  2638. ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
  2639. /* max AMSDU is implicitly taken from vht_cap_info */
  2640. if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
  2641. ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  2642. for (i = 0; i < ar->num_rf_chains; i++)
  2643. ht_cap.mcs.rx_mask[i] = 0xFF;
  2644. ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  2645. return ht_cap;
  2646. }
  2647. static void ath10k_get_arvif_iter(void *data, u8 *mac,
  2648. struct ieee80211_vif *vif)
  2649. {
  2650. struct ath10k_vif_iter *arvif_iter = data;
  2651. struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
  2652. if (arvif->vdev_id == arvif_iter->vdev_id)
  2653. arvif_iter->arvif = arvif;
  2654. }
  2655. struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
  2656. {
  2657. struct ath10k_vif_iter arvif_iter;
  2658. u32 flags;
  2659. memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
  2660. arvif_iter.vdev_id = vdev_id;
  2661. flags = IEEE80211_IFACE_ITER_RESUME_ALL;
  2662. ieee80211_iterate_active_interfaces_atomic(ar->hw,
  2663. flags,
  2664. ath10k_get_arvif_iter,
  2665. &arvif_iter);
  2666. if (!arvif_iter.arvif) {
  2667. ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
  2668. return NULL;
  2669. }
  2670. return arvif_iter.arvif;
  2671. }
  2672. int ath10k_mac_register(struct ath10k *ar)
  2673. {
  2674. struct ieee80211_supported_band *band;
  2675. struct ieee80211_sta_vht_cap vht_cap;
  2676. struct ieee80211_sta_ht_cap ht_cap;
  2677. void *channels;
  2678. int ret;
  2679. SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
  2680. SET_IEEE80211_DEV(ar->hw, ar->dev);
  2681. ht_cap = ath10k_get_ht_cap(ar);
  2682. vht_cap = ath10k_create_vht_cap(ar);
  2683. if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
  2684. channels = kmemdup(ath10k_2ghz_channels,
  2685. sizeof(ath10k_2ghz_channels),
  2686. GFP_KERNEL);
  2687. if (!channels) {
  2688. ret = -ENOMEM;
  2689. goto err_free;
  2690. }
  2691. band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
  2692. band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
  2693. band->channels = channels;
  2694. band->n_bitrates = ath10k_g_rates_size;
  2695. band->bitrates = ath10k_g_rates;
  2696. band->ht_cap = ht_cap;
  2697. /* vht is not supported in 2.4 GHz */
  2698. ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
  2699. }
  2700. if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
  2701. channels = kmemdup(ath10k_5ghz_channels,
  2702. sizeof(ath10k_5ghz_channels),
  2703. GFP_KERNEL);
  2704. if (!channels) {
  2705. ret = -ENOMEM;
  2706. goto err_free;
  2707. }
  2708. band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
  2709. band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
  2710. band->channels = channels;
  2711. band->n_bitrates = ath10k_a_rates_size;
  2712. band->bitrates = ath10k_a_rates;
  2713. band->ht_cap = ht_cap;
  2714. band->vht_cap = vht_cap;
  2715. ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
  2716. }
  2717. ar->hw->wiphy->interface_modes =
  2718. BIT(NL80211_IFTYPE_STATION) |
  2719. BIT(NL80211_IFTYPE_ADHOC) |
  2720. BIT(NL80211_IFTYPE_AP) |
  2721. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  2722. BIT(NL80211_IFTYPE_P2P_GO);
  2723. ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
  2724. IEEE80211_HW_SUPPORTS_PS |
  2725. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  2726. IEEE80211_HW_SUPPORTS_UAPSD |
  2727. IEEE80211_HW_MFP_CAPABLE |
  2728. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  2729. IEEE80211_HW_HAS_RATE_CONTROL |
  2730. IEEE80211_HW_SUPPORTS_STATIC_SMPS |
  2731. IEEE80211_HW_WANT_MONITOR_VIF |
  2732. IEEE80211_HW_AP_LINK_PS;
  2733. /* MSDU can have HTT TX fragment pushed in front. The additional 4
  2734. * bytes is used for padding/alignment if necessary. */
  2735. ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
  2736. if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
  2737. ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
  2738. if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
  2739. ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  2740. ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
  2741. }
  2742. ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
  2743. ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
  2744. ar->hw->vif_data_size = sizeof(struct ath10k_vif);
  2745. ar->hw->channel_change_time = 5000;
  2746. ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
  2747. ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  2748. ar->hw->wiphy->max_remain_on_channel_duration = 5000;
  2749. ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  2750. /*
  2751. * on LL hardware queues are managed entirely by the FW
  2752. * so we only advertise to mac we can do the queues thing
  2753. */
  2754. ar->hw->queues = 4;
  2755. ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
  2756. ar->hw->wiphy->n_iface_combinations = 1;
  2757. ar->hw->netdev_features = NETIF_F_HW_CSUM;
  2758. ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
  2759. ath10k_reg_notifier);
  2760. if (ret) {
  2761. ath10k_err("Regulatory initialization failed\n");
  2762. goto err_free;
  2763. }
  2764. ret = ieee80211_register_hw(ar->hw);
  2765. if (ret) {
  2766. ath10k_err("ieee80211 registration failed: %d\n", ret);
  2767. goto err_free;
  2768. }
  2769. if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
  2770. ret = regulatory_hint(ar->hw->wiphy,
  2771. ar->ath_common.regulatory.alpha2);
  2772. if (ret)
  2773. goto err_unregister;
  2774. }
  2775. return 0;
  2776. err_unregister:
  2777. ieee80211_unregister_hw(ar->hw);
  2778. err_free:
  2779. kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
  2780. kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
  2781. return ret;
  2782. }
  2783. void ath10k_mac_unregister(struct ath10k *ar)
  2784. {
  2785. ieee80211_unregister_hw(ar->hw);
  2786. kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
  2787. kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
  2788. SET_IEEE80211_DEV(ar->hw, NULL);
  2789. }