iwl-4965-rs.c 59 KB

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