iwl-4965-rs.c 77 KB

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