mac.c 76 KB

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