iwl-4965-rs.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/skbuff.h>
  29. #include <linux/wireless.h>
  30. #include <net/mac80211.h>
  31. #include <net/ieee80211.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/delay.h>
  35. #include <linux/workqueue.h>
  36. #define IWL 4965
  37. #include "../net/mac80211/ieee80211_rate.h"
  38. #include "iwlwifi.h"
  39. #include "iwl-helpers.h"
  40. #define RS_NAME "iwl-4965-rs"
  41. #define NUM_TRY_BEFORE_ANTENNA_TOGGLE 1
  42. #define IWL_NUMBER_TRY 1
  43. #define IWL_HT_NUMBER_TRY 3
  44. #define IWL_RATE_MAX_WINDOW 62
  45. #define IWL_RATE_HIGH_TH 10880
  46. #define IWL_RATE_MIN_FAILURE_TH 6
  47. #define IWL_RATE_MIN_SUCCESS_TH 8
  48. #define IWL_RATE_DECREASE_TH 1920
  49. #define IWL_RATE_INCREASE_TH 8960
  50. #define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ) /*2 seconds */
  51. static u8 rs_ht_to_legacy[] = {
  52. IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
  53. IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
  54. IWL_RATE_6M_INDEX,
  55. IWL_RATE_6M_INDEX, IWL_RATE_9M_INDEX,
  56. IWL_RATE_12M_INDEX, IWL_RATE_18M_INDEX,
  57. IWL_RATE_24M_INDEX, IWL_RATE_36M_INDEX,
  58. IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX
  59. };
  60. struct iwl_rate {
  61. u32 rate_n_flags;
  62. } __attribute__ ((packed));
  63. struct iwl_rate_scale_data {
  64. u64 data;
  65. s32 success_counter;
  66. s32 success_ratio;
  67. s32 counter;
  68. s32 average_tpt;
  69. unsigned long stamp;
  70. };
  71. struct iwl_scale_tbl_info {
  72. enum iwl_table_type lq_type;
  73. enum iwl_antenna_type antenna_type;
  74. u8 is_SGI;
  75. u8 is_fat;
  76. u8 is_dup;
  77. u8 action;
  78. s32 *expected_tpt;
  79. struct iwl_rate current_rate;
  80. struct iwl_rate_scale_data win[IWL_RATE_COUNT];
  81. };
  82. struct iwl_rate_scale_priv {
  83. u8 active_tbl;
  84. u8 enable_counter;
  85. u8 stay_in_tbl;
  86. u8 search_better_tbl;
  87. s32 last_tpt;
  88. u32 table_count_limit;
  89. u32 max_failure_limit;
  90. u32 max_success_limit;
  91. u32 table_count;
  92. u32 total_failed;
  93. u32 total_success;
  94. u32 flush_timer;
  95. u8 action_counter;
  96. u8 antenna;
  97. u8 valid_antenna;
  98. u8 is_green;
  99. u8 is_dup;
  100. u8 phymode;
  101. u8 ibss_sta_added;
  102. u32 supp_rates;
  103. u16 active_rate;
  104. u16 active_siso_rate;
  105. u16 active_mimo_rate;
  106. u16 active_rate_basic;
  107. struct iwl_link_quality_cmd lq;
  108. struct iwl_scale_tbl_info lq_info[LQ_SIZE];
  109. #ifdef CONFIG_MAC80211_DEBUGFS
  110. struct dentry *rs_sta_dbgfs_scale_table_file;
  111. struct dentry *rs_sta_dbgfs_stats_table_file;
  112. struct iwl_rate dbg_fixed;
  113. struct iwl_priv *drv;
  114. #endif
  115. };
  116. static void rs_rate_scale_perform(struct iwl_priv *priv,
  117. struct net_device *dev,
  118. struct ieee80211_hdr *hdr,
  119. struct sta_info *sta);
  120. static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data,
  121. struct iwl_rate *tx_mcs,
  122. struct iwl_link_quality_cmd *tbl);
  123. #ifdef CONFIG_MAC80211_DEBUGFS
  124. static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,
  125. struct iwl_rate *mcs, int index);
  126. #else
  127. static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,
  128. struct iwl_rate *mcs, int index)
  129. {}
  130. #endif
  131. static s32 expected_tpt_A[IWL_RATE_COUNT] = {
  132. 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
  133. };
  134. static s32 expected_tpt_G[IWL_RATE_COUNT] = {
  135. 7, 13, 35, 58, 40, 57, 72, 98, 121, 154, 177, 186, 186
  136. };
  137. static s32 expected_tpt_siso20MHz[IWL_RATE_COUNT] = {
  138. 0, 0, 0, 0, 42, 42, 76, 102, 124, 159, 183, 193, 202
  139. };
  140. static s32 expected_tpt_siso20MHzSGI[IWL_RATE_COUNT] = {
  141. 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
  142. };
  143. static s32 expected_tpt_mimo20MHz[IWL_RATE_COUNT] = {
  144. 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
  145. };
  146. static s32 expected_tpt_mimo20MHzSGI[IWL_RATE_COUNT] = {
  147. 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
  148. };
  149. static s32 expected_tpt_siso40MHz[IWL_RATE_COUNT] = {
  150. 0, 0, 0, 0, 77, 77, 127, 160, 184, 220, 242, 250, 257
  151. };
  152. static s32 expected_tpt_siso40MHzSGI[IWL_RATE_COUNT] = {
  153. 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
  154. };
  155. static s32 expected_tpt_mimo40MHz[IWL_RATE_COUNT] = {
  156. 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
  157. };
  158. static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = {
  159. 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
  160. };
  161. static int iwl_lq_sync_callback(struct iwl_priv *priv,
  162. struct iwl_cmd *cmd, struct sk_buff *skb)
  163. {
  164. /*We didn't cache the SKB; let the caller free it */
  165. return 1;
  166. }
  167. static inline u8 iwl_rate_get_rate(u32 rate_n_flags)
  168. {
  169. return (u8)(rate_n_flags & 0xFF);
  170. }
  171. static int rs_send_lq_cmd(struct iwl_priv *priv,
  172. struct iwl_link_quality_cmd *lq, u8 flags)
  173. {
  174. #ifdef CONFIG_IWLWIFI_DEBUG
  175. int i;
  176. #endif
  177. struct iwl_host_cmd cmd = {
  178. .id = REPLY_TX_LINK_QUALITY_CMD,
  179. .len = sizeof(struct iwl_link_quality_cmd),
  180. .meta.flags = flags,
  181. .data = lq,
  182. };
  183. if ((lq->sta_id == 0xFF) &&
  184. (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
  185. return -EINVAL;
  186. if (lq->sta_id == 0xFF)
  187. lq->sta_id = IWL_AP_ID;
  188. IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
  189. IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
  190. lq->general_params.single_stream_ant_msk,
  191. lq->general_params.dual_stream_ant_msk);
  192. #ifdef CONFIG_IWLWIFI_DEBUG
  193. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  194. IWL_DEBUG_RATE("lq index %d 0x%X\n",
  195. i, lq->rs_table[i].rate_n_flags);
  196. #endif
  197. if (flags & CMD_ASYNC)
  198. cmd.meta.u.callback = iwl_lq_sync_callback;
  199. if (iwl_is_associated(priv) && priv->assoc_station_added &&
  200. priv->lq_mngr.lq_ready)
  201. return iwl_send_cmd(priv, &cmd);
  202. return 0;
  203. }
  204. static void rs_rate_scale_clear_window(struct iwl_rate_scale_data *window)
  205. {
  206. window->data = 0;
  207. window->success_counter = 0;
  208. window->success_ratio = IWL_INVALID_VALUE;
  209. window->counter = 0;
  210. window->average_tpt = IWL_INVALID_VALUE;
  211. window->stamp = 0;
  212. }
  213. static int rs_collect_tx_data(struct iwl_rate_scale_data *windows,
  214. int scale_index, s32 tpt, u32 status)
  215. {
  216. struct iwl_rate_scale_data *window = NULL;
  217. u64 mask;
  218. u8 win_size = IWL_RATE_MAX_WINDOW;
  219. s32 fail_count;
  220. if (scale_index < 0 || scale_index >= IWL_RATE_COUNT)
  221. return -EINVAL;
  222. window = &(windows[scale_index]);
  223. if (window->counter >= win_size) {
  224. window->counter = win_size - 1;
  225. mask = 1;
  226. mask = (mask << (win_size - 1));
  227. if ((window->data & mask)) {
  228. window->data &= ~mask;
  229. window->success_counter = window->success_counter - 1;
  230. }
  231. }
  232. window->counter = window->counter + 1;
  233. mask = window->data;
  234. window->data = (mask << 1);
  235. if (status != 0) {
  236. window->success_counter = window->success_counter + 1;
  237. window->data |= 0x1;
  238. }
  239. if (window->counter > 0)
  240. window->success_ratio = 128 * (100 * window->success_counter)
  241. / window->counter;
  242. else
  243. window->success_ratio = IWL_INVALID_VALUE;
  244. fail_count = window->counter - window->success_counter;
  245. if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) ||
  246. (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH))
  247. window->average_tpt = (window->success_ratio * tpt + 64) / 128;
  248. else
  249. window->average_tpt = IWL_INVALID_VALUE;
  250. window->stamp = jiffies;
  251. return 0;
  252. }
  253. static void rs_mcs_from_tbl(struct iwl_rate *mcs_rate,
  254. struct iwl_scale_tbl_info *tbl,
  255. int index, u8 use_green)
  256. {
  257. if (is_legacy(tbl->lq_type)) {
  258. mcs_rate->rate_n_flags = iwl_rates[index].plcp;
  259. if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
  260. mcs_rate->rate_n_flags |= RATE_MCS_CCK_MSK;
  261. } else if (is_siso(tbl->lq_type)) {
  262. if (index > IWL_LAST_OFDM_RATE)
  263. index = IWL_LAST_OFDM_RATE;
  264. mcs_rate->rate_n_flags = iwl_rates[index].plcp_siso |
  265. RATE_MCS_HT_MSK;
  266. } else {
  267. if (index > IWL_LAST_OFDM_RATE)
  268. index = IWL_LAST_OFDM_RATE;
  269. mcs_rate->rate_n_flags = iwl_rates[index].plcp_mimo |
  270. RATE_MCS_HT_MSK;
  271. }
  272. switch (tbl->antenna_type) {
  273. case ANT_BOTH:
  274. mcs_rate->rate_n_flags |= RATE_MCS_ANT_AB_MSK;
  275. break;
  276. case ANT_MAIN:
  277. mcs_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
  278. break;
  279. case ANT_AUX:
  280. mcs_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
  281. break;
  282. case ANT_NONE:
  283. break;
  284. }
  285. if (is_legacy(tbl->lq_type))
  286. return;
  287. if (tbl->is_fat) {
  288. if (tbl->is_dup)
  289. mcs_rate->rate_n_flags |= RATE_MCS_DUP_MSK;
  290. else
  291. mcs_rate->rate_n_flags |= RATE_MCS_FAT_MSK;
  292. }
  293. if (tbl->is_SGI)
  294. mcs_rate->rate_n_flags |= RATE_MCS_SGI_MSK;
  295. if (use_green) {
  296. mcs_rate->rate_n_flags |= RATE_MCS_GF_MSK;
  297. if (is_siso(tbl->lq_type))
  298. mcs_rate->rate_n_flags &= ~RATE_MCS_SGI_MSK;
  299. }
  300. }
  301. static int rs_get_tbl_info_from_mcs(const struct iwl_rate *mcs_rate,
  302. int phymode, struct iwl_scale_tbl_info *tbl,
  303. int *rate_idx)
  304. {
  305. int index;
  306. u32 ant_msk;
  307. index = iwl_rate_index_from_plcp(mcs_rate->rate_n_flags);
  308. if (index == IWL_RATE_INVALID) {
  309. *rate_idx = -1;
  310. return -EINVAL;
  311. }
  312. tbl->is_SGI = 0;
  313. tbl->is_fat = 0;
  314. tbl->is_dup = 0;
  315. tbl->antenna_type = ANT_BOTH;
  316. if (!(mcs_rate->rate_n_flags & RATE_MCS_HT_MSK)) {
  317. ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
  318. if (ant_msk == RATE_MCS_ANT_AB_MSK)
  319. tbl->lq_type = LQ_NONE;
  320. else {
  321. if (phymode == MODE_IEEE80211A)
  322. tbl->lq_type = LQ_A;
  323. else
  324. tbl->lq_type = LQ_G;
  325. if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
  326. tbl->antenna_type = ANT_MAIN;
  327. else
  328. tbl->antenna_type = ANT_AUX;
  329. }
  330. *rate_idx = index;
  331. } else if (iwl_rate_get_rate(mcs_rate->rate_n_flags)
  332. <= IWL_RATE_SISO_60M_PLCP) {
  333. tbl->lq_type = LQ_SISO;
  334. ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
  335. if (ant_msk == RATE_MCS_ANT_AB_MSK)
  336. tbl->lq_type = LQ_NONE;
  337. else {
  338. if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
  339. tbl->antenna_type = ANT_MAIN;
  340. else
  341. tbl->antenna_type = ANT_AUX;
  342. }
  343. if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
  344. tbl->is_SGI = 1;
  345. if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
  346. (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
  347. tbl->is_fat = 1;
  348. if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
  349. tbl->is_dup = 1;
  350. *rate_idx = index;
  351. } else {
  352. tbl->lq_type = LQ_MIMO;
  353. if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
  354. tbl->is_SGI = 1;
  355. if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
  356. (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
  357. tbl->is_fat = 1;
  358. if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
  359. tbl->is_dup = 1;
  360. *rate_idx = index;
  361. }
  362. return 0;
  363. }
  364. static inline void rs_toggle_antenna(struct iwl_rate *new_rate,
  365. struct iwl_scale_tbl_info *tbl)
  366. {
  367. if (tbl->antenna_type == ANT_AUX) {
  368. tbl->antenna_type = ANT_MAIN;
  369. new_rate->rate_n_flags &= ~RATE_MCS_ANT_B_MSK;
  370. new_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
  371. } else {
  372. tbl->antenna_type = ANT_AUX;
  373. new_rate->rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
  374. new_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
  375. }
  376. }
  377. static inline u8 rs_use_green(struct iwl_priv *priv)
  378. {
  379. #ifdef CONFIG_IWLWIFI_HT
  380. if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
  381. return 0;
  382. return ((priv->current_assoc_ht.is_green_field) &&
  383. !(priv->current_assoc_ht.operating_mode & 0x4));
  384. #endif /*CONFIG_IWLWIFI_HT */
  385. return 0;
  386. }
  387. /**
  388. * rs_get_supported_rates - get the available rates
  389. *
  390. * if management frame or broadcast frame only return
  391. * basic available rates.
  392. *
  393. */
  394. static void rs_get_supported_rates(struct iwl_rate_scale_priv *lq_data,
  395. struct ieee80211_hdr *hdr,
  396. enum iwl_table_type rate_type,
  397. u16 *data_rate)
  398. {
  399. if (is_legacy(rate_type))
  400. *data_rate = lq_data->active_rate;
  401. else {
  402. if (is_siso(rate_type))
  403. *data_rate = lq_data->active_siso_rate;
  404. else
  405. *data_rate = lq_data->active_mimo_rate;
  406. }
  407. if (hdr && is_multicast_ether_addr(hdr->addr1) &&
  408. lq_data->active_rate_basic)
  409. *data_rate = lq_data->active_rate_basic;
  410. }
  411. static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
  412. {
  413. u8 high = IWL_RATE_INVALID;
  414. u8 low = IWL_RATE_INVALID;
  415. /* 802.11A or ht walks to the next literal adjacent rate in
  416. * the rate table */
  417. if (is_a_band(rate_type) || !is_legacy(rate_type)) {
  418. int i;
  419. u32 mask;
  420. /* Find the previous rate that is in the rate mask */
  421. i = index - 1;
  422. for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
  423. if (rate_mask & mask) {
  424. low = i;
  425. break;
  426. }
  427. }
  428. /* Find the next rate that is in the rate mask */
  429. i = index + 1;
  430. for (mask = (1 << i); i < IWL_RATE_COUNT; i++, mask <<= 1) {
  431. if (rate_mask & mask) {
  432. high = i;
  433. break;
  434. }
  435. }
  436. return (high << 8) | low;
  437. }
  438. low = index;
  439. while (low != IWL_RATE_INVALID) {
  440. low = iwl_rates[low].prev_rs;
  441. if (low == IWL_RATE_INVALID)
  442. break;
  443. if (rate_mask & (1 << low))
  444. break;
  445. IWL_DEBUG_RATE("Skipping masked lower rate: %d\n", low);
  446. }
  447. high = index;
  448. while (high != IWL_RATE_INVALID) {
  449. high = iwl_rates[high].next_rs;
  450. if (high == IWL_RATE_INVALID)
  451. break;
  452. if (rate_mask & (1 << high))
  453. break;
  454. IWL_DEBUG_RATE("Skipping masked higher rate: %d\n", high);
  455. }
  456. return (high << 8) | low;
  457. }
  458. static void rs_get_lower_rate(struct iwl_rate_scale_priv *lq_data,
  459. struct iwl_scale_tbl_info *tbl, u8 scale_index,
  460. u8 ht_possible, struct iwl_rate *mcs_rate)
  461. {
  462. s32 low;
  463. u16 rate_mask;
  464. u16 high_low;
  465. u8 switch_to_legacy = 0;
  466. u8 is_green = lq_data->is_green;
  467. /* check if we need to switch from HT to legacy rates.
  468. * assumption is that mandatory rates (1Mbps or 6Mbps)
  469. * are always supported (spec demand) */
  470. if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) {
  471. switch_to_legacy = 1;
  472. scale_index = rs_ht_to_legacy[scale_index];
  473. if (lq_data->phymode == MODE_IEEE80211A)
  474. tbl->lq_type = LQ_A;
  475. else
  476. tbl->lq_type = LQ_G;
  477. if ((tbl->antenna_type == ANT_BOTH) ||
  478. (tbl->antenna_type == ANT_NONE))
  479. tbl->antenna_type = ANT_MAIN;
  480. tbl->is_fat = 0;
  481. tbl->is_SGI = 0;
  482. }
  483. rs_get_supported_rates(lq_data, NULL, tbl->lq_type, &rate_mask);
  484. /* mask with station rate restriction */
  485. if (is_legacy(tbl->lq_type)) {
  486. if (lq_data->phymode == (u8) MODE_IEEE80211A)
  487. rate_mask = (u16)(rate_mask &
  488. (lq_data->supp_rates << IWL_FIRST_OFDM_RATE));
  489. else
  490. rate_mask = (u16)(rate_mask & lq_data->supp_rates);
  491. }
  492. /* if we did switched from HT to legacy check current rate */
  493. if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
  494. rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
  495. return;
  496. }
  497. high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type);
  498. low = high_low & 0xff;
  499. if (low != IWL_RATE_INVALID)
  500. rs_mcs_from_tbl(mcs_rate, tbl, low, is_green);
  501. else
  502. rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green);
  503. }
  504. static void rs_tx_status(void *priv_rate,
  505. struct net_device *dev,
  506. struct sk_buff *skb,
  507. struct ieee80211_tx_status *tx_resp)
  508. {
  509. int status;
  510. u8 retries;
  511. int rs_index, index = 0;
  512. struct iwl_rate_scale_priv *lq;
  513. struct iwl_link_quality_cmd *table;
  514. struct sta_info *sta;
  515. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  516. struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
  517. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  518. struct iwl_rate_scale_data *window = NULL;
  519. struct iwl_rate_scale_data *search_win = NULL;
  520. struct iwl_rate tx_mcs;
  521. struct iwl_scale_tbl_info tbl_type;
  522. struct iwl_scale_tbl_info *curr_tbl, *search_tbl;
  523. u8 active_index = 0;
  524. u16 fc = le16_to_cpu(hdr->frame_control);
  525. s32 tpt = 0;
  526. IWL_DEBUG_RATE_LIMIT("get frame ack response, update rate scale window\n");
  527. if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1))
  528. return;
  529. retries = tx_resp->retry_count;
  530. if (retries > 15)
  531. retries = 15;
  532. sta = sta_info_get(local, hdr->addr1);
  533. if (!sta || !sta->rate_ctrl_priv) {
  534. if (sta)
  535. sta_info_put(sta);
  536. return;
  537. }
  538. lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
  539. if (!priv->lq_mngr.lq_ready)
  540. return;
  541. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added)
  542. return;
  543. table = &lq->lq;
  544. active_index = lq->active_tbl;
  545. lq->antenna = (lq->valid_antenna & local->hw.conf.antenna_sel_tx);
  546. if (!lq->antenna)
  547. lq->antenna = lq->valid_antenna;
  548. lq->antenna = lq->valid_antenna;
  549. curr_tbl = &(lq->lq_info[active_index]);
  550. search_tbl = &(lq->lq_info[(1 - active_index)]);
  551. window = (struct iwl_rate_scale_data *)
  552. &(curr_tbl->win[0]);
  553. search_win = (struct iwl_rate_scale_data *)
  554. &(search_tbl->win[0]);
  555. tx_mcs.rate_n_flags = tx_resp->control.tx_rate;
  556. rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
  557. &tbl_type, &rs_index);
  558. if ((rs_index < 0) || (rs_index >= IWL_RATE_COUNT)) {
  559. IWL_DEBUG_RATE("bad rate index at: %d rate 0x%X\n",
  560. rs_index, tx_mcs.rate_n_flags);
  561. sta_info_put(sta);
  562. return;
  563. }
  564. if (retries &&
  565. (tx_mcs.rate_n_flags !=
  566. le32_to_cpu(table->rs_table[0].rate_n_flags))) {
  567. IWL_DEBUG_RATE("initial rate does not match 0x%x 0x%x\n",
  568. tx_mcs.rate_n_flags,
  569. le32_to_cpu(table->rs_table[0].rate_n_flags));
  570. sta_info_put(sta);
  571. return;
  572. }
  573. while (retries) {
  574. tx_mcs.rate_n_flags =
  575. le32_to_cpu(table->rs_table[index].rate_n_flags);
  576. rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
  577. &tbl_type, &rs_index);
  578. if ((tbl_type.lq_type == search_tbl->lq_type) &&
  579. (tbl_type.antenna_type == search_tbl->antenna_type) &&
  580. (tbl_type.is_SGI == search_tbl->is_SGI)) {
  581. if (search_tbl->expected_tpt)
  582. tpt = search_tbl->expected_tpt[rs_index];
  583. else
  584. tpt = 0;
  585. rs_collect_tx_data(search_win,
  586. rs_index, tpt, 0);
  587. } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
  588. (tbl_type.antenna_type == curr_tbl->antenna_type) &&
  589. (tbl_type.is_SGI == curr_tbl->is_SGI)) {
  590. if (curr_tbl->expected_tpt)
  591. tpt = curr_tbl->expected_tpt[rs_index];
  592. else
  593. tpt = 0;
  594. rs_collect_tx_data(window, rs_index, tpt, 0);
  595. }
  596. if (lq->stay_in_tbl)
  597. lq->total_failed++;
  598. --retries;
  599. index++;
  600. }
  601. if (!tx_resp->retry_count)
  602. tx_mcs.rate_n_flags = tx_resp->control.tx_rate;
  603. else
  604. tx_mcs.rate_n_flags =
  605. le32_to_cpu(table->rs_table[index].rate_n_flags);
  606. rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode,
  607. &tbl_type, &rs_index);
  608. if (tx_resp->flags & IEEE80211_TX_STATUS_ACK)
  609. status = 1;
  610. else
  611. status = 0;
  612. if ((tbl_type.lq_type == search_tbl->lq_type) &&
  613. (tbl_type.antenna_type == search_tbl->antenna_type) &&
  614. (tbl_type.is_SGI == search_tbl->is_SGI)) {
  615. if (search_tbl->expected_tpt)
  616. tpt = search_tbl->expected_tpt[rs_index];
  617. else
  618. tpt = 0;
  619. rs_collect_tx_data(search_win,
  620. rs_index, tpt, status);
  621. } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
  622. (tbl_type.antenna_type == curr_tbl->antenna_type) &&
  623. (tbl_type.is_SGI == curr_tbl->is_SGI)) {
  624. if (curr_tbl->expected_tpt)
  625. tpt = curr_tbl->expected_tpt[rs_index];
  626. else
  627. tpt = 0;
  628. rs_collect_tx_data(window, rs_index, tpt, status);
  629. }
  630. if (lq->stay_in_tbl) {
  631. if (status)
  632. lq->total_success++;
  633. else
  634. lq->total_failed++;
  635. }
  636. rs_rate_scale_perform(priv, dev, hdr, sta);
  637. sta_info_put(sta);
  638. return;
  639. }
  640. static u8 rs_is_ant_connected(u8 valid_antenna,
  641. enum iwl_antenna_type antenna_type)
  642. {
  643. if (antenna_type == ANT_AUX)
  644. return ((valid_antenna & 0x2) ? 1:0);
  645. else if (antenna_type == ANT_MAIN)
  646. return ((valid_antenna & 0x1) ? 1:0);
  647. else if (antenna_type == ANT_BOTH)
  648. return ((valid_antenna & 0x3) == 0x3);
  649. return 1;
  650. }
  651. static u8 rs_is_other_ant_connected(u8 valid_antenna,
  652. enum iwl_antenna_type antenna_type)
  653. {
  654. if (antenna_type == ANT_AUX)
  655. return rs_is_ant_connected(valid_antenna, ANT_MAIN);
  656. else
  657. return rs_is_ant_connected(valid_antenna, ANT_AUX);
  658. return 0;
  659. }
  660. static void rs_set_stay_in_table(u8 is_legacy,
  661. struct iwl_rate_scale_priv *lq_data)
  662. {
  663. IWL_DEBUG_HT("we are staying in the same table\n");
  664. lq_data->stay_in_tbl = 1;
  665. if (is_legacy) {
  666. lq_data->table_count_limit = IWL_LEGACY_TABLE_COUNT;
  667. lq_data->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT;
  668. lq_data->max_success_limit = IWL_LEGACY_TABLE_COUNT;
  669. } else {
  670. lq_data->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT;
  671. lq_data->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT;
  672. lq_data->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT;
  673. }
  674. lq_data->table_count = 0;
  675. lq_data->total_failed = 0;
  676. lq_data->total_success = 0;
  677. }
  678. static void rs_get_expected_tpt_table(struct iwl_rate_scale_priv *lq_data,
  679. struct iwl_scale_tbl_info *tbl)
  680. {
  681. if (is_legacy(tbl->lq_type)) {
  682. if (!is_a_band(tbl->lq_type))
  683. tbl->expected_tpt = expected_tpt_G;
  684. else
  685. tbl->expected_tpt = expected_tpt_A;
  686. } else if (is_siso(tbl->lq_type)) {
  687. if (tbl->is_fat && !lq_data->is_dup)
  688. if (tbl->is_SGI)
  689. tbl->expected_tpt = expected_tpt_siso40MHzSGI;
  690. else
  691. tbl->expected_tpt = expected_tpt_siso40MHz;
  692. else if (tbl->is_SGI)
  693. tbl->expected_tpt = expected_tpt_siso20MHzSGI;
  694. else
  695. tbl->expected_tpt = expected_tpt_siso20MHz;
  696. } else if (is_mimo(tbl->lq_type)) {
  697. if (tbl->is_fat && !lq_data->is_dup)
  698. if (tbl->is_SGI)
  699. tbl->expected_tpt = expected_tpt_mimo40MHzSGI;
  700. else
  701. tbl->expected_tpt = expected_tpt_mimo40MHz;
  702. else if (tbl->is_SGI)
  703. tbl->expected_tpt = expected_tpt_mimo20MHzSGI;
  704. else
  705. tbl->expected_tpt = expected_tpt_mimo20MHz;
  706. } else
  707. tbl->expected_tpt = expected_tpt_G;
  708. }
  709. #ifdef CONFIG_IWLWIFI_HT
  710. static s32 rs_get_best_rate(struct iwl_priv *priv,
  711. struct iwl_rate_scale_priv *lq_data,
  712. struct iwl_scale_tbl_info *tbl,
  713. u16 rate_mask, s8 index, s8 rate)
  714. {
  715. struct iwl_scale_tbl_info *active_tbl =
  716. &(lq_data->lq_info[lq_data->active_tbl]);
  717. s32 new_rate, high, low, start_hi;
  718. s32 active_sr = active_tbl->win[index].success_ratio;
  719. s32 *tpt_tbl = tbl->expected_tpt;
  720. s32 active_tpt = active_tbl->expected_tpt[index];
  721. u16 high_low;
  722. new_rate = high = low = start_hi = IWL_RATE_INVALID;
  723. for (; ;) {
  724. high_low = rs_get_adjacent_rate(rate, rate_mask, tbl->lq_type);
  725. low = high_low & 0xff;
  726. high = (high_low >> 8) & 0xff;
  727. if ((((100 * tpt_tbl[rate]) > lq_data->last_tpt) &&
  728. ((active_sr > IWL_RATE_DECREASE_TH) &&
  729. (active_sr <= IWL_RATE_HIGH_TH) &&
  730. (tpt_tbl[rate] <= active_tpt))) ||
  731. ((active_sr >= IWL_RATE_SCALE_SWITCH) &&
  732. (tpt_tbl[rate] > active_tpt))) {
  733. if (start_hi != IWL_RATE_INVALID) {
  734. new_rate = start_hi;
  735. break;
  736. }
  737. new_rate = rate;
  738. if (low != IWL_RATE_INVALID)
  739. rate = low;
  740. else
  741. break;
  742. } else {
  743. if (new_rate != IWL_RATE_INVALID)
  744. break;
  745. else if (high != IWL_RATE_INVALID) {
  746. start_hi = high;
  747. rate = high;
  748. } else {
  749. new_rate = rate;
  750. break;
  751. }
  752. }
  753. }
  754. return new_rate;
  755. }
  756. #endif /* CONFIG_IWLWIFI_HT */
  757. static inline u8 rs_is_both_ant_supp(u8 valid_antenna)
  758. {
  759. return (rs_is_ant_connected(valid_antenna, ANT_BOTH));
  760. }
  761. static int rs_switch_to_mimo(struct iwl_priv *priv,
  762. struct iwl_rate_scale_priv *lq_data,
  763. struct iwl_scale_tbl_info *tbl, int index)
  764. {
  765. #ifdef CONFIG_IWLWIFI_HT
  766. u16 rate_mask;
  767. s32 rate;
  768. s8 is_green = lq_data->is_green;
  769. if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
  770. return -1;
  771. IWL_DEBUG_HT("LQ: try to switch to MIMO\n");
  772. tbl->lq_type = LQ_MIMO;
  773. rs_get_supported_rates(lq_data, NULL, tbl->lq_type,
  774. &rate_mask);
  775. if (priv->current_assoc_ht.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC)
  776. return -1;
  777. if (!rs_is_both_ant_supp(lq_data->antenna))
  778. return -1;
  779. tbl->is_dup = lq_data->is_dup;
  780. tbl->action = 0;
  781. if (priv->current_channel_width == IWL_CHANNEL_WIDTH_40MHZ)
  782. tbl->is_fat = 1;
  783. else
  784. tbl->is_fat = 0;
  785. if (tbl->is_fat) {
  786. if (priv->current_assoc_ht.sgf & HT_SHORT_GI_40MHZ_ONLY)
  787. tbl->is_SGI = 1;
  788. else
  789. tbl->is_SGI = 0;
  790. } else if (priv->current_assoc_ht.sgf & HT_SHORT_GI_20MHZ_ONLY)
  791. tbl->is_SGI = 1;
  792. else
  793. tbl->is_SGI = 0;
  794. rs_get_expected_tpt_table(lq_data, tbl);
  795. rate = rs_get_best_rate(priv, lq_data, tbl, rate_mask, index, index);
  796. IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate, rate_mask);
  797. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask))
  798. return -1;
  799. rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
  800. IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
  801. tbl->current_rate.rate_n_flags, is_green);
  802. #endif /*CONFIG_IWLWIFI_HT */
  803. return 0;
  804. }
  805. static int rs_switch_to_siso(struct iwl_priv *priv,
  806. struct iwl_rate_scale_priv *lq_data,
  807. struct iwl_scale_tbl_info *tbl, int index)
  808. {
  809. #ifdef CONFIG_IWLWIFI_HT
  810. u16 rate_mask;
  811. u8 is_green = lq_data->is_green;
  812. s32 rate;
  813. IWL_DEBUG_HT("LQ: try to switch to SISO\n");
  814. if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht)
  815. return -1;
  816. tbl->is_dup = lq_data->is_dup;
  817. tbl->lq_type = LQ_SISO;
  818. tbl->action = 0;
  819. rs_get_supported_rates(lq_data, NULL, tbl->lq_type,
  820. &rate_mask);
  821. if (priv->current_channel_width == IWL_CHANNEL_WIDTH_40MHZ)
  822. tbl->is_fat = 1;
  823. else
  824. tbl->is_fat = 0;
  825. if (tbl->is_fat) {
  826. if (priv->current_assoc_ht.sgf & HT_SHORT_GI_40MHZ_ONLY)
  827. tbl->is_SGI = 1;
  828. else
  829. tbl->is_SGI = 0;
  830. } else if (priv->current_assoc_ht.sgf & HT_SHORT_GI_20MHZ_ONLY)
  831. tbl->is_SGI = 1;
  832. else
  833. tbl->is_SGI = 0;
  834. if (is_green)
  835. tbl->is_SGI = 0;
  836. rs_get_expected_tpt_table(lq_data, tbl);
  837. rate = rs_get_best_rate(priv, lq_data, tbl, rate_mask, index, index);
  838. IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate, rate_mask);
  839. if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
  840. IWL_DEBUG_HT("can not switch with index %d rate mask %x\n",
  841. rate, rate_mask);
  842. return -1;
  843. }
  844. rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green);
  845. IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n",
  846. tbl->current_rate.rate_n_flags, is_green);
  847. #endif /*CONFIG_IWLWIFI_HT */
  848. return 0;
  849. }
  850. static int rs_move_legacy_other(struct iwl_priv *priv,
  851. struct iwl_rate_scale_priv *lq_data,
  852. int index)
  853. {
  854. int ret = 0;
  855. struct iwl_scale_tbl_info *tbl =
  856. &(lq_data->lq_info[lq_data->active_tbl]);
  857. struct iwl_scale_tbl_info *search_tbl =
  858. &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
  859. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  860. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  861. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  862. u8 start_action = tbl->action;
  863. for (; ;) {
  864. switch (tbl->action) {
  865. case IWL_LEGACY_SWITCH_ANTENNA:
  866. IWL_DEBUG_HT("LQ Legacy switch Antenna\n");
  867. search_tbl->lq_type = LQ_NONE;
  868. lq_data->action_counter++;
  869. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  870. break;
  871. if (!rs_is_other_ant_connected(lq_data->antenna,
  872. tbl->antenna_type))
  873. break;
  874. memcpy(search_tbl, tbl, sz);
  875. rs_toggle_antenna(&(search_tbl->current_rate),
  876. search_tbl);
  877. rs_get_expected_tpt_table(lq_data, search_tbl);
  878. lq_data->search_better_tbl = 1;
  879. goto out;
  880. case IWL_LEGACY_SWITCH_SISO:
  881. IWL_DEBUG_HT("LQ: Legacy switch to SISO\n");
  882. memcpy(search_tbl, tbl, sz);
  883. search_tbl->lq_type = LQ_SISO;
  884. search_tbl->is_SGI = 0;
  885. search_tbl->is_fat = 0;
  886. ret = rs_switch_to_siso(priv, lq_data, search_tbl,
  887. index);
  888. if (!ret) {
  889. lq_data->search_better_tbl = 1;
  890. lq_data->action_counter = 0;
  891. goto out;
  892. }
  893. break;
  894. case IWL_LEGACY_SWITCH_MIMO:
  895. IWL_DEBUG_HT("LQ: Legacy switch MIMO\n");
  896. memcpy(search_tbl, tbl, sz);
  897. search_tbl->lq_type = LQ_MIMO;
  898. search_tbl->is_SGI = 0;
  899. search_tbl->is_fat = 0;
  900. search_tbl->antenna_type = ANT_BOTH;
  901. ret = rs_switch_to_mimo(priv, lq_data, search_tbl,
  902. index);
  903. if (!ret) {
  904. lq_data->search_better_tbl = 1;
  905. lq_data->action_counter = 0;
  906. goto out;
  907. }
  908. break;
  909. }
  910. tbl->action++;
  911. if (tbl->action > IWL_LEGACY_SWITCH_MIMO)
  912. tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
  913. if (tbl->action == start_action)
  914. break;
  915. }
  916. return 0;
  917. out:
  918. tbl->action++;
  919. if (tbl->action > IWL_LEGACY_SWITCH_MIMO)
  920. tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
  921. return 0;
  922. }
  923. static int rs_move_siso_to_other(struct iwl_priv *priv,
  924. struct iwl_rate_scale_priv *lq_data,
  925. int index)
  926. {
  927. int ret;
  928. u8 is_green = lq_data->is_green;
  929. struct iwl_scale_tbl_info *tbl =
  930. &(lq_data->lq_info[lq_data->active_tbl]);
  931. struct iwl_scale_tbl_info *search_tbl =
  932. &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
  933. struct iwl_rate_scale_data *window = &(tbl->win[index]);
  934. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  935. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  936. u8 start_action = tbl->action;
  937. for (;;) {
  938. lq_data->action_counter++;
  939. switch (tbl->action) {
  940. case IWL_SISO_SWITCH_ANTENNA:
  941. IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n");
  942. search_tbl->lq_type = LQ_NONE;
  943. if (window->success_ratio >= IWL_RS_GOOD_RATIO)
  944. break;
  945. if (!rs_is_other_ant_connected(lq_data->antenna,
  946. tbl->antenna_type))
  947. break;
  948. memcpy(search_tbl, tbl, sz);
  949. search_tbl->action = IWL_SISO_SWITCH_MIMO;
  950. rs_toggle_antenna(&(search_tbl->current_rate),
  951. search_tbl);
  952. lq_data->search_better_tbl = 1;
  953. goto out;
  954. case IWL_SISO_SWITCH_MIMO:
  955. IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO FROM SISO\n");
  956. memcpy(search_tbl, tbl, sz);
  957. search_tbl->lq_type = LQ_MIMO;
  958. search_tbl->is_SGI = 0;
  959. search_tbl->is_fat = 0;
  960. search_tbl->antenna_type = ANT_BOTH;
  961. ret = rs_switch_to_mimo(priv, lq_data, search_tbl,
  962. index);
  963. if (!ret) {
  964. lq_data->search_better_tbl = 1;
  965. goto out;
  966. }
  967. break;
  968. case IWL_SISO_SWITCH_GI:
  969. IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n");
  970. memcpy(search_tbl, tbl, sz);
  971. search_tbl->action = 0;
  972. if (search_tbl->is_SGI)
  973. search_tbl->is_SGI = 0;
  974. else if (!is_green)
  975. search_tbl->is_SGI = 1;
  976. else
  977. break;
  978. lq_data->search_better_tbl = 1;
  979. if ((tbl->lq_type == LQ_SISO) &&
  980. (tbl->is_SGI)) {
  981. s32 tpt = lq_data->last_tpt / 100;
  982. if (((!tbl->is_fat) &&
  983. (tpt >= expected_tpt_siso20MHz[index])) ||
  984. ((tbl->is_fat) &&
  985. (tpt >= expected_tpt_siso40MHz[index])))
  986. lq_data->search_better_tbl = 0;
  987. }
  988. rs_get_expected_tpt_table(lq_data, search_tbl);
  989. rs_mcs_from_tbl(&search_tbl->current_rate,
  990. search_tbl, index, is_green);
  991. goto out;
  992. }
  993. tbl->action++;
  994. if (tbl->action > IWL_SISO_SWITCH_GI)
  995. tbl->action = IWL_SISO_SWITCH_ANTENNA;
  996. if (tbl->action == start_action)
  997. break;
  998. }
  999. return 0;
  1000. out:
  1001. tbl->action++;
  1002. if (tbl->action > IWL_SISO_SWITCH_GI)
  1003. tbl->action = IWL_SISO_SWITCH_ANTENNA;
  1004. return 0;
  1005. }
  1006. static int rs_move_mimo_to_other(struct iwl_priv *priv,
  1007. struct iwl_rate_scale_priv *lq_data,
  1008. int index)
  1009. {
  1010. int ret;
  1011. s8 is_green = lq_data->is_green;
  1012. struct iwl_scale_tbl_info *tbl =
  1013. &(lq_data->lq_info[lq_data->active_tbl]);
  1014. struct iwl_scale_tbl_info *search_tbl =
  1015. &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
  1016. u32 sz = (sizeof(struct iwl_scale_tbl_info) -
  1017. (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
  1018. u8 start_action = tbl->action;
  1019. for (;;) {
  1020. lq_data->action_counter++;
  1021. switch (tbl->action) {
  1022. case IWL_MIMO_SWITCH_ANTENNA_A:
  1023. case IWL_MIMO_SWITCH_ANTENNA_B:
  1024. IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n");
  1025. memcpy(search_tbl, tbl, sz);
  1026. search_tbl->lq_type = LQ_SISO;
  1027. search_tbl->is_SGI = 0;
  1028. search_tbl->is_fat = 0;
  1029. if (tbl->action == IWL_MIMO_SWITCH_ANTENNA_A)
  1030. search_tbl->antenna_type = ANT_MAIN;
  1031. else
  1032. search_tbl->antenna_type = ANT_AUX;
  1033. ret = rs_switch_to_siso(priv, lq_data, search_tbl,
  1034. index);
  1035. if (!ret) {
  1036. lq_data->search_better_tbl = 1;
  1037. goto out;
  1038. }
  1039. break;
  1040. case IWL_MIMO_SWITCH_GI:
  1041. IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n");
  1042. memcpy(search_tbl, tbl, sz);
  1043. search_tbl->lq_type = LQ_MIMO;
  1044. search_tbl->antenna_type = ANT_BOTH;
  1045. search_tbl->action = 0;
  1046. if (search_tbl->is_SGI)
  1047. search_tbl->is_SGI = 0;
  1048. else
  1049. search_tbl->is_SGI = 1;
  1050. lq_data->search_better_tbl = 1;
  1051. if ((tbl->lq_type == LQ_MIMO) &&
  1052. (tbl->is_SGI)) {
  1053. s32 tpt = lq_data->last_tpt / 100;
  1054. if (((!tbl->is_fat) &&
  1055. (tpt >= expected_tpt_mimo20MHz[index])) ||
  1056. ((tbl->is_fat) &&
  1057. (tpt >= expected_tpt_mimo40MHz[index])))
  1058. lq_data->search_better_tbl = 0;
  1059. }
  1060. rs_get_expected_tpt_table(lq_data, search_tbl);
  1061. rs_mcs_from_tbl(&search_tbl->current_rate,
  1062. search_tbl, index, is_green);
  1063. goto out;
  1064. }
  1065. tbl->action++;
  1066. if (tbl->action > IWL_MIMO_SWITCH_GI)
  1067. tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
  1068. if (tbl->action == start_action)
  1069. break;
  1070. }
  1071. return 0;
  1072. out:
  1073. tbl->action++;
  1074. if (tbl->action > IWL_MIMO_SWITCH_GI)
  1075. tbl->action = IWL_MIMO_SWITCH_ANTENNA_A;
  1076. return 0;
  1077. }
  1078. static void rs_stay_in_table(struct iwl_rate_scale_priv *lq_data)
  1079. {
  1080. struct iwl_scale_tbl_info *tbl;
  1081. int i;
  1082. int active_tbl;
  1083. int flush_interval_passed = 0;
  1084. active_tbl = lq_data->active_tbl;
  1085. tbl = &(lq_data->lq_info[active_tbl]);
  1086. if (lq_data->stay_in_tbl) {
  1087. if (lq_data->flush_timer)
  1088. flush_interval_passed =
  1089. time_after(jiffies,
  1090. (unsigned long)(lq_data->flush_timer +
  1091. IWL_RATE_SCALE_FLUSH_INTVL));
  1092. flush_interval_passed = 0;
  1093. if ((lq_data->total_failed > lq_data->max_failure_limit) ||
  1094. (lq_data->total_success > lq_data->max_success_limit) ||
  1095. ((!lq_data->search_better_tbl) && (lq_data->flush_timer)
  1096. && (flush_interval_passed))) {
  1097. IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:",
  1098. lq_data->total_failed,
  1099. lq_data->total_success,
  1100. flush_interval_passed);
  1101. lq_data->stay_in_tbl = 0;
  1102. lq_data->total_failed = 0;
  1103. lq_data->total_success = 0;
  1104. lq_data->flush_timer = 0;
  1105. } else if (lq_data->table_count > 0) {
  1106. lq_data->table_count++;
  1107. if (lq_data->table_count >=
  1108. lq_data->table_count_limit) {
  1109. lq_data->table_count = 0;
  1110. IWL_DEBUG_HT("LQ: stay in table clear win\n");
  1111. for (i = 0; i < IWL_RATE_COUNT; i++)
  1112. rs_rate_scale_clear_window(
  1113. &(tbl->win[i]));
  1114. }
  1115. }
  1116. if (!lq_data->stay_in_tbl) {
  1117. for (i = 0; i < IWL_RATE_COUNT; i++)
  1118. rs_rate_scale_clear_window(&(tbl->win[i]));
  1119. }
  1120. }
  1121. }
  1122. static void rs_rate_scale_perform(struct iwl_priv *priv,
  1123. struct net_device *dev,
  1124. struct ieee80211_hdr *hdr,
  1125. struct sta_info *sta)
  1126. {
  1127. int low = IWL_RATE_INVALID;
  1128. int high = IWL_RATE_INVALID;
  1129. int index;
  1130. int i;
  1131. struct iwl_rate_scale_data *window = NULL;
  1132. int current_tpt = IWL_INVALID_VALUE;
  1133. int low_tpt = IWL_INVALID_VALUE;
  1134. int high_tpt = IWL_INVALID_VALUE;
  1135. u32 fail_count;
  1136. s8 scale_action = 0;
  1137. u16 fc, rate_mask;
  1138. u8 update_lq = 0;
  1139. struct iwl_rate_scale_priv *lq_data;
  1140. struct iwl_scale_tbl_info *tbl, *tbl1;
  1141. u16 rate_scale_index_msk = 0;
  1142. struct iwl_rate mcs_rate;
  1143. u8 is_green = 0;
  1144. u8 active_tbl = 0;
  1145. u8 done_search = 0;
  1146. u16 high_low;
  1147. IWL_DEBUG_RATE("rate scale calculate new rate for skb\n");
  1148. fc = le16_to_cpu(hdr->frame_control);
  1149. if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) {
  1150. /* Send management frames and broadcast/multicast data using
  1151. * lowest rate. */
  1152. /* TODO: this could probably be improved.. */
  1153. return;
  1154. }
  1155. if (!sta || !sta->rate_ctrl_priv)
  1156. return;
  1157. if (!priv->lq_mngr.lq_ready) {
  1158. IWL_DEBUG_RATE("still rate scaling not ready\n");
  1159. return;
  1160. }
  1161. lq_data = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
  1162. if (!lq_data->search_better_tbl)
  1163. active_tbl = lq_data->active_tbl;
  1164. else
  1165. active_tbl = 1 - lq_data->active_tbl;
  1166. tbl = &(lq_data->lq_info[active_tbl]);
  1167. is_green = lq_data->is_green;
  1168. index = sta->last_txrate;
  1169. IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index,
  1170. tbl->lq_type);
  1171. rs_get_supported_rates(lq_data, hdr, tbl->lq_type,
  1172. &rate_mask);
  1173. IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask);
  1174. /* mask with station rate restriction */
  1175. if (is_legacy(tbl->lq_type)) {
  1176. if (lq_data->phymode == (u8) MODE_IEEE80211A)
  1177. rate_scale_index_msk = (u16) (rate_mask &
  1178. (lq_data->supp_rates << IWL_FIRST_OFDM_RATE));
  1179. else
  1180. rate_scale_index_msk = (u16) (rate_mask &
  1181. lq_data->supp_rates);
  1182. } else
  1183. rate_scale_index_msk = rate_mask;
  1184. if (!rate_scale_index_msk)
  1185. rate_scale_index_msk = rate_mask;
  1186. if (index < 0 || !((1 << index) & rate_scale_index_msk)) {
  1187. index = IWL_INVALID_VALUE;
  1188. update_lq = 1;
  1189. /* get the lowest available rate */
  1190. for (i = 0; i <= IWL_RATE_COUNT; i++) {
  1191. if ((1 << i) & rate_scale_index_msk)
  1192. index = i;
  1193. }
  1194. if (index == IWL_INVALID_VALUE) {
  1195. IWL_WARNING("Can not find a suitable rate\n");
  1196. return;
  1197. }
  1198. }
  1199. if (!tbl->expected_tpt)
  1200. rs_get_expected_tpt_table(lq_data, tbl);
  1201. window = &(tbl->win[index]);
  1202. fail_count = window->counter - window->success_counter;
  1203. if (((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
  1204. (window->success_counter < IWL_RATE_MIN_SUCCESS_TH))
  1205. || (tbl->expected_tpt == NULL)) {
  1206. IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
  1207. "for index %d\n",
  1208. window->success_counter, window->counter, index);
  1209. window->average_tpt = IWL_INVALID_VALUE;
  1210. rs_stay_in_table(lq_data);
  1211. if (update_lq) {
  1212. rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
  1213. rs_fill_link_cmd(lq_data, &mcs_rate, &lq_data->lq);
  1214. rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
  1215. }
  1216. goto out;
  1217. } else
  1218. window->average_tpt = ((window->success_ratio *
  1219. tbl->expected_tpt[index] + 64) / 128);
  1220. if (lq_data->search_better_tbl) {
  1221. int success_limit = IWL_RATE_SCALE_SWITCH;
  1222. if ((window->success_ratio > success_limit) ||
  1223. (window->average_tpt > lq_data->last_tpt)) {
  1224. if (!is_legacy(tbl->lq_type)) {
  1225. IWL_DEBUG_HT("LQ: we are switching to HT"
  1226. " rate suc %d current tpt %d"
  1227. " old tpt %d\n",
  1228. window->success_ratio,
  1229. window->average_tpt,
  1230. lq_data->last_tpt);
  1231. lq_data->enable_counter = 1;
  1232. }
  1233. lq_data->active_tbl = active_tbl;
  1234. current_tpt = window->average_tpt;
  1235. } else {
  1236. tbl->lq_type = LQ_NONE;
  1237. active_tbl = lq_data->active_tbl;
  1238. tbl = &(lq_data->lq_info[active_tbl]);
  1239. index = iwl_rate_index_from_plcp(
  1240. tbl->current_rate.rate_n_flags);
  1241. update_lq = 1;
  1242. current_tpt = lq_data->last_tpt;
  1243. IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
  1244. }
  1245. lq_data->search_better_tbl = 0;
  1246. done_search = 1;
  1247. goto lq_update;
  1248. }
  1249. high_low = rs_get_adjacent_rate(index, rate_scale_index_msk,
  1250. tbl->lq_type);
  1251. low = high_low & 0xff;
  1252. high = (high_low >> 8) & 0xff;
  1253. current_tpt = window->average_tpt;
  1254. if (low != IWL_RATE_INVALID)
  1255. low_tpt = tbl->win[low].average_tpt;
  1256. if (high != IWL_RATE_INVALID)
  1257. high_tpt = tbl->win[high].average_tpt;
  1258. scale_action = 1;
  1259. if ((window->success_ratio <= IWL_RATE_DECREASE_TH) ||
  1260. (current_tpt == 0)) {
  1261. IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
  1262. scale_action = -1;
  1263. } else if ((low_tpt == IWL_INVALID_VALUE) &&
  1264. (high_tpt == IWL_INVALID_VALUE))
  1265. scale_action = 1;
  1266. else if ((low_tpt != IWL_INVALID_VALUE) &&
  1267. (high_tpt != IWL_INVALID_VALUE) &&
  1268. (low_tpt < current_tpt) &&
  1269. (high_tpt < current_tpt))
  1270. scale_action = 0;
  1271. else {
  1272. if (high_tpt != IWL_INVALID_VALUE) {
  1273. if (high_tpt > current_tpt)
  1274. scale_action = 1;
  1275. else {
  1276. IWL_DEBUG_RATE
  1277. ("decrease rate because of high tpt\n");
  1278. scale_action = -1;
  1279. }
  1280. } else if (low_tpt != IWL_INVALID_VALUE) {
  1281. if (low_tpt > current_tpt) {
  1282. IWL_DEBUG_RATE
  1283. ("decrease rate because of low tpt\n");
  1284. scale_action = -1;
  1285. } else
  1286. scale_action = 1;
  1287. }
  1288. }
  1289. if (scale_action == -1) {
  1290. if ((low != IWL_RATE_INVALID) &&
  1291. ((window->success_ratio > IWL_RATE_HIGH_TH) ||
  1292. (current_tpt > (100 * tbl->expected_tpt[low]))))
  1293. scale_action = 0;
  1294. } else if ((scale_action == 1) &&
  1295. (window->success_ratio < IWL_RATE_INCREASE_TH))
  1296. scale_action = 0;
  1297. switch (scale_action) {
  1298. case -1:
  1299. if (low != IWL_RATE_INVALID) {
  1300. update_lq = 1;
  1301. index = low;
  1302. }
  1303. break;
  1304. case 1:
  1305. if (high != IWL_RATE_INVALID) {
  1306. update_lq = 1;
  1307. index = high;
  1308. }
  1309. break;
  1310. case 0:
  1311. default:
  1312. break;
  1313. }
  1314. IWL_DEBUG_HT("choose rate scale index %d action %d low %d "
  1315. "high %d type %d\n",
  1316. index, scale_action, low, high, tbl->lq_type);
  1317. lq_update:
  1318. if (update_lq) {
  1319. rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
  1320. rs_fill_link_cmd(lq_data, &mcs_rate, &lq_data->lq);
  1321. rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
  1322. }
  1323. rs_stay_in_table(lq_data);
  1324. if (!update_lq && !done_search && !lq_data->stay_in_tbl) {
  1325. lq_data->last_tpt = current_tpt;
  1326. if (is_legacy(tbl->lq_type))
  1327. rs_move_legacy_other(priv, lq_data, index);
  1328. else if (is_siso(tbl->lq_type))
  1329. rs_move_siso_to_other(priv, lq_data, index);
  1330. else
  1331. rs_move_mimo_to_other(priv, lq_data, index);
  1332. if (lq_data->search_better_tbl) {
  1333. tbl = &(lq_data->lq_info[(1 - lq_data->active_tbl)]);
  1334. for (i = 0; i < IWL_RATE_COUNT; i++)
  1335. rs_rate_scale_clear_window(&(tbl->win[i]));
  1336. index = iwl_rate_index_from_plcp(
  1337. tbl->current_rate.rate_n_flags);
  1338. IWL_DEBUG_HT("Switch current mcs: %X index: %d\n",
  1339. tbl->current_rate.rate_n_flags, index);
  1340. rs_fill_link_cmd(lq_data, &tbl->current_rate,
  1341. &lq_data->lq);
  1342. rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC);
  1343. }
  1344. tbl1 = &(lq_data->lq_info[lq_data->active_tbl]);
  1345. if (is_legacy(tbl1->lq_type) &&
  1346. #ifdef CONFIG_IWLWIFI_HT
  1347. !priv->current_assoc_ht.is_ht &&
  1348. #endif
  1349. (lq_data->action_counter >= 1)) {
  1350. lq_data->action_counter = 0;
  1351. IWL_DEBUG_HT("LQ: STAY in legacy table\n");
  1352. rs_set_stay_in_table(1, lq_data);
  1353. }
  1354. if (lq_data->enable_counter &&
  1355. (lq_data->action_counter >= IWL_ACTION_LIMIT)) {
  1356. #ifdef CONFIG_IWLWIFI_HT_AGG
  1357. if ((lq_data->last_tpt > TID_AGG_TPT_THREHOLD) &&
  1358. (priv->lq_mngr.agg_ctrl.auto_agg)) {
  1359. priv->lq_mngr.agg_ctrl.tid_retry =
  1360. TID_ALL_SPECIFIED;
  1361. schedule_work(&priv->agg_work);
  1362. }
  1363. #endif /*CONFIG_IWLWIFI_HT_AGG */
  1364. lq_data->action_counter = 0;
  1365. rs_set_stay_in_table(0, lq_data);
  1366. }
  1367. } else {
  1368. if ((!update_lq) && (!done_search) && (!lq_data->flush_timer))
  1369. lq_data->flush_timer = jiffies;
  1370. }
  1371. out:
  1372. rs_mcs_from_tbl(&tbl->current_rate, tbl, index, is_green);
  1373. i = index;
  1374. sta->last_txrate = i;
  1375. /* sta->txrate is an index to A mode rates which start
  1376. * at IWL_FIRST_OFDM_RATE
  1377. */
  1378. if (lq_data->phymode == (u8) MODE_IEEE80211A)
  1379. sta->txrate = i - IWL_FIRST_OFDM_RATE;
  1380. else
  1381. sta->txrate = i;
  1382. return;
  1383. }
  1384. static void rs_initialize_lq(struct iwl_priv *priv,
  1385. struct sta_info *sta)
  1386. {
  1387. int i;
  1388. struct iwl_rate_scale_priv *lq;
  1389. struct iwl_scale_tbl_info *tbl;
  1390. u8 active_tbl = 0;
  1391. int rate_idx;
  1392. u8 use_green = rs_use_green(priv);
  1393. struct iwl_rate mcs_rate;
  1394. if (!sta || !sta->rate_ctrl_priv)
  1395. goto out;
  1396. lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
  1397. i = sta->last_txrate;
  1398. if ((lq->lq.sta_id == 0xff) &&
  1399. (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
  1400. goto out;
  1401. if (!lq->search_better_tbl)
  1402. active_tbl = lq->active_tbl;
  1403. else
  1404. active_tbl = 1 - lq->active_tbl;
  1405. tbl = &(lq->lq_info[active_tbl]);
  1406. if ((i < 0) || (i >= IWL_RATE_COUNT))
  1407. i = 0;
  1408. mcs_rate.rate_n_flags = iwl_rates[i].plcp ;
  1409. mcs_rate.rate_n_flags |= RATE_MCS_ANT_B_MSK;
  1410. mcs_rate.rate_n_flags &= ~RATE_MCS_ANT_A_MSK;
  1411. if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
  1412. mcs_rate.rate_n_flags |= RATE_MCS_CCK_MSK;
  1413. tbl->antenna_type = ANT_AUX;
  1414. rs_get_tbl_info_from_mcs(&mcs_rate, priv->phymode, tbl, &rate_idx);
  1415. if (!rs_is_ant_connected(priv->valid_antenna, tbl->antenna_type))
  1416. rs_toggle_antenna(&mcs_rate, tbl);
  1417. rs_mcs_from_tbl(&mcs_rate, tbl, rate_idx, use_green);
  1418. tbl->current_rate.rate_n_flags = mcs_rate.rate_n_flags;
  1419. rs_get_expected_tpt_table(lq, tbl);
  1420. rs_fill_link_cmd(lq, &mcs_rate, &lq->lq);
  1421. rs_send_lq_cmd(priv, &lq->lq, CMD_ASYNC);
  1422. out:
  1423. return;
  1424. }
  1425. static void rs_get_rate(void *priv_rate, struct net_device *dev,
  1426. struct ieee80211_hw_mode *mode, struct sk_buff *skb,
  1427. struct rate_selection *sel)
  1428. {
  1429. int i;
  1430. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1431. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1432. struct sta_info *sta;
  1433. struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
  1434. struct iwl_rate_scale_priv *lq;
  1435. IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
  1436. sta = sta_info_get(local, hdr->addr1);
  1437. if (!sta || !sta->rate_ctrl_priv) {
  1438. sel->rate = rate_lowest(local, local->oper_hw_mode, sta);
  1439. if (sta)
  1440. sta_info_put(sta);
  1441. return;
  1442. }
  1443. lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv;
  1444. i = sta->last_txrate;
  1445. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added) {
  1446. u8 sta_id = iwl_hw_find_station(priv, hdr->addr1);
  1447. DECLARE_MAC_BUF(mac);
  1448. if (sta_id == IWL_INVALID_STATION) {
  1449. IWL_DEBUG_RATE("LQ: ADD station %s\n",
  1450. print_mac(mac, hdr->addr1));
  1451. sta_id = iwl_add_station(priv,
  1452. hdr->addr1, 0, CMD_ASYNC);
  1453. }
  1454. if ((sta_id != IWL_INVALID_STATION)) {
  1455. lq->lq.sta_id = sta_id;
  1456. lq->lq.rs_table[0].rate_n_flags = 0;
  1457. lq->ibss_sta_added = 1;
  1458. rs_initialize_lq(priv, sta);
  1459. }
  1460. if (!lq->ibss_sta_added)
  1461. goto done;
  1462. }
  1463. done:
  1464. if ((i < 0) || (i > IWL_RATE_COUNT)) {
  1465. sel->rate = rate_lowest(local, local->oper_hw_mode, sta);
  1466. return;
  1467. }
  1468. sta_info_put(sta);
  1469. sel->rate = &priv->ieee_rates[i];
  1470. }
  1471. static void *rs_alloc_sta(void *priv, gfp_t gfp)
  1472. {
  1473. struct iwl_rate_scale_priv *crl;
  1474. int i, j;
  1475. IWL_DEBUG_RATE("create station rate scale window\n");
  1476. crl = kzalloc(sizeof(struct iwl_rate_scale_priv), gfp);
  1477. if (crl == NULL)
  1478. return NULL;
  1479. crl->lq.sta_id = 0xff;
  1480. for (j = 0; j < LQ_SIZE; j++)
  1481. for (i = 0; i < IWL_RATE_COUNT; i++)
  1482. rs_rate_scale_clear_window(&(crl->lq_info[j].win[i]));
  1483. return crl;
  1484. }
  1485. static void rs_rate_init(void *priv_rate, void *priv_sta,
  1486. struct ieee80211_local *local,
  1487. struct sta_info *sta)
  1488. {
  1489. int i, j;
  1490. struct ieee80211_hw_mode *mode = local->oper_hw_mode;
  1491. struct iwl_priv *priv = (struct iwl_priv *)priv_rate;
  1492. struct iwl_rate_scale_priv *crl = priv_sta;
  1493. crl->flush_timer = 0;
  1494. crl->supp_rates = sta->supp_rates;
  1495. sta->txrate = 3;
  1496. for (j = 0; j < LQ_SIZE; j++)
  1497. for (i = 0; i < IWL_RATE_COUNT; i++)
  1498. rs_rate_scale_clear_window(&(crl->lq_info[j].win[i]));
  1499. IWL_DEBUG_RATE("rate scale global init\n");
  1500. /* TODO: what is a good starting rate for STA? About middle? Maybe not
  1501. * the lowest or the highest rate.. Could consider using RSSI from
  1502. * previous packets? Need to have IEEE 802.1X auth succeed immediately
  1503. * after assoc.. */
  1504. crl->ibss_sta_added = 0;
  1505. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  1506. u8 sta_id = iwl_hw_find_station(priv, sta->addr);
  1507. DECLARE_MAC_BUF(mac);
  1508. /* for IBSS the call are from tasklet */
  1509. IWL_DEBUG_HT("LQ: ADD station %s\n",
  1510. print_mac(mac, sta->addr));
  1511. if (sta_id == IWL_INVALID_STATION) {
  1512. IWL_DEBUG_RATE("LQ: ADD station %s\n",
  1513. print_mac(mac, sta->addr));
  1514. sta_id = iwl_add_station(priv,
  1515. sta->addr, 0, CMD_ASYNC);
  1516. }
  1517. if ((sta_id != IWL_INVALID_STATION)) {
  1518. crl->lq.sta_id = sta_id;
  1519. crl->lq.rs_table[0].rate_n_flags = 0;
  1520. }
  1521. /* FIXME: this is w/a remove it later */
  1522. priv->assoc_station_added = 1;
  1523. }
  1524. for (i = 0; i < mode->num_rates; i++) {
  1525. if ((sta->supp_rates & BIT(i)) &&
  1526. (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED))
  1527. sta->txrate = i;
  1528. }
  1529. sta->last_txrate = sta->txrate;
  1530. /* For MODE_IEEE80211A mode cck rate are at end
  1531. * rate table
  1532. */
  1533. if (local->hw.conf.phymode == MODE_IEEE80211A)
  1534. sta->last_txrate += IWL_FIRST_OFDM_RATE;
  1535. crl->is_dup = priv->is_dup;
  1536. crl->valid_antenna = priv->valid_antenna;
  1537. crl->antenna = priv->antenna;
  1538. crl->is_green = rs_use_green(priv);
  1539. crl->active_rate = priv->active_rate;
  1540. crl->active_rate &= ~(0x1000);
  1541. crl->active_rate_basic = priv->active_rate_basic;
  1542. crl->phymode = priv->phymode;
  1543. #ifdef CONFIG_IWLWIFI_HT
  1544. crl->active_siso_rate = (priv->current_assoc_ht.supp_rates[0] << 1);
  1545. crl->active_siso_rate |= (priv->current_assoc_ht.supp_rates[0] & 0x1);
  1546. crl->active_siso_rate &= ~((u16)0x2);
  1547. crl->active_siso_rate = crl->active_siso_rate << IWL_FIRST_OFDM_RATE;
  1548. crl->active_mimo_rate = (priv->current_assoc_ht.supp_rates[1] << 1);
  1549. crl->active_mimo_rate |= (priv->current_assoc_ht.supp_rates[1] & 0x1);
  1550. crl->active_mimo_rate &= ~((u16)0x2);
  1551. crl->active_mimo_rate = crl->active_mimo_rate << IWL_FIRST_OFDM_RATE;
  1552. IWL_DEBUG_HT("MIMO RATE 0x%X SISO MASK 0x%X\n", crl->active_siso_rate,
  1553. crl->active_mimo_rate);
  1554. #endif /*CONFIG_IWLWIFI_HT*/
  1555. #ifdef CONFIG_MAC80211_DEBUGFS
  1556. crl->drv = priv;
  1557. #endif
  1558. if (priv->assoc_station_added)
  1559. priv->lq_mngr.lq_ready = 1;
  1560. rs_initialize_lq(priv, sta);
  1561. }
  1562. static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data,
  1563. struct iwl_rate *tx_mcs,
  1564. struct iwl_link_quality_cmd *lq_cmd)
  1565. {
  1566. int index = 0;
  1567. int rate_idx;
  1568. int repeat_rate = 0;
  1569. u8 ant_toggle_count = 0;
  1570. u8 use_ht_possible = 1;
  1571. struct iwl_rate new_rate;
  1572. struct iwl_scale_tbl_info tbl_type = { 0 };
  1573. rs_dbgfs_set_mcs(lq_data, tx_mcs, index);
  1574. rs_get_tbl_info_from_mcs(tx_mcs, lq_data->phymode,
  1575. &tbl_type, &rate_idx);
  1576. if (is_legacy(tbl_type.lq_type)) {
  1577. ant_toggle_count = 1;
  1578. repeat_rate = IWL_NUMBER_TRY;
  1579. } else
  1580. repeat_rate = IWL_HT_NUMBER_TRY;
  1581. lq_cmd->general_params.mimo_delimiter =
  1582. is_mimo(tbl_type.lq_type) ? 1 : 0;
  1583. lq_cmd->rs_table[index].rate_n_flags =
  1584. cpu_to_le32(tx_mcs->rate_n_flags);
  1585. new_rate.rate_n_flags = tx_mcs->rate_n_flags;
  1586. if (is_mimo(tbl_type.lq_type) || (tbl_type.antenna_type == ANT_MAIN))
  1587. lq_cmd->general_params.single_stream_ant_msk = 1;
  1588. else
  1589. lq_cmd->general_params.single_stream_ant_msk = 2;
  1590. index++;
  1591. repeat_rate--;
  1592. while (index < LINK_QUAL_MAX_RETRY_NUM) {
  1593. while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
  1594. if (is_legacy(tbl_type.lq_type)) {
  1595. if (ant_toggle_count <
  1596. NUM_TRY_BEFORE_ANTENNA_TOGGLE)
  1597. ant_toggle_count++;
  1598. else {
  1599. rs_toggle_antenna(&new_rate, &tbl_type);
  1600. ant_toggle_count = 1;
  1601. }
  1602. }
  1603. rs_dbgfs_set_mcs(lq_data, &new_rate, index);
  1604. lq_cmd->rs_table[index].rate_n_flags =
  1605. cpu_to_le32(new_rate.rate_n_flags);
  1606. repeat_rate--;
  1607. index++;
  1608. }
  1609. rs_get_tbl_info_from_mcs(&new_rate, lq_data->phymode, &tbl_type,
  1610. &rate_idx);
  1611. if (is_mimo(tbl_type.lq_type))
  1612. lq_cmd->general_params.mimo_delimiter = index;
  1613. rs_get_lower_rate(lq_data, &tbl_type, rate_idx,
  1614. use_ht_possible, &new_rate);
  1615. if (is_legacy(tbl_type.lq_type)) {
  1616. if (ant_toggle_count < NUM_TRY_BEFORE_ANTENNA_TOGGLE)
  1617. ant_toggle_count++;
  1618. else {
  1619. rs_toggle_antenna(&new_rate, &tbl_type);
  1620. ant_toggle_count = 1;
  1621. }
  1622. repeat_rate = IWL_NUMBER_TRY;
  1623. } else
  1624. repeat_rate = IWL_HT_NUMBER_TRY;
  1625. use_ht_possible = 0;
  1626. rs_dbgfs_set_mcs(lq_data, &new_rate, index);
  1627. lq_cmd->rs_table[index].rate_n_flags =
  1628. cpu_to_le32(new_rate.rate_n_flags);
  1629. index++;
  1630. repeat_rate--;
  1631. }
  1632. lq_cmd->general_params.dual_stream_ant_msk = 3;
  1633. lq_cmd->agg_params.agg_dis_start_th = 3;
  1634. lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);
  1635. }
  1636. static void *rs_alloc(struct ieee80211_local *local)
  1637. {
  1638. return local->hw.priv;
  1639. }
  1640. /* rate scale requires free function to be implemented */
  1641. static void rs_free(void *priv_rate)
  1642. {
  1643. return;
  1644. }
  1645. static void rs_clear(void *priv_rate)
  1646. {
  1647. struct iwl_priv *priv = (struct iwl_priv *) priv_rate;
  1648. IWL_DEBUG_RATE("enter\n");
  1649. priv->lq_mngr.lq_ready = 0;
  1650. #ifdef CONFIG_IWLWIFI_HT
  1651. #ifdef CONFIG_IWLWIFI_HT_AGG
  1652. if (priv->lq_mngr.agg_ctrl.granted_ba)
  1653. iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);
  1654. #endif /*CONFIG_IWLWIFI_HT_AGG */
  1655. #endif /* CONFIG_IWLWIFI_HT */
  1656. IWL_DEBUG_RATE("leave\n");
  1657. }
  1658. static void rs_free_sta(void *priv, void *priv_sta)
  1659. {
  1660. struct iwl_rate_scale_priv *rs_priv = priv_sta;
  1661. IWL_DEBUG_RATE("enter\n");
  1662. kfree(rs_priv);
  1663. IWL_DEBUG_RATE("leave\n");
  1664. }
  1665. #ifdef CONFIG_MAC80211_DEBUGFS
  1666. static int open_file_generic(struct inode *inode, struct file *file)
  1667. {
  1668. file->private_data = inode->i_private;
  1669. return 0;
  1670. }
  1671. static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv,
  1672. struct iwl_rate *mcs, int index)
  1673. {
  1674. u32 base_rate;
  1675. if (rs_priv->phymode == (u8) MODE_IEEE80211A)
  1676. base_rate = 0x800D;
  1677. else
  1678. base_rate = 0x820A;
  1679. if (rs_priv->dbg_fixed.rate_n_flags) {
  1680. if (index < 12)
  1681. mcs->rate_n_flags = rs_priv->dbg_fixed.rate_n_flags;
  1682. else
  1683. mcs->rate_n_flags = base_rate;
  1684. IWL_DEBUG_RATE("Fixed rate ON\n");
  1685. return;
  1686. }
  1687. IWL_DEBUG_RATE("Fixed rate OFF\n");
  1688. }
  1689. static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
  1690. const char __user *user_buf, size_t count, loff_t *ppos)
  1691. {
  1692. struct iwl_rate_scale_priv *rs_priv = file->private_data;
  1693. char buf[64];
  1694. int buf_size;
  1695. u32 parsed_rate;
  1696. memset(buf, 0, sizeof(buf));
  1697. buf_size = min(count, sizeof(buf) - 1);
  1698. if (copy_from_user(buf, user_buf, buf_size))
  1699. return -EFAULT;
  1700. if (sscanf(buf, "%x", &parsed_rate) == 1)
  1701. rs_priv->dbg_fixed.rate_n_flags = parsed_rate;
  1702. else
  1703. rs_priv->dbg_fixed.rate_n_flags = 0;
  1704. rs_priv->active_rate = 0x0FFF;
  1705. rs_priv->active_siso_rate = 0x1FD0;
  1706. rs_priv->active_mimo_rate = 0x1FD0;
  1707. IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
  1708. rs_priv->lq.sta_id, rs_priv->dbg_fixed.rate_n_flags);
  1709. if (rs_priv->dbg_fixed.rate_n_flags) {
  1710. rs_fill_link_cmd(rs_priv, &rs_priv->dbg_fixed, &rs_priv->lq);
  1711. rs_send_lq_cmd(rs_priv->drv, &rs_priv->lq, CMD_ASYNC);
  1712. }
  1713. return count;
  1714. }
  1715. static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
  1716. char __user *user_buf, size_t count, loff_t *ppos)
  1717. {
  1718. char buff[1024];
  1719. int desc = 0;
  1720. int i = 0;
  1721. struct iwl_rate_scale_priv *rs_priv = file->private_data;
  1722. desc += sprintf(buff+desc, "sta_id %d\n", rs_priv->lq.sta_id);
  1723. desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
  1724. rs_priv->total_failed, rs_priv->total_success,
  1725. rs_priv->active_rate);
  1726. desc += sprintf(buff+desc, "fixed rate 0x%X\n",
  1727. rs_priv->dbg_fixed.rate_n_flags);
  1728. desc += sprintf(buff+desc, "general:"
  1729. "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
  1730. rs_priv->lq.general_params.flags,
  1731. rs_priv->lq.general_params.mimo_delimiter,
  1732. rs_priv->lq.general_params.single_stream_ant_msk,
  1733. rs_priv->lq.general_params.dual_stream_ant_msk);
  1734. desc += sprintf(buff+desc, "agg:"
  1735. "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n",
  1736. le16_to_cpu(rs_priv->lq.agg_params.agg_time_limit),
  1737. rs_priv->lq.agg_params.agg_dis_start_th,
  1738. rs_priv->lq.agg_params.agg_frame_cnt_limit);
  1739. desc += sprintf(buff+desc,
  1740. "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n",
  1741. rs_priv->lq.general_params.start_rate_index[0],
  1742. rs_priv->lq.general_params.start_rate_index[1],
  1743. rs_priv->lq.general_params.start_rate_index[2],
  1744. rs_priv->lq.general_params.start_rate_index[3]);
  1745. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  1746. desc += sprintf(buff+desc, " rate[%d] 0x%X\n",
  1747. i, le32_to_cpu(rs_priv->lq.rs_table[i].rate_n_flags));
  1748. return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  1749. }
  1750. static const struct file_operations rs_sta_dbgfs_scale_table_ops = {
  1751. .write = rs_sta_dbgfs_scale_table_write,
  1752. .read = rs_sta_dbgfs_scale_table_read,
  1753. .open = open_file_generic,
  1754. };
  1755. static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
  1756. char __user *user_buf, size_t count, loff_t *ppos)
  1757. {
  1758. char buff[1024];
  1759. int desc = 0;
  1760. int i, j;
  1761. struct iwl_rate_scale_priv *rs_priv = file->private_data;
  1762. for (i = 0; i < LQ_SIZE; i++) {
  1763. desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n"
  1764. "rate=0x%X\n",
  1765. rs_priv->active_tbl == i?"*":"x",
  1766. rs_priv->lq_info[i].lq_type,
  1767. rs_priv->lq_info[i].is_SGI,
  1768. rs_priv->lq_info[i].is_fat,
  1769. rs_priv->lq_info[i].is_dup,
  1770. rs_priv->lq_info[i].current_rate.rate_n_flags);
  1771. for (j = 0; j < IWL_RATE_COUNT; j++) {
  1772. desc += sprintf(buff+desc,
  1773. "counter=%d success=%d %%=%d\n",
  1774. rs_priv->lq_info[i].win[j].counter,
  1775. rs_priv->lq_info[i].win[j].success_counter,
  1776. rs_priv->lq_info[i].win[j].success_ratio);
  1777. }
  1778. }
  1779. return simple_read_from_buffer(user_buf, count, ppos, buff, desc);
  1780. }
  1781. static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
  1782. .read = rs_sta_dbgfs_stats_table_read,
  1783. .open = open_file_generic,
  1784. };
  1785. static void rs_add_debugfs(void *priv, void *priv_sta,
  1786. struct dentry *dir)
  1787. {
  1788. struct iwl_rate_scale_priv *rs_priv = priv_sta;
  1789. rs_priv->rs_sta_dbgfs_scale_table_file =
  1790. debugfs_create_file("rate_scale_table", 0600, dir,
  1791. rs_priv, &rs_sta_dbgfs_scale_table_ops);
  1792. rs_priv->rs_sta_dbgfs_stats_table_file =
  1793. debugfs_create_file("rate_stats_table", 0600, dir,
  1794. rs_priv, &rs_sta_dbgfs_stats_table_ops);
  1795. }
  1796. static void rs_remove_debugfs(void *priv, void *priv_sta)
  1797. {
  1798. struct iwl_rate_scale_priv *rs_priv = priv_sta;
  1799. debugfs_remove(rs_priv->rs_sta_dbgfs_scale_table_file);
  1800. debugfs_remove(rs_priv->rs_sta_dbgfs_stats_table_file);
  1801. }
  1802. #endif
  1803. static struct rate_control_ops rs_ops = {
  1804. .module = NULL,
  1805. .name = RS_NAME,
  1806. .tx_status = rs_tx_status,
  1807. .get_rate = rs_get_rate,
  1808. .rate_init = rs_rate_init,
  1809. .clear = rs_clear,
  1810. .alloc = rs_alloc,
  1811. .free = rs_free,
  1812. .alloc_sta = rs_alloc_sta,
  1813. .free_sta = rs_free_sta,
  1814. #ifdef CONFIG_MAC80211_DEBUGFS
  1815. .add_sta_debugfs = rs_add_debugfs,
  1816. .remove_sta_debugfs = rs_remove_debugfs,
  1817. #endif
  1818. };
  1819. int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
  1820. {
  1821. struct ieee80211_local *local = hw_to_local(hw);
  1822. struct iwl_priv *priv = hw->priv;
  1823. struct iwl_rate_scale_priv *rs_priv;
  1824. struct sta_info *sta;
  1825. int count = 0, i;
  1826. u32 samples = 0, success = 0, good = 0;
  1827. unsigned long now = jiffies;
  1828. u32 max_time = 0;
  1829. u8 lq_type, antenna;
  1830. sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr);
  1831. if (!sta || !sta->rate_ctrl_priv) {
  1832. if (sta) {
  1833. sta_info_put(sta);
  1834. IWL_DEBUG_RATE("leave - no private rate data!\n");
  1835. } else
  1836. IWL_DEBUG_RATE("leave - no station!\n");
  1837. return sprintf(buf, "station %d not found\n", sta_id);
  1838. }
  1839. rs_priv = (void *)sta->rate_ctrl_priv;
  1840. lq_type = rs_priv->lq_info[rs_priv->active_tbl].lq_type;
  1841. antenna = rs_priv->lq_info[rs_priv->active_tbl].antenna_type;
  1842. if (is_legacy(lq_type))
  1843. i = IWL_RATE_54M_INDEX;
  1844. else
  1845. i = IWL_RATE_60M_INDEX;
  1846. while (1) {
  1847. u64 mask;
  1848. int j;
  1849. int active = rs_priv->active_tbl;
  1850. count +=
  1851. sprintf(&buf[count], " %2dMbs: ", iwl_rates[i].ieee / 2);
  1852. mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
  1853. for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
  1854. buf[count++] =
  1855. (rs_priv->lq_info[active].win[i].data & mask)
  1856. ? '1' : '0';
  1857. samples += rs_priv->lq_info[active].win[i].counter;
  1858. good += rs_priv->lq_info[active].win[i].success_counter;
  1859. success += rs_priv->lq_info[active].win[i].success_counter *
  1860. iwl_rates[i].ieee;
  1861. if (rs_priv->lq_info[active].win[i].stamp) {
  1862. int delta =
  1863. jiffies_to_msecs(now -
  1864. rs_priv->lq_info[active].win[i].stamp);
  1865. if (delta > max_time)
  1866. max_time = delta;
  1867. count += sprintf(&buf[count], "%5dms\n", delta);
  1868. } else
  1869. buf[count++] = '\n';
  1870. j = iwl_get_prev_ieee_rate(i);
  1871. if (j == i)
  1872. break;
  1873. i = j;
  1874. }
  1875. /* Display the average rate of all samples taken.
  1876. *
  1877. * NOTE: We multiple # of samples by 2 since the IEEE measurement
  1878. * added from iwl_rates is actually 2X the rate */
  1879. if (samples)
  1880. count += sprintf(&buf[count],
  1881. "\nAverage rate is %3d.%02dMbs over last %4dms\n"
  1882. "%3d%% success (%d good packets over %d tries)\n",
  1883. success / (2 * samples), (success * 5 / samples) % 10,
  1884. max_time, good * 100 / samples, good, samples);
  1885. else
  1886. count += sprintf(&buf[count], "\nAverage rate: 0Mbs\n");
  1887. count += sprintf(&buf[count], "\nrate scale type %d antenna %d "
  1888. "active_search %d rate index %d\n", lq_type, antenna,
  1889. rs_priv->search_better_tbl, sta->last_txrate);
  1890. sta_info_put(sta);
  1891. return count;
  1892. }
  1893. void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
  1894. {
  1895. struct iwl_priv *priv = hw->priv;
  1896. priv->lq_mngr.lq_ready = 1;
  1897. }
  1898. void iwl_rate_control_register(struct ieee80211_hw *hw)
  1899. {
  1900. ieee80211_rate_control_register(&rs_ops);
  1901. }
  1902. void iwl_rate_control_unregister(struct ieee80211_hw *hw)
  1903. {
  1904. ieee80211_rate_control_unregister(&rs_ops);
  1905. }