1 /*- 2 * SPDX-License-Identifier: ISC 3 * 4 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting 5 * Copyright (c) 2002-2008 Atheros Communications, Inc. 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 #include "opt_ah.h" 20 21 #include "ah.h" 22 #include "ah_internal.h" 23 24 #include "ar5212/ar5212.h" 25 26 /* shorthands to compact tables for readability */ 27 #define OFDM IEEE80211_T_OFDM 28 #define CCK IEEE80211_T_CCK 29 #define TURBO IEEE80211_T_TURBO 30 #define HALF IEEE80211_T_OFDM_HALF 31 #define QUART IEEE80211_T_OFDM_QUARTER 32 33 HAL_RATE_TABLE ar5212_11a_table = { 34 8, /* number of rates */ 35 { 0 }, 36 { 37 /* short ctrl */ 38 /* valid rateCode Preamble dot11Rate Rate */ 39 /* 6 Mb */ { AH_TRUE, OFDM, 6000, 0x0b, 0x00, (0x80|12), 0 }, 40 /* 9 Mb */ { AH_TRUE, OFDM, 9000, 0x0f, 0x00, 18, 0 }, 41 /* 12 Mb */ { AH_TRUE, OFDM, 12000, 0x0a, 0x00, (0x80|24), 2 }, 42 /* 18 Mb */ { AH_TRUE, OFDM, 18000, 0x0e, 0x00, 36, 2 }, 43 /* 24 Mb */ { AH_TRUE, OFDM, 24000, 0x09, 0x00, (0x80|48), 4 }, 44 /* 36 Mb */ { AH_TRUE, OFDM, 36000, 0x0d, 0x00, 72, 4 }, 45 /* 48 Mb */ { AH_TRUE, OFDM, 48000, 0x08, 0x00, 96, 4 }, 46 /* 54 Mb */ { AH_TRUE, OFDM, 54000, 0x0c, 0x00, 108, 4 } 47 }, 48 }; 49 50 HAL_RATE_TABLE ar5212_half_table = { 51 8, /* number of rates */ 52 { 0 }, 53 { 54 /* short ctrl */ 55 /* valid rateCode Preamble dot11Rate Rate */ 56 /* 3 Mb */ { AH_TRUE, HALF, 3000, 0x0b, 0x00, (0x80|6), 0 }, 57 /* 4.5 Mb */ { AH_TRUE, HALF, 4500, 0x0f, 0x00, 9, 0 }, 58 /* 6 Mb */ { AH_TRUE, HALF, 6000, 0x0a, 0x00, (0x80|12), 2 }, 59 /* 9 Mb */ { AH_TRUE, HALF, 9000, 0x0e, 0x00, 18, 2 }, 60 /* 12 Mb */ { AH_TRUE, HALF, 12000, 0x09, 0x00, (0x80|24), 4 }, 61 /* 18 Mb */ { AH_TRUE, HALF, 18000, 0x0d, 0x00, 36, 4 }, 62 /* 24 Mb */ { AH_TRUE, HALF, 24000, 0x08, 0x00, 48, 4 }, 63 /* 27 Mb */ { AH_TRUE, HALF, 27000, 0x0c, 0x00, 54, 4 } 64 }, 65 }; 66 67 HAL_RATE_TABLE ar5212_quarter_table = { 68 8, /* number of rates */ 69 { 0 }, 70 { 71 /* short ctrl */ 72 /* valid rateCode Preamble dot11Rate Rate */ 73 /* 1.5 Mb */ { AH_TRUE, QUART, 1500, 0x0b, 0x00, (0x80|3), 0 }, 74 /* 2 Mb */ { AH_TRUE, QUART, 2250, 0x0f, 0x00, 4, 0 }, 75 /* 3 Mb */ { AH_TRUE, QUART, 3000, 0x0a, 0x00, (0x80|6), 2 }, 76 /* 4.5 Mb */ { AH_TRUE, QUART, 4500, 0x0e, 0x00, 9, 2 }, 77 /* 6 Mb */ { AH_TRUE, QUART, 6000, 0x09, 0x00, (0x80|12), 4 }, 78 /* 9 Mb */ { AH_TRUE, QUART, 9000, 0x0d, 0x00, 18, 4 }, 79 /* 12 Mb */ { AH_TRUE, QUART, 12000, 0x08, 0x00, 24, 4 }, 80 /*13.5 Mb */ { AH_TRUE, QUART, 13500, 0x0c, 0x00, 27, 4 } 81 }, 82 }; 83 84 HAL_RATE_TABLE ar5212_turbog_table = { 85 7, /* number of rates */ 86 { 0 }, 87 { 88 /* short ctrl */ 89 /* valid rateCode Preamble dot11Rate Rate */ 90 /* 6 Mb */ { AH_TRUE, TURBO, 12000, 0x0b, 0x00, (0x80|12), 0 }, 91 /* 12 Mb */ { AH_TRUE, TURBO, 24000, 0x0a, 0x00, (0x80|24), 1 }, 92 /* 18 Mb */ { AH_TRUE, TURBO, 36000, 0x0e, 0x00, 36, 1 }, 93 /* 24 Mb */ { AH_TRUE, TURBO, 48000, 0x09, 0x00, (0x80|48), 2 }, 94 /* 36 Mb */ { AH_TRUE, TURBO, 72000, 0x0d, 0x00, 72, 2 }, 95 /* 48 Mb */ { AH_TRUE, TURBO, 96000, 0x08, 0x00, 96, 2 }, 96 /* 54 Mb */ { AH_TRUE, TURBO, 108000, 0x0c, 0x00, 108, 2 } 97 }, 98 }; 99 100 HAL_RATE_TABLE ar5212_turboa_table = { 101 8, /* number of rates */ 102 { 0 }, 103 { 104 /* short ctrl */ 105 /* valid rateCode Preamble dot11Rate Rate */ 106 /* 6 Mb */ { AH_TRUE, TURBO, 12000, 0x0b, 0x00, (0x80|12), 0 }, 107 /* 9 Mb */ { AH_TRUE, TURBO, 18000, 0x0f, 0x00, 18, 0 }, 108 /* 12 Mb */ { AH_TRUE, TURBO, 24000, 0x0a, 0x00, (0x80|24), 2 }, 109 /* 18 Mb */ { AH_TRUE, TURBO, 36000, 0x0e, 0x00, 36, 2 }, 110 /* 24 Mb */ { AH_TRUE, TURBO, 48000, 0x09, 0x00, (0x80|48), 4 }, 111 /* 36 Mb */ { AH_TRUE, TURBO, 72000, 0x0d, 0x00, 72, 4 }, 112 /* 48 Mb */ { AH_TRUE, TURBO, 96000, 0x08, 0x00, 96, 4 }, 113 /* 54 Mb */ { AH_TRUE, TURBO, 108000, 0x0c, 0x00, 108, 4 } 114 }, 115 }; 116 117 HAL_RATE_TABLE ar5212_11b_table = { 118 4, /* number of rates */ 119 { 0 }, 120 { 121 /* short ctrl */ 122 /* valid rateCode Preamble dot11Rate Rate */ 123 /* 1 Mb */ { AH_TRUE, CCK, 1000, 0x1b, 0x00, (0x80| 2), 0 }, 124 /* 2 Mb */ { AH_TRUE, CCK, 2000, 0x1a, 0x04, (0x80| 4), 1 }, 125 /* 5.5 Mb */ { AH_TRUE, CCK, 5500, 0x19, 0x04, (0x80|11), 1 }, 126 /* 11 Mb */ { AH_TRUE, CCK, 11000, 0x18, 0x04, (0x80|22), 1 } 127 }, 128 }; 129 130 /* Venice TODO: roundUpRate() is broken when the rate table does not represent rates 131 * in increasing order e.g. 5.5, 11, 6, 9. 132 * An average rate of 6 Mbps will currently map to 11 Mbps. 133 */ 134 HAL_RATE_TABLE ar5212_11g_table = { 135 12, /* number of rates */ 136 { 0 }, 137 { 138 /* short ctrl */ 139 /* valid rateCode Preamble dot11Rate Rate */ 140 /* 1 Mb */ { AH_TRUE, CCK, 1000, 0x1b, 0x00, (0x80| 2), 0 }, 141 /* 2 Mb */ { AH_TRUE, CCK, 2000, 0x1a, 0x04, (0x80| 4), 1 }, 142 /* 5.5 Mb */ { AH_TRUE, CCK, 5500, 0x19, 0x04, (0x80|11), 2 }, 143 /* 11 Mb */ { AH_TRUE, CCK, 11000, 0x18, 0x04, (0x80|22), 3 }, 144 /* remove rates 6, 9 from rate ctrl */ 145 /* 6 Mb */ { AH_FALSE, OFDM, 6000, 0x0b, 0x00, 12, 4 }, 146 /* 9 Mb */ { AH_FALSE, OFDM, 9000, 0x0f, 0x00, 18, 4 }, 147 /* 12 Mb */ { AH_TRUE, OFDM, 12000, 0x0a, 0x00, 24, 6 }, 148 /* 18 Mb */ { AH_TRUE, OFDM, 18000, 0x0e, 0x00, 36, 6 }, 149 /* 24 Mb */ { AH_TRUE, OFDM, 24000, 0x09, 0x00, 48, 8 }, 150 /* 36 Mb */ { AH_TRUE, OFDM, 36000, 0x0d, 0x00, 72, 8 }, 151 /* 48 Mb */ { AH_TRUE, OFDM, 48000, 0x08, 0x00, 96, 8 }, 152 /* 54 Mb */ { AH_TRUE, OFDM, 54000, 0x0c, 0x00, 108, 8 } 153 }, 154 }; 155 156 #undef OFDM 157 #undef CCK 158 #undef TURBO 159 #undef XR 160 161 const HAL_RATE_TABLE * 162 ar5212GetRateTable(struct ath_hal *ah, u_int mode) 163 { 164 HAL_RATE_TABLE *rt; 165 switch (mode) { 166 case HAL_MODE_11A: 167 rt = &ar5212_11a_table; 168 break; 169 case HAL_MODE_11B: 170 rt = &ar5212_11b_table; 171 break; 172 case HAL_MODE_11G: 173 #ifdef notdef 174 case HAL_MODE_PUREG: 175 #endif 176 rt = &ar5212_11g_table; 177 break; 178 case HAL_MODE_108A: 179 case HAL_MODE_TURBO: 180 rt = &ar5212_turboa_table; 181 break; 182 case HAL_MODE_108G: 183 rt = &ar5212_turbog_table; 184 break; 185 case HAL_MODE_11A_HALF_RATE: 186 case HAL_MODE_11G_HALF_RATE: 187 rt = &ar5212_half_table; 188 break; 189 case HAL_MODE_11A_QUARTER_RATE: 190 case HAL_MODE_11G_QUARTER_RATE: 191 rt = &ar5212_quarter_table; 192 break; 193 default: 194 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid mode 0x%x\n", 195 __func__, mode); 196 return AH_NULL; 197 } 198 ath_hal_setupratetable(ah, rt); 199 return rt; 200 } 201