mac.c 83 KB

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