mac.c 76 KB

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