iwl-agn-rs.c 90 KB

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