mac.c 100 KB

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