iwl-4965-rs.c 77 KB

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