iwl-4965-rs.c 59 KB

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