mac.c 87 KB

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