mac.c 83 KB

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