iwl-4965-rs.c 77 KB

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