iwl-4965-rs.c 77 KB

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