blob: 66d3004af2bcb4ba984ae696394cbff8afaf6327 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
2 * Copyright (c) 2004 Video54 Technologies, Inc.
Sujithcee075a2009-03-13 09:07:23 +05303 * Copyright (c) 2004-2009 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
Sujith394cf0a2009-02-09 13:26:54 +053018#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070019
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -040020static const struct ath_rate_table ar5416_11na_ratetable = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070021 42,
Felix Fietkau545750d2009-11-23 22:21:01 +010022 8, /* MCS start */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070023 {
Sujith46d14a52008-11-18 09:08:13 +053024 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010025 5400, 0, 0x00, 12,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040026 0, 0, 0, 0, 0, 0 },
Sujithe8324352009-01-16 21:38:42 +053027 { VALID, VALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010028 7800, 1, 0x00, 18,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040029 0, 1, 1, 1, 1, 0 },
Sujith46d14a52008-11-18 09:08:13 +053030 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010031 10000, 2, 0x00, 24,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040032 2, 2, 2, 2, 2, 0 },
Sujith46d14a52008-11-18 09:08:13 +053033 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010034 13900, 3, 0x00, 36,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040035 2, 3, 3, 3, 3, 0 },
Sujith46d14a52008-11-18 09:08:13 +053036 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010037 17300, 4, 0x00, 48,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040038 4, 4, 4, 4, 4, 0 },
Sujith46d14a52008-11-18 09:08:13 +053039 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010040 23000, 5, 0x00, 72,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040041 4, 5, 5, 5, 5, 0 },
Sujith46d14a52008-11-18 09:08:13 +053042 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010043 27400, 6, 0x00, 96,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040044 4, 6, 6, 6, 6, 0 },
Sujith46d14a52008-11-18 09:08:13 +053045 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010046 29300, 7, 0x00, 108,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040047 4, 7, 7, 7, 7, 0 },
Vasanthakumar Thiagarajan42e88562009-07-29 15:05:21 +053048 { VALID_2040, VALID_2040, WLAN_RC_PHY_HT_20_SS, 6500, /* 6.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010049 6400, 0, 0x00, 0,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040050 0, 8, 24, 8, 24, 3216 },
Sujith46d14a52008-11-18 09:08:13 +053051 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 13000, /* 13 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010052 12700, 1, 0x00, 1,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040053 2, 9, 25, 9, 25, 6434 },
Sujith46d14a52008-11-18 09:08:13 +053054 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 19500, /* 19.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010055 18800, 2, 0x00, 2,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040056 2, 10, 26, 10, 26, 9650 },
Sujith46d14a52008-11-18 09:08:13 +053057 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 26000, /* 26 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010058 25000, 3, 0x00, 3,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040059 4, 11, 27, 11, 27, 12868 },
Sujith46d14a52008-11-18 09:08:13 +053060 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 39000, /* 39 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010061 36700, 4, 0x00, 4,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040062 4, 12, 28, 12, 28, 19304 },
Sujith46d14a52008-11-18 09:08:13 +053063 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 52000, /* 52 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010064 48100, 5, 0x00, 5,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040065 4, 13, 29, 13, 29, 25740 },
Sujith46d14a52008-11-18 09:08:13 +053066 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 58500, /* 58.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010067 53500, 6, 0x00, 6,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040068 4, 14, 30, 14, 30, 28956 },
Sujith46d14a52008-11-18 09:08:13 +053069 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 65000, /* 65 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010070 59000, 7, 0x00, 7,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040071 4, 15, 31, 15, 32, 32180 },
Sujith46d14a52008-11-18 09:08:13 +053072 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 13000, /* 13 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010073 12700, 8, 0x00,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040074 8, 3, 16, 33, 16, 33, 6430 },
Sujith46d14a52008-11-18 09:08:13 +053075 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 26000, /* 26 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010076 24800, 9, 0x00, 9,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040077 2, 17, 34, 17, 34, 12860 },
Sujith46d14a52008-11-18 09:08:13 +053078 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 39000, /* 39 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010079 36600, 10, 0x00, 10,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040080 2, 18, 35, 18, 35, 19300 },
Sujith46d14a52008-11-18 09:08:13 +053081 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 52000, /* 52 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010082 48100, 11, 0x00, 11,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040083 4, 19, 36, 19, 36, 25736 },
Sujith46d14a52008-11-18 09:08:13 +053084 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 78000, /* 78 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010085 69500, 12, 0x00, 12,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040086 4, 20, 37, 20, 37, 38600 },
Sujith46d14a52008-11-18 09:08:13 +053087 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 104000, /* 104 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010088 89500, 13, 0x00, 13,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040089 4, 21, 38, 21, 38, 51472 },
Sujith46d14a52008-11-18 09:08:13 +053090 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 117000, /* 117 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010091 98900, 14, 0x00, 14,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040092 4, 22, 39, 22, 39, 57890 },
Sujith46d14a52008-11-18 09:08:13 +053093 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 130000, /* 130 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010094 108300, 15, 0x00, 15,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040095 4, 23, 40, 23, 41, 64320 },
Sujith46d14a52008-11-18 09:08:13 +053096 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 13500, /* 13.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +010097 13200, 0, 0x00, 0,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -040098 0, 8, 24, 24, 24, 6684 },
Sujith46d14a52008-11-18 09:08:13 +053099 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 27500, /* 27.0 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100100 25900, 1, 0x00, 1,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400101 2, 9, 25, 25, 25, 13368 },
Sujith46d14a52008-11-18 09:08:13 +0530102 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 40500, /* 40.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100103 38600, 2, 0x00, 2,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400104 2, 10, 26, 26, 26, 20052 },
Sujith46d14a52008-11-18 09:08:13 +0530105 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 54000, /* 54 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100106 49800, 3, 0x00, 3,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400107 4, 11, 27, 27, 27, 26738 },
Sujith46d14a52008-11-18 09:08:13 +0530108 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 81500, /* 81 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100109 72200, 4, 0x00, 4,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400110 4, 12, 28, 28, 28, 40104 },
Sujith46d14a52008-11-18 09:08:13 +0530111 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 108000, /* 108 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100112 92900, 5, 0x00, 5,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400113 4, 13, 29, 29, 29, 53476 },
Sujith46d14a52008-11-18 09:08:13 +0530114 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 121500, /* 121.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100115 102700, 6, 0x00, 6,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400116 4, 14, 30, 30, 30, 60156 },
Sujith46d14a52008-11-18 09:08:13 +0530117 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 135000, /* 135 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100118 112000, 7, 0x00, 7,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400119 4, 15, 31, 32, 32, 66840 },
Sujith46d14a52008-11-18 09:08:13 +0530120 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100121 122000, 7, 0x00, 7,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400122 4, 15, 31, 32, 32, 74200 },
Sujith46d14a52008-11-18 09:08:13 +0530123 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 27000, /* 27 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100124 25800, 8, 0x00, 8,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400125 0, 16, 33, 33, 33, 13360 },
Sujith46d14a52008-11-18 09:08:13 +0530126 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 54000, /* 54 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100127 49800, 9, 0x00, 9,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400128 2, 17, 34, 34, 34, 26720 },
Sujith46d14a52008-11-18 09:08:13 +0530129 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 81000, /* 81 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100130 71900, 10, 0x00, 10,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400131 2, 18, 35, 35, 35, 40080 },
Sujith46d14a52008-11-18 09:08:13 +0530132 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 108000, /* 108 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100133 92500, 11, 0x00, 11,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400134 4, 19, 36, 36, 36, 53440 },
Sujith46d14a52008-11-18 09:08:13 +0530135 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 162000, /* 162 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100136 130300, 12, 0x00, 12,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400137 4, 20, 37, 37, 37, 80160 },
Sujith46d14a52008-11-18 09:08:13 +0530138 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 216000, /* 216 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100139 162800, 13, 0x00, 13,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400140 4, 21, 38, 38, 38, 106880 },
Sujith46d14a52008-11-18 09:08:13 +0530141 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 243000, /* 243 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100142 178200, 14, 0x00, 14,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400143 4, 22, 39, 39, 39, 120240 },
Sujith46d14a52008-11-18 09:08:13 +0530144 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 270000, /* 270 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100145 192100, 15, 0x00, 15,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400146 4, 23, 40, 41, 41, 133600 },
Sujith46d14a52008-11-18 09:08:13 +0530147 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100148 207000, 15, 0x00, 15,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400149 4, 23, 40, 41, 41, 148400 },
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700150 },
151 50, /* probe interval */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700152 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
153};
154
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700155/* 4ms frame limit not used for NG mode. The values filled
156 * for HT are the 64K max aggregate limit */
157
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400158static const struct ath_rate_table ar5416_11ng_ratetable = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700159 46,
Felix Fietkau545750d2009-11-23 22:21:01 +0100160 12, /* MCS start */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700161 {
Sujith46d14a52008-11-18 09:08:13 +0530162 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100163 900, 0, 0x00, 2,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400164 0, 0, 0, 0, 0, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530165 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100166 1900, 1, 0x04, 4,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400167 1, 1, 1, 1, 1, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530168 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100169 4900, 2, 0x04, 11,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400170 2, 2, 2, 2, 2, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530171 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100172 8100, 3, 0x04, 22,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400173 3, 3, 3, 3, 3, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530174 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100175 5400, 4, 0x00, 12,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400176 4, 4, 4, 4, 4, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530177 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100178 7800, 5, 0x00, 18,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400179 4, 5, 5, 5, 5, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530180 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100181 10100, 6, 0x00, 24,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400182 6, 6, 6, 6, 6, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530183 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100184 14100, 7, 0x00, 36,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400185 6, 7, 7, 7, 7, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530186 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100187 17700, 8, 0x00, 48,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400188 8, 8, 8, 8, 8, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530189 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100190 23700, 9, 0x00, 72,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400191 8, 9, 9, 9, 9, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530192 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100193 27400, 10, 0x00, 96,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400194 8, 10, 10, 10, 10, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530195 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100196 30900, 11, 0x00, 108,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400197 8, 11, 11, 11, 11, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530198 { INVALID, INVALID, WLAN_RC_PHY_HT_20_SS, 6500, /* 6.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100199 6400, 0, 0x00, 0,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400200 4, 12, 28, 12, 28, 3216 },
Sujith46d14a52008-11-18 09:08:13 +0530201 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 13000, /* 13 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100202 12700, 1, 0x00, 1,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400203 6, 13, 29, 13, 29, 6434 },
Sujith46d14a52008-11-18 09:08:13 +0530204 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 19500, /* 19.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100205 18800, 2, 0x00, 2,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400206 6, 14, 30, 14, 30, 9650 },
Sujith46d14a52008-11-18 09:08:13 +0530207 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 26000, /* 26 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100208 25000, 3, 0x00, 3,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400209 8, 15, 31, 15, 31, 12868 },
Sujith46d14a52008-11-18 09:08:13 +0530210 { VALID_20, VALID_20, WLAN_RC_PHY_HT_20_SS, 39000, /* 39 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100211 36700, 4, 0x00, 4,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400212 8, 16, 32, 16, 32, 19304 },
Sujith46d14a52008-11-18 09:08:13 +0530213 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 52000, /* 52 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100214 48100, 5, 0x00, 5,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400215 8, 17, 33, 17, 33, 25740 },
Sujith46d14a52008-11-18 09:08:13 +0530216 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 58500, /* 58.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100217 53500, 6, 0x00, 6,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400218 8, 18, 34, 18, 34, 28956 },
Sujith46d14a52008-11-18 09:08:13 +0530219 { INVALID, VALID_20, WLAN_RC_PHY_HT_20_SS, 65000, /* 65 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100220 59000, 7, 0x00, 7,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400221 8, 19, 35, 19, 36, 32180 },
Sujith46d14a52008-11-18 09:08:13 +0530222 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 13000, /* 13 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100223 12700, 8, 0x00, 8,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400224 4, 20, 37, 20, 37, 6430 },
Sujith46d14a52008-11-18 09:08:13 +0530225 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 26000, /* 26 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100226 24800, 9, 0x00, 9,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400227 6, 21, 38, 21, 38, 12860 },
Sujith46d14a52008-11-18 09:08:13 +0530228 { INVALID, INVALID, WLAN_RC_PHY_HT_20_DS, 39000, /* 39 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100229 36600, 10, 0x00, 10,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400230 6, 22, 39, 22, 39, 19300 },
Sujith46d14a52008-11-18 09:08:13 +0530231 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 52000, /* 52 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100232 48100, 11, 0x00, 11,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400233 8, 23, 40, 23, 40, 25736 },
Sujith46d14a52008-11-18 09:08:13 +0530234 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 78000, /* 78 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100235 69500, 12, 0x00, 12,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400236 8, 24, 41, 24, 41, 38600 },
Sujith46d14a52008-11-18 09:08:13 +0530237 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 104000, /* 104 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100238 89500, 13, 0x00, 13,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400239 8, 25, 42, 25, 42, 51472 },
Sujith46d14a52008-11-18 09:08:13 +0530240 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 117000, /* 117 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100241 98900, 14, 0x00, 14,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400242 8, 26, 43, 26, 44, 57890 },
Sujith46d14a52008-11-18 09:08:13 +0530243 { VALID_20, INVALID, WLAN_RC_PHY_HT_20_DS, 130000, /* 130 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100244 108300, 15, 0x00, 15,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400245 8, 27, 44, 27, 45, 64320 },
Sujith46d14a52008-11-18 09:08:13 +0530246 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 13500, /* 13.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100247 13200, 0, 0x00, 0,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400248 8, 12, 28, 28, 28, 6684 },
Sujith46d14a52008-11-18 09:08:13 +0530249 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 27500, /* 27.0 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100250 25900, 1, 0x00, 1,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400251 8, 13, 29, 29, 29, 13368 },
Sujith46d14a52008-11-18 09:08:13 +0530252 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 40500, /* 40.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100253 38600, 2, 0x00, 2,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400254 8, 14, 30, 30, 30, 20052 },
Sujith46d14a52008-11-18 09:08:13 +0530255 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 54000, /* 54 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100256 49800, 3, 0x00, 3,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400257 8, 15, 31, 31, 31, 26738 },
Sujith46d14a52008-11-18 09:08:13 +0530258 { VALID_40, VALID_40, WLAN_RC_PHY_HT_40_SS, 81500, /* 81 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100259 72200, 4, 0x00, 4,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400260 8, 16, 32, 32, 32, 40104 },
Sujith46d14a52008-11-18 09:08:13 +0530261 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 108000, /* 108 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100262 92900, 5, 0x00, 5,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400263 8, 17, 33, 33, 33, 53476 },
Sujith46d14a52008-11-18 09:08:13 +0530264 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 121500, /* 121.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100265 102700, 6, 0x00, 6,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400266 8, 18, 34, 34, 34, 60156 },
Sujith46d14a52008-11-18 09:08:13 +0530267 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS, 135000, /* 135 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100268 112000, 7, 0x00, 7,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400269 8, 19, 35, 36, 36, 66840 },
Sujith46d14a52008-11-18 09:08:13 +0530270 { INVALID, VALID_40, WLAN_RC_PHY_HT_40_SS_HGI, 150000, /* 150 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100271 122000, 7, 0x00, 7,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400272 8, 19, 35, 36, 36, 74200 },
Sujith46d14a52008-11-18 09:08:13 +0530273 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 27000, /* 27 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100274 25800, 8, 0x00, 8,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400275 8, 20, 37, 37, 37, 13360 },
Sujith46d14a52008-11-18 09:08:13 +0530276 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 54000, /* 54 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100277 49800, 9, 0x00, 9,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400278 8, 21, 38, 38, 38, 26720 },
Sujith46d14a52008-11-18 09:08:13 +0530279 { INVALID, INVALID, WLAN_RC_PHY_HT_40_DS, 81000, /* 81 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100280 71900, 10, 0x00, 10,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400281 8, 22, 39, 39, 39, 40080 },
Sujith46d14a52008-11-18 09:08:13 +0530282 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 108000, /* 108 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100283 92500, 11, 0x00, 11,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400284 8, 23, 40, 40, 40, 53440 },
Sujith46d14a52008-11-18 09:08:13 +0530285 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 162000, /* 162 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100286 130300, 12, 0x00, 12,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400287 8, 24, 41, 41, 41, 80160 },
Sujith46d14a52008-11-18 09:08:13 +0530288 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 216000, /* 216 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100289 162800, 13, 0x00, 13,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400290 8, 25, 42, 42, 42, 106880 },
Sujith46d14a52008-11-18 09:08:13 +0530291 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 243000, /* 243 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100292 178200, 14, 0x00, 14,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400293 8, 26, 43, 43, 43, 120240 },
Sujith46d14a52008-11-18 09:08:13 +0530294 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS, 270000, /* 270 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100295 192100, 15, 0x00, 15,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400296 8, 27, 44, 45, 45, 133600 },
Sujith46d14a52008-11-18 09:08:13 +0530297 { VALID_40, INVALID, WLAN_RC_PHY_HT_40_DS_HGI, 300000, /* 300 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100298 207000, 15, 0x00, 15,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400299 8, 27, 44, 45, 45, 148400 },
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700300 },
301 50, /* probe interval */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700302 WLAN_RC_HT_FLAG, /* Phy rates allowed initially */
303};
304
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400305static const struct ath_rate_table ar5416_11a_ratetable = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700306 8,
Felix Fietkau545750d2009-11-23 22:21:01 +0100307 0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700308 {
Sujith46d14a52008-11-18 09:08:13 +0530309 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100310 5400, 0, 0x00, 12,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400311 0, 0, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530312 { VALID, VALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100313 7800, 1, 0x00, 18,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400314 0, 1, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530315 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100316 10000, 2, 0x00, 24,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400317 2, 2, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530318 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100319 13900, 3, 0x00, 36,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400320 2, 3, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530321 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100322 17300, 4, 0x00, 48,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400323 4, 4, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530324 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100325 23000, 5, 0x00, 72,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400326 4, 5, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530327 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100328 27400, 6, 0x00, 96,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400329 4, 6, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530330 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100331 29300, 7, 0x00, 108,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400332 4, 7, 0 },
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700333 },
334 50, /* probe interval */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700335 0, /* Phy rates allowed initially */
336};
337
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400338static const struct ath_rate_table ar5416_11g_ratetable = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700339 12,
Felix Fietkau545750d2009-11-23 22:21:01 +0100340 0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700341 {
Sujith46d14a52008-11-18 09:08:13 +0530342 { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100343 900, 0, 0x00, 2,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400344 0, 0, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530345 { VALID, VALID, WLAN_RC_PHY_CCK, 2000, /* 2 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100346 1900, 1, 0x04, 4,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400347 1, 1, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530348 { VALID, VALID, WLAN_RC_PHY_CCK, 5500, /* 5.5 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100349 4900, 2, 0x04, 11,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400350 2, 2, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530351 { VALID, VALID, WLAN_RC_PHY_CCK, 11000, /* 11 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100352 8100, 3, 0x04, 22,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400353 3, 3, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530354 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100355 5400, 4, 0x00, 12,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400356 4, 4, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530357 { INVALID, INVALID, WLAN_RC_PHY_OFDM, 9000, /* 9 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100358 7800, 5, 0x00, 18,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400359 4, 5, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530360 { VALID, VALID, WLAN_RC_PHY_OFDM, 12000, /* 12 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100361 10000, 6, 0x00, 24,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400362 6, 6, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530363 { VALID, VALID, WLAN_RC_PHY_OFDM, 18000, /* 18 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100364 13900, 7, 0x00, 36,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400365 6, 7, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530366 { VALID, VALID, WLAN_RC_PHY_OFDM, 24000, /* 24 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100367 17300, 8, 0x00, 48,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400368 8, 8, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530369 { VALID, VALID, WLAN_RC_PHY_OFDM, 36000, /* 36 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100370 23000, 9, 0x00, 72,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400371 8, 9, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530372 { VALID, VALID, WLAN_RC_PHY_OFDM, 48000, /* 48 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100373 27400, 10, 0x00, 96,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400374 8, 10, 0 },
Sujith46d14a52008-11-18 09:08:13 +0530375 { VALID, VALID, WLAN_RC_PHY_OFDM, 54000, /* 54 Mb */
Felix Fietkau545750d2009-11-23 22:21:01 +0100376 29300, 11, 0x00, 108,
Vasanthakumar Thiagarajanddf4a2d2009-07-14 20:14:11 -0400377 8, 11, 0 },
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700378 },
379 50, /* probe interval */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700380 0, /* Phy rates allowed initially */
381};
382
Felix Fietkau545750d2009-11-23 22:21:01 +0100383static const struct ath_rate_table *hw_rate_table[ATH9K_MODE_MAX] = {
384 [ATH9K_MODE_11A] = &ar5416_11a_ratetable,
385 [ATH9K_MODE_11G] = &ar5416_11g_ratetable,
386 [ATH9K_MODE_11NA_HT20] = &ar5416_11na_ratetable,
387 [ATH9K_MODE_11NG_HT20] = &ar5416_11ng_ratetable,
388 [ATH9K_MODE_11NA_HT40PLUS] = &ar5416_11na_ratetable,
389 [ATH9K_MODE_11NA_HT40MINUS] = &ar5416_11na_ratetable,
390 [ATH9K_MODE_11NG_HT40PLUS] = &ar5416_11ng_ratetable,
391 [ATH9K_MODE_11NG_HT40MINUS] = &ar5416_11ng_ratetable,
392};
393
394static int ath_rc_get_rateindex(const struct ath_rate_table *rate_table,
395 struct ieee80211_tx_rate *rate);
396
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700397static inline int8_t median(int8_t a, int8_t b, int8_t c)
398{
399 if (a >= b) {
400 if (b >= c)
401 return b;
402 else if (a > c)
403 return c;
404 else
405 return a;
406 } else {
407 if (a >= c)
408 return a;
409 else if (b >= c)
410 return c;
411 else
412 return b;
413 }
414}
415
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400416static void ath_rc_sort_validrates(const struct ath_rate_table *rate_table,
Sujith46d14a52008-11-18 09:08:13 +0530417 struct ath_rate_priv *ath_rc_priv)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700418{
419 u8 i, j, idx, idx_next;
420
Sujith256b77592008-11-18 09:03:12 +0530421 for (i = ath_rc_priv->max_valid_rate - 1; i > 0; i--) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700422 for (j = 0; j <= i-1; j++) {
Sujith256b77592008-11-18 09:03:12 +0530423 idx = ath_rc_priv->valid_rate_index[j];
424 idx_next = ath_rc_priv->valid_rate_index[j+1];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425
426 if (rate_table->info[idx].ratekbps >
427 rate_table->info[idx_next].ratekbps) {
Sujith256b77592008-11-18 09:03:12 +0530428 ath_rc_priv->valid_rate_index[j] = idx_next;
429 ath_rc_priv->valid_rate_index[j+1] = idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700430 }
431 }
432 }
433}
434
Sujith46d14a52008-11-18 09:08:13 +0530435static void ath_rc_init_valid_txmask(struct ath_rate_priv *ath_rc_priv)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700436{
437 u8 i;
438
Sujith256b77592008-11-18 09:03:12 +0530439 for (i = 0; i < ath_rc_priv->rate_table_size; i++)
Sujith46d14a52008-11-18 09:08:13 +0530440 ath_rc_priv->valid_rate_index[i] = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700441}
442
Sujith46d14a52008-11-18 09:08:13 +0530443static inline void ath_rc_set_valid_txmask(struct ath_rate_priv *ath_rc_priv,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700444 u8 index, int valid_tx_rate)
445{
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -0700446 BUG_ON(index > ath_rc_priv->rate_table_size);
Sujith46d14a52008-11-18 09:08:13 +0530447 ath_rc_priv->valid_rate_index[index] = valid_tx_rate ? 1 : 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700448}
449
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400450static inline
451int ath_rc_get_nextvalid_txrate(const struct ath_rate_table *rate_table,
452 struct ath_rate_priv *ath_rc_priv,
453 u8 cur_valid_txrate,
454 u8 *next_idx)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700455{
456 u8 i;
457
Sujith256b77592008-11-18 09:03:12 +0530458 for (i = 0; i < ath_rc_priv->max_valid_rate - 1; i++) {
459 if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
460 *next_idx = ath_rc_priv->valid_rate_index[i+1];
Sujith46d14a52008-11-18 09:08:13 +0530461 return 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700462 }
463 }
464
465 /* No more valid rates */
466 *next_idx = 0;
Sujith2c5a7442008-11-18 09:08:33 +0530467
Sujith46d14a52008-11-18 09:08:13 +0530468 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700469}
470
471/* Return true only for single stream */
472
473static int ath_rc_valid_phyrate(u32 phy, u32 capflag, int ignore_cw)
474{
Jouni Malinenb657ead2009-01-13 14:33:49 +0200475 if (WLAN_RC_PHY_HT(phy) && !(capflag & WLAN_RC_HT_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530476 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700477 if (WLAN_RC_PHY_DS(phy) && !(capflag & WLAN_RC_DS_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530478 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700479 if (WLAN_RC_PHY_SGI(phy) && !(capflag & WLAN_RC_SGI_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530480 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700481 if (!ignore_cw && WLAN_RC_PHY_HT(phy))
482 if (WLAN_RC_PHY_40(phy) && !(capflag & WLAN_RC_40_FLAG))
Sujith46d14a52008-11-18 09:08:13 +0530483 return 0;
Sujith46d14a52008-11-18 09:08:13 +0530484 return 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700485}
486
487static inline int
Luis R. Rodriguez39448b02009-07-14 20:14:00 -0400488ath_rc_get_lower_rix(const struct ath_rate_table *rate_table,
489 struct ath_rate_priv *ath_rc_priv,
490 u8 cur_valid_txrate, u8 *next_idx)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700491{
492 int8_t i;
493
Sujith256b77592008-11-18 09:03:12 +0530494 for (i = 1; i < ath_rc_priv->max_valid_rate ; i++) {
495 if (ath_rc_priv->valid_rate_index[i] == cur_valid_txrate) {
496 *next_idx = ath_rc_priv->valid_rate_index[i-1];
Sujith46d14a52008-11-18 09:08:13 +0530497 return 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700498 }
499 }
Sujith2c5a7442008-11-18 09:08:33 +0530500
Sujith46d14a52008-11-18 09:08:13 +0530501 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700502}
503
Sujith2c5a7442008-11-18 09:08:33 +0530504static u8 ath_rc_init_validrates(struct ath_rate_priv *ath_rc_priv,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400505 const struct ath_rate_table *rate_table,
Sujith2c5a7442008-11-18 09:08:33 +0530506 u32 capflag)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700507{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700508 u8 i, hi = 0;
509 u32 valid;
510
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700511 for (i = 0; i < rate_table->rate_cnt; i++) {
Sujithc6483cf2009-03-30 15:28:56 +0530512 valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
Sujithdc2222a2008-08-14 13:26:55 +0530513 rate_table->info[i].valid_single_stream :
514 rate_table->info[i].valid);
Sujith46d14a52008-11-18 09:08:13 +0530515 if (valid == 1) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700516 u32 phy = rate_table->info[i].phy;
517 u8 valid_rate_count = 0;
518
Sujith46d14a52008-11-18 09:08:13 +0530519 if (!ath_rc_valid_phyrate(phy, capflag, 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700520 continue;
521
Sujith256b77592008-11-18 09:03:12 +0530522 valid_rate_count = ath_rc_priv->valid_phy_ratecnt[phy];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700523
Sujith256b77592008-11-18 09:03:12 +0530524 ath_rc_priv->valid_phy_rateidx[phy][valid_rate_count] = i;
525 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
Sujith46d14a52008-11-18 09:08:13 +0530526 ath_rc_set_valid_txmask(ath_rc_priv, i, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700527 hi = A_MAX(hi, i);
528 }
529 }
Sujith2c5a7442008-11-18 09:08:33 +0530530
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700531 return hi;
532}
533
Sujith2c5a7442008-11-18 09:08:33 +0530534static u8 ath_rc_setvalid_rates(struct ath_rate_priv *ath_rc_priv,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400535 const struct ath_rate_table *rate_table,
Sujith2c5a7442008-11-18 09:08:33 +0530536 struct ath_rateset *rateset,
537 u32 capflag)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700538{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700539 u8 i, j, hi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700540
541 /* Use intersection of working rates and valid rates */
542 for (i = 0; i < rateset->rs_nrates; i++) {
543 for (j = 0; j < rate_table->rate_cnt; j++) {
544 u32 phy = rate_table->info[j].phy;
Sujithc6483cf2009-03-30 15:28:56 +0530545 u32 valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
546 rate_table->info[j].valid_single_stream :
547 rate_table->info[j].valid);
Sujith2c5a7442008-11-18 09:08:33 +0530548 u8 rate = rateset->rs_rates[i];
549 u8 dot11rate = rate_table->info[j].dot11rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700550
551 /* We allow a rate only if its valid and the
552 * capflag matches one of the validity
Sujith46d14a52008-11-18 09:08:13 +0530553 * (VALID/VALID_20/VALID_40) flags */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700554
Felix Fietkau545750d2009-11-23 22:21:01 +0100555 if ((rate == dot11rate) &&
Sujith2c5a7442008-11-18 09:08:33 +0530556 ((valid & WLAN_RC_CAP_MODE(capflag)) ==
557 WLAN_RC_CAP_MODE(capflag)) &&
558 !WLAN_RC_PHY_HT(phy)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700559 u8 valid_rate_count = 0;
560
Sujith46d14a52008-11-18 09:08:13 +0530561 if (!ath_rc_valid_phyrate(phy, capflag, 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700562 continue;
563
564 valid_rate_count =
Sujith256b77592008-11-18 09:03:12 +0530565 ath_rc_priv->valid_phy_ratecnt[phy];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700566
Sujith256b77592008-11-18 09:03:12 +0530567 ath_rc_priv->valid_phy_rateidx[phy]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700568 [valid_rate_count] = j;
Sujith256b77592008-11-18 09:03:12 +0530569 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
Sujith46d14a52008-11-18 09:08:13 +0530570 ath_rc_set_valid_txmask(ath_rc_priv, j, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700571 hi = A_MAX(hi, j);
572 }
573 }
574 }
Sujith2c5a7442008-11-18 09:08:33 +0530575
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700576 return hi;
577}
578
Sujith2c5a7442008-11-18 09:08:33 +0530579static u8 ath_rc_setvalid_htrates(struct ath_rate_priv *ath_rc_priv,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400580 const struct ath_rate_table *rate_table,
Sujith2c5a7442008-11-18 09:08:33 +0530581 u8 *mcs_set, u32 capflag)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700582{
Sujith2c5a7442008-11-18 09:08:33 +0530583 struct ath_rateset *rateset = (struct ath_rateset *)mcs_set;
584
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700585 u8 i, j, hi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700586
587 /* Use intersection of working rates and valid rates */
Sujith2c5a7442008-11-18 09:08:33 +0530588 for (i = 0; i < rateset->rs_nrates; i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700589 for (j = 0; j < rate_table->rate_cnt; j++) {
590 u32 phy = rate_table->info[j].phy;
Sujithc6483cf2009-03-30 15:28:56 +0530591 u32 valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
Sujithdc2222a2008-08-14 13:26:55 +0530592 rate_table->info[j].valid_single_stream :
593 rate_table->info[j].valid);
Sujith2c5a7442008-11-18 09:08:33 +0530594 u8 rate = rateset->rs_rates[i];
595 u8 dot11rate = rate_table->info[j].dot11rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700596
Felix Fietkau545750d2009-11-23 22:21:01 +0100597 if ((rate != dot11rate) || !WLAN_RC_PHY_HT(phy) ||
Sujithdc2222a2008-08-14 13:26:55 +0530598 !WLAN_RC_PHY_HT_VALID(valid, capflag))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700599 continue;
600
Sujith46d14a52008-11-18 09:08:13 +0530601 if (!ath_rc_valid_phyrate(phy, capflag, 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700602 continue;
603
Sujith256b77592008-11-18 09:03:12 +0530604 ath_rc_priv->valid_phy_rateidx[phy]
605 [ath_rc_priv->valid_phy_ratecnt[phy]] = j;
606 ath_rc_priv->valid_phy_ratecnt[phy] += 1;
Sujith46d14a52008-11-18 09:08:13 +0530607 ath_rc_set_valid_txmask(ath_rc_priv, j, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700608 hi = A_MAX(hi, j);
609 }
610 }
Sujith2c5a7442008-11-18 09:08:33 +0530611
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700612 return hi;
613}
614
Luis R. Rodriguez201c3b42009-07-14 20:14:04 -0400615/* Finds the highest rate index we can use */
616static u8 ath_rc_get_highest_rix(struct ath_softc *sc,
617 struct ath_rate_priv *ath_rc_priv,
618 const struct ath_rate_table *rate_table,
619 int *is_probing)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700620{
Vasanthakumar Thiagarajan39a4caf2009-07-14 20:14:10 -0400621 u32 best_thruput, this_thruput, now_msec;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700622 u8 rate, next_rate, best_rate, maxindex, minindex;
Vasanthakumar Thiagarajan39a4caf2009-07-14 20:14:10 -0400623 int8_t index = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700624
625 now_msec = jiffies_to_msecs(jiffies);
Vasanthakumar Thiagarajan39a4caf2009-07-14 20:14:10 -0400626 *is_probing = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700627 best_thruput = 0;
Sujith256b77592008-11-18 09:03:12 +0530628 maxindex = ath_rc_priv->max_valid_rate-1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700629 minindex = 0;
630 best_rate = minindex;
631
632 /*
633 * Try the higher rate first. It will reduce memory moving time
634 * if we have very good channel characteristics.
635 */
636 for (index = maxindex; index >= minindex ; index--) {
637 u8 per_thres;
638
Sujith256b77592008-11-18 09:03:12 +0530639 rate = ath_rc_priv->valid_rate_index[index];
640 if (rate > ath_rc_priv->rate_max_phy)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700641 continue;
642
643 /*
644 * For TCP the average collision rate is around 11%,
645 * so we ignore PERs less than this. This is to
646 * prevent the rate we are currently using (whose
647 * PER might be in the 10-15 range because of TCP
648 * collisions) looking worse than the next lower
649 * rate whose PER has decayed close to 0. If we
650 * used to next lower rate, its PER would grow to
651 * 10-15 and we would be worse off then staying
652 * at the current rate.
653 */
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400654 per_thres = ath_rc_priv->per[rate];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700655 if (per_thres < 12)
656 per_thres = 12;
657
658 this_thruput = rate_table->info[rate].user_ratekbps *
659 (100 - per_thres);
660
661 if (best_thruput <= this_thruput) {
662 best_thruput = this_thruput;
663 best_rate = rate;
664 }
665 }
666
667 rate = best_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700668
669 /*
670 * Must check the actual rate (ratekbps) to account for
671 * non-monoticity of 11g's rate table
672 */
673
Sujith39008982009-01-30 14:29:15 +0530674 if (rate >= ath_rc_priv->rate_max_phy) {
Sujith256b77592008-11-18 09:03:12 +0530675 rate = ath_rc_priv->rate_max_phy;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700676
677 /* Probe the next allowed phy state */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700678 if (ath_rc_get_nextvalid_txrate(rate_table,
Sujith39008982009-01-30 14:29:15 +0530679 ath_rc_priv, rate, &next_rate) &&
Sujith256b77592008-11-18 09:03:12 +0530680 (now_msec - ath_rc_priv->probe_time >
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700681 rate_table->probe_interval) &&
Sujith256b77592008-11-18 09:03:12 +0530682 (ath_rc_priv->hw_maxretry_pktcnt >= 1)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700683 rate = next_rate;
Sujith256b77592008-11-18 09:03:12 +0530684 ath_rc_priv->probe_rate = rate;
685 ath_rc_priv->probe_time = now_msec;
686 ath_rc_priv->hw_maxretry_pktcnt = 0;
Sujith46d14a52008-11-18 09:08:13 +0530687 *is_probing = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700688 }
689 }
690
Sujith256b77592008-11-18 09:03:12 +0530691 if (rate > (ath_rc_priv->rate_table_size - 1))
692 rate = ath_rc_priv->rate_table_size - 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700693
Luis R. Rodrigueze43419f2009-07-14 20:13:54 -0400694 if (rate_table->info[rate].valid &&
695 (ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG))
696 return rate;
697
698 if (rate_table->info[rate].valid_single_stream &&
Luis R. Rodrigueze55ea2b2009-10-28 20:19:06 -0400699 !(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG))
Luis R. Rodrigueze43419f2009-07-14 20:13:54 -0400700 return rate;
701
702 /* This should not happen */
703 WARN_ON(1);
704
705 rate = ath_rc_priv->valid_rate_index[0];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700706
707 return rate;
708}
709
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400710static void ath_rc_rate_set_series(const struct ath_rate_table *rate_table,
Sujitha8efee42008-11-18 09:07:30 +0530711 struct ieee80211_tx_rate *rate,
Sujithc89424d2009-01-30 14:29:28 +0530712 struct ieee80211_tx_rate_control *txrc,
Sujith2c5a7442008-11-18 09:08:33 +0530713 u8 tries, u8 rix, int rtsctsenable)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700714{
Sujitha8efee42008-11-18 09:07:30 +0530715 rate->count = tries;
Felix Fietkau545750d2009-11-23 22:21:01 +0100716 rate->idx = rate_table->info[rix].ratecode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700717
Sujithc89424d2009-01-30 14:29:28 +0530718 if (txrc->short_preamble)
719 rate->flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
720 if (txrc->rts || rtsctsenable)
Sujitha8efee42008-11-18 09:07:30 +0530721 rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100722
723 if (WLAN_RC_PHY_HT(rate_table->info[rix].phy)) {
Sujitha8efee42008-11-18 09:07:30 +0530724 rate->flags |= IEEE80211_TX_RC_MCS;
Felix Fietkau545750d2009-11-23 22:21:01 +0100725 if (WLAN_RC_PHY_40(rate_table->info[rix].phy))
726 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
727 if (WLAN_RC_PHY_SGI(rate_table->info[rix].phy))
728 rate->flags |= IEEE80211_TX_RC_SHORT_GI;
729 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700730}
731
Sujithc89424d2009-01-30 14:29:28 +0530732static void ath_rc_rate_set_rtscts(struct ath_softc *sc,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400733 const struct ath_rate_table *rate_table,
Sujithc89424d2009-01-30 14:29:28 +0530734 struct ieee80211_tx_info *tx_info)
735{
736 struct ieee80211_tx_rate *rates = tx_info->control.rates;
737 int i = 0, rix = 0, cix, enable_g_protection = 0;
738
739 /* get the cix for the lowest valid rix */
740 for (i = 3; i >= 0; i--) {
741 if (rates[i].count && (rates[i].idx >= 0)) {
Felix Fietkau545750d2009-11-23 22:21:01 +0100742 rix = ath_rc_get_rateindex(rate_table, &rates[i]);
Sujithc89424d2009-01-30 14:29:28 +0530743 break;
744 }
745 }
746 cix = rate_table->info[rix].ctrl_rate;
747
748 /* All protection frames are transmited at 2Mb/s for 802.11g,
749 * otherwise we transmit them at 1Mb/s */
750 if (sc->hw->conf.channel->band == IEEE80211_BAND_2GHZ &&
751 !conf_is_ht(&sc->hw->conf))
752 enable_g_protection = 1;
753
754 /*
755 * If 802.11g protection is enabled, determine whether to use RTS/CTS or
756 * just CTS. Note that this is only done for OFDM/HT unicast frames.
757 */
758 if ((sc->sc_flags & SC_OP_PROTECT_ENABLE) &&
Sujithc89424d2009-01-30 14:29:28 +0530759 (rate_table->info[rix].phy == WLAN_RC_PHY_OFDM ||
760 WLAN_RC_PHY_HT(rate_table->info[rix].phy))) {
761 rates[0].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT;
762 cix = rate_table->info[enable_g_protection].ctrl_rate;
763 }
764
765 tx_info->control.rts_cts_rate_idx = cix;
766}
767
Luis R. Rodrigueze25739a2009-07-14 20:14:09 -0400768static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
769 struct ieee80211_tx_rate_control *txrc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770{
Luis R. Rodrigueze25739a2009-07-14 20:14:09 -0400771 struct ath_softc *sc = priv;
772 struct ath_rate_priv *ath_rc_priv = priv_sta;
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400773 const struct ath_rate_table *rate_table;
Sujith39008982009-01-30 14:29:15 +0530774 struct sk_buff *skb = txrc->skb;
775 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Sujitha8efee42008-11-18 09:07:30 +0530776 struct ieee80211_tx_rate *rates = tx_info->control.rates;
Sujithc89424d2009-01-30 14:29:28 +0530777 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
778 __le16 fc = hdr->frame_control;
Luis R. Rodriguezdd190182009-07-14 20:13:56 -0400779 u8 try_per_rate, i = 0, rix, nrix;
Sujith39008982009-01-30 14:29:15 +0530780 int is_probe = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781
Luis R. Rodrigueze25739a2009-07-14 20:14:09 -0400782 if (rate_control_send_low(sta, priv_sta, txrc))
783 return;
784
Luis R. Rodriguezdd190182009-07-14 20:13:56 -0400785 /*
786 * For Multi Rate Retry we use a different number of
787 * retry attempt counts. This ends up looking like this:
788 *
789 * MRR[0] = 2
790 * MRR[1] = 2
791 * MRR[2] = 2
792 * MRR[3] = 4
793 *
794 */
795 try_per_rate = sc->hw->max_rate_tries;
796
Sujith40990ec2008-12-07 21:41:37 +0530797 rate_table = sc->cur_rate_table;
Luis R. Rodriguez201c3b42009-07-14 20:14:04 -0400798 rix = ath_rc_get_highest_rix(sc, ath_rc_priv, rate_table, &is_probe);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700799 nrix = rix;
800
Sujith39008982009-01-30 14:29:15 +0530801 if (is_probe) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 /* set one try for probe rates. For the
803 * probes don't enable rts */
Sujithc89424d2009-01-30 14:29:28 +0530804 ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
Sujith39008982009-01-30 14:29:15 +0530805 1, nrix, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700807 /* Get the next tried/allowed rate. No RTS for the next series
808 * after the probe rate
809 */
Luis R. Rodriguez39448b02009-07-14 20:14:00 -0400810 ath_rc_get_lower_rix(rate_table, ath_rc_priv, rix, &nrix);
Sujithc89424d2009-01-30 14:29:28 +0530811 ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
Sujith39008982009-01-30 14:29:15 +0530812 try_per_rate, nrix, 0);
Vasanthakumar Thiagarajan14587ce2009-03-12 15:32:54 +0530813
814 tx_info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700815 } else {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816 /* Set the choosen rate. No RTS for first series entry. */
Sujithc89424d2009-01-30 14:29:28 +0530817 ath_rc_rate_set_series(rate_table, &rates[i++], txrc,
Sujith39008982009-01-30 14:29:15 +0530818 try_per_rate, nrix, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700819 }
820
821 /* Fill in the other rates for multirate retry */
Sujith39008982009-01-30 14:29:15 +0530822 for ( ; i < 4; i++) {
Luis R. Rodriguezdd190182009-07-14 20:13:56 -0400823 /* Use twice the number of tries for the last MRR segment. */
824 if (i + 1 == 4)
825 try_per_rate = 4;
826
Luis R. Rodriguez39448b02009-07-14 20:14:00 -0400827 ath_rc_get_lower_rix(rate_table, ath_rc_priv, rix, &nrix);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700828 /* All other rates in the series have RTS enabled */
Sujithc89424d2009-01-30 14:29:28 +0530829 ath_rc_rate_set_series(rate_table, &rates[i], txrc,
Luis R. Rodriguezdd190182009-07-14 20:13:56 -0400830 try_per_rate, nrix, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700831 }
832
833 /*
834 * NB:Change rate series to enable aggregation when operating
835 * at lower MCS rates. When first rate in series is MCS2
836 * in HT40 @ 2.4GHz, series should look like:
837 *
838 * {MCS2, MCS1, MCS0, MCS0}.
839 *
840 * When first rate in series is MCS3 in HT20 @ 2.4GHz, series should
841 * look like:
842 *
843 * {MCS3, MCS2, MCS1, MCS1}
844 *
845 * So, set fourth rate in series to be same as third one for
846 * above conditions.
847 */
Sujith3706de62008-12-07 21:42:10 +0530848 if ((sc->hw->conf.channel->band == IEEE80211_BAND_2GHZ) &&
Luis R. Rodriguezecf70442008-12-23 15:58:43 -0800849 (conf_is_ht(&sc->hw->conf))) {
Sujith40990ec2008-12-07 21:41:37 +0530850 u8 dot11rate = rate_table->info[rix].dot11rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700851 u8 phy = rate_table->info[rix].phy;
852 if (i == 4 &&
853 ((dot11rate == 2 && phy == WLAN_RC_PHY_HT_40_SS) ||
Sujithdc2222a2008-08-14 13:26:55 +0530854 (dot11rate == 3 && phy == WLAN_RC_PHY_HT_20_SS))) {
Sujitha8efee42008-11-18 09:07:30 +0530855 rates[3].idx = rates[2].idx;
856 rates[3].flags = rates[2].flags;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700857 }
858 }
Sujithc89424d2009-01-30 14:29:28 +0530859
860 /*
861 * Force hardware to use computed duration for next
862 * fragment by disabling multi-rate retry, which
863 * updates duration based on the multi-rate duration table.
864 *
865 * FIXME: Fix duration
866 */
Luis R. Rodriguez7682a762009-07-14 20:14:05 -0400867 if (ieee80211_has_morefrags(fc) ||
868 (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) {
Sujithc89424d2009-01-30 14:29:28 +0530869 rates[1].count = rates[2].count = rates[3].count = 0;
870 rates[1].idx = rates[2].idx = rates[3].idx = 0;
871 rates[0].count = ATH_TXMAXTRY;
872 }
873
874 /* Setup RTS/CTS */
875 ath_rc_rate_set_rtscts(sc, rate_table, tx_info);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700876}
877
Sujith2c5a7442008-11-18 09:08:33 +0530878static bool ath_rc_update_per(struct ath_softc *sc,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400879 const struct ath_rate_table *rate_table,
Sujith2c5a7442008-11-18 09:08:33 +0530880 struct ath_rate_priv *ath_rc_priv,
Felix Fietkau827e69b2009-11-15 23:09:25 +0100881 struct ieee80211_tx_info *tx_info,
Sujith2c5a7442008-11-18 09:08:33 +0530882 int tx_rate, int xretries, int retries,
883 u32 now_msec)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700884{
Sujith2c5a7442008-11-18 09:08:33 +0530885 bool state_change = false;
Felix Fietkau827e69b2009-11-15 23:09:25 +0100886 int count, n_bad_frames;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700887 u8 last_per;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700888 static u32 nretry_to_per_lookup[10] = {
889 100 * 0 / 1,
890 100 * 1 / 4,
891 100 * 1 / 2,
892 100 * 3 / 4,
893 100 * 4 / 5,
894 100 * 5 / 6,
895 100 * 6 / 7,
896 100 * 7 / 8,
897 100 * 8 / 9,
898 100 * 9 / 10
899 };
900
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400901 last_per = ath_rc_priv->per[tx_rate];
Felix Fietkau827e69b2009-11-15 23:09:25 +0100902 n_bad_frames = tx_info->status.ampdu_len - tx_info->status.ampdu_ack_len;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700903
904 if (xretries) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700905 if (xretries == 1) {
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400906 ath_rc_priv->per[tx_rate] += 30;
907 if (ath_rc_priv->per[tx_rate] > 100)
908 ath_rc_priv->per[tx_rate] = 100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700909 } else {
910 /* xretries == 2 */
Julia Lawall87c16872008-11-09 17:56:10 +0100911 count = ARRAY_SIZE(nretry_to_per_lookup);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700912 if (retries >= count)
913 retries = count - 1;
Sujith2c5a7442008-11-18 09:08:33 +0530914
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700915 /* new_PER = 7/8*old_PER + 1/8*(currentPER) */
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400916 ath_rc_priv->per[tx_rate] =
Sujith2c5a7442008-11-18 09:08:33 +0530917 (u8)(last_per - (last_per >> 3) + (100 >> 3));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700918 }
919
920 /* xretries == 1 or 2 */
921
Sujith256b77592008-11-18 09:03:12 +0530922 if (ath_rc_priv->probe_rate == tx_rate)
923 ath_rc_priv->probe_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700924
Sujith2c5a7442008-11-18 09:08:33 +0530925 } else { /* xretries == 0 */
Julia Lawall87c16872008-11-09 17:56:10 +0100926 count = ARRAY_SIZE(nretry_to_per_lookup);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700927 if (retries >= count)
928 retries = count - 1;
Sujith2c5a7442008-11-18 09:08:33 +0530929
Felix Fietkau827e69b2009-11-15 23:09:25 +0100930 if (n_bad_frames) {
Sujithdc2222a2008-08-14 13:26:55 +0530931 /* new_PER = 7/8*old_PER + 1/8*(currentPER)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700932 * Assuming that n_frames is not 0. The current PER
933 * from the retries is 100 * retries / (retries+1),
934 * since the first retries attempts failed, and the
935 * next one worked. For the one that worked,
936 * n_bad_frames subframes out of n_frames wored,
937 * so the PER for that part is
938 * 100 * n_bad_frames / n_frames, and it contributes
939 * 100 * n_bad_frames / (n_frames * (retries+1)) to
940 * the above PER. The expression below is a
941 * simplified version of the sum of these two terms.
942 */
Felix Fietkau827e69b2009-11-15 23:09:25 +0100943 if (tx_info->status.ampdu_len > 0) {
944 int n_frames, n_bad_tries;
Sujith2c5a7442008-11-18 09:08:33 +0530945 u8 cur_per, new_per;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700946
Felix Fietkau827e69b2009-11-15 23:09:25 +0100947 n_bad_tries = retries * tx_info->status.ampdu_len +
948 n_bad_frames;
949 n_frames = tx_info->status.ampdu_len * (retries + 1);
950 cur_per = (100 * n_bad_tries / n_frames) >> 3;
Sujith2c5a7442008-11-18 09:08:33 +0530951 new_per = (u8)(last_per - (last_per >> 3) + cur_per);
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400952 ath_rc_priv->per[tx_rate] = new_per;
Sujith2c5a7442008-11-18 09:08:33 +0530953 }
954 } else {
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400955 ath_rc_priv->per[tx_rate] =
Sujith2c5a7442008-11-18 09:08:33 +0530956 (u8)(last_per - (last_per >> 3) +
957 (nretry_to_per_lookup[retries] >> 3));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700958 }
959
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700960
961 /*
962 * If we got at most one retry then increase the max rate if
963 * this was a probe. Otherwise, ignore the probe.
964 */
Sujith256b77592008-11-18 09:03:12 +0530965 if (ath_rc_priv->probe_rate && ath_rc_priv->probe_rate == tx_rate) {
Felix Fietkau827e69b2009-11-15 23:09:25 +0100966 if (retries > 0 || 2 * n_bad_frames > tx_info->status.ampdu_len) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700967 /*
968 * Since we probed with just a single attempt,
969 * any retries means the probe failed. Also,
970 * if the attempt worked, but more than half
971 * the subframes were bad then also consider
972 * the probe a failure.
973 */
Sujith256b77592008-11-18 09:03:12 +0530974 ath_rc_priv->probe_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700975 } else {
976 u8 probe_rate = 0;
977
Sujith2c5a7442008-11-18 09:08:33 +0530978 ath_rc_priv->rate_max_phy =
979 ath_rc_priv->probe_rate;
Sujith256b77592008-11-18 09:03:12 +0530980 probe_rate = ath_rc_priv->probe_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700981
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400982 if (ath_rc_priv->per[probe_rate] > 30)
983 ath_rc_priv->per[probe_rate] = 20;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700984
Sujith256b77592008-11-18 09:03:12 +0530985 ath_rc_priv->probe_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700986
987 /*
988 * Since this probe succeeded, we allow the next
989 * probe twice as soon. This allows the maxRate
990 * to move up faster if the probes are
991 * succesful.
992 */
Sujith2c5a7442008-11-18 09:08:33 +0530993 ath_rc_priv->probe_time =
994 now_msec - rate_table->probe_interval / 2;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700995 }
996 }
997
998 if (retries > 0) {
999 /*
1000 * Don't update anything. We don't know if
1001 * this was because of collisions or poor signal.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001002 */
Sujith256b77592008-11-18 09:03:12 +05301003 ath_rc_priv->hw_maxretry_pktcnt = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001004 } else {
1005 /*
1006 * It worked with no retries. First ignore bogus (small)
1007 * rssi_ack values.
1008 */
Sujith256b77592008-11-18 09:03:12 +05301009 if (tx_rate == ath_rc_priv->rate_max_phy &&
1010 ath_rc_priv->hw_maxretry_pktcnt < 255) {
1011 ath_rc_priv->hw_maxretry_pktcnt++;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001012 }
1013
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001014 }
1015 }
Vasanthakumar Thiagarajan39a4caf2009-07-14 20:14:10 -04001016
Sujith2c5a7442008-11-18 09:08:33 +05301017 return state_change;
1018}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001019
Sujith2c5a7442008-11-18 09:08:33 +05301020/* Update PER, RSSI and whatever else that the code thinks it is doing.
1021 If you can make sense of all this, you really need to go out more. */
1022
1023static void ath_rc_update_ht(struct ath_softc *sc,
1024 struct ath_rate_priv *ath_rc_priv,
Felix Fietkau827e69b2009-11-15 23:09:25 +01001025 struct ieee80211_tx_info *tx_info,
Sujith2c5a7442008-11-18 09:08:33 +05301026 int tx_rate, int xretries, int retries)
1027{
Sujith2c5a7442008-11-18 09:08:33 +05301028 u32 now_msec = jiffies_to_msecs(jiffies);
1029 int rate;
1030 u8 last_per;
1031 bool state_change = false;
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -04001032 const struct ath_rate_table *rate_table = sc->cur_rate_table;
Sujith2c5a7442008-11-18 09:08:33 +05301033 int size = ath_rc_priv->rate_table_size;
1034
1035 if ((tx_rate < 0) || (tx_rate > rate_table->rate_cnt))
1036 return;
1037
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001038 last_per = ath_rc_priv->per[tx_rate];
Sujith2c5a7442008-11-18 09:08:33 +05301039
1040 /* Update PER first */
1041 state_change = ath_rc_update_per(sc, rate_table, ath_rc_priv,
Felix Fietkau827e69b2009-11-15 23:09:25 +01001042 tx_info, tx_rate, xretries,
Sujith2c5a7442008-11-18 09:08:33 +05301043 retries, now_msec);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001044
1045 /*
1046 * If this rate looks bad (high PER) then stop using it for
1047 * a while (except if we are probing).
1048 */
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001049 if (ath_rc_priv->per[tx_rate] >= 55 && tx_rate > 0 &&
Sujithdc2222a2008-08-14 13:26:55 +05301050 rate_table->info[tx_rate].ratekbps <=
Sujith256b77592008-11-18 09:03:12 +05301051 rate_table->info[ath_rc_priv->rate_max_phy].ratekbps) {
Luis R. Rodriguez39448b02009-07-14 20:14:00 -04001052 ath_rc_get_lower_rix(rate_table, ath_rc_priv,
1053 (u8)tx_rate, &ath_rc_priv->rate_max_phy);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001054
1055 /* Don't probe for a little while. */
Sujith256b77592008-11-18 09:03:12 +05301056 ath_rc_priv->probe_time = now_msec;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001057 }
1058
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001059 /* Make sure the rates below this have lower PER */
1060 /* Monotonicity is kept only for rates below the current rate. */
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001061 if (ath_rc_priv->per[tx_rate] < last_per) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001062 for (rate = tx_rate - 1; rate >= 0; rate--) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001063
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001064 if (ath_rc_priv->per[rate] >
1065 ath_rc_priv->per[rate+1]) {
1066 ath_rc_priv->per[rate] =
1067 ath_rc_priv->per[rate+1];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001068 }
1069 }
1070 }
1071
1072 /* Maintain monotonicity for rates above the current rate */
Sujith2c5a7442008-11-18 09:08:33 +05301073 for (rate = tx_rate; rate < size - 1; rate++) {
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001074 if (ath_rc_priv->per[rate+1] <
1075 ath_rc_priv->per[rate])
1076 ath_rc_priv->per[rate+1] =
1077 ath_rc_priv->per[rate];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001078 }
1079
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001080 /* Every so often, we reduce the thresholds
1081 * and PER (different for CCK and OFDM). */
Sujith256b77592008-11-18 09:03:12 +05301082 if (now_msec - ath_rc_priv->per_down_time >=
Vasanthakumar Thiagarajanc4130462009-07-14 20:14:12 -04001083 rate_table->probe_interval) {
Sujith2c5a7442008-11-18 09:08:33 +05301084 for (rate = 0; rate < size; rate++) {
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001085 ath_rc_priv->per[rate] =
1086 7 * ath_rc_priv->per[rate] / 8;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001087 }
1088
Sujith256b77592008-11-18 09:03:12 +05301089 ath_rc_priv->per_down_time = now_msec;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001090 }
Sujith2c5a7442008-11-18 09:08:33 +05301091
Sujith9e712792009-02-20 15:13:20 +05301092 ath_debug_stat_retries(sc, tx_rate, xretries, retries,
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001093 ath_rc_priv->per[tx_rate]);
Sujith029bc432009-02-04 08:10:26 +05301094
Sujith2c5a7442008-11-18 09:08:33 +05301095}
1096
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -04001097static int ath_rc_get_rateindex(const struct ath_rate_table *rate_table,
Sujith2c5a7442008-11-18 09:08:33 +05301098 struct ieee80211_tx_rate *rate)
1099{
1100 int rix;
1101
Felix Fietkau545750d2009-11-23 22:21:01 +01001102 if (!(rate->flags & IEEE80211_TX_RC_MCS))
1103 return rate->idx;
1104
1105 rix = rate->idx + rate_table->mcs_start;
Sujith2c5a7442008-11-18 09:08:33 +05301106 if ((rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
1107 (rate->flags & IEEE80211_TX_RC_SHORT_GI))
Felix Fietkau545750d2009-11-23 22:21:01 +01001108 rix = rate_table->info[rix].ht_index;
Sujith2c5a7442008-11-18 09:08:33 +05301109 else if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
Felix Fietkau545750d2009-11-23 22:21:01 +01001110 rix = rate_table->info[rix].sgi_index;
Sujith2c5a7442008-11-18 09:08:33 +05301111 else if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
Felix Fietkau545750d2009-11-23 22:21:01 +01001112 rix = rate_table->info[rix].cw40index;
Sujith2c5a7442008-11-18 09:08:33 +05301113 else
Felix Fietkau545750d2009-11-23 22:21:01 +01001114 rix = rate_table->info[rix].base_index;
Sujith2c5a7442008-11-18 09:08:33 +05301115
1116 return rix;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001117}
1118
Sujith46d14a52008-11-18 09:08:13 +05301119static void ath_rc_tx_status(struct ath_softc *sc,
1120 struct ath_rate_priv *ath_rc_priv,
1121 struct ieee80211_tx_info *tx_info,
1122 int final_ts_idx, int xretries, int long_retry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001123{
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -04001124 const struct ath_rate_table *rate_table;
Sujitha8efee42008-11-18 09:07:30 +05301125 struct ieee80211_tx_rate *rates = tx_info->status.rates;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001126 u8 flags;
Sujith2c5a7442008-11-18 09:08:33 +05301127 u32 i = 0, rix;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001128
Sujith40990ec2008-12-07 21:41:37 +05301129 rate_table = sc->cur_rate_table;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001130
1131 /*
1132 * If the first rate is not the final index, there
1133 * are intermediate rate failures to be processed.
1134 */
1135 if (final_ts_idx != 0) {
1136 /* Process intermediate rates that failed.*/
Sujith2c5a7442008-11-18 09:08:33 +05301137 for (i = 0; i < final_ts_idx ; i++) {
1138 if (rates[i].count != 0 && (rates[i].idx >= 0)) {
1139 flags = rates[i].flags;
1140
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001141 /* If HT40 and we have switched mode from
1142 * 40 to 20 => don't update */
Sujith2c5a7442008-11-18 09:08:33 +05301143
Sujitha8efee42008-11-18 09:07:30 +05301144 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
Sujithf5c38ef2009-03-30 15:28:57 +05301145 !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001146 return;
Sujithe63835b2008-11-18 09:07:53 +05301147
Sujith2c5a7442008-11-18 09:08:33 +05301148 rix = ath_rc_get_rateindex(rate_table, &rates[i]);
Felix Fietkau827e69b2009-11-15 23:09:25 +01001149 ath_rc_update_ht(sc, ath_rc_priv, tx_info,
1150 rix, xretries ? 1 : 2,
Sujith2c5a7442008-11-18 09:08:33 +05301151 rates[i].count);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001152 }
1153 }
1154 } else {
1155 /*
1156 * Handle the special case of MIMO PS burst, where the second
1157 * aggregate is sent out with only one rate and one try.
1158 * Treating it as an excessive retry penalizes the rate
1159 * inordinately.
1160 */
Sujitha8efee42008-11-18 09:07:30 +05301161 if (rates[0].count == 1 && xretries == 1)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001162 xretries = 2;
1163 }
1164
Sujith2c5a7442008-11-18 09:08:33 +05301165 flags = rates[i].flags;
1166
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001167 /* If HT40 and we have switched mode from 40 to 20 => don't update */
Sujitha8efee42008-11-18 09:07:30 +05301168 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
Sujithf5c38ef2009-03-30 15:28:57 +05301169 !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001170 return;
1171
Sujith2c5a7442008-11-18 09:08:33 +05301172 rix = ath_rc_get_rateindex(rate_table, &rates[i]);
Felix Fietkau827e69b2009-11-15 23:09:25 +01001173 ath_rc_update_ht(sc, ath_rc_priv, tx_info, rix, xretries, long_retry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001174}
1175
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -04001176static const
1177struct ath_rate_table *ath_choose_rate_table(struct ath_softc *sc,
1178 enum ieee80211_band band,
1179 bool is_ht,
1180 bool is_cw_40)
Sujithe11602b2008-11-27 09:46:27 +05301181{
1182 int mode = 0;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001183 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithe11602b2008-11-27 09:46:27 +05301184
1185 switch(band) {
1186 case IEEE80211_BAND_2GHZ:
1187 mode = ATH9K_MODE_11G;
1188 if (is_ht)
1189 mode = ATH9K_MODE_11NG_HT20;
1190 if (is_cw_40)
1191 mode = ATH9K_MODE_11NG_HT40PLUS;
1192 break;
1193 case IEEE80211_BAND_5GHZ:
1194 mode = ATH9K_MODE_11A;
1195 if (is_ht)
1196 mode = ATH9K_MODE_11NA_HT20;
1197 if (is_cw_40)
1198 mode = ATH9K_MODE_11NA_HT40PLUS;
1199 break;
1200 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001201 ath_print(common, ATH_DBG_CONFIG, "Invalid band\n");
Sujithe11602b2008-11-27 09:46:27 +05301202 return NULL;
1203 }
1204
1205 BUG_ON(mode >= ATH9K_MODE_MAX);
1206
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001207 ath_print(common, ATH_DBG_CONFIG,
1208 "Choosing rate table for mode: %d\n", mode);
Felix Fietkau545750d2009-11-23 22:21:01 +01001209
1210 sc->cur_rate_mode = mode;
1211 return hw_rate_table[mode];
Sujithe11602b2008-11-27 09:46:27 +05301212}
1213
Sujith5ddfac32008-11-18 09:06:44 +05301214static void ath_rc_init(struct ath_softc *sc,
Sujith46d14a52008-11-18 09:08:13 +05301215 struct ath_rate_priv *ath_rc_priv,
Sujith5ddfac32008-11-18 09:06:44 +05301216 struct ieee80211_supported_band *sband,
Sujith9331ec82009-03-02 13:29:45 +05301217 struct ieee80211_sta *sta,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -04001218 const struct ath_rate_table *rate_table)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001219{
Sujith5ddfac32008-11-18 09:06:44 +05301220 struct ath_rateset *rateset = &ath_rc_priv->neg_rates;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001221 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith5ddfac32008-11-18 09:06:44 +05301222 u8 *ht_mcs = (u8 *)&ath_rc_priv->neg_ht_rates;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001223 u8 i, j, k, hi = 0, hthi = 0;
Sujithe11602b2008-11-27 09:46:27 +05301224
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001225 /* Initial rate table size. Will change depending
1226 * on the working rate set */
Sujith46d14a52008-11-18 09:08:13 +05301227 ath_rc_priv->rate_table_size = RATE_TABLE_SIZE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001228
1229 /* Initialize thresholds according to the global rate table */
Sujith5ddfac32008-11-18 09:06:44 +05301230 for (i = 0 ; i < ath_rc_priv->rate_table_size; i++) {
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -04001231 ath_rc_priv->per[i] = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001232 }
1233
1234 /* Determine the valid rates */
Sujith256b77592008-11-18 09:03:12 +05301235 ath_rc_init_valid_txmask(ath_rc_priv);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001236
1237 for (i = 0; i < WLAN_RC_PHY_MAX; i++) {
1238 for (j = 0; j < MAX_TX_RATE_PHY; j++)
Sujith256b77592008-11-18 09:03:12 +05301239 ath_rc_priv->valid_phy_rateidx[i][j] = 0;
1240 ath_rc_priv->valid_phy_ratecnt[i] = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001241 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001242
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001243 if (!rateset->rs_nrates) {
1244 /* No working rate, just initialize valid rates */
Sujith2c5a7442008-11-18 09:08:33 +05301245 hi = ath_rc_init_validrates(ath_rc_priv, rate_table,
Sujithc89424d2009-01-30 14:29:28 +05301246 ath_rc_priv->ht_cap);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001247 } else {
1248 /* Use intersection of working rates and valid rates */
Sujith2c5a7442008-11-18 09:08:33 +05301249 hi = ath_rc_setvalid_rates(ath_rc_priv, rate_table,
Sujithc89424d2009-01-30 14:29:28 +05301250 rateset, ath_rc_priv->ht_cap);
Sujith5ddfac32008-11-18 09:06:44 +05301251 if (ath_rc_priv->ht_cap & WLAN_RC_HT_FLAG) {
Sujith2c5a7442008-11-18 09:08:33 +05301252 hthi = ath_rc_setvalid_htrates(ath_rc_priv,
Sujithc89424d2009-01-30 14:29:28 +05301253 rate_table,
1254 ht_mcs,
1255 ath_rc_priv->ht_cap);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001256 }
1257 hi = A_MAX(hi, hthi);
1258 }
1259
Sujith256b77592008-11-18 09:03:12 +05301260 ath_rc_priv->rate_table_size = hi + 1;
1261 ath_rc_priv->rate_max_phy = 0;
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07001262 BUG_ON(ath_rc_priv->rate_table_size > RATE_TABLE_SIZE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001263
1264 for (i = 0, k = 0; i < WLAN_RC_PHY_MAX; i++) {
Sujith256b77592008-11-18 09:03:12 +05301265 for (j = 0; j < ath_rc_priv->valid_phy_ratecnt[i]; j++) {
1266 ath_rc_priv->valid_rate_index[k++] =
1267 ath_rc_priv->valid_phy_rateidx[i][j];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001268 }
1269
Sujith46d14a52008-11-18 09:08:13 +05301270 if (!ath_rc_valid_phyrate(i, rate_table->initial_ratemax, 1)
Sujith256b77592008-11-18 09:03:12 +05301271 || !ath_rc_priv->valid_phy_ratecnt[i])
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001272 continue;
1273
Sujith256b77592008-11-18 09:03:12 +05301274 ath_rc_priv->rate_max_phy = ath_rc_priv->valid_phy_rateidx[i][j-1];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001275 }
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07001276 BUG_ON(ath_rc_priv->rate_table_size > RATE_TABLE_SIZE);
1277 BUG_ON(k > RATE_TABLE_SIZE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001278
Sujith256b77592008-11-18 09:03:12 +05301279 ath_rc_priv->max_valid_rate = k;
Sujith256b77592008-11-18 09:03:12 +05301280 ath_rc_sort_validrates(rate_table, ath_rc_priv);
1281 ath_rc_priv->rate_max_phy = ath_rc_priv->valid_rate_index[k-4];
Sujith40990ec2008-12-07 21:41:37 +05301282 sc->cur_rate_table = rate_table;
Sujith9331ec82009-03-02 13:29:45 +05301283
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001284 ath_print(common, ATH_DBG_CONFIG,
1285 "RC Initialized with capabilities: 0x%x\n",
1286 ath_rc_priv->ht_cap);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001287}
1288
Sujithc2da50e2009-03-13 08:56:11 +05301289static u8 ath_rc_build_ht_caps(struct ath_softc *sc, struct ieee80211_sta *sta,
1290 bool is_cw40, bool is_sgi40)
Sujith9331ec82009-03-02 13:29:45 +05301291{
1292 u8 caps = 0;
1293
Sujithc2da50e2009-03-13 08:56:11 +05301294 if (sta->ht_cap.ht_supported) {
Sujith9331ec82009-03-02 13:29:45 +05301295 caps = WLAN_RC_HT_FLAG;
1296 if (sc->sc_ah->caps.tx_chainmask != 1 &&
Sujithc2da50e2009-03-13 08:56:11 +05301297 ath9k_hw_getcapability(sc->sc_ah, ATH9K_CAP_DS, 0, NULL)) {
1298 if (sta->ht_cap.mcs.rx_mask[1])
1299 caps |= WLAN_RC_DS_FLAG;
1300 }
Sujith9331ec82009-03-02 13:29:45 +05301301 if (is_cw40)
1302 caps |= WLAN_RC_40_FLAG;
1303 if (is_sgi40)
1304 caps |= WLAN_RC_SGI_FLAG;
1305 }
1306
1307 return caps;
1308}
1309
1310/***********************************/
1311/* mac80211 Rate Control callbacks */
1312/***********************************/
1313
Johannes Berg4b7679a2008-09-18 18:14:18 +02001314static void ath_tx_status(void *priv, struct ieee80211_supported_band *sband,
1315 struct ieee80211_sta *sta, void *priv_sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001316 struct sk_buff *skb)
1317{
1318 struct ath_softc *sc = priv;
Sujith46d14a52008-11-18 09:08:13 +05301319 struct ath_rate_priv *ath_rc_priv = priv_sta;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001320 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1321 struct ieee80211_hdr *hdr;
Felix Fietkau827e69b2009-11-15 23:09:25 +01001322 int final_ts_idx = 0, tx_status = 0, is_underrun = 0;
1323 int long_retry = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001324 __le16 fc;
Felix Fietkau827e69b2009-11-15 23:09:25 +01001325 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001326
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001327 hdr = (struct ieee80211_hdr *)skb->data;
1328 fc = hdr->frame_control;
Felix Fietkau827e69b2009-11-15 23:09:25 +01001329 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
1330 struct ieee80211_tx_rate *rate = &tx_info->status.rates[i];
1331 if (!rate->count)
1332 break;
1333
1334 final_ts_idx = i;
1335 long_retry = rate->count - 1;
1336 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001337
Sujithff37e332008-11-24 12:07:55 +05301338 if (!priv_sta || !ieee80211_is_data(fc) ||
Felix Fietkau827e69b2009-11-15 23:09:25 +01001339 !(tx_info->pad[0] & ATH_TX_INFO_UPDATE_RC))
1340 return;
Johannes Berge6a98542008-10-21 12:40:02 +02001341
Felix Fietkau827e69b2009-11-15 23:09:25 +01001342 if (tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED)
1343 return;
Johannes Berge6a98542008-10-21 12:40:02 +02001344
Sujith46d14a52008-11-18 09:08:13 +05301345 /*
1346 * If underrun error is seen assume it as an excessive retry only
1347 * if prefetch trigger level have reached the max (0x3f for 5416)
Luis R. Rodriguezdd190182009-07-14 20:13:56 -04001348 * Adjust the long retry as if the frame was tried hw->max_rate_tries
Sujith46d14a52008-11-18 09:08:13 +05301349 * times. This affects how ratectrl updates PER for the failed rate.
1350 */
Felix Fietkau827e69b2009-11-15 23:09:25 +01001351 if ((tx_info->pad[0] & ATH_TX_INFO_UNDERRUN) &&
1352 (sc->sc_ah->tx_trig_level >= ath_rc_priv->tx_triglevel_max)) {
Sujith46d14a52008-11-18 09:08:13 +05301353 tx_status = 1;
1354 is_underrun = 1;
1355 }
1356
Felix Fietkau827e69b2009-11-15 23:09:25 +01001357 if (tx_info->pad[0] & ATH_TX_INFO_XRETRY)
Sujith46d14a52008-11-18 09:08:13 +05301358 tx_status = 1;
1359
1360 ath_rc_tx_status(sc, ath_rc_priv, tx_info, final_ts_idx, tx_status,
Felix Fietkau827e69b2009-11-15 23:09:25 +01001361 (is_underrun) ? sc->hw->max_rate_tries : long_retry);
Sujith46d14a52008-11-18 09:08:13 +05301362
Sujithd22b0022009-01-28 11:55:45 +05301363 /* Check if aggregation has to be enabled for this tid */
Vasanthakumar Thiagarajand5c232f2009-02-18 10:22:02 +05301364 if (conf_is_ht(&sc->hw->conf) &&
1365 !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
Sujithd22b0022009-01-28 11:55:45 +05301366 if (ieee80211_is_data_qos(fc)) {
1367 u8 *qc, tid;
1368 struct ath_node *an;
1369
1370 qc = ieee80211_get_qos_ctl(hdr);
1371 tid = qc[0] & 0xf;
1372 an = (struct ath_node *)sta->drv_priv;
1373
1374 if(ath_tx_aggr_check(sc, an, tid))
Johannes Bergc951ad32009-11-16 12:00:38 +01001375 ieee80211_start_tx_ba_session(sta, tid);
Sujithd22b0022009-01-28 11:55:45 +05301376 }
1377 }
Sujith7a7dec62009-01-30 14:32:09 +05301378
Felix Fietkau545750d2009-11-23 22:21:01 +01001379 ath_debug_stat_rc(sc, ath_rc_get_rateindex(sc->cur_rate_table,
1380 &tx_info->status.rates[final_ts_idx]));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001381}
1382
Johannes Berg4b7679a2008-09-18 18:14:18 +02001383static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
1384 struct ieee80211_sta *sta, void *priv_sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001385{
Johannes Berg4b7679a2008-09-18 18:14:18 +02001386 struct ath_softc *sc = priv;
Sujith46d14a52008-11-18 09:08:13 +05301387 struct ath_rate_priv *ath_rc_priv = priv_sta;
Felix Fietkau545750d2009-11-23 22:21:01 +01001388 const struct ath_rate_table *rate_table;
Sujith9331ec82009-03-02 13:29:45 +05301389 bool is_cw40, is_sgi40;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001390 int i, j = 0;
1391
Sujith7b4d2732008-11-18 09:04:00 +05301392 for (i = 0; i < sband->n_bitrates; i++) {
1393 if (sta->supp_rates[sband->band] & BIT(i)) {
1394 ath_rc_priv->neg_rates.rs_rates[j]
1395 = (sband->bitrates[i].bitrate * 2) / 10;
1396 j++;
1397 }
1398 }
1399 ath_rc_priv->neg_rates.rs_nrates = j;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001400
Sujitha4510bf2008-10-23 12:15:19 +05301401 if (sta->ht_cap.ht_supported) {
Sujith7b4d2732008-11-18 09:04:00 +05301402 for (i = 0, j = 0; i < 77; i++) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001403 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
Sujithdc2222a2008-08-14 13:26:55 +05301404 ath_rc_priv->neg_ht_rates.rs_rates[j++] = i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001405 if (j == ATH_RATE_MAX)
1406 break;
1407 }
Sujithdc2222a2008-08-14 13:26:55 +05301408 ath_rc_priv->neg_ht_rates.rs_nrates = j;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001409 }
Sujith7b4d2732008-11-18 09:04:00 +05301410
Sujith9331ec82009-03-02 13:29:45 +05301411 is_cw40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1412 is_sgi40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
1413
1414 /* Choose rate table first */
1415
1416 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) ||
Pat Erley9cb54122009-03-20 22:59:59 -04001417 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT) ||
Sujith9331ec82009-03-02 13:29:45 +05301418 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)) {
1419 rate_table = ath_choose_rate_table(sc, sband->band,
Felix Fietkau545750d2009-11-23 22:21:01 +01001420 sta->ht_cap.ht_supported, is_cw40);
1421 } else {
1422 rate_table = hw_rate_table[sc->cur_rate_mode];
Sujith9331ec82009-03-02 13:29:45 +05301423 }
1424
Sujithc2da50e2009-03-13 08:56:11 +05301425 ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta, is_cw40, is_sgi40);
Sujith9331ec82009-03-02 13:29:45 +05301426 ath_rc_init(sc, priv_sta, sband, sta, rate_table);
1427}
1428
1429static void ath_rate_update(void *priv, struct ieee80211_supported_band *sband,
1430 struct ieee80211_sta *sta, void *priv_sta,
1431 u32 changed)
1432{
1433 struct ath_softc *sc = priv;
1434 struct ath_rate_priv *ath_rc_priv = priv_sta;
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -04001435 const struct ath_rate_table *rate_table = NULL;
Sujith9331ec82009-03-02 13:29:45 +05301436 bool oper_cw40 = false, oper_sgi40;
1437 bool local_cw40 = (ath_rc_priv->ht_cap & WLAN_RC_40_FLAG) ?
1438 true : false;
1439 bool local_sgi40 = (ath_rc_priv->ht_cap & WLAN_RC_SGI_FLAG) ?
1440 true : false;
1441
1442 /* FIXME: Handle AP mode later when we support CWM */
1443
1444 if (changed & IEEE80211_RC_HT_CHANGED) {
1445 if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
1446 return;
1447
1448 if (sc->hw->conf.channel_type == NL80211_CHAN_HT40MINUS ||
1449 sc->hw->conf.channel_type == NL80211_CHAN_HT40PLUS)
1450 oper_cw40 = true;
1451
1452 oper_sgi40 = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
1453 true : false;
1454
1455 if ((local_cw40 != oper_cw40) || (local_sgi40 != oper_sgi40)) {
1456 rate_table = ath_choose_rate_table(sc, sband->band,
1457 sta->ht_cap.ht_supported,
1458 oper_cw40);
Sujithc2da50e2009-03-13 08:56:11 +05301459 ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta,
Sujith9331ec82009-03-02 13:29:45 +05301460 oper_cw40, oper_sgi40);
1461 ath_rc_init(sc, priv_sta, sband, sta, rate_table);
1462
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001463 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
1464 "Operating HT Bandwidth changed to: %d\n",
1465 sc->hw->conf.channel_type);
Felix Fietkau545750d2009-11-23 22:21:01 +01001466 sc->cur_rate_table = hw_rate_table[sc->cur_rate_mode];
Sujith9331ec82009-03-02 13:29:45 +05301467 }
1468 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001469}
1470
Johannes Berg4b7679a2008-09-18 18:14:18 +02001471static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001472{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001473 struct ath_wiphy *aphy = hw->priv;
1474 return aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001475}
1476
1477static void ath_rate_free(void *priv)
1478{
1479 return;
1480}
1481
Johannes Berg4b7679a2008-09-18 18:14:18 +02001482static void *ath_rate_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001483{
1484 struct ath_softc *sc = priv;
Sujith46d14a52008-11-18 09:08:13 +05301485 struct ath_rate_priv *rate_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001486
Sujith46d14a52008-11-18 09:08:13 +05301487 rate_priv = kzalloc(sizeof(struct ath_rate_priv), gfp);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001488 if (!rate_priv) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001489 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
1490 "Unable to allocate private rc structure\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001491 return NULL;
1492 }
Sujithfe605942008-11-18 09:03:36 +05301493
Sujith2660b812009-02-09 13:27:26 +05301494 rate_priv->tx_triglevel_max = sc->sc_ah->caps.tx_triglevel_max;
Sujithdc2222a2008-08-14 13:26:55 +05301495
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001496 return rate_priv;
1497}
1498
Johannes Berg4b7679a2008-09-18 18:14:18 +02001499static void ath_rate_free_sta(void *priv, struct ieee80211_sta *sta,
1500 void *priv_sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001501{
Sujith46d14a52008-11-18 09:08:13 +05301502 struct ath_rate_priv *rate_priv = priv_sta;
Sujithfe605942008-11-18 09:03:36 +05301503 kfree(rate_priv);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001504}
1505
1506static struct rate_control_ops ath_rate_ops = {
1507 .module = NULL,
1508 .name = "ath9k_rate_control",
1509 .tx_status = ath_tx_status,
1510 .get_rate = ath_get_rate,
1511 .rate_init = ath_rate_init,
Sujith9331ec82009-03-02 13:29:45 +05301512 .rate_update = ath_rate_update,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001513 .alloc = ath_rate_alloc,
1514 .free = ath_rate_free,
1515 .alloc_sta = ath_rate_alloc_sta,
Johannes Berg4b7679a2008-09-18 18:14:18 +02001516 .free_sta = ath_rate_free_sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001517};
1518
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001519int ath_rate_control_register(void)
1520{
1521 return ieee80211_rate_control_register(&ath_rate_ops);
1522}
1523
1524void ath_rate_control_unregister(void)
1525{
1526 ieee80211_rate_control_unregister(&ath_rate_ops);
1527}