rs.c 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * Intel Linux Wireless <ilw@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/skbuff.h>
  29. #include <linux/slab.h>
  30. #include <net/mac80211.h>
  31. #include <linux/netdevice.h>
  32. #include <linux/etherdevice.h>
  33. #include <linux/delay.h>
  34. #include <linux/workqueue.h>
  35. #include "rs.h"
  36. #include "fw-api.h"
  37. #include "sta.h"
  38. #include "iwl-op-mode.h"
  39. #include "mvm.h"
  40. #define RS_NAME "iwl-mvm-rs"
  41. #define NUM_TRY_BEFORE_ANT_TOGGLE 1
  42. #define IWL_NUMBER_TRY 1
  43. #define IWL_HT_NUMBER_TRY 3
  44. #define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */
  45. #define IWL_RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */
  46. #define IWL_RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */
  47. /* max allowed rate miss before sync LQ cmd */
  48. #define IWL_MISSED_RATE_MAX 15
  49. /* max time to accum history 2 seconds */
  50. #define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ)
  51. static u8 rs_ht_to_legacy[] = {
  52. IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
  53. IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
  54. IWL_RATE_6M_INDEX,
  55. IWL_RATE_6M_INDEX, IWL_RATE_9M_INDEX,
  56. IWL_RATE_12M_INDEX, IWL_RATE_18M_INDEX,
  57. IWL_RATE_24M_INDEX, IWL_RATE_36M_INDEX,
  58. IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX
  59. };
  60. static const u8 ant_toggle_lookup[] = {
  61. /*ANT_NONE -> */ ANT_NONE,
  62. /*ANT_A -> */ ANT_B,
  63. /*ANT_B -> */ ANT_C,
  64. /*ANT_AB -> */ ANT_BC,
  65. /*ANT_C -> */ ANT_A,
  66. /*ANT_AC -> */ ANT_AB,
  67. /*ANT_BC -> */ ANT_AC,
  68. /*ANT_ABC -> */ ANT_ABC,
  69. };
  70. #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
  71. [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
  72. IWL_RATE_SISO_##s##M_PLCP, \
  73. IWL_RATE_MIMO2_##s##M_PLCP,\
  74. IWL_RATE_MIMO3_##s##M_PLCP,\
  75. IWL_RATE_##r##M_IEEE, \
  76. IWL_RATE_##ip##M_INDEX, \
  77. IWL_RATE_##in##M_INDEX, \
  78. IWL_RATE_##rp##M_INDEX, \
  79. IWL_RATE_##rn##M_INDEX, \
  80. IWL_RATE_##pp##M_INDEX, \
  81. IWL_RATE_##np##M_INDEX }
  82. /*
  83. * Parameter order:
  84. * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
  85. *
  86. * If there isn't a valid next or previous rate then INV is used which
  87. * maps to IWL_RATE_INVALID
  88. *
  89. */
  90. static const struct iwl_rs_rate_info iwl_rates[IWL_RATE_COUNT] = {
  91. IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
  92. IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
  93. IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
  94. IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
  95. IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
  96. IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
  97. IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
  98. IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
  99. IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
  100. IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
  101. IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
  102. IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
  103. IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
  104. /* FIXME:RS: ^^ should be INV (legacy) */
  105. };
  106. static inline u8 rs_extract_rate(u32 rate_n_flags)
  107. {
  108. /* also works for HT because bits 7:6 are zero there */
  109. return (u8)(rate_n_flags & RATE_LEGACY_RATE_MSK);
  110. }
  111. static int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
  112. {
  113. int idx = 0;
  114. /* HT rate format */
  115. if (rate_n_flags & RATE_MCS_HT_MSK) {
  116. idx = rs_extract_rate(rate_n_flags);
  117. if (idx >= IWL_RATE_MIMO3_6M_PLCP)
  118. idx = idx - IWL_RATE_MIMO3_6M_PLCP;
  119. else if (idx >= IWL_RATE_MIMO2_6M_PLCP)
  120. idx = idx - IWL_RATE_MIMO2_6M_PLCP;
  121. idx += IWL_FIRST_OFDM_RATE;
  122. /* skip 9M not supported in ht*/
  123. if (idx >= IWL_RATE_9M_INDEX)
  124. idx += 1;
  125. if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
  126. return idx;
  127. /* legacy rate format, search for match in table */
  128. } else {
  129. for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
  130. if (iwl_rates[idx].plcp ==
  131. rs_extract_rate(rate_n_flags))
  132. return idx;
  133. }
  134. return -1;
  135. }
  136. static void rs_rate_scale_perform(struct iwl_mvm *mvm,
  137. struct sk_buff *skb,
  138. struct ieee80211_sta *sta,
  139. struct iwl_lq_sta *lq_sta);
  140. static void rs_fill_link_cmd(struct iwl_mvm *mvm,
  141. struct iwl_lq_sta *lq_sta, u32 rate_n_flags);
  142. static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search);
  143. #ifdef CONFIG_MAC80211_DEBUGFS
  144. static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
  145. u32 *rate_n_flags, int index);
  146. #else
  147. static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
  148. u32 *rate_n_flags, int index)
  149. {}
  150. #endif
  151. /**
  152. * The following tables contain the expected throughput metrics for all rates
  153. *
  154. * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
  155. *
  156. * where invalid entries are zeros.
  157. *
  158. * CCK rates are only valid in legacy table and will only be used in G
  159. * (2.4 GHz) band.
  160. */
  161. static s32 expected_tpt_legacy[IWL_RATE_COUNT] = {
  162. 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 0
  163. };
  164. static s32 expected_tpt_siso20MHz[4][IWL_RATE_COUNT] = {
  165. {0, 0, 0, 0, 42, 0, 76, 102, 124, 159, 183, 193, 202}, /* Norm */
  166. {0, 0, 0, 0, 46, 0, 82, 110, 132, 168, 192, 202, 210}, /* SGI */
  167. {0, 0, 0, 0, 47, 0, 91, 133, 171, 242, 305, 334, 362}, /* AGG */
  168. {0, 0, 0, 0, 52, 0, 101, 145, 187, 264, 330, 361, 390}, /* AGG+SGI */
  169. };
  170. static s32 expected_tpt_siso40MHz[4][IWL_RATE_COUNT] = {
  171. {0, 0, 0, 0, 77, 0, 127, 160, 184, 220, 242, 250, 257}, /* Norm */
  172. {0, 0, 0, 0, 83, 0, 135, 169, 193, 229, 250, 257, 264}, /* SGI */
  173. {0, 0, 0, 0, 94, 0, 177, 249, 313, 423, 512, 550, 586}, /* AGG */
  174. {0, 0, 0, 0, 104, 0, 193, 270, 338, 454, 545, 584, 620}, /* AGG+SGI */
  175. };
  176. static s32 expected_tpt_mimo2_20MHz[4][IWL_RATE_COUNT] = {
  177. {0, 0, 0, 0, 74, 0, 123, 155, 179, 214, 236, 244, 251}, /* Norm */
  178. {0, 0, 0, 0, 81, 0, 131, 164, 188, 223, 243, 251, 257}, /* SGI */
  179. {0, 0, 0, 0, 89, 0, 167, 235, 296, 402, 488, 526, 560}, /* AGG */
  180. {0, 0, 0, 0, 97, 0, 182, 255, 320, 431, 520, 558, 593}, /* AGG+SGI*/
  181. };
  182. static s32 expected_tpt_mimo2_40MHz[4][IWL_RATE_COUNT] = {
  183. {0, 0, 0, 0, 123, 0, 182, 214, 235, 264, 279, 285, 289}, /* Norm */
  184. {0, 0, 0, 0, 131, 0, 191, 222, 242, 270, 284, 289, 293}, /* SGI */
  185. {0, 0, 0, 0, 171, 0, 305, 410, 496, 634, 731, 771, 805}, /* AGG */
  186. {0, 0, 0, 0, 186, 0, 329, 439, 527, 667, 764, 803, 838}, /* AGG+SGI */
  187. };
  188. static s32 expected_tpt_mimo3_20MHz[4][IWL_RATE_COUNT] = {
  189. {0, 0, 0, 0, 99, 0, 153, 186, 208, 239, 256, 263, 268}, /* Norm */
  190. {0, 0, 0, 0, 106, 0, 162, 194, 215, 246, 262, 268, 273}, /* SGI */
  191. {0, 0, 0, 0, 134, 0, 249, 346, 431, 574, 685, 732, 775}, /* AGG */
  192. {0, 0, 0, 0, 148, 0, 272, 376, 465, 614, 727, 775, 818}, /* AGG+SGI */
  193. };
  194. static s32 expected_tpt_mimo3_40MHz[4][IWL_RATE_COUNT] = {
  195. {0, 0, 0, 0, 152, 0, 211, 239, 255, 279, 290, 294, 297}, /* Norm */
  196. {0, 0, 0, 0, 160, 0, 219, 245, 261, 284, 294, 297, 300}, /* SGI */
  197. {0, 0, 0, 0, 254, 0, 443, 584, 695, 868, 984, 1030, 1070}, /* AGG */
  198. {0, 0, 0, 0, 277, 0, 478, 624, 737, 911, 1026, 1070, 1109}, /* AGG+SGI */
  199. };
  200. /* mbps, mcs */
  201. static const struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = {
  202. { "1", "BPSK DSSS"},
  203. { "2", "QPSK DSSS"},
  204. {"5.5", "BPSK CCK"},
  205. { "11", "QPSK CCK"},
  206. { "6", "BPSK 1/2"},
  207. { "9", "BPSK 1/2"},
  208. { "12", "QPSK 1/2"},
  209. { "18", "QPSK 3/4"},
  210. { "24", "16QAM 1/2"},
  211. { "36", "16QAM 3/4"},
  212. { "48", "64QAM 2/3"},
  213. { "54", "64QAM 3/4"},
  214. { "60", "64QAM 5/6"},
  215. };
  216. #define MCS_INDEX_PER_STREAM (8)
  217. static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window)
  218. {
  219. window->data = 0;
  220. window->success_counter = 0;
  221. window->success_ratio = IWL_INVALID_VALUE;
  222. window->counter = 0;
  223. window->average_tpt = IWL_INVALID_VALUE;
  224. window->stamp = 0;
  225. }
  226. static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type)
  227. {
  228. return (ant_type & valid_antenna) == ant_type;
  229. }
  230. /*
  231. * removes the old data from the statistics. All data that is older than
  232. * TID_MAX_TIME_DIFF, will be deleted.
  233. */
  234. static void rs_tl_rm_old_stats(struct iwl_traffic_load *tl, u32 curr_time)
  235. {
  236. /* The oldest age we want to keep */
  237. u32 oldest_time = curr_time - TID_MAX_TIME_DIFF;
  238. while (tl->queue_count &&
  239. (tl->time_stamp < oldest_time)) {
  240. tl->total -= tl->packet_count[tl->head];
  241. tl->packet_count[tl->head] = 0;
  242. tl->time_stamp += TID_QUEUE_CELL_SPACING;
  243. tl->queue_count--;
  244. tl->head++;
  245. if (tl->head >= TID_QUEUE_MAX_SIZE)
  246. tl->head = 0;
  247. }
  248. }
  249. /*
  250. * increment traffic load value for tid and also remove
  251. * any old values if passed the certain time period
  252. */
  253. static u8 rs_tl_add_packet(struct iwl_lq_sta *lq_data,
  254. struct ieee80211_hdr *hdr)
  255. {
  256. u32 curr_time = jiffies_to_msecs(jiffies);
  257. u32 time_diff;
  258. s32 index;
  259. struct iwl_traffic_load *tl = NULL;
  260. u8 tid;
  261. if (ieee80211_is_data_qos(hdr->frame_control)) {
  262. u8 *qc = ieee80211_get_qos_ctl(hdr);
  263. tid = qc[0] & 0xf;
  264. } else {
  265. return IWL_MAX_TID_COUNT;
  266. }
  267. if (unlikely(tid >= IWL_MAX_TID_COUNT))
  268. return IWL_MAX_TID_COUNT;
  269. tl = &lq_data->load[tid];
  270. curr_time -= curr_time % TID_ROUND_VALUE;
  271. /* Happens only for the first packet. Initialize the data */
  272. if (!(tl->queue_count)) {
  273. tl->total = 1;
  274. tl->time_stamp = curr_time;
  275. tl->queue_count = 1;
  276. tl->head = 0;
  277. tl->packet_count[0] = 1;
  278. return IWL_MAX_TID_COUNT;
  279. }
  280. time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
  281. index = time_diff / TID_QUEUE_CELL_SPACING;
  282. /* The history is too long: remove data that is older than */
  283. /* TID_MAX_TIME_DIFF */
  284. if (index >= TID_QUEUE_MAX_SIZE)
  285. rs_tl_rm_old_stats(tl, curr_time);
  286. index = (tl->head + index) % TID_QUEUE_MAX_SIZE;
  287. tl->packet_count[index] = tl->packet_count[index] + 1;
  288. tl->total = tl->total + 1;
  289. if ((index + 1) > tl->queue_count)
  290. tl->queue_count = index + 1;
  291. return tid;
  292. }
  293. #ifdef CONFIG_MAC80211_DEBUGFS
  294. /**
  295. * Program the device to use fixed rate for frame transmit
  296. * This is for debugging/testing only
  297. * once the device start use fixed rate, we need to reload the module
  298. * to being back the normal operation.
  299. */
  300. static void rs_program_fix_rate(struct iwl_mvm *mvm,
  301. struct iwl_lq_sta *lq_sta)
  302. {
  303. lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */
  304. lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
  305. lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
  306. lq_sta->active_mimo3_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
  307. IWL_DEBUG_RATE(mvm, "sta_id %d rate 0x%X\n",
  308. lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate);
  309. if (lq_sta->dbg_fixed_rate) {
  310. rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate);
  311. iwl_mvm_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC, false);
  312. }
  313. }
  314. #endif
  315. /*
  316. get the traffic load value for tid
  317. */
  318. static u32 rs_tl_get_load(struct iwl_lq_sta *lq_data, u8 tid)
  319. {
  320. u32 curr_time = jiffies_to_msecs(jiffies);
  321. u32 time_diff;
  322. s32 index;
  323. struct iwl_traffic_load *tl = NULL;
  324. if (tid >= IWL_MAX_TID_COUNT)
  325. return 0;
  326. tl = &(lq_data->load[tid]);
  327. curr_time -= curr_time % TID_ROUND_VALUE;
  328. if (!(tl->queue_count))
  329. return 0;
  330. time_diff = TIME_WRAP_AROUND(tl->time_stamp, curr_time);
  331. index = time_diff / TID_QUEUE_CELL_SPACING;
  332. /* The history is too long: remove data that is older than */
  333. /* TID_MAX_TIME_DIFF */
  334. if (index >= TID_QUEUE_MAX_SIZE)
  335. rs_tl_rm_old_stats(tl, curr_time);
  336. return tl->total;
  337. }
  338. static int rs_tl_turn_on_agg_for_tid(struct iwl_mvm *mvm,
  339. struct iwl_lq_sta *lq_data, u8 tid,
  340. struct ieee80211_sta *sta)
  341. {
  342. int ret = -EAGAIN;
  343. u32 load;
  344. load = rs_tl_get_load(lq_data, tid);
  345. if ((iwlwifi_mod_params.auto_agg) || (load > IWL_AGG_LOAD_THRESHOLD)) {
  346. IWL_DEBUG_HT(mvm, "Starting Tx agg: STA: %pM tid: %d\n",
  347. sta->addr, tid);
  348. ret = ieee80211_start_tx_ba_session(sta, tid, 5000);
  349. if (ret == -EAGAIN) {
  350. /*
  351. * driver and mac80211 is out of sync
  352. * this might be cause by reloading firmware
  353. * stop the tx ba session here
  354. */
  355. IWL_ERR(mvm, "Fail start Tx agg on tid: %d\n",
  356. tid);
  357. ieee80211_stop_tx_ba_session(sta, tid);
  358. }
  359. } else {
  360. IWL_DEBUG_HT(mvm,
  361. "Aggregation not enabled for tid %d because load = %u\n",
  362. tid, load);
  363. }
  364. return ret;
  365. }
  366. static void rs_tl_turn_on_agg(struct iwl_mvm *mvm, u8 tid,
  367. struct iwl_lq_sta *lq_data,
  368. struct ieee80211_sta *sta)
  369. {
  370. if (tid < IWL_MAX_TID_COUNT)
  371. rs_tl_turn_on_agg_for_tid(mvm, lq_data, tid, sta);
  372. else
  373. IWL_ERR(mvm, "tid exceeds max TID count: %d/%d\n",
  374. tid, IWL_MAX_TID_COUNT);
  375. }
  376. static inline int get_num_of_ant_from_rate(u32 rate_n_flags)
  377. {
  378. return !!(rate_n_flags & RATE_MCS_ANT_A_MSK) +
  379. !!(rate_n_flags & RATE_MCS_ANT_B_MSK) +
  380. !!(rate_n_flags & RATE_MCS_ANT_C_MSK);
  381. }
  382. /*
  383. * Static function to get the expected throughput from an iwl_scale_tbl_info
  384. * that wraps a NULL pointer check
  385. */
  386. static s32 get_expected_tpt(struct iwl_scale_tbl_info *tbl, int rs_index)
  387. {
  388. if (tbl->expected_tpt)
  389. return tbl->expected_tpt[rs_index];
  390. return 0;
  391. }
  392. /**
  393. * rs_collect_tx_data - Update the success/failure sliding window
  394. *
  395. * We keep a sliding window of the last 62 packets transmitted
  396. * at this rate. window->data contains the bitmask of successful
  397. * packets.
  398. */
  399. static int rs_collect_tx_data(struct iwl_scale_tbl_info *tbl,
  400. int scale_index, int attempts, int successes)
  401. {
  402. struct iwl_rate_scale_data *window = NULL;
  403. static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1));
  404. s32 fail_count, tpt;
  405. if (scale_index < 0 || scale_index >= IWL_RATE_COUNT)
  406. return -EINVAL;
  407. /* Select window for current tx bit rate */
  408. window = &(tbl->win[scale_index]);
  409. /* Get expected throughput */
  410. tpt = get_expected_tpt(tbl, scale_index);
  411. /*
  412. * Keep track of only the latest 62 tx frame attempts in this rate's
  413. * history window; anything older isn't really relevant any more.
  414. * If we have filled up the sliding window, drop the oldest attempt;
  415. * if the oldest attempt (highest bit in bitmap) shows "success",
  416. * subtract "1" from the success counter (this is the main reason
  417. * we keep these bitmaps!).
  418. */
  419. while (attempts > 0) {
  420. if (window->counter >= IWL_RATE_MAX_WINDOW) {
  421. /* remove earliest */
  422. window->counter = IWL_RATE_MAX_WINDOW - 1;
  423. if (window->data & mask) {
  424. window->data &= ~mask;
  425. window->success_counter--;
  426. }
  427. }
  428. /* Increment frames-attempted counter */
  429. window->counter++;
  430. /* Shift bitmap by one frame to throw away oldest history */
  431. window->data <<= 1;
  432. /* Mark the most recent #successes attempts as successful */
  433. if (successes > 0) {
  434. window->success_counter++;
  435. window->data |= 0x1;
  436. successes--;
  437. }
  438. attempts--;
  439. }
  440. /* Calculate current success ratio, avoid divide-by-0! */
  441. if (window->counter > 0)
  442. window->success_ratio = 128 * (100 * window->success_counter)
  443. / window->counter;
  444. else
  445. window->success_ratio = IWL_INVALID_VALUE;
  446. fail_count = window->counter - window->success_counter;
  447. /* Calculate average throughput, if we have enough history. */
  448. if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
  449. (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
  450. window->average_tpt = (window->success_ratio * tpt + 64) / 128;
  451. else
  452. window->average_tpt = IWL_INVALID_VALUE;
  453. /* Tag this window as having been updated */
  454. window->stamp = jiffies;
  455. return 0;
  456. }
  457. /*
  458. * Fill uCode API rate_n_flags field, based on "search" or "active" table.
  459. */
  460. /* FIXME:RS:remove this function and put the flags statically in the table */
  461. static u32 rate_n_flags_from_tbl(struct iwl_mvm *mvm,
  462. struct iwl_scale_tbl_info *tbl,
  463. int index, u8 use_green)
  464. {
  465. u32 rate_n_flags = 0;
  466. if (is_legacy(tbl->lq_type)) {
  467. rate_n_flags = iwl_rates[index].plcp;
  468. if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
  469. rate_n_flags |= RATE_MCS_CCK_MSK;
  470. } else if (is_Ht(tbl->lq_type)) {
  471. if (index > IWL_LAST_OFDM_RATE) {
  472. IWL_ERR(mvm, "Invalid HT rate index %d\n", index);
  473. index = IWL_LAST_OFDM_RATE;
  474. }
  475. rate_n_flags = RATE_MCS_HT_MSK;
  476. if (is_siso(tbl->lq_type))
  477. rate_n_flags |= iwl_rates[index].plcp_siso;
  478. else if (is_mimo2(tbl->lq_type))
  479. rate_n_flags |= iwl_rates[index].plcp_mimo2;
  480. else
  481. rate_n_flags |= iwl_rates[index].plcp_mimo3;
  482. } else {
  483. IWL_ERR(mvm, "Invalid tbl->lq_type %d\n", tbl->lq_type);
  484. }
  485. rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) &
  486. RATE_MCS_ANT_ABC_MSK);
  487. if (is_Ht(tbl->lq_type)) {
  488. if (tbl->is_ht40)
  489. rate_n_flags |= RATE_MCS_CHAN_WIDTH_40;
  490. if (tbl->is_SGI)
  491. rate_n_flags |= RATE_MCS_SGI_MSK;
  492. if (use_green) {
  493. rate_n_flags |= RATE_HT_MCS_GF_MSK;
  494. if (is_siso(tbl->lq_type) && tbl->is_SGI) {
  495. rate_n_flags &= ~RATE_MCS_SGI_MSK;
  496. IWL_ERR(mvm, "GF was set with SGI:SISO\n");
  497. }
  498. }
  499. }
  500. return rate_n_flags;
  501. }
  502. /*
  503. * Interpret uCode API's rate_n_flags format,
  504. * fill "search" or "active" tx mode table.
  505. */
  506. static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
  507. enum ieee80211_band band,
  508. struct iwl_scale_tbl_info *tbl,
  509. int *rate_idx)
  510. {
  511. u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK);
  512. u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags);
  513. u8 mcs;
  514. memset(tbl, 0, sizeof(struct iwl_scale_tbl_info));
  515. *rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags);
  516. if (*rate_idx == IWL_RATE_INVALID) {
  517. *rate_idx = -1;
  518. return -EINVAL;
  519. }
  520. tbl->is_SGI = 0; /* default legacy setup */
  521. tbl->is_ht40 = 0;
  522. tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
  523. tbl->lq_type = LQ_NONE;
  524. tbl->max_search = IWL_MAX_SEARCH;
  525. /* legacy rate format */
  526. if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
  527. if (num_of_ant == 1) {
  528. if (band == IEEE80211_BAND_5GHZ)
  529. tbl->lq_type = LQ_A;
  530. else
  531. tbl->lq_type = LQ_G;
  532. }
  533. /* HT rate format */
  534. } else {
  535. if (rate_n_flags & RATE_MCS_SGI_MSK)
  536. tbl->is_SGI = 1;
  537. if (rate_n_flags & RATE_MCS_CHAN_WIDTH_40) /* TODO */
  538. tbl->is_ht40 = 1;
  539. mcs = rs_extract_rate(rate_n_flags);
  540. /* SISO */
  541. if (mcs <= IWL_RATE_SISO_60M_PLCP) {
  542. if (num_of_ant == 1)
  543. tbl->lq_type = LQ_SISO; /*else NONE*/
  544. /* MIMO2 */
  545. } else if (mcs <= IWL_RATE_MIMO2_60M_PLCP) {
  546. if (num_of_ant == 2)
  547. tbl->lq_type = LQ_MIMO2;
  548. /* MIMO3 */
  549. } else {
  550. if (num_of_ant == 3) {
  551. tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
  552. tbl->lq_type = LQ_MIMO3;
  553. }
  554. }
  555. }
  556. return 0;
  557. }
  558. /* switch to another antenna/antennas and return 1 */
  559. /* if no other valid antenna found, return 0 */
  560. static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
  561. struct iwl_scale_tbl_info *tbl)
  562. {
  563. u8 new_ant_type;
  564. if (!tbl->ant_type || tbl->ant_type > ANT_ABC)
  565. return 0;
  566. if (!rs_is_valid_ant(valid_ant, tbl->ant_type))
  567. return 0;
  568. new_ant_type = ant_toggle_lookup[tbl->ant_type];
  569. while ((new_ant_type != tbl->ant_type) &&
  570. !rs_is_valid_ant(valid_ant, new_ant_type))
  571. new_ant_type = ant_toggle_lookup[new_ant_type];
  572. if (new_ant_type == tbl->ant_type)
  573. return 0;
  574. tbl->ant_type = new_ant_type;
  575. *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK;
  576. *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS;
  577. return 1;
  578. }
  579. /**
  580. * Green-field mode is valid if the station supports it and
  581. * there are no non-GF stations present in the BSS.
  582. */
  583. static bool rs_use_green(struct ieee80211_sta *sta)
  584. {
  585. struct iwl_mvm_sta *sta_priv = (void *)sta->drv_priv;
  586. bool use_green = !(sta_priv->vif->bss_conf.ht_operation_mode &
  587. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  588. return (sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) && use_green;
  589. }
  590. /**
  591. * rs_get_supported_rates - get the available rates
  592. *
  593. * if management frame or broadcast frame only return
  594. * basic available rates.
  595. *
  596. */
  597. static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta,
  598. struct ieee80211_hdr *hdr,
  599. enum iwl_table_type rate_type)
  600. {
  601. if (is_legacy(rate_type)) {
  602. return lq_sta->active_legacy_rate;
  603. } else {
  604. if (is_siso(rate_type))
  605. return lq_sta->active_siso_rate;
  606. else if (is_mimo2(rate_type))
  607. return lq_sta->active_mimo2_rate;
  608. else
  609. return lq_sta->active_mimo3_rate;
  610. }
  611. }
  612. static u16 rs_get_adjacent_rate(struct iwl_mvm *mvm, u8 index, u16 rate_mask,
  613. int rate_type)
  614. {
  615. u8 high = IWL_RATE_INVALID;
  616. u8 low = IWL_RATE_INVALID;
  617. /* 802.11A or ht walks to the next literal adjacent rate in
  618. * the rate table */
  619. if (is_a_band(rate_type) || !is_legacy(rate_type)) {
  620. int i;
  621. u32 mask;
  622. /* Find the previous rate that is in the rate mask */
  623. i = index - 1;
  624. for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
  625. if (rate_mask & mask) {
  626. low = i;
  627. break;
  628. }
  629. }
  630. /* Find the next rate that is in the rate mask */
  631. i = index + 1;
  632. for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
  633. if (rate_mask & mask) {
  634. high = i;
  635. break;
  636. }
  637. }
  638. return (high << 8) | low;
  639. }
  640. low = index;
  641. while (low != IWL_RATE_INVALID) {
  642. low = iwl_rates[low].prev_rs;
  643. if (low == IWL_RATE_INVALID)
  644. break;
  645. if (rate_mask & (1 << low))
  646. break;
  647. IWL_DEBUG_RATE(mvm, "Skipping masked lower rate: %d\n", low);
  648. }
  649. high = index;
  650. while (high != IWL_RATE_INVALID) {
  651. high = iwl_rates[high].next_rs;
  652. if (high == IWL_RATE_INVALID)
  653. break;
  654. if (rate_mask & (1 << high))
  655. break;
  656. IWL_DEBUG_RATE(mvm, "Skipping masked higher rate: %d\n", high);
  657. }
  658. return (high << 8) | low;
  659. }
  660. static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
  661. struct iwl_scale_tbl_info *tbl,
  662. u8 scale_index, u8 ht_possible)
  663. {
  664. s32 low;
  665. u16 rate_mask;
  666. u16 high_low;
  667. u8 switch_to_legacy = 0;
  668. u8 is_green = lq_sta->is_green;
  669. struct iwl_mvm *mvm = lq_sta->drv;
  670. /* check if we need to switch from HT to legacy rates.
  671. * assumption is that mandatory rates (1Mbps or 6Mbps)
  672. * are always supported (spec demand) */
  673. if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
  674. switch_to_legacy = 1;
  675. scale_index = rs_ht_to_legacy[scale_index];
  676. if (lq_sta->band == IEEE80211_BAND_5GHZ)
  677. tbl->lq_type = LQ_A;
  678. else
  679. tbl->lq_type = LQ_G;
  680. if (num_of_ant(tbl->ant_type) > 1)
  681. tbl->ant_type =
  682. first_antenna(mvm->nvm_data->valid_tx_ant);
  683. tbl->is_ht40 = 0;
  684. tbl->is_SGI = 0;
  685. tbl->max_search = IWL_MAX_SEARCH;
  686. }
  687. rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
  688. /* Mask with station rate restriction */
  689. if (is_legacy(tbl->lq_type)) {
  690. /* supp_rates has no CCK bits in A mode */
  691. if (lq_sta->band == IEEE80211_BAND_5GHZ)
  692. rate_mask = (u16)(rate_mask &
  693. (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
  694. else
  695. rate_mask = (u16)(rate_mask & lq_sta->supp_rates);
  696. }
  697. /* If we switched from HT to legacy, check current rate */
  698. if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
  699. low = scale_index;
  700. goto out;
  701. }
  702. high_low = rs_get_adjacent_rate(lq_sta->drv, scale_index, rate_mask,
  703. tbl->lq_type);
  704. low = high_low & 0xff;
  705. if (low == IWL_RATE_INVALID)
  706. low = scale_index;
  707. out:
  708. return rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green);
  709. }
  710. /*
  711. * Simple function to compare two rate scale table types
  712. */
  713. static bool table_type_matches(struct iwl_scale_tbl_info *a,
  714. struct iwl_scale_tbl_info *b)
  715. {
  716. return (a->lq_type == b->lq_type) && (a->ant_type == b->ant_type) &&
  717. (a->is_SGI == b->is_SGI);
  718. }
  719. /*
  720. * mac80211 sends us Tx status
  721. */
  722. static void rs_tx_status(void *mvm_r, struct ieee80211_supported_band *sband,
  723. struct ieee80211_sta *sta, void *priv_sta,
  724. struct sk_buff *skb)
  725. {
  726. int legacy_success;
  727. int retries;
  728. int rs_index, mac_index, i;
  729. struct iwl_lq_sta *lq_sta = priv_sta;
  730. struct iwl_lq_cmd *table;
  731. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  732. struct iwl_op_mode *op_mode = (struct iwl_op_mode *)mvm_r;
  733. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  734. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  735. enum mac80211_rate_control_flags mac_flags;
  736. u32 tx_rate;
  737. struct iwl_scale_tbl_info tbl_type;
  738. struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl;
  739. IWL_DEBUG_RATE_LIMIT(mvm,
  740. "get frame ack response, update rate scale window\n");
  741. /* Treat uninitialized rate scaling data same as non-existing. */
  742. if (!lq_sta) {
  743. IWL_DEBUG_RATE(mvm, "Station rate scaling not created yet.\n");
  744. return;
  745. } else if (!lq_sta->drv) {
  746. IWL_DEBUG_RATE(mvm, "Rate scaling not initialized yet.\n");
  747. return;
  748. }
  749. if (!ieee80211_is_data(hdr->frame_control) ||
  750. info->flags & IEEE80211_TX_CTL_NO_ACK)
  751. return;
  752. /* This packet was aggregated but doesn't carry status info */
  753. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  754. !(info->flags & IEEE80211_TX_STAT_AMPDU))
  755. return;
  756. /*
  757. * Ignore this Tx frame response if its initial rate doesn't match
  758. * that of latest Link Quality command. There may be stragglers
  759. * from a previous Link Quality command, but we're no longer interested
  760. * in those; they're either from the "active" mode while we're trying
  761. * to check "search" mode, or a prior "search" mode after we've moved
  762. * to a new "search" mode (which might become the new "active" mode).
  763. */
  764. table = &lq_sta->lq;
  765. tx_rate = le32_to_cpu(table->rs_table[0]);
  766. rs_get_tbl_info_from_mcs(tx_rate, info->band, &tbl_type, &rs_index);
  767. if (info->band == IEEE80211_BAND_5GHZ)
  768. rs_index -= IWL_FIRST_OFDM_RATE;
  769. mac_flags = info->status.rates[0].flags;
  770. mac_index = info->status.rates[0].idx;
  771. /* For HT packets, map MCS to PLCP */
  772. if (mac_flags & IEEE80211_TX_RC_MCS) {
  773. /* Remove # of streams */
  774. mac_index &= RATE_HT_MCS_RATE_CODE_MSK;
  775. if (mac_index >= (IWL_RATE_9M_INDEX - IWL_FIRST_OFDM_RATE))
  776. mac_index++;
  777. /*
  778. * mac80211 HT index is always zero-indexed; we need to move
  779. * HT OFDM rates after CCK rates in 2.4 GHz band
  780. */
  781. if (info->band == IEEE80211_BAND_2GHZ)
  782. mac_index += IWL_FIRST_OFDM_RATE;
  783. }
  784. /* Here we actually compare this rate to the latest LQ command */
  785. if ((mac_index < 0) ||
  786. (tbl_type.is_SGI != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI)) ||
  787. (tbl_type.is_ht40 != !!(mac_flags & IEEE80211_TX_RC_40_MHZ_WIDTH)) ||
  788. (tbl_type.ant_type != info->status.antenna) ||
  789. (!!(tx_rate & RATE_MCS_HT_MSK) !=
  790. !!(mac_flags & IEEE80211_TX_RC_MCS)) ||
  791. (!!(tx_rate & RATE_HT_MCS_GF_MSK) !=
  792. !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD)) ||
  793. (rs_index != mac_index)) {
  794. IWL_DEBUG_RATE(mvm,
  795. "initial rate %d does not match %d (0x%x)\n",
  796. mac_index, rs_index, tx_rate);
  797. /*
  798. * Since rates mis-match, the last LQ command may have failed.
  799. * After IWL_MISSED_RATE_MAX mis-matches, resync the uCode with
  800. * ... driver.
  801. */
  802. lq_sta->missed_rate_counter++;
  803. if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) {
  804. lq_sta->missed_rate_counter = 0;
  805. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_ASYNC, false);
  806. }
  807. /* Regardless, ignore this status info for outdated rate */
  808. return;
  809. } else
  810. /* Rate did match, so reset the missed_rate_counter */
  811. lq_sta->missed_rate_counter = 0;
  812. /* Figure out if rate scale algorithm is in active or search table */
  813. if (table_type_matches(&tbl_type,
  814. &(lq_sta->lq_info[lq_sta->active_tbl]))) {
  815. curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  816. other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
  817. } else if (table_type_matches(
  818. &tbl_type, &lq_sta->lq_info[1 - lq_sta->active_tbl])) {
  819. curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
  820. other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  821. } else {
  822. IWL_DEBUG_RATE(mvm,
  823. "Neither active nor search matches tx rate\n");
  824. tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  825. IWL_DEBUG_RATE(mvm, "active- lq:%x, ant:%x, SGI:%d\n",
  826. tmp_tbl->lq_type, tmp_tbl->ant_type,
  827. tmp_tbl->is_SGI);
  828. tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
  829. IWL_DEBUG_RATE(mvm, "search- lq:%x, ant:%x, SGI:%d\n",
  830. tmp_tbl->lq_type, tmp_tbl->ant_type,
  831. tmp_tbl->is_SGI);
  832. IWL_DEBUG_RATE(mvm, "actual- lq:%x, ant:%x, SGI:%d\n",
  833. tbl_type.lq_type, tbl_type.ant_type,
  834. tbl_type.is_SGI);
  835. /*
  836. * no matching table found, let's by-pass the data collection
  837. * and continue to perform rate scale to find the rate table
  838. */
  839. rs_stay_in_table(lq_sta, true);
  840. goto done;
  841. }
  842. /*
  843. * Updating the frame history depends on whether packets were
  844. * aggregated.
  845. *
  846. * For aggregation, all packets were transmitted at the same rate, the
  847. * first index into rate scale table.
  848. */
  849. if (info->flags & IEEE80211_TX_STAT_AMPDU) {
  850. tx_rate = le32_to_cpu(table->rs_table[0]);
  851. rs_get_tbl_info_from_mcs(tx_rate, info->band, &tbl_type,
  852. &rs_index);
  853. rs_collect_tx_data(curr_tbl, rs_index,
  854. info->status.ampdu_len,
  855. info->status.ampdu_ack_len);
  856. /* Update success/fail counts if not searching for new mode */
  857. if (lq_sta->stay_in_tbl) {
  858. lq_sta->total_success += info->status.ampdu_ack_len;
  859. lq_sta->total_failed += (info->status.ampdu_len -
  860. info->status.ampdu_ack_len);
  861. }
  862. } else {
  863. /*
  864. * For legacy, update frame history with for each Tx retry.
  865. */
  866. retries = info->status.rates[0].count - 1;
  867. /* HW doesn't send more than 15 retries */
  868. retries = min(retries, 15);
  869. /* The last transmission may have been successful */
  870. legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK);
  871. /* Collect data for each rate used during failed TX attempts */
  872. for (i = 0; i <= retries; ++i) {
  873. tx_rate = le32_to_cpu(table->rs_table[i]);
  874. rs_get_tbl_info_from_mcs(tx_rate, info->band,
  875. &tbl_type, &rs_index);
  876. /*
  877. * Only collect stats if retried rate is in the same RS
  878. * table as active/search.
  879. */
  880. if (table_type_matches(&tbl_type, curr_tbl))
  881. tmp_tbl = curr_tbl;
  882. else if (table_type_matches(&tbl_type, other_tbl))
  883. tmp_tbl = other_tbl;
  884. else
  885. continue;
  886. rs_collect_tx_data(tmp_tbl, rs_index, 1,
  887. i < retries ? 0 : legacy_success);
  888. }
  889. /* Update success/fail counts if not searching for new mode */
  890. if (lq_sta->stay_in_tbl) {
  891. lq_sta->total_success += legacy_success;
  892. lq_sta->total_failed += retries + (1 - legacy_success);
  893. }
  894. }
  895. /* The last TX rate is cached in lq_sta; it's set in if/else above */
  896. lq_sta->last_rate_n_flags = tx_rate;
  897. done:
  898. /* See if there's a better rate or modulation mode to try. */
  899. if (sta && sta->supp_rates[sband->band])
  900. rs_rate_scale_perform(mvm, skb, sta, lq_sta);
  901. }
  902. /*
  903. * Begin a period of staying with a selected modulation mode.
  904. * Set "stay_in_tbl" flag to prevent any mode switches.
  905. * Set frame tx success limits according to legacy vs. high-throughput,
  906. * and reset overall (spanning all rates) tx success history statistics.
  907. * These control how long we stay using same modulation mode before
  908. * searching for a new mode.
  909. */
  910. static void rs_set_stay_in_table(struct iwl_mvm *mvm, u8 is_legacy,
  911. struct iwl_lq_sta *lq_sta)
  912. {
  913. IWL_DEBUG_RATE(mvm, "we are staying in the same table\n");
  914. lq_sta->stay_in_tbl = 1; /* only place this gets set */
  915. if (is_legacy) {
  916. lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT;
  917. lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
  918. lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT;
  919. } else {
  920. lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
  921. lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
  922. lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
  923. }
  924. lq_sta->table_count = 0;
  925. lq_sta->total_failed = 0;
  926. lq_sta->total_success = 0;
  927. lq_sta->flush_timer = jiffies;
  928. lq_sta->action_counter = 0;
  929. }
  930. /*
  931. * Find correct throughput table for given mode of modulation
  932. */
  933. static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta,
  934. struct iwl_scale_tbl_info *tbl)
  935. {
  936. /* Used to choose among HT tables */
  937. s32 (*ht_tbl_pointer)[IWL_RATE_COUNT];
  938. /* Check for invalid LQ type */
  939. if (WARN_ON_ONCE(!is_legacy(tbl->lq_type) && !is_Ht(tbl->lq_type))) {
  940. tbl->expected_tpt = expected_tpt_legacy;
  941. return;
  942. }
  943. /* Legacy rates have only one table */
  944. if (is_legacy(tbl->lq_type)) {
  945. tbl->expected_tpt = expected_tpt_legacy;
  946. return;
  947. }
  948. /* Choose among many HT tables depending on number of streams
  949. * (SISO/MIMO2/MIMO3), channel width (20/40), SGI, and aggregation
  950. * status */
  951. if (is_siso(tbl->lq_type) && !tbl->is_ht40)
  952. ht_tbl_pointer = expected_tpt_siso20MHz;
  953. else if (is_siso(tbl->lq_type))
  954. ht_tbl_pointer = expected_tpt_siso40MHz;
  955. else if (is_mimo2(tbl->lq_type) && !tbl->is_ht40)
  956. ht_tbl_pointer = expected_tpt_mimo2_20MHz;
  957. else if (is_mimo2(tbl->lq_type))
  958. ht_tbl_pointer = expected_tpt_mimo2_40MHz;
  959. else if (is_mimo3(tbl->lq_type) && !tbl->is_ht40)
  960. ht_tbl_pointer = expected_tpt_mimo3_20MHz;
  961. else /* if (is_mimo3(tbl->lq_type)) <-- must be true */
  962. ht_tbl_pointer = expected_tpt_mimo3_40MHz;
  963. if (!tbl->is_SGI && !lq_sta->is_agg) /* Normal */
  964. tbl->expected_tpt = ht_tbl_pointer[0];
  965. else if (tbl->is_SGI && !lq_sta->is_agg) /* SGI */
  966. tbl->expected_tpt = ht_tbl_pointer[1];
  967. else if (!tbl->is_SGI && lq_sta->is_agg) /* AGG */
  968. tbl->expected_tpt = ht_tbl_pointer[2];
  969. else /* AGG+SGI */
  970. tbl->expected_tpt = ht_tbl_pointer[3];
  971. }
  972. /*
  973. * Find starting rate for new "search" high-throughput mode of modulation.
  974. * Goal is to find lowest expected rate (under perfect conditions) that is
  975. * above the current measured throughput of "active" mode, to give new mode
  976. * a fair chance to prove itself without too many challenges.
  977. *
  978. * This gets called when transitioning to more aggressive modulation
  979. * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive
  980. * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need
  981. * to decrease to match "active" throughput. When moving from MIMO to SISO,
  982. * bit rate will typically need to increase, but not if performance was bad.
  983. */
  984. static s32 rs_get_best_rate(struct iwl_mvm *mvm,
  985. struct iwl_lq_sta *lq_sta,
  986. struct iwl_scale_tbl_info *tbl, /* "search" */
  987. u16 rate_mask, s8 index)
  988. {
  989. /* "active" values */
  990. struct iwl_scale_tbl_info *active_tbl =
  991. &(lq_sta->lq_info[lq_sta->active_tbl]);
  992. s32 active_sr = active_tbl->win[index].success_ratio;
  993. s32 active_tpt = active_tbl->expected_tpt[index];
  994. /* expected "search" throughput */
  995. s32 *tpt_tbl = tbl->expected_tpt;
  996. s32 new_rate, high, low, start_hi;
  997. u16 high_low;
  998. s8 rate = index;
  999. new_rate = high = low = start_hi = IWL_RATE_INVALID;
  1000. while (1) {
  1001. high_low = rs_get_adjacent_rate(mvm, rate, rate_mask,
  1002. tbl->lq_type);
  1003. low = high_low & 0xff;
  1004. high = (high_low >> 8) & 0xff;
  1005. /*
  1006. * Lower the "search" bit rate, to give new "search" mode
  1007. * approximately the same throughput as "active" if:
  1008. *
  1009. * 1) "Active" mode has been working modestly well (but not
  1010. * great), and expected "search" throughput (under perfect
  1011. * conditions) at candidate rate is above the actual
  1012. * measured "active" throughput (but less than expected
  1013. * "active" throughput under perfect conditions).
  1014. * OR
  1015. * 2) "Active" mode has been working perfectly or very well
  1016. * and expected "search" throughput (under perfect
  1017. * conditions) at candidate rate is above expected
  1018. * "active" throughput (under perfect conditions).
  1019. */
  1020. if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) &&
  1021. ((active_sr > IWL_RATE_DECREASE_TH) &&
  1022. (active_sr <= IWL_RATE_HIGH_TH) &&
  1023. (tpt_tbl[rate] <= active_tpt))) ||
  1024. ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
  1025. (tpt_tbl[rate] > active_tpt))) {
  1026. /* (2nd or later pass)
  1027. * If we've already tried to raise the rate, and are
  1028. * now trying to lower it, use the higher rate. */
  1029. if (start_hi != IWL_RATE_INVALID) {
  1030. new_rate = start_hi;
  1031. break;
  1032. }
  1033. new_rate = rate;
  1034. /* Loop again with lower rate */
  1035. if (low != IWL_RATE_INVALID)
  1036. rate = low;
  1037. /* Lower rate not available, use the original */
  1038. else
  1039. break;
  1040. /* Else try to raise the "search" rate to match "active" */
  1041. } else {
  1042. /* (2nd or later pass)
  1043. * If we've already tried to lower the rate, and are
  1044. * now trying to raise it, use the lower rate. */
  1045. if (new_rate != IWL_RATE_INVALID)
  1046. break;
  1047. /* Loop again with higher rate */
  1048. else if (high != IWL_RATE_INVALID) {
  1049. start_hi = high;
  1050. rate = high;
  1051. /* Higher rate not available, use the original */
  1052. } else {
  1053. new_rate = rate;
  1054. break;
  1055. }
  1056. }
  1057. }
  1058. return new_rate;
  1059. }
  1060. static bool iwl_is_ht40_tx_allowed(struct ieee80211_sta *sta)
  1061. {
  1062. return sta->bandwidth >= IEEE80211_STA_RX_BW_40;
  1063. }
  1064. /*
  1065. * Set up search table for MIMO2
  1066. */
  1067. static int rs_switch_to_mimo2(struct iwl_mvm *mvm,
  1068. struct iwl_lq_sta *lq_sta,
  1069. struct ieee80211_sta *sta,
  1070. struct iwl_scale_tbl_info *tbl, int index)
  1071. {
  1072. u16 rate_mask;
  1073. s32 rate;
  1074. s8 is_green = lq_sta->is_green;
  1075. if (!sta->ht_cap.ht_supported)
  1076. return -1;
  1077. if (sta->smps_mode == IEEE80211_SMPS_STATIC)
  1078. return -1;
  1079. /* Need both Tx chains/antennas to support MIMO */
  1080. if (num_of_ant(mvm->nvm_data->valid_tx_ant) < 2)
  1081. return -1;
  1082. IWL_DEBUG_RATE(mvm, "LQ: try to switch to MIMO2\n");
  1083. tbl->lq_type = LQ_MIMO2;
  1084. tbl->action = 0;
  1085. tbl->max_search = IWL_MAX_SEARCH;
  1086. rate_mask = lq_sta->active_mimo2_rate;
  1087. if (iwl_is_ht40_tx_allowed(sta))
  1088. tbl->is_ht40 = 1;
  1089. else
  1090. tbl->is_ht40 = 0;
  1091. rs_set_expected_tpt_table(lq_sta, tbl);
  1092. rate = rs_get_best_rate(mvm, lq_sta, tbl, rate_mask, index);
  1093. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 best rate %d mask %X\n",
  1094. rate, rate_mask);
  1095. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
  1096. IWL_DEBUG_RATE(mvm, "Can't switch with index %d rate mask %x\n",
  1097. rate, rate_mask);
  1098. return -1;
  1099. }
  1100. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, rate, is_green);
  1101. IWL_DEBUG_RATE(mvm, "LQ: Switch to new mcs %X index is green %X\n",
  1102. tbl->current_rate, is_green);
  1103. return 0;
  1104. }
  1105. /*
  1106. * Set up search table for MIMO3
  1107. */
  1108. static int rs_switch_to_mimo3(struct iwl_mvm *mvm,
  1109. struct iwl_lq_sta *lq_sta,
  1110. struct ieee80211_sta *sta,
  1111. struct iwl_scale_tbl_info *tbl, int index)
  1112. {
  1113. u16 rate_mask;
  1114. s32 rate;
  1115. s8 is_green = lq_sta->is_green;
  1116. if (!sta->ht_cap.ht_supported)
  1117. return -1;
  1118. if (sta->smps_mode == IEEE80211_SMPS_STATIC)
  1119. return -1;
  1120. /* Need both Tx chains/antennas to support MIMO */
  1121. if (num_of_ant(mvm->nvm_data->valid_tx_ant) < 3)
  1122. return -1;
  1123. IWL_DEBUG_RATE(mvm, "LQ: try to switch to MIMO3\n");
  1124. tbl->lq_type = LQ_MIMO3;
  1125. tbl->action = 0;
  1126. tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
  1127. rate_mask = lq_sta->active_mimo3_rate;
  1128. if (iwl_is_ht40_tx_allowed(sta))
  1129. tbl->is_ht40 = 1;
  1130. else
  1131. tbl->is_ht40 = 0;
  1132. rs_set_expected_tpt_table(lq_sta, tbl);
  1133. rate = rs_get_best_rate(mvm, lq_sta, tbl, rate_mask, index);
  1134. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 best rate %d mask %X\n",
  1135. rate, rate_mask);
  1136. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
  1137. IWL_DEBUG_RATE(mvm, "Can't switch with index %d rate mask %x\n",
  1138. rate, rate_mask);
  1139. return -1;
  1140. }
  1141. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, rate, is_green);
  1142. IWL_DEBUG_RATE(mvm, "LQ: Switch to new mcs %X index is green %X\n",
  1143. tbl->current_rate, is_green);
  1144. return 0;
  1145. }
  1146. /*
  1147. * Set up search table for SISO
  1148. */
  1149. static int rs_switch_to_siso(struct iwl_mvm *mvm,
  1150. struct iwl_lq_sta *lq_sta,
  1151. struct ieee80211_sta *sta,
  1152. struct iwl_scale_tbl_info *tbl, int index)
  1153. {
  1154. u16 rate_mask;
  1155. u8 is_green = lq_sta->is_green;
  1156. s32 rate;
  1157. if (!sta->ht_cap.ht_supported)
  1158. return -1;
  1159. IWL_DEBUG_RATE(mvm, "LQ: try to switch to SISO\n");
  1160. tbl->lq_type = LQ_SISO;
  1161. tbl->action = 0;
  1162. tbl->max_search = IWL_MAX_SEARCH;
  1163. rate_mask = lq_sta->active_siso_rate;
  1164. if (iwl_is_ht40_tx_allowed(sta))
  1165. tbl->is_ht40 = 1;
  1166. else
  1167. tbl->is_ht40 = 0;
  1168. if (is_green)
  1169. tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/
  1170. rs_set_expected_tpt_table(lq_sta, tbl);
  1171. rate = rs_get_best_rate(mvm, lq_sta, tbl, rate_mask, index);
  1172. IWL_DEBUG_RATE(mvm, "LQ: get best rate %d mask %X\n", rate, rate_mask);
  1173. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
  1174. IWL_DEBUG_RATE(mvm,
  1175. "can not switch with index %d rate mask %x\n",
  1176. rate, rate_mask);
  1177. return -1;
  1178. }
  1179. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, rate, is_green);
  1180. IWL_DEBUG_RATE(mvm, "LQ: Switch to new mcs %X index is green %X\n",
  1181. tbl->current_rate, is_green);
  1182. return 0;
  1183. }
  1184. /*
  1185. * Try to switch to new modulation mode from legacy
  1186. */
  1187. static int rs_move_legacy_other(struct iwl_mvm *mvm,
  1188. struct iwl_lq_sta *lq_sta,
  1189. struct ieee80211_sta *sta,
  1190. int index)
  1191. {
  1192. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1193. struct iwl_scale_tbl_info *search_tbl =
  1194. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1195. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1196. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1197. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1198. u8 start_action;
  1199. u8 valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  1200. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1201. int ret;
  1202. u8 update_search_tbl_counter = 0;
  1203. start_action = tbl->action;
  1204. while (1) {
  1205. lq_sta->action_counter++;
  1206. switch (tbl->action) {
  1207. case IWL_LEGACY_SWITCH_ANTENNA1:
  1208. case IWL_LEGACY_SWITCH_ANTENNA2:
  1209. IWL_DEBUG_RATE(mvm, "LQ: Legacy toggle Antenna\n");
  1210. if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 &&
  1211. tx_chains_num <= 1) ||
  1212. (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 &&
  1213. tx_chains_num <= 2))
  1214. break;
  1215. /* Don't change antenna if success has been great */
  1216. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1217. break;
  1218. /* Set up search table to try other antenna */
  1219. memcpy(search_tbl, tbl, sz);
  1220. if (rs_toggle_antenna(valid_tx_ant,
  1221. &search_tbl->current_rate,
  1222. search_tbl)) {
  1223. update_search_tbl_counter = 1;
  1224. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1225. goto out;
  1226. }
  1227. break;
  1228. case IWL_LEGACY_SWITCH_SISO:
  1229. IWL_DEBUG_RATE(mvm, "LQ: Legacy switch to SISO\n");
  1230. /* Set up search table to try SISO */
  1231. memcpy(search_tbl, tbl, sz);
  1232. search_tbl->is_SGI = 0;
  1233. ret = rs_switch_to_siso(mvm, lq_sta, sta,
  1234. search_tbl, index);
  1235. if (!ret) {
  1236. lq_sta->action_counter = 0;
  1237. goto out;
  1238. }
  1239. break;
  1240. case IWL_LEGACY_SWITCH_MIMO2_AB:
  1241. case IWL_LEGACY_SWITCH_MIMO2_AC:
  1242. case IWL_LEGACY_SWITCH_MIMO2_BC:
  1243. IWL_DEBUG_RATE(mvm, "LQ: Legacy switch to MIMO2\n");
  1244. /* Set up search table to try MIMO */
  1245. memcpy(search_tbl, tbl, sz);
  1246. search_tbl->is_SGI = 0;
  1247. if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AB)
  1248. search_tbl->ant_type = ANT_AB;
  1249. else if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AC)
  1250. search_tbl->ant_type = ANT_AC;
  1251. else
  1252. search_tbl->ant_type = ANT_BC;
  1253. if (!rs_is_valid_ant(valid_tx_ant,
  1254. search_tbl->ant_type))
  1255. break;
  1256. ret = rs_switch_to_mimo2(mvm, lq_sta, sta,
  1257. search_tbl, index);
  1258. if (!ret) {
  1259. lq_sta->action_counter = 0;
  1260. goto out;
  1261. }
  1262. break;
  1263. case IWL_LEGACY_SWITCH_MIMO3_ABC:
  1264. IWL_DEBUG_RATE(mvm, "LQ: Legacy switch to MIMO3\n");
  1265. /* Set up search table to try MIMO3 */
  1266. memcpy(search_tbl, tbl, sz);
  1267. search_tbl->is_SGI = 0;
  1268. search_tbl->ant_type = ANT_ABC;
  1269. if (!rs_is_valid_ant(valid_tx_ant,
  1270. search_tbl->ant_type))
  1271. break;
  1272. ret = rs_switch_to_mimo3(mvm, lq_sta, sta,
  1273. search_tbl, index);
  1274. if (!ret) {
  1275. lq_sta->action_counter = 0;
  1276. goto out;
  1277. }
  1278. break;
  1279. }
  1280. tbl->action++;
  1281. if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
  1282. tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
  1283. if (tbl->action == start_action)
  1284. break;
  1285. }
  1286. search_tbl->lq_type = LQ_NONE;
  1287. return 0;
  1288. out:
  1289. lq_sta->search_better_tbl = 1;
  1290. tbl->action++;
  1291. if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
  1292. tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
  1293. if (update_search_tbl_counter)
  1294. search_tbl->action = tbl->action;
  1295. return 0;
  1296. }
  1297. /*
  1298. * Try to switch to new modulation mode from SISO
  1299. */
  1300. static int rs_move_siso_to_other(struct iwl_mvm *mvm,
  1301. struct iwl_lq_sta *lq_sta,
  1302. struct ieee80211_sta *sta, int index)
  1303. {
  1304. u8 is_green = lq_sta->is_green;
  1305. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1306. struct iwl_scale_tbl_info *search_tbl =
  1307. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1308. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1309. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1310. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1311. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1312. u8 start_action;
  1313. u8 valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  1314. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1315. u8 update_search_tbl_counter = 0;
  1316. int ret;
  1317. start_action = tbl->action;
  1318. while (1) {
  1319. lq_sta->action_counter++;
  1320. switch (tbl->action) {
  1321. case IWL_SISO_SWITCH_ANTENNA1:
  1322. case IWL_SISO_SWITCH_ANTENNA2:
  1323. IWL_DEBUG_RATE(mvm, "LQ: SISO toggle Antenna\n");
  1324. if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 &&
  1325. tx_chains_num <= 1) ||
  1326. (tbl->action == IWL_SISO_SWITCH_ANTENNA2 &&
  1327. tx_chains_num <= 2))
  1328. break;
  1329. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1330. break;
  1331. memcpy(search_tbl, tbl, sz);
  1332. if (rs_toggle_antenna(valid_tx_ant,
  1333. &search_tbl->current_rate,
  1334. search_tbl)) {
  1335. update_search_tbl_counter = 1;
  1336. goto out;
  1337. }
  1338. break;
  1339. case IWL_SISO_SWITCH_MIMO2_AB:
  1340. case IWL_SISO_SWITCH_MIMO2_AC:
  1341. case IWL_SISO_SWITCH_MIMO2_BC:
  1342. IWL_DEBUG_RATE(mvm, "LQ: SISO switch to MIMO2\n");
  1343. memcpy(search_tbl, tbl, sz);
  1344. search_tbl->is_SGI = 0;
  1345. if (tbl->action == IWL_SISO_SWITCH_MIMO2_AB)
  1346. search_tbl->ant_type = ANT_AB;
  1347. else if (tbl->action == IWL_SISO_SWITCH_MIMO2_AC)
  1348. search_tbl->ant_type = ANT_AC;
  1349. else
  1350. search_tbl->ant_type = ANT_BC;
  1351. if (!rs_is_valid_ant(valid_tx_ant,
  1352. search_tbl->ant_type))
  1353. break;
  1354. ret = rs_switch_to_mimo2(mvm, lq_sta, sta,
  1355. search_tbl, index);
  1356. if (!ret)
  1357. goto out;
  1358. break;
  1359. case IWL_SISO_SWITCH_GI:
  1360. if (!tbl->is_ht40 && !(ht_cap->cap &
  1361. IEEE80211_HT_CAP_SGI_20))
  1362. break;
  1363. if (tbl->is_ht40 && !(ht_cap->cap &
  1364. IEEE80211_HT_CAP_SGI_40))
  1365. break;
  1366. IWL_DEBUG_RATE(mvm, "LQ: SISO toggle SGI/NGI\n");
  1367. memcpy(search_tbl, tbl, sz);
  1368. if (is_green) {
  1369. if (!tbl->is_SGI)
  1370. break;
  1371. else
  1372. IWL_ERR(mvm,
  1373. "SGI was set in GF+SISO\n");
  1374. }
  1375. search_tbl->is_SGI = !tbl->is_SGI;
  1376. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1377. if (tbl->is_SGI) {
  1378. s32 tpt = lq_sta->last_tpt / 100;
  1379. if (tpt >= search_tbl->expected_tpt[index])
  1380. break;
  1381. }
  1382. search_tbl->current_rate =
  1383. rate_n_flags_from_tbl(mvm, search_tbl,
  1384. index, is_green);
  1385. update_search_tbl_counter = 1;
  1386. goto out;
  1387. case IWL_SISO_SWITCH_MIMO3_ABC:
  1388. IWL_DEBUG_RATE(mvm, "LQ: SISO switch to MIMO3\n");
  1389. memcpy(search_tbl, tbl, sz);
  1390. search_tbl->is_SGI = 0;
  1391. search_tbl->ant_type = ANT_ABC;
  1392. if (!rs_is_valid_ant(valid_tx_ant,
  1393. search_tbl->ant_type))
  1394. break;
  1395. ret = rs_switch_to_mimo3(mvm, lq_sta, sta,
  1396. search_tbl, index);
  1397. if (!ret)
  1398. goto out;
  1399. break;
  1400. }
  1401. tbl->action++;
  1402. if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
  1403. tbl->action = IWL_SISO_SWITCH_ANTENNA1;
  1404. if (tbl->action == start_action)
  1405. break;
  1406. }
  1407. search_tbl->lq_type = LQ_NONE;
  1408. return 0;
  1409. out:
  1410. lq_sta->search_better_tbl = 1;
  1411. tbl->action++;
  1412. if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC)
  1413. tbl->action = IWL_SISO_SWITCH_ANTENNA1;
  1414. if (update_search_tbl_counter)
  1415. search_tbl->action = tbl->action;
  1416. return 0;
  1417. }
  1418. /*
  1419. * Try to switch to new modulation mode from MIMO2
  1420. */
  1421. static int rs_move_mimo2_to_other(struct iwl_mvm *mvm,
  1422. struct iwl_lq_sta *lq_sta,
  1423. struct ieee80211_sta *sta, int index)
  1424. {
  1425. s8 is_green = lq_sta->is_green;
  1426. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1427. struct iwl_scale_tbl_info *search_tbl =
  1428. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1429. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1430. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1431. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1432. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1433. u8 start_action;
  1434. u8 valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  1435. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1436. u8 update_search_tbl_counter = 0;
  1437. int ret;
  1438. start_action = tbl->action;
  1439. while (1) {
  1440. lq_sta->action_counter++;
  1441. switch (tbl->action) {
  1442. case IWL_MIMO2_SWITCH_ANTENNA1:
  1443. case IWL_MIMO2_SWITCH_ANTENNA2:
  1444. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 toggle Antennas\n");
  1445. if (tx_chains_num <= 2)
  1446. break;
  1447. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1448. break;
  1449. memcpy(search_tbl, tbl, sz);
  1450. if (rs_toggle_antenna(valid_tx_ant,
  1451. &search_tbl->current_rate,
  1452. search_tbl)) {
  1453. update_search_tbl_counter = 1;
  1454. goto out;
  1455. }
  1456. break;
  1457. case IWL_MIMO2_SWITCH_SISO_A:
  1458. case IWL_MIMO2_SWITCH_SISO_B:
  1459. case IWL_MIMO2_SWITCH_SISO_C:
  1460. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 switch to SISO\n");
  1461. /* Set up new search table for SISO */
  1462. memcpy(search_tbl, tbl, sz);
  1463. if (tbl->action == IWL_MIMO2_SWITCH_SISO_A)
  1464. search_tbl->ant_type = ANT_A;
  1465. else if (tbl->action == IWL_MIMO2_SWITCH_SISO_B)
  1466. search_tbl->ant_type = ANT_B;
  1467. else
  1468. search_tbl->ant_type = ANT_C;
  1469. if (!rs_is_valid_ant(valid_tx_ant,
  1470. search_tbl->ant_type))
  1471. break;
  1472. ret = rs_switch_to_siso(mvm, lq_sta, sta,
  1473. search_tbl, index);
  1474. if (!ret)
  1475. goto out;
  1476. break;
  1477. case IWL_MIMO2_SWITCH_GI:
  1478. if (!tbl->is_ht40 && !(ht_cap->cap &
  1479. IEEE80211_HT_CAP_SGI_20))
  1480. break;
  1481. if (tbl->is_ht40 && !(ht_cap->cap &
  1482. IEEE80211_HT_CAP_SGI_40))
  1483. break;
  1484. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 toggle SGI/NGI\n");
  1485. /* Set up new search table for MIMO2 */
  1486. memcpy(search_tbl, tbl, sz);
  1487. search_tbl->is_SGI = !tbl->is_SGI;
  1488. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1489. /*
  1490. * If active table already uses the fastest possible
  1491. * modulation (dual stream with short guard interval),
  1492. * and it's working well, there's no need to look
  1493. * for a better type of modulation!
  1494. */
  1495. if (tbl->is_SGI) {
  1496. s32 tpt = lq_sta->last_tpt / 100;
  1497. if (tpt >= search_tbl->expected_tpt[index])
  1498. break;
  1499. }
  1500. search_tbl->current_rate =
  1501. rate_n_flags_from_tbl(mvm, search_tbl,
  1502. index, is_green);
  1503. update_search_tbl_counter = 1;
  1504. goto out;
  1505. case IWL_MIMO2_SWITCH_MIMO3_ABC:
  1506. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 switch to MIMO3\n");
  1507. memcpy(search_tbl, tbl, sz);
  1508. search_tbl->is_SGI = 0;
  1509. search_tbl->ant_type = ANT_ABC;
  1510. if (!rs_is_valid_ant(valid_tx_ant,
  1511. search_tbl->ant_type))
  1512. break;
  1513. ret = rs_switch_to_mimo3(mvm, lq_sta, sta,
  1514. search_tbl, index);
  1515. if (!ret)
  1516. goto out;
  1517. break;
  1518. }
  1519. tbl->action++;
  1520. if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
  1521. tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
  1522. if (tbl->action == start_action)
  1523. break;
  1524. }
  1525. search_tbl->lq_type = LQ_NONE;
  1526. return 0;
  1527. out:
  1528. lq_sta->search_better_tbl = 1;
  1529. tbl->action++;
  1530. if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
  1531. tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
  1532. if (update_search_tbl_counter)
  1533. search_tbl->action = tbl->action;
  1534. return 0;
  1535. }
  1536. /*
  1537. * Try to switch to new modulation mode from MIMO3
  1538. */
  1539. static int rs_move_mimo3_to_other(struct iwl_mvm *mvm,
  1540. struct iwl_lq_sta *lq_sta,
  1541. struct ieee80211_sta *sta, int index)
  1542. {
  1543. s8 is_green = lq_sta->is_green;
  1544. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1545. struct iwl_scale_tbl_info *search_tbl =
  1546. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1547. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1548. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1549. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1550. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1551. u8 start_action;
  1552. u8 valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  1553. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1554. int ret;
  1555. u8 update_search_tbl_counter = 0;
  1556. start_action = tbl->action;
  1557. while (1) {
  1558. lq_sta->action_counter++;
  1559. switch (tbl->action) {
  1560. case IWL_MIMO3_SWITCH_ANTENNA1:
  1561. case IWL_MIMO3_SWITCH_ANTENNA2:
  1562. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 toggle Antennas\n");
  1563. if (tx_chains_num <= 3)
  1564. break;
  1565. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1566. break;
  1567. memcpy(search_tbl, tbl, sz);
  1568. if (rs_toggle_antenna(valid_tx_ant,
  1569. &search_tbl->current_rate,
  1570. search_tbl))
  1571. goto out;
  1572. break;
  1573. case IWL_MIMO3_SWITCH_SISO_A:
  1574. case IWL_MIMO3_SWITCH_SISO_B:
  1575. case IWL_MIMO3_SWITCH_SISO_C:
  1576. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 switch to SISO\n");
  1577. /* Set up new search table for SISO */
  1578. memcpy(search_tbl, tbl, sz);
  1579. if (tbl->action == IWL_MIMO3_SWITCH_SISO_A)
  1580. search_tbl->ant_type = ANT_A;
  1581. else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B)
  1582. search_tbl->ant_type = ANT_B;
  1583. else
  1584. search_tbl->ant_type = ANT_C;
  1585. if (!rs_is_valid_ant(valid_tx_ant,
  1586. search_tbl->ant_type))
  1587. break;
  1588. ret = rs_switch_to_siso(mvm, lq_sta, sta,
  1589. search_tbl, index);
  1590. if (!ret)
  1591. goto out;
  1592. break;
  1593. case IWL_MIMO3_SWITCH_MIMO2_AB:
  1594. case IWL_MIMO3_SWITCH_MIMO2_AC:
  1595. case IWL_MIMO3_SWITCH_MIMO2_BC:
  1596. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 switch to MIMO2\n");
  1597. memcpy(search_tbl, tbl, sz);
  1598. search_tbl->is_SGI = 0;
  1599. if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB)
  1600. search_tbl->ant_type = ANT_AB;
  1601. else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC)
  1602. search_tbl->ant_type = ANT_AC;
  1603. else
  1604. search_tbl->ant_type = ANT_BC;
  1605. if (!rs_is_valid_ant(valid_tx_ant,
  1606. search_tbl->ant_type))
  1607. break;
  1608. ret = rs_switch_to_mimo2(mvm, lq_sta, sta,
  1609. search_tbl, index);
  1610. if (!ret)
  1611. goto out;
  1612. break;
  1613. case IWL_MIMO3_SWITCH_GI:
  1614. if (!tbl->is_ht40 && !(ht_cap->cap &
  1615. IEEE80211_HT_CAP_SGI_20))
  1616. break;
  1617. if (tbl->is_ht40 && !(ht_cap->cap &
  1618. IEEE80211_HT_CAP_SGI_40))
  1619. break;
  1620. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 toggle SGI/NGI\n");
  1621. /* Set up new search table for MIMO */
  1622. memcpy(search_tbl, tbl, sz);
  1623. search_tbl->is_SGI = !tbl->is_SGI;
  1624. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1625. /*
  1626. * If active table already uses the fastest possible
  1627. * modulation (dual stream with short guard interval),
  1628. * and it's working well, there's no need to look
  1629. * for a better type of modulation!
  1630. */
  1631. if (tbl->is_SGI) {
  1632. s32 tpt = lq_sta->last_tpt / 100;
  1633. if (tpt >= search_tbl->expected_tpt[index])
  1634. break;
  1635. }
  1636. search_tbl->current_rate =
  1637. rate_n_flags_from_tbl(mvm, search_tbl,
  1638. index, is_green);
  1639. update_search_tbl_counter = 1;
  1640. goto out;
  1641. }
  1642. tbl->action++;
  1643. if (tbl->action > IWL_MIMO3_SWITCH_GI)
  1644. tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
  1645. if (tbl->action == start_action)
  1646. break;
  1647. }
  1648. search_tbl->lq_type = LQ_NONE;
  1649. return 0;
  1650. out:
  1651. lq_sta->search_better_tbl = 1;
  1652. tbl->action++;
  1653. if (tbl->action > IWL_MIMO3_SWITCH_GI)
  1654. tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
  1655. if (update_search_tbl_counter)
  1656. search_tbl->action = tbl->action;
  1657. return 0;
  1658. }
  1659. /*
  1660. * Check whether we should continue using same modulation mode, or
  1661. * begin search for a new mode, based on:
  1662. * 1) # tx successes or failures while using this mode
  1663. * 2) # times calling this function
  1664. * 3) elapsed time in this mode (not used, for now)
  1665. */
  1666. static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search)
  1667. {
  1668. struct iwl_scale_tbl_info *tbl;
  1669. int i;
  1670. int active_tbl;
  1671. int flush_interval_passed = 0;
  1672. struct iwl_mvm *mvm;
  1673. mvm = lq_sta->drv;
  1674. active_tbl = lq_sta->active_tbl;
  1675. tbl = &(lq_sta->lq_info[active_tbl]);
  1676. /* If we've been disallowing search, see if we should now allow it */
  1677. if (lq_sta->stay_in_tbl) {
  1678. /* Elapsed time using current modulation mode */
  1679. if (lq_sta->flush_timer)
  1680. flush_interval_passed =
  1681. time_after(jiffies,
  1682. (unsigned long)(lq_sta->flush_timer +
  1683. IWL_RATE_SCALE_FLUSH_INTVL));
  1684. /*
  1685. * Check if we should allow search for new modulation mode.
  1686. * If many frames have failed or succeeded, or we've used
  1687. * this same modulation for a long time, allow search, and
  1688. * reset history stats that keep track of whether we should
  1689. * allow a new search. Also (below) reset all bitmaps and
  1690. * stats in active history.
  1691. */
  1692. if (force_search ||
  1693. (lq_sta->total_failed > lq_sta->max_failure_limit) ||
  1694. (lq_sta->total_success > lq_sta->max_success_limit) ||
  1695. ((!lq_sta->search_better_tbl) &&
  1696. (lq_sta->flush_timer) && (flush_interval_passed))) {
  1697. IWL_DEBUG_RATE(mvm,
  1698. "LQ: stay is expired %d %d %d\n",
  1699. lq_sta->total_failed,
  1700. lq_sta->total_success,
  1701. flush_interval_passed);
  1702. /* Allow search for new mode */
  1703. lq_sta->stay_in_tbl = 0; /* only place reset */
  1704. lq_sta->total_failed = 0;
  1705. lq_sta->total_success = 0;
  1706. lq_sta->flush_timer = 0;
  1707. /*
  1708. * Else if we've used this modulation mode enough repetitions
  1709. * (regardless of elapsed time or success/failure), reset
  1710. * history bitmaps and rate-specific stats for all rates in
  1711. * active table.
  1712. */
  1713. } else {
  1714. lq_sta->table_count++;
  1715. if (lq_sta->table_count >=
  1716. lq_sta->table_count_limit) {
  1717. lq_sta->table_count = 0;
  1718. IWL_DEBUG_RATE(mvm,
  1719. "LQ: stay in table clear win\n");
  1720. for (i = 0; i < IWL_RATE_COUNT; i++)
  1721. rs_rate_scale_clear_window(
  1722. &(tbl->win[i]));
  1723. }
  1724. }
  1725. /* If transitioning to allow "search", reset all history
  1726. * bitmaps and stats in active table (this will become the new
  1727. * "search" table). */
  1728. if (!lq_sta->stay_in_tbl) {
  1729. for (i = 0; i < IWL_RATE_COUNT; i++)
  1730. rs_rate_scale_clear_window(&(tbl->win[i]));
  1731. }
  1732. }
  1733. }
  1734. /*
  1735. * setup rate table in uCode
  1736. */
  1737. static void rs_update_rate_tbl(struct iwl_mvm *mvm,
  1738. struct iwl_lq_sta *lq_sta,
  1739. struct iwl_scale_tbl_info *tbl,
  1740. int index, u8 is_green)
  1741. {
  1742. u32 rate;
  1743. /* Update uCode's rate table. */
  1744. rate = rate_n_flags_from_tbl(mvm, tbl, index, is_green);
  1745. rs_fill_link_cmd(mvm, lq_sta, rate);
  1746. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_ASYNC, false);
  1747. }
  1748. /*
  1749. * Do rate scaling and search for new modulation mode.
  1750. */
  1751. static void rs_rate_scale_perform(struct iwl_mvm *mvm,
  1752. struct sk_buff *skb,
  1753. struct ieee80211_sta *sta,
  1754. struct iwl_lq_sta *lq_sta)
  1755. {
  1756. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1757. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1758. int low = IWL_RATE_INVALID;
  1759. int high = IWL_RATE_INVALID;
  1760. int index;
  1761. int i;
  1762. struct iwl_rate_scale_data *window = NULL;
  1763. int current_tpt = IWL_INVALID_VALUE;
  1764. int low_tpt = IWL_INVALID_VALUE;
  1765. int high_tpt = IWL_INVALID_VALUE;
  1766. u32 fail_count;
  1767. s8 scale_action = 0;
  1768. u16 rate_mask;
  1769. u8 update_lq = 0;
  1770. struct iwl_scale_tbl_info *tbl, *tbl1;
  1771. u16 rate_scale_index_msk = 0;
  1772. u8 is_green = 0;
  1773. u8 active_tbl = 0;
  1774. u8 done_search = 0;
  1775. u16 high_low;
  1776. s32 sr;
  1777. u8 tid = IWL_MAX_TID_COUNT;
  1778. struct iwl_mvm_sta *sta_priv = (void *)sta->drv_priv;
  1779. struct iwl_mvm_tid_data *tid_data;
  1780. IWL_DEBUG_RATE(mvm, "rate scale calculate new rate for skb\n");
  1781. /* Send management frames and NO_ACK data using lowest rate. */
  1782. /* TODO: this could probably be improved.. */
  1783. if (!ieee80211_is_data(hdr->frame_control) ||
  1784. info->flags & IEEE80211_TX_CTL_NO_ACK)
  1785. return;
  1786. lq_sta->supp_rates = sta->supp_rates[lq_sta->band];
  1787. tid = rs_tl_add_packet(lq_sta, hdr);
  1788. if ((tid != IWL_MAX_TID_COUNT) &&
  1789. (lq_sta->tx_agg_tid_en & (1 << tid))) {
  1790. tid_data = &sta_priv->tid_data[tid];
  1791. if (tid_data->state == IWL_AGG_OFF)
  1792. lq_sta->is_agg = 0;
  1793. else
  1794. lq_sta->is_agg = 1;
  1795. } else {
  1796. lq_sta->is_agg = 0;
  1797. }
  1798. /*
  1799. * Select rate-scale / modulation-mode table to work with in
  1800. * the rest of this function: "search" if searching for better
  1801. * modulation mode, or "active" if doing rate scaling within a mode.
  1802. */
  1803. if (!lq_sta->search_better_tbl)
  1804. active_tbl = lq_sta->active_tbl;
  1805. else
  1806. active_tbl = 1 - lq_sta->active_tbl;
  1807. tbl = &(lq_sta->lq_info[active_tbl]);
  1808. if (is_legacy(tbl->lq_type))
  1809. lq_sta->is_green = 0;
  1810. else
  1811. lq_sta->is_green = rs_use_green(sta);
  1812. is_green = lq_sta->is_green;
  1813. /* current tx rate */
  1814. index = lq_sta->last_txrate_idx;
  1815. IWL_DEBUG_RATE(mvm, "Rate scale index %d for type %d\n", index,
  1816. tbl->lq_type);
  1817. /* rates available for this association, and for modulation mode */
  1818. rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
  1819. IWL_DEBUG_RATE(mvm, "mask 0x%04X\n", rate_mask);
  1820. /* mask with station rate restriction */
  1821. if (is_legacy(tbl->lq_type)) {
  1822. if (lq_sta->band == IEEE80211_BAND_5GHZ)
  1823. /* supp_rates has no CCK bits in A mode */
  1824. rate_scale_index_msk = (u16) (rate_mask &
  1825. (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
  1826. else
  1827. rate_scale_index_msk = (u16) (rate_mask &
  1828. lq_sta->supp_rates);
  1829. } else {
  1830. rate_scale_index_msk = rate_mask;
  1831. }
  1832. if (!rate_scale_index_msk)
  1833. rate_scale_index_msk = rate_mask;
  1834. if (!((1 << index) & rate_scale_index_msk)) {
  1835. IWL_ERR(mvm, "Current Rate is not valid\n");
  1836. if (lq_sta->search_better_tbl) {
  1837. /* revert to active table if search table is not valid*/
  1838. tbl->lq_type = LQ_NONE;
  1839. lq_sta->search_better_tbl = 0;
  1840. tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1841. /* get "active" rate info */
  1842. index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
  1843. rs_update_rate_tbl(mvm, lq_sta, tbl, index, is_green);
  1844. }
  1845. return;
  1846. }
  1847. /* Get expected throughput table and history window for current rate */
  1848. if (!tbl->expected_tpt) {
  1849. IWL_ERR(mvm, "tbl->expected_tpt is NULL\n");
  1850. return;
  1851. }
  1852. /* force user max rate if set by user */
  1853. if ((lq_sta->max_rate_idx != -1) &&
  1854. (lq_sta->max_rate_idx < index)) {
  1855. index = lq_sta->max_rate_idx;
  1856. update_lq = 1;
  1857. window = &(tbl->win[index]);
  1858. goto lq_update;
  1859. }
  1860. window = &(tbl->win[index]);
  1861. /*
  1862. * If there is not enough history to calculate actual average
  1863. * throughput, keep analyzing results of more tx frames, without
  1864. * changing rate or mode (bypass most of the rest of this function).
  1865. * Set up new rate table in uCode only if old rate is not supported
  1866. * in current association (use new rate found above).
  1867. */
  1868. fail_count = window->counter - window->success_counter;
  1869. if ((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
  1870. (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) {
  1871. IWL_DEBUG_RATE(mvm,
  1872. "LQ: still below TH. succ=%d total=%d for index %d\n",
  1873. window->success_counter, window->counter, index);
  1874. /* Can't calculate this yet; not enough history */
  1875. window->average_tpt = IWL_INVALID_VALUE;
  1876. /* Should we stay with this modulation mode,
  1877. * or search for a new one? */
  1878. rs_stay_in_table(lq_sta, false);
  1879. goto out;
  1880. }
  1881. /* Else we have enough samples; calculate estimate of
  1882. * actual average throughput */
  1883. if (window->average_tpt != ((window->success_ratio *
  1884. tbl->expected_tpt[index] + 64) / 128)) {
  1885. IWL_ERR(mvm,
  1886. "expected_tpt should have been calculated by now\n");
  1887. window->average_tpt = ((window->success_ratio *
  1888. tbl->expected_tpt[index] + 64) / 128);
  1889. }
  1890. /* If we are searching for better modulation mode, check success. */
  1891. if (lq_sta->search_better_tbl) {
  1892. /* If good success, continue using the "search" mode;
  1893. * no need to send new link quality command, since we're
  1894. * continuing to use the setup that we've been trying. */
  1895. if (window->average_tpt > lq_sta->last_tpt) {
  1896. IWL_DEBUG_RATE(mvm,
  1897. "LQ: SWITCHING TO NEW TABLE suc=%d cur-tpt=%d old-tpt=%d\n",
  1898. window->success_ratio,
  1899. window->average_tpt,
  1900. lq_sta->last_tpt);
  1901. if (!is_legacy(tbl->lq_type))
  1902. lq_sta->enable_counter = 1;
  1903. /* Swap tables; "search" becomes "active" */
  1904. lq_sta->active_tbl = active_tbl;
  1905. current_tpt = window->average_tpt;
  1906. /* Else poor success; go back to mode in "active" table */
  1907. } else {
  1908. IWL_DEBUG_RATE(mvm,
  1909. "LQ: GOING BACK TO THE OLD TABLE suc=%d cur-tpt=%d old-tpt=%d\n",
  1910. window->success_ratio,
  1911. window->average_tpt,
  1912. lq_sta->last_tpt);
  1913. /* Nullify "search" table */
  1914. tbl->lq_type = LQ_NONE;
  1915. /* Revert to "active" table */
  1916. active_tbl = lq_sta->active_tbl;
  1917. tbl = &(lq_sta->lq_info[active_tbl]);
  1918. /* Revert to "active" rate and throughput info */
  1919. index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
  1920. current_tpt = lq_sta->last_tpt;
  1921. /* Need to set up a new rate table in uCode */
  1922. update_lq = 1;
  1923. }
  1924. /* Either way, we've made a decision; modulation mode
  1925. * search is done, allow rate adjustment next time. */
  1926. lq_sta->search_better_tbl = 0;
  1927. done_search = 1; /* Don't switch modes below! */
  1928. goto lq_update;
  1929. }
  1930. /* (Else) not in search of better modulation mode, try for better
  1931. * starting rate, while staying in this mode. */
  1932. high_low = rs_get_adjacent_rate(mvm, index, rate_scale_index_msk,
  1933. tbl->lq_type);
  1934. low = high_low & 0xff;
  1935. high = (high_low >> 8) & 0xff;
  1936. /* If user set max rate, dont allow higher than user constrain */
  1937. if ((lq_sta->max_rate_idx != -1) &&
  1938. (lq_sta->max_rate_idx < high))
  1939. high = IWL_RATE_INVALID;
  1940. sr = window->success_ratio;
  1941. /* Collect measured throughputs for current and adjacent rates */
  1942. current_tpt = window->average_tpt;
  1943. if (low != IWL_RATE_INVALID)
  1944. low_tpt = tbl->win[low].average_tpt;
  1945. if (high != IWL_RATE_INVALID)
  1946. high_tpt = tbl->win[high].average_tpt;
  1947. scale_action = 0;
  1948. /* Too many failures, decrease rate */
  1949. if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) {
  1950. IWL_DEBUG_RATE(mvm,
  1951. "decrease rate because of low success_ratio\n");
  1952. scale_action = -1;
  1953. /* No throughput measured yet for adjacent rates; try increase. */
  1954. } else if ((low_tpt == IWL_INVALID_VALUE) &&
  1955. (high_tpt == IWL_INVALID_VALUE)) {
  1956. if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH)
  1957. scale_action = 1;
  1958. else if (low != IWL_RATE_INVALID)
  1959. scale_action = 0;
  1960. }
  1961. /* Both adjacent throughputs are measured, but neither one has better
  1962. * throughput; we're using the best rate, don't change it! */
  1963. else if ((low_tpt != IWL_INVALID_VALUE) &&
  1964. (high_tpt != IWL_INVALID_VALUE) &&
  1965. (low_tpt < current_tpt) &&
  1966. (high_tpt < current_tpt))
  1967. scale_action = 0;
  1968. /* At least one adjacent rate's throughput is measured,
  1969. * and may have better performance. */
  1970. else {
  1971. /* Higher adjacent rate's throughput is measured */
  1972. if (high_tpt != IWL_INVALID_VALUE) {
  1973. /* Higher rate has better throughput */
  1974. if (high_tpt > current_tpt &&
  1975. sr >= IWL_RATE_INCREASE_TH) {
  1976. scale_action = 1;
  1977. } else {
  1978. scale_action = 0;
  1979. }
  1980. /* Lower adjacent rate's throughput is measured */
  1981. } else if (low_tpt != IWL_INVALID_VALUE) {
  1982. /* Lower rate has better throughput */
  1983. if (low_tpt > current_tpt) {
  1984. IWL_DEBUG_RATE(mvm,
  1985. "decrease rate because of low tpt\n");
  1986. scale_action = -1;
  1987. } else if (sr >= IWL_RATE_INCREASE_TH) {
  1988. scale_action = 1;
  1989. }
  1990. }
  1991. }
  1992. /* Sanity check; asked for decrease, but success rate or throughput
  1993. * has been good at old rate. Don't change it. */
  1994. if ((scale_action == -1) && (low != IWL_RATE_INVALID) &&
  1995. ((sr > IWL_RATE_HIGH_TH) ||
  1996. (current_tpt > (100 * tbl->expected_tpt[low]))))
  1997. scale_action = 0;
  1998. switch (scale_action) {
  1999. case -1:
  2000. /* Decrease starting rate, update uCode's rate table */
  2001. if (low != IWL_RATE_INVALID) {
  2002. update_lq = 1;
  2003. index = low;
  2004. }
  2005. break;
  2006. case 1:
  2007. /* Increase starting rate, update uCode's rate table */
  2008. if (high != IWL_RATE_INVALID) {
  2009. update_lq = 1;
  2010. index = high;
  2011. }
  2012. break;
  2013. case 0:
  2014. /* No change */
  2015. default:
  2016. break;
  2017. }
  2018. IWL_DEBUG_RATE(mvm,
  2019. "choose rate scale index %d action %d low %d high %d type %d\n",
  2020. index, scale_action, low, high, tbl->lq_type);
  2021. lq_update:
  2022. /* Replace uCode's rate table for the destination station. */
  2023. if (update_lq)
  2024. rs_update_rate_tbl(mvm, lq_sta, tbl, index, is_green);
  2025. rs_stay_in_table(lq_sta, false);
  2026. /*
  2027. * Search for new modulation mode if we're:
  2028. * 1) Not changing rates right now
  2029. * 2) Not just finishing up a search
  2030. * 3) Allowing a new search
  2031. */
  2032. if (!update_lq && !done_search &&
  2033. !lq_sta->stay_in_tbl && window->counter) {
  2034. /* Save current throughput to compare with "search" throughput*/
  2035. lq_sta->last_tpt = current_tpt;
  2036. /* Select a new "search" modulation mode to try.
  2037. * If one is found, set up the new "search" table. */
  2038. if (is_legacy(tbl->lq_type))
  2039. rs_move_legacy_other(mvm, lq_sta, sta, index);
  2040. else if (is_siso(tbl->lq_type))
  2041. rs_move_siso_to_other(mvm, lq_sta, sta, index);
  2042. else if (is_mimo2(tbl->lq_type))
  2043. rs_move_mimo2_to_other(mvm, lq_sta, sta, index);
  2044. else
  2045. rs_move_mimo3_to_other(mvm, lq_sta, sta, index);
  2046. /* If new "search" mode was selected, set up in uCode table */
  2047. if (lq_sta->search_better_tbl) {
  2048. /* Access the "search" table, clear its history. */
  2049. tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  2050. for (i = 0; i < IWL_RATE_COUNT; i++)
  2051. rs_rate_scale_clear_window(&(tbl->win[i]));
  2052. /* Use new "search" start rate */
  2053. index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
  2054. IWL_DEBUG_RATE(mvm,
  2055. "Switch current mcs: %X index: %d\n",
  2056. tbl->current_rate, index);
  2057. rs_fill_link_cmd(mvm, lq_sta, tbl->current_rate);
  2058. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_ASYNC, false);
  2059. } else {
  2060. done_search = 1;
  2061. }
  2062. }
  2063. if (done_search && !lq_sta->stay_in_tbl) {
  2064. /* If the "active" (non-search) mode was legacy,
  2065. * and we've tried switching antennas,
  2066. * but we haven't been able to try HT modes (not available),
  2067. * stay with best antenna legacy modulation for a while
  2068. * before next round of mode comparisons. */
  2069. tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
  2070. if (is_legacy(tbl1->lq_type) && !sta->ht_cap.ht_supported &&
  2071. lq_sta->action_counter > tbl1->max_search) {
  2072. IWL_DEBUG_RATE(mvm, "LQ: STAY in legacy table\n");
  2073. rs_set_stay_in_table(mvm, 1, lq_sta);
  2074. }
  2075. /* If we're in an HT mode, and all 3 mode switch actions
  2076. * have been tried and compared, stay in this best modulation
  2077. * mode for a while before next round of mode comparisons. */
  2078. if (lq_sta->enable_counter &&
  2079. (lq_sta->action_counter >= tbl1->max_search)) {
  2080. if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
  2081. (lq_sta->tx_agg_tid_en & (1 << tid)) &&
  2082. (tid != IWL_MAX_TID_COUNT)) {
  2083. tid_data = &sta_priv->tid_data[tid];
  2084. if (tid_data->state == IWL_AGG_OFF) {
  2085. IWL_DEBUG_RATE(mvm,
  2086. "try to aggregate tid %d\n",
  2087. tid);
  2088. rs_tl_turn_on_agg(mvm, tid,
  2089. lq_sta, sta);
  2090. }
  2091. }
  2092. rs_set_stay_in_table(mvm, 0, lq_sta);
  2093. }
  2094. }
  2095. out:
  2096. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, index, is_green);
  2097. lq_sta->last_txrate_idx = index;
  2098. }
  2099. /**
  2100. * rs_initialize_lq - Initialize a station's hardware rate table
  2101. *
  2102. * The uCode's station table contains a table of fallback rates
  2103. * for automatic fallback during transmission.
  2104. *
  2105. * NOTE: This sets up a default set of values. These will be replaced later
  2106. * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
  2107. * rc80211_simple.
  2108. *
  2109. * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
  2110. * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  2111. * which requires station table entry to exist).
  2112. */
  2113. static void rs_initialize_lq(struct iwl_mvm *mvm,
  2114. struct ieee80211_sta *sta,
  2115. struct iwl_lq_sta *lq_sta,
  2116. enum ieee80211_band band)
  2117. {
  2118. struct iwl_scale_tbl_info *tbl;
  2119. int rate_idx;
  2120. int i;
  2121. u32 rate;
  2122. u8 use_green = rs_use_green(sta);
  2123. u8 active_tbl = 0;
  2124. u8 valid_tx_ant;
  2125. if (!sta || !lq_sta)
  2126. return;
  2127. i = lq_sta->last_txrate_idx;
  2128. valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  2129. if (!lq_sta->search_better_tbl)
  2130. active_tbl = lq_sta->active_tbl;
  2131. else
  2132. active_tbl = 1 - lq_sta->active_tbl;
  2133. tbl = &(lq_sta->lq_info[active_tbl]);
  2134. if ((i < 0) || (i >= IWL_RATE_COUNT))
  2135. i = 0;
  2136. rate = iwl_rates[i].plcp;
  2137. tbl->ant_type = first_antenna(valid_tx_ant);
  2138. rate |= tbl->ant_type << RATE_MCS_ANT_POS;
  2139. if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
  2140. rate |= RATE_MCS_CCK_MSK;
  2141. rs_get_tbl_info_from_mcs(rate, band, tbl, &rate_idx);
  2142. if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
  2143. rs_toggle_antenna(valid_tx_ant, &rate, tbl);
  2144. rate = rate_n_flags_from_tbl(mvm, tbl, rate_idx, use_green);
  2145. tbl->current_rate = rate;
  2146. rs_set_expected_tpt_table(lq_sta, tbl);
  2147. rs_fill_link_cmd(NULL, lq_sta, rate);
  2148. /* TODO restore station should remember the lq cmd */
  2149. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_SYNC, true);
  2150. }
  2151. static void rs_get_rate(void *mvm_r, struct ieee80211_sta *sta, void *mvm_sta,
  2152. struct ieee80211_tx_rate_control *txrc)
  2153. {
  2154. struct sk_buff *skb = txrc->skb;
  2155. struct ieee80211_supported_band *sband = txrc->sband;
  2156. struct iwl_op_mode *op_mode __maybe_unused =
  2157. (struct iwl_op_mode *)mvm_r;
  2158. struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode);
  2159. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2160. struct iwl_lq_sta *lq_sta = mvm_sta;
  2161. int rate_idx;
  2162. IWL_DEBUG_RATE_LIMIT(mvm, "rate scale calculate new rate for skb\n");
  2163. /* Get max rate if user set max rate */
  2164. if (lq_sta) {
  2165. lq_sta->max_rate_idx = txrc->max_rate_idx;
  2166. if ((sband->band == IEEE80211_BAND_5GHZ) &&
  2167. (lq_sta->max_rate_idx != -1))
  2168. lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE;
  2169. if ((lq_sta->max_rate_idx < 0) ||
  2170. (lq_sta->max_rate_idx >= IWL_RATE_COUNT))
  2171. lq_sta->max_rate_idx = -1;
  2172. }
  2173. /* Treat uninitialized rate scaling data same as non-existing. */
  2174. if (lq_sta && !lq_sta->drv) {
  2175. IWL_DEBUG_RATE(mvm, "Rate scaling not initialized yet.\n");
  2176. mvm_sta = NULL;
  2177. }
  2178. /* Send management frames and NO_ACK data using lowest rate. */
  2179. if (rate_control_send_low(sta, mvm_sta, txrc))
  2180. return;
  2181. rate_idx = lq_sta->last_txrate_idx;
  2182. if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
  2183. rate_idx -= IWL_FIRST_OFDM_RATE;
  2184. /* 6M and 9M shared same MCS index */
  2185. rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0;
  2186. if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
  2187. IWL_RATE_MIMO3_6M_PLCP)
  2188. rate_idx = rate_idx + (2 * MCS_INDEX_PER_STREAM);
  2189. else if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
  2190. IWL_RATE_MIMO2_6M_PLCP)
  2191. rate_idx = rate_idx + MCS_INDEX_PER_STREAM;
  2192. info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
  2193. if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK)
  2194. info->control.rates[0].flags |= IEEE80211_TX_RC_SHORT_GI;
  2195. if (lq_sta->last_rate_n_flags & RATE_MCS_CHAN_WIDTH_40) /* TODO */
  2196. info->control.rates[0].flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  2197. if (lq_sta->last_rate_n_flags & RATE_HT_MCS_GF_MSK)
  2198. info->control.rates[0].flags |= IEEE80211_TX_RC_GREEN_FIELD;
  2199. } else {
  2200. /* Check for invalid rates */
  2201. if ((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT_LEGACY) ||
  2202. ((sband->band == IEEE80211_BAND_5GHZ) &&
  2203. (rate_idx < IWL_FIRST_OFDM_RATE)))
  2204. rate_idx = rate_lowest_index(sband, sta);
  2205. /* On valid 5 GHz rate, adjust index */
  2206. else if (sband->band == IEEE80211_BAND_5GHZ)
  2207. rate_idx -= IWL_FIRST_OFDM_RATE;
  2208. info->control.rates[0].flags = 0;
  2209. }
  2210. info->control.rates[0].idx = rate_idx;
  2211. }
  2212. static void *rs_alloc_sta(void *mvm_rate, struct ieee80211_sta *sta,
  2213. gfp_t gfp)
  2214. {
  2215. struct iwl_mvm_sta *sta_priv = (struct iwl_mvm_sta *)sta->drv_priv;
  2216. struct iwl_op_mode *op_mode __maybe_unused =
  2217. (struct iwl_op_mode *)mvm_rate;
  2218. struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode);
  2219. IWL_DEBUG_RATE(mvm, "create station rate scale window\n");
  2220. return &sta_priv->lq_sta;
  2221. }
  2222. /*
  2223. * Called after adding a new station to initialize rate scaling
  2224. */
  2225. void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
  2226. enum ieee80211_band band)
  2227. {
  2228. int i, j;
  2229. struct ieee80211_hw *hw = mvm->hw;
  2230. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  2231. struct iwl_mvm_sta *sta_priv;
  2232. struct iwl_lq_sta *lq_sta;
  2233. struct ieee80211_supported_band *sband;
  2234. unsigned long supp; /* must be unsigned long for for_each_set_bit */
  2235. sta_priv = (struct iwl_mvm_sta *)sta->drv_priv;
  2236. lq_sta = &sta_priv->lq_sta;
  2237. sband = hw->wiphy->bands[band];
  2238. lq_sta->lq.sta_id = sta_priv->sta_id;
  2239. for (j = 0; j < LQ_SIZE; j++)
  2240. for (i = 0; i < IWL_RATE_COUNT; i++)
  2241. rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
  2242. lq_sta->flush_timer = 0;
  2243. lq_sta->supp_rates = sta->supp_rates[sband->band];
  2244. for (j = 0; j < LQ_SIZE; j++)
  2245. for (i = 0; i < IWL_RATE_COUNT; i++)
  2246. rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
  2247. IWL_DEBUG_RATE(mvm,
  2248. "LQ: *** rate scale station global init for station %d ***\n",
  2249. sta_priv->sta_id);
  2250. /* TODO: what is a good starting rate for STA? About middle? Maybe not
  2251. * the lowest or the highest rate.. Could consider using RSSI from
  2252. * previous packets? Need to have IEEE 802.1X auth succeed immediately
  2253. * after assoc.. */
  2254. lq_sta->max_rate_idx = -1;
  2255. lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX;
  2256. lq_sta->is_green = rs_use_green(sta);
  2257. lq_sta->band = sband->band;
  2258. /*
  2259. * active legacy rates as per supported rates bitmap
  2260. */
  2261. supp = sta->supp_rates[sband->band];
  2262. lq_sta->active_legacy_rate = 0;
  2263. for_each_set_bit(i, &supp, BITS_PER_LONG)
  2264. lq_sta->active_legacy_rate |= BIT(sband->bitrates[i].hw_value);
  2265. /*
  2266. * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
  2267. * supp_rates[] does not; shift to convert format, force 9 MBits off.
  2268. */
  2269. lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1;
  2270. lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1;
  2271. lq_sta->active_siso_rate &= ~((u16)0x2);
  2272. lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE;
  2273. /* Same here */
  2274. lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1;
  2275. lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1;
  2276. lq_sta->active_mimo2_rate &= ~((u16)0x2);
  2277. lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE;
  2278. lq_sta->active_mimo3_rate = ht_cap->mcs.rx_mask[2] << 1;
  2279. lq_sta->active_mimo3_rate |= ht_cap->mcs.rx_mask[2] & 0x1;
  2280. lq_sta->active_mimo3_rate &= ~((u16)0x2);
  2281. lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE;
  2282. IWL_DEBUG_RATE(mvm,
  2283. "SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n",
  2284. lq_sta->active_siso_rate,
  2285. lq_sta->active_mimo2_rate,
  2286. lq_sta->active_mimo3_rate);
  2287. /* These values will be overridden later */
  2288. lq_sta->lq.single_stream_ant_msk =
  2289. first_antenna(mvm->nvm_data->valid_tx_ant);
  2290. lq_sta->lq.dual_stream_ant_msk =
  2291. mvm->nvm_data->valid_tx_ant &
  2292. ~first_antenna(mvm->nvm_data->valid_tx_ant);
  2293. if (!lq_sta->lq.dual_stream_ant_msk) {
  2294. lq_sta->lq.dual_stream_ant_msk = ANT_AB;
  2295. } else if (num_of_ant(mvm->nvm_data->valid_tx_ant) == 2) {
  2296. lq_sta->lq.dual_stream_ant_msk =
  2297. mvm->nvm_data->valid_tx_ant;
  2298. }
  2299. /* as default allow aggregation for all tids */
  2300. lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
  2301. lq_sta->drv = mvm;
  2302. /* Set last_txrate_idx to lowest rate */
  2303. lq_sta->last_txrate_idx = rate_lowest_index(sband, sta);
  2304. if (sband->band == IEEE80211_BAND_5GHZ)
  2305. lq_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
  2306. lq_sta->is_agg = 0;
  2307. #ifdef CONFIG_MAC80211_DEBUGFS
  2308. lq_sta->dbg_fixed_rate = 0;
  2309. #endif
  2310. rs_initialize_lq(mvm, sta, lq_sta, band);
  2311. }
  2312. static void rs_fill_link_cmd(struct iwl_mvm *mvm,
  2313. struct iwl_lq_sta *lq_sta, u32 new_rate)
  2314. {
  2315. struct iwl_scale_tbl_info tbl_type;
  2316. int index = 0;
  2317. int rate_idx;
  2318. int repeat_rate = 0;
  2319. u8 ant_toggle_cnt = 0;
  2320. u8 use_ht_possible = 1;
  2321. u8 valid_tx_ant = 0;
  2322. struct iwl_lq_cmd *lq_cmd = &lq_sta->lq;
  2323. /* Override starting rate (index 0) if needed for debug purposes */
  2324. rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
  2325. /* Interpret new_rate (rate_n_flags) */
  2326. rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
  2327. &tbl_type, &rate_idx);
  2328. /* How many times should we repeat the initial rate? */
  2329. if (is_legacy(tbl_type.lq_type)) {
  2330. ant_toggle_cnt = 1;
  2331. repeat_rate = IWL_NUMBER_TRY;
  2332. } else {
  2333. repeat_rate = min(IWL_HT_NUMBER_TRY,
  2334. LINK_QUAL_AGG_DISABLE_START_DEF - 1);
  2335. }
  2336. lq_cmd->mimo_delim = is_mimo(tbl_type.lq_type) ? 1 : 0;
  2337. /* Fill 1st table entry (index 0) */
  2338. lq_cmd->rs_table[index] = cpu_to_le32(new_rate);
  2339. if (num_of_ant(tbl_type.ant_type) == 1)
  2340. lq_cmd->single_stream_ant_msk = tbl_type.ant_type;
  2341. else if (num_of_ant(tbl_type.ant_type) == 2)
  2342. lq_cmd->dual_stream_ant_msk = tbl_type.ant_type;
  2343. /* otherwise we don't modify the existing value */
  2344. index++;
  2345. repeat_rate--;
  2346. if (mvm)
  2347. valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  2348. /* Fill rest of rate table */
  2349. while (index < LINK_QUAL_MAX_RETRY_NUM) {
  2350. /* Repeat initial/next rate.
  2351. * For legacy IWL_NUMBER_TRY == 1, this loop will not execute.
  2352. * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
  2353. while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
  2354. if (is_legacy(tbl_type.lq_type)) {
  2355. if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
  2356. ant_toggle_cnt++;
  2357. else if (mvm &&
  2358. rs_toggle_antenna(valid_tx_ant,
  2359. &new_rate, &tbl_type))
  2360. ant_toggle_cnt = 1;
  2361. }
  2362. /* Override next rate if needed for debug purposes */
  2363. rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
  2364. /* Fill next table entry */
  2365. lq_cmd->rs_table[index] =
  2366. cpu_to_le32(new_rate);
  2367. repeat_rate--;
  2368. index++;
  2369. }
  2370. rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type,
  2371. &rate_idx);
  2372. /* Indicate to uCode which entries might be MIMO.
  2373. * If initial rate was MIMO, this will finally end up
  2374. * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
  2375. if (is_mimo(tbl_type.lq_type))
  2376. lq_cmd->mimo_delim = index;
  2377. /* Get next rate */
  2378. new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
  2379. use_ht_possible);
  2380. /* How many times should we repeat the next rate? */
  2381. if (is_legacy(tbl_type.lq_type)) {
  2382. if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
  2383. ant_toggle_cnt++;
  2384. else if (mvm &&
  2385. rs_toggle_antenna(valid_tx_ant,
  2386. &new_rate, &tbl_type))
  2387. ant_toggle_cnt = 1;
  2388. repeat_rate = IWL_NUMBER_TRY;
  2389. } else {
  2390. repeat_rate = IWL_HT_NUMBER_TRY;
  2391. }
  2392. /* Don't allow HT rates after next pass.
  2393. * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
  2394. use_ht_possible = 0;
  2395. /* Override next rate if needed for debug purposes */
  2396. rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
  2397. /* Fill next table entry */
  2398. lq_cmd->rs_table[index] = cpu_to_le32(new_rate);
  2399. index++;
  2400. repeat_rate--;
  2401. }
  2402. lq_cmd->agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  2403. lq_cmd->agg_disable_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  2404. lq_cmd->agg_time_limit =
  2405. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  2406. }
  2407. static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
  2408. {
  2409. return hw->priv;
  2410. }
  2411. /* rate scale requires free function to be implemented */
  2412. static void rs_free(void *mvm_rate)
  2413. {
  2414. return;
  2415. }
  2416. static void rs_free_sta(void *mvm_r, struct ieee80211_sta *sta,
  2417. void *mvm_sta)
  2418. {
  2419. struct iwl_op_mode *op_mode __maybe_unused = mvm_r;
  2420. struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode);
  2421. IWL_DEBUG_RATE(mvm, "enter\n");
  2422. IWL_DEBUG_RATE(mvm, "leave\n");
  2423. }
  2424. #ifdef CONFIG_MAC80211_DEBUGFS
  2425. static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
  2426. u32 *rate_n_flags, int index)
  2427. {
  2428. struct iwl_mvm *mvm;
  2429. u8 valid_tx_ant;
  2430. u8 ant_sel_tx;
  2431. mvm = lq_sta->drv;
  2432. valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  2433. if (lq_sta->dbg_fixed_rate) {
  2434. ant_sel_tx =
  2435. ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK)
  2436. >> RATE_MCS_ANT_POS);
  2437. if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) {
  2438. *rate_n_flags = lq_sta->dbg_fixed_rate;
  2439. IWL_DEBUG_RATE(mvm, "Fixed rate ON\n");
  2440. } else {
  2441. lq_sta->dbg_fixed_rate = 0;
  2442. IWL_ERR(mvm,
  2443. "Invalid antenna selection 0x%X, Valid is 0x%X\n",
  2444. ant_sel_tx, valid_tx_ant);
  2445. IWL_DEBUG_RATE(mvm, "Fixed rate OFF\n");
  2446. }
  2447. } else {
  2448. IWL_DEBUG_RATE(mvm, "Fixed rate OFF\n");
  2449. }
  2450. }
  2451. static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
  2452. const char __user *user_buf, size_t count, loff_t *ppos)
  2453. {
  2454. struct iwl_lq_sta *lq_sta = file->private_data;
  2455. struct iwl_mvm *mvm;
  2456. char buf[64];
  2457. size_t buf_size;
  2458. u32 parsed_rate;
  2459. mvm = lq_sta->drv;
  2460. memset(buf, 0, sizeof(buf));
  2461. buf_size = min(count, sizeof(buf) - 1);
  2462. if (copy_from_user(buf, user_buf, buf_size))
  2463. return -EFAULT;
  2464. if (sscanf(buf, "%x", &parsed_rate) == 1)
  2465. lq_sta->dbg_fixed_rate = parsed_rate;
  2466. else
  2467. lq_sta->dbg_fixed_rate = 0;
  2468. rs_program_fix_rate(mvm, lq_sta);
  2469. return count;
  2470. }
  2471. static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
  2472. char __user *user_buf, size_t count, loff_t *ppos)
  2473. {
  2474. char *buff;
  2475. int desc = 0;
  2476. int i = 0;
  2477. int index = 0;
  2478. ssize_t ret;
  2479. struct iwl_lq_sta *lq_sta = file->private_data;
  2480. struct iwl_mvm *mvm;
  2481. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  2482. mvm = lq_sta->drv;
  2483. buff = kmalloc(1024, GFP_KERNEL);
  2484. if (!buff)
  2485. return -ENOMEM;
  2486. desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
  2487. desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
  2488. lq_sta->total_failed, lq_sta->total_success,
  2489. lq_sta->active_legacy_rate);
  2490. desc += sprintf(buff+desc, "fixed rate 0x%X\n",
  2491. lq_sta->dbg_fixed_rate);
  2492. desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n",
  2493. (mvm->nvm_data->valid_tx_ant & ANT_A) ? "ANT_A," : "",
  2494. (mvm->nvm_data->valid_tx_ant & ANT_B) ? "ANT_B," : "",
  2495. (mvm->nvm_data->valid_tx_ant & ANT_C) ? "ANT_C" : "");
  2496. desc += sprintf(buff+desc, "lq type %s\n",
  2497. (is_legacy(tbl->lq_type)) ? "legacy" : "HT");
  2498. if (is_Ht(tbl->lq_type)) {
  2499. desc += sprintf(buff+desc, " %s",
  2500. (is_siso(tbl->lq_type)) ? "SISO" :
  2501. ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3"));
  2502. desc += sprintf(buff+desc, " %s",
  2503. (tbl->is_ht40) ? "40MHz" : "20MHz");
  2504. desc += sprintf(buff+desc, " %s %s %s\n",
  2505. (tbl->is_SGI) ? "SGI" : "",
  2506. (lq_sta->is_green) ? "GF enabled" : "",
  2507. (lq_sta->is_agg) ? "AGG on" : "");
  2508. }
  2509. desc += sprintf(buff+desc, "last tx rate=0x%X\n",
  2510. lq_sta->last_rate_n_flags);
  2511. desc += sprintf(buff+desc,
  2512. "general: flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
  2513. lq_sta->lq.flags,
  2514. lq_sta->lq.mimo_delim,
  2515. lq_sta->lq.single_stream_ant_msk,
  2516. lq_sta->lq.dual_stream_ant_msk);
  2517. desc += sprintf(buff+desc,
  2518. "agg: time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
  2519. le16_to_cpu(lq_sta->lq.agg_time_limit),
  2520. lq_sta->lq.agg_disable_start_th,
  2521. lq_sta->lq.agg_frame_cnt_limit);
  2522. desc += sprintf(buff+desc,
  2523. "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
  2524. lq_sta->lq.initial_rate_index[0],
  2525. lq_sta->lq.initial_rate_index[1],
  2526. lq_sta->lq.initial_rate_index[2],
  2527. lq_sta->lq.initial_rate_index[3]);
  2528. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  2529. index = iwl_hwrate_to_plcp_idx(
  2530. le32_to_cpu(lq_sta->lq.rs_table[i]));
  2531. if (is_legacy(tbl->lq_type)) {
  2532. desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
  2533. i, le32_to_cpu(lq_sta->lq.rs_table[i]),
  2534. iwl_rate_mcs[index].mbps);
  2535. } else {
  2536. desc += sprintf(buff+desc,
  2537. " rate[%d] 0x%X %smbps (%s)\n",
  2538. i, le32_to_cpu(lq_sta->lq.rs_table[i]),
  2539. iwl_rate_mcs[index].mbps,
  2540. iwl_rate_mcs[index].mcs);
  2541. }
  2542. }
  2543. ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  2544. kfree(buff);
  2545. return ret;
  2546. }
  2547. static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
  2548. .write = rs_sta_dbgfs_scale_table_write,
  2549. .read = rs_sta_dbgfs_scale_table_read,
  2550. .open = simple_open,
  2551. .llseek = default_llseek,
  2552. };
  2553. static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
  2554. char __user *user_buf, size_t count, loff_t *ppos)
  2555. {
  2556. char *buff;
  2557. int desc = 0;
  2558. int i, j;
  2559. ssize_t ret;
  2560. struct iwl_lq_sta *lq_sta = file->private_data;
  2561. buff = kmalloc(1024, GFP_KERNEL);
  2562. if (!buff)
  2563. return -ENOMEM;
  2564. for (i = 0; i < LQ_SIZE; i++) {
  2565. desc += sprintf(buff+desc,
  2566. "%s type=%d SGI=%d HT40=%d DUP=0 GF=%d\n"
  2567. "rate=0x%X\n",
  2568. lq_sta->active_tbl == i ? "*" : "x",
  2569. lq_sta->lq_info[i].lq_type,
  2570. lq_sta->lq_info[i].is_SGI,
  2571. lq_sta->lq_info[i].is_ht40,
  2572. lq_sta->is_green,
  2573. lq_sta->lq_info[i].current_rate);
  2574. for (j = 0; j < IWL_RATE_COUNT; j++) {
  2575. desc += sprintf(buff+desc,
  2576. "counter=%d success=%d %%=%d\n",
  2577. lq_sta->lq_info[i].win[j].counter,
  2578. lq_sta->lq_info[i].win[j].success_counter,
  2579. lq_sta->lq_info[i].win[j].success_ratio);
  2580. }
  2581. }
  2582. ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  2583. kfree(buff);
  2584. return ret;
  2585. }
  2586. static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
  2587. .read = rs_sta_dbgfs_stats_table_read,
  2588. .open = simple_open,
  2589. .llseek = default_llseek,
  2590. };
  2591. static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file,
  2592. char __user *user_buf, size_t count, loff_t *ppos)
  2593. {
  2594. struct iwl_lq_sta *lq_sta = file->private_data;
  2595. struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
  2596. char buff[120];
  2597. int desc = 0;
  2598. if (is_Ht(tbl->lq_type))
  2599. desc += sprintf(buff+desc,
  2600. "Bit Rate= %d Mb/s\n",
  2601. tbl->expected_tpt[lq_sta->last_txrate_idx]);
  2602. else
  2603. desc += sprintf(buff+desc,
  2604. "Bit Rate= %d Mb/s\n",
  2605. iwl_rates[lq_sta->last_txrate_idx].ieee >> 1);
  2606. return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  2607. }
  2608. static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
  2609. .read = rs_sta_dbgfs_rate_scale_data_read,
  2610. .open = simple_open,
  2611. .llseek = default_llseek,
  2612. };
  2613. static void rs_add_debugfs(void *mvm, void *mvm_sta, struct dentry *dir)
  2614. {
  2615. struct iwl_lq_sta *lq_sta = mvm_sta;
  2616. lq_sta->rs_sta_dbgfs_scale_table_file =
  2617. debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir,
  2618. lq_sta, &rs_sta_dbgfs_scale_table_ops);
  2619. lq_sta->rs_sta_dbgfs_stats_table_file =
  2620. debugfs_create_file("rate_stats_table", S_IRUSR, dir,
  2621. lq_sta, &rs_sta_dbgfs_stats_table_ops);
  2622. lq_sta->rs_sta_dbgfs_rate_scale_data_file =
  2623. debugfs_create_file("rate_scale_data", S_IRUSR, dir,
  2624. lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
  2625. lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
  2626. debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir,
  2627. &lq_sta->tx_agg_tid_en);
  2628. }
  2629. static void rs_remove_debugfs(void *mvm, void *mvm_sta)
  2630. {
  2631. struct iwl_lq_sta *lq_sta = mvm_sta;
  2632. debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
  2633. debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
  2634. debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
  2635. debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
  2636. }
  2637. #endif
  2638. /*
  2639. * Initialization of rate scaling information is done by driver after
  2640. * the station is added. Since mac80211 calls this function before a
  2641. * station is added we ignore it.
  2642. */
  2643. static void rs_rate_init_stub(void *mvm_r,
  2644. struct ieee80211_supported_band *sband,
  2645. struct ieee80211_sta *sta, void *mvm_sta)
  2646. {
  2647. }
  2648. static struct rate_control_ops rs_mvm_ops = {
  2649. .module = NULL,
  2650. .name = RS_NAME,
  2651. .tx_status = rs_tx_status,
  2652. .get_rate = rs_get_rate,
  2653. .rate_init = rs_rate_init_stub,
  2654. .alloc = rs_alloc,
  2655. .free = rs_free,
  2656. .alloc_sta = rs_alloc_sta,
  2657. .free_sta = rs_free_sta,
  2658. #ifdef CONFIG_MAC80211_DEBUGFS
  2659. .add_sta_debugfs = rs_add_debugfs,
  2660. .remove_sta_debugfs = rs_remove_debugfs,
  2661. #endif
  2662. };
  2663. int iwl_mvm_rate_control_register(void)
  2664. {
  2665. return ieee80211_rate_control_register(&rs_mvm_ops);
  2666. }
  2667. void iwl_mvm_rate_control_unregister(void)
  2668. {
  2669. ieee80211_rate_control_unregister(&rs_mvm_ops);
  2670. }