rs.c 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096
  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 iwl_mvm *mvm,
  1061. struct ieee80211_sta_ht_cap *ht_cap)
  1062. {
  1063. /*
  1064. * Remainder of this function checks ht_cap, but if it's
  1065. * NULL then we can do HT40 (special case for RXON)
  1066. */
  1067. if (!ht_cap)
  1068. return true;
  1069. if (!ht_cap->ht_supported)
  1070. return false;
  1071. if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  1072. return false;
  1073. return true;
  1074. }
  1075. /*
  1076. * Set up search table for MIMO2
  1077. */
  1078. static int rs_switch_to_mimo2(struct iwl_mvm *mvm,
  1079. struct iwl_lq_sta *lq_sta,
  1080. struct ieee80211_sta *sta,
  1081. struct iwl_scale_tbl_info *tbl, int index)
  1082. {
  1083. u16 rate_mask;
  1084. s32 rate;
  1085. s8 is_green = lq_sta->is_green;
  1086. if (!sta->ht_cap.ht_supported)
  1087. return -1;
  1088. if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
  1089. == WLAN_HT_CAP_SM_PS_STATIC)
  1090. return -1;
  1091. /* Need both Tx chains/antennas to support MIMO */
  1092. if (num_of_ant(mvm->nvm_data->valid_tx_ant) < 2)
  1093. return -1;
  1094. IWL_DEBUG_RATE(mvm, "LQ: try to switch to MIMO2\n");
  1095. tbl->lq_type = LQ_MIMO2;
  1096. tbl->action = 0;
  1097. tbl->max_search = IWL_MAX_SEARCH;
  1098. rate_mask = lq_sta->active_mimo2_rate;
  1099. if (iwl_is_ht40_tx_allowed(mvm, &sta->ht_cap))
  1100. tbl->is_ht40 = 1;
  1101. else
  1102. tbl->is_ht40 = 0;
  1103. rs_set_expected_tpt_table(lq_sta, tbl);
  1104. rate = rs_get_best_rate(mvm, lq_sta, tbl, rate_mask, index);
  1105. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 best rate %d mask %X\n",
  1106. rate, rate_mask);
  1107. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
  1108. IWL_DEBUG_RATE(mvm, "Can't switch with index %d rate mask %x\n",
  1109. rate, rate_mask);
  1110. return -1;
  1111. }
  1112. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, rate, is_green);
  1113. IWL_DEBUG_RATE(mvm, "LQ: Switch to new mcs %X index is green %X\n",
  1114. tbl->current_rate, is_green);
  1115. return 0;
  1116. }
  1117. /*
  1118. * Set up search table for MIMO3
  1119. */
  1120. static int rs_switch_to_mimo3(struct iwl_mvm *mvm,
  1121. struct iwl_lq_sta *lq_sta,
  1122. struct ieee80211_sta *sta,
  1123. struct iwl_scale_tbl_info *tbl, int index)
  1124. {
  1125. u16 rate_mask;
  1126. s32 rate;
  1127. s8 is_green = lq_sta->is_green;
  1128. if (!sta->ht_cap.ht_supported)
  1129. return -1;
  1130. if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
  1131. == WLAN_HT_CAP_SM_PS_STATIC)
  1132. return -1;
  1133. /* Need both Tx chains/antennas to support MIMO */
  1134. if (num_of_ant(mvm->nvm_data->valid_tx_ant) < 3)
  1135. return -1;
  1136. IWL_DEBUG_RATE(mvm, "LQ: try to switch to MIMO3\n");
  1137. tbl->lq_type = LQ_MIMO3;
  1138. tbl->action = 0;
  1139. tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
  1140. rate_mask = lq_sta->active_mimo3_rate;
  1141. if (iwl_is_ht40_tx_allowed(mvm, &sta->ht_cap))
  1142. tbl->is_ht40 = 1;
  1143. else
  1144. tbl->is_ht40 = 0;
  1145. rs_set_expected_tpt_table(lq_sta, tbl);
  1146. rate = rs_get_best_rate(mvm, lq_sta, tbl, rate_mask, index);
  1147. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 best rate %d mask %X\n",
  1148. rate, rate_mask);
  1149. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
  1150. IWL_DEBUG_RATE(mvm, "Can't switch with index %d rate mask %x\n",
  1151. rate, rate_mask);
  1152. return -1;
  1153. }
  1154. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, rate, is_green);
  1155. IWL_DEBUG_RATE(mvm, "LQ: Switch to new mcs %X index is green %X\n",
  1156. tbl->current_rate, is_green);
  1157. return 0;
  1158. }
  1159. /*
  1160. * Set up search table for SISO
  1161. */
  1162. static int rs_switch_to_siso(struct iwl_mvm *mvm,
  1163. struct iwl_lq_sta *lq_sta,
  1164. struct ieee80211_sta *sta,
  1165. struct iwl_scale_tbl_info *tbl, int index)
  1166. {
  1167. u16 rate_mask;
  1168. u8 is_green = lq_sta->is_green;
  1169. s32 rate;
  1170. if (!sta->ht_cap.ht_supported)
  1171. return -1;
  1172. IWL_DEBUG_RATE(mvm, "LQ: try to switch to SISO\n");
  1173. tbl->lq_type = LQ_SISO;
  1174. tbl->action = 0;
  1175. tbl->max_search = IWL_MAX_SEARCH;
  1176. rate_mask = lq_sta->active_siso_rate;
  1177. if (iwl_is_ht40_tx_allowed(mvm, &sta->ht_cap))
  1178. tbl->is_ht40 = 1;
  1179. else
  1180. tbl->is_ht40 = 0;
  1181. if (is_green)
  1182. tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/
  1183. rs_set_expected_tpt_table(lq_sta, tbl);
  1184. rate = rs_get_best_rate(mvm, lq_sta, tbl, rate_mask, index);
  1185. IWL_DEBUG_RATE(mvm, "LQ: get best rate %d mask %X\n", rate, rate_mask);
  1186. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
  1187. IWL_DEBUG_RATE(mvm,
  1188. "can not switch with index %d rate mask %x\n",
  1189. rate, rate_mask);
  1190. return -1;
  1191. }
  1192. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, rate, is_green);
  1193. IWL_DEBUG_RATE(mvm, "LQ: Switch to new mcs %X index is green %X\n",
  1194. tbl->current_rate, is_green);
  1195. return 0;
  1196. }
  1197. /*
  1198. * Try to switch to new modulation mode from legacy
  1199. */
  1200. static int rs_move_legacy_other(struct iwl_mvm *mvm,
  1201. struct iwl_lq_sta *lq_sta,
  1202. struct ieee80211_sta *sta,
  1203. int index)
  1204. {
  1205. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1206. struct iwl_scale_tbl_info *search_tbl =
  1207. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1208. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1209. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1210. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1211. u8 start_action;
  1212. u8 valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  1213. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1214. int ret;
  1215. u8 update_search_tbl_counter = 0;
  1216. start_action = tbl->action;
  1217. while (1) {
  1218. lq_sta->action_counter++;
  1219. switch (tbl->action) {
  1220. case IWL_LEGACY_SWITCH_ANTENNA1:
  1221. case IWL_LEGACY_SWITCH_ANTENNA2:
  1222. IWL_DEBUG_RATE(mvm, "LQ: Legacy toggle Antenna\n");
  1223. if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 &&
  1224. tx_chains_num <= 1) ||
  1225. (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 &&
  1226. tx_chains_num <= 2))
  1227. break;
  1228. /* Don't change antenna if success has been great */
  1229. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1230. break;
  1231. /* Set up search table to try other antenna */
  1232. memcpy(search_tbl, tbl, sz);
  1233. if (rs_toggle_antenna(valid_tx_ant,
  1234. &search_tbl->current_rate,
  1235. search_tbl)) {
  1236. update_search_tbl_counter = 1;
  1237. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1238. goto out;
  1239. }
  1240. break;
  1241. case IWL_LEGACY_SWITCH_SISO:
  1242. IWL_DEBUG_RATE(mvm, "LQ: Legacy switch to SISO\n");
  1243. /* Set up search table to try SISO */
  1244. memcpy(search_tbl, tbl, sz);
  1245. search_tbl->is_SGI = 0;
  1246. ret = rs_switch_to_siso(mvm, lq_sta, sta,
  1247. search_tbl, index);
  1248. if (!ret) {
  1249. lq_sta->action_counter = 0;
  1250. goto out;
  1251. }
  1252. break;
  1253. case IWL_LEGACY_SWITCH_MIMO2_AB:
  1254. case IWL_LEGACY_SWITCH_MIMO2_AC:
  1255. case IWL_LEGACY_SWITCH_MIMO2_BC:
  1256. IWL_DEBUG_RATE(mvm, "LQ: Legacy switch to MIMO2\n");
  1257. /* Set up search table to try MIMO */
  1258. memcpy(search_tbl, tbl, sz);
  1259. search_tbl->is_SGI = 0;
  1260. if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AB)
  1261. search_tbl->ant_type = ANT_AB;
  1262. else if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AC)
  1263. search_tbl->ant_type = ANT_AC;
  1264. else
  1265. search_tbl->ant_type = ANT_BC;
  1266. if (!rs_is_valid_ant(valid_tx_ant,
  1267. search_tbl->ant_type))
  1268. break;
  1269. ret = rs_switch_to_mimo2(mvm, lq_sta, sta,
  1270. search_tbl, index);
  1271. if (!ret) {
  1272. lq_sta->action_counter = 0;
  1273. goto out;
  1274. }
  1275. break;
  1276. case IWL_LEGACY_SWITCH_MIMO3_ABC:
  1277. IWL_DEBUG_RATE(mvm, "LQ: Legacy switch to MIMO3\n");
  1278. /* Set up search table to try MIMO3 */
  1279. memcpy(search_tbl, tbl, sz);
  1280. search_tbl->is_SGI = 0;
  1281. search_tbl->ant_type = ANT_ABC;
  1282. if (!rs_is_valid_ant(valid_tx_ant,
  1283. search_tbl->ant_type))
  1284. break;
  1285. ret = rs_switch_to_mimo3(mvm, lq_sta, sta,
  1286. search_tbl, index);
  1287. if (!ret) {
  1288. lq_sta->action_counter = 0;
  1289. goto out;
  1290. }
  1291. break;
  1292. }
  1293. tbl->action++;
  1294. if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
  1295. tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
  1296. if (tbl->action == start_action)
  1297. break;
  1298. }
  1299. search_tbl->lq_type = LQ_NONE;
  1300. return 0;
  1301. out:
  1302. lq_sta->search_better_tbl = 1;
  1303. tbl->action++;
  1304. if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
  1305. tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
  1306. if (update_search_tbl_counter)
  1307. search_tbl->action = tbl->action;
  1308. return 0;
  1309. }
  1310. /*
  1311. * Try to switch to new modulation mode from SISO
  1312. */
  1313. static int rs_move_siso_to_other(struct iwl_mvm *mvm,
  1314. struct iwl_lq_sta *lq_sta,
  1315. struct ieee80211_sta *sta, int index)
  1316. {
  1317. u8 is_green = lq_sta->is_green;
  1318. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1319. struct iwl_scale_tbl_info *search_tbl =
  1320. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1321. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1322. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1323. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1324. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1325. u8 start_action;
  1326. u8 valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  1327. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1328. u8 update_search_tbl_counter = 0;
  1329. int ret;
  1330. start_action = tbl->action;
  1331. while (1) {
  1332. lq_sta->action_counter++;
  1333. switch (tbl->action) {
  1334. case IWL_SISO_SWITCH_ANTENNA1:
  1335. case IWL_SISO_SWITCH_ANTENNA2:
  1336. IWL_DEBUG_RATE(mvm, "LQ: SISO toggle Antenna\n");
  1337. if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 &&
  1338. tx_chains_num <= 1) ||
  1339. (tbl->action == IWL_SISO_SWITCH_ANTENNA2 &&
  1340. tx_chains_num <= 2))
  1341. break;
  1342. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1343. break;
  1344. memcpy(search_tbl, tbl, sz);
  1345. if (rs_toggle_antenna(valid_tx_ant,
  1346. &search_tbl->current_rate,
  1347. search_tbl)) {
  1348. update_search_tbl_counter = 1;
  1349. goto out;
  1350. }
  1351. break;
  1352. case IWL_SISO_SWITCH_MIMO2_AB:
  1353. case IWL_SISO_SWITCH_MIMO2_AC:
  1354. case IWL_SISO_SWITCH_MIMO2_BC:
  1355. IWL_DEBUG_RATE(mvm, "LQ: SISO switch to MIMO2\n");
  1356. memcpy(search_tbl, tbl, sz);
  1357. search_tbl->is_SGI = 0;
  1358. if (tbl->action == IWL_SISO_SWITCH_MIMO2_AB)
  1359. search_tbl->ant_type = ANT_AB;
  1360. else if (tbl->action == IWL_SISO_SWITCH_MIMO2_AC)
  1361. search_tbl->ant_type = ANT_AC;
  1362. else
  1363. search_tbl->ant_type = ANT_BC;
  1364. if (!rs_is_valid_ant(valid_tx_ant,
  1365. search_tbl->ant_type))
  1366. break;
  1367. ret = rs_switch_to_mimo2(mvm, lq_sta, sta,
  1368. search_tbl, index);
  1369. if (!ret)
  1370. goto out;
  1371. break;
  1372. case IWL_SISO_SWITCH_GI:
  1373. if (!tbl->is_ht40 && !(ht_cap->cap &
  1374. IEEE80211_HT_CAP_SGI_20))
  1375. break;
  1376. if (tbl->is_ht40 && !(ht_cap->cap &
  1377. IEEE80211_HT_CAP_SGI_40))
  1378. break;
  1379. IWL_DEBUG_RATE(mvm, "LQ: SISO toggle SGI/NGI\n");
  1380. memcpy(search_tbl, tbl, sz);
  1381. if (is_green) {
  1382. if (!tbl->is_SGI)
  1383. break;
  1384. else
  1385. IWL_ERR(mvm,
  1386. "SGI was set in GF+SISO\n");
  1387. }
  1388. search_tbl->is_SGI = !tbl->is_SGI;
  1389. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1390. if (tbl->is_SGI) {
  1391. s32 tpt = lq_sta->last_tpt / 100;
  1392. if (tpt >= search_tbl->expected_tpt[index])
  1393. break;
  1394. }
  1395. search_tbl->current_rate =
  1396. rate_n_flags_from_tbl(mvm, search_tbl,
  1397. index, is_green);
  1398. update_search_tbl_counter = 1;
  1399. goto out;
  1400. case IWL_SISO_SWITCH_MIMO3_ABC:
  1401. IWL_DEBUG_RATE(mvm, "LQ: SISO switch to MIMO3\n");
  1402. memcpy(search_tbl, tbl, sz);
  1403. search_tbl->is_SGI = 0;
  1404. search_tbl->ant_type = ANT_ABC;
  1405. if (!rs_is_valid_ant(valid_tx_ant,
  1406. search_tbl->ant_type))
  1407. break;
  1408. ret = rs_switch_to_mimo3(mvm, lq_sta, sta,
  1409. search_tbl, index);
  1410. if (!ret)
  1411. goto out;
  1412. break;
  1413. }
  1414. tbl->action++;
  1415. if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
  1416. tbl->action = IWL_SISO_SWITCH_ANTENNA1;
  1417. if (tbl->action == start_action)
  1418. break;
  1419. }
  1420. search_tbl->lq_type = LQ_NONE;
  1421. return 0;
  1422. out:
  1423. lq_sta->search_better_tbl = 1;
  1424. tbl->action++;
  1425. if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC)
  1426. tbl->action = IWL_SISO_SWITCH_ANTENNA1;
  1427. if (update_search_tbl_counter)
  1428. search_tbl->action = tbl->action;
  1429. return 0;
  1430. }
  1431. /*
  1432. * Try to switch to new modulation mode from MIMO2
  1433. */
  1434. static int rs_move_mimo2_to_other(struct iwl_mvm *mvm,
  1435. struct iwl_lq_sta *lq_sta,
  1436. struct ieee80211_sta *sta, int index)
  1437. {
  1438. s8 is_green = lq_sta->is_green;
  1439. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1440. struct iwl_scale_tbl_info *search_tbl =
  1441. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1442. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1443. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1444. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1445. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1446. u8 start_action;
  1447. u8 valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  1448. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1449. u8 update_search_tbl_counter = 0;
  1450. int ret;
  1451. start_action = tbl->action;
  1452. while (1) {
  1453. lq_sta->action_counter++;
  1454. switch (tbl->action) {
  1455. case IWL_MIMO2_SWITCH_ANTENNA1:
  1456. case IWL_MIMO2_SWITCH_ANTENNA2:
  1457. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 toggle Antennas\n");
  1458. if (tx_chains_num <= 2)
  1459. break;
  1460. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1461. break;
  1462. memcpy(search_tbl, tbl, sz);
  1463. if (rs_toggle_antenna(valid_tx_ant,
  1464. &search_tbl->current_rate,
  1465. search_tbl)) {
  1466. update_search_tbl_counter = 1;
  1467. goto out;
  1468. }
  1469. break;
  1470. case IWL_MIMO2_SWITCH_SISO_A:
  1471. case IWL_MIMO2_SWITCH_SISO_B:
  1472. case IWL_MIMO2_SWITCH_SISO_C:
  1473. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 switch to SISO\n");
  1474. /* Set up new search table for SISO */
  1475. memcpy(search_tbl, tbl, sz);
  1476. if (tbl->action == IWL_MIMO2_SWITCH_SISO_A)
  1477. search_tbl->ant_type = ANT_A;
  1478. else if (tbl->action == IWL_MIMO2_SWITCH_SISO_B)
  1479. search_tbl->ant_type = ANT_B;
  1480. else
  1481. search_tbl->ant_type = ANT_C;
  1482. if (!rs_is_valid_ant(valid_tx_ant,
  1483. search_tbl->ant_type))
  1484. break;
  1485. ret = rs_switch_to_siso(mvm, lq_sta, sta,
  1486. search_tbl, index);
  1487. if (!ret)
  1488. goto out;
  1489. break;
  1490. case IWL_MIMO2_SWITCH_GI:
  1491. if (!tbl->is_ht40 && !(ht_cap->cap &
  1492. IEEE80211_HT_CAP_SGI_20))
  1493. break;
  1494. if (tbl->is_ht40 && !(ht_cap->cap &
  1495. IEEE80211_HT_CAP_SGI_40))
  1496. break;
  1497. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 toggle SGI/NGI\n");
  1498. /* Set up new search table for MIMO2 */
  1499. memcpy(search_tbl, tbl, sz);
  1500. search_tbl->is_SGI = !tbl->is_SGI;
  1501. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1502. /*
  1503. * If active table already uses the fastest possible
  1504. * modulation (dual stream with short guard interval),
  1505. * and it's working well, there's no need to look
  1506. * for a better type of modulation!
  1507. */
  1508. if (tbl->is_SGI) {
  1509. s32 tpt = lq_sta->last_tpt / 100;
  1510. if (tpt >= search_tbl->expected_tpt[index])
  1511. break;
  1512. }
  1513. search_tbl->current_rate =
  1514. rate_n_flags_from_tbl(mvm, search_tbl,
  1515. index, is_green);
  1516. update_search_tbl_counter = 1;
  1517. goto out;
  1518. case IWL_MIMO2_SWITCH_MIMO3_ABC:
  1519. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 switch to MIMO3\n");
  1520. memcpy(search_tbl, tbl, sz);
  1521. search_tbl->is_SGI = 0;
  1522. search_tbl->ant_type = ANT_ABC;
  1523. if (!rs_is_valid_ant(valid_tx_ant,
  1524. search_tbl->ant_type))
  1525. break;
  1526. ret = rs_switch_to_mimo3(mvm, lq_sta, sta,
  1527. search_tbl, index);
  1528. if (!ret)
  1529. goto out;
  1530. break;
  1531. }
  1532. tbl->action++;
  1533. if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
  1534. tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
  1535. if (tbl->action == start_action)
  1536. break;
  1537. }
  1538. search_tbl->lq_type = LQ_NONE;
  1539. return 0;
  1540. out:
  1541. lq_sta->search_better_tbl = 1;
  1542. tbl->action++;
  1543. if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
  1544. tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
  1545. if (update_search_tbl_counter)
  1546. search_tbl->action = tbl->action;
  1547. return 0;
  1548. }
  1549. /*
  1550. * Try to switch to new modulation mode from MIMO3
  1551. */
  1552. static int rs_move_mimo3_to_other(struct iwl_mvm *mvm,
  1553. struct iwl_lq_sta *lq_sta,
  1554. struct ieee80211_sta *sta, int index)
  1555. {
  1556. s8 is_green = lq_sta->is_green;
  1557. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1558. struct iwl_scale_tbl_info *search_tbl =
  1559. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1560. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1561. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1562. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1563. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1564. u8 start_action;
  1565. u8 valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  1566. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1567. int ret;
  1568. u8 update_search_tbl_counter = 0;
  1569. start_action = tbl->action;
  1570. while (1) {
  1571. lq_sta->action_counter++;
  1572. switch (tbl->action) {
  1573. case IWL_MIMO3_SWITCH_ANTENNA1:
  1574. case IWL_MIMO3_SWITCH_ANTENNA2:
  1575. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 toggle Antennas\n");
  1576. if (tx_chains_num <= 3)
  1577. break;
  1578. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1579. break;
  1580. memcpy(search_tbl, tbl, sz);
  1581. if (rs_toggle_antenna(valid_tx_ant,
  1582. &search_tbl->current_rate,
  1583. search_tbl))
  1584. goto out;
  1585. break;
  1586. case IWL_MIMO3_SWITCH_SISO_A:
  1587. case IWL_MIMO3_SWITCH_SISO_B:
  1588. case IWL_MIMO3_SWITCH_SISO_C:
  1589. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 switch to SISO\n");
  1590. /* Set up new search table for SISO */
  1591. memcpy(search_tbl, tbl, sz);
  1592. if (tbl->action == IWL_MIMO3_SWITCH_SISO_A)
  1593. search_tbl->ant_type = ANT_A;
  1594. else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B)
  1595. search_tbl->ant_type = ANT_B;
  1596. else
  1597. search_tbl->ant_type = ANT_C;
  1598. if (!rs_is_valid_ant(valid_tx_ant,
  1599. search_tbl->ant_type))
  1600. break;
  1601. ret = rs_switch_to_siso(mvm, lq_sta, sta,
  1602. search_tbl, index);
  1603. if (!ret)
  1604. goto out;
  1605. break;
  1606. case IWL_MIMO3_SWITCH_MIMO2_AB:
  1607. case IWL_MIMO3_SWITCH_MIMO2_AC:
  1608. case IWL_MIMO3_SWITCH_MIMO2_BC:
  1609. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 switch to MIMO2\n");
  1610. memcpy(search_tbl, tbl, sz);
  1611. search_tbl->is_SGI = 0;
  1612. if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB)
  1613. search_tbl->ant_type = ANT_AB;
  1614. else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC)
  1615. search_tbl->ant_type = ANT_AC;
  1616. else
  1617. search_tbl->ant_type = ANT_BC;
  1618. if (!rs_is_valid_ant(valid_tx_ant,
  1619. search_tbl->ant_type))
  1620. break;
  1621. ret = rs_switch_to_mimo2(mvm, lq_sta, sta,
  1622. search_tbl, index);
  1623. if (!ret)
  1624. goto out;
  1625. break;
  1626. case IWL_MIMO3_SWITCH_GI:
  1627. if (!tbl->is_ht40 && !(ht_cap->cap &
  1628. IEEE80211_HT_CAP_SGI_20))
  1629. break;
  1630. if (tbl->is_ht40 && !(ht_cap->cap &
  1631. IEEE80211_HT_CAP_SGI_40))
  1632. break;
  1633. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 toggle SGI/NGI\n");
  1634. /* Set up new search table for MIMO */
  1635. memcpy(search_tbl, tbl, sz);
  1636. search_tbl->is_SGI = !tbl->is_SGI;
  1637. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1638. /*
  1639. * If active table already uses the fastest possible
  1640. * modulation (dual stream with short guard interval),
  1641. * and it's working well, there's no need to look
  1642. * for a better type of modulation!
  1643. */
  1644. if (tbl->is_SGI) {
  1645. s32 tpt = lq_sta->last_tpt / 100;
  1646. if (tpt >= search_tbl->expected_tpt[index])
  1647. break;
  1648. }
  1649. search_tbl->current_rate =
  1650. rate_n_flags_from_tbl(mvm, search_tbl,
  1651. index, is_green);
  1652. update_search_tbl_counter = 1;
  1653. goto out;
  1654. }
  1655. tbl->action++;
  1656. if (tbl->action > IWL_MIMO3_SWITCH_GI)
  1657. tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
  1658. if (tbl->action == start_action)
  1659. break;
  1660. }
  1661. search_tbl->lq_type = LQ_NONE;
  1662. return 0;
  1663. out:
  1664. lq_sta->search_better_tbl = 1;
  1665. tbl->action++;
  1666. if (tbl->action > IWL_MIMO3_SWITCH_GI)
  1667. tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
  1668. if (update_search_tbl_counter)
  1669. search_tbl->action = tbl->action;
  1670. return 0;
  1671. }
  1672. /*
  1673. * Check whether we should continue using same modulation mode, or
  1674. * begin search for a new mode, based on:
  1675. * 1) # tx successes or failures while using this mode
  1676. * 2) # times calling this function
  1677. * 3) elapsed time in this mode (not used, for now)
  1678. */
  1679. static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search)
  1680. {
  1681. struct iwl_scale_tbl_info *tbl;
  1682. int i;
  1683. int active_tbl;
  1684. int flush_interval_passed = 0;
  1685. struct iwl_mvm *mvm;
  1686. mvm = lq_sta->drv;
  1687. active_tbl = lq_sta->active_tbl;
  1688. tbl = &(lq_sta->lq_info[active_tbl]);
  1689. /* If we've been disallowing search, see if we should now allow it */
  1690. if (lq_sta->stay_in_tbl) {
  1691. /* Elapsed time using current modulation mode */
  1692. if (lq_sta->flush_timer)
  1693. flush_interval_passed =
  1694. time_after(jiffies,
  1695. (unsigned long)(lq_sta->flush_timer +
  1696. IWL_RATE_SCALE_FLUSH_INTVL));
  1697. /*
  1698. * Check if we should allow search for new modulation mode.
  1699. * If many frames have failed or succeeded, or we've used
  1700. * this same modulation for a long time, allow search, and
  1701. * reset history stats that keep track of whether we should
  1702. * allow a new search. Also (below) reset all bitmaps and
  1703. * stats in active history.
  1704. */
  1705. if (force_search ||
  1706. (lq_sta->total_failed > lq_sta->max_failure_limit) ||
  1707. (lq_sta->total_success > lq_sta->max_success_limit) ||
  1708. ((!lq_sta->search_better_tbl) &&
  1709. (lq_sta->flush_timer) && (flush_interval_passed))) {
  1710. IWL_DEBUG_RATE(mvm,
  1711. "LQ: stay is expired %d %d %d\n",
  1712. lq_sta->total_failed,
  1713. lq_sta->total_success,
  1714. flush_interval_passed);
  1715. /* Allow search for new mode */
  1716. lq_sta->stay_in_tbl = 0; /* only place reset */
  1717. lq_sta->total_failed = 0;
  1718. lq_sta->total_success = 0;
  1719. lq_sta->flush_timer = 0;
  1720. /*
  1721. * Else if we've used this modulation mode enough repetitions
  1722. * (regardless of elapsed time or success/failure), reset
  1723. * history bitmaps and rate-specific stats for all rates in
  1724. * active table.
  1725. */
  1726. } else {
  1727. lq_sta->table_count++;
  1728. if (lq_sta->table_count >=
  1729. lq_sta->table_count_limit) {
  1730. lq_sta->table_count = 0;
  1731. IWL_DEBUG_RATE(mvm,
  1732. "LQ: stay in table clear win\n");
  1733. for (i = 0; i < IWL_RATE_COUNT; i++)
  1734. rs_rate_scale_clear_window(
  1735. &(tbl->win[i]));
  1736. }
  1737. }
  1738. /* If transitioning to allow "search", reset all history
  1739. * bitmaps and stats in active table (this will become the new
  1740. * "search" table). */
  1741. if (!lq_sta->stay_in_tbl) {
  1742. for (i = 0; i < IWL_RATE_COUNT; i++)
  1743. rs_rate_scale_clear_window(&(tbl->win[i]));
  1744. }
  1745. }
  1746. }
  1747. /*
  1748. * setup rate table in uCode
  1749. */
  1750. static void rs_update_rate_tbl(struct iwl_mvm *mvm,
  1751. struct iwl_lq_sta *lq_sta,
  1752. struct iwl_scale_tbl_info *tbl,
  1753. int index, u8 is_green)
  1754. {
  1755. u32 rate;
  1756. /* Update uCode's rate table. */
  1757. rate = rate_n_flags_from_tbl(mvm, tbl, index, is_green);
  1758. rs_fill_link_cmd(mvm, lq_sta, rate);
  1759. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_ASYNC, false);
  1760. }
  1761. /*
  1762. * Do rate scaling and search for new modulation mode.
  1763. */
  1764. static void rs_rate_scale_perform(struct iwl_mvm *mvm,
  1765. struct sk_buff *skb,
  1766. struct ieee80211_sta *sta,
  1767. struct iwl_lq_sta *lq_sta)
  1768. {
  1769. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1770. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1771. int low = IWL_RATE_INVALID;
  1772. int high = IWL_RATE_INVALID;
  1773. int index;
  1774. int i;
  1775. struct iwl_rate_scale_data *window = NULL;
  1776. int current_tpt = IWL_INVALID_VALUE;
  1777. int low_tpt = IWL_INVALID_VALUE;
  1778. int high_tpt = IWL_INVALID_VALUE;
  1779. u32 fail_count;
  1780. s8 scale_action = 0;
  1781. u16 rate_mask;
  1782. u8 update_lq = 0;
  1783. struct iwl_scale_tbl_info *tbl, *tbl1;
  1784. u16 rate_scale_index_msk = 0;
  1785. u8 is_green = 0;
  1786. u8 active_tbl = 0;
  1787. u8 done_search = 0;
  1788. u16 high_low;
  1789. s32 sr;
  1790. u8 tid = IWL_MAX_TID_COUNT;
  1791. struct iwl_mvm_sta *sta_priv = (void *)sta->drv_priv;
  1792. struct iwl_mvm_tid_data *tid_data;
  1793. IWL_DEBUG_RATE(mvm, "rate scale calculate new rate for skb\n");
  1794. /* Send management frames and NO_ACK data using lowest rate. */
  1795. /* TODO: this could probably be improved.. */
  1796. if (!ieee80211_is_data(hdr->frame_control) ||
  1797. info->flags & IEEE80211_TX_CTL_NO_ACK)
  1798. return;
  1799. lq_sta->supp_rates = sta->supp_rates[lq_sta->band];
  1800. tid = rs_tl_add_packet(lq_sta, hdr);
  1801. if ((tid != IWL_MAX_TID_COUNT) &&
  1802. (lq_sta->tx_agg_tid_en & (1 << tid))) {
  1803. tid_data = &sta_priv->tid_data[tid];
  1804. if (tid_data->state == IWL_AGG_OFF)
  1805. lq_sta->is_agg = 0;
  1806. else
  1807. lq_sta->is_agg = 1;
  1808. } else {
  1809. lq_sta->is_agg = 0;
  1810. }
  1811. /*
  1812. * Select rate-scale / modulation-mode table to work with in
  1813. * the rest of this function: "search" if searching for better
  1814. * modulation mode, or "active" if doing rate scaling within a mode.
  1815. */
  1816. if (!lq_sta->search_better_tbl)
  1817. active_tbl = lq_sta->active_tbl;
  1818. else
  1819. active_tbl = 1 - lq_sta->active_tbl;
  1820. tbl = &(lq_sta->lq_info[active_tbl]);
  1821. if (is_legacy(tbl->lq_type))
  1822. lq_sta->is_green = 0;
  1823. else
  1824. lq_sta->is_green = rs_use_green(sta);
  1825. is_green = lq_sta->is_green;
  1826. /* current tx rate */
  1827. index = lq_sta->last_txrate_idx;
  1828. IWL_DEBUG_RATE(mvm, "Rate scale index %d for type %d\n", index,
  1829. tbl->lq_type);
  1830. /* rates available for this association, and for modulation mode */
  1831. rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
  1832. IWL_DEBUG_RATE(mvm, "mask 0x%04X\n", rate_mask);
  1833. /* mask with station rate restriction */
  1834. if (is_legacy(tbl->lq_type)) {
  1835. if (lq_sta->band == IEEE80211_BAND_5GHZ)
  1836. /* supp_rates has no CCK bits in A mode */
  1837. rate_scale_index_msk = (u16) (rate_mask &
  1838. (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
  1839. else
  1840. rate_scale_index_msk = (u16) (rate_mask &
  1841. lq_sta->supp_rates);
  1842. } else {
  1843. rate_scale_index_msk = rate_mask;
  1844. }
  1845. if (!rate_scale_index_msk)
  1846. rate_scale_index_msk = rate_mask;
  1847. if (!((1 << index) & rate_scale_index_msk)) {
  1848. IWL_ERR(mvm, "Current Rate is not valid\n");
  1849. if (lq_sta->search_better_tbl) {
  1850. /* revert to active table if search table is not valid*/
  1851. tbl->lq_type = LQ_NONE;
  1852. lq_sta->search_better_tbl = 0;
  1853. tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1854. /* get "active" rate info */
  1855. index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
  1856. rs_update_rate_tbl(mvm, lq_sta, tbl, index, is_green);
  1857. }
  1858. return;
  1859. }
  1860. /* Get expected throughput table and history window for current rate */
  1861. if (!tbl->expected_tpt) {
  1862. IWL_ERR(mvm, "tbl->expected_tpt is NULL\n");
  1863. return;
  1864. }
  1865. /* force user max rate if set by user */
  1866. if ((lq_sta->max_rate_idx != -1) &&
  1867. (lq_sta->max_rate_idx < index)) {
  1868. index = lq_sta->max_rate_idx;
  1869. update_lq = 1;
  1870. window = &(tbl->win[index]);
  1871. goto lq_update;
  1872. }
  1873. window = &(tbl->win[index]);
  1874. /*
  1875. * If there is not enough history to calculate actual average
  1876. * throughput, keep analyzing results of more tx frames, without
  1877. * changing rate or mode (bypass most of the rest of this function).
  1878. * Set up new rate table in uCode only if old rate is not supported
  1879. * in current association (use new rate found above).
  1880. */
  1881. fail_count = window->counter - window->success_counter;
  1882. if ((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
  1883. (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) {
  1884. IWL_DEBUG_RATE(mvm,
  1885. "LQ: still below TH. succ=%d total=%d for index %d\n",
  1886. window->success_counter, window->counter, index);
  1887. /* Can't calculate this yet; not enough history */
  1888. window->average_tpt = IWL_INVALID_VALUE;
  1889. /* Should we stay with this modulation mode,
  1890. * or search for a new one? */
  1891. rs_stay_in_table(lq_sta, false);
  1892. goto out;
  1893. }
  1894. /* Else we have enough samples; calculate estimate of
  1895. * actual average throughput */
  1896. if (window->average_tpt != ((window->success_ratio *
  1897. tbl->expected_tpt[index] + 64) / 128)) {
  1898. IWL_ERR(mvm,
  1899. "expected_tpt should have been calculated by now\n");
  1900. window->average_tpt = ((window->success_ratio *
  1901. tbl->expected_tpt[index] + 64) / 128);
  1902. }
  1903. /* If we are searching for better modulation mode, check success. */
  1904. if (lq_sta->search_better_tbl) {
  1905. /* If good success, continue using the "search" mode;
  1906. * no need to send new link quality command, since we're
  1907. * continuing to use the setup that we've been trying. */
  1908. if (window->average_tpt > lq_sta->last_tpt) {
  1909. IWL_DEBUG_RATE(mvm,
  1910. "LQ: SWITCHING TO NEW TABLE suc=%d cur-tpt=%d old-tpt=%d\n",
  1911. window->success_ratio,
  1912. window->average_tpt,
  1913. lq_sta->last_tpt);
  1914. if (!is_legacy(tbl->lq_type))
  1915. lq_sta->enable_counter = 1;
  1916. /* Swap tables; "search" becomes "active" */
  1917. lq_sta->active_tbl = active_tbl;
  1918. current_tpt = window->average_tpt;
  1919. /* Else poor success; go back to mode in "active" table */
  1920. } else {
  1921. IWL_DEBUG_RATE(mvm,
  1922. "LQ: GOING BACK TO THE OLD TABLE suc=%d cur-tpt=%d old-tpt=%d\n",
  1923. window->success_ratio,
  1924. window->average_tpt,
  1925. lq_sta->last_tpt);
  1926. /* Nullify "search" table */
  1927. tbl->lq_type = LQ_NONE;
  1928. /* Revert to "active" table */
  1929. active_tbl = lq_sta->active_tbl;
  1930. tbl = &(lq_sta->lq_info[active_tbl]);
  1931. /* Revert to "active" rate and throughput info */
  1932. index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
  1933. current_tpt = lq_sta->last_tpt;
  1934. /* Need to set up a new rate table in uCode */
  1935. update_lq = 1;
  1936. }
  1937. /* Either way, we've made a decision; modulation mode
  1938. * search is done, allow rate adjustment next time. */
  1939. lq_sta->search_better_tbl = 0;
  1940. done_search = 1; /* Don't switch modes below! */
  1941. goto lq_update;
  1942. }
  1943. /* (Else) not in search of better modulation mode, try for better
  1944. * starting rate, while staying in this mode. */
  1945. high_low = rs_get_adjacent_rate(mvm, index, rate_scale_index_msk,
  1946. tbl->lq_type);
  1947. low = high_low & 0xff;
  1948. high = (high_low >> 8) & 0xff;
  1949. /* If user set max rate, dont allow higher than user constrain */
  1950. if ((lq_sta->max_rate_idx != -1) &&
  1951. (lq_sta->max_rate_idx < high))
  1952. high = IWL_RATE_INVALID;
  1953. sr = window->success_ratio;
  1954. /* Collect measured throughputs for current and adjacent rates */
  1955. current_tpt = window->average_tpt;
  1956. if (low != IWL_RATE_INVALID)
  1957. low_tpt = tbl->win[low].average_tpt;
  1958. if (high != IWL_RATE_INVALID)
  1959. high_tpt = tbl->win[high].average_tpt;
  1960. scale_action = 0;
  1961. /* Too many failures, decrease rate */
  1962. if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) {
  1963. IWL_DEBUG_RATE(mvm,
  1964. "decrease rate because of low success_ratio\n");
  1965. scale_action = -1;
  1966. /* No throughput measured yet for adjacent rates; try increase. */
  1967. } else if ((low_tpt == IWL_INVALID_VALUE) &&
  1968. (high_tpt == IWL_INVALID_VALUE)) {
  1969. if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH)
  1970. scale_action = 1;
  1971. else if (low != IWL_RATE_INVALID)
  1972. scale_action = 0;
  1973. }
  1974. /* Both adjacent throughputs are measured, but neither one has better
  1975. * throughput; we're using the best rate, don't change it! */
  1976. else if ((low_tpt != IWL_INVALID_VALUE) &&
  1977. (high_tpt != IWL_INVALID_VALUE) &&
  1978. (low_tpt < current_tpt) &&
  1979. (high_tpt < current_tpt))
  1980. scale_action = 0;
  1981. /* At least one adjacent rate's throughput is measured,
  1982. * and may have better performance. */
  1983. else {
  1984. /* Higher adjacent rate's throughput is measured */
  1985. if (high_tpt != IWL_INVALID_VALUE) {
  1986. /* Higher rate has better throughput */
  1987. if (high_tpt > current_tpt &&
  1988. sr >= IWL_RATE_INCREASE_TH) {
  1989. scale_action = 1;
  1990. } else {
  1991. scale_action = 0;
  1992. }
  1993. /* Lower adjacent rate's throughput is measured */
  1994. } else if (low_tpt != IWL_INVALID_VALUE) {
  1995. /* Lower rate has better throughput */
  1996. if (low_tpt > current_tpt) {
  1997. IWL_DEBUG_RATE(mvm,
  1998. "decrease rate because of low tpt\n");
  1999. scale_action = -1;
  2000. } else if (sr >= IWL_RATE_INCREASE_TH) {
  2001. scale_action = 1;
  2002. }
  2003. }
  2004. }
  2005. /* Sanity check; asked for decrease, but success rate or throughput
  2006. * has been good at old rate. Don't change it. */
  2007. if ((scale_action == -1) && (low != IWL_RATE_INVALID) &&
  2008. ((sr > IWL_RATE_HIGH_TH) ||
  2009. (current_tpt > (100 * tbl->expected_tpt[low]))))
  2010. scale_action = 0;
  2011. switch (scale_action) {
  2012. case -1:
  2013. /* Decrease starting rate, update uCode's rate table */
  2014. if (low != IWL_RATE_INVALID) {
  2015. update_lq = 1;
  2016. index = low;
  2017. }
  2018. break;
  2019. case 1:
  2020. /* Increase starting rate, update uCode's rate table */
  2021. if (high != IWL_RATE_INVALID) {
  2022. update_lq = 1;
  2023. index = high;
  2024. }
  2025. break;
  2026. case 0:
  2027. /* No change */
  2028. default:
  2029. break;
  2030. }
  2031. IWL_DEBUG_RATE(mvm,
  2032. "choose rate scale index %d action %d low %d high %d type %d\n",
  2033. index, scale_action, low, high, tbl->lq_type);
  2034. lq_update:
  2035. /* Replace uCode's rate table for the destination station. */
  2036. if (update_lq)
  2037. rs_update_rate_tbl(mvm, lq_sta, tbl, index, is_green);
  2038. rs_stay_in_table(lq_sta, false);
  2039. /*
  2040. * Search for new modulation mode if we're:
  2041. * 1) Not changing rates right now
  2042. * 2) Not just finishing up a search
  2043. * 3) Allowing a new search
  2044. */
  2045. if (!update_lq && !done_search &&
  2046. !lq_sta->stay_in_tbl && window->counter) {
  2047. /* Save current throughput to compare with "search" throughput*/
  2048. lq_sta->last_tpt = current_tpt;
  2049. /* Select a new "search" modulation mode to try.
  2050. * If one is found, set up the new "search" table. */
  2051. if (is_legacy(tbl->lq_type))
  2052. rs_move_legacy_other(mvm, lq_sta, sta, index);
  2053. else if (is_siso(tbl->lq_type))
  2054. rs_move_siso_to_other(mvm, lq_sta, sta, index);
  2055. else if (is_mimo2(tbl->lq_type))
  2056. rs_move_mimo2_to_other(mvm, lq_sta, sta, index);
  2057. else
  2058. rs_move_mimo3_to_other(mvm, lq_sta, sta, index);
  2059. /* If new "search" mode was selected, set up in uCode table */
  2060. if (lq_sta->search_better_tbl) {
  2061. /* Access the "search" table, clear its history. */
  2062. tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  2063. for (i = 0; i < IWL_RATE_COUNT; i++)
  2064. rs_rate_scale_clear_window(&(tbl->win[i]));
  2065. /* Use new "search" start rate */
  2066. index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
  2067. IWL_DEBUG_RATE(mvm,
  2068. "Switch current mcs: %X index: %d\n",
  2069. tbl->current_rate, index);
  2070. rs_fill_link_cmd(mvm, lq_sta, tbl->current_rate);
  2071. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_ASYNC, false);
  2072. } else {
  2073. done_search = 1;
  2074. }
  2075. }
  2076. if (done_search && !lq_sta->stay_in_tbl) {
  2077. /* If the "active" (non-search) mode was legacy,
  2078. * and we've tried switching antennas,
  2079. * but we haven't been able to try HT modes (not available),
  2080. * stay with best antenna legacy modulation for a while
  2081. * before next round of mode comparisons. */
  2082. tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
  2083. if (is_legacy(tbl1->lq_type) && !sta->ht_cap.ht_supported &&
  2084. lq_sta->action_counter > tbl1->max_search) {
  2085. IWL_DEBUG_RATE(mvm, "LQ: STAY in legacy table\n");
  2086. rs_set_stay_in_table(mvm, 1, lq_sta);
  2087. }
  2088. /* If we're in an HT mode, and all 3 mode switch actions
  2089. * have been tried and compared, stay in this best modulation
  2090. * mode for a while before next round of mode comparisons. */
  2091. if (lq_sta->enable_counter &&
  2092. (lq_sta->action_counter >= tbl1->max_search)) {
  2093. if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
  2094. (lq_sta->tx_agg_tid_en & (1 << tid)) &&
  2095. (tid != IWL_MAX_TID_COUNT)) {
  2096. tid_data = &sta_priv->tid_data[tid];
  2097. if (tid_data->state == IWL_AGG_OFF) {
  2098. IWL_DEBUG_RATE(mvm,
  2099. "try to aggregate tid %d\n",
  2100. tid);
  2101. rs_tl_turn_on_agg(mvm, tid,
  2102. lq_sta, sta);
  2103. }
  2104. }
  2105. rs_set_stay_in_table(mvm, 0, lq_sta);
  2106. }
  2107. }
  2108. out:
  2109. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, index, is_green);
  2110. lq_sta->last_txrate_idx = index;
  2111. }
  2112. /**
  2113. * rs_initialize_lq - Initialize a station's hardware rate table
  2114. *
  2115. * The uCode's station table contains a table of fallback rates
  2116. * for automatic fallback during transmission.
  2117. *
  2118. * NOTE: This sets up a default set of values. These will be replaced later
  2119. * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
  2120. * rc80211_simple.
  2121. *
  2122. * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
  2123. * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  2124. * which requires station table entry to exist).
  2125. */
  2126. static void rs_initialize_lq(struct iwl_mvm *mvm,
  2127. struct ieee80211_sta *sta,
  2128. struct iwl_lq_sta *lq_sta,
  2129. enum ieee80211_band band)
  2130. {
  2131. struct iwl_scale_tbl_info *tbl;
  2132. int rate_idx;
  2133. int i;
  2134. u32 rate;
  2135. u8 use_green = rs_use_green(sta);
  2136. u8 active_tbl = 0;
  2137. u8 valid_tx_ant;
  2138. if (!sta || !lq_sta)
  2139. return;
  2140. i = lq_sta->last_txrate_idx;
  2141. valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  2142. if (!lq_sta->search_better_tbl)
  2143. active_tbl = lq_sta->active_tbl;
  2144. else
  2145. active_tbl = 1 - lq_sta->active_tbl;
  2146. tbl = &(lq_sta->lq_info[active_tbl]);
  2147. if ((i < 0) || (i >= IWL_RATE_COUNT))
  2148. i = 0;
  2149. rate = iwl_rates[i].plcp;
  2150. tbl->ant_type = first_antenna(valid_tx_ant);
  2151. rate |= tbl->ant_type << RATE_MCS_ANT_POS;
  2152. if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
  2153. rate |= RATE_MCS_CCK_MSK;
  2154. rs_get_tbl_info_from_mcs(rate, band, tbl, &rate_idx);
  2155. if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
  2156. rs_toggle_antenna(valid_tx_ant, &rate, tbl);
  2157. rate = rate_n_flags_from_tbl(mvm, tbl, rate_idx, use_green);
  2158. tbl->current_rate = rate;
  2159. rs_set_expected_tpt_table(lq_sta, tbl);
  2160. rs_fill_link_cmd(NULL, lq_sta, rate);
  2161. /* TODO restore station should remember the lq cmd */
  2162. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_SYNC, true);
  2163. }
  2164. static void rs_get_rate(void *mvm_r, struct ieee80211_sta *sta, void *mvm_sta,
  2165. struct ieee80211_tx_rate_control *txrc)
  2166. {
  2167. struct sk_buff *skb = txrc->skb;
  2168. struct ieee80211_supported_band *sband = txrc->sband;
  2169. struct iwl_op_mode *op_mode __maybe_unused =
  2170. (struct iwl_op_mode *)mvm_r;
  2171. struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode);
  2172. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2173. struct iwl_lq_sta *lq_sta = mvm_sta;
  2174. int rate_idx;
  2175. IWL_DEBUG_RATE_LIMIT(mvm, "rate scale calculate new rate for skb\n");
  2176. /* Get max rate if user set max rate */
  2177. if (lq_sta) {
  2178. lq_sta->max_rate_idx = txrc->max_rate_idx;
  2179. if ((sband->band == IEEE80211_BAND_5GHZ) &&
  2180. (lq_sta->max_rate_idx != -1))
  2181. lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE;
  2182. if ((lq_sta->max_rate_idx < 0) ||
  2183. (lq_sta->max_rate_idx >= IWL_RATE_COUNT))
  2184. lq_sta->max_rate_idx = -1;
  2185. }
  2186. /* Treat uninitialized rate scaling data same as non-existing. */
  2187. if (lq_sta && !lq_sta->drv) {
  2188. IWL_DEBUG_RATE(mvm, "Rate scaling not initialized yet.\n");
  2189. mvm_sta = NULL;
  2190. }
  2191. /* Send management frames and NO_ACK data using lowest rate. */
  2192. if (rate_control_send_low(sta, mvm_sta, txrc))
  2193. return;
  2194. rate_idx = lq_sta->last_txrate_idx;
  2195. if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
  2196. rate_idx -= IWL_FIRST_OFDM_RATE;
  2197. /* 6M and 9M shared same MCS index */
  2198. rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0;
  2199. if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
  2200. IWL_RATE_MIMO3_6M_PLCP)
  2201. rate_idx = rate_idx + (2 * MCS_INDEX_PER_STREAM);
  2202. else if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
  2203. IWL_RATE_MIMO2_6M_PLCP)
  2204. rate_idx = rate_idx + MCS_INDEX_PER_STREAM;
  2205. info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
  2206. if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK)
  2207. info->control.rates[0].flags |= IEEE80211_TX_RC_SHORT_GI;
  2208. if (lq_sta->last_rate_n_flags & RATE_MCS_CHAN_WIDTH_40) /* TODO */
  2209. info->control.rates[0].flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  2210. if (lq_sta->last_rate_n_flags & RATE_HT_MCS_GF_MSK)
  2211. info->control.rates[0].flags |= IEEE80211_TX_RC_GREEN_FIELD;
  2212. } else {
  2213. /* Check for invalid rates */
  2214. if ((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT_LEGACY) ||
  2215. ((sband->band == IEEE80211_BAND_5GHZ) &&
  2216. (rate_idx < IWL_FIRST_OFDM_RATE)))
  2217. rate_idx = rate_lowest_index(sband, sta);
  2218. /* On valid 5 GHz rate, adjust index */
  2219. else if (sband->band == IEEE80211_BAND_5GHZ)
  2220. rate_idx -= IWL_FIRST_OFDM_RATE;
  2221. info->control.rates[0].flags = 0;
  2222. }
  2223. info->control.rates[0].idx = rate_idx;
  2224. }
  2225. static void *rs_alloc_sta(void *mvm_rate, struct ieee80211_sta *sta,
  2226. gfp_t gfp)
  2227. {
  2228. struct iwl_mvm_sta *sta_priv = (struct iwl_mvm_sta *)sta->drv_priv;
  2229. struct iwl_op_mode *op_mode __maybe_unused =
  2230. (struct iwl_op_mode *)mvm_rate;
  2231. struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode);
  2232. IWL_DEBUG_RATE(mvm, "create station rate scale window\n");
  2233. return &sta_priv->lq_sta;
  2234. }
  2235. /*
  2236. * Called after adding a new station to initialize rate scaling
  2237. */
  2238. void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
  2239. enum ieee80211_band band)
  2240. {
  2241. int i, j;
  2242. struct ieee80211_hw *hw = mvm->hw;
  2243. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  2244. struct iwl_mvm_sta *sta_priv;
  2245. struct iwl_lq_sta *lq_sta;
  2246. struct ieee80211_supported_band *sband;
  2247. unsigned long supp; /* must be unsigned long for for_each_set_bit */
  2248. sta_priv = (struct iwl_mvm_sta *)sta->drv_priv;
  2249. lq_sta = &sta_priv->lq_sta;
  2250. sband = hw->wiphy->bands[band];
  2251. lq_sta->lq.sta_id = sta_priv->sta_id;
  2252. for (j = 0; j < LQ_SIZE; j++)
  2253. for (i = 0; i < IWL_RATE_COUNT; i++)
  2254. rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
  2255. lq_sta->flush_timer = 0;
  2256. lq_sta->supp_rates = sta->supp_rates[sband->band];
  2257. for (j = 0; j < LQ_SIZE; j++)
  2258. for (i = 0; i < IWL_RATE_COUNT; i++)
  2259. rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
  2260. IWL_DEBUG_RATE(mvm,
  2261. "LQ: *** rate scale station global init for station %d ***\n",
  2262. sta_priv->sta_id);
  2263. /* TODO: what is a good starting rate for STA? About middle? Maybe not
  2264. * the lowest or the highest rate.. Could consider using RSSI from
  2265. * previous packets? Need to have IEEE 802.1X auth succeed immediately
  2266. * after assoc.. */
  2267. lq_sta->max_rate_idx = -1;
  2268. lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX;
  2269. lq_sta->is_green = rs_use_green(sta);
  2270. lq_sta->band = sband->band;
  2271. /*
  2272. * active legacy rates as per supported rates bitmap
  2273. */
  2274. supp = sta->supp_rates[sband->band];
  2275. lq_sta->active_legacy_rate = 0;
  2276. for_each_set_bit(i, &supp, BITS_PER_LONG)
  2277. lq_sta->active_legacy_rate |= BIT(sband->bitrates[i].hw_value);
  2278. /*
  2279. * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
  2280. * supp_rates[] does not; shift to convert format, force 9 MBits off.
  2281. */
  2282. lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1;
  2283. lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1;
  2284. lq_sta->active_siso_rate &= ~((u16)0x2);
  2285. lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE;
  2286. /* Same here */
  2287. lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1;
  2288. lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1;
  2289. lq_sta->active_mimo2_rate &= ~((u16)0x2);
  2290. lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE;
  2291. lq_sta->active_mimo3_rate = ht_cap->mcs.rx_mask[2] << 1;
  2292. lq_sta->active_mimo3_rate |= ht_cap->mcs.rx_mask[2] & 0x1;
  2293. lq_sta->active_mimo3_rate &= ~((u16)0x2);
  2294. lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE;
  2295. IWL_DEBUG_RATE(mvm,
  2296. "SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n",
  2297. lq_sta->active_siso_rate,
  2298. lq_sta->active_mimo2_rate,
  2299. lq_sta->active_mimo3_rate);
  2300. /* These values will be overridden later */
  2301. lq_sta->lq.single_stream_ant_msk =
  2302. first_antenna(mvm->nvm_data->valid_tx_ant);
  2303. lq_sta->lq.dual_stream_ant_msk =
  2304. mvm->nvm_data->valid_tx_ant &
  2305. ~first_antenna(mvm->nvm_data->valid_tx_ant);
  2306. if (!lq_sta->lq.dual_stream_ant_msk) {
  2307. lq_sta->lq.dual_stream_ant_msk = ANT_AB;
  2308. } else if (num_of_ant(mvm->nvm_data->valid_tx_ant) == 2) {
  2309. lq_sta->lq.dual_stream_ant_msk =
  2310. mvm->nvm_data->valid_tx_ant;
  2311. }
  2312. /* as default allow aggregation for all tids */
  2313. lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
  2314. lq_sta->drv = mvm;
  2315. /* Set last_txrate_idx to lowest rate */
  2316. lq_sta->last_txrate_idx = rate_lowest_index(sband, sta);
  2317. if (sband->band == IEEE80211_BAND_5GHZ)
  2318. lq_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
  2319. lq_sta->is_agg = 0;
  2320. #ifdef CONFIG_MAC80211_DEBUGFS
  2321. lq_sta->dbg_fixed_rate = 0;
  2322. #endif
  2323. rs_initialize_lq(mvm, sta, lq_sta, band);
  2324. }
  2325. static void rs_fill_link_cmd(struct iwl_mvm *mvm,
  2326. struct iwl_lq_sta *lq_sta, u32 new_rate)
  2327. {
  2328. struct iwl_scale_tbl_info tbl_type;
  2329. int index = 0;
  2330. int rate_idx;
  2331. int repeat_rate = 0;
  2332. u8 ant_toggle_cnt = 0;
  2333. u8 use_ht_possible = 1;
  2334. u8 valid_tx_ant = 0;
  2335. struct iwl_lq_cmd *lq_cmd = &lq_sta->lq;
  2336. /* Override starting rate (index 0) if needed for debug purposes */
  2337. rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
  2338. /* Interpret new_rate (rate_n_flags) */
  2339. rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
  2340. &tbl_type, &rate_idx);
  2341. /* How many times should we repeat the initial rate? */
  2342. if (is_legacy(tbl_type.lq_type)) {
  2343. ant_toggle_cnt = 1;
  2344. repeat_rate = IWL_NUMBER_TRY;
  2345. } else {
  2346. repeat_rate = min(IWL_HT_NUMBER_TRY,
  2347. LINK_QUAL_AGG_DISABLE_START_DEF - 1);
  2348. }
  2349. lq_cmd->mimo_delim = is_mimo(tbl_type.lq_type) ? 1 : 0;
  2350. /* Fill 1st table entry (index 0) */
  2351. lq_cmd->rs_table[index] = cpu_to_le32(new_rate);
  2352. if (num_of_ant(tbl_type.ant_type) == 1)
  2353. lq_cmd->single_stream_ant_msk = tbl_type.ant_type;
  2354. else if (num_of_ant(tbl_type.ant_type) == 2)
  2355. lq_cmd->dual_stream_ant_msk = tbl_type.ant_type;
  2356. /* otherwise we don't modify the existing value */
  2357. index++;
  2358. repeat_rate--;
  2359. if (mvm)
  2360. valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  2361. /* Fill rest of rate table */
  2362. while (index < LINK_QUAL_MAX_RETRY_NUM) {
  2363. /* Repeat initial/next rate.
  2364. * For legacy IWL_NUMBER_TRY == 1, this loop will not execute.
  2365. * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
  2366. while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
  2367. if (is_legacy(tbl_type.lq_type)) {
  2368. if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
  2369. ant_toggle_cnt++;
  2370. else if (mvm &&
  2371. rs_toggle_antenna(valid_tx_ant,
  2372. &new_rate, &tbl_type))
  2373. ant_toggle_cnt = 1;
  2374. }
  2375. /* Override next rate if needed for debug purposes */
  2376. rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
  2377. /* Fill next table entry */
  2378. lq_cmd->rs_table[index] =
  2379. cpu_to_le32(new_rate);
  2380. repeat_rate--;
  2381. index++;
  2382. }
  2383. rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type,
  2384. &rate_idx);
  2385. /* Indicate to uCode which entries might be MIMO.
  2386. * If initial rate was MIMO, this will finally end up
  2387. * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
  2388. if (is_mimo(tbl_type.lq_type))
  2389. lq_cmd->mimo_delim = index;
  2390. /* Get next rate */
  2391. new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
  2392. use_ht_possible);
  2393. /* How many times should we repeat the next rate? */
  2394. if (is_legacy(tbl_type.lq_type)) {
  2395. if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
  2396. ant_toggle_cnt++;
  2397. else if (mvm &&
  2398. rs_toggle_antenna(valid_tx_ant,
  2399. &new_rate, &tbl_type))
  2400. ant_toggle_cnt = 1;
  2401. repeat_rate = IWL_NUMBER_TRY;
  2402. } else {
  2403. repeat_rate = IWL_HT_NUMBER_TRY;
  2404. }
  2405. /* Don't allow HT rates after next pass.
  2406. * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
  2407. use_ht_possible = 0;
  2408. /* Override next rate if needed for debug purposes */
  2409. rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
  2410. /* Fill next table entry */
  2411. lq_cmd->rs_table[index] = cpu_to_le32(new_rate);
  2412. index++;
  2413. repeat_rate--;
  2414. }
  2415. lq_cmd->agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  2416. lq_cmd->agg_disable_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  2417. lq_cmd->agg_time_limit =
  2418. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  2419. }
  2420. static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
  2421. {
  2422. return hw->priv;
  2423. }
  2424. /* rate scale requires free function to be implemented */
  2425. static void rs_free(void *mvm_rate)
  2426. {
  2427. return;
  2428. }
  2429. static void rs_free_sta(void *mvm_r, struct ieee80211_sta *sta,
  2430. void *mvm_sta)
  2431. {
  2432. struct iwl_op_mode *op_mode __maybe_unused = mvm_r;
  2433. struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode);
  2434. IWL_DEBUG_RATE(mvm, "enter\n");
  2435. IWL_DEBUG_RATE(mvm, "leave\n");
  2436. }
  2437. #ifdef CONFIG_MAC80211_DEBUGFS
  2438. static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
  2439. u32 *rate_n_flags, int index)
  2440. {
  2441. struct iwl_mvm *mvm;
  2442. u8 valid_tx_ant;
  2443. u8 ant_sel_tx;
  2444. mvm = lq_sta->drv;
  2445. valid_tx_ant = mvm->nvm_data->valid_tx_ant;
  2446. if (lq_sta->dbg_fixed_rate) {
  2447. ant_sel_tx =
  2448. ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK)
  2449. >> RATE_MCS_ANT_POS);
  2450. if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) {
  2451. *rate_n_flags = lq_sta->dbg_fixed_rate;
  2452. IWL_DEBUG_RATE(mvm, "Fixed rate ON\n");
  2453. } else {
  2454. lq_sta->dbg_fixed_rate = 0;
  2455. IWL_ERR(mvm,
  2456. "Invalid antenna selection 0x%X, Valid is 0x%X\n",
  2457. ant_sel_tx, valid_tx_ant);
  2458. IWL_DEBUG_RATE(mvm, "Fixed rate OFF\n");
  2459. }
  2460. } else {
  2461. IWL_DEBUG_RATE(mvm, "Fixed rate OFF\n");
  2462. }
  2463. }
  2464. static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
  2465. const char __user *user_buf, size_t count, loff_t *ppos)
  2466. {
  2467. struct iwl_lq_sta *lq_sta = file->private_data;
  2468. struct iwl_mvm *mvm;
  2469. char buf[64];
  2470. size_t buf_size;
  2471. u32 parsed_rate;
  2472. mvm = lq_sta->drv;
  2473. memset(buf, 0, sizeof(buf));
  2474. buf_size = min(count, sizeof(buf) - 1);
  2475. if (copy_from_user(buf, user_buf, buf_size))
  2476. return -EFAULT;
  2477. if (sscanf(buf, "%x", &parsed_rate) == 1)
  2478. lq_sta->dbg_fixed_rate = parsed_rate;
  2479. else
  2480. lq_sta->dbg_fixed_rate = 0;
  2481. rs_program_fix_rate(mvm, lq_sta);
  2482. return count;
  2483. }
  2484. static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
  2485. char __user *user_buf, size_t count, loff_t *ppos)
  2486. {
  2487. char *buff;
  2488. int desc = 0;
  2489. int i = 0;
  2490. int index = 0;
  2491. ssize_t ret;
  2492. struct iwl_lq_sta *lq_sta = file->private_data;
  2493. struct iwl_mvm *mvm;
  2494. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  2495. mvm = lq_sta->drv;
  2496. buff = kmalloc(1024, GFP_KERNEL);
  2497. if (!buff)
  2498. return -ENOMEM;
  2499. desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
  2500. desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
  2501. lq_sta->total_failed, lq_sta->total_success,
  2502. lq_sta->active_legacy_rate);
  2503. desc += sprintf(buff+desc, "fixed rate 0x%X\n",
  2504. lq_sta->dbg_fixed_rate);
  2505. desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n",
  2506. (mvm->nvm_data->valid_tx_ant & ANT_A) ? "ANT_A," : "",
  2507. (mvm->nvm_data->valid_tx_ant & ANT_B) ? "ANT_B," : "",
  2508. (mvm->nvm_data->valid_tx_ant & ANT_C) ? "ANT_C" : "");
  2509. desc += sprintf(buff+desc, "lq type %s\n",
  2510. (is_legacy(tbl->lq_type)) ? "legacy" : "HT");
  2511. if (is_Ht(tbl->lq_type)) {
  2512. desc += sprintf(buff+desc, " %s",
  2513. (is_siso(tbl->lq_type)) ? "SISO" :
  2514. ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3"));
  2515. desc += sprintf(buff+desc, " %s",
  2516. (tbl->is_ht40) ? "40MHz" : "20MHz");
  2517. desc += sprintf(buff+desc, " %s %s %s\n",
  2518. (tbl->is_SGI) ? "SGI" : "",
  2519. (lq_sta->is_green) ? "GF enabled" : "",
  2520. (lq_sta->is_agg) ? "AGG on" : "");
  2521. }
  2522. desc += sprintf(buff+desc, "last tx rate=0x%X\n",
  2523. lq_sta->last_rate_n_flags);
  2524. desc += sprintf(buff+desc,
  2525. "general: flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
  2526. lq_sta->lq.flags,
  2527. lq_sta->lq.mimo_delim,
  2528. lq_sta->lq.single_stream_ant_msk,
  2529. lq_sta->lq.dual_stream_ant_msk);
  2530. desc += sprintf(buff+desc,
  2531. "agg: time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
  2532. le16_to_cpu(lq_sta->lq.agg_time_limit),
  2533. lq_sta->lq.agg_disable_start_th,
  2534. lq_sta->lq.agg_frame_cnt_limit);
  2535. desc += sprintf(buff+desc,
  2536. "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
  2537. lq_sta->lq.initial_rate_index[0],
  2538. lq_sta->lq.initial_rate_index[1],
  2539. lq_sta->lq.initial_rate_index[2],
  2540. lq_sta->lq.initial_rate_index[3]);
  2541. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  2542. index = iwl_hwrate_to_plcp_idx(
  2543. le32_to_cpu(lq_sta->lq.rs_table[i]));
  2544. if (is_legacy(tbl->lq_type)) {
  2545. desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
  2546. i, le32_to_cpu(lq_sta->lq.rs_table[i]),
  2547. iwl_rate_mcs[index].mbps);
  2548. } else {
  2549. desc += sprintf(buff+desc,
  2550. " rate[%d] 0x%X %smbps (%s)\n",
  2551. i, le32_to_cpu(lq_sta->lq.rs_table[i]),
  2552. iwl_rate_mcs[index].mbps,
  2553. iwl_rate_mcs[index].mcs);
  2554. }
  2555. }
  2556. ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  2557. kfree(buff);
  2558. return ret;
  2559. }
  2560. static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
  2561. .write = rs_sta_dbgfs_scale_table_write,
  2562. .read = rs_sta_dbgfs_scale_table_read,
  2563. .open = simple_open,
  2564. .llseek = default_llseek,
  2565. };
  2566. static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
  2567. char __user *user_buf, size_t count, loff_t *ppos)
  2568. {
  2569. char *buff;
  2570. int desc = 0;
  2571. int i, j;
  2572. ssize_t ret;
  2573. struct iwl_lq_sta *lq_sta = file->private_data;
  2574. buff = kmalloc(1024, GFP_KERNEL);
  2575. if (!buff)
  2576. return -ENOMEM;
  2577. for (i = 0; i < LQ_SIZE; i++) {
  2578. desc += sprintf(buff+desc,
  2579. "%s type=%d SGI=%d HT40=%d DUP=0 GF=%d\n"
  2580. "rate=0x%X\n",
  2581. lq_sta->active_tbl == i ? "*" : "x",
  2582. lq_sta->lq_info[i].lq_type,
  2583. lq_sta->lq_info[i].is_SGI,
  2584. lq_sta->lq_info[i].is_ht40,
  2585. lq_sta->is_green,
  2586. lq_sta->lq_info[i].current_rate);
  2587. for (j = 0; j < IWL_RATE_COUNT; j++) {
  2588. desc += sprintf(buff+desc,
  2589. "counter=%d success=%d %%=%d\n",
  2590. lq_sta->lq_info[i].win[j].counter,
  2591. lq_sta->lq_info[i].win[j].success_counter,
  2592. lq_sta->lq_info[i].win[j].success_ratio);
  2593. }
  2594. }
  2595. ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  2596. kfree(buff);
  2597. return ret;
  2598. }
  2599. static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
  2600. .read = rs_sta_dbgfs_stats_table_read,
  2601. .open = simple_open,
  2602. .llseek = default_llseek,
  2603. };
  2604. static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file,
  2605. char __user *user_buf, size_t count, loff_t *ppos)
  2606. {
  2607. struct iwl_lq_sta *lq_sta = file->private_data;
  2608. struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
  2609. char buff[120];
  2610. int desc = 0;
  2611. if (is_Ht(tbl->lq_type))
  2612. desc += sprintf(buff+desc,
  2613. "Bit Rate= %d Mb/s\n",
  2614. tbl->expected_tpt[lq_sta->last_txrate_idx]);
  2615. else
  2616. desc += sprintf(buff+desc,
  2617. "Bit Rate= %d Mb/s\n",
  2618. iwl_rates[lq_sta->last_txrate_idx].ieee >> 1);
  2619. return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  2620. }
  2621. static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
  2622. .read = rs_sta_dbgfs_rate_scale_data_read,
  2623. .open = simple_open,
  2624. .llseek = default_llseek,
  2625. };
  2626. static void rs_add_debugfs(void *mvm, void *mvm_sta, struct dentry *dir)
  2627. {
  2628. struct iwl_lq_sta *lq_sta = mvm_sta;
  2629. lq_sta->rs_sta_dbgfs_scale_table_file =
  2630. debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir,
  2631. lq_sta, &rs_sta_dbgfs_scale_table_ops);
  2632. lq_sta->rs_sta_dbgfs_stats_table_file =
  2633. debugfs_create_file("rate_stats_table", S_IRUSR, dir,
  2634. lq_sta, &rs_sta_dbgfs_stats_table_ops);
  2635. lq_sta->rs_sta_dbgfs_rate_scale_data_file =
  2636. debugfs_create_file("rate_scale_data", S_IRUSR, dir,
  2637. lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
  2638. lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
  2639. debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir,
  2640. &lq_sta->tx_agg_tid_en);
  2641. }
  2642. static void rs_remove_debugfs(void *mvm, void *mvm_sta)
  2643. {
  2644. struct iwl_lq_sta *lq_sta = mvm_sta;
  2645. debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
  2646. debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
  2647. debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
  2648. debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
  2649. }
  2650. #endif
  2651. /*
  2652. * Initialization of rate scaling information is done by driver after
  2653. * the station is added. Since mac80211 calls this function before a
  2654. * station is added we ignore it.
  2655. */
  2656. static void rs_rate_init_stub(void *mvm_r,
  2657. struct ieee80211_supported_band *sband,
  2658. struct ieee80211_sta *sta, void *mvm_sta)
  2659. {
  2660. }
  2661. static struct rate_control_ops rs_mvm_ops = {
  2662. .module = NULL,
  2663. .name = RS_NAME,
  2664. .tx_status = rs_tx_status,
  2665. .get_rate = rs_get_rate,
  2666. .rate_init = rs_rate_init_stub,
  2667. .alloc = rs_alloc,
  2668. .free = rs_free,
  2669. .alloc_sta = rs_alloc_sta,
  2670. .free_sta = rs_free_sta,
  2671. #ifdef CONFIG_MAC80211_DEBUGFS
  2672. .add_sta_debugfs = rs_add_debugfs,
  2673. .remove_sta_debugfs = rs_remove_debugfs,
  2674. #endif
  2675. };
  2676. int iwl_mvm_rate_control_register(void)
  2677. {
  2678. return ieee80211_rate_control_register(&rs_mvm_ops);
  2679. }
  2680. void iwl_mvm_rate_control_unregister(void)
  2681. {
  2682. ieee80211_rate_control_unregister(&rs_mvm_ops);
  2683. }