iwl-agn-rs.c 90 KB

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