blob: 7eb1f4b458e4fb1f3c096fd297bb60b273d9c686 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
2 * Copyright (c) 2004 Video54 Technologies, Inc.
Sujith Manoharan5b681382011-05-17 13:36:18 +05303 * Copyright (c) 2004-2011 Atheros Communications, Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004 *
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
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Paul Gortmakeree40fa02011-05-27 16:14:23 -040019#include <linux/export.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020
Sujith394cf0a2009-02-09 13:26:54 +053021#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -040023static const struct ath_rate_table ar5416_11na_ratetable = {
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053024 68,
Felix Fietkau545750d2009-11-23 22:21:01 +010025 8, /* MCS start */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070026 {
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053027 [0] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 6000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053028 5400, 0, 12 }, /* 6 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053029 [1] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 9000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053030 7800, 1, 18 }, /* 9 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053031 [2] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 12000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053032 10000, 2, 24 }, /* 12 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053033 [3] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 18000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053034 13900, 3, 36 }, /* 18 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053035 [4] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 24000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053036 17300, 4, 48 }, /* 24 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053037 [5] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 36000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053038 23000, 5, 72 }, /* 36 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053039 [6] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 48000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053040 27400, 6, 96 }, /* 48 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053041 [7] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 54000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053042 29300, 7, 108 }, /* 54 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053043 [8] = { RC_HT_SDT_2040, WLAN_RC_PHY_HT_20_SS, 6500,
Sujith Manoharan23d99392012-08-10 16:47:23 +053044 6400, 0, 0 }, /* 6.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053045 [9] = { RC_HT_SDT_20, WLAN_RC_PHY_HT_20_SS, 13000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053046 12700, 1, 1 }, /* 13 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053047 [10] = { RC_HT_SDT_20, WLAN_RC_PHY_HT_20_SS, 19500,
Sujith Manoharan23d99392012-08-10 16:47:23 +053048 18800, 2, 2 }, /* 19.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053049 [11] = { RC_HT_SD_20, WLAN_RC_PHY_HT_20_SS, 26000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053050 25000, 3, 3 }, /* 26 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053051 [12] = { RC_HT_SD_20, WLAN_RC_PHY_HT_20_SS, 39000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053052 36700, 4, 4 }, /* 39 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053053 [13] = { RC_HT_S_20, WLAN_RC_PHY_HT_20_SS, 52000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053054 48100, 5, 5 }, /* 52 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053055 [14] = { RC_HT_S_20, WLAN_RC_PHY_HT_20_SS, 58500,
Sujith Manoharan23d99392012-08-10 16:47:23 +053056 53500, 6, 6 }, /* 58.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053057 [15] = { RC_HT_S_20, WLAN_RC_PHY_HT_20_SS, 65000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053058 59000, 7, 7 }, /* 65 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053059 [16] = { RC_HT_S_20, WLAN_RC_PHY_HT_20_SS_HGI, 72200,
Sujith Manoharan23d99392012-08-10 16:47:23 +053060 65400, 7, 7 }, /* 75 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053061 [17] = { RC_INVALID, WLAN_RC_PHY_HT_20_DS, 13000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053062 12700, 8, 8 }, /* 13 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053063 [18] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_DS, 26000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053064 24800, 9, 9 }, /* 26 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053065 [19] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_DS, 39000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053066 36600, 10, 10 }, /* 39 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053067 [20] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS, 52000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053068 48100, 11, 11 }, /* 52 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053069 [21] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS, 78000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053070 69500, 12, 12 }, /* 78 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053071 [22] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS, 104000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053072 89500, 13, 13 }, /* 104 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053073 [23] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS, 117000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053074 98900, 14, 14 }, /* 117 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053075 [24] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS, 130000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053076 108300, 15, 15 }, /* 130 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053077 [25] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS_HGI, 144400,
Sujith Manoharan23d99392012-08-10 16:47:23 +053078 120000, 15, 15 }, /* 144.4 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053079 [26] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS, 19500,
Sujith Manoharan23d99392012-08-10 16:47:23 +053080 17400, 16, 16 }, /* 19.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053081 [27] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS, 39000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053082 35100, 17, 17 }, /* 39 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053083 [28] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS, 58500,
Sujith Manoharan23d99392012-08-10 16:47:23 +053084 52600, 18, 18 }, /* 58.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053085 [29] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS, 78000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053086 70400, 19, 19 }, /* 78 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053087 [30] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS, 117000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053088 104900, 20, 20 }, /* 117 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053089 [31] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS_HGI, 130000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053090 115800, 20, 20 }, /* 130 Mb*/
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053091 [32] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS, 156000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053092 137200, 21, 21 }, /* 156 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053093 [33] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS_HGI, 173300,
Sujith Manoharan23d99392012-08-10 16:47:23 +053094 151100, 21, 21 }, /* 173.3 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053095 [34] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS, 175500,
Sujith Manoharan23d99392012-08-10 16:47:23 +053096 152800, 22, 22 }, /* 175.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053097 [35] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS_HGI, 195000,
Sujith Manoharan23d99392012-08-10 16:47:23 +053098 168400, 22, 22 }, /* 195 Mb*/
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +053099 [36] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS, 195000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530100 168400, 23, 23 }, /* 195 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530101 [37] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS_HGI, 216700,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530102 185000, 23, 23 }, /* 216.7 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530103 [38] = { RC_HT_SDT_40, WLAN_RC_PHY_HT_40_SS, 13500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530104 13200, 0, 0 }, /* 13.5 Mb*/
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530105 [39] = { RC_HT_SDT_40, WLAN_RC_PHY_HT_40_SS, 27500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530106 25900, 1, 1 }, /* 27.0 Mb*/
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530107 [40] = { RC_HT_SDT_40, WLAN_RC_PHY_HT_40_SS, 40500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530108 38600, 2, 2 }, /* 40.5 Mb*/
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530109 [41] = { RC_HT_SD_40, WLAN_RC_PHY_HT_40_SS, 54000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530110 49800, 3, 3 }, /* 54 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530111 [42] = { RC_HT_SD_40, WLAN_RC_PHY_HT_40_SS, 81500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530112 72200, 4, 4 }, /* 81 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530113 [43] = { RC_HT_S_40, WLAN_RC_PHY_HT_40_SS, 108000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530114 92900, 5, 5 }, /* 108 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530115 [44] = { RC_HT_S_40, WLAN_RC_PHY_HT_40_SS, 121500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530116 102700, 6, 6 }, /* 121.5 Mb*/
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530117 [45] = { RC_HT_S_40, WLAN_RC_PHY_HT_40_SS, 135000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530118 112000, 7, 7 }, /* 135 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530119 [46] = { RC_HT_S_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530120 122000, 7, 7 }, /* 150 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530121 [47] = { RC_INVALID, WLAN_RC_PHY_HT_40_DS, 27000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530122 25800, 8, 8 }, /* 27 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530123 [48] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_DS, 54000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530124 49800, 9, 9 }, /* 54 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530125 [49] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_DS, 81000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530126 71900, 10, 10 }, /* 81 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530127 [50] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS, 108000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530128 92500, 11, 11 }, /* 108 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530129 [51] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS, 162000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530130 130300, 12, 12 }, /* 162 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530131 [52] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS, 216000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530132 162800, 13, 13 }, /* 216 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530133 [53] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS, 243000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530134 178200, 14, 14 }, /* 243 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530135 [54] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS, 270000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530136 192100, 15, 15 }, /* 270 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530137 [55] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS_HGI, 300000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530138 207000, 15, 15 }, /* 300 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530139 [56] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS, 40500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530140 36100, 16, 16 }, /* 40.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530141 [57] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS, 81000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530142 72900, 17, 17 }, /* 81 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530143 [58] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS, 121500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530144 108300, 18, 18 }, /* 121.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530145 [59] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS, 162000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530146 142000, 19, 19 }, /* 162 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530147 [60] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS, 243000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530148 205100, 20, 20 }, /* 243 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530149 [61] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS_HGI, 270000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530150 224700, 20, 20 }, /* 270 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530151 [62] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS, 324000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530152 263100, 21, 21 }, /* 324 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530153 [63] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS_HGI, 360000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530154 288000, 21, 21 }, /* 360 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530155 [64] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS, 364500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530156 290700, 22, 22 }, /* 364.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530157 [65] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS_HGI, 405000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530158 317200, 22, 22 }, /* 405 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530159 [66] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS, 405000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530160 317200, 23, 23 }, /* 405 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530161 [67] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS_HGI, 450000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530162 346400, 23, 23 }, /* 450 Mb */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700163 },
164 50, /* probe interval */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700165 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
166};
167
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700168/* 4ms frame limit not used for NG mode. The values filled
169 * for HT are the 64K max aggregate limit */
170
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400171static const struct ath_rate_table ar5416_11ng_ratetable = {
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530172 72,
Felix Fietkau545750d2009-11-23 22:21:01 +0100173 12, /* MCS start */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700174 {
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530175 [0] = { RC_ALL, WLAN_RC_PHY_CCK, 1000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530176 900, 0, 2 }, /* 1 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530177 [1] = { RC_ALL, WLAN_RC_PHY_CCK, 2000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530178 1900, 1, 4 }, /* 2 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530179 [2] = { RC_ALL, WLAN_RC_PHY_CCK, 5500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530180 4900, 2, 11 }, /* 5.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530181 [3] = { RC_ALL, WLAN_RC_PHY_CCK, 11000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530182 8100, 3, 22 }, /* 11 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530183 [4] = { RC_INVALID, WLAN_RC_PHY_OFDM, 6000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530184 5400, 4, 12 }, /* 6 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530185 [5] = { RC_INVALID, WLAN_RC_PHY_OFDM, 9000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530186 7800, 5, 18 }, /* 9 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530187 [6] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 12000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530188 10100, 6, 24 }, /* 12 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530189 [7] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 18000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530190 14100, 7, 36 }, /* 18 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530191 [8] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 24000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530192 17700, 8, 48 }, /* 24 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530193 [9] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 36000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530194 23700, 9, 72 }, /* 36 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530195 [10] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 48000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530196 27400, 10, 96 }, /* 48 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530197 [11] = { RC_L_SDT, WLAN_RC_PHY_OFDM, 54000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530198 30900, 11, 108 }, /* 54 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530199 [12] = { RC_INVALID, WLAN_RC_PHY_HT_20_SS, 6500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530200 6400, 0, 0 }, /* 6.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530201 [13] = { RC_HT_SDT_20, WLAN_RC_PHY_HT_20_SS, 13000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530202 12700, 1, 1 }, /* 13 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530203 [14] = { RC_HT_SDT_20, WLAN_RC_PHY_HT_20_SS, 19500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530204 18800, 2, 2 }, /* 19.5 Mb*/
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530205 [15] = { RC_HT_SD_20, WLAN_RC_PHY_HT_20_SS, 26000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530206 25000, 3, 3 }, /* 26 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530207 [16] = { RC_HT_SD_20, WLAN_RC_PHY_HT_20_SS, 39000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530208 36700, 4, 4 }, /* 39 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530209 [17] = { RC_HT_S_20, WLAN_RC_PHY_HT_20_SS, 52000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530210 48100, 5, 5 }, /* 52 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530211 [18] = { RC_HT_S_20, WLAN_RC_PHY_HT_20_SS, 58500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530212 53500, 6, 6 }, /* 58.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530213 [19] = { RC_HT_S_20, WLAN_RC_PHY_HT_20_SS, 65000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530214 59000, 7, 7 }, /* 65 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530215 [20] = { RC_HT_S_20, WLAN_RC_PHY_HT_20_SS_HGI, 72200,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530216 65400, 7, 7 }, /* 65 Mb*/
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530217 [21] = { RC_INVALID, WLAN_RC_PHY_HT_20_DS, 13000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530218 12700, 8, 8 }, /* 13 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530219 [22] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_DS, 26000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530220 24800, 9, 9 }, /* 26 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530221 [23] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_DS, 39000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530222 36600, 10, 10 }, /* 39 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530223 [24] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS, 52000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530224 48100, 11, 11 }, /* 52 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530225 [25] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS, 78000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530226 69500, 12, 12 }, /* 78 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530227 [26] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS, 104000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530228 89500, 13, 13 }, /* 104 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530229 [27] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS, 117000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530230 98900, 14, 14 }, /* 117 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530231 [28] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS, 130000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530232 108300, 15, 15 }, /* 130 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530233 [29] = { RC_HT_DT_20, WLAN_RC_PHY_HT_20_DS_HGI, 144400,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530234 120000, 15, 15 }, /* 144.4 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530235 [30] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS, 19500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530236 17400, 16, 16 }, /* 19.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530237 [31] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS, 39000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530238 35100, 17, 17 }, /* 39 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530239 [32] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS, 58500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530240 52600, 18, 18 }, /* 58.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530241 [33] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS, 78000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530242 70400, 19, 19 }, /* 78 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530243 [34] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS, 117000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530244 104900, 20, 20 }, /* 117 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530245 [35] = { RC_INVALID, WLAN_RC_PHY_HT_20_TS_HGI, 130000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530246 115800, 20, 20 }, /* 130 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530247 [36] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS, 156000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530248 137200, 21, 21 }, /* 156 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530249 [37] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS_HGI, 173300,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530250 151100, 21, 21 }, /* 173.3 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530251 [38] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS, 175500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530252 152800, 22, 22 }, /* 175.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530253 [39] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS_HGI, 195000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530254 168400, 22, 22 }, /* 195 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530255 [40] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS, 195000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530256 168400, 23, 23 }, /* 195 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530257 [41] = { RC_HT_T_20, WLAN_RC_PHY_HT_20_TS_HGI, 216700,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530258 185000, 23, 23 }, /* 216.7 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530259 [42] = { RC_HT_SDT_40, WLAN_RC_PHY_HT_40_SS, 13500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530260 13200, 0, 0 }, /* 13.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530261 [43] = { RC_HT_SDT_40, WLAN_RC_PHY_HT_40_SS, 27500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530262 25900, 1, 1 }, /* 27.0 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530263 [44] = { RC_HT_SDT_40, WLAN_RC_PHY_HT_40_SS, 40500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530264 38600, 2, 2 }, /* 40.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530265 [45] = { RC_HT_SD_40, WLAN_RC_PHY_HT_40_SS, 54000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530266 49800, 3, 3 }, /* 54 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530267 [46] = { RC_HT_SD_40, WLAN_RC_PHY_HT_40_SS, 81500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530268 72200, 4, 4 }, /* 81 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530269 [47] = { RC_HT_S_40 , WLAN_RC_PHY_HT_40_SS, 108000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530270 92900, 5, 5 }, /* 108 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530271 [48] = { RC_HT_S_40, WLAN_RC_PHY_HT_40_SS, 121500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530272 102700, 6, 6 }, /* 121.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530273 [49] = { RC_HT_S_40, WLAN_RC_PHY_HT_40_SS, 135000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530274 112000, 7, 7 }, /* 135 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530275 [50] = { RC_HT_S_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530276 122000, 7, 7 }, /* 150 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530277 [51] = { RC_INVALID, WLAN_RC_PHY_HT_40_DS, 27000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530278 25800, 8, 8 }, /* 27 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530279 [52] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_DS, 54000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530280 49800, 9, 9 }, /* 54 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530281 [53] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_DS, 81000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530282 71900, 10, 10 }, /* 81 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530283 [54] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS, 108000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530284 92500, 11, 11 }, /* 108 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530285 [55] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS, 162000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530286 130300, 12, 12 }, /* 162 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530287 [56] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS, 216000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530288 162800, 13, 13 }, /* 216 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530289 [57] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS, 243000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530290 178200, 14, 14 }, /* 243 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530291 [58] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS, 270000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530292 192100, 15, 15 }, /* 270 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530293 [59] = { RC_HT_DT_40, WLAN_RC_PHY_HT_40_DS_HGI, 300000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530294 207000, 15, 15 }, /* 300 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530295 [60] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS, 40500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530296 36100, 16, 16 }, /* 40.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530297 [61] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS, 81000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530298 72900, 17, 17 }, /* 81 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530299 [62] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS, 121500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530300 108300, 18, 18 }, /* 121.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530301 [63] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS, 162000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530302 142000, 19, 19 }, /* 162 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530303 [64] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS, 243000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530304 205100, 20, 20 }, /* 243 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530305 [65] = { RC_INVALID, WLAN_RC_PHY_HT_40_TS_HGI, 270000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530306 224700, 20, 20 }, /* 270 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530307 [66] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS, 324000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530308 263100, 21, 21 }, /* 324 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530309 [67] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS_HGI, 360000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530310 288000, 21, 21 }, /* 360 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530311 [68] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS, 364500,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530312 290700, 22, 22 }, /* 364.5 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530313 [69] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS_HGI, 405000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530314 317200, 22, 22 }, /* 405 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530315 [70] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS, 405000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530316 317200, 23, 23 }, /* 405 Mb */
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530317 [71] = { RC_HT_T_40, WLAN_RC_PHY_HT_40_TS_HGI, 450000,
Sujith Manoharan23d99392012-08-10 16:47:23 +0530318 346400, 23, 23 }, /* 450 Mb */
Felix Fietkau1fe82342009-11-23 22:22:27 +0100319 },
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700320 50, /* probe interval */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700321 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
322};
323
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400324static const struct ath_rate_table ar5416_11a_ratetable = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700325 8,
Felix Fietkau545750d2009-11-23 22:21:01 +0100326 0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700327 {
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530328 { RC_L_SDT, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530329 5400, 0, 12},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530330 { RC_L_SDT, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530331 7800, 1, 18},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530332 { RC_L_SDT, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530333 10000, 2, 24},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530334 { RC_L_SDT, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530335 13900, 3, 36},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530336 { RC_L_SDT, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530337 17300, 4, 48},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530338 { RC_L_SDT, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530339 23000, 5, 72},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530340 { RC_L_SDT, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530341 27400, 6, 96},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530342 { RC_L_SDT, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530343 29300, 7, 108},
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700344 },
345 50, /* probe interval */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700346 0, /* Phy rates allowed initially */
347};
348
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400349static const struct ath_rate_table ar5416_11g_ratetable = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700350 12,
Felix Fietkau545750d2009-11-23 22:21:01 +0100351 0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700352 {
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530353 { RC_L_SDT, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530354 900, 0, 2},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530355 { RC_L_SDT, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530356 1900, 1, 4},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530357 { RC_L_SDT, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530358 4900, 2, 11},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530359 { RC_L_SDT, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530360 8100, 3, 22},
Senthil Balasubramanianf63b3402010-07-27 19:16:31 +0530361 { RC_INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530362 5400, 4, 12},
Senthil Balasubramanianf63b3402010-07-27 19:16:31 +0530363 { RC_INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530364 7800, 5, 18},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530365 { RC_L_SDT, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530366 10000, 6, 24},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530367 { RC_L_SDT, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530368 13900, 7, 36},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530369 { RC_L_SDT, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530370 17300, 8, 48},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530371 { RC_L_SDT, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530372 23000, 9, 72},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530373 { RC_L_SDT, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530374 27400, 10, 96},
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530375 { RC_L_SDT, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
Sujith Manoharan23d99392012-08-10 16:47:23 +0530376 29300, 11, 108},
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700377 },
378 50, /* probe interval */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700379 0, /* Phy rates allowed initially */
380};
381
Sujith Manoharan23d99392012-08-10 16:47:23 +0530382static int ath_rc_get_rateindex(struct ath_rate_priv *ath_rc_priv,
Mohammed Shafi Shajakhan9dff3872011-07-11 20:14:14 +0530383 struct ieee80211_tx_rate *rate)
384{
Sujith Manoharan23d99392012-08-10 16:47:23 +0530385 const struct ath_rate_table *rate_table = ath_rc_priv->rate_table;
386 int rix, i, idx = 0;
Mohammed Shafi Shajakhan9dff3872011-07-11 20:14:14 +0530387
388 if (!(rate->flags & IEEE80211_TX_RC_MCS))
389 return rate->idx;
390
Sujith Manoharan23d99392012-08-10 16:47:23 +0530391 for (i = 0; i < ath_rc_priv->max_valid_rate; i++) {
392 idx = ath_rc_priv->valid_rate_index[i];
393
394 if (WLAN_RC_PHY_HT(rate_table->info[idx].phy) &&
395 rate_table->info[idx].ratecode == rate->idx)
396 break;
Mohammed Shafi Shajakhan9dff3872011-07-11 20:14:14 +0530397 }
398
Sujith Manoharan23d99392012-08-10 16:47:23 +0530399 rix = idx;
Mohammed Shafi Shajakhan9dff3872011-07-11 20:14:14 +0530400
Sujith Manoharan23d99392012-08-10 16:47:23 +0530401 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
402 rix++;
Mohammed Shafi Shajakhan9dff3872011-07-11 20:14:14 +0530403
404 return rix;
405}
Felix Fietkau545750d2009-11-23 22:21:01 +0100406
Sujith Manoharanea2771f2012-08-10 16:46:04 +0530407static void ath_rc_sort_validrates(struct ath_rate_priv *ath_rc_priv)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700408{
Sujith Manoharanea2771f2012-08-10 16:46:04 +0530409 const struct ath_rate_table *rate_table = ath_rc_priv->rate_table;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700410 u8 i, j, idx, idx_next;
411
Sujith256b7752008-11-18 09:03:12 +0530412 for (i = ath_rc_priv->max_valid_rate - 1; i > 0; i--) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700413 for (j = 0; j <= i-1; j++) {
Sujith256b7752008-11-18 09:03:12 +0530414 idx = ath_rc_priv->valid_rate_index[j];
415 idx_next = ath_rc_priv->valid_rate_index[j+1];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700416
417 if (rate_table->info[idx].ratekbps >
418 rate_table->info[idx_next].ratekbps) {
Sujith256b7752008-11-18 09:03:12 +0530419 ath_rc_priv->valid_rate_index[j] = idx_next;
420 ath_rc_priv->valid_rate_index[j+1] = idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700421 }
422 }
423 }
424}
425
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400426static inline
427int ath_rc_get_nextvalid_txrate(const struct ath_rate_table *rate_table,
428 struct ath_rate_priv *ath_rc_priv,
429 u8 cur_valid_txrate,
430 u8 *next_idx)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700431{
432 u8 i;
433
Sujith256b7752008-11-18 09:03:12 +0530434 for (i = 0; i < ath_rc_priv->max_valid_rate - 1; i++) {
435 if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
436 *next_idx = ath_rc_priv->valid_rate_index[i+1];
Sujith46d14a52008-11-18 09:08:13 +0530437 return 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438 }
439 }
440
441 /* No more valid rates */
442 *next_idx = 0;
Sujith2c5a7442008-11-18 09:08:33 +0530443
Sujith46d14a52008-11-18 09:08:13 +0530444 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700445}
446
447/* Return true only for single stream */
448
449static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw)
450{
Jouni Malinenb657ead2009-01-13 14:33:49 +0200451 if (WLAN_RC_PHY_HT(phy) && !(capflag & WLAN_RC_HT_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530452 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700453 if (WLAN_RC_PHY_DS(phy) && !(capflag & WLAN_RC_DS_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530454 return 0;
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530455 if (WLAN_RC_PHY_TS(phy) && !(capflag & WLAN_RC_TS_FLAG))
456 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700457 if (WLAN_RC_PHY_SGI(phy) && !(capflag & WLAN_RC_SGI_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530458 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700459 if (!ignore_cw && WLAN_RC_PHY_HT(phy))
460 if (WLAN_RC_PHY_40(phy) && !(capflag & WLAN_RC_40_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530461 return 0;
Sujith46d14a52008-11-18 09:08:13 +0530462 return 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700463}
464
465static inline int
Sujith Manoharanfc8d0232012-08-10 16:46:24 +0530466ath_rc_get_lower_rix(struct ath_rate_priv *ath_rc_priv,
Luis R. Rodriguez39448b02009-07-14 20:14:00 -0400467 u8 cur_valid_txrate, u8 *next_idx)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700468{
469 int8_t i;
470
Sujith256b7752008-11-18 09:03:12 +0530471 for (i = 1; i < ath_rc_priv->max_valid_rate ; i++) {
472 if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
473 *next_idx = ath_rc_priv->valid_rate_index[i-1];
Sujith46d14a52008-11-18 09:08:13 +0530474 return 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700475 }
476 }
Sujith2c5a7442008-11-18 09:08:33 +0530477
Sujith46d14a52008-11-18 09:08:13 +0530478 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700479}
480
Sujith Manoharanea2771f2012-08-10 16:46:04 +0530481static u8 ath_rc_init_validrates(struct ath_rate_priv *ath_rc_priv)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700482{
Sujith Manoharanea2771f2012-08-10 16:46:04 +0530483 const struct ath_rate_table *rate_table = ath_rc_priv->rate_table;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700484 u8 i, hi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700486 for (i = 0; i < rate_table->rate_cnt; i++) {
Senthil Balasubramanianf63b3402010-07-27 19:16:31 +0530487 if (rate_table->info[i].rate_flags & RC_LEGACY) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700488 u32 phy = rate_table->info[i].phy;
489 u8 valid_rate_count = 0;
490
Sujith Manoharanea2771f2012-08-10 16:46:04 +0530491 if (!ath_rc_valid_phyrate(phy, ath_rc_priv->ht_cap, 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700492 continue;
493
Sujith256b7752008-11-18 09:03:12 +0530494 valid_rate_count = ath_rc_priv->valid_phy_ratecnt[phy];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700495
Sujith256b7752008-11-18 09:03:12 +0530496 ath_rc_priv->valid_phy_rateidx[phy][valid_rate_count] = i;
497 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
Sujith Manoharanf5c9a802012-08-10 16:46:37 +0530498 ath_rc_priv->valid_rate_index[i] = true;
Senthil Balasubramanianf63b3402010-07-27 19:16:31 +0530499 hi = i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700500 }
501 }
Sujith2c5a7442008-11-18 09:08:33 +0530502
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700503 return hi;
504}
505
Sujith Manoharan3d2776f2012-08-10 16:46:44 +0530506static inline bool ath_rc_check_legacy(u8 rate, u8 dot11rate, u16 rate_flags,
507 u32 phy, u32 capflag)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700508{
Sujith Manoharan3d2776f2012-08-10 16:46:44 +0530509 if (rate != dot11rate || WLAN_RC_PHY_HT(phy))
510 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700511
Sujith Manoharan3d2776f2012-08-10 16:46:44 +0530512 if ((rate_flags & WLAN_RC_CAP_MODE(capflag)) != WLAN_RC_CAP_MODE(capflag))
513 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700514
Sujith Manoharan3d2776f2012-08-10 16:46:44 +0530515 if (!(rate_flags & WLAN_RC_CAP_STREAM(capflag)))
516 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700517
Sujith Manoharan3d2776f2012-08-10 16:46:44 +0530518 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700519}
520
Sujith Manoharan3d2776f2012-08-10 16:46:44 +0530521static inline bool ath_rc_check_ht(u8 rate, u8 dot11rate, u16 rate_flags,
522 u32 phy, u32 capflag)
523{
524 if (rate != dot11rate || !WLAN_RC_PHY_HT(phy))
525 return false;
526
527 if (!WLAN_RC_PHY_HT_VALID(rate_flags, capflag))
528 return false;
529
530 if (!(rate_flags & WLAN_RC_CAP_STREAM(capflag)))
531 return false;
532
533 return true;
534}
535
536static u8 ath_rc_setvalid_rates(struct ath_rate_priv *ath_rc_priv, bool legacy)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700537{
Sujith Manoharanea2771f2012-08-10 16:46:04 +0530538 const struct ath_rate_table *rate_table = ath_rc_priv->rate_table;
Sujith Manoharan3d2776f2012-08-10 16:46:44 +0530539 struct ath_rateset *rateset;
Sujith Manoharandacde352012-08-10 16:46:18 +0530540 u32 phy, capflag = ath_rc_priv->ht_cap;
541 u16 rate_flags;
542 u8 i, j, hi = 0, rate, dot11rate, valid_rate_count;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700543
Sujith Manoharan3d2776f2012-08-10 16:46:44 +0530544 if (legacy)
545 rateset = &ath_rc_priv->neg_rates;
546 else
547 rateset = &ath_rc_priv->neg_ht_rates;
548
Sujith2c5a7442008-11-18 09:08:33 +0530549 for (i = 0; i < rateset->rs_nrates; i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700550 for (j = 0; j < rate_table->rate_cnt; j++) {
Sujith Manoharandacde352012-08-10 16:46:18 +0530551 phy = rate_table->info[j].phy;
552 rate_flags = rate_table->info[j].rate_flags;
553 rate = rateset->rs_rates[i];
554 dot11rate = rate_table->info[j].dot11rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700555
Sujith Manoharan3d2776f2012-08-10 16:46:44 +0530556 if (legacy &&
557 !ath_rc_check_legacy(rate, dot11rate,
558 rate_flags, phy, capflag))
559 continue;
560
561 if (!legacy &&
562 !ath_rc_check_ht(rate, dot11rate,
563 rate_flags, phy, capflag))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700564 continue;
565
Sujith46d14a52008-11-18 09:08:13 +0530566 if (!ath_rc_valid_phyrate(phy, capflag, 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700567 continue;
568
Sujith Manoharandacde352012-08-10 16:46:18 +0530569 valid_rate_count = ath_rc_priv->valid_phy_ratecnt[phy];
570 ath_rc_priv->valid_phy_rateidx[phy][valid_rate_count] = j;
Sujith256b7752008-11-18 09:03:12 +0530571 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
Sujith Manoharanf5c9a802012-08-10 16:46:37 +0530572 ath_rc_priv->valid_rate_index[j] = true;
Pavel Roskinf6351d42011-06-15 18:01:05 -0400573 hi = max(hi, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700574 }
575 }
Sujith2c5a7442008-11-18 09:08:33 +0530576
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700577 return hi;
578}
579
Sujith Manoharanfc8d0232012-08-10 16:46:24 +0530580static u8 ath_rc_get_highest_rix(struct ath_rate_priv *ath_rc_priv,
Sujith Manoharan6e1e3742012-08-10 16:46:31 +0530581 int *is_probing)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700582{
Sujith Manoharanfc8d0232012-08-10 16:46:24 +0530583 const struct ath_rate_table *rate_table = ath_rc_priv->rate_table;
Vasanthakumar Thiagarajan39a4caf2009-07-14 20:14:10 -0400584 u32 best_thruput, this_thruput, now_msec;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700585 u8 rate, next_rate, best_rate, maxindex, minindex;
Vasanthakumar Thiagarajan39a4caf2009-07-14 20:14:10 -0400586 int8_t index = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700587
588 now_msec = jiffies_to_msecs(jiffies);
Vasanthakumar Thiagarajan39a4caf2009-07-14 20:14:10 -0400589 *is_probing = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700590 best_thruput = 0;
Sujith256b7752008-11-18 09:03:12 +0530591 maxindex = ath_rc_priv->max_valid_rate-1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700592 minindex = 0;
593 best_rate = minindex;
594
595 /*
596 * Try the higher rate first. It will reduce memory moving time
597 * if we have very good channel characteristics.
598 */
599 for (index = maxindex; index >= minindex ; index--) {
600 u8 per_thres;
601
Sujith256b7752008-11-18 09:03:12 +0530602 rate = ath_rc_priv->valid_rate_index[index];
603 if (rate > ath_rc_priv->rate_max_phy)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700604 continue;
605
606 /*
607 * For TCP the average collision rate is around 11%,
608 * so we ignore PERs less than this. This is to
609 * prevent the rate we are currently using (whose
610 * PER might be in the 10-15 range because of TCP
611 * collisions) looking worse than the next lower
612 * rate whose PER has decayed close to 0. If we
613 * used to next lower rate, its PER would grow to
614 * 10-15 and we would be worse off then staying
615 * at the current rate.
616 */
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400617 per_thres = ath_rc_priv->per[rate];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700618 if (per_thres < 12)
619 per_thres = 12;
620
621 this_thruput = rate_table->info[rate].user_ratekbps *
622 (100 - per_thres);
623
624 if (best_thruput <= this_thruput) {
625 best_thruput = this_thruput;
626 best_rate = rate;
627 }
628 }
629
630 rate = best_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700631
632 /*
633 * Must check the actual rate (ratekbps) to account for
634 * non-monoticity of 11g's rate table
635 */
636
Sujith39008982009-01-30 14:29:15 +0530637 if (rate >= ath_rc_priv->rate_max_phy) {
Sujith256b7752008-11-18 09:03:12 +0530638 rate = ath_rc_priv->rate_max_phy;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700639
640 /* Probe the next allowed phy state */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700641 if (ath_rc_get_nextvalid_txrate(rate_table,
Sujith39008982009-01-30 14:29:15 +0530642 ath_rc_priv, rate, &next_rate) &&
Sujith256b7752008-11-18 09:03:12 +0530643 (now_msec - ath_rc_priv->probe_time >
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700644 rate_table->probe_interval) &&
Sujith256b7752008-11-18 09:03:12 +0530645 (ath_rc_priv->hw_maxretry_pktcnt >= 1)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700646 rate = next_rate;
Sujith256b7752008-11-18 09:03:12 +0530647 ath_rc_priv->probe_rate = rate;
648 ath_rc_priv->probe_time = now_msec;
649 ath_rc_priv->hw_maxretry_pktcnt = 0;
Sujith46d14a52008-11-18 09:08:13 +0530650 *is_probing = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700651 }
652 }
653
Sujith256b7752008-11-18 09:03:12 +0530654 if (rate > (ath_rc_priv->rate_table_size - 1))
655 rate = ath_rc_priv->rate_table_size - 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700656
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +0530657 if (RC_TS_ONLY(rate_table->info[rate].rate_flags) &&
658 (ath_rc_priv->ht_cap & WLAN_RC_TS_FLAG))
659 return rate;
660
661 if (RC_DS_OR_LATER(rate_table->info[rate].rate_flags) &&
662 (ath_rc_priv->ht_cap & (WLAN_RC_DS_FLAG | WLAN_RC_TS_FLAG)))
Luis R. Rodrigueze43419f2009-07-14 20:13:54 -0400663 return rate;
664
Senthil Balasubramanianf63b3402010-07-27 19:16:31 +0530665 if (RC_SS_OR_LEGACY(rate_table->info[rate].rate_flags))
Luis R. Rodrigueze43419f2009-07-14 20:13:54 -0400666 return rate;
667
668 /* This should not happen */
John W. Linville81494152012-01-30 10:55:13 -0500669 WARN_ON_ONCE(1);
Luis R. Rodrigueze43419f2009-07-14 20:13:54 -0400670
671 rate = ath_rc_priv->valid_rate_index[0];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700672
673 return rate;
674}
675
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400676static void ath_rc_rate_set_series(const struct ath_rate_table *rate_table,
Sujitha8efee42008-11-18 09:07:30 +0530677 struct ieee80211_tx_rate *rate,
Sujithc89424d2009-01-30 14:29:28 +0530678 struct ieee80211_tx_rate_control *txrc,
Sujith2c5a7442008-11-18 09:08:33 +0530679 u8 tries, u8 rix, int rtsctsenable)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700680{
Sujitha8efee42008-11-18 09:07:30 +0530681 rate->count = tries;
Felix Fietkau545750d2009-11-23 22:21:01 +0100682 rate->idx = rate_table->info[rix].ratecode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700683
Sujithc89424d2009-01-30 14:29:28 +0530684 if (txrc->rts || rtsctsenable)
Sujitha8efee42008-11-18 09:07:30 +0530685 rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100686
687 if (WLAN_RC_PHY_HT(rate_table->info[rix].phy)) {
Sujitha8efee42008-11-18 09:07:30 +0530688 rate->flags |= IEEE80211_TX_RC_MCS;
Rajkumar Manoharan41e2b052011-05-20 17:52:14 +0530689 if (WLAN_RC_PHY_40(rate_table->info[rix].phy) &&
690 conf_is_ht40(&txrc->hw->conf))
Felix Fietkau545750d2009-11-23 22:21:01 +0100691 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
692 if (WLAN_RC_PHY_SGI(rate_table->info[rix].phy))
693 rate->flags |= IEEE80211_TX_RC_SHORT_GI;
694 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700695}
696
Sujithc89424d2009-01-30 14:29:28 +0530697static void ath_rc_rate_set_rtscts(struct ath_softc *sc,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400698 const struct ath_rate_table *rate_table,
Sujithc89424d2009-01-30 14:29:28 +0530699 struct ieee80211_tx_info *tx_info)
700{
Sujith Manoharan2e546752012-08-10 16:46:57 +0530701 struct ieee80211_bss_conf *bss_conf;
Sujithc89424d2009-01-30 14:29:28 +0530702
Sujith Manoharan2e546752012-08-10 16:46:57 +0530703 if (!tx_info->control.vif)
704 return;
705 /*
706 * For legacy frames, mac80211 takes care of CTS protection.
707 */
708 if (!(tx_info->control.rates[0].flags & IEEE80211_TX_RC_MCS))
709 return;
Sujithc89424d2009-01-30 14:29:28 +0530710
Sujith Manoharan2e546752012-08-10 16:46:57 +0530711 bss_conf = &tx_info->control.vif->bss_conf;
712
713 if (!bss_conf->basic_rates)
714 return;
Sujithc89424d2009-01-30 14:29:28 +0530715
716 /*
Sujith Manoharan2e546752012-08-10 16:46:57 +0530717 * For now, use the lowest allowed basic rate for HT frames.
Sujithc89424d2009-01-30 14:29:28 +0530718 */
Sujith Manoharan2e546752012-08-10 16:46:57 +0530719 tx_info->control.rts_cts_rate_idx = __ffs(bss_conf->basic_rates);
Sujithc89424d2009-01-30 14:29:28 +0530720}
721
Luis R. Rodrigueze25739a2009-07-14 20:14:09 -0400722static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
723 struct ieee80211_tx_rate_control *txrc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700724{
Luis R. Rodrigueze25739a2009-07-14 20:14:09 -0400725 struct ath_softc *sc = priv;
726 struct ath_rate_priv *ath_rc_priv = priv_sta;
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400727 const struct ath_rate_table *rate_table;
Sujith39008982009-01-30 14:29:15 +0530728 struct sk_buff *skb = txrc->skb;
729 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Sujitha8efee42008-11-18 09:07:30 +0530730 struct ieee80211_tx_rate *rates = tx_info->control.rates;
Sujithc89424d2009-01-30 14:29:28 +0530731 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
732 __le16 fc = hdr->frame_control;
Rajkumar Manoharancec429dd2012-06-11 12:19:29 +0530733 u8 try_per_rate, i = 0, rix;
Sujith39008982009-01-30 14:29:15 +0530734 int is_probe = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735
Luis R. Rodrigueze25739a2009-07-14 20:14:09 -0400736 if (rate_control_send_low(sta, priv_sta, txrc))
737 return;
738
Luis R. Rodriguezdd190182009-07-14 20:13:56 -0400739 /*
740 * For Multi Rate Retry we use a different number of
741 * retry attempt counts. This ends up looking like this:
742 *
Felix Fietkau65896512010-01-24 03:26:11 +0100743 * MRR[0] = 4
744 * MRR[1] = 4
745 * MRR[2] = 4
746 * MRR[3] = 8
Luis R. Rodriguezdd190182009-07-14 20:13:56 -0400747 *
748 */
Felix Fietkau65896512010-01-24 03:26:11 +0100749 try_per_rate = 4;
Luis R. Rodriguezdd190182009-07-14 20:13:56 -0400750
Felix Fietkau4e990012010-10-13 16:43:27 +0200751 rate_table = ath_rc_priv->rate_table;
Sujith Manoharan6e1e3742012-08-10 16:46:31 +0530752 rix = ath_rc_get_highest_rix(ath_rc_priv, &is_probe);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753
Luis R. Rodriguezb0a33442010-04-15 17:39:39 -0400754 if (conf_is_ht(&sc->hw->conf) &&
755 (sta->ht_cap.cap & IEEE80211_HT_CAP_LDPC_CODING))
756 tx_info->flags |= IEEE80211_TX_CTL_LDPC;
757
Felix Fietkau58b51902010-04-19 19:57:37 +0200758 if (conf_is_ht(&sc->hw->conf) &&
759 (sta->ht_cap.cap & IEEE80211_HT_CAP_TX_STBC))
760 tx_info->flags |= (1 << IEEE80211_TX_CTL_STBC_SHIFT);
761
Sujith39008982009-01-30 14:29:15 +0530762 if (is_probe) {
Sujith Manoharanfc8d0232012-08-10 16:46:24 +0530763 /*
764 * Set one try for probe rates. For the
765 * probes don't enable RTS.
766 */
Sujithc89424d2009-01-30 14:29:28 +0530767 ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
Felix Fietkau5c0ba622010-02-19 01:46:36 +0100768 1, rix, 0);
Sujith Manoharanfc8d0232012-08-10 16:46:24 +0530769 /*
770 * Get the next tried/allowed rate.
771 * No RTS for the next series after the probe rate.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 */
Sujith Manoharanfc8d0232012-08-10 16:46:24 +0530773 ath_rc_get_lower_rix(ath_rc_priv, rix, &rix);
Sujithc89424d2009-01-30 14:29:28 +0530774 ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
Felix Fietkau5c0ba622010-02-19 01:46:36 +0100775 try_per_rate, rix, 0);
Vasanthakumar Thiagarajan14587ce2009-03-12 15:32:54 +0530776
777 tx_info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778 } else {
Sujith Manoharanfc8d0232012-08-10 16:46:24 +0530779 /*
780 * Set the chosen rate. No RTS for first series entry.
781 */
Sujithc89424d2009-01-30 14:29:28 +0530782 ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
Felix Fietkau5c0ba622010-02-19 01:46:36 +0100783 try_per_rate, rix, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700784 }
785
Sujith Manoharan6e1e3742012-08-10 16:46:31 +0530786 for ( ; i < 4; i++) {
787 /*
788 * Use twice the number of tries for the last MRR segment.
789 */
790 if (i + 1 == 4)
791 try_per_rate = 8;
792
Sujith Manoharanfc8d0232012-08-10 16:46:24 +0530793 ath_rc_get_lower_rix(ath_rc_priv, rix, &rix);
Luis R. Rodriguezdd190182009-07-14 20:13:56 -0400794
Sujith Manoharanfc8d0232012-08-10 16:46:24 +0530795 /*
796 * All other rates in the series have RTS enabled.
797 */
Sujithc89424d2009-01-30 14:29:28 +0530798 ath_rc_rate_set_series(rate_table, &rates[i], txrc,
Felix Fietkau5c0ba622010-02-19 01:46:36 +0100799 try_per_rate, rix, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 }
801
Sujith Manoharanfc8d0232012-08-10 16:46:24 +0530802 /*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700803 * NB:Change rate series to enable aggregation when operating
804 * at lower MCS rates. When first rate in series is MCS2
805 * in HT40 @ 2.4GHz, series should look like:
806 *
807 * {MCS2, MCS1, MCS0, MCS0}.
808 *
809 * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
810 * look like:
811 *
812 * {MCS3, MCS2, MCS1, MCS1}
813 *
814 * So, set fourth rate in series to be same as third one for
815 * above conditions.
816 */
Karl Beldan675a0b02013-03-25 16:26:57 +0100817 if ((sc->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) &&
Luis R. Rodriguezecf70442008-12-23 15:58:43 -0800818 (conf_is_ht(&sc->hw->conf))) {
Sujith40990ec2008-12-07 21:41:37 +0530819 u8 dot11rate = rate_table->info[rix].dot11rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700820 u8 phy = rate_table->info[rix].phy;
821 if (i == 4 &&
822 ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) ||
Sujithdc2222a2008-08-14 13:26:55 +0530823 (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) {
Sujitha8efee42008-11-18 09:07:30 +0530824 rates[3].idx = rates[2].idx;
825 rates[3].flags = rates[2].flags;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700826 }
827 }
Sujithc89424d2009-01-30 14:29:28 +0530828
829 /*
830 * Force hardware to use computed duration for next
831 * fragment by disabling multi-rate retry, which
832 * updates duration based on the multi-rate duration table.
833 *
834 * FIXME: Fix duration
835 */
Luis R. Rodriguez7682a762009-07-14 20:14:05 -0400836 if (ieee80211_has_morefrags(fc) ||
837 (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) {
Sujithc89424d2009-01-30 14:29:28 +0530838 rates[1].count = rates[2].count = rates[3].count = 0;
839 rates[1].idx = rates[2].idx = rates[3].idx = 0;
840 rates[0].count = ATH_TXMAXTRY;
841 }
842
Sujithc89424d2009-01-30 14:29:28 +0530843 ath_rc_rate_set_rtscts(sc, rate_table, tx_info);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700844}
845
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +0530846static void ath_rc_update_per(struct ath_softc *sc,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400847 const struct ath_rate_table *rate_table,
Sujith2c5a7442008-11-18 09:08:33 +0530848 struct ath_rate_priv *ath_rc_priv,
Felix Fietkau827e69b2009-11-15 23:09:25 +0100849 struct ieee80211_tx_info *tx_info,
Sujith2c5a7442008-11-18 09:08:33 +0530850 int tx_rate, int xretries, int retries,
851 u32 now_msec)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700852{
Felix Fietkau827e69b2009-11-15 23:09:25 +0100853 int count, n_bad_frames;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700854 u8 last_per;
Joe Perches07b2fa52010-11-20 18:38:53 -0800855 static const u32 nretry_to_per_lookup[10] = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700856 100 * 0 / 1,
857 100 * 1 / 4,
858 100 * 1 / 2,
859 100 * 3 / 4,
860 100 * 4 / 5,
861 100 * 5 / 6,
862 100 * 6 / 7,
863 100 * 7 / 8,
864 100 * 8 / 9,
865 100 * 9 / 10
866 };
867
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400868 last_per = ath_rc_priv->per[tx_rate];
Felix Fietkau827e69b2009-11-15 23:09:25 +0100869 n_bad_frames = tx_info->status.ampdu_len - tx_info->status.ampdu_ack_len;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700870
871 if (xretries) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700872 if (xretries == 1) {
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400873 ath_rc_priv->per[tx_rate] += 30;
874 if (ath_rc_priv->per[tx_rate] > 100)
875 ath_rc_priv->per[tx_rate] = 100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700876 } else {
877 /* xretries == 2 */
Julia Lawall87c16872008-11-09 17:56:10 +0100878 count = ARRAY_SIZE(nretry_to_per_lookup);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700879 if (retries >= count)
880 retries = count - 1;
Sujith2c5a7442008-11-18 09:08:33 +0530881
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700882 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400883 ath_rc_priv->per[tx_rate] =
Sujith2c5a7442008-11-18 09:08:33 +0530884 (u8)(last_per - (last_per >> 3) + (100 >> 3));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700885 }
886
887 /* xretries == 1 or 2 */
888
Sujith256b7752008-11-18 09:03:12 +0530889 if (ath_rc_priv->probe_rate == tx_rate)
890 ath_rc_priv->probe_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700891
Sujith2c5a7442008-11-18 09:08:33 +0530892 } else { /* xretries == 0 */
Julia Lawall87c16872008-11-09 17:56:10 +0100893 count = ARRAY_SIZE(nretry_to_per_lookup);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700894 if (retries >= count)
895 retries = count - 1;
Sujith2c5a7442008-11-18 09:08:33 +0530896
Felix Fietkau827e69b2009-11-15 23:09:25 +0100897 if (n_bad_frames) {
Sujithdc2222a2008-08-14 13:26:55 +0530898 /* new_PER = 7/8*old_PER + 1/8*(currentPER)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700899 * Assuming that n_frames is not 0. The current PER
900 * from the retries is 100 * retries / (retries+1),
901 * since the first retries attempts failed, and the
902 * next one worked. For the one that worked,
903 * n_bad_frames subframes out of n_frames wored,
904 * so the PER for that part is
905 * 100 * n_bad_frames / n_frames, and it contributes
906 * 100 * n_bad_frames / (n_frames * (retries+1)) to
907 * the above PER. The expression below is a
908 * simplified version of the sum of these two terms.
909 */
Felix Fietkau827e69b2009-11-15 23:09:25 +0100910 if (tx_info->status.ampdu_len > 0) {
911 int n_frames, n_bad_tries;
Sujith2c5a7442008-11-18 09:08:33 +0530912 u8 cur_per, new_per;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700913
Felix Fietkau827e69b2009-11-15 23:09:25 +0100914 n_bad_tries = retries * tx_info->status.ampdu_len +
915 n_bad_frames;
916 n_frames = tx_info->status.ampdu_len * (retries + 1);
917 cur_per = (100 * n_bad_tries / n_frames) >> 3;
Sujith2c5a7442008-11-18 09:08:33 +0530918 new_per = (u8)(last_per - (last_per >> 3) + cur_per);
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400919 ath_rc_priv->per[tx_rate] = new_per;
Sujith2c5a7442008-11-18 09:08:33 +0530920 }
921 } else {
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400922 ath_rc_priv->per[tx_rate] =
Sujith2c5a7442008-11-18 09:08:33 +0530923 (u8)(last_per - (last_per >> 3) +
924 (nretry_to_per_lookup[retries] >> 3));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700925 }
926
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700927
928 /*
929 * If we got at most one retry then increase the max rate if
930 * this was a probe. Otherwise, ignore the probe.
931 */
Sujith256b7752008-11-18 09:03:12 +0530932 if (ath_rc_priv->probe_rate && ath_rc_priv->probe_rate == tx_rate) {
Felix Fietkau827e69b2009-11-15 23:09:25 +0100933 if (retries > 0 || 2 * n_bad_frames > tx_info->status.ampdu_len) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700934 /*
935 * Since we probed with just a single attempt,
936 * any retries means the probe failed. Also,
937 * if the attempt worked, but more than half
938 * the subframes were bad then also consider
939 * the probe a failure.
940 */
Sujith256b7752008-11-18 09:03:12 +0530941 ath_rc_priv->probe_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700942 } else {
943 u8 probe_rate = 0;
944
Sujith2c5a7442008-11-18 09:08:33 +0530945 ath_rc_priv->rate_max_phy =
946 ath_rc_priv->probe_rate;
Sujith256b7752008-11-18 09:03:12 +0530947 probe_rate = ath_rc_priv->probe_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700948
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400949 if (ath_rc_priv->per[probe_rate] > 30)
950 ath_rc_priv->per[probe_rate] = 20;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700951
Sujith256b7752008-11-18 09:03:12 +0530952 ath_rc_priv->probe_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700953
954 /*
955 * Since this probe succeeded, we allow the next
956 * probe twice as soon. This allows the maxRate
957 * to move up faster if the probes are
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200958 * successful.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700959 */
Sujith2c5a7442008-11-18 09:08:33 +0530960 ath_rc_priv->probe_time =
961 now_msec - rate_table->probe_interval / 2;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700962 }
963 }
964
965 if (retries > 0) {
966 /*
967 * Don't update anything. We don't know if
968 * this was because of collisions or poor signal.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700969 */
Sujith256b7752008-11-18 09:03:12 +0530970 ath_rc_priv->hw_maxretry_pktcnt = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700971 } else {
972 /*
973 * It worked with no retries. First ignore bogus (small)
974 * rssi_ack values.
975 */
Sujith256b7752008-11-18 09:03:12 +0530976 if (tx_rate == ath_rc_priv->rate_max_phy &&
977 ath_rc_priv->hw_maxretry_pktcnt < 255) {
978 ath_rc_priv->hw_maxretry_pktcnt++;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700979 }
980
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700981 }
982 }
Sujith2c5a7442008-11-18 09:08:33 +0530983}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700984
Sujith2c5a7442008-11-18 09:08:33 +0530985static void ath_rc_update_ht(struct ath_softc *sc,
986 struct ath_rate_priv *ath_rc_priv,
Felix Fietkau827e69b2009-11-15 23:09:25 +0100987 struct ieee80211_tx_info *tx_info,
Sujith2c5a7442008-11-18 09:08:33 +0530988 int tx_rate, int xretries, int retries)
989{
Sujith2c5a7442008-11-18 09:08:33 +0530990 u32 now_msec = jiffies_to_msecs(jiffies);
991 int rate;
992 u8 last_per;
Felix Fietkau4e990012010-10-13 16:43:27 +0200993 const struct ath_rate_table *rate_table = ath_rc_priv->rate_table;
Sujith2c5a7442008-11-18 09:08:33 +0530994 int size = ath_rc_priv->rate_table_size;
995
996 if ((tx_rate < 0) || (tx_rate > rate_table->rate_cnt))
997 return;
998
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400999 last_per = ath_rc_priv->per[tx_rate];
Sujith2c5a7442008-11-18 09:08:33 +05301000
1001 /* Update PER first */
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +05301002 ath_rc_update_per(sc, rate_table, ath_rc_priv,
1003 tx_info, tx_rate, xretries,
1004 retries, now_msec);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001005
1006 /*
1007 * If this rate looks bad (high PER) then stop using it for
1008 * a while (except if we are probing).
1009 */
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001010 if (ath_rc_priv->per[tx_rate] >= 55 && tx_rate > 0 &&
Sujithdc2222a2008-08-14 13:26:55 +05301011 rate_table->info[tx_rate].ratekbps <=
Sujith256b7752008-11-18 09:03:12 +05301012 rate_table->info[ath_rc_priv->rate_max_phy].ratekbps) {
Sujith Manoharanfc8d0232012-08-10 16:46:24 +05301013 ath_rc_get_lower_rix(ath_rc_priv, (u8)tx_rate,
1014 &ath_rc_priv->rate_max_phy);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001015
1016 /* Don't probe for a little while. */
Sujith256b7752008-11-18 09:03:12 +05301017 ath_rc_priv->probe_time = now_msec;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001018 }
1019
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001020 /* Make sure the rates below this have lower PER */
1021 /* Monotonicity is kept only for rates below the current rate. */
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001022 if (ath_rc_priv->per[tx_rate] < last_per) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001023 for (rate = tx_rate - 1; rate >= 0; rate--) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001024
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001025 if (ath_rc_priv->per[rate] >
1026 ath_rc_priv->per[rate+1]) {
1027 ath_rc_priv->per[rate] =
1028 ath_rc_priv->per[rate+1];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001029 }
1030 }
1031 }
1032
1033 /* Maintain monotonicity for rates above the current rate */
Sujith2c5a7442008-11-18 09:08:33 +05301034 for (rate = tx_rate; rate < size - 1; rate++) {
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001035 if (ath_rc_priv->per[rate+1] <
1036 ath_rc_priv->per[rate])
1037 ath_rc_priv->per[rate+1] =
1038 ath_rc_priv->per[rate];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001039 }
1040
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001041 /* Every so often, we reduce the thresholds
1042 * and PER (different for CCK and OFDM). */
Sujith256b7752008-11-18 09:03:12 +05301043 if (now_msec - ath_rc_priv->per_down_time >=
Vasanthakumar Thiagarajanc4130462009-07-14 20:14:12 -04001044 rate_table->probe_interval) {
Sujith2c5a7442008-11-18 09:08:33 +05301045 for (rate = 0; rate < size; rate++) {
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001046 ath_rc_priv->per[rate] =
1047 7 * ath_rc_priv->per[rate] / 8;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001048 }
1049
Sujith256b7752008-11-18 09:03:12 +05301050 ath_rc_priv->per_down_time = now_msec;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001051 }
Sujith2c5a7442008-11-18 09:08:33 +05301052
Felix Fietkau772d5512010-10-13 16:43:26 +02001053 ath_debug_stat_retries(ath_rc_priv, tx_rate, xretries, retries,
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001054 ath_rc_priv->per[tx_rate]);
Sujith029bc432009-02-04 08:10:26 +05301055
Sujith2c5a7442008-11-18 09:08:33 +05301056}
1057
Sujith46d14a52008-11-18 09:08:13 +05301058static void ath_rc_tx_status(struct ath_softc *sc,
1059 struct ath_rate_priv *ath_rc_priv,
Sujith Manoharan88dcc2d2012-08-10 16:47:09 +05301060 struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001061{
Sujith Manoharan88dcc2d2012-08-10 16:47:09 +05301062 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Sujitha8efee42008-11-18 09:07:30 +05301063 struct ieee80211_tx_rate *rates = tx_info->status.rates;
Sujith Manoharan88dcc2d2012-08-10 16:47:09 +05301064 struct ieee80211_tx_rate *rate;
1065 int final_ts_idx = 0, xretries = 0, long_retry = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001066 u8 flags;
Sujith2c5a7442008-11-18 09:08:33 +05301067 u32 i = 0, rix;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001068
Sujith Manoharan88dcc2d2012-08-10 16:47:09 +05301069 for (i = 0; i < sc->hw->max_rates; i++) {
1070 rate = &tx_info->status.rates[i];
1071 if (rate->idx < 0 || !rate->count)
1072 break;
1073
1074 final_ts_idx = i;
1075 long_retry = rate->count - 1;
1076 }
1077
1078 if (!(tx_info->flags & IEEE80211_TX_STAT_ACK))
1079 xretries = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001080
1081 /*
1082 * If the first rate is not the final index, there
1083 * are intermediate rate failures to be processed.
1084 */
1085 if (final_ts_idx != 0) {
Sujith2c5a7442008-11-18 09:08:33 +05301086 for (i = 0; i < final_ts_idx ; i++) {
1087 if (rates[i].count != 0 && (rates[i].idx >= 0)) {
1088 flags = rates[i].flags;
1089
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001090 /* If HT40 and we have switched mode from
1091 * 40 to 20 => don't update */
Sujith2c5a7442008-11-18 09:08:33 +05301092
Sujitha8efee42008-11-18 09:07:30 +05301093 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
Sujithf5c38ef2009-03-30 15:28:57 +05301094 !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001095 return;
Sujithe63835b2008-11-18 09:07:53 +05301096
Sujith Manoharan23d99392012-08-10 16:47:23 +05301097 rix = ath_rc_get_rateindex(ath_rc_priv, &rates[i]);
Felix Fietkau827e69b2009-11-15 23:09:25 +01001098 ath_rc_update_ht(sc, ath_rc_priv, tx_info,
Sujith Manoharan88dcc2d2012-08-10 16:47:09 +05301099 rix, xretries ? 1 : 2,
1100 rates[i].count);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001101 }
1102 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001103 }
1104
Sujith Manoharan88dcc2d2012-08-10 16:47:09 +05301105 flags = rates[final_ts_idx].flags;
Sujith2c5a7442008-11-18 09:08:33 +05301106
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001107 /* If HT40 and we have switched mode from 40 to 20 => don't update */
Sujitha8efee42008-11-18 09:07:30 +05301108 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
Sujithf5c38ef2009-03-30 15:28:57 +05301109 !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001110 return;
1111
Sujith Manoharan23d99392012-08-10 16:47:23 +05301112 rix = ath_rc_get_rateindex(ath_rc_priv, &rates[final_ts_idx]);
Felix Fietkau827e69b2009-11-15 23:09:25 +01001113 ath_rc_update_ht(sc, ath_rc_priv, tx_info, rix, xretries, long_retry);
Sujith Manoharan88dcc2d2012-08-10 16:47:09 +05301114 ath_debug_stat_rc(ath_rc_priv, rix);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001115}
1116
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -04001117static const
1118struct ath_rate_table *ath_choose_rate_table(struct ath_softc *sc,
1119 enum ieee80211_band band,
Felix Fietkaud4659912010-10-14 16:02:39 +02001120 bool is_ht)
Sujithe11602b2008-11-27 09:46:27 +05301121{
Sujithe11602b2008-11-27 09:46:27 +05301122 switch(band) {
1123 case IEEE80211_BAND_2GHZ:
Sujithe11602b2008-11-27 09:46:27 +05301124 if (is_ht)
Felix Fietkaud4659912010-10-14 16:02:39 +02001125 return &ar5416_11ng_ratetable;
1126 return &ar5416_11g_ratetable;
Sujithe11602b2008-11-27 09:46:27 +05301127 case IEEE80211_BAND_5GHZ:
Sujithe11602b2008-11-27 09:46:27 +05301128 if (is_ht)
Felix Fietkaud4659912010-10-14 16:02:39 +02001129 return &ar5416_11na_ratetable;
1130 return &ar5416_11a_ratetable;
Sujithe11602b2008-11-27 09:46:27 +05301131 default:
Sujithe11602b2008-11-27 09:46:27 +05301132 return NULL;
1133 }
Sujithe11602b2008-11-27 09:46:27 +05301134}
1135
Sujith5ddfac32008-11-18 09:06:44 +05301136static void ath_rc_init(struct ath_softc *sc,
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301137 struct ath_rate_priv *ath_rc_priv)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001138{
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301139 const struct ath_rate_table *rate_table = ath_rc_priv->rate_table;
Sujith5ddfac32008-11-18 09:06:44 +05301140 struct ath_rateset *rateset = &ath_rc_priv->neg_rates;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001141 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001142 u8 i, j, k, hi = 0, hthi = 0;
Sujithe11602b2008-11-27 09:46:27 +05301143
Sujith46d14a52008-11-18 09:08:13 +05301144 ath_rc_priv->rate_table_size = RATE_TABLE_SIZE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001145
Sujith5ddfac32008-11-18 09:06:44 +05301146 for (i = 0 ; i < ath_rc_priv->rate_table_size; i++) {
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001147 ath_rc_priv->per[i] = 0;
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301148 ath_rc_priv->valid_rate_index[i] = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001149 }
1150
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001151 for (i = 0; i < WLAN_RC_PHY_MAX; i++) {
Mohammed Shafi Shajakhand53c74e2012-02-28 20:54:43 +05301152 for (j = 0; j < RATE_TABLE_SIZE; j++)
Sujith256b7752008-11-18 09:03:12 +05301153 ath_rc_priv->valid_phy_rateidx[i][j] = 0;
1154 ath_rc_priv->valid_phy_ratecnt[i] = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001155 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001156
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001157 if (!rateset->rs_nrates) {
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301158 hi = ath_rc_init_validrates(ath_rc_priv);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001159 } else {
Sujith Manoharan3d2776f2012-08-10 16:46:44 +05301160 hi = ath_rc_setvalid_rates(ath_rc_priv, true);
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301161
1162 if (ath_rc_priv->ht_cap & WLAN_RC_HT_FLAG)
Sujith Manoharan3d2776f2012-08-10 16:46:44 +05301163 hthi = ath_rc_setvalid_rates(ath_rc_priv, false);
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301164
Pavel Roskinf6351d42011-06-15 18:01:05 -04001165 hi = max(hi, hthi);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001166 }
1167
Sujith256b7752008-11-18 09:03:12 +05301168 ath_rc_priv->rate_table_size = hi + 1;
1169 ath_rc_priv->rate_max_phy = 0;
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301170 WARN_ON(ath_rc_priv->rate_table_size > RATE_TABLE_SIZE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001171
1172 for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) {
Sujith256b7752008-11-18 09:03:12 +05301173 for (j = 0; j < ath_rc_priv->valid_phy_ratecnt[i]; j++) {
1174 ath_rc_priv->valid_rate_index[k++] =
1175 ath_rc_priv->valid_phy_rateidx[i][j];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001176 }
1177
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301178 if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, 1) ||
1179 !ath_rc_priv->valid_phy_ratecnt[i])
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001180 continue;
1181
Sujith256b7752008-11-18 09:03:12 +05301182 ath_rc_priv->rate_max_phy = ath_rc_priv->valid_phy_rateidx[i][j-1];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001183 }
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301184 WARN_ON(ath_rc_priv->rate_table_size > RATE_TABLE_SIZE);
1185 WARN_ON(k > RATE_TABLE_SIZE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001186
Sujith256b7752008-11-18 09:03:12 +05301187 ath_rc_priv->max_valid_rate = k;
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301188 ath_rc_sort_validrates(ath_rc_priv);
Rajkumar Manoharan10636bc2011-12-10 18:59:43 +05301189 ath_rc_priv->rate_max_phy = (k > 4) ?
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301190 ath_rc_priv->valid_rate_index[k-4] :
1191 ath_rc_priv->valid_rate_index[k-1];
Sujith9331ec82009-03-02 13:29:45 +05301192
Joe Perchesd2182b62011-12-15 14:55:53 -08001193 ath_dbg(common, CONFIG, "RC Initialized with capabilities: 0x%x\n",
Joe Perches226afe62010-12-02 19:12:37 -08001194 ath_rc_priv->ht_cap);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001195}
1196
Sujith Manoharan62a29182012-08-10 16:45:52 +05301197static u8 ath_rc_build_ht_caps(struct ath_softc *sc, struct ieee80211_sta *sta)
Sujith9331ec82009-03-02 13:29:45 +05301198{
1199 u8 caps = 0;
1200
Sujithc2da50e2009-03-13 08:56:11 +05301201 if (sta->ht_cap.ht_supported) {
Sujith9331ec82009-03-02 13:29:45 +05301202 caps = WLAN_RC_HT_FLAG;
Senthil Balasubramanian1d9d06a2010-07-27 19:16:32 +05301203 if (sta->ht_cap.mcs.rx_mask[1] && sta->ht_cap.mcs.rx_mask[2])
1204 caps |= WLAN_RC_TS_FLAG | WLAN_RC_DS_FLAG;
1205 else if (sta->ht_cap.mcs.rx_mask[1])
Felix Fietkau35537272010-06-12 17:22:33 +02001206 caps |= WLAN_RC_DS_FLAG;
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001207 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
Sujith9331ec82009-03-02 13:29:45 +05301208 caps |= WLAN_RC_40_FLAG;
Sujith Manoharan215999f2012-09-12 14:59:58 +05301209 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)
1210 caps |= WLAN_RC_SGI_FLAG;
1211 } else {
1212 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20)
1213 caps |= WLAN_RC_SGI_FLAG;
1214 }
Sujith9331ec82009-03-02 13:29:45 +05301215 }
1216
1217 return caps;
1218}
1219
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +05301220static bool ath_tx_aggr_check(struct ath_softc *sc, struct ieee80211_sta *sta,
Felix Fietkau334b0602010-09-20 13:45:39 +02001221 u8 tidno)
1222{
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +05301223 struct ath_node *an = (struct ath_node *)sta->drv_priv;
Felix Fietkau334b0602010-09-20 13:45:39 +02001224 struct ath_atx_tid *txtid;
1225
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +05301226 if (!sta->ht_cap.ht_supported)
Felix Fietkau334b0602010-09-20 13:45:39 +02001227 return false;
1228
1229 txtid = ATH_AN_2_TID(an, tidno);
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001230 return !txtid->active;
Felix Fietkau334b0602010-09-20 13:45:39 +02001231}
1232
1233
Sujith9331ec82009-03-02 13:29:45 +05301234/***********************************/
1235/* mac80211 Rate Control callbacks */
1236/***********************************/
1237
Johannes Berg4b7679a2008-09-18 18:14:18 +02001238static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
1239 struct ieee80211_sta *sta, void *priv_sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001240 struct sk_buff *skb)
1241{
1242 struct ath_softc *sc = priv;
Sujith46d14a52008-11-18 09:08:13 +05301243 struct ath_rate_priv *ath_rc_priv = priv_sta;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001244 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Sujith Manoharanc1610112012-08-10 16:47:03 +05301245 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Sujith Manoharanc1610112012-08-10 16:47:03 +05301246 __le16 fc = hdr->frame_control;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001247
Felix Fietkaud9698472010-03-01 13:32:11 +01001248 if (!priv_sta || !ieee80211_is_data(fc))
1249 return;
1250
1251 /* This packet was aggregated but doesn't carry status info */
1252 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) &&
1253 !(tx_info->flags & IEEE80211_TX_STAT_AMPDU))
Felix Fietkau827e69b2009-11-15 23:09:25 +01001254 return;
Johannes Berge6a98542008-10-21 12:40:02 +02001255
Felix Fietkau827e69b2009-11-15 23:09:25 +01001256 if (tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED)
1257 return;
Johannes Berge6a98542008-10-21 12:40:02 +02001258
Sujith Manoharan88dcc2d2012-08-10 16:47:09 +05301259 ath_rc_tx_status(sc, ath_rc_priv, skb);
Sujith46d14a52008-11-18 09:08:13 +05301260
Sujithd22b0022009-01-28 11:55:45 +05301261 /* Check if aggregation has to be enabled for this tid */
Vasanthakumar Thiagarajand5c232f2009-02-18 10:22:02 +05301262 if (conf_is_ht(&sc->hw->conf) &&
1263 !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
Luis R. Rodriguezc8b57602010-11-23 15:05:01 -08001264 if (ieee80211_is_data_qos(fc) &&
1265 skb_get_queue_mapping(skb) != IEEE80211_AC_VO) {
Sujithd22b0022009-01-28 11:55:45 +05301266 u8 *qc, tid;
Sujithd22b0022009-01-28 11:55:45 +05301267
1268 qc = ieee80211_get_qos_ctl(hdr);
1269 tid = qc[0] & 0xf;
Sujithd22b0022009-01-28 11:55:45 +05301270
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +05301271 if(ath_tx_aggr_check(sc, sta, tid))
Sujith Manoharanbd2ce6e2010-12-15 07:47:10 +05301272 ieee80211_start_tx_ba_session(sta, tid, 0);
Sujithd22b0022009-01-28 11:55:45 +05301273 }
1274 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001275}
1276
Johannes Berg4b7679a2008-09-18 18:14:18 +02001277static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
1278 struct ieee80211_sta *sta, void *priv_sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001279{
Johannes Berg4b7679a2008-09-18 18:14:18 +02001280 struct ath_softc *sc = priv;
Sujith Manoharan62a29182012-08-10 16:45:52 +05301281 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith46d14a52008-11-18 09:08:13 +05301282 struct ath_rate_priv *ath_rc_priv = priv_sta;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001283 int i, j = 0;
1284
Sujith7b4d2732008-11-18 09:04:00 +05301285 for (i = 0; i < sband->n_bitrates; i++) {
1286 if (sta->supp_rates[sband->band] & BIT(i)) {
1287 ath_rc_priv->neg_rates.rs_rates[j]
1288 = (sband->bitrates[i].bitrate * 2) / 10;
1289 j++;
1290 }
1291 }
1292 ath_rc_priv->neg_rates.rs_nrates = j;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001293
Sujitha4510bf2008-10-23 12:15:19 +05301294 if (sta->ht_cap.ht_supported) {
Sujith7b4d2732008-11-18 09:04:00 +05301295 for (i = 0, j = 0; i < 77; i++) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001296 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
Sujithdc2222a2008-08-14 13:26:55 +05301297 ath_rc_priv->neg_ht_rates.rs_rates[j++] = i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001298 if (j == ATH_RATE_MAX)
1299 break;
1300 }
Sujithdc2222a2008-08-14 13:26:55 +05301301 ath_rc_priv->neg_ht_rates.rs_nrates = j;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001302 }
Sujith7b4d2732008-11-18 09:04:00 +05301303
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301304 ath_rc_priv->rate_table = ath_choose_rate_table(sc, sband->band,
1305 sta->ht_cap.ht_supported);
1306 if (!ath_rc_priv->rate_table) {
Sujith Manoharan62a29182012-08-10 16:45:52 +05301307 ath_err(common, "No rate table chosen\n");
1308 return;
1309 }
Sujith9331ec82009-03-02 13:29:45 +05301310
Sujith Manoharan62a29182012-08-10 16:45:52 +05301311 ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta);
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301312 ath_rc_init(sc, priv_sta);
Sujith9331ec82009-03-02 13:29:45 +05301313}
1314
1315static void ath_rate_update(void *priv, struct ieee80211_supported_band *sband,
1316 struct ieee80211_sta *sta, void *priv_sta,
Johannes Berg64f68e52012-03-28 10:58:37 +02001317 u32 changed)
Sujith9331ec82009-03-02 13:29:45 +05301318{
1319 struct ath_softc *sc = priv;
1320 struct ath_rate_priv *ath_rc_priv = priv_sta;
Sujith9331ec82009-03-02 13:29:45 +05301321
Johannes Berg8f727ef2012-03-30 08:43:32 +02001322 if (changed & IEEE80211_RC_BW_CHANGED) {
Sujith Manoharan62a29182012-08-10 16:45:52 +05301323 ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta);
Sujith Manoharanea2771f2012-08-10 16:46:04 +05301324 ath_rc_init(sc, priv_sta);
Sujith9331ec82009-03-02 13:29:45 +05301325
Sujith Manoharan62a29182012-08-10 16:45:52 +05301326 ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG,
1327 "Operating HT Bandwidth changed to: %d\n",
Karl Beldan675a0b02013-03-25 16:26:57 +01001328 cfg80211_get_chandef_type(&sc->hw->conf.chandef));
Sujith9331ec82009-03-02 13:29:45 +05301329 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001330}
1331
Sujith Manoharan1c11e102012-11-21 18:13:13 +05301332#if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_DEBUGFS)
Felix Fietkau772d5512010-10-13 16:43:26 +02001333
Sujith Manoharan4d28f772012-11-21 18:13:14 +05301334void ath_debug_stat_rc(struct ath_rate_priv *rc, int final_rate)
1335{
1336 struct ath_rc_stats *stats;
1337
1338 stats = &rc->rcstats[final_rate];
1339 stats->success++;
1340}
1341
1342void ath_debug_stat_retries(struct ath_rate_priv *rc, int rix,
1343 int xretries, int retries, u8 per)
1344{
1345 struct ath_rc_stats *stats = &rc->rcstats[rix];
1346
1347 stats->xretries += xretries;
1348 stats->retries += retries;
1349 stats->per = per;
1350}
1351
Felix Fietkau772d5512010-10-13 16:43:26 +02001352static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
1353 size_t count, loff_t *ppos)
1354{
1355 struct ath_rate_priv *rc = file->private_data;
1356 char *buf;
1357 unsigned int len = 0, max;
Rajkumar Manoharanc771b512012-08-10 16:47:30 +05301358 int rix;
Felix Fietkau772d5512010-10-13 16:43:26 +02001359 ssize_t retval;
1360
1361 if (rc->rate_table == NULL)
1362 return 0;
1363
Mohammed Shafi Shajakhan32359e32011-08-09 21:33:43 +05301364 max = 80 + rc->rate_table_size * 1024 + 1;
Felix Fietkau772d5512010-10-13 16:43:26 +02001365 buf = kmalloc(max, GFP_KERNEL);
1366 if (buf == NULL)
1367 return -ENOMEM;
1368
1369 len += sprintf(buf, "%6s %6s %6s "
1370 "%10s %10s %10s %10s\n",
1371 "HT", "MCS", "Rate",
1372 "Success", "Retries", "XRetries", "PER");
1373
Rajkumar Manoharanc771b512012-08-10 16:47:30 +05301374 for (rix = 0; rix < rc->max_valid_rate; rix++) {
1375 u8 i = rc->valid_rate_index[rix];
Felix Fietkau772d5512010-10-13 16:43:26 +02001376 u32 ratekbps = rc->rate_table->info[i].ratekbps;
1377 struct ath_rc_stats *stats = &rc->rcstats[i];
1378 char mcs[5];
1379 char htmode[5];
1380 int used_mcs = 0, used_htmode = 0;
1381
1382 if (WLAN_RC_PHY_HT(rc->rate_table->info[i].phy)) {
1383 used_mcs = snprintf(mcs, 5, "%d",
1384 rc->rate_table->info[i].ratecode);
1385
1386 if (WLAN_RC_PHY_40(rc->rate_table->info[i].phy))
1387 used_htmode = snprintf(htmode, 5, "HT40");
1388 else if (WLAN_RC_PHY_20(rc->rate_table->info[i].phy))
1389 used_htmode = snprintf(htmode, 5, "HT20");
1390 else
1391 used_htmode = snprintf(htmode, 5, "????");
1392 }
1393
1394 mcs[used_mcs] = '\0';
1395 htmode[used_htmode] = '\0';
1396
1397 len += snprintf(buf + len, max - len,
1398 "%6s %6s %3u.%d: "
1399 "%10u %10u %10u %10u\n",
1400 htmode,
1401 mcs,
1402 ratekbps / 1000,
1403 (ratekbps % 1000) / 100,
1404 stats->success,
1405 stats->retries,
1406 stats->xretries,
1407 stats->per);
1408 }
1409
1410 if (len > max)
1411 len = max;
1412
1413 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1414 kfree(buf);
1415 return retval;
1416}
1417
1418static const struct file_operations fops_rcstat = {
1419 .read = read_file_rcstat,
Stephen Boyd234e3402012-04-05 14:25:11 -07001420 .open = simple_open,
Felix Fietkau772d5512010-10-13 16:43:26 +02001421 .owner = THIS_MODULE
1422};
1423
1424static void ath_rate_add_sta_debugfs(void *priv, void *priv_sta,
1425 struct dentry *dir)
1426{
1427 struct ath_rate_priv *rc = priv_sta;
Sujith Manoharan1c11e102012-11-21 18:13:13 +05301428 rc->debugfs_rcstats = debugfs_create_file("rc_stats", S_IRUGO,
1429 dir, rc, &fops_rcstat);
Felix Fietkau772d5512010-10-13 16:43:26 +02001430}
1431
Sujith Manoharan1c11e102012-11-21 18:13:13 +05301432static void ath_rate_remove_sta_debugfs(void *priv, void *priv_sta)
1433{
1434 struct ath_rate_priv *rc = priv_sta;
1435 debugfs_remove(rc->debugfs_rcstats);
1436}
1437
1438#endif /* CONFIG_MAC80211_DEBUGFS && CONFIG_ATH9K_DEBUGFS */
Felix Fietkau772d5512010-10-13 16:43:26 +02001439
Johannes Berg4b7679a2008-09-18 18:14:18 +02001440static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001441{
Felix Fietkau9ac58612011-01-24 19:23:18 +01001442 return hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001443}
1444
1445static void ath_rate_free(void *priv)
1446{
1447 return;
1448}
1449
Johannes Berg4b7679a2008-09-18 18:14:18 +02001450static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001451{
Joe Perches14f8dc42013-02-07 11:46:27 +00001452 return kzalloc(sizeof(struct ath_rate_priv), gfp);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001453}
1454
Johannes Berg4b7679a2008-09-18 18:14:18 +02001455static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta,
1456 void *priv_sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001457{
Sujith46d14a52008-11-18 09:08:13 +05301458 struct ath_rate_priv *rate_priv = priv_sta;
Sujithfe605942008-11-18 09:03:36 +05301459 kfree(rate_priv);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001460}
1461
1462static struct rate_control_ops ath_rate_ops = {
1463 .module = NULL,
1464 .name = "ath9k_rate_control",
1465 .tx_status = ath_tx_status,
1466 .get_rate = ath_get_rate,
1467 .rate_init = ath_rate_init,
Sujith9331ec82009-03-02 13:29:45 +05301468 .rate_update = ath_rate_update,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001469 .alloc = ath_rate_alloc,
1470 .free = ath_rate_free,
1471 .alloc_sta = ath_rate_alloc_sta,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001472 .free_sta = ath_rate_free_sta,
Sujith Manoharan1c11e102012-11-21 18:13:13 +05301473
1474#if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_DEBUGFS)
Felix Fietkau772d5512010-10-13 16:43:26 +02001475 .add_sta_debugfs = ath_rate_add_sta_debugfs,
Sujith Manoharan1c11e102012-11-21 18:13:13 +05301476 .remove_sta_debugfs = ath_rate_remove_sta_debugfs,
Felix Fietkau772d5512010-10-13 16:43:26 +02001477#endif
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001478};
1479
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001480int ath_rate_control_register(void)
1481{
1482 return ieee80211_rate_control_register(&ath_rate_ops);
1483}
1484
1485void ath_rate_control_unregister(void)
1486{
1487 ieee80211_rate_control_unregister(&ath_rate_ops);
1488}