mac.c 86 KB

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