mac.c 86 KB

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