rc.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  1. /*
  2. * Copyright (c) 2004 Video54 Technologies, Inc.
  3. * Copyright (c) 2004-2008 Atheros Communications, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /*
  18. * Atheros rate control algorithm
  19. */
  20. #include "core.h"
  21. /* FIXME: remove this include! */
  22. #include "../net/mac80211/rate.h"
  23. static u32 tx_triglevel_max;
  24. static struct ath_rate_table ar5416_11na_ratetable = {
  25. 42,
  26. {
  27. { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
  28. 5400, 0x0b, 0x00, 12,
  29. 0, 2, 1, 0, 0, 0, 0, 0 },
  30. { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
  31. 7800, 0x0f, 0x00, 18,
  32. 0, 3, 1, 1, 1, 1, 1, 0 },
  33. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
  34. 10000, 0x0a, 0x00, 24,
  35. 2, 4, 2, 2, 2, 2, 2, 0 },
  36. { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
  37. 13900, 0x0e, 0x00, 36,
  38. 2, 6, 2, 3, 3, 3, 3, 0 },
  39. { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
  40. 17300, 0x09, 0x00, 48,
  41. 4, 10, 3, 4, 4, 4, 4, 0 },
  42. { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
  43. 23000, 0x0d, 0x00, 72,
  44. 4, 14, 3, 5, 5, 5, 5, 0 },
  45. { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
  46. 27400, 0x08, 0x00, 96,
  47. 4, 20, 3, 6, 6, 6, 6, 0 },
  48. { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
  49. 29300, 0x0c, 0x00, 108,
  50. 4, 23, 3, 7, 7, 7, 7, 0 },
  51. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 6500, /* 6.5 Mb */
  52. 6400, 0x80, 0x00, 0,
  53. 0, 2, 3, 8, 24, 8, 24, 3216 },
  54. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 13000, /* 13 Mb */
  55. 12700, 0x81, 0x00, 1,
  56. 2, 4, 3, 9, 25, 9, 25, 6434 },
  57. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 19500, /* 19.5 Mb */
  58. 18800, 0x82, 0x00, 2,
  59. 2, 6, 3, 10, 26, 10, 26, 9650 },
  60. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 26000, /* 26 Mb */
  61. 25000, 0x83, 0x00, 3,
  62. 4, 10, 3, 11, 27, 11, 27, 12868 },
  63. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 39000, /* 39 Mb */
  64. 36700, 0x84, 0x00, 4,
  65. 4, 14, 3, 12, 28, 12, 28, 19304 },
  66. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 52000, /* 52 Mb */
  67. 48100, 0x85, 0x00, 5,
  68. 4, 20, 3, 13, 29, 13, 29, 25740 },
  69. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 58500, /* 58.5 Mb */
  70. 53500, 0x86, 0x00, 6,
  71. 4, 23, 3, 14, 30, 14, 30, 28956 },
  72. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 65000, /* 65 Mb */
  73. 59000, 0x87, 0x00, 7,
  74. 4, 25, 3, 15, 31, 15, 32, 32180 },
  75. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 13000, /* 13 Mb */
  76. 12700, 0x88, 0x00,
  77. 8, 0, 2, 3, 16, 33, 16, 33, 6430 },
  78. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 26000, /* 26 Mb */
  79. 24800, 0x89, 0x00, 9,
  80. 2, 4, 3, 17, 34, 17, 34, 12860 },
  81. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 39000, /* 39 Mb */
  82. 36600, 0x8a, 0x00, 10,
  83. 2, 6, 3, 18, 35, 18, 35, 19300 },
  84. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 52000, /* 52 Mb */
  85. 48100, 0x8b, 0x00, 11,
  86. 4, 10, 3, 19, 36, 19, 36, 25736 },
  87. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 78000, /* 78 Mb */
  88. 69500, 0x8c, 0x00, 12,
  89. 4, 14, 3, 20, 37, 20, 37, 38600 },
  90. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 104000, /* 104 Mb */
  91. 89500, 0x8d, 0x00, 13,
  92. 4, 20, 3, 21, 38, 21, 38, 51472 },
  93. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 117000, /* 117 Mb */
  94. 98900, 0x8e, 0x00, 14,
  95. 4, 23, 3, 22, 39, 22, 39, 57890 },
  96. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 130000, /* 130 Mb */
  97. 108300, 0x8f, 0x00, 15,
  98. 4, 25, 3, 23, 40, 23, 41, 64320 },
  99. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 13500, /* 13.5 Mb */
  100. 13200, 0x80, 0x00, 0,
  101. 0, 2, 3, 8, 24, 24, 24, 6684 },
  102. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 27500, /* 27.0 Mb */
  103. 25900, 0x81, 0x00, 1,
  104. 2, 4, 3, 9, 25, 25, 25, 13368 },
  105. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 40500, /* 40.5 Mb */
  106. 38600, 0x82, 0x00, 2,
  107. 2, 6, 3, 10, 26, 26, 26, 20052 },
  108. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 54000, /* 54 Mb */
  109. 49800, 0x83, 0x00, 3,
  110. 4, 10, 3, 11, 27, 27, 27, 26738 },
  111. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 81500, /* 81 Mb */
  112. 72200, 0x84, 0x00, 4,
  113. 4, 14, 3, 12, 28, 28, 28, 40104 },
  114. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 108000, /* 108 Mb */
  115. 92900, 0x85, 0x00, 5,
  116. 4, 20, 3, 13, 29, 29, 29, 53476 },
  117. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 121500, /* 121.5 Mb */
  118. 102700, 0x86, 0x00, 6,
  119. 4, 23, 3, 14, 30, 30, 30, 60156 },
  120. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 135000, /* 135 Mb */
  121. 112000, 0x87, 0x00, 7,
  122. 4, 25, 3, 15, 31, 32, 32, 66840 },
  123. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
  124. 122000, 0x87, 0x00, 7,
  125. 4, 25, 3, 15, 31, 32, 32, 74200 },
  126. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 27000, /* 27 Mb */
  127. 25800, 0x88, 0x00, 8,
  128. 0, 2, 3, 16, 33, 33, 33, 13360 },
  129. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 54000, /* 54 Mb */
  130. 49800, 0x89, 0x00, 9,
  131. 2, 4, 3, 17, 34, 34, 34, 26720 },
  132. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 81000, /* 81 Mb */
  133. 71900, 0x8a, 0x00, 10,
  134. 2, 6, 3, 18, 35, 35, 35, 40080 },
  135. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 108000, /* 108 Mb */
  136. 92500, 0x8b, 0x00, 11,
  137. 4, 10, 3, 19, 36, 36, 36, 53440 },
  138. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 162000, /* 162 Mb */
  139. 130300, 0x8c, 0x00, 12,
  140. 4, 14, 3, 20, 37, 37, 37, 80160 },
  141. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 216000, /* 216 Mb */
  142. 162800, 0x8d, 0x00, 13,
  143. 4, 20, 3, 21, 38, 38, 38, 106880 },
  144. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 243000, /* 243 Mb */
  145. 178200, 0x8e, 0x00, 14,
  146. 4, 23, 3, 22, 39, 39, 39, 120240 },
  147. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 270000, /* 270 Mb */
  148. 192100, 0x8f, 0x00, 15,
  149. 4, 25, 3, 23, 40, 41, 41, 133600 },
  150. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
  151. 207000, 0x8f, 0x00, 15,
  152. 4, 25, 3, 23, 40, 41, 41, 148400 },
  153. },
  154. 50, /* probe interval */
  155. 50, /* rssi reduce interval */
  156. WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
  157. };
  158. /* TRUE_ALL - valid for 20/40/Legacy,
  159. * TRUE - Legacy only,
  160. * TRUE_20 - HT 20 only,
  161. * TRUE_40 - HT 40 only */
  162. /* 4ms frame limit not used for NG mode. The values filled
  163. * for HT are the 64K max aggregate limit */
  164. static struct ath_rate_table ar5416_11ng_ratetable = {
  165. 46,
  166. {
  167. { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 1000, /* 1 Mb */
  168. 900, 0x1b, 0x00, 2,
  169. 0, 0, 1, 0, 0, 0, 0, 0 },
  170. { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 2000, /* 2 Mb */
  171. 1900, 0x1a, 0x04, 4,
  172. 1, 1, 1, 1, 1, 1, 1, 0 },
  173. { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 5500, /* 5.5 Mb */
  174. 4900, 0x19, 0x04, 11,
  175. 2, 2, 2, 2, 2, 2, 2, 0 },
  176. { TRUE_ALL, TRUE_ALL, WLAN_PHY_CCK, 11000, /* 11 Mb */
  177. 8100, 0x18, 0x04, 22,
  178. 3, 3, 2, 3, 3, 3, 3, 0 },
  179. { FALSE, FALSE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
  180. 5400, 0x0b, 0x00, 12,
  181. 4, 2, 1, 4, 4, 4, 4, 0 },
  182. { FALSE, FALSE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
  183. 7800, 0x0f, 0x00, 18,
  184. 4, 3, 1, 5, 5, 5, 5, 0 },
  185. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
  186. 10100, 0x0a, 0x00, 24,
  187. 6, 4, 1, 6, 6, 6, 6, 0 },
  188. { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
  189. 14100, 0x0e, 0x00, 36,
  190. 6, 6, 2, 7, 7, 7, 7, 0 },
  191. { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
  192. 17700, 0x09, 0x00, 48,
  193. 8, 10, 3, 8, 8, 8, 8, 0 },
  194. { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
  195. 23700, 0x0d, 0x00, 72,
  196. 8, 14, 3, 9, 9, 9, 9, 0 },
  197. { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
  198. 27400, 0x08, 0x00, 96,
  199. 8, 20, 3, 10, 10, 10, 10, 0 },
  200. { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
  201. 30900, 0x0c, 0x00, 108,
  202. 8, 23, 3, 11, 11, 11, 11, 0 },
  203. { FALSE, FALSE, WLAN_PHY_HT_20_SS, 6500, /* 6.5 Mb */
  204. 6400, 0x80, 0x00, 0,
  205. 4, 2, 3, 12, 28, 12, 28, 3216 },
  206. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 13000, /* 13 Mb */
  207. 12700, 0x81, 0x00, 1,
  208. 6, 4, 3, 13, 29, 13, 29, 6434 },
  209. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 19500, /* 19.5 Mb */
  210. 18800, 0x82, 0x00, 2,
  211. 6, 6, 3, 14, 30, 14, 30, 9650 },
  212. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 26000, /* 26 Mb */
  213. 25000, 0x83, 0x00, 3,
  214. 8, 10, 3, 15, 31, 15, 31, 12868 },
  215. { TRUE_20, TRUE_20, WLAN_PHY_HT_20_SS, 39000, /* 39 Mb */
  216. 36700, 0x84, 0x00, 4,
  217. 8, 14, 3, 16, 32, 16, 32, 19304 },
  218. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 52000, /* 52 Mb */
  219. 48100, 0x85, 0x00, 5,
  220. 8, 20, 3, 17, 33, 17, 33, 25740 },
  221. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 58500, /* 58.5 Mb */
  222. 53500, 0x86, 0x00, 6,
  223. 8, 23, 3, 18, 34, 18, 34, 28956 },
  224. { FALSE, TRUE_20, WLAN_PHY_HT_20_SS, 65000, /* 65 Mb */
  225. 59000, 0x87, 0x00, 7,
  226. 8, 25, 3, 19, 35, 19, 36, 32180 },
  227. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 13000, /* 13 Mb */
  228. 12700, 0x88, 0x00, 8,
  229. 4, 2, 3, 20, 37, 20, 37, 6430 },
  230. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 26000, /* 26 Mb */
  231. 24800, 0x89, 0x00, 9,
  232. 6, 4, 3, 21, 38, 21, 38, 12860 },
  233. { FALSE, FALSE, WLAN_PHY_HT_20_DS, 39000, /* 39 Mb */
  234. 36600, 0x8a, 0x00, 10,
  235. 6, 6, 3, 22, 39, 22, 39, 19300 },
  236. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 52000, /* 52 Mb */
  237. 48100, 0x8b, 0x00, 11,
  238. 8, 10, 3, 23, 40, 23, 40, 25736 },
  239. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 78000, /* 78 Mb */
  240. 69500, 0x8c, 0x00, 12,
  241. 8, 14, 3, 24, 41, 24, 41, 38600 },
  242. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 104000, /* 104 Mb */
  243. 89500, 0x8d, 0x00, 13,
  244. 8, 20, 3, 25, 42, 25, 42, 51472 },
  245. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 117000, /* 117 Mb */
  246. 98900, 0x8e, 0x00, 14,
  247. 8, 23, 3, 26, 43, 26, 44, 57890 },
  248. { TRUE_20, FALSE, WLAN_PHY_HT_20_DS, 130000, /* 130 Mb */
  249. 108300, 0x8f, 0x00, 15,
  250. 8, 25, 3, 27, 44, 27, 45, 64320 },
  251. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 13500, /* 13.5 Mb */
  252. 13200, 0x80, 0x00, 0,
  253. 8, 2, 3, 12, 28, 28, 28, 6684 },
  254. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 27500, /* 27.0 Mb */
  255. 25900, 0x81, 0x00, 1,
  256. 8, 4, 3, 13, 29, 29, 29, 13368 },
  257. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 40500, /* 40.5 Mb */
  258. 38600, 0x82, 0x00, 2,
  259. 8, 6, 3, 14, 30, 30, 30, 20052 },
  260. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 54000, /* 54 Mb */
  261. 49800, 0x83, 0x00, 3,
  262. 8, 10, 3, 15, 31, 31, 31, 26738 },
  263. { TRUE_40, TRUE_40, WLAN_PHY_HT_40_SS, 81500, /* 81 Mb */
  264. 72200, 0x84, 0x00, 4,
  265. 8, 14, 3, 16, 32, 32, 32, 40104 },
  266. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 108000, /* 108 Mb */
  267. 92900, 0x85, 0x00, 5,
  268. 8, 20, 3, 17, 33, 33, 33, 53476 },
  269. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 121500, /* 121.5 Mb */
  270. 102700, 0x86, 0x00, 6,
  271. 8, 23, 3, 18, 34, 34, 34, 60156 },
  272. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS, 135000, /* 135 Mb */
  273. 112000, 0x87, 0x00, 7,
  274. 8, 23, 3, 19, 35, 36, 36, 66840 },
  275. { FALSE, TRUE_40, WLAN_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
  276. 122000, 0x87, 0x00, 7,
  277. 8, 25, 3, 19, 35, 36, 36, 74200 },
  278. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 27000, /* 27 Mb */
  279. 25800, 0x88, 0x00, 8,
  280. 8, 2, 3, 20, 37, 37, 37, 13360 },
  281. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 54000, /* 54 Mb */
  282. 49800, 0x89, 0x00, 9,
  283. 8, 4, 3, 21, 38, 38, 38, 26720 },
  284. { FALSE, FALSE, WLAN_PHY_HT_40_DS, 81000, /* 81 Mb */
  285. 71900, 0x8a, 0x00, 10,
  286. 8, 6, 3, 22, 39, 39, 39, 40080 },
  287. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 108000, /* 108 Mb */
  288. 92500, 0x8b, 0x00, 11,
  289. 8, 10, 3, 23, 40, 40, 40, 53440 },
  290. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 162000, /* 162 Mb */
  291. 130300, 0x8c, 0x00, 12,
  292. 8, 14, 3, 24, 41, 41, 41, 80160 },
  293. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 216000, /* 216 Mb */
  294. 162800, 0x8d, 0x00, 13,
  295. 8, 20, 3, 25, 42, 42, 42, 106880 },
  296. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 243000, /* 243 Mb */
  297. 178200, 0x8e, 0x00, 14,
  298. 8, 23, 3, 26, 43, 43, 43, 120240 },
  299. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS, 270000, /* 270 Mb */
  300. 192100, 0x8f, 0x00, 15,
  301. 8, 23, 3, 27, 44, 45, 45, 133600 },
  302. { TRUE_40, FALSE, WLAN_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
  303. 207000, 0x8f, 0x00, 15,
  304. 8, 25, 3, 27, 44, 45, 45, 148400 },
  305. },
  306. 50, /* probe interval */
  307. 50, /* rssi reduce interval */
  308. WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
  309. };
  310. static struct ath_rate_table ar5416_11a_ratetable = {
  311. 8,
  312. {
  313. { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
  314. 5400, 0x0b, 0x00, (0x80|12),
  315. 0, 2, 1, 0, 0 },
  316. { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
  317. 7800, 0x0f, 0x00, 18,
  318. 0, 3, 1, 1, 0 },
  319. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
  320. 10000, 0x0a, 0x00, (0x80|24),
  321. 2, 4, 2, 2, 0 },
  322. { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
  323. 13900, 0x0e, 0x00, 36,
  324. 2, 6, 2, 3, 0 },
  325. { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
  326. 17300, 0x09, 0x00, (0x80|48),
  327. 4, 10, 3, 4, 0 },
  328. { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
  329. 23000, 0x0d, 0x00, 72,
  330. 4, 14, 3, 5, 0 },
  331. { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
  332. 27400, 0x08, 0x00, 96,
  333. 4, 19, 3, 6, 0 },
  334. { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
  335. 29300, 0x0c, 0x00, 108,
  336. 4, 23, 3, 7, 0 },
  337. },
  338. 50, /* probe interval */
  339. 50, /* rssi reduce interval */
  340. 0, /* Phy rates allowed initially */
  341. };
  342. static struct ath_rate_table ar5416_11a_ratetable_Half = {
  343. 8,
  344. {
  345. { TRUE, TRUE, WLAN_PHY_OFDM, 3000, /* 6 Mb */
  346. 2700, 0x0b, 0x00, (0x80|6),
  347. 0, 2, 1, 0, 0},
  348. { TRUE, TRUE, WLAN_PHY_OFDM, 4500, /* 9 Mb */
  349. 3900, 0x0f, 0x00, 9,
  350. 0, 3, 1, 1, 0 },
  351. { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 12 Mb */
  352. 5000, 0x0a, 0x00, (0x80|12),
  353. 2, 4, 2, 2, 0 },
  354. { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 18 Mb */
  355. 6950, 0x0e, 0x00, 18,
  356. 2, 6, 2, 3, 0 },
  357. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 24 Mb */
  358. 8650, 0x09, 0x00, (0x80|24),
  359. 4, 10, 3, 4, 0 },
  360. { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 36 Mb */
  361. 11500, 0x0d, 0x00, 36,
  362. 4, 14, 3, 5, 0 },
  363. { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 48 Mb */
  364. 13700, 0x08, 0x00, 48,
  365. 4, 19, 3, 6, 0 },
  366. { TRUE, TRUE, WLAN_PHY_OFDM, 27000, /* 54 Mb */
  367. 14650, 0x0c, 0x00, 54,
  368. 4, 23, 3, 7, 0 },
  369. },
  370. 50, /* probe interval */
  371. 50, /* rssi reduce interval */
  372. 0, /* Phy rates allowed initially */
  373. };
  374. static struct ath_rate_table ar5416_11a_ratetable_Quarter = {
  375. 8,
  376. {
  377. { TRUE, TRUE, WLAN_PHY_OFDM, 1500, /* 6 Mb */
  378. 1350, 0x0b, 0x00, (0x80|3),
  379. 0, 2, 1, 0, 0 },
  380. { TRUE, TRUE, WLAN_PHY_OFDM, 2250, /* 9 Mb */
  381. 1950, 0x0f, 0x00, 4,
  382. 0, 3, 1, 1, 0 },
  383. { TRUE, TRUE, WLAN_PHY_OFDM, 3000, /* 12 Mb */
  384. 2500, 0x0a, 0x00, (0x80|6),
  385. 2, 4, 2, 2, 0 },
  386. { TRUE, TRUE, WLAN_PHY_OFDM, 4500, /* 18 Mb */
  387. 3475, 0x0e, 0x00, 9,
  388. 2, 6, 2, 3, 0 },
  389. { TRUE, TRUE, WLAN_PHY_OFDM, 6000, /* 25 Mb */
  390. 4325, 0x09, 0x00, (0x80|12),
  391. 4, 10, 3, 4, 0 },
  392. { TRUE, TRUE, WLAN_PHY_OFDM, 9000, /* 36 Mb */
  393. 5750, 0x0d, 0x00, 18,
  394. 4, 14, 3, 5, 0 },
  395. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 48 Mb */
  396. 6850, 0x08, 0x00, 24,
  397. 4, 19, 3, 6, 0 },
  398. { TRUE, TRUE, WLAN_PHY_OFDM, 13500, /* 54 Mb */
  399. 7325, 0x0c, 0x00, 27,
  400. 4, 23, 3, 7, 0 },
  401. },
  402. 50, /* probe interval */
  403. 50, /* rssi reduce interval */
  404. 0, /* Phy rates allowed initially */
  405. };
  406. static struct ath_rate_table ar5416_11g_ratetable = {
  407. 12,
  408. {
  409. { TRUE, TRUE, WLAN_PHY_CCK, 1000, /* 1 Mb */
  410. 900, 0x1b, 0x00, 2,
  411. 0, 0, 1, 0, 0 },
  412. { TRUE, TRUE, WLAN_PHY_CCK, 2000, /* 2 Mb */
  413. 1900, 0x1a, 0x04, 4,
  414. 1, 1, 1, 1, 0 },
  415. { TRUE, TRUE, WLAN_PHY_CCK, 5500, /* 5.5 Mb */
  416. 4900, 0x19, 0x04, 11,
  417. 2, 2, 2, 2, 0 },
  418. { TRUE, TRUE, WLAN_PHY_CCK, 11000, /* 11 Mb */
  419. 8100, 0x18, 0x04, 22,
  420. 3, 3, 2, 3, 0 },
  421. { FALSE, FALSE, WLAN_PHY_OFDM, 6000, /* 6 Mb */
  422. 5400, 0x0b, 0x00, 12,
  423. 4, 2, 1, 4, 0 },
  424. { FALSE, FALSE, WLAN_PHY_OFDM, 9000, /* 9 Mb */
  425. 7800, 0x0f, 0x00, 18,
  426. 4, 3, 1, 5, 0 },
  427. { TRUE, TRUE, WLAN_PHY_OFDM, 12000, /* 12 Mb */
  428. 10000, 0x0a, 0x00, 24,
  429. 6, 4, 1, 6, 0 },
  430. { TRUE, TRUE, WLAN_PHY_OFDM, 18000, /* 18 Mb */
  431. 13900, 0x0e, 0x00, 36,
  432. 6, 6, 2, 7, 0 },
  433. { TRUE, TRUE, WLAN_PHY_OFDM, 24000, /* 24 Mb */
  434. 17300, 0x09, 0x00, 48,
  435. 8, 10, 3, 8, 0 },
  436. { TRUE, TRUE, WLAN_PHY_OFDM, 36000, /* 36 Mb */
  437. 23000, 0x0d, 0x00, 72,
  438. 8, 14, 3, 9, 0 },
  439. { TRUE, TRUE, WLAN_PHY_OFDM, 48000, /* 48 Mb */
  440. 27400, 0x08, 0x00, 96,
  441. 8, 19, 3, 10, 0 },
  442. { TRUE, TRUE, WLAN_PHY_OFDM, 54000, /* 54 Mb */
  443. 29300, 0x0c, 0x00, 108,
  444. 8, 23, 3, 11, 0 },
  445. },
  446. 50, /* probe interval */
  447. 50, /* rssi reduce interval */
  448. 0, /* Phy rates allowed initially */
  449. };
  450. static struct ath_rate_table ar5416_11b_ratetable = {
  451. 4,
  452. {
  453. { TRUE, TRUE, WLAN_PHY_CCK, 1000, /* 1 Mb */
  454. 900, 0x1b, 0x00, (0x80|2),
  455. 0, 0, 1, 0, 0 },
  456. { TRUE, TRUE, WLAN_PHY_CCK, 2000, /* 2 Mb */
  457. 1800, 0x1a, 0x04, (0x80|4),
  458. 1, 1, 1, 1, 0 },
  459. { TRUE, TRUE, WLAN_PHY_CCK, 5500, /* 5.5 Mb */
  460. 4300, 0x19, 0x04, (0x80|11),
  461. 1, 2, 2, 2, 0 },
  462. { TRUE, TRUE, WLAN_PHY_CCK, 11000, /* 11 Mb */
  463. 7100, 0x18, 0x04, (0x80|22),
  464. 1, 4, 100, 3, 0 },
  465. },
  466. 100, /* probe interval */
  467. 100, /* rssi reduce interval */
  468. 0, /* Phy rates allowed initially */
  469. };
  470. static void ar5416_attach_ratetables(struct ath_rate_softc *sc)
  471. {
  472. /*
  473. * Attach rate tables.
  474. */
  475. sc->hw_rate_table[ATH9K_MODE_11B] = &ar5416_11b_ratetable;
  476. sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable;
  477. sc->hw_rate_table[ATH9K_MODE_11G] = &ar5416_11g_ratetable;
  478. sc->hw_rate_table[ATH9K_MODE_11NA_HT20] = &ar5416_11na_ratetable;
  479. sc->hw_rate_table[ATH9K_MODE_11NG_HT20] = &ar5416_11ng_ratetable;
  480. sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS] =
  481. &ar5416_11na_ratetable;
  482. sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS] =
  483. &ar5416_11na_ratetable;
  484. sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS] =
  485. &ar5416_11ng_ratetable;
  486. sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS] =
  487. &ar5416_11ng_ratetable;
  488. }
  489. static void ar5416_setquarter_ratetable(struct ath_rate_softc *sc)
  490. {
  491. sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable_Quarter;
  492. return;
  493. }
  494. static void ar5416_sethalf_ratetable(struct ath_rate_softc *sc)
  495. {
  496. sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable_Half;
  497. return;
  498. }
  499. static void ar5416_setfull_ratetable(struct ath_rate_softc *sc)
  500. {
  501. sc->hw_rate_table[ATH9K_MODE_11A] = &ar5416_11a_ratetable;
  502. return;
  503. }
  504. /*
  505. * Return the median of three numbers
  506. */
  507. static inline int8_t median(int8_t a, int8_t b, int8_t c)
  508. {
  509. if (a >= b) {
  510. if (b >= c)
  511. return b;
  512. else if (a > c)
  513. return c;
  514. else
  515. return a;
  516. } else {
  517. if (a >= c)
  518. return a;
  519. else if (b >= c)
  520. return c;
  521. else
  522. return b;
  523. }
  524. }
  525. static void ath_rc_sort_validrates(const struct ath_rate_table *rate_table,
  526. struct ath_rate_node *ath_rc_priv)
  527. {
  528. u8 i, j, idx, idx_next;
  529. for (i = ath_rc_priv->max_valid_rate - 1; i > 0; i--) {
  530. for (j = 0; j <= i-1; j++) {
  531. idx = ath_rc_priv->valid_rate_index[j];
  532. idx_next = ath_rc_priv->valid_rate_index[j+1];
  533. if (rate_table->info[idx].ratekbps >
  534. rate_table->info[idx_next].ratekbps) {
  535. ath_rc_priv->valid_rate_index[j] = idx_next;
  536. ath_rc_priv->valid_rate_index[j+1] = idx;
  537. }
  538. }
  539. }
  540. }
  541. /* Access functions for valid_txrate_mask */
  542. static void ath_rc_init_valid_txmask(struct ath_rate_node *ath_rc_priv)
  543. {
  544. u8 i;
  545. for (i = 0; i < ath_rc_priv->rate_table_size; i++)
  546. ath_rc_priv->valid_rate_index[i] = FALSE;
  547. }
  548. static inline void ath_rc_set_valid_txmask(struct ath_rate_node *ath_rc_priv,
  549. u8 index, int valid_tx_rate)
  550. {
  551. ASSERT(index <= ath_rc_priv->rate_table_size);
  552. ath_rc_priv->valid_rate_index[index] = valid_tx_rate ? TRUE : FALSE;
  553. }
  554. static inline int ath_rc_isvalid_txmask(struct ath_rate_node *ath_rc_priv,
  555. u8 index)
  556. {
  557. ASSERT(index <= ath_rc_priv->rate_table_size);
  558. return ath_rc_priv->valid_rate_index[index];
  559. }
  560. /* Iterators for valid_txrate_mask */
  561. static inline int
  562. ath_rc_get_nextvalid_txrate(const struct ath_rate_table *rate_table,
  563. struct ath_rate_node *ath_rc_priv,
  564. u8 cur_valid_txrate,
  565. u8 *next_idx)
  566. {
  567. u8 i;
  568. for (i = 0; i < ath_rc_priv->max_valid_rate - 1; i++) {
  569. if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
  570. *next_idx = ath_rc_priv->valid_rate_index[i+1];
  571. return TRUE;
  572. }
  573. }
  574. /* No more valid rates */
  575. *next_idx = 0;
  576. return FALSE;
  577. }
  578. /* Return true only for single stream */
  579. static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw)
  580. {
  581. if (WLAN_RC_PHY_HT(phy) & !(capflag & WLAN_RC_HT_FLAG))
  582. return FALSE;
  583. if (WLAN_RC_PHY_DS(phy) && !(capflag & WLAN_RC_DS_FLAG))
  584. return FALSE;
  585. if (WLAN_RC_PHY_SGI(phy) && !(capflag & WLAN_RC_SGI_FLAG))
  586. return FALSE;
  587. if (!ignore_cw && WLAN_RC_PHY_HT(phy))
  588. if (WLAN_RC_PHY_40(phy) && !(capflag & WLAN_RC_40_FLAG))
  589. return FALSE;
  590. if (!WLAN_RC_PHY_40(phy) && (capflag & WLAN_RC_40_FLAG))
  591. return FALSE;
  592. return TRUE;
  593. }
  594. static inline int
  595. ath_rc_get_nextlowervalid_txrate(const struct ath_rate_table *rate_table,
  596. struct ath_rate_node *ath_rc_priv,
  597. u8 cur_valid_txrate, u8 *next_idx)
  598. {
  599. int8_t i;
  600. for (i = 1; i < ath_rc_priv->max_valid_rate ; i++) {
  601. if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
  602. *next_idx = ath_rc_priv->valid_rate_index[i-1];
  603. return TRUE;
  604. }
  605. }
  606. return FALSE;
  607. }
  608. /*
  609. * Initialize the Valid Rate Index from valid entries in Rate Table
  610. */
  611. static u8
  612. ath_rc_sib_init_validrates(struct ath_rate_node *ath_rc_priv,
  613. const struct ath_rate_table *rate_table,
  614. u32 capflag)
  615. {
  616. u8 i, hi = 0;
  617. u32 valid;
  618. for (i = 0; i < rate_table->rate_cnt; i++) {
  619. valid = (ath_rc_priv->single_stream ?
  620. rate_table->info[i].valid_single_stream :
  621. rate_table->info[i].valid);
  622. if (valid == TRUE) {
  623. u32 phy = rate_table->info[i].phy;
  624. u8 valid_rate_count = 0;
  625. if (!ath_rc_valid_phyrate(phy, capflag, FALSE))
  626. continue;
  627. valid_rate_count = ath_rc_priv->valid_phy_ratecnt[phy];
  628. ath_rc_priv->valid_phy_rateidx[phy][valid_rate_count] = i;
  629. ath_rc_priv->valid_phy_ratecnt[phy] += 1;
  630. ath_rc_set_valid_txmask(ath_rc_priv, i, TRUE);
  631. hi = A_MAX(hi, i);
  632. }
  633. }
  634. return hi;
  635. }
  636. /*
  637. * Initialize the Valid Rate Index from Rate Set
  638. */
  639. static u8
  640. ath_rc_sib_setvalid_rates(struct ath_rate_node *ath_rc_priv,
  641. const struct ath_rate_table *rate_table,
  642. struct ath_rateset *rateset,
  643. u32 capflag)
  644. {
  645. /* XXX: Clean me up and make identation friendly */
  646. u8 i, j, hi = 0;
  647. /* Use intersection of working rates and valid rates */
  648. for (i = 0; i < rateset->rs_nrates; i++) {
  649. for (j = 0; j < rate_table->rate_cnt; j++) {
  650. u32 phy = rate_table->info[j].phy;
  651. u32 valid = (ath_rc_priv->single_stream ?
  652. rate_table->info[j].valid_single_stream :
  653. rate_table->info[j].valid);
  654. /* We allow a rate only if its valid and the
  655. * capflag matches one of the validity
  656. * (TRUE/TRUE_20/TRUE_40) flags */
  657. /* XXX: catch the negative of this branch
  658. * first and then continue */
  659. if (((rateset->rs_rates[i] & 0x7F) ==
  660. (rate_table->info[j].dot11rate & 0x7F)) &&
  661. ((valid & WLAN_RC_CAP_MODE(capflag)) ==
  662. WLAN_RC_CAP_MODE(capflag)) &&
  663. !WLAN_RC_PHY_HT(phy)) {
  664. u8 valid_rate_count = 0;
  665. if (!ath_rc_valid_phyrate(phy, capflag, FALSE))
  666. continue;
  667. valid_rate_count =
  668. ath_rc_priv->valid_phy_ratecnt[phy];
  669. ath_rc_priv->valid_phy_rateidx[phy]
  670. [valid_rate_count] = j;
  671. ath_rc_priv->valid_phy_ratecnt[phy] += 1;
  672. ath_rc_set_valid_txmask(ath_rc_priv, j, TRUE);
  673. hi = A_MAX(hi, j);
  674. }
  675. }
  676. }
  677. return hi;
  678. }
  679. static u8
  680. ath_rc_sib_setvalid_htrates(struct ath_rate_node *ath_rc_priv,
  681. const struct ath_rate_table *rate_table,
  682. u8 *mcs_set, u32 capflag)
  683. {
  684. u8 i, j, hi = 0;
  685. /* Use intersection of working rates and valid rates */
  686. for (i = 0; i < ((struct ath_rateset *)mcs_set)->rs_nrates; i++) {
  687. for (j = 0; j < rate_table->rate_cnt; j++) {
  688. u32 phy = rate_table->info[j].phy;
  689. u32 valid = (ath_rc_priv->single_stream ?
  690. rate_table->info[j].valid_single_stream :
  691. rate_table->info[j].valid);
  692. if (((((struct ath_rateset *)
  693. mcs_set)->rs_rates[i] & 0x7F) !=
  694. (rate_table->info[j].dot11rate & 0x7F)) ||
  695. !WLAN_RC_PHY_HT(phy) ||
  696. !WLAN_RC_PHY_HT_VALID(valid, capflag))
  697. continue;
  698. if (!ath_rc_valid_phyrate(phy, capflag, FALSE))
  699. continue;
  700. ath_rc_priv->valid_phy_rateidx[phy]
  701. [ath_rc_priv->valid_phy_ratecnt[phy]] = j;
  702. ath_rc_priv->valid_phy_ratecnt[phy] += 1;
  703. ath_rc_set_valid_txmask(ath_rc_priv, j, TRUE);
  704. hi = A_MAX(hi, j);
  705. }
  706. }
  707. return hi;
  708. }
  709. /*
  710. * Attach to a device instance. Setup the public definition
  711. * of how much per-node space we need and setup the private
  712. * phy tables that have rate control parameters.
  713. */
  714. struct ath_rate_softc *ath_rate_attach(struct ath_hal *ah)
  715. {
  716. struct ath_rate_softc *asc;
  717. /* we are only in user context so we can sleep for memory */
  718. asc = kzalloc(sizeof(struct ath_rate_softc), GFP_KERNEL);
  719. if (asc == NULL)
  720. return NULL;
  721. ar5416_attach_ratetables(asc);
  722. /* Save Maximum TX Trigger Level (used for 11n) */
  723. tx_triglevel_max = ah->ah_caps.tx_triglevel_max;
  724. /* return alias for ath_rate_softc * */
  725. return asc;
  726. }
  727. static struct ath_rate_node *ath_rate_node_alloc(struct ath_vap *avp,
  728. struct ath_rate_softc *rsc,
  729. gfp_t gfp)
  730. {
  731. struct ath_rate_node *anode;
  732. anode = kzalloc(sizeof(struct ath_rate_node), gfp);
  733. if (anode == NULL)
  734. return NULL;
  735. anode->avp = avp;
  736. anode->asc = rsc;
  737. avp->rc_node = anode;
  738. return anode;
  739. }
  740. static void ath_rate_node_free(struct ath_rate_node *anode)
  741. {
  742. if (anode != NULL)
  743. kfree(anode);
  744. }
  745. void ath_rate_detach(struct ath_rate_softc *asc)
  746. {
  747. if (asc != NULL)
  748. kfree(asc);
  749. }
  750. u8 ath_rate_findrateix(struct ath_softc *sc,
  751. u8 dot11rate)
  752. {
  753. const struct ath_rate_table *ratetable;
  754. struct ath_rate_softc *rsc = sc->sc_rc;
  755. int i;
  756. ratetable = rsc->hw_rate_table[sc->sc_curmode];
  757. if (WARN_ON(!ratetable))
  758. return 0;
  759. for (i = 0; i < ratetable->rate_cnt; i++) {
  760. if ((ratetable->info[i].dot11rate & 0x7f) == (dot11rate & 0x7f))
  761. return i;
  762. }
  763. return 0;
  764. }
  765. /*
  766. * Update rate-control state on a device state change. When
  767. * operating as a station this includes associate/reassociate
  768. * with an AP. Otherwise this gets called, for example, when
  769. * the we transition to run state when operating as an AP.
  770. */
  771. void ath_rate_newstate(struct ath_softc *sc, struct ath_vap *avp)
  772. {
  773. struct ath_rate_softc *asc = sc->sc_rc;
  774. /* For half and quarter rate channles use different
  775. * rate tables
  776. */
  777. if (sc->sc_ah->ah_curchan->channelFlags & CHANNEL_HALF)
  778. ar5416_sethalf_ratetable(asc);
  779. else if (sc->sc_ah->ah_curchan->channelFlags & CHANNEL_QUARTER)
  780. ar5416_setquarter_ratetable(asc);
  781. else /* full rate */
  782. ar5416_setfull_ratetable(asc);
  783. if (avp->av_config.av_fixed_rateset != IEEE80211_FIXED_RATE_NONE) {
  784. asc->fixedrix =
  785. sc->sc_rixmap[avp->av_config.av_fixed_rateset & 0xff];
  786. /* NB: check the fixed rate exists */
  787. if (asc->fixedrix == 0xff)
  788. asc->fixedrix = IEEE80211_FIXED_RATE_NONE;
  789. } else {
  790. asc->fixedrix = IEEE80211_FIXED_RATE_NONE;
  791. }
  792. }
  793. static u8 ath_rc_ratefind_ht(struct ath_softc *sc,
  794. struct ath_rate_node *ath_rc_priv,
  795. const struct ath_rate_table *rate_table,
  796. int probe_allowed, int *is_probing,
  797. int is_retry)
  798. {
  799. u32 dt, best_thruput, this_thruput, now_msec;
  800. u8 rate, next_rate, best_rate, maxindex, minindex;
  801. int8_t rssi_last, rssi_reduce = 0, index = 0;
  802. *is_probing = FALSE;
  803. rssi_last = median(ath_rc_priv->rssi_last,
  804. ath_rc_priv->rssi_last_prev,
  805. ath_rc_priv->rssi_last_prev2);
  806. /*
  807. * Age (reduce) last ack rssi based on how old it is.
  808. * The bizarre numbers are so the delta is 160msec,
  809. * meaning we divide by 16.
  810. * 0msec <= dt <= 25msec: don't derate
  811. * 25msec <= dt <= 185msec: derate linearly from 0 to 10dB
  812. * 185msec <= dt: derate by 10dB
  813. */
  814. now_msec = jiffies_to_msecs(jiffies);
  815. dt = now_msec - ath_rc_priv->rssi_time;
  816. if (dt >= 185)
  817. rssi_reduce = 10;
  818. else if (dt >= 25)
  819. rssi_reduce = (u8)((dt - 25) >> 4);
  820. /* Now reduce rssi_last by rssi_reduce */
  821. if (rssi_last < rssi_reduce)
  822. rssi_last = 0;
  823. else
  824. rssi_last -= rssi_reduce;
  825. /*
  826. * Now look up the rate in the rssi table and return it.
  827. * If no rates match then we return 0 (lowest rate)
  828. */
  829. best_thruput = 0;
  830. maxindex = ath_rc_priv->max_valid_rate-1;
  831. minindex = 0;
  832. best_rate = minindex;
  833. /*
  834. * Try the higher rate first. It will reduce memory moving time
  835. * if we have very good channel characteristics.
  836. */
  837. for (index = maxindex; index >= minindex ; index--) {
  838. u8 per_thres;
  839. rate = ath_rc_priv->valid_rate_index[index];
  840. if (rate > ath_rc_priv->rate_max_phy)
  841. continue;
  842. /*
  843. * For TCP the average collision rate is around 11%,
  844. * so we ignore PERs less than this. This is to
  845. * prevent the rate we are currently using (whose
  846. * PER might be in the 10-15 range because of TCP
  847. * collisions) looking worse than the next lower
  848. * rate whose PER has decayed close to 0. If we
  849. * used to next lower rate, its PER would grow to
  850. * 10-15 and we would be worse off then staying
  851. * at the current rate.
  852. */
  853. per_thres = ath_rc_priv->state[rate].per;
  854. if (per_thres < 12)
  855. per_thres = 12;
  856. this_thruput = rate_table->info[rate].user_ratekbps *
  857. (100 - per_thres);
  858. if (best_thruput <= this_thruput) {
  859. best_thruput = this_thruput;
  860. best_rate = rate;
  861. }
  862. }
  863. rate = best_rate;
  864. /* if we are retrying for more than half the number
  865. * of max retries, use the min rate for the next retry
  866. */
  867. if (is_retry)
  868. rate = ath_rc_priv->valid_rate_index[minindex];
  869. ath_rc_priv->rssi_last_lookup = rssi_last;
  870. /*
  871. * Must check the actual rate (ratekbps) to account for
  872. * non-monoticity of 11g's rate table
  873. */
  874. if (rate >= ath_rc_priv->rate_max_phy && probe_allowed) {
  875. rate = ath_rc_priv->rate_max_phy;
  876. /* Probe the next allowed phy state */
  877. /* FIXME:XXXX Check to make sure ratMax is checked properly */
  878. if (ath_rc_get_nextvalid_txrate(rate_table,
  879. ath_rc_priv, rate, &next_rate) &&
  880. (now_msec - ath_rc_priv->probe_time >
  881. rate_table->probe_interval) &&
  882. (ath_rc_priv->hw_maxretry_pktcnt >= 1)) {
  883. rate = next_rate;
  884. ath_rc_priv->probe_rate = rate;
  885. ath_rc_priv->probe_time = now_msec;
  886. ath_rc_priv->hw_maxretry_pktcnt = 0;
  887. *is_probing = TRUE;
  888. }
  889. }
  890. /*
  891. * Make sure rate is not higher than the allowed maximum.
  892. * We should also enforce the min, but I suspect the min is
  893. * normally 1 rather than 0 because of the rate 9 vs 6 issue
  894. * in the old code.
  895. */
  896. if (rate > (ath_rc_priv->rate_table_size - 1))
  897. rate = ath_rc_priv->rate_table_size - 1;
  898. ASSERT((rate_table->info[rate].valid && !ath_rc_priv->single_stream) ||
  899. (rate_table->info[rate].valid_single_stream &&
  900. ath_rc_priv->single_stream));
  901. return rate;
  902. }
  903. static void ath_rc_rate_set_series(const struct ath_rate_table *rate_table ,
  904. struct ath_rc_series *series,
  905. u8 tries,
  906. u8 rix,
  907. int rtsctsenable)
  908. {
  909. series->tries = tries;
  910. series->flags = (rtsctsenable ? ATH_RC_RTSCTS_FLAG : 0) |
  911. (WLAN_RC_PHY_DS(rate_table->info[rix].phy) ?
  912. ATH_RC_DS_FLAG : 0) |
  913. (WLAN_RC_PHY_40(rate_table->info[rix].phy) ?
  914. ATH_RC_CW40_FLAG : 0) |
  915. (WLAN_RC_PHY_SGI(rate_table->info[rix].phy) ?
  916. ATH_RC_SGI_FLAG : 0);
  917. series->rix = rate_table->info[rix].base_index;
  918. series->max_4ms_framelen = rate_table->info[rix].max_4ms_framelen;
  919. }
  920. static u8 ath_rc_rate_getidx(struct ath_softc *sc,
  921. struct ath_rate_node *ath_rc_priv,
  922. const struct ath_rate_table *rate_table,
  923. u8 rix, u16 stepdown,
  924. u16 min_rate)
  925. {
  926. u32 j;
  927. u8 nextindex;
  928. if (min_rate) {
  929. for (j = RATE_TABLE_SIZE; j > 0; j--) {
  930. if (ath_rc_get_nextlowervalid_txrate(rate_table,
  931. ath_rc_priv, rix, &nextindex))
  932. rix = nextindex;
  933. else
  934. break;
  935. }
  936. } else {
  937. for (j = stepdown; j > 0; j--) {
  938. if (ath_rc_get_nextlowervalid_txrate(rate_table,
  939. ath_rc_priv, rix, &nextindex))
  940. rix = nextindex;
  941. else
  942. break;
  943. }
  944. }
  945. return rix;
  946. }
  947. static void ath_rc_ratefind(struct ath_softc *sc,
  948. struct ath_rate_node *ath_rc_priv,
  949. int num_tries, int num_rates, unsigned int rcflag,
  950. struct ath_rc_series series[], int *is_probe,
  951. int is_retry)
  952. {
  953. u8 try_per_rate = 0, i = 0, rix, nrix;
  954. struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
  955. struct ath_rate_table *rate_table;
  956. rate_table =
  957. (struct ath_rate_table *)asc->hw_rate_table[sc->sc_curmode];
  958. rix = ath_rc_ratefind_ht(sc, ath_rc_priv, rate_table,
  959. (rcflag & ATH_RC_PROBE_ALLOWED) ? 1 : 0,
  960. is_probe, is_retry);
  961. nrix = rix;
  962. if ((rcflag & ATH_RC_PROBE_ALLOWED) && (*is_probe)) {
  963. /* set one try for probe rates. For the
  964. * probes don't enable rts */
  965. ath_rc_rate_set_series(rate_table,
  966. &series[i++], 1, nrix, FALSE);
  967. try_per_rate = (num_tries/num_rates);
  968. /* Get the next tried/allowed rate. No RTS for the next series
  969. * after the probe rate
  970. */
  971. nrix = ath_rc_rate_getidx(sc,
  972. ath_rc_priv, rate_table, nrix, 1, FALSE);
  973. ath_rc_rate_set_series(rate_table,
  974. &series[i++], try_per_rate, nrix, 0);
  975. } else {
  976. try_per_rate = (num_tries/num_rates);
  977. /* Set the choosen rate. No RTS for first series entry. */
  978. ath_rc_rate_set_series(rate_table,
  979. &series[i++], try_per_rate, nrix, FALSE);
  980. }
  981. /* Fill in the other rates for multirate retry */
  982. for ( ; i < num_rates; i++) {
  983. u8 try_num;
  984. u8 min_rate;
  985. try_num = ((i + 1) == num_rates) ?
  986. num_tries - (try_per_rate * i) : try_per_rate ;
  987. min_rate = (((i + 1) == num_rates) &&
  988. (rcflag & ATH_RC_MINRATE_LASTRATE)) ? 1 : 0;
  989. nrix = ath_rc_rate_getidx(sc, ath_rc_priv,
  990. rate_table, nrix, 1, min_rate);
  991. /* All other rates in the series have RTS enabled */
  992. ath_rc_rate_set_series(rate_table,
  993. &series[i], try_num, nrix, TRUE);
  994. }
  995. /*
  996. * NB:Change rate series to enable aggregation when operating
  997. * at lower MCS rates. When first rate in series is MCS2
  998. * in HT40 @ 2.4GHz, series should look like:
  999. *
  1000. * {MCS2, MCS1, MCS0, MCS0}.
  1001. *
  1002. * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
  1003. * look like:
  1004. *
  1005. * {MCS3, MCS2, MCS1, MCS1}
  1006. *
  1007. * So, set fourth rate in series to be same as third one for
  1008. * above conditions.
  1009. */
  1010. if ((sc->sc_curmode == ATH9K_MODE_11NG_HT20) ||
  1011. (sc->sc_curmode == ATH9K_MODE_11NG_HT40PLUS) ||
  1012. (sc->sc_curmode == ATH9K_MODE_11NG_HT40MINUS)) {
  1013. u8 dot11rate = rate_table->info[rix].dot11rate;
  1014. u8 phy = rate_table->info[rix].phy;
  1015. if (i == 4 &&
  1016. ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) ||
  1017. (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) {
  1018. series[3].rix = series[2].rix;
  1019. series[3].flags = series[2].flags;
  1020. series[3].max_4ms_framelen = series[2].max_4ms_framelen;
  1021. }
  1022. }
  1023. }
  1024. /*
  1025. * Return the Tx rate series.
  1026. */
  1027. static void ath_rate_findrate(struct ath_softc *sc,
  1028. struct ath_rate_node *ath_rc_priv,
  1029. int num_tries,
  1030. int num_rates,
  1031. unsigned int rcflag,
  1032. struct ath_rc_series series[],
  1033. int *is_probe,
  1034. int is_retry)
  1035. {
  1036. struct ath_vap *avp = ath_rc_priv->avp;
  1037. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1038. if (!num_rates || !num_tries)
  1039. return;
  1040. if (avp->av_config.av_fixed_rateset == IEEE80211_FIXED_RATE_NONE) {
  1041. ath_rc_ratefind(sc, ath_rc_priv, num_tries, num_rates,
  1042. rcflag, series, is_probe, is_retry);
  1043. } else {
  1044. /* Fixed rate */
  1045. int idx;
  1046. u8 flags;
  1047. u32 rix;
  1048. struct ath_rate_softc *asc = ath_rc_priv->asc;
  1049. struct ath_rate_table *rate_table;
  1050. rate_table = (struct ath_rate_table *)
  1051. asc->hw_rate_table[sc->sc_curmode];
  1052. for (idx = 0; idx < 4; idx++) {
  1053. unsigned int mcs;
  1054. u8 series_rix = 0;
  1055. series[idx].tries = IEEE80211_RATE_IDX_ENTRY(
  1056. avp->av_config.av_fixed_retryset, idx);
  1057. mcs = IEEE80211_RATE_IDX_ENTRY(
  1058. avp->av_config.av_fixed_rateset, idx);
  1059. if (idx == 3 && (mcs & 0xf0) == 0x70)
  1060. mcs = (mcs & ~0xf0)|0x80;
  1061. if (!(mcs & 0x80))
  1062. flags = 0;
  1063. else
  1064. flags = ((ath_rc_priv->ht_cap &
  1065. WLAN_RC_DS_FLAG) ?
  1066. ATH_RC_DS_FLAG : 0) |
  1067. ((ath_rc_priv->ht_cap &
  1068. WLAN_RC_40_FLAG) ?
  1069. ATH_RC_CW40_FLAG : 0) |
  1070. ((ath_rc_priv->ht_cap &
  1071. WLAN_RC_SGI_FLAG) ?
  1072. ((ath_rc_priv->ht_cap &
  1073. WLAN_RC_40_FLAG) ?
  1074. ATH_RC_SGI_FLAG : 0) : 0);
  1075. series[idx].rix = sc->sc_rixmap[mcs];
  1076. series_rix = series[idx].rix;
  1077. /* XXX: Give me some cleanup love */
  1078. if ((flags & ATH_RC_CW40_FLAG) &&
  1079. (flags & ATH_RC_SGI_FLAG))
  1080. rix = rate_table->info[series_rix].ht_index;
  1081. else if (flags & ATH_RC_SGI_FLAG)
  1082. rix = rate_table->info[series_rix].sgi_index;
  1083. else if (flags & ATH_RC_CW40_FLAG)
  1084. rix = rate_table->info[series_rix].cw40index;
  1085. else
  1086. rix = rate_table->info[series_rix].base_index;
  1087. series[idx].max_4ms_framelen =
  1088. rate_table->info[rix].max_4ms_framelen;
  1089. series[idx].flags = flags;
  1090. }
  1091. }
  1092. }
  1093. static void ath_rc_update_ht(struct ath_softc *sc,
  1094. struct ath_rate_node *ath_rc_priv,
  1095. struct ath_tx_info_priv *info_priv,
  1096. int tx_rate, int xretries, int retries)
  1097. {
  1098. u32 now_msec = jiffies_to_msecs(jiffies);
  1099. int state_change = FALSE, rate, count;
  1100. u8 last_per;
  1101. struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
  1102. struct ath_rate_table *rate_table =
  1103. (struct ath_rate_table *)asc->hw_rate_table[sc->sc_curmode];
  1104. static u32 nretry_to_per_lookup[10] = {
  1105. 100 * 0 / 1,
  1106. 100 * 1 / 4,
  1107. 100 * 1 / 2,
  1108. 100 * 3 / 4,
  1109. 100 * 4 / 5,
  1110. 100 * 5 / 6,
  1111. 100 * 6 / 7,
  1112. 100 * 7 / 8,
  1113. 100 * 8 / 9,
  1114. 100 * 9 / 10
  1115. };
  1116. if (!ath_rc_priv)
  1117. return;
  1118. ASSERT(tx_rate >= 0);
  1119. if (tx_rate < 0)
  1120. return;
  1121. /* To compensate for some imbalance between ctrl and ext. channel */
  1122. if (WLAN_RC_PHY_40(rate_table->info[tx_rate].phy))
  1123. info_priv->tx.ts_rssi =
  1124. info_priv->tx.ts_rssi < 3 ? 0 :
  1125. info_priv->tx.ts_rssi - 3;
  1126. last_per = ath_rc_priv->state[tx_rate].per;
  1127. if (xretries) {
  1128. /* Update the PER. */
  1129. if (xretries == 1) {
  1130. ath_rc_priv->state[tx_rate].per += 30;
  1131. if (ath_rc_priv->state[tx_rate].per > 100)
  1132. ath_rc_priv->state[tx_rate].per = 100;
  1133. } else {
  1134. /* xretries == 2 */
  1135. count = ARRAY_SIZE(nretry_to_per_lookup);
  1136. if (retries >= count)
  1137. retries = count - 1;
  1138. /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
  1139. ath_rc_priv->state[tx_rate].per =
  1140. (u8)(ath_rc_priv->state[tx_rate].per -
  1141. (ath_rc_priv->state[tx_rate].per >> 3) +
  1142. ((100) >> 3));
  1143. }
  1144. /* xretries == 1 or 2 */
  1145. if (ath_rc_priv->probe_rate == tx_rate)
  1146. ath_rc_priv->probe_rate = 0;
  1147. } else { /* xretries == 0 */
  1148. /* Update the PER. */
  1149. /* Make sure it doesn't index out of array's bounds. */
  1150. count = ARRAY_SIZE(nretry_to_per_lookup);
  1151. if (retries >= count)
  1152. retries = count - 1;
  1153. if (info_priv->n_bad_frames) {
  1154. /* new_PER = 7/8*old_PER + 1/8*(currentPER)
  1155. * Assuming that n_frames is not 0. The current PER
  1156. * from the retries is 100 * retries / (retries+1),
  1157. * since the first retries attempts failed, and the
  1158. * next one worked. For the one that worked,
  1159. * n_bad_frames subframes out of n_frames wored,
  1160. * so the PER for that part is
  1161. * 100 * n_bad_frames / n_frames, and it contributes
  1162. * 100 * n_bad_frames / (n_frames * (retries+1)) to
  1163. * the above PER. The expression below is a
  1164. * simplified version of the sum of these two terms.
  1165. */
  1166. if (info_priv->n_frames > 0)
  1167. ath_rc_priv->state[tx_rate].per
  1168. = (u8)
  1169. (ath_rc_priv->state[tx_rate].per -
  1170. (ath_rc_priv->state[tx_rate].per >> 3) +
  1171. ((100*(retries*info_priv->n_frames +
  1172. info_priv->n_bad_frames) /
  1173. (info_priv->n_frames *
  1174. (retries+1))) >> 3));
  1175. } else {
  1176. /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
  1177. ath_rc_priv->state[tx_rate].per = (u8)
  1178. (ath_rc_priv->state[tx_rate].per -
  1179. (ath_rc_priv->state[tx_rate].per >> 3) +
  1180. (nretry_to_per_lookup[retries] >> 3));
  1181. }
  1182. ath_rc_priv->rssi_last_prev2 = ath_rc_priv->rssi_last_prev;
  1183. ath_rc_priv->rssi_last_prev = ath_rc_priv->rssi_last;
  1184. ath_rc_priv->rssi_last = info_priv->tx.ts_rssi;
  1185. ath_rc_priv->rssi_time = now_msec;
  1186. /*
  1187. * If we got at most one retry then increase the max rate if
  1188. * this was a probe. Otherwise, ignore the probe.
  1189. */
  1190. if (ath_rc_priv->probe_rate && ath_rc_priv->probe_rate == tx_rate) {
  1191. if (retries > 0 || 2 * info_priv->n_bad_frames >
  1192. info_priv->n_frames) {
  1193. /*
  1194. * Since we probed with just a single attempt,
  1195. * any retries means the probe failed. Also,
  1196. * if the attempt worked, but more than half
  1197. * the subframes were bad then also consider
  1198. * the probe a failure.
  1199. */
  1200. ath_rc_priv->probe_rate = 0;
  1201. } else {
  1202. u8 probe_rate = 0;
  1203. ath_rc_priv->rate_max_phy = ath_rc_priv->probe_rate;
  1204. probe_rate = ath_rc_priv->probe_rate;
  1205. if (ath_rc_priv->state[probe_rate].per > 30)
  1206. ath_rc_priv->state[probe_rate].per = 20;
  1207. ath_rc_priv->probe_rate = 0;
  1208. /*
  1209. * Since this probe succeeded, we allow the next
  1210. * probe twice as soon. This allows the maxRate
  1211. * to move up faster if the probes are
  1212. * succesful.
  1213. */
  1214. ath_rc_priv->probe_time = now_msec -
  1215. rate_table->probe_interval / 2;
  1216. }
  1217. }
  1218. if (retries > 0) {
  1219. /*
  1220. * Don't update anything. We don't know if
  1221. * this was because of collisions or poor signal.
  1222. *
  1223. * Later: if rssi_ack is close to
  1224. * ath_rc_priv->state[txRate].rssi_thres and we see lots
  1225. * of retries, then we could increase
  1226. * ath_rc_priv->state[txRate].rssi_thres.
  1227. */
  1228. ath_rc_priv->hw_maxretry_pktcnt = 0;
  1229. } else {
  1230. /*
  1231. * It worked with no retries. First ignore bogus (small)
  1232. * rssi_ack values.
  1233. */
  1234. if (tx_rate == ath_rc_priv->rate_max_phy &&
  1235. ath_rc_priv->hw_maxretry_pktcnt < 255) {
  1236. ath_rc_priv->hw_maxretry_pktcnt++;
  1237. }
  1238. if (info_priv->tx.ts_rssi >=
  1239. rate_table->info[tx_rate].rssi_ack_validmin) {
  1240. /* Average the rssi */
  1241. if (tx_rate != ath_rc_priv->rssi_sum_rate) {
  1242. ath_rc_priv->rssi_sum_rate = tx_rate;
  1243. ath_rc_priv->rssi_sum =
  1244. ath_rc_priv->rssi_sum_cnt = 0;
  1245. }
  1246. ath_rc_priv->rssi_sum += info_priv->tx.ts_rssi;
  1247. ath_rc_priv->rssi_sum_cnt++;
  1248. if (ath_rc_priv->rssi_sum_cnt > 4) {
  1249. int32_t rssi_ackAvg =
  1250. (ath_rc_priv->rssi_sum + 2) / 4;
  1251. int8_t rssi_thres =
  1252. ath_rc_priv->state[tx_rate].
  1253. rssi_thres;
  1254. int8_t rssi_ack_vmin =
  1255. rate_table->info[tx_rate].
  1256. rssi_ack_validmin;
  1257. ath_rc_priv->rssi_sum =
  1258. ath_rc_priv->rssi_sum_cnt = 0;
  1259. /* Now reduce the current
  1260. * rssi threshold. */
  1261. if ((rssi_ackAvg < rssi_thres + 2) &&
  1262. (rssi_thres > rssi_ack_vmin)) {
  1263. ath_rc_priv->state[tx_rate].
  1264. rssi_thres--;
  1265. }
  1266. state_change = TRUE;
  1267. }
  1268. }
  1269. }
  1270. }
  1271. /* For all cases */
  1272. /*
  1273. * If this rate looks bad (high PER) then stop using it for
  1274. * a while (except if we are probing).
  1275. */
  1276. if (ath_rc_priv->state[tx_rate].per >= 55 && tx_rate > 0 &&
  1277. rate_table->info[tx_rate].ratekbps <=
  1278. rate_table->info[ath_rc_priv->rate_max_phy].ratekbps) {
  1279. ath_rc_get_nextlowervalid_txrate(rate_table, ath_rc_priv,
  1280. (u8) tx_rate, &ath_rc_priv->rate_max_phy);
  1281. /* Don't probe for a little while. */
  1282. ath_rc_priv->probe_time = now_msec;
  1283. }
  1284. if (state_change) {
  1285. /*
  1286. * Make sure the rates above this have higher rssi thresholds.
  1287. * (Note: Monotonicity is kept within the OFDM rates and
  1288. * within the CCK rates. However, no adjustment is
  1289. * made to keep the rssi thresholds monotonically
  1290. * increasing between the CCK and OFDM rates.)
  1291. */
  1292. for (rate = tx_rate; rate <
  1293. ath_rc_priv->rate_table_size - 1; rate++) {
  1294. if (rate_table->info[rate+1].phy !=
  1295. rate_table->info[tx_rate].phy)
  1296. break;
  1297. if (ath_rc_priv->state[rate].rssi_thres +
  1298. rate_table->info[rate].rssi_ack_deltamin >
  1299. ath_rc_priv->state[rate+1].rssi_thres) {
  1300. ath_rc_priv->state[rate+1].rssi_thres =
  1301. ath_rc_priv->state[rate].
  1302. rssi_thres +
  1303. rate_table->info[rate].
  1304. rssi_ack_deltamin;
  1305. }
  1306. }
  1307. /* Make sure the rates below this have lower rssi thresholds. */
  1308. for (rate = tx_rate - 1; rate >= 0; rate--) {
  1309. if (rate_table->info[rate].phy !=
  1310. rate_table->info[tx_rate].phy)
  1311. break;
  1312. if (ath_rc_priv->state[rate].rssi_thres +
  1313. rate_table->info[rate].rssi_ack_deltamin >
  1314. ath_rc_priv->state[rate+1].rssi_thres) {
  1315. if (ath_rc_priv->state[rate+1].rssi_thres <
  1316. rate_table->info[rate].
  1317. rssi_ack_deltamin)
  1318. ath_rc_priv->state[rate].rssi_thres = 0;
  1319. else {
  1320. ath_rc_priv->state[rate].rssi_thres =
  1321. ath_rc_priv->state[rate+1].
  1322. rssi_thres -
  1323. rate_table->info[rate].
  1324. rssi_ack_deltamin;
  1325. }
  1326. if (ath_rc_priv->state[rate].rssi_thres <
  1327. rate_table->info[rate].
  1328. rssi_ack_validmin) {
  1329. ath_rc_priv->state[rate].rssi_thres =
  1330. rate_table->info[rate].
  1331. rssi_ack_validmin;
  1332. }
  1333. }
  1334. }
  1335. }
  1336. /* Make sure the rates below this have lower PER */
  1337. /* Monotonicity is kept only for rates below the current rate. */
  1338. if (ath_rc_priv->state[tx_rate].per < last_per) {
  1339. for (rate = tx_rate - 1; rate >= 0; rate--) {
  1340. if (rate_table->info[rate].phy !=
  1341. rate_table->info[tx_rate].phy)
  1342. break;
  1343. if (ath_rc_priv->state[rate].per >
  1344. ath_rc_priv->state[rate+1].per) {
  1345. ath_rc_priv->state[rate].per =
  1346. ath_rc_priv->state[rate+1].per;
  1347. }
  1348. }
  1349. }
  1350. /* Maintain monotonicity for rates above the current rate */
  1351. for (rate = tx_rate; rate < ath_rc_priv->rate_table_size - 1; rate++) {
  1352. if (ath_rc_priv->state[rate+1].per < ath_rc_priv->state[rate].per)
  1353. ath_rc_priv->state[rate+1].per =
  1354. ath_rc_priv->state[rate].per;
  1355. }
  1356. /* Every so often, we reduce the thresholds and
  1357. * PER (different for CCK and OFDM). */
  1358. if (now_msec - ath_rc_priv->rssi_down_time >=
  1359. rate_table->rssi_reduce_interval) {
  1360. for (rate = 0; rate < ath_rc_priv->rate_table_size; rate++) {
  1361. if (ath_rc_priv->state[rate].rssi_thres >
  1362. rate_table->info[rate].rssi_ack_validmin)
  1363. ath_rc_priv->state[rate].rssi_thres -= 1;
  1364. }
  1365. ath_rc_priv->rssi_down_time = now_msec;
  1366. }
  1367. /* Every so often, we reduce the thresholds
  1368. * and PER (different for CCK and OFDM). */
  1369. if (now_msec - ath_rc_priv->per_down_time >=
  1370. rate_table->rssi_reduce_interval) {
  1371. for (rate = 0; rate < ath_rc_priv->rate_table_size; rate++) {
  1372. ath_rc_priv->state[rate].per =
  1373. 7 * ath_rc_priv->state[rate].per / 8;
  1374. }
  1375. ath_rc_priv->per_down_time = now_msec;
  1376. }
  1377. }
  1378. /*
  1379. * This routine is called in rate control callback tx_status() to give
  1380. * the status of previous frames.
  1381. */
  1382. static void ath_rc_update(struct ath_softc *sc,
  1383. struct ath_rate_node *ath_rc_priv,
  1384. struct ath_tx_info_priv *info_priv, int final_ts_idx,
  1385. int xretries, int long_retry)
  1386. {
  1387. struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
  1388. struct ath_rate_table *rate_table;
  1389. struct ath_rc_series rcs[4];
  1390. u8 flags;
  1391. u32 series = 0, rix;
  1392. memcpy(rcs, info_priv->rcs, 4 * sizeof(rcs[0]));
  1393. rate_table = (struct ath_rate_table *)
  1394. asc->hw_rate_table[sc->sc_curmode];
  1395. ASSERT(rcs[0].tries != 0);
  1396. /*
  1397. * If the first rate is not the final index, there
  1398. * are intermediate rate failures to be processed.
  1399. */
  1400. if (final_ts_idx != 0) {
  1401. /* Process intermediate rates that failed.*/
  1402. for (series = 0; series < final_ts_idx ; series++) {
  1403. if (rcs[series].tries != 0) {
  1404. flags = rcs[series].flags;
  1405. /* If HT40 and we have switched mode from
  1406. * 40 to 20 => don't update */
  1407. if ((flags & ATH_RC_CW40_FLAG) &&
  1408. (ath_rc_priv->rc_phy_mode !=
  1409. (flags & ATH_RC_CW40_FLAG)))
  1410. return;
  1411. if ((flags & ATH_RC_CW40_FLAG) &&
  1412. (flags & ATH_RC_SGI_FLAG))
  1413. rix = rate_table->info[
  1414. rcs[series].rix].ht_index;
  1415. else if (flags & ATH_RC_SGI_FLAG)
  1416. rix = rate_table->info[
  1417. rcs[series].rix].sgi_index;
  1418. else if (flags & ATH_RC_CW40_FLAG)
  1419. rix = rate_table->info[
  1420. rcs[series].rix].cw40index;
  1421. else
  1422. rix = rate_table->info[
  1423. rcs[series].rix].base_index;
  1424. ath_rc_update_ht(sc, ath_rc_priv,
  1425. info_priv, rix,
  1426. xretries ? 1 : 2,
  1427. rcs[series].tries);
  1428. }
  1429. }
  1430. } else {
  1431. /*
  1432. * Handle the special case of MIMO PS burst, where the second
  1433. * aggregate is sent out with only one rate and one try.
  1434. * Treating it as an excessive retry penalizes the rate
  1435. * inordinately.
  1436. */
  1437. if (rcs[0].tries == 1 && xretries == 1)
  1438. xretries = 2;
  1439. }
  1440. flags = rcs[series].flags;
  1441. /* If HT40 and we have switched mode from 40 to 20 => don't update */
  1442. if ((flags & ATH_RC_CW40_FLAG) &&
  1443. (ath_rc_priv->rc_phy_mode != (flags & ATH_RC_CW40_FLAG)))
  1444. return;
  1445. if ((flags & ATH_RC_CW40_FLAG) && (flags & ATH_RC_SGI_FLAG))
  1446. rix = rate_table->info[rcs[series].rix].ht_index;
  1447. else if (flags & ATH_RC_SGI_FLAG)
  1448. rix = rate_table->info[rcs[series].rix].sgi_index;
  1449. else if (flags & ATH_RC_CW40_FLAG)
  1450. rix = rate_table->info[rcs[series].rix].cw40index;
  1451. else
  1452. rix = rate_table->info[rcs[series].rix].base_index;
  1453. ath_rc_update_ht(sc, ath_rc_priv, info_priv, rix,
  1454. xretries, long_retry);
  1455. }
  1456. /*
  1457. * Process a tx descriptor for a completed transmit (success or failure).
  1458. */
  1459. static void ath_rate_tx_complete(struct ath_softc *sc,
  1460. struct ath_node *an,
  1461. struct ath_rate_node *rc_priv,
  1462. struct ath_tx_info_priv *info_priv)
  1463. {
  1464. int final_ts_idx = info_priv->tx.ts_rateindex;
  1465. int tx_status = 0, is_underrun = 0;
  1466. struct ath_vap *avp;
  1467. avp = rc_priv->avp;
  1468. if ((avp->av_config.av_fixed_rateset != IEEE80211_FIXED_RATE_NONE) ||
  1469. (info_priv->tx.ts_status & ATH9K_TXERR_FILT))
  1470. return;
  1471. if (info_priv->tx.ts_rssi > 0) {
  1472. ATH_RSSI_LPF(an->an_chainmask_sel.tx_avgrssi,
  1473. info_priv->tx.ts_rssi);
  1474. }
  1475. /*
  1476. * If underrun error is seen assume it as an excessive retry only
  1477. * if prefetch trigger level have reached the max (0x3f for 5416)
  1478. * Adjust the long retry as if the frame was tried ATH_11N_TXMAXTRY
  1479. * times. This affects how ratectrl updates PER for the failed rate.
  1480. */
  1481. if (info_priv->tx.ts_flags &
  1482. (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN) &&
  1483. ((sc->sc_ah->ah_txTrigLevel) >= tx_triglevel_max)) {
  1484. tx_status = 1;
  1485. is_underrun = 1;
  1486. }
  1487. if ((info_priv->tx.ts_status & ATH9K_TXERR_XRETRY) ||
  1488. (info_priv->tx.ts_status & ATH9K_TXERR_FIFO))
  1489. tx_status = 1;
  1490. ath_rc_update(sc, rc_priv, info_priv, final_ts_idx, tx_status,
  1491. (is_underrun) ? ATH_11N_TXMAXTRY :
  1492. info_priv->tx.ts_longretry);
  1493. }
  1494. /*
  1495. * Update the SIB's rate control information
  1496. *
  1497. * This should be called when the supported rates change
  1498. * (e.g. SME operation, wireless mode change)
  1499. *
  1500. * It will determine which rates are valid for use.
  1501. */
  1502. static void ath_rc_sib_update(struct ath_softc *sc,
  1503. struct ath_rate_node *ath_rc_priv,
  1504. u32 capflag, int keep_state,
  1505. struct ath_rateset *negotiated_rates,
  1506. struct ath_rateset *negotiated_htrates)
  1507. {
  1508. struct ath_rate_table *rate_table = NULL;
  1509. struct ath_rate_softc *asc = (struct ath_rate_softc *)sc->sc_rc;
  1510. struct ath_rateset *rateset = negotiated_rates;
  1511. u8 *ht_mcs = (u8 *)negotiated_htrates;
  1512. u8 i, j, k, hi = 0, hthi = 0;
  1513. rate_table = (struct ath_rate_table *)
  1514. asc->hw_rate_table[sc->sc_curmode];
  1515. /* Initial rate table size. Will change depending
  1516. * on the working rate set */
  1517. ath_rc_priv->rate_table_size = MAX_TX_RATE_TBL;
  1518. /* Initialize thresholds according to the global rate table */
  1519. for (i = 0 ; (i < ath_rc_priv->rate_table_size) && (!keep_state); i++) {
  1520. ath_rc_priv->state[i].rssi_thres =
  1521. rate_table->info[i].rssi_ack_validmin;
  1522. ath_rc_priv->state[i].per = 0;
  1523. }
  1524. /* Determine the valid rates */
  1525. ath_rc_init_valid_txmask(ath_rc_priv);
  1526. for (i = 0; i < WLAN_RC_PHY_MAX; i++) {
  1527. for (j = 0; j < MAX_TX_RATE_PHY; j++)
  1528. ath_rc_priv->valid_phy_rateidx[i][j] = 0;
  1529. ath_rc_priv->valid_phy_ratecnt[i] = 0;
  1530. }
  1531. ath_rc_priv->rc_phy_mode = (capflag & WLAN_RC_40_FLAG);
  1532. /* Set stream capability */
  1533. ath_rc_priv->single_stream = (capflag & WLAN_RC_DS_FLAG) ? 0 : 1;
  1534. if (!rateset->rs_nrates) {
  1535. /* No working rate, just initialize valid rates */
  1536. hi = ath_rc_sib_init_validrates(ath_rc_priv, rate_table,
  1537. capflag);
  1538. } else {
  1539. /* Use intersection of working rates and valid rates */
  1540. hi = ath_rc_sib_setvalid_rates(ath_rc_priv, rate_table,
  1541. rateset, capflag);
  1542. if (capflag & WLAN_RC_HT_FLAG) {
  1543. hthi = ath_rc_sib_setvalid_htrates(ath_rc_priv,
  1544. rate_table,
  1545. ht_mcs,
  1546. capflag);
  1547. }
  1548. hi = A_MAX(hi, hthi);
  1549. }
  1550. ath_rc_priv->rate_table_size = hi + 1;
  1551. ath_rc_priv->rate_max_phy = 0;
  1552. ASSERT(ath_rc_priv->rate_table_size <= MAX_TX_RATE_TBL);
  1553. for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) {
  1554. for (j = 0; j < ath_rc_priv->valid_phy_ratecnt[i]; j++) {
  1555. ath_rc_priv->valid_rate_index[k++] =
  1556. ath_rc_priv->valid_phy_rateidx[i][j];
  1557. }
  1558. if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, TRUE)
  1559. || !ath_rc_priv->valid_phy_ratecnt[i])
  1560. continue;
  1561. ath_rc_priv->rate_max_phy = ath_rc_priv->valid_phy_rateidx[i][j-1];
  1562. }
  1563. ASSERT(ath_rc_priv->rate_table_size <= MAX_TX_RATE_TBL);
  1564. ASSERT(k <= MAX_TX_RATE_TBL);
  1565. ath_rc_priv->max_valid_rate = k;
  1566. /*
  1567. * Some third party vendors don't send the supported rate series in
  1568. * order. So sorting to make sure its in order, otherwise our RateFind
  1569. * Algo will select wrong rates
  1570. */
  1571. ath_rc_sort_validrates(rate_table, ath_rc_priv);
  1572. ath_rc_priv->rate_max_phy = ath_rc_priv->valid_rate_index[k-4];
  1573. }
  1574. /*
  1575. * Update rate-control state on station associate/reassociate.
  1576. */
  1577. static int ath_rate_newassoc(struct ath_softc *sc,
  1578. struct ath_rate_node *ath_rc_priv,
  1579. unsigned int capflag,
  1580. struct ath_rateset *negotiated_rates,
  1581. struct ath_rateset *negotiated_htrates)
  1582. {
  1583. ath_rc_priv->ht_cap =
  1584. ((capflag & ATH_RC_DS_FLAG) ? WLAN_RC_DS_FLAG : 0) |
  1585. ((capflag & ATH_RC_SGI_FLAG) ? WLAN_RC_SGI_FLAG : 0) |
  1586. ((capflag & ATH_RC_HT_FLAG) ? WLAN_RC_HT_FLAG : 0) |
  1587. ((capflag & ATH_RC_CW40_FLAG) ? WLAN_RC_40_FLAG : 0);
  1588. ath_rc_sib_update(sc, ath_rc_priv, ath_rc_priv->ht_cap, 0,
  1589. negotiated_rates, negotiated_htrates);
  1590. return 0;
  1591. }
  1592. /*
  1593. * This routine is called to initialize the rate control parameters
  1594. * in the SIB. It is called initially during system initialization
  1595. * or when a station is associated with the AP.
  1596. */
  1597. static void ath_rc_sib_init(struct ath_rate_node *ath_rc_priv)
  1598. {
  1599. ath_rc_priv->rssi_down_time = jiffies_to_msecs(jiffies);
  1600. }
  1601. static void ath_setup_rates(struct ath_softc *sc,
  1602. struct ieee80211_supported_band *sband,
  1603. struct ieee80211_sta *sta,
  1604. struct ath_rate_node *rc_priv)
  1605. {
  1606. int i, j = 0;
  1607. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1608. for (i = 0; i < sband->n_bitrates; i++) {
  1609. if (sta->supp_rates[sband->band] & BIT(i)) {
  1610. rc_priv->neg_rates.rs_rates[j]
  1611. = (sband->bitrates[i].bitrate * 2) / 10;
  1612. j++;
  1613. }
  1614. }
  1615. rc_priv->neg_rates.rs_nrates = j;
  1616. }
  1617. void ath_rc_node_update(struct ieee80211_hw *hw, struct ath_rate_node *rc_priv)
  1618. {
  1619. struct ath_softc *sc = hw->priv;
  1620. u32 capflag = 0;
  1621. if (hw->conf.ht.enabled) {
  1622. capflag |= ATH_RC_HT_FLAG | ATH_RC_DS_FLAG;
  1623. if (sc->sc_ht_info.tx_chan_width == ATH9K_HT_MACMODE_2040)
  1624. capflag |= ATH_RC_CW40_FLAG;
  1625. }
  1626. ath_rate_newassoc(sc, rc_priv, capflag,
  1627. &rc_priv->neg_rates,
  1628. &rc_priv->neg_ht_rates);
  1629. }
  1630. /* Rate Control callbacks */
  1631. static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
  1632. struct ieee80211_sta *sta, void *priv_sta,
  1633. struct sk_buff *skb)
  1634. {
  1635. struct ath_softc *sc = priv;
  1636. struct ath_tx_info_priv *tx_info_priv;
  1637. struct ath_node *an;
  1638. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1639. struct ieee80211_hdr *hdr;
  1640. __le16 fc;
  1641. hdr = (struct ieee80211_hdr *)skb->data;
  1642. fc = hdr->frame_control;
  1643. /* XXX: UGLY HACK!! */
  1644. tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif;
  1645. an = (struct ath_node *)sta->drv_priv;
  1646. if (tx_info_priv == NULL)
  1647. return;
  1648. if (an && priv_sta && ieee80211_is_data(fc))
  1649. ath_rate_tx_complete(sc, an, priv_sta, tx_info_priv);
  1650. kfree(tx_info_priv);
  1651. tx_info->control.vif = NULL;
  1652. }
  1653. static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
  1654. struct ieee80211_tx_rate_control *txrc)
  1655. {
  1656. struct ieee80211_supported_band *sband = txrc->sband;
  1657. struct sk_buff *skb = txrc->skb;
  1658. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1659. struct ath_softc *sc = priv;
  1660. struct ieee80211_hw *hw = sc->hw;
  1661. struct ath_tx_info_priv *tx_info_priv;
  1662. struct ath_rate_node *ath_rc_priv = priv_sta;
  1663. struct ath_node *an;
  1664. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  1665. int is_probe = FALSE;
  1666. s8 lowest_idx;
  1667. __le16 fc = hdr->frame_control;
  1668. u8 *qc, tid;
  1669. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1670. /* allocate driver private area of tx_info, XXX: UGLY HACK! */
  1671. tx_info->control.vif = kzalloc(sizeof(*tx_info_priv), GFP_ATOMIC);
  1672. tx_info_priv = (struct ath_tx_info_priv *)tx_info->control.vif;
  1673. ASSERT(tx_info_priv != NULL);
  1674. lowest_idx = rate_lowest_index(sband, sta);
  1675. tx_info_priv->min_rate = (sband->bitrates[lowest_idx].bitrate * 2) / 10;
  1676. /* lowest rate for management and multicast/broadcast frames */
  1677. if (!ieee80211_is_data(fc) ||
  1678. is_multicast_ether_addr(hdr->addr1) || !sta) {
  1679. tx_info->control.rates[0].idx = lowest_idx;
  1680. return;
  1681. }
  1682. /* Find tx rate for unicast frames */
  1683. ath_rate_findrate(sc, ath_rc_priv,
  1684. ATH_11N_TXMAXTRY, 4,
  1685. ATH_RC_PROBE_ALLOWED,
  1686. tx_info_priv->rcs,
  1687. &is_probe,
  1688. false);
  1689. #if 0
  1690. if (is_probe)
  1691. sel->probe_idx = ath_rc_priv->tx_ratectrl.probe_rate;
  1692. #endif
  1693. /* Ratecontrol sometimes returns invalid rate index */
  1694. if (tx_info_priv->rcs[0].rix != 0xff)
  1695. ath_rc_priv->prev_data_rix = tx_info_priv->rcs[0].rix;
  1696. else
  1697. tx_info_priv->rcs[0].rix = ath_rc_priv->prev_data_rix;
  1698. tx_info->control.rates[0].idx = tx_info_priv->rcs[0].rix;
  1699. /* Check if aggregation has to be enabled for this tid */
  1700. if (hw->conf.ht.enabled) {
  1701. if (ieee80211_is_data_qos(fc)) {
  1702. qc = ieee80211_get_qos_ctl(hdr);
  1703. tid = qc[0] & 0xf;
  1704. an = (struct ath_node *)sta->drv_priv;
  1705. if(ath_tx_aggr_check(sc, an, tid))
  1706. ieee80211_start_tx_ba_session(hw, hdr->addr1, tid);
  1707. }
  1708. }
  1709. }
  1710. static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
  1711. struct ieee80211_sta *sta, void *priv_sta)
  1712. {
  1713. struct ath_softc *sc = priv;
  1714. struct ath_rate_node *ath_rc_priv = priv_sta;
  1715. int i, j = 0;
  1716. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1717. ath_setup_rates(sc, sband, sta, ath_rc_priv);
  1718. if (sta->ht_cap.ht_supported) {
  1719. for (i = 0; i < 77; i++) {
  1720. if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
  1721. ath_rc_priv->neg_ht_rates.rs_rates[j++] = i;
  1722. if (j == ATH_RATE_MAX)
  1723. break;
  1724. }
  1725. ath_rc_priv->neg_ht_rates.rs_nrates = j;
  1726. }
  1727. ath_rc_node_update(sc->hw, priv_sta);
  1728. }
  1729. static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
  1730. {
  1731. struct ath_softc *sc = hw->priv;
  1732. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1733. return hw->priv;
  1734. }
  1735. static void ath_rate_free(void *priv)
  1736. {
  1737. return;
  1738. }
  1739. static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
  1740. {
  1741. struct ieee80211_vif *vif;
  1742. struct ath_softc *sc = priv;
  1743. struct ath_vap *avp;
  1744. struct ath_rate_node *rate_priv;
  1745. DPRINTF(sc, ATH_DBG_RATE, "%s\n", __func__);
  1746. vif = sc->sc_vaps[0];
  1747. ASSERT(vif);
  1748. avp = (void *)vif->drv_priv;
  1749. rate_priv = ath_rate_node_alloc(avp, sc->sc_rc, gfp);
  1750. if (!rate_priv) {
  1751. DPRINTF(sc, ATH_DBG_FATAL,
  1752. "%s: Unable to allocate private rc structure\n",
  1753. __func__);
  1754. return NULL;
  1755. }
  1756. ath_rc_sib_init(rate_priv);
  1757. return rate_priv;
  1758. }
  1759. static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta,
  1760. void *priv_sta)
  1761. {
  1762. struct ath_rate_node *rate_priv = priv_sta;
  1763. struct ath_softc *sc = priv;
  1764. DPRINTF(sc, ATH_DBG_RATE, "%s", __func__);
  1765. ath_rate_node_free(rate_priv);
  1766. }
  1767. static struct rate_control_ops ath_rate_ops = {
  1768. .module = NULL,
  1769. .name = "ath9k_rate_control",
  1770. .tx_status = ath_tx_status,
  1771. .get_rate = ath_get_rate,
  1772. .rate_init = ath_rate_init,
  1773. .alloc = ath_rate_alloc,
  1774. .free = ath_rate_free,
  1775. .alloc_sta = ath_rate_alloc_sta,
  1776. .free_sta = ath_rate_free_sta,
  1777. };
  1778. int ath_rate_control_register(void)
  1779. {
  1780. return ieee80211_rate_control_register(&ath_rate_ops);
  1781. }
  1782. void ath_rate_control_unregister(void)
  1783. {
  1784. ieee80211_rate_control_unregister(&ath_rate_ops);
  1785. }