rs.c 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082
  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. /*
  586. * There's a bug somewhere in this code that causes the
  587. * scaling to get stuck because GF+SGI can't be combined
  588. * in SISO rates. Until we find that bug, disable GF, it
  589. * has only limited benefit and we still interoperate with
  590. * GF APs since we can always receive GF transmissions.
  591. */
  592. return false;
  593. }
  594. /**
  595. * rs_get_supported_rates - get the available rates
  596. *
  597. * if management frame or broadcast frame only return
  598. * basic available rates.
  599. *
  600. */
  601. static u16 rs_get_supported_rates(struct iwl_lq_sta *lq_sta,
  602. struct ieee80211_hdr *hdr,
  603. enum iwl_table_type rate_type)
  604. {
  605. if (is_legacy(rate_type)) {
  606. return lq_sta->active_legacy_rate;
  607. } else {
  608. if (is_siso(rate_type))
  609. return lq_sta->active_siso_rate;
  610. else if (is_mimo2(rate_type))
  611. return lq_sta->active_mimo2_rate;
  612. else
  613. return lq_sta->active_mimo3_rate;
  614. }
  615. }
  616. static u16 rs_get_adjacent_rate(struct iwl_mvm *mvm, u8 index, u16 rate_mask,
  617. int rate_type)
  618. {
  619. u8 high = IWL_RATE_INVALID;
  620. u8 low = IWL_RATE_INVALID;
  621. /* 802.11A or ht walks to the next literal adjacent rate in
  622. * the rate table */
  623. if (is_a_band(rate_type) || !is_legacy(rate_type)) {
  624. int i;
  625. u32 mask;
  626. /* Find the previous rate that is in the rate mask */
  627. i = index - 1;
  628. for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
  629. if (rate_mask & mask) {
  630. low = i;
  631. break;
  632. }
  633. }
  634. /* Find the next rate that is in the rate mask */
  635. i = index + 1;
  636. for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
  637. if (rate_mask & mask) {
  638. high = i;
  639. break;
  640. }
  641. }
  642. return (high << 8) | low;
  643. }
  644. low = index;
  645. while (low != IWL_RATE_INVALID) {
  646. low = iwl_rates[low].prev_rs;
  647. if (low == IWL_RATE_INVALID)
  648. break;
  649. if (rate_mask & (1 << low))
  650. break;
  651. IWL_DEBUG_RATE(mvm, "Skipping masked lower rate: %d\n", low);
  652. }
  653. high = index;
  654. while (high != IWL_RATE_INVALID) {
  655. high = iwl_rates[high].next_rs;
  656. if (high == IWL_RATE_INVALID)
  657. break;
  658. if (rate_mask & (1 << high))
  659. break;
  660. IWL_DEBUG_RATE(mvm, "Skipping masked higher rate: %d\n", high);
  661. }
  662. return (high << 8) | low;
  663. }
  664. static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
  665. struct iwl_scale_tbl_info *tbl,
  666. u8 scale_index, u8 ht_possible)
  667. {
  668. s32 low;
  669. u16 rate_mask;
  670. u16 high_low;
  671. u8 switch_to_legacy = 0;
  672. u8 is_green = lq_sta->is_green;
  673. struct iwl_mvm *mvm = lq_sta->drv;
  674. /* check if we need to switch from HT to legacy rates.
  675. * assumption is that mandatory rates (1Mbps or 6Mbps)
  676. * are always supported (spec demand) */
  677. if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
  678. switch_to_legacy = 1;
  679. scale_index = rs_ht_to_legacy[scale_index];
  680. if (lq_sta->band == IEEE80211_BAND_5GHZ)
  681. tbl->lq_type = LQ_A;
  682. else
  683. tbl->lq_type = LQ_G;
  684. if (num_of_ant(tbl->ant_type) > 1)
  685. tbl->ant_type =
  686. first_antenna(iwl_fw_valid_tx_ant(mvm->fw));
  687. tbl->is_ht40 = 0;
  688. tbl->is_SGI = 0;
  689. tbl->max_search = IWL_MAX_SEARCH;
  690. }
  691. rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
  692. /* Mask with station rate restriction */
  693. if (is_legacy(tbl->lq_type)) {
  694. /* supp_rates has no CCK bits in A mode */
  695. if (lq_sta->band == IEEE80211_BAND_5GHZ)
  696. rate_mask = (u16)(rate_mask &
  697. (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
  698. else
  699. rate_mask = (u16)(rate_mask & lq_sta->supp_rates);
  700. }
  701. /* If we switched from HT to legacy, check current rate */
  702. if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
  703. low = scale_index;
  704. goto out;
  705. }
  706. high_low = rs_get_adjacent_rate(lq_sta->drv, scale_index, rate_mask,
  707. tbl->lq_type);
  708. low = high_low & 0xff;
  709. if (low == IWL_RATE_INVALID)
  710. low = scale_index;
  711. out:
  712. return rate_n_flags_from_tbl(lq_sta->drv, tbl, low, is_green);
  713. }
  714. /*
  715. * Simple function to compare two rate scale table types
  716. */
  717. static bool table_type_matches(struct iwl_scale_tbl_info *a,
  718. struct iwl_scale_tbl_info *b)
  719. {
  720. return (a->lq_type == b->lq_type) && (a->ant_type == b->ant_type) &&
  721. (a->is_SGI == b->is_SGI);
  722. }
  723. /*
  724. * mac80211 sends us Tx status
  725. */
  726. static void rs_tx_status(void *mvm_r, struct ieee80211_supported_band *sband,
  727. struct ieee80211_sta *sta, void *priv_sta,
  728. struct sk_buff *skb)
  729. {
  730. int legacy_success;
  731. int retries;
  732. int rs_index, mac_index, i;
  733. struct iwl_lq_sta *lq_sta = priv_sta;
  734. struct iwl_lq_cmd *table;
  735. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  736. struct iwl_op_mode *op_mode = (struct iwl_op_mode *)mvm_r;
  737. struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
  738. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  739. enum mac80211_rate_control_flags mac_flags;
  740. u32 tx_rate;
  741. struct iwl_scale_tbl_info tbl_type;
  742. struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl;
  743. IWL_DEBUG_RATE_LIMIT(mvm,
  744. "get frame ack response, update rate scale window\n");
  745. /* Treat uninitialized rate scaling data same as non-existing. */
  746. if (!lq_sta) {
  747. IWL_DEBUG_RATE(mvm, "Station rate scaling not created yet.\n");
  748. return;
  749. } else if (!lq_sta->drv) {
  750. IWL_DEBUG_RATE(mvm, "Rate scaling not initialized yet.\n");
  751. return;
  752. }
  753. if (!ieee80211_is_data(hdr->frame_control) ||
  754. info->flags & IEEE80211_TX_CTL_NO_ACK)
  755. return;
  756. /* This packet was aggregated but doesn't carry status info */
  757. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  758. !(info->flags & IEEE80211_TX_STAT_AMPDU))
  759. return;
  760. /*
  761. * Ignore this Tx frame response if its initial rate doesn't match
  762. * that of latest Link Quality command. There may be stragglers
  763. * from a previous Link Quality command, but we're no longer interested
  764. * in those; they're either from the "active" mode while we're trying
  765. * to check "search" mode, or a prior "search" mode after we've moved
  766. * to a new "search" mode (which might become the new "active" mode).
  767. */
  768. table = &lq_sta->lq;
  769. tx_rate = le32_to_cpu(table->rs_table[0]);
  770. rs_get_tbl_info_from_mcs(tx_rate, info->band, &tbl_type, &rs_index);
  771. if (info->band == IEEE80211_BAND_5GHZ)
  772. rs_index -= IWL_FIRST_OFDM_RATE;
  773. mac_flags = info->status.rates[0].flags;
  774. mac_index = info->status.rates[0].idx;
  775. /* For HT packets, map MCS to PLCP */
  776. if (mac_flags & IEEE80211_TX_RC_MCS) {
  777. /* Remove # of streams */
  778. mac_index &= RATE_HT_MCS_RATE_CODE_MSK;
  779. if (mac_index >= (IWL_RATE_9M_INDEX - IWL_FIRST_OFDM_RATE))
  780. mac_index++;
  781. /*
  782. * mac80211 HT index is always zero-indexed; we need to move
  783. * HT OFDM rates after CCK rates in 2.4 GHz band
  784. */
  785. if (info->band == IEEE80211_BAND_2GHZ)
  786. mac_index += IWL_FIRST_OFDM_RATE;
  787. }
  788. /* Here we actually compare this rate to the latest LQ command */
  789. if ((mac_index < 0) ||
  790. (tbl_type.is_SGI != !!(mac_flags & IEEE80211_TX_RC_SHORT_GI)) ||
  791. (tbl_type.is_ht40 != !!(mac_flags & IEEE80211_TX_RC_40_MHZ_WIDTH)) ||
  792. (tbl_type.ant_type != info->status.antenna) ||
  793. (!!(tx_rate & RATE_MCS_HT_MSK) !=
  794. !!(mac_flags & IEEE80211_TX_RC_MCS)) ||
  795. (!!(tx_rate & RATE_HT_MCS_GF_MSK) !=
  796. !!(mac_flags & IEEE80211_TX_RC_GREEN_FIELD)) ||
  797. (rs_index != mac_index)) {
  798. IWL_DEBUG_RATE(mvm,
  799. "initial rate %d does not match %d (0x%x)\n",
  800. mac_index, rs_index, tx_rate);
  801. /*
  802. * Since rates mis-match, the last LQ command may have failed.
  803. * After IWL_MISSED_RATE_MAX mis-matches, resync the uCode with
  804. * ... driver.
  805. */
  806. lq_sta->missed_rate_counter++;
  807. if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) {
  808. lq_sta->missed_rate_counter = 0;
  809. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_ASYNC, false);
  810. }
  811. /* Regardless, ignore this status info for outdated rate */
  812. return;
  813. } else
  814. /* Rate did match, so reset the missed_rate_counter */
  815. lq_sta->missed_rate_counter = 0;
  816. /* Figure out if rate scale algorithm is in active or search table */
  817. if (table_type_matches(&tbl_type,
  818. &(lq_sta->lq_info[lq_sta->active_tbl]))) {
  819. curr_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  820. other_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
  821. } else if (table_type_matches(
  822. &tbl_type, &lq_sta->lq_info[1 - lq_sta->active_tbl])) {
  823. curr_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
  824. other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  825. } else {
  826. IWL_DEBUG_RATE(mvm,
  827. "Neither active nor search matches tx rate\n");
  828. tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  829. IWL_DEBUG_RATE(mvm, "active- lq:%x, ant:%x, SGI:%d\n",
  830. tmp_tbl->lq_type, tmp_tbl->ant_type,
  831. tmp_tbl->is_SGI);
  832. tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
  833. IWL_DEBUG_RATE(mvm, "search- lq:%x, ant:%x, SGI:%d\n",
  834. tmp_tbl->lq_type, tmp_tbl->ant_type,
  835. tmp_tbl->is_SGI);
  836. IWL_DEBUG_RATE(mvm, "actual- lq:%x, ant:%x, SGI:%d\n",
  837. tbl_type.lq_type, tbl_type.ant_type,
  838. tbl_type.is_SGI);
  839. /*
  840. * no matching table found, let's by-pass the data collection
  841. * and continue to perform rate scale to find the rate table
  842. */
  843. rs_stay_in_table(lq_sta, true);
  844. goto done;
  845. }
  846. /*
  847. * Updating the frame history depends on whether packets were
  848. * aggregated.
  849. *
  850. * For aggregation, all packets were transmitted at the same rate, the
  851. * first index into rate scale table.
  852. */
  853. if (info->flags & IEEE80211_TX_STAT_AMPDU) {
  854. tx_rate = le32_to_cpu(table->rs_table[0]);
  855. rs_get_tbl_info_from_mcs(tx_rate, info->band, &tbl_type,
  856. &rs_index);
  857. rs_collect_tx_data(curr_tbl, rs_index,
  858. info->status.ampdu_len,
  859. info->status.ampdu_ack_len);
  860. /* Update success/fail counts if not searching for new mode */
  861. if (lq_sta->stay_in_tbl) {
  862. lq_sta->total_success += info->status.ampdu_ack_len;
  863. lq_sta->total_failed += (info->status.ampdu_len -
  864. info->status.ampdu_ack_len);
  865. }
  866. } else {
  867. /*
  868. * For legacy, update frame history with for each Tx retry.
  869. */
  870. retries = info->status.rates[0].count - 1;
  871. /* HW doesn't send more than 15 retries */
  872. retries = min(retries, 15);
  873. /* The last transmission may have been successful */
  874. legacy_success = !!(info->flags & IEEE80211_TX_STAT_ACK);
  875. /* Collect data for each rate used during failed TX attempts */
  876. for (i = 0; i <= retries; ++i) {
  877. tx_rate = le32_to_cpu(table->rs_table[i]);
  878. rs_get_tbl_info_from_mcs(tx_rate, info->band,
  879. &tbl_type, &rs_index);
  880. /*
  881. * Only collect stats if retried rate is in the same RS
  882. * table as active/search.
  883. */
  884. if (table_type_matches(&tbl_type, curr_tbl))
  885. tmp_tbl = curr_tbl;
  886. else if (table_type_matches(&tbl_type, other_tbl))
  887. tmp_tbl = other_tbl;
  888. else
  889. continue;
  890. rs_collect_tx_data(tmp_tbl, rs_index, 1,
  891. i < retries ? 0 : legacy_success);
  892. }
  893. /* Update success/fail counts if not searching for new mode */
  894. if (lq_sta->stay_in_tbl) {
  895. lq_sta->total_success += legacy_success;
  896. lq_sta->total_failed += retries + (1 - legacy_success);
  897. }
  898. }
  899. /* The last TX rate is cached in lq_sta; it's set in if/else above */
  900. lq_sta->last_rate_n_flags = tx_rate;
  901. done:
  902. /* See if there's a better rate or modulation mode to try. */
  903. if (sta && sta->supp_rates[sband->band])
  904. rs_rate_scale_perform(mvm, skb, sta, lq_sta);
  905. }
  906. /*
  907. * Begin a period of staying with a selected modulation mode.
  908. * Set "stay_in_tbl" flag to prevent any mode switches.
  909. * Set frame tx success limits according to legacy vs. high-throughput,
  910. * and reset overall (spanning all rates) tx success history statistics.
  911. * These control how long we stay using same modulation mode before
  912. * searching for a new mode.
  913. */
  914. static void rs_set_stay_in_table(struct iwl_mvm *mvm, u8 is_legacy,
  915. struct iwl_lq_sta *lq_sta)
  916. {
  917. IWL_DEBUG_RATE(mvm, "we are staying in the same table\n");
  918. lq_sta->stay_in_tbl = 1; /* only place this gets set */
  919. if (is_legacy) {
  920. lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT;
  921. lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
  922. lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT;
  923. } else {
  924. lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
  925. lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
  926. lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
  927. }
  928. lq_sta->table_count = 0;
  929. lq_sta->total_failed = 0;
  930. lq_sta->total_success = 0;
  931. lq_sta->flush_timer = jiffies;
  932. lq_sta->action_counter = 0;
  933. }
  934. /*
  935. * Find correct throughput table for given mode of modulation
  936. */
  937. static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta,
  938. struct iwl_scale_tbl_info *tbl)
  939. {
  940. /* Used to choose among HT tables */
  941. s32 (*ht_tbl_pointer)[IWL_RATE_COUNT];
  942. /* Check for invalid LQ type */
  943. if (WARN_ON_ONCE(!is_legacy(tbl->lq_type) && !is_Ht(tbl->lq_type))) {
  944. tbl->expected_tpt = expected_tpt_legacy;
  945. return;
  946. }
  947. /* Legacy rates have only one table */
  948. if (is_legacy(tbl->lq_type)) {
  949. tbl->expected_tpt = expected_tpt_legacy;
  950. return;
  951. }
  952. /* Choose among many HT tables depending on number of streams
  953. * (SISO/MIMO2/MIMO3), channel width (20/40), SGI, and aggregation
  954. * status */
  955. if (is_siso(tbl->lq_type) && !tbl->is_ht40)
  956. ht_tbl_pointer = expected_tpt_siso20MHz;
  957. else if (is_siso(tbl->lq_type))
  958. ht_tbl_pointer = expected_tpt_siso40MHz;
  959. else if (is_mimo2(tbl->lq_type) && !tbl->is_ht40)
  960. ht_tbl_pointer = expected_tpt_mimo2_20MHz;
  961. else if (is_mimo2(tbl->lq_type))
  962. ht_tbl_pointer = expected_tpt_mimo2_40MHz;
  963. else if (is_mimo3(tbl->lq_type) && !tbl->is_ht40)
  964. ht_tbl_pointer = expected_tpt_mimo3_20MHz;
  965. else /* if (is_mimo3(tbl->lq_type)) <-- must be true */
  966. ht_tbl_pointer = expected_tpt_mimo3_40MHz;
  967. if (!tbl->is_SGI && !lq_sta->is_agg) /* Normal */
  968. tbl->expected_tpt = ht_tbl_pointer[0];
  969. else if (tbl->is_SGI && !lq_sta->is_agg) /* SGI */
  970. tbl->expected_tpt = ht_tbl_pointer[1];
  971. else if (!tbl->is_SGI && lq_sta->is_agg) /* AGG */
  972. tbl->expected_tpt = ht_tbl_pointer[2];
  973. else /* AGG+SGI */
  974. tbl->expected_tpt = ht_tbl_pointer[3];
  975. }
  976. /*
  977. * Find starting rate for new "search" high-throughput mode of modulation.
  978. * Goal is to find lowest expected rate (under perfect conditions) that is
  979. * above the current measured throughput of "active" mode, to give new mode
  980. * a fair chance to prove itself without too many challenges.
  981. *
  982. * This gets called when transitioning to more aggressive modulation
  983. * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive
  984. * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need
  985. * to decrease to match "active" throughput. When moving from MIMO to SISO,
  986. * bit rate will typically need to increase, but not if performance was bad.
  987. */
  988. static s32 rs_get_best_rate(struct iwl_mvm *mvm,
  989. struct iwl_lq_sta *lq_sta,
  990. struct iwl_scale_tbl_info *tbl, /* "search" */
  991. u16 rate_mask, s8 index)
  992. {
  993. /* "active" values */
  994. struct iwl_scale_tbl_info *active_tbl =
  995. &(lq_sta->lq_info[lq_sta->active_tbl]);
  996. s32 active_sr = active_tbl->win[index].success_ratio;
  997. s32 active_tpt = active_tbl->expected_tpt[index];
  998. /* expected "search" throughput */
  999. s32 *tpt_tbl = tbl->expected_tpt;
  1000. s32 new_rate, high, low, start_hi;
  1001. u16 high_low;
  1002. s8 rate = index;
  1003. new_rate = high = low = start_hi = IWL_RATE_INVALID;
  1004. while (1) {
  1005. high_low = rs_get_adjacent_rate(mvm, rate, rate_mask,
  1006. tbl->lq_type);
  1007. low = high_low & 0xff;
  1008. high = (high_low >> 8) & 0xff;
  1009. /*
  1010. * Lower the "search" bit rate, to give new "search" mode
  1011. * approximately the same throughput as "active" if:
  1012. *
  1013. * 1) "Active" mode has been working modestly well (but not
  1014. * great), and expected "search" throughput (under perfect
  1015. * conditions) at candidate rate is above the actual
  1016. * measured "active" throughput (but less than expected
  1017. * "active" throughput under perfect conditions).
  1018. * OR
  1019. * 2) "Active" mode has been working perfectly or very well
  1020. * and expected "search" throughput (under perfect
  1021. * conditions) at candidate rate is above expected
  1022. * "active" throughput (under perfect conditions).
  1023. */
  1024. if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) &&
  1025. ((active_sr > IWL_RATE_DECREASE_TH) &&
  1026. (active_sr <= IWL_RATE_HIGH_TH) &&
  1027. (tpt_tbl[rate] <= active_tpt))) ||
  1028. ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
  1029. (tpt_tbl[rate] > active_tpt))) {
  1030. /* (2nd or later pass)
  1031. * If we've already tried to raise the rate, and are
  1032. * now trying to lower it, use the higher rate. */
  1033. if (start_hi != IWL_RATE_INVALID) {
  1034. new_rate = start_hi;
  1035. break;
  1036. }
  1037. new_rate = rate;
  1038. /* Loop again with lower rate */
  1039. if (low != IWL_RATE_INVALID)
  1040. rate = low;
  1041. /* Lower rate not available, use the original */
  1042. else
  1043. break;
  1044. /* Else try to raise the "search" rate to match "active" */
  1045. } else {
  1046. /* (2nd or later pass)
  1047. * If we've already tried to lower the rate, and are
  1048. * now trying to raise it, use the lower rate. */
  1049. if (new_rate != IWL_RATE_INVALID)
  1050. break;
  1051. /* Loop again with higher rate */
  1052. else if (high != IWL_RATE_INVALID) {
  1053. start_hi = high;
  1054. rate = high;
  1055. /* Higher rate not available, use the original */
  1056. } else {
  1057. new_rate = rate;
  1058. break;
  1059. }
  1060. }
  1061. }
  1062. return new_rate;
  1063. }
  1064. static bool iwl_is_ht40_tx_allowed(struct ieee80211_sta *sta)
  1065. {
  1066. return sta->bandwidth >= IEEE80211_STA_RX_BW_40;
  1067. }
  1068. /*
  1069. * Set up search table for MIMO2
  1070. */
  1071. static int rs_switch_to_mimo2(struct iwl_mvm *mvm,
  1072. struct iwl_lq_sta *lq_sta,
  1073. struct ieee80211_sta *sta,
  1074. struct iwl_scale_tbl_info *tbl, int index)
  1075. {
  1076. u16 rate_mask;
  1077. s32 rate;
  1078. s8 is_green = lq_sta->is_green;
  1079. if (!sta->ht_cap.ht_supported)
  1080. return -1;
  1081. if (sta->smps_mode == IEEE80211_SMPS_STATIC)
  1082. return -1;
  1083. /* Need both Tx chains/antennas to support MIMO */
  1084. if (num_of_ant(iwl_fw_valid_tx_ant(mvm->fw)) < 2)
  1085. return -1;
  1086. IWL_DEBUG_RATE(mvm, "LQ: try to switch to MIMO2\n");
  1087. tbl->lq_type = LQ_MIMO2;
  1088. tbl->action = 0;
  1089. tbl->max_search = IWL_MAX_SEARCH;
  1090. rate_mask = lq_sta->active_mimo2_rate;
  1091. if (iwl_is_ht40_tx_allowed(sta))
  1092. tbl->is_ht40 = 1;
  1093. else
  1094. tbl->is_ht40 = 0;
  1095. rs_set_expected_tpt_table(lq_sta, tbl);
  1096. rate = rs_get_best_rate(mvm, lq_sta, tbl, rate_mask, index);
  1097. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 best rate %d mask %X\n",
  1098. rate, rate_mask);
  1099. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
  1100. IWL_DEBUG_RATE(mvm, "Can't switch with index %d rate mask %x\n",
  1101. rate, rate_mask);
  1102. return -1;
  1103. }
  1104. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, rate, is_green);
  1105. IWL_DEBUG_RATE(mvm, "LQ: Switch to new mcs %X index is green %X\n",
  1106. tbl->current_rate, is_green);
  1107. return 0;
  1108. }
  1109. /*
  1110. * Set up search table for MIMO3
  1111. */
  1112. static int rs_switch_to_mimo3(struct iwl_mvm *mvm,
  1113. struct iwl_lq_sta *lq_sta,
  1114. struct ieee80211_sta *sta,
  1115. struct iwl_scale_tbl_info *tbl, int index)
  1116. {
  1117. u16 rate_mask;
  1118. s32 rate;
  1119. s8 is_green = lq_sta->is_green;
  1120. if (!sta->ht_cap.ht_supported)
  1121. return -1;
  1122. if (sta->smps_mode == IEEE80211_SMPS_STATIC)
  1123. return -1;
  1124. /* Need both Tx chains/antennas to support MIMO */
  1125. if (num_of_ant(iwl_fw_valid_tx_ant(mvm->fw)) < 3)
  1126. return -1;
  1127. IWL_DEBUG_RATE(mvm, "LQ: try to switch to MIMO3\n");
  1128. tbl->lq_type = LQ_MIMO3;
  1129. tbl->action = 0;
  1130. tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
  1131. rate_mask = lq_sta->active_mimo3_rate;
  1132. if (iwl_is_ht40_tx_allowed(sta))
  1133. tbl->is_ht40 = 1;
  1134. else
  1135. tbl->is_ht40 = 0;
  1136. rs_set_expected_tpt_table(lq_sta, tbl);
  1137. rate = rs_get_best_rate(mvm, lq_sta, tbl, rate_mask, index);
  1138. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 best rate %d mask %X\n",
  1139. rate, rate_mask);
  1140. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
  1141. IWL_DEBUG_RATE(mvm, "Can't switch with index %d rate mask %x\n",
  1142. rate, rate_mask);
  1143. return -1;
  1144. }
  1145. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, rate, is_green);
  1146. IWL_DEBUG_RATE(mvm, "LQ: Switch to new mcs %X index is green %X\n",
  1147. tbl->current_rate, is_green);
  1148. return 0;
  1149. }
  1150. /*
  1151. * Set up search table for SISO
  1152. */
  1153. static int rs_switch_to_siso(struct iwl_mvm *mvm,
  1154. struct iwl_lq_sta *lq_sta,
  1155. struct ieee80211_sta *sta,
  1156. struct iwl_scale_tbl_info *tbl, int index)
  1157. {
  1158. u16 rate_mask;
  1159. u8 is_green = lq_sta->is_green;
  1160. s32 rate;
  1161. if (!sta->ht_cap.ht_supported)
  1162. return -1;
  1163. IWL_DEBUG_RATE(mvm, "LQ: try to switch to SISO\n");
  1164. tbl->lq_type = LQ_SISO;
  1165. tbl->action = 0;
  1166. tbl->max_search = IWL_MAX_SEARCH;
  1167. rate_mask = lq_sta->active_siso_rate;
  1168. if (iwl_is_ht40_tx_allowed(sta))
  1169. tbl->is_ht40 = 1;
  1170. else
  1171. tbl->is_ht40 = 0;
  1172. if (is_green)
  1173. tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/
  1174. rs_set_expected_tpt_table(lq_sta, tbl);
  1175. rate = rs_get_best_rate(mvm, lq_sta, tbl, rate_mask, index);
  1176. IWL_DEBUG_RATE(mvm, "LQ: get best rate %d mask %X\n", rate, rate_mask);
  1177. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
  1178. IWL_DEBUG_RATE(mvm,
  1179. "can not switch with index %d rate mask %x\n",
  1180. rate, rate_mask);
  1181. return -1;
  1182. }
  1183. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, rate, is_green);
  1184. IWL_DEBUG_RATE(mvm, "LQ: Switch to new mcs %X index is green %X\n",
  1185. tbl->current_rate, is_green);
  1186. return 0;
  1187. }
  1188. /*
  1189. * Try to switch to new modulation mode from legacy
  1190. */
  1191. static int rs_move_legacy_other(struct iwl_mvm *mvm,
  1192. struct iwl_lq_sta *lq_sta,
  1193. struct ieee80211_sta *sta,
  1194. int index)
  1195. {
  1196. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1197. struct iwl_scale_tbl_info *search_tbl =
  1198. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1199. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1200. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1201. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1202. u8 start_action;
  1203. u8 valid_tx_ant = iwl_fw_valid_tx_ant(mvm->fw);
  1204. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1205. int ret;
  1206. u8 update_search_tbl_counter = 0;
  1207. start_action = tbl->action;
  1208. while (1) {
  1209. lq_sta->action_counter++;
  1210. switch (tbl->action) {
  1211. case IWL_LEGACY_SWITCH_ANTENNA1:
  1212. case IWL_LEGACY_SWITCH_ANTENNA2:
  1213. IWL_DEBUG_RATE(mvm, "LQ: Legacy toggle Antenna\n");
  1214. if ((tbl->action == IWL_LEGACY_SWITCH_ANTENNA1 &&
  1215. tx_chains_num <= 1) ||
  1216. (tbl->action == IWL_LEGACY_SWITCH_ANTENNA2 &&
  1217. tx_chains_num <= 2))
  1218. break;
  1219. /* Don't change antenna if success has been great */
  1220. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1221. break;
  1222. /* Set up search table to try other antenna */
  1223. memcpy(search_tbl, tbl, sz);
  1224. if (rs_toggle_antenna(valid_tx_ant,
  1225. &search_tbl->current_rate,
  1226. search_tbl)) {
  1227. update_search_tbl_counter = 1;
  1228. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1229. goto out;
  1230. }
  1231. break;
  1232. case IWL_LEGACY_SWITCH_SISO:
  1233. IWL_DEBUG_RATE(mvm, "LQ: Legacy switch to SISO\n");
  1234. /* Set up search table to try SISO */
  1235. memcpy(search_tbl, tbl, sz);
  1236. search_tbl->is_SGI = 0;
  1237. ret = rs_switch_to_siso(mvm, lq_sta, sta,
  1238. search_tbl, index);
  1239. if (!ret) {
  1240. lq_sta->action_counter = 0;
  1241. goto out;
  1242. }
  1243. break;
  1244. case IWL_LEGACY_SWITCH_MIMO2_AB:
  1245. case IWL_LEGACY_SWITCH_MIMO2_AC:
  1246. case IWL_LEGACY_SWITCH_MIMO2_BC:
  1247. IWL_DEBUG_RATE(mvm, "LQ: Legacy switch to MIMO2\n");
  1248. /* Set up search table to try MIMO */
  1249. memcpy(search_tbl, tbl, sz);
  1250. search_tbl->is_SGI = 0;
  1251. if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AB)
  1252. search_tbl->ant_type = ANT_AB;
  1253. else if (tbl->action == IWL_LEGACY_SWITCH_MIMO2_AC)
  1254. search_tbl->ant_type = ANT_AC;
  1255. else
  1256. search_tbl->ant_type = ANT_BC;
  1257. if (!rs_is_valid_ant(valid_tx_ant,
  1258. search_tbl->ant_type))
  1259. break;
  1260. ret = rs_switch_to_mimo2(mvm, lq_sta, sta,
  1261. search_tbl, index);
  1262. if (!ret) {
  1263. lq_sta->action_counter = 0;
  1264. goto out;
  1265. }
  1266. break;
  1267. case IWL_LEGACY_SWITCH_MIMO3_ABC:
  1268. IWL_DEBUG_RATE(mvm, "LQ: Legacy switch to MIMO3\n");
  1269. /* Set up search table to try MIMO3 */
  1270. memcpy(search_tbl, tbl, sz);
  1271. search_tbl->is_SGI = 0;
  1272. search_tbl->ant_type = ANT_ABC;
  1273. if (!rs_is_valid_ant(valid_tx_ant,
  1274. search_tbl->ant_type))
  1275. break;
  1276. ret = rs_switch_to_mimo3(mvm, lq_sta, sta,
  1277. search_tbl, index);
  1278. if (!ret) {
  1279. lq_sta->action_counter = 0;
  1280. goto out;
  1281. }
  1282. break;
  1283. }
  1284. tbl->action++;
  1285. if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
  1286. tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
  1287. if (tbl->action == start_action)
  1288. break;
  1289. }
  1290. search_tbl->lq_type = LQ_NONE;
  1291. return 0;
  1292. out:
  1293. lq_sta->search_better_tbl = 1;
  1294. tbl->action++;
  1295. if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
  1296. tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
  1297. if (update_search_tbl_counter)
  1298. search_tbl->action = tbl->action;
  1299. return 0;
  1300. }
  1301. /*
  1302. * Try to switch to new modulation mode from SISO
  1303. */
  1304. static int rs_move_siso_to_other(struct iwl_mvm *mvm,
  1305. struct iwl_lq_sta *lq_sta,
  1306. struct ieee80211_sta *sta, int index)
  1307. {
  1308. u8 is_green = lq_sta->is_green;
  1309. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1310. struct iwl_scale_tbl_info *search_tbl =
  1311. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1312. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1313. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1314. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1315. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1316. u8 start_action;
  1317. u8 valid_tx_ant = iwl_fw_valid_tx_ant(mvm->fw);
  1318. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1319. u8 update_search_tbl_counter = 0;
  1320. int ret;
  1321. start_action = tbl->action;
  1322. while (1) {
  1323. lq_sta->action_counter++;
  1324. switch (tbl->action) {
  1325. case IWL_SISO_SWITCH_ANTENNA1:
  1326. case IWL_SISO_SWITCH_ANTENNA2:
  1327. IWL_DEBUG_RATE(mvm, "LQ: SISO toggle Antenna\n");
  1328. if ((tbl->action == IWL_SISO_SWITCH_ANTENNA1 &&
  1329. tx_chains_num <= 1) ||
  1330. (tbl->action == IWL_SISO_SWITCH_ANTENNA2 &&
  1331. tx_chains_num <= 2))
  1332. break;
  1333. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1334. break;
  1335. memcpy(search_tbl, tbl, sz);
  1336. if (rs_toggle_antenna(valid_tx_ant,
  1337. &search_tbl->current_rate,
  1338. search_tbl)) {
  1339. update_search_tbl_counter = 1;
  1340. goto out;
  1341. }
  1342. break;
  1343. case IWL_SISO_SWITCH_MIMO2_AB:
  1344. case IWL_SISO_SWITCH_MIMO2_AC:
  1345. case IWL_SISO_SWITCH_MIMO2_BC:
  1346. IWL_DEBUG_RATE(mvm, "LQ: SISO switch to MIMO2\n");
  1347. memcpy(search_tbl, tbl, sz);
  1348. search_tbl->is_SGI = 0;
  1349. if (tbl->action == IWL_SISO_SWITCH_MIMO2_AB)
  1350. search_tbl->ant_type = ANT_AB;
  1351. else if (tbl->action == IWL_SISO_SWITCH_MIMO2_AC)
  1352. search_tbl->ant_type = ANT_AC;
  1353. else
  1354. search_tbl->ant_type = ANT_BC;
  1355. if (!rs_is_valid_ant(valid_tx_ant,
  1356. search_tbl->ant_type))
  1357. break;
  1358. ret = rs_switch_to_mimo2(mvm, lq_sta, sta,
  1359. search_tbl, index);
  1360. if (!ret)
  1361. goto out;
  1362. break;
  1363. case IWL_SISO_SWITCH_GI:
  1364. if (!tbl->is_ht40 && !(ht_cap->cap &
  1365. IEEE80211_HT_CAP_SGI_20))
  1366. break;
  1367. if (tbl->is_ht40 && !(ht_cap->cap &
  1368. IEEE80211_HT_CAP_SGI_40))
  1369. break;
  1370. IWL_DEBUG_RATE(mvm, "LQ: SISO toggle SGI/NGI\n");
  1371. memcpy(search_tbl, tbl, sz);
  1372. if (is_green) {
  1373. if (!tbl->is_SGI)
  1374. break;
  1375. else
  1376. IWL_ERR(mvm,
  1377. "SGI was set in GF+SISO\n");
  1378. }
  1379. search_tbl->is_SGI = !tbl->is_SGI;
  1380. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1381. if (tbl->is_SGI) {
  1382. s32 tpt = lq_sta->last_tpt / 100;
  1383. if (tpt >= search_tbl->expected_tpt[index])
  1384. break;
  1385. }
  1386. search_tbl->current_rate =
  1387. rate_n_flags_from_tbl(mvm, search_tbl,
  1388. index, is_green);
  1389. update_search_tbl_counter = 1;
  1390. goto out;
  1391. case IWL_SISO_SWITCH_MIMO3_ABC:
  1392. IWL_DEBUG_RATE(mvm, "LQ: SISO switch to MIMO3\n");
  1393. memcpy(search_tbl, tbl, sz);
  1394. search_tbl->is_SGI = 0;
  1395. search_tbl->ant_type = ANT_ABC;
  1396. if (!rs_is_valid_ant(valid_tx_ant,
  1397. search_tbl->ant_type))
  1398. break;
  1399. ret = rs_switch_to_mimo3(mvm, lq_sta, sta,
  1400. search_tbl, index);
  1401. if (!ret)
  1402. goto out;
  1403. break;
  1404. }
  1405. tbl->action++;
  1406. if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
  1407. tbl->action = IWL_SISO_SWITCH_ANTENNA1;
  1408. if (tbl->action == start_action)
  1409. break;
  1410. }
  1411. search_tbl->lq_type = LQ_NONE;
  1412. return 0;
  1413. out:
  1414. lq_sta->search_better_tbl = 1;
  1415. tbl->action++;
  1416. if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC)
  1417. tbl->action = IWL_SISO_SWITCH_ANTENNA1;
  1418. if (update_search_tbl_counter)
  1419. search_tbl->action = tbl->action;
  1420. return 0;
  1421. }
  1422. /*
  1423. * Try to switch to new modulation mode from MIMO2
  1424. */
  1425. static int rs_move_mimo2_to_other(struct iwl_mvm *mvm,
  1426. struct iwl_lq_sta *lq_sta,
  1427. struct ieee80211_sta *sta, int index)
  1428. {
  1429. s8 is_green = lq_sta->is_green;
  1430. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1431. struct iwl_scale_tbl_info *search_tbl =
  1432. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1433. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1434. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1435. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1436. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1437. u8 start_action;
  1438. u8 valid_tx_ant = iwl_fw_valid_tx_ant(mvm->fw);
  1439. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1440. u8 update_search_tbl_counter = 0;
  1441. int ret;
  1442. start_action = tbl->action;
  1443. while (1) {
  1444. lq_sta->action_counter++;
  1445. switch (tbl->action) {
  1446. case IWL_MIMO2_SWITCH_ANTENNA1:
  1447. case IWL_MIMO2_SWITCH_ANTENNA2:
  1448. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 toggle Antennas\n");
  1449. if (tx_chains_num <= 2)
  1450. break;
  1451. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1452. break;
  1453. memcpy(search_tbl, tbl, sz);
  1454. if (rs_toggle_antenna(valid_tx_ant,
  1455. &search_tbl->current_rate,
  1456. search_tbl)) {
  1457. update_search_tbl_counter = 1;
  1458. goto out;
  1459. }
  1460. break;
  1461. case IWL_MIMO2_SWITCH_SISO_A:
  1462. case IWL_MIMO2_SWITCH_SISO_B:
  1463. case IWL_MIMO2_SWITCH_SISO_C:
  1464. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 switch to SISO\n");
  1465. /* Set up new search table for SISO */
  1466. memcpy(search_tbl, tbl, sz);
  1467. if (tbl->action == IWL_MIMO2_SWITCH_SISO_A)
  1468. search_tbl->ant_type = ANT_A;
  1469. else if (tbl->action == IWL_MIMO2_SWITCH_SISO_B)
  1470. search_tbl->ant_type = ANT_B;
  1471. else
  1472. search_tbl->ant_type = ANT_C;
  1473. if (!rs_is_valid_ant(valid_tx_ant,
  1474. search_tbl->ant_type))
  1475. break;
  1476. ret = rs_switch_to_siso(mvm, lq_sta, sta,
  1477. search_tbl, index);
  1478. if (!ret)
  1479. goto out;
  1480. break;
  1481. case IWL_MIMO2_SWITCH_GI:
  1482. if (!tbl->is_ht40 && !(ht_cap->cap &
  1483. IEEE80211_HT_CAP_SGI_20))
  1484. break;
  1485. if (tbl->is_ht40 && !(ht_cap->cap &
  1486. IEEE80211_HT_CAP_SGI_40))
  1487. break;
  1488. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 toggle SGI/NGI\n");
  1489. /* Set up new search table for MIMO2 */
  1490. memcpy(search_tbl, tbl, sz);
  1491. search_tbl->is_SGI = !tbl->is_SGI;
  1492. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1493. /*
  1494. * If active table already uses the fastest possible
  1495. * modulation (dual stream with short guard interval),
  1496. * and it's working well, there's no need to look
  1497. * for a better type of modulation!
  1498. */
  1499. if (tbl->is_SGI) {
  1500. s32 tpt = lq_sta->last_tpt / 100;
  1501. if (tpt >= search_tbl->expected_tpt[index])
  1502. break;
  1503. }
  1504. search_tbl->current_rate =
  1505. rate_n_flags_from_tbl(mvm, search_tbl,
  1506. index, is_green);
  1507. update_search_tbl_counter = 1;
  1508. goto out;
  1509. case IWL_MIMO2_SWITCH_MIMO3_ABC:
  1510. IWL_DEBUG_RATE(mvm, "LQ: MIMO2 switch to MIMO3\n");
  1511. memcpy(search_tbl, tbl, sz);
  1512. search_tbl->is_SGI = 0;
  1513. search_tbl->ant_type = ANT_ABC;
  1514. if (!rs_is_valid_ant(valid_tx_ant,
  1515. search_tbl->ant_type))
  1516. break;
  1517. ret = rs_switch_to_mimo3(mvm, lq_sta, sta,
  1518. search_tbl, index);
  1519. if (!ret)
  1520. goto out;
  1521. break;
  1522. }
  1523. tbl->action++;
  1524. if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
  1525. tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
  1526. if (tbl->action == start_action)
  1527. break;
  1528. }
  1529. search_tbl->lq_type = LQ_NONE;
  1530. return 0;
  1531. out:
  1532. lq_sta->search_better_tbl = 1;
  1533. tbl->action++;
  1534. if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
  1535. tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
  1536. if (update_search_tbl_counter)
  1537. search_tbl->action = tbl->action;
  1538. return 0;
  1539. }
  1540. /*
  1541. * Try to switch to new modulation mode from MIMO3
  1542. */
  1543. static int rs_move_mimo3_to_other(struct iwl_mvm *mvm,
  1544. struct iwl_lq_sta *lq_sta,
  1545. struct ieee80211_sta *sta, int index)
  1546. {
  1547. s8 is_green = lq_sta->is_green;
  1548. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1549. struct iwl_scale_tbl_info *search_tbl =
  1550. &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  1551. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  1552. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1553. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1554. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1555. u8 start_action;
  1556. u8 valid_tx_ant = iwl_fw_valid_tx_ant(mvm->fw);
  1557. u8 tx_chains_num = num_of_ant(valid_tx_ant);
  1558. int ret;
  1559. u8 update_search_tbl_counter = 0;
  1560. start_action = tbl->action;
  1561. while (1) {
  1562. lq_sta->action_counter++;
  1563. switch (tbl->action) {
  1564. case IWL_MIMO3_SWITCH_ANTENNA1:
  1565. case IWL_MIMO3_SWITCH_ANTENNA2:
  1566. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 toggle Antennas\n");
  1567. if (tx_chains_num <= 3)
  1568. break;
  1569. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  1570. break;
  1571. memcpy(search_tbl, tbl, sz);
  1572. if (rs_toggle_antenna(valid_tx_ant,
  1573. &search_tbl->current_rate,
  1574. search_tbl))
  1575. goto out;
  1576. break;
  1577. case IWL_MIMO3_SWITCH_SISO_A:
  1578. case IWL_MIMO3_SWITCH_SISO_B:
  1579. case IWL_MIMO3_SWITCH_SISO_C:
  1580. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 switch to SISO\n");
  1581. /* Set up new search table for SISO */
  1582. memcpy(search_tbl, tbl, sz);
  1583. if (tbl->action == IWL_MIMO3_SWITCH_SISO_A)
  1584. search_tbl->ant_type = ANT_A;
  1585. else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B)
  1586. search_tbl->ant_type = ANT_B;
  1587. else
  1588. search_tbl->ant_type = ANT_C;
  1589. if (!rs_is_valid_ant(valid_tx_ant,
  1590. search_tbl->ant_type))
  1591. break;
  1592. ret = rs_switch_to_siso(mvm, lq_sta, sta,
  1593. search_tbl, index);
  1594. if (!ret)
  1595. goto out;
  1596. break;
  1597. case IWL_MIMO3_SWITCH_MIMO2_AB:
  1598. case IWL_MIMO3_SWITCH_MIMO2_AC:
  1599. case IWL_MIMO3_SWITCH_MIMO2_BC:
  1600. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 switch to MIMO2\n");
  1601. memcpy(search_tbl, tbl, sz);
  1602. search_tbl->is_SGI = 0;
  1603. if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB)
  1604. search_tbl->ant_type = ANT_AB;
  1605. else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC)
  1606. search_tbl->ant_type = ANT_AC;
  1607. else
  1608. search_tbl->ant_type = ANT_BC;
  1609. if (!rs_is_valid_ant(valid_tx_ant,
  1610. search_tbl->ant_type))
  1611. break;
  1612. ret = rs_switch_to_mimo2(mvm, lq_sta, sta,
  1613. search_tbl, index);
  1614. if (!ret)
  1615. goto out;
  1616. break;
  1617. case IWL_MIMO3_SWITCH_GI:
  1618. if (!tbl->is_ht40 && !(ht_cap->cap &
  1619. IEEE80211_HT_CAP_SGI_20))
  1620. break;
  1621. if (tbl->is_ht40 && !(ht_cap->cap &
  1622. IEEE80211_HT_CAP_SGI_40))
  1623. break;
  1624. IWL_DEBUG_RATE(mvm, "LQ: MIMO3 toggle SGI/NGI\n");
  1625. /* Set up new search table for MIMO */
  1626. memcpy(search_tbl, tbl, sz);
  1627. search_tbl->is_SGI = !tbl->is_SGI;
  1628. rs_set_expected_tpt_table(lq_sta, search_tbl);
  1629. /*
  1630. * If active table already uses the fastest possible
  1631. * modulation (dual stream with short guard interval),
  1632. * and it's working well, there's no need to look
  1633. * for a better type of modulation!
  1634. */
  1635. if (tbl->is_SGI) {
  1636. s32 tpt = lq_sta->last_tpt / 100;
  1637. if (tpt >= search_tbl->expected_tpt[index])
  1638. break;
  1639. }
  1640. search_tbl->current_rate =
  1641. rate_n_flags_from_tbl(mvm, search_tbl,
  1642. index, is_green);
  1643. update_search_tbl_counter = 1;
  1644. goto out;
  1645. }
  1646. tbl->action++;
  1647. if (tbl->action > IWL_MIMO3_SWITCH_GI)
  1648. tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
  1649. if (tbl->action == start_action)
  1650. break;
  1651. }
  1652. search_tbl->lq_type = LQ_NONE;
  1653. return 0;
  1654. out:
  1655. lq_sta->search_better_tbl = 1;
  1656. tbl->action++;
  1657. if (tbl->action > IWL_MIMO3_SWITCH_GI)
  1658. tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
  1659. if (update_search_tbl_counter)
  1660. search_tbl->action = tbl->action;
  1661. return 0;
  1662. }
  1663. /*
  1664. * Check whether we should continue using same modulation mode, or
  1665. * begin search for a new mode, based on:
  1666. * 1) # tx successes or failures while using this mode
  1667. * 2) # times calling this function
  1668. * 3) elapsed time in this mode (not used, for now)
  1669. */
  1670. static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search)
  1671. {
  1672. struct iwl_scale_tbl_info *tbl;
  1673. int i;
  1674. int active_tbl;
  1675. int flush_interval_passed = 0;
  1676. struct iwl_mvm *mvm;
  1677. mvm = lq_sta->drv;
  1678. active_tbl = lq_sta->active_tbl;
  1679. tbl = &(lq_sta->lq_info[active_tbl]);
  1680. /* If we've been disallowing search, see if we should now allow it */
  1681. if (lq_sta->stay_in_tbl) {
  1682. /* Elapsed time using current modulation mode */
  1683. if (lq_sta->flush_timer)
  1684. flush_interval_passed =
  1685. time_after(jiffies,
  1686. (unsigned long)(lq_sta->flush_timer +
  1687. IWL_RATE_SCALE_FLUSH_INTVL));
  1688. /*
  1689. * Check if we should allow search for new modulation mode.
  1690. * If many frames have failed or succeeded, or we've used
  1691. * this same modulation for a long time, allow search, and
  1692. * reset history stats that keep track of whether we should
  1693. * allow a new search. Also (below) reset all bitmaps and
  1694. * stats in active history.
  1695. */
  1696. if (force_search ||
  1697. (lq_sta->total_failed > lq_sta->max_failure_limit) ||
  1698. (lq_sta->total_success > lq_sta->max_success_limit) ||
  1699. ((!lq_sta->search_better_tbl) &&
  1700. (lq_sta->flush_timer) && (flush_interval_passed))) {
  1701. IWL_DEBUG_RATE(mvm,
  1702. "LQ: stay is expired %d %d %d\n",
  1703. lq_sta->total_failed,
  1704. lq_sta->total_success,
  1705. flush_interval_passed);
  1706. /* Allow search for new mode */
  1707. lq_sta->stay_in_tbl = 0; /* only place reset */
  1708. lq_sta->total_failed = 0;
  1709. lq_sta->total_success = 0;
  1710. lq_sta->flush_timer = 0;
  1711. /*
  1712. * Else if we've used this modulation mode enough repetitions
  1713. * (regardless of elapsed time or success/failure), reset
  1714. * history bitmaps and rate-specific stats for all rates in
  1715. * active table.
  1716. */
  1717. } else {
  1718. lq_sta->table_count++;
  1719. if (lq_sta->table_count >=
  1720. lq_sta->table_count_limit) {
  1721. lq_sta->table_count = 0;
  1722. IWL_DEBUG_RATE(mvm,
  1723. "LQ: stay in table clear win\n");
  1724. for (i = 0; i < IWL_RATE_COUNT; i++)
  1725. rs_rate_scale_clear_window(
  1726. &(tbl->win[i]));
  1727. }
  1728. }
  1729. /* If transitioning to allow "search", reset all history
  1730. * bitmaps and stats in active table (this will become the new
  1731. * "search" table). */
  1732. if (!lq_sta->stay_in_tbl) {
  1733. for (i = 0; i < IWL_RATE_COUNT; i++)
  1734. rs_rate_scale_clear_window(&(tbl->win[i]));
  1735. }
  1736. }
  1737. }
  1738. /*
  1739. * setup rate table in uCode
  1740. */
  1741. static void rs_update_rate_tbl(struct iwl_mvm *mvm,
  1742. struct iwl_lq_sta *lq_sta,
  1743. struct iwl_scale_tbl_info *tbl,
  1744. int index, u8 is_green)
  1745. {
  1746. u32 rate;
  1747. /* Update uCode's rate table. */
  1748. rate = rate_n_flags_from_tbl(mvm, tbl, index, is_green);
  1749. rs_fill_link_cmd(mvm, lq_sta, rate);
  1750. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_ASYNC, false);
  1751. }
  1752. /*
  1753. * Do rate scaling and search for new modulation mode.
  1754. */
  1755. static void rs_rate_scale_perform(struct iwl_mvm *mvm,
  1756. struct sk_buff *skb,
  1757. struct ieee80211_sta *sta,
  1758. struct iwl_lq_sta *lq_sta)
  1759. {
  1760. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1761. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1762. int low = IWL_RATE_INVALID;
  1763. int high = IWL_RATE_INVALID;
  1764. int index;
  1765. int i;
  1766. struct iwl_rate_scale_data *window = NULL;
  1767. int current_tpt = IWL_INVALID_VALUE;
  1768. int low_tpt = IWL_INVALID_VALUE;
  1769. int high_tpt = IWL_INVALID_VALUE;
  1770. u32 fail_count;
  1771. s8 scale_action = 0;
  1772. u16 rate_mask;
  1773. u8 update_lq = 0;
  1774. struct iwl_scale_tbl_info *tbl, *tbl1;
  1775. u16 rate_scale_index_msk = 0;
  1776. u8 is_green = 0;
  1777. u8 active_tbl = 0;
  1778. u8 done_search = 0;
  1779. u16 high_low;
  1780. s32 sr;
  1781. u8 tid = IWL_MAX_TID_COUNT;
  1782. struct iwl_mvm_sta *sta_priv = (void *)sta->drv_priv;
  1783. struct iwl_mvm_tid_data *tid_data;
  1784. IWL_DEBUG_RATE(mvm, "rate scale calculate new rate for skb\n");
  1785. /* Send management frames and NO_ACK data using lowest rate. */
  1786. /* TODO: this could probably be improved.. */
  1787. if (!ieee80211_is_data(hdr->frame_control) ||
  1788. info->flags & IEEE80211_TX_CTL_NO_ACK)
  1789. return;
  1790. lq_sta->supp_rates = sta->supp_rates[lq_sta->band];
  1791. tid = rs_tl_add_packet(lq_sta, hdr);
  1792. if ((tid != IWL_MAX_TID_COUNT) &&
  1793. (lq_sta->tx_agg_tid_en & (1 << tid))) {
  1794. tid_data = &sta_priv->tid_data[tid];
  1795. if (tid_data->state == IWL_AGG_OFF)
  1796. lq_sta->is_agg = 0;
  1797. else
  1798. lq_sta->is_agg = 1;
  1799. } else {
  1800. lq_sta->is_agg = 0;
  1801. }
  1802. /*
  1803. * Select rate-scale / modulation-mode table to work with in
  1804. * the rest of this function: "search" if searching for better
  1805. * modulation mode, or "active" if doing rate scaling within a mode.
  1806. */
  1807. if (!lq_sta->search_better_tbl)
  1808. active_tbl = lq_sta->active_tbl;
  1809. else
  1810. active_tbl = 1 - lq_sta->active_tbl;
  1811. tbl = &(lq_sta->lq_info[active_tbl]);
  1812. if (is_legacy(tbl->lq_type))
  1813. lq_sta->is_green = 0;
  1814. else
  1815. lq_sta->is_green = rs_use_green(sta);
  1816. is_green = lq_sta->is_green;
  1817. /* current tx rate */
  1818. index = lq_sta->last_txrate_idx;
  1819. IWL_DEBUG_RATE(mvm, "Rate scale index %d for type %d\n", index,
  1820. tbl->lq_type);
  1821. /* rates available for this association, and for modulation mode */
  1822. rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
  1823. IWL_DEBUG_RATE(mvm, "mask 0x%04X\n", rate_mask);
  1824. /* mask with station rate restriction */
  1825. if (is_legacy(tbl->lq_type)) {
  1826. if (lq_sta->band == IEEE80211_BAND_5GHZ)
  1827. /* supp_rates has no CCK bits in A mode */
  1828. rate_scale_index_msk = (u16) (rate_mask &
  1829. (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE));
  1830. else
  1831. rate_scale_index_msk = (u16) (rate_mask &
  1832. lq_sta->supp_rates);
  1833. } else {
  1834. rate_scale_index_msk = rate_mask;
  1835. }
  1836. if (!rate_scale_index_msk)
  1837. rate_scale_index_msk = rate_mask;
  1838. if (!((1 << index) & rate_scale_index_msk)) {
  1839. IWL_ERR(mvm, "Current Rate is not valid\n");
  1840. if (lq_sta->search_better_tbl) {
  1841. /* revert to active table if search table is not valid*/
  1842. tbl->lq_type = LQ_NONE;
  1843. lq_sta->search_better_tbl = 0;
  1844. tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  1845. /* get "active" rate info */
  1846. index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
  1847. rs_update_rate_tbl(mvm, lq_sta, tbl, index, is_green);
  1848. }
  1849. return;
  1850. }
  1851. /* Get expected throughput table and history window for current rate */
  1852. if (!tbl->expected_tpt) {
  1853. IWL_ERR(mvm, "tbl->expected_tpt is NULL\n");
  1854. return;
  1855. }
  1856. /* force user max rate if set by user */
  1857. if ((lq_sta->max_rate_idx != -1) &&
  1858. (lq_sta->max_rate_idx < index)) {
  1859. index = lq_sta->max_rate_idx;
  1860. update_lq = 1;
  1861. window = &(tbl->win[index]);
  1862. goto lq_update;
  1863. }
  1864. window = &(tbl->win[index]);
  1865. /*
  1866. * If there is not enough history to calculate actual average
  1867. * throughput, keep analyzing results of more tx frames, without
  1868. * changing rate or mode (bypass most of the rest of this function).
  1869. * Set up new rate table in uCode only if old rate is not supported
  1870. * in current association (use new rate found above).
  1871. */
  1872. fail_count = window->counter - window->success_counter;
  1873. if ((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
  1874. (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) {
  1875. IWL_DEBUG_RATE(mvm,
  1876. "LQ: still below TH. succ=%d total=%d for index %d\n",
  1877. window->success_counter, window->counter, index);
  1878. /* Can't calculate this yet; not enough history */
  1879. window->average_tpt = IWL_INVALID_VALUE;
  1880. /* Should we stay with this modulation mode,
  1881. * or search for a new one? */
  1882. rs_stay_in_table(lq_sta, false);
  1883. goto out;
  1884. }
  1885. /* Else we have enough samples; calculate estimate of
  1886. * actual average throughput */
  1887. if (window->average_tpt != ((window->success_ratio *
  1888. tbl->expected_tpt[index] + 64) / 128)) {
  1889. IWL_ERR(mvm,
  1890. "expected_tpt should have been calculated by now\n");
  1891. window->average_tpt = ((window->success_ratio *
  1892. tbl->expected_tpt[index] + 64) / 128);
  1893. }
  1894. /* If we are searching for better modulation mode, check success. */
  1895. if (lq_sta->search_better_tbl) {
  1896. /* If good success, continue using the "search" mode;
  1897. * no need to send new link quality command, since we're
  1898. * continuing to use the setup that we've been trying. */
  1899. if (window->average_tpt > lq_sta->last_tpt) {
  1900. IWL_DEBUG_RATE(mvm,
  1901. "LQ: SWITCHING TO NEW TABLE suc=%d cur-tpt=%d old-tpt=%d\n",
  1902. window->success_ratio,
  1903. window->average_tpt,
  1904. lq_sta->last_tpt);
  1905. if (!is_legacy(tbl->lq_type))
  1906. lq_sta->enable_counter = 1;
  1907. /* Swap tables; "search" becomes "active" */
  1908. lq_sta->active_tbl = active_tbl;
  1909. current_tpt = window->average_tpt;
  1910. /* Else poor success; go back to mode in "active" table */
  1911. } else {
  1912. IWL_DEBUG_RATE(mvm,
  1913. "LQ: GOING BACK TO THE OLD TABLE suc=%d cur-tpt=%d old-tpt=%d\n",
  1914. window->success_ratio,
  1915. window->average_tpt,
  1916. lq_sta->last_tpt);
  1917. /* Nullify "search" table */
  1918. tbl->lq_type = LQ_NONE;
  1919. /* Revert to "active" table */
  1920. active_tbl = lq_sta->active_tbl;
  1921. tbl = &(lq_sta->lq_info[active_tbl]);
  1922. /* Revert to "active" rate and throughput info */
  1923. index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
  1924. current_tpt = lq_sta->last_tpt;
  1925. /* Need to set up a new rate table in uCode */
  1926. update_lq = 1;
  1927. }
  1928. /* Either way, we've made a decision; modulation mode
  1929. * search is done, allow rate adjustment next time. */
  1930. lq_sta->search_better_tbl = 0;
  1931. done_search = 1; /* Don't switch modes below! */
  1932. goto lq_update;
  1933. }
  1934. /* (Else) not in search of better modulation mode, try for better
  1935. * starting rate, while staying in this mode. */
  1936. high_low = rs_get_adjacent_rate(mvm, index, rate_scale_index_msk,
  1937. tbl->lq_type);
  1938. low = high_low & 0xff;
  1939. high = (high_low >> 8) & 0xff;
  1940. /* If user set max rate, dont allow higher than user constrain */
  1941. if ((lq_sta->max_rate_idx != -1) &&
  1942. (lq_sta->max_rate_idx < high))
  1943. high = IWL_RATE_INVALID;
  1944. sr = window->success_ratio;
  1945. /* Collect measured throughputs for current and adjacent rates */
  1946. current_tpt = window->average_tpt;
  1947. if (low != IWL_RATE_INVALID)
  1948. low_tpt = tbl->win[low].average_tpt;
  1949. if (high != IWL_RATE_INVALID)
  1950. high_tpt = tbl->win[high].average_tpt;
  1951. scale_action = 0;
  1952. /* Too many failures, decrease rate */
  1953. if ((sr <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) {
  1954. IWL_DEBUG_RATE(mvm,
  1955. "decrease rate because of low success_ratio\n");
  1956. scale_action = -1;
  1957. /* No throughput measured yet for adjacent rates; try increase. */
  1958. } else if ((low_tpt == IWL_INVALID_VALUE) &&
  1959. (high_tpt == IWL_INVALID_VALUE)) {
  1960. if (high != IWL_RATE_INVALID && sr >= IWL_RATE_INCREASE_TH)
  1961. scale_action = 1;
  1962. else if (low != IWL_RATE_INVALID)
  1963. scale_action = 0;
  1964. }
  1965. /* Both adjacent throughputs are measured, but neither one has better
  1966. * throughput; we're using the best rate, don't change it! */
  1967. else if ((low_tpt != IWL_INVALID_VALUE) &&
  1968. (high_tpt != IWL_INVALID_VALUE) &&
  1969. (low_tpt < current_tpt) &&
  1970. (high_tpt < current_tpt))
  1971. scale_action = 0;
  1972. /* At least one adjacent rate's throughput is measured,
  1973. * and may have better performance. */
  1974. else {
  1975. /* Higher adjacent rate's throughput is measured */
  1976. if (high_tpt != IWL_INVALID_VALUE) {
  1977. /* Higher rate has better throughput */
  1978. if (high_tpt > current_tpt &&
  1979. sr >= IWL_RATE_INCREASE_TH) {
  1980. scale_action = 1;
  1981. } else {
  1982. scale_action = 0;
  1983. }
  1984. /* Lower adjacent rate's throughput is measured */
  1985. } else if (low_tpt != IWL_INVALID_VALUE) {
  1986. /* Lower rate has better throughput */
  1987. if (low_tpt > current_tpt) {
  1988. IWL_DEBUG_RATE(mvm,
  1989. "decrease rate because of low tpt\n");
  1990. scale_action = -1;
  1991. } else if (sr >= IWL_RATE_INCREASE_TH) {
  1992. scale_action = 1;
  1993. }
  1994. }
  1995. }
  1996. /* Sanity check; asked for decrease, but success rate or throughput
  1997. * has been good at old rate. Don't change it. */
  1998. if ((scale_action == -1) && (low != IWL_RATE_INVALID) &&
  1999. ((sr > IWL_RATE_HIGH_TH) ||
  2000. (current_tpt > (100 * tbl->expected_tpt[low]))))
  2001. scale_action = 0;
  2002. switch (scale_action) {
  2003. case -1:
  2004. /* Decrease starting rate, update uCode's rate table */
  2005. if (low != IWL_RATE_INVALID) {
  2006. update_lq = 1;
  2007. index = low;
  2008. }
  2009. break;
  2010. case 1:
  2011. /* Increase starting rate, update uCode's rate table */
  2012. if (high != IWL_RATE_INVALID) {
  2013. update_lq = 1;
  2014. index = high;
  2015. }
  2016. break;
  2017. case 0:
  2018. /* No change */
  2019. default:
  2020. break;
  2021. }
  2022. IWL_DEBUG_RATE(mvm,
  2023. "choose rate scale index %d action %d low %d high %d type %d\n",
  2024. index, scale_action, low, high, tbl->lq_type);
  2025. lq_update:
  2026. /* Replace uCode's rate table for the destination station. */
  2027. if (update_lq)
  2028. rs_update_rate_tbl(mvm, lq_sta, tbl, index, is_green);
  2029. rs_stay_in_table(lq_sta, false);
  2030. /*
  2031. * Search for new modulation mode if we're:
  2032. * 1) Not changing rates right now
  2033. * 2) Not just finishing up a search
  2034. * 3) Allowing a new search
  2035. */
  2036. if (!update_lq && !done_search &&
  2037. !lq_sta->stay_in_tbl && window->counter) {
  2038. /* Save current throughput to compare with "search" throughput*/
  2039. lq_sta->last_tpt = current_tpt;
  2040. /* Select a new "search" modulation mode to try.
  2041. * If one is found, set up the new "search" table. */
  2042. if (is_legacy(tbl->lq_type))
  2043. rs_move_legacy_other(mvm, lq_sta, sta, index);
  2044. else if (is_siso(tbl->lq_type))
  2045. rs_move_siso_to_other(mvm, lq_sta, sta, index);
  2046. else if (is_mimo2(tbl->lq_type))
  2047. rs_move_mimo2_to_other(mvm, lq_sta, sta, index);
  2048. else
  2049. rs_move_mimo3_to_other(mvm, lq_sta, sta, index);
  2050. /* If new "search" mode was selected, set up in uCode table */
  2051. if (lq_sta->search_better_tbl) {
  2052. /* Access the "search" table, clear its history. */
  2053. tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
  2054. for (i = 0; i < IWL_RATE_COUNT; i++)
  2055. rs_rate_scale_clear_window(&(tbl->win[i]));
  2056. /* Use new "search" start rate */
  2057. index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
  2058. IWL_DEBUG_RATE(mvm,
  2059. "Switch current mcs: %X index: %d\n",
  2060. tbl->current_rate, index);
  2061. rs_fill_link_cmd(mvm, lq_sta, tbl->current_rate);
  2062. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_ASYNC, false);
  2063. } else {
  2064. done_search = 1;
  2065. }
  2066. }
  2067. if (done_search && !lq_sta->stay_in_tbl) {
  2068. /* If the "active" (non-search) mode was legacy,
  2069. * and we've tried switching antennas,
  2070. * but we haven't been able to try HT modes (not available),
  2071. * stay with best antenna legacy modulation for a while
  2072. * before next round of mode comparisons. */
  2073. tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]);
  2074. if (is_legacy(tbl1->lq_type) && !sta->ht_cap.ht_supported &&
  2075. lq_sta->action_counter > tbl1->max_search) {
  2076. IWL_DEBUG_RATE(mvm, "LQ: STAY in legacy table\n");
  2077. rs_set_stay_in_table(mvm, 1, lq_sta);
  2078. }
  2079. /* If we're in an HT mode, and all 3 mode switch actions
  2080. * have been tried and compared, stay in this best modulation
  2081. * mode for a while before next round of mode comparisons. */
  2082. if (lq_sta->enable_counter &&
  2083. (lq_sta->action_counter >= tbl1->max_search)) {
  2084. if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
  2085. (lq_sta->tx_agg_tid_en & (1 << tid)) &&
  2086. (tid != IWL_MAX_TID_COUNT)) {
  2087. tid_data = &sta_priv->tid_data[tid];
  2088. if (tid_data->state == IWL_AGG_OFF) {
  2089. IWL_DEBUG_RATE(mvm,
  2090. "try to aggregate tid %d\n",
  2091. tid);
  2092. rs_tl_turn_on_agg(mvm, tid,
  2093. lq_sta, sta);
  2094. }
  2095. }
  2096. rs_set_stay_in_table(mvm, 0, lq_sta);
  2097. }
  2098. }
  2099. out:
  2100. tbl->current_rate = rate_n_flags_from_tbl(mvm, tbl, index, is_green);
  2101. lq_sta->last_txrate_idx = index;
  2102. }
  2103. /**
  2104. * rs_initialize_lq - Initialize a station's hardware rate table
  2105. *
  2106. * The uCode's station table contains a table of fallback rates
  2107. * for automatic fallback during transmission.
  2108. *
  2109. * NOTE: This sets up a default set of values. These will be replaced later
  2110. * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
  2111. * rc80211_simple.
  2112. *
  2113. * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
  2114. * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  2115. * which requires station table entry to exist).
  2116. */
  2117. static void rs_initialize_lq(struct iwl_mvm *mvm,
  2118. struct ieee80211_sta *sta,
  2119. struct iwl_lq_sta *lq_sta,
  2120. enum ieee80211_band band)
  2121. {
  2122. struct iwl_scale_tbl_info *tbl;
  2123. int rate_idx;
  2124. int i;
  2125. u32 rate;
  2126. u8 use_green = rs_use_green(sta);
  2127. u8 active_tbl = 0;
  2128. u8 valid_tx_ant;
  2129. if (!sta || !lq_sta)
  2130. return;
  2131. i = lq_sta->last_txrate_idx;
  2132. valid_tx_ant = iwl_fw_valid_tx_ant(mvm->fw);
  2133. if (!lq_sta->search_better_tbl)
  2134. active_tbl = lq_sta->active_tbl;
  2135. else
  2136. active_tbl = 1 - lq_sta->active_tbl;
  2137. tbl = &(lq_sta->lq_info[active_tbl]);
  2138. if ((i < 0) || (i >= IWL_RATE_COUNT))
  2139. i = 0;
  2140. rate = iwl_rates[i].plcp;
  2141. tbl->ant_type = first_antenna(valid_tx_ant);
  2142. rate |= tbl->ant_type << RATE_MCS_ANT_POS;
  2143. if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
  2144. rate |= RATE_MCS_CCK_MSK;
  2145. rs_get_tbl_info_from_mcs(rate, band, tbl, &rate_idx);
  2146. if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
  2147. rs_toggle_antenna(valid_tx_ant, &rate, tbl);
  2148. rate = rate_n_flags_from_tbl(mvm, tbl, rate_idx, use_green);
  2149. tbl->current_rate = rate;
  2150. rs_set_expected_tpt_table(lq_sta, tbl);
  2151. rs_fill_link_cmd(NULL, lq_sta, rate);
  2152. /* TODO restore station should remember the lq cmd */
  2153. iwl_mvm_send_lq_cmd(mvm, &lq_sta->lq, CMD_SYNC, true);
  2154. }
  2155. static void rs_get_rate(void *mvm_r, struct ieee80211_sta *sta, void *mvm_sta,
  2156. struct ieee80211_tx_rate_control *txrc)
  2157. {
  2158. struct sk_buff *skb = txrc->skb;
  2159. struct ieee80211_supported_band *sband = txrc->sband;
  2160. struct iwl_op_mode *op_mode __maybe_unused =
  2161. (struct iwl_op_mode *)mvm_r;
  2162. struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode);
  2163. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2164. struct iwl_lq_sta *lq_sta = mvm_sta;
  2165. int rate_idx;
  2166. IWL_DEBUG_RATE_LIMIT(mvm, "rate scale calculate new rate for skb\n");
  2167. /* Get max rate if user set max rate */
  2168. if (lq_sta) {
  2169. lq_sta->max_rate_idx = txrc->max_rate_idx;
  2170. if ((sband->band == IEEE80211_BAND_5GHZ) &&
  2171. (lq_sta->max_rate_idx != -1))
  2172. lq_sta->max_rate_idx += IWL_FIRST_OFDM_RATE;
  2173. if ((lq_sta->max_rate_idx < 0) ||
  2174. (lq_sta->max_rate_idx >= IWL_RATE_COUNT))
  2175. lq_sta->max_rate_idx = -1;
  2176. }
  2177. /* Treat uninitialized rate scaling data same as non-existing. */
  2178. if (lq_sta && !lq_sta->drv) {
  2179. IWL_DEBUG_RATE(mvm, "Rate scaling not initialized yet.\n");
  2180. mvm_sta = NULL;
  2181. }
  2182. /* Send management frames and NO_ACK data using lowest rate. */
  2183. if (rate_control_send_low(sta, mvm_sta, txrc))
  2184. return;
  2185. rate_idx = lq_sta->last_txrate_idx;
  2186. if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
  2187. rate_idx -= IWL_FIRST_OFDM_RATE;
  2188. /* 6M and 9M shared same MCS index */
  2189. rate_idx = (rate_idx > 0) ? (rate_idx - 1) : 0;
  2190. if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
  2191. IWL_RATE_MIMO3_6M_PLCP)
  2192. rate_idx = rate_idx + (2 * MCS_INDEX_PER_STREAM);
  2193. else if (rs_extract_rate(lq_sta->last_rate_n_flags) >=
  2194. IWL_RATE_MIMO2_6M_PLCP)
  2195. rate_idx = rate_idx + MCS_INDEX_PER_STREAM;
  2196. info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
  2197. if (lq_sta->last_rate_n_flags & RATE_MCS_SGI_MSK)
  2198. info->control.rates[0].flags |= IEEE80211_TX_RC_SHORT_GI;
  2199. if (lq_sta->last_rate_n_flags & RATE_MCS_CHAN_WIDTH_40) /* TODO */
  2200. info->control.rates[0].flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  2201. if (lq_sta->last_rate_n_flags & RATE_HT_MCS_GF_MSK)
  2202. info->control.rates[0].flags |= IEEE80211_TX_RC_GREEN_FIELD;
  2203. } else {
  2204. /* Check for invalid rates */
  2205. if ((rate_idx < 0) || (rate_idx >= IWL_RATE_COUNT_LEGACY) ||
  2206. ((sband->band == IEEE80211_BAND_5GHZ) &&
  2207. (rate_idx < IWL_FIRST_OFDM_RATE)))
  2208. rate_idx = rate_lowest_index(sband, sta);
  2209. /* On valid 5 GHz rate, adjust index */
  2210. else if (sband->band == IEEE80211_BAND_5GHZ)
  2211. rate_idx -= IWL_FIRST_OFDM_RATE;
  2212. info->control.rates[0].flags = 0;
  2213. }
  2214. info->control.rates[0].idx = rate_idx;
  2215. }
  2216. static void *rs_alloc_sta(void *mvm_rate, struct ieee80211_sta *sta,
  2217. gfp_t gfp)
  2218. {
  2219. struct iwl_mvm_sta *sta_priv = (struct iwl_mvm_sta *)sta->drv_priv;
  2220. struct iwl_op_mode *op_mode __maybe_unused =
  2221. (struct iwl_op_mode *)mvm_rate;
  2222. struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode);
  2223. IWL_DEBUG_RATE(mvm, "create station rate scale window\n");
  2224. return &sta_priv->lq_sta;
  2225. }
  2226. /*
  2227. * Called after adding a new station to initialize rate scaling
  2228. */
  2229. void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
  2230. enum ieee80211_band band)
  2231. {
  2232. int i, j;
  2233. struct ieee80211_hw *hw = mvm->hw;
  2234. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  2235. struct iwl_mvm_sta *sta_priv;
  2236. struct iwl_lq_sta *lq_sta;
  2237. struct ieee80211_supported_band *sband;
  2238. unsigned long supp; /* must be unsigned long for for_each_set_bit */
  2239. sta_priv = (struct iwl_mvm_sta *)sta->drv_priv;
  2240. lq_sta = &sta_priv->lq_sta;
  2241. sband = hw->wiphy->bands[band];
  2242. lq_sta->lq.sta_id = sta_priv->sta_id;
  2243. for (j = 0; j < LQ_SIZE; j++)
  2244. for (i = 0; i < IWL_RATE_COUNT; i++)
  2245. rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
  2246. lq_sta->flush_timer = 0;
  2247. lq_sta->supp_rates = sta->supp_rates[sband->band];
  2248. for (j = 0; j < LQ_SIZE; j++)
  2249. for (i = 0; i < IWL_RATE_COUNT; i++)
  2250. rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
  2251. IWL_DEBUG_RATE(mvm,
  2252. "LQ: *** rate scale station global init for station %d ***\n",
  2253. sta_priv->sta_id);
  2254. /* TODO: what is a good starting rate for STA? About middle? Maybe not
  2255. * the lowest or the highest rate.. Could consider using RSSI from
  2256. * previous packets? Need to have IEEE 802.1X auth succeed immediately
  2257. * after assoc.. */
  2258. lq_sta->max_rate_idx = -1;
  2259. lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX;
  2260. lq_sta->is_green = rs_use_green(sta);
  2261. lq_sta->band = sband->band;
  2262. /*
  2263. * active legacy rates as per supported rates bitmap
  2264. */
  2265. supp = sta->supp_rates[sband->band];
  2266. lq_sta->active_legacy_rate = 0;
  2267. for_each_set_bit(i, &supp, BITS_PER_LONG)
  2268. lq_sta->active_legacy_rate |= BIT(sband->bitrates[i].hw_value);
  2269. /*
  2270. * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
  2271. * supp_rates[] does not; shift to convert format, force 9 MBits off.
  2272. */
  2273. lq_sta->active_siso_rate = ht_cap->mcs.rx_mask[0] << 1;
  2274. lq_sta->active_siso_rate |= ht_cap->mcs.rx_mask[0] & 0x1;
  2275. lq_sta->active_siso_rate &= ~((u16)0x2);
  2276. lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE;
  2277. /* Same here */
  2278. lq_sta->active_mimo2_rate = ht_cap->mcs.rx_mask[1] << 1;
  2279. lq_sta->active_mimo2_rate |= ht_cap->mcs.rx_mask[1] & 0x1;
  2280. lq_sta->active_mimo2_rate &= ~((u16)0x2);
  2281. lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE;
  2282. lq_sta->active_mimo3_rate = ht_cap->mcs.rx_mask[2] << 1;
  2283. lq_sta->active_mimo3_rate |= ht_cap->mcs.rx_mask[2] & 0x1;
  2284. lq_sta->active_mimo3_rate &= ~((u16)0x2);
  2285. lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE;
  2286. IWL_DEBUG_RATE(mvm,
  2287. "SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n",
  2288. lq_sta->active_siso_rate,
  2289. lq_sta->active_mimo2_rate,
  2290. lq_sta->active_mimo3_rate);
  2291. /* These values will be overridden later */
  2292. lq_sta->lq.single_stream_ant_msk =
  2293. first_antenna(iwl_fw_valid_tx_ant(mvm->fw));
  2294. lq_sta->lq.dual_stream_ant_msk =
  2295. iwl_fw_valid_tx_ant(mvm->fw) &
  2296. ~first_antenna(iwl_fw_valid_tx_ant(mvm->fw));
  2297. if (!lq_sta->lq.dual_stream_ant_msk) {
  2298. lq_sta->lq.dual_stream_ant_msk = ANT_AB;
  2299. } else if (num_of_ant(iwl_fw_valid_tx_ant(mvm->fw)) == 2) {
  2300. lq_sta->lq.dual_stream_ant_msk =
  2301. iwl_fw_valid_tx_ant(mvm->fw);
  2302. }
  2303. /* as default allow aggregation for all tids */
  2304. lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
  2305. lq_sta->drv = mvm;
  2306. /* Set last_txrate_idx to lowest rate */
  2307. lq_sta->last_txrate_idx = rate_lowest_index(sband, sta);
  2308. if (sband->band == IEEE80211_BAND_5GHZ)
  2309. lq_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
  2310. lq_sta->is_agg = 0;
  2311. #ifdef CONFIG_MAC80211_DEBUGFS
  2312. lq_sta->dbg_fixed_rate = 0;
  2313. #endif
  2314. rs_initialize_lq(mvm, sta, lq_sta, band);
  2315. }
  2316. static void rs_fill_link_cmd(struct iwl_mvm *mvm,
  2317. struct iwl_lq_sta *lq_sta, u32 new_rate)
  2318. {
  2319. struct iwl_scale_tbl_info tbl_type;
  2320. int index = 0;
  2321. int rate_idx;
  2322. int repeat_rate = 0;
  2323. u8 ant_toggle_cnt = 0;
  2324. u8 use_ht_possible = 1;
  2325. u8 valid_tx_ant = 0;
  2326. struct iwl_lq_cmd *lq_cmd = &lq_sta->lq;
  2327. /* Override starting rate (index 0) if needed for debug purposes */
  2328. rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
  2329. /* Interpret new_rate (rate_n_flags) */
  2330. rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
  2331. &tbl_type, &rate_idx);
  2332. /* How many times should we repeat the initial rate? */
  2333. if (is_legacy(tbl_type.lq_type)) {
  2334. ant_toggle_cnt = 1;
  2335. repeat_rate = IWL_NUMBER_TRY;
  2336. } else {
  2337. repeat_rate = min(IWL_HT_NUMBER_TRY,
  2338. LINK_QUAL_AGG_DISABLE_START_DEF - 1);
  2339. }
  2340. lq_cmd->mimo_delim = is_mimo(tbl_type.lq_type) ? 1 : 0;
  2341. /* Fill 1st table entry (index 0) */
  2342. lq_cmd->rs_table[index] = cpu_to_le32(new_rate);
  2343. if (num_of_ant(tbl_type.ant_type) == 1)
  2344. lq_cmd->single_stream_ant_msk = tbl_type.ant_type;
  2345. else if (num_of_ant(tbl_type.ant_type) == 2)
  2346. lq_cmd->dual_stream_ant_msk = tbl_type.ant_type;
  2347. /* otherwise we don't modify the existing value */
  2348. index++;
  2349. repeat_rate--;
  2350. if (mvm)
  2351. valid_tx_ant = iwl_fw_valid_tx_ant(mvm->fw);
  2352. /* Fill rest of rate table */
  2353. while (index < LINK_QUAL_MAX_RETRY_NUM) {
  2354. /* Repeat initial/next rate.
  2355. * For legacy IWL_NUMBER_TRY == 1, this loop will not execute.
  2356. * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
  2357. while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
  2358. if (is_legacy(tbl_type.lq_type)) {
  2359. if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
  2360. ant_toggle_cnt++;
  2361. else if (mvm &&
  2362. rs_toggle_antenna(valid_tx_ant,
  2363. &new_rate, &tbl_type))
  2364. ant_toggle_cnt = 1;
  2365. }
  2366. /* Override next rate if needed for debug purposes */
  2367. rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
  2368. /* Fill next table entry */
  2369. lq_cmd->rs_table[index] =
  2370. cpu_to_le32(new_rate);
  2371. repeat_rate--;
  2372. index++;
  2373. }
  2374. rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type,
  2375. &rate_idx);
  2376. /* Indicate to uCode which entries might be MIMO.
  2377. * If initial rate was MIMO, this will finally end up
  2378. * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */
  2379. if (is_mimo(tbl_type.lq_type))
  2380. lq_cmd->mimo_delim = index;
  2381. /* Get next rate */
  2382. new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
  2383. use_ht_possible);
  2384. /* How many times should we repeat the next rate? */
  2385. if (is_legacy(tbl_type.lq_type)) {
  2386. if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
  2387. ant_toggle_cnt++;
  2388. else if (mvm &&
  2389. rs_toggle_antenna(valid_tx_ant,
  2390. &new_rate, &tbl_type))
  2391. ant_toggle_cnt = 1;
  2392. repeat_rate = IWL_NUMBER_TRY;
  2393. } else {
  2394. repeat_rate = IWL_HT_NUMBER_TRY;
  2395. }
  2396. /* Don't allow HT rates after next pass.
  2397. * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
  2398. use_ht_possible = 0;
  2399. /* Override next rate if needed for debug purposes */
  2400. rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
  2401. /* Fill next table entry */
  2402. lq_cmd->rs_table[index] = cpu_to_le32(new_rate);
  2403. index++;
  2404. repeat_rate--;
  2405. }
  2406. lq_cmd->agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  2407. lq_cmd->agg_disable_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  2408. lq_cmd->agg_time_limit =
  2409. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  2410. }
  2411. static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
  2412. {
  2413. return hw->priv;
  2414. }
  2415. /* rate scale requires free function to be implemented */
  2416. static void rs_free(void *mvm_rate)
  2417. {
  2418. return;
  2419. }
  2420. static void rs_free_sta(void *mvm_r, struct ieee80211_sta *sta,
  2421. void *mvm_sta)
  2422. {
  2423. struct iwl_op_mode *op_mode __maybe_unused = mvm_r;
  2424. struct iwl_mvm *mvm __maybe_unused = IWL_OP_MODE_GET_MVM(op_mode);
  2425. IWL_DEBUG_RATE(mvm, "enter\n");
  2426. IWL_DEBUG_RATE(mvm, "leave\n");
  2427. }
  2428. #ifdef CONFIG_MAC80211_DEBUGFS
  2429. static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
  2430. u32 *rate_n_flags, int index)
  2431. {
  2432. struct iwl_mvm *mvm;
  2433. u8 valid_tx_ant;
  2434. u8 ant_sel_tx;
  2435. mvm = lq_sta->drv;
  2436. valid_tx_ant = iwl_fw_valid_tx_ant(mvm->fw);
  2437. if (lq_sta->dbg_fixed_rate) {
  2438. ant_sel_tx =
  2439. ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK)
  2440. >> RATE_MCS_ANT_POS);
  2441. if ((valid_tx_ant & ant_sel_tx) == ant_sel_tx) {
  2442. *rate_n_flags = lq_sta->dbg_fixed_rate;
  2443. IWL_DEBUG_RATE(mvm, "Fixed rate ON\n");
  2444. } else {
  2445. lq_sta->dbg_fixed_rate = 0;
  2446. IWL_ERR(mvm,
  2447. "Invalid antenna selection 0x%X, Valid is 0x%X\n",
  2448. ant_sel_tx, valid_tx_ant);
  2449. IWL_DEBUG_RATE(mvm, "Fixed rate OFF\n");
  2450. }
  2451. } else {
  2452. IWL_DEBUG_RATE(mvm, "Fixed rate OFF\n");
  2453. }
  2454. }
  2455. static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
  2456. const char __user *user_buf, size_t count, loff_t *ppos)
  2457. {
  2458. struct iwl_lq_sta *lq_sta = file->private_data;
  2459. struct iwl_mvm *mvm;
  2460. char buf[64];
  2461. size_t buf_size;
  2462. u32 parsed_rate;
  2463. mvm = lq_sta->drv;
  2464. memset(buf, 0, sizeof(buf));
  2465. buf_size = min(count, sizeof(buf) - 1);
  2466. if (copy_from_user(buf, user_buf, buf_size))
  2467. return -EFAULT;
  2468. if (sscanf(buf, "%x", &parsed_rate) == 1)
  2469. lq_sta->dbg_fixed_rate = parsed_rate;
  2470. else
  2471. lq_sta->dbg_fixed_rate = 0;
  2472. rs_program_fix_rate(mvm, lq_sta);
  2473. return count;
  2474. }
  2475. static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
  2476. char __user *user_buf, size_t count, loff_t *ppos)
  2477. {
  2478. char *buff;
  2479. int desc = 0;
  2480. int i = 0;
  2481. int index = 0;
  2482. ssize_t ret;
  2483. struct iwl_lq_sta *lq_sta = file->private_data;
  2484. struct iwl_mvm *mvm;
  2485. struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
  2486. mvm = lq_sta->drv;
  2487. buff = kmalloc(1024, GFP_KERNEL);
  2488. if (!buff)
  2489. return -ENOMEM;
  2490. desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
  2491. desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
  2492. lq_sta->total_failed, lq_sta->total_success,
  2493. lq_sta->active_legacy_rate);
  2494. desc += sprintf(buff+desc, "fixed rate 0x%X\n",
  2495. lq_sta->dbg_fixed_rate);
  2496. desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n",
  2497. (iwl_fw_valid_tx_ant(mvm->fw) & ANT_A) ? "ANT_A," : "",
  2498. (iwl_fw_valid_tx_ant(mvm->fw) & ANT_B) ? "ANT_B," : "",
  2499. (iwl_fw_valid_tx_ant(mvm->fw) & ANT_C) ? "ANT_C" : "");
  2500. desc += sprintf(buff+desc, "lq type %s\n",
  2501. (is_legacy(tbl->lq_type)) ? "legacy" : "HT");
  2502. if (is_Ht(tbl->lq_type)) {
  2503. desc += sprintf(buff+desc, " %s",
  2504. (is_siso(tbl->lq_type)) ? "SISO" :
  2505. ((is_mimo2(tbl->lq_type)) ? "MIMO2" : "MIMO3"));
  2506. desc += sprintf(buff+desc, " %s",
  2507. (tbl->is_ht40) ? "40MHz" : "20MHz");
  2508. desc += sprintf(buff+desc, " %s %s %s\n",
  2509. (tbl->is_SGI) ? "SGI" : "",
  2510. (lq_sta->is_green) ? "GF enabled" : "",
  2511. (lq_sta->is_agg) ? "AGG on" : "");
  2512. }
  2513. desc += sprintf(buff+desc, "last tx rate=0x%X\n",
  2514. lq_sta->last_rate_n_flags);
  2515. desc += sprintf(buff+desc,
  2516. "general: flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
  2517. lq_sta->lq.flags,
  2518. lq_sta->lq.mimo_delim,
  2519. lq_sta->lq.single_stream_ant_msk,
  2520. lq_sta->lq.dual_stream_ant_msk);
  2521. desc += sprintf(buff+desc,
  2522. "agg: time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
  2523. le16_to_cpu(lq_sta->lq.agg_time_limit),
  2524. lq_sta->lq.agg_disable_start_th,
  2525. lq_sta->lq.agg_frame_cnt_limit);
  2526. desc += sprintf(buff+desc,
  2527. "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
  2528. lq_sta->lq.initial_rate_index[0],
  2529. lq_sta->lq.initial_rate_index[1],
  2530. lq_sta->lq.initial_rate_index[2],
  2531. lq_sta->lq.initial_rate_index[3]);
  2532. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  2533. index = iwl_hwrate_to_plcp_idx(
  2534. le32_to_cpu(lq_sta->lq.rs_table[i]));
  2535. if (is_legacy(tbl->lq_type)) {
  2536. desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
  2537. i, le32_to_cpu(lq_sta->lq.rs_table[i]),
  2538. iwl_rate_mcs[index].mbps);
  2539. } else {
  2540. desc += sprintf(buff+desc,
  2541. " rate[%d] 0x%X %smbps (%s)\n",
  2542. i, le32_to_cpu(lq_sta->lq.rs_table[i]),
  2543. iwl_rate_mcs[index].mbps,
  2544. iwl_rate_mcs[index].mcs);
  2545. }
  2546. }
  2547. ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  2548. kfree(buff);
  2549. return ret;
  2550. }
  2551. static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
  2552. .write = rs_sta_dbgfs_scale_table_write,
  2553. .read = rs_sta_dbgfs_scale_table_read,
  2554. .open = simple_open,
  2555. .llseek = default_llseek,
  2556. };
  2557. static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
  2558. char __user *user_buf, size_t count, loff_t *ppos)
  2559. {
  2560. char *buff;
  2561. int desc = 0;
  2562. int i, j;
  2563. ssize_t ret;
  2564. struct iwl_lq_sta *lq_sta = file->private_data;
  2565. buff = kmalloc(1024, GFP_KERNEL);
  2566. if (!buff)
  2567. return -ENOMEM;
  2568. for (i = 0; i < LQ_SIZE; i++) {
  2569. desc += sprintf(buff+desc,
  2570. "%s type=%d SGI=%d HT40=%d DUP=0 GF=%d\n"
  2571. "rate=0x%X\n",
  2572. lq_sta->active_tbl == i ? "*" : "x",
  2573. lq_sta->lq_info[i].lq_type,
  2574. lq_sta->lq_info[i].is_SGI,
  2575. lq_sta->lq_info[i].is_ht40,
  2576. lq_sta->is_green,
  2577. lq_sta->lq_info[i].current_rate);
  2578. for (j = 0; j < IWL_RATE_COUNT; j++) {
  2579. desc += sprintf(buff+desc,
  2580. "counter=%d success=%d %%=%d\n",
  2581. lq_sta->lq_info[i].win[j].counter,
  2582. lq_sta->lq_info[i].win[j].success_counter,
  2583. lq_sta->lq_info[i].win[j].success_ratio);
  2584. }
  2585. }
  2586. ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  2587. kfree(buff);
  2588. return ret;
  2589. }
  2590. static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
  2591. .read = rs_sta_dbgfs_stats_table_read,
  2592. .open = simple_open,
  2593. .llseek = default_llseek,
  2594. };
  2595. static ssize_t rs_sta_dbgfs_rate_scale_data_read(struct file *file,
  2596. char __user *user_buf, size_t count, loff_t *ppos)
  2597. {
  2598. struct iwl_lq_sta *lq_sta = file->private_data;
  2599. struct iwl_scale_tbl_info *tbl = &lq_sta->lq_info[lq_sta->active_tbl];
  2600. char buff[120];
  2601. int desc = 0;
  2602. if (is_Ht(tbl->lq_type))
  2603. desc += sprintf(buff+desc,
  2604. "Bit Rate= %d Mb/s\n",
  2605. tbl->expected_tpt[lq_sta->last_txrate_idx]);
  2606. else
  2607. desc += sprintf(buff+desc,
  2608. "Bit Rate= %d Mb/s\n",
  2609. iwl_rates[lq_sta->last_txrate_idx].ieee >> 1);
  2610. return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  2611. }
  2612. static const struct file_operations rs_sta_dbgfs_rate_scale_data_ops = {
  2613. .read = rs_sta_dbgfs_rate_scale_data_read,
  2614. .open = simple_open,
  2615. .llseek = default_llseek,
  2616. };
  2617. static void rs_add_debugfs(void *mvm, void *mvm_sta, struct dentry *dir)
  2618. {
  2619. struct iwl_lq_sta *lq_sta = mvm_sta;
  2620. lq_sta->rs_sta_dbgfs_scale_table_file =
  2621. debugfs_create_file("rate_scale_table", S_IRUSR | S_IWUSR, dir,
  2622. lq_sta, &rs_sta_dbgfs_scale_table_ops);
  2623. lq_sta->rs_sta_dbgfs_stats_table_file =
  2624. debugfs_create_file("rate_stats_table", S_IRUSR, dir,
  2625. lq_sta, &rs_sta_dbgfs_stats_table_ops);
  2626. lq_sta->rs_sta_dbgfs_rate_scale_data_file =
  2627. debugfs_create_file("rate_scale_data", S_IRUSR, dir,
  2628. lq_sta, &rs_sta_dbgfs_rate_scale_data_ops);
  2629. lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file =
  2630. debugfs_create_u8("tx_agg_tid_enable", S_IRUSR | S_IWUSR, dir,
  2631. &lq_sta->tx_agg_tid_en);
  2632. }
  2633. static void rs_remove_debugfs(void *mvm, void *mvm_sta)
  2634. {
  2635. struct iwl_lq_sta *lq_sta = mvm_sta;
  2636. debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file);
  2637. debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file);
  2638. debugfs_remove(lq_sta->rs_sta_dbgfs_rate_scale_data_file);
  2639. debugfs_remove(lq_sta->rs_sta_dbgfs_tx_agg_tid_en_file);
  2640. }
  2641. #endif
  2642. /*
  2643. * Initialization of rate scaling information is done by driver after
  2644. * the station is added. Since mac80211 calls this function before a
  2645. * station is added we ignore it.
  2646. */
  2647. static void rs_rate_init_stub(void *mvm_r,
  2648. struct ieee80211_supported_band *sband,
  2649. struct ieee80211_sta *sta, void *mvm_sta)
  2650. {
  2651. }
  2652. static struct rate_control_ops rs_mvm_ops = {
  2653. .module = NULL,
  2654. .name = RS_NAME,
  2655. .tx_status = rs_tx_status,
  2656. .get_rate = rs_get_rate,
  2657. .rate_init = rs_rate_init_stub,
  2658. .alloc = rs_alloc,
  2659. .free = rs_free,
  2660. .alloc_sta = rs_alloc_sta,
  2661. .free_sta = rs_free_sta,
  2662. #ifdef CONFIG_MAC80211_DEBUGFS
  2663. .add_sta_debugfs = rs_add_debugfs,
  2664. .remove_sta_debugfs = rs_remove_debugfs,
  2665. #endif
  2666. };
  2667. int iwl_mvm_rate_control_register(void)
  2668. {
  2669. return ieee80211_rate_control_register(&rs_mvm_ops);
  2670. }
  2671. void iwl_mvm_rate_control_unregister(void)
  2672. {
  2673. ieee80211_rate_control_unregister(&rs_mvm_ops);
  2674. }