mac.c 87 KB

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