iwl-agn-rs.c 77 KB

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