iwl-4965-rs.c 58 KB

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