iwl-agn-rs.c 77 KB

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