iwl-agn-rs.c 90 KB

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