mac.c 87 KB

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