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 * $FreeBSD$ 20 */ 21 #include "opt_ah.h" 22 23 #include "ah.h" 24 #include "ah_internal.h" 25 26 #include "ar5212/ar5212.h" 27 28 /* shorthands to compact tables for readability */ 29 #define OFDM IEEE80211_T_OFDM 30 #define CCK IEEE80211_T_CCK 31 #define TURBO IEEE80211_T_TURBO 32 #define HALF IEEE80211_T_OFDM_HALF 33 #define QUART IEEE80211_T_OFDM_QUARTER 34 35 HAL_RATE_TABLE ar5212_11a_table = { 36 8, /* number of rates */ 37 { 0 }, 38 { 39 /* short ctrl */ 40 /* valid rateCode Preamble dot11Rate Rate */ 41 /* 6 Mb */ { AH_TRUE, OFDM, 6000, 0x0b, 0x00, (0x80|12), 0 }, 42 /* 9 Mb */ { AH_TRUE, OFDM, 9000, 0x0f, 0x00, 18, 0 }, 43 /* 12 Mb */ { AH_TRUE, OFDM, 12000, 0x0a, 0x00, (0x80|24), 2 }, 44 /* 18 Mb */ { AH_TRUE, OFDM, 18000, 0x0e, 0x00, 36, 2 }, 45 /* 24 Mb */ { AH_TRUE, OFDM, 24000, 0x09, 0x00, (0x80|48), 4 }, 46 /* 36 Mb */ { AH_TRUE, OFDM, 36000, 0x0d, 0x00, 72, 4 }, 47 /* 48 Mb */ { AH_TRUE, OFDM, 48000, 0x08, 0x00, 96, 4 }, 48 /* 54 Mb */ { AH_TRUE, OFDM, 54000, 0x0c, 0x00, 108, 4 } 49 }, 50 }; 51 52 HAL_RATE_TABLE ar5212_half_table = { 53 8, /* number of rates */ 54 { 0 }, 55 { 56 /* short ctrl */ 57 /* valid rateCode Preamble dot11Rate Rate */ 58 /* 3 Mb */ { AH_TRUE, HALF, 3000, 0x0b, 0x00, (0x80|6), 0 }, 59 /* 4.5 Mb */ { AH_TRUE, HALF, 4500, 0x0f, 0x00, 9, 0 }, 60 /* 6 Mb */ { AH_TRUE, HALF, 6000, 0x0a, 0x00, (0x80|12), 2 }, 61 /* 9 Mb */ { AH_TRUE, HALF, 9000, 0x0e, 0x00, 18, 2 }, 62 /* 12 Mb */ { AH_TRUE, HALF, 12000, 0x09, 0x00, (0x80|24), 4 }, 63 /* 18 Mb */ { AH_TRUE, HALF, 18000, 0x0d, 0x00, 36, 4 }, 64 /* 24 Mb */ { AH_TRUE, HALF, 24000, 0x08, 0x00, 48, 4 }, 65 /* 27 Mb */ { AH_TRUE, HALF, 27000, 0x0c, 0x00, 54, 4 } 66 }, 67 }; 68 69 HAL_RATE_TABLE ar5212_quarter_table = { 70 8, /* number of rates */ 71 { 0 }, 72 { 73 /* short ctrl */ 74 /* valid rateCode Preamble dot11Rate Rate */ 75 /* 1.5 Mb */ { AH_TRUE, QUART, 1500, 0x0b, 0x00, (0x80|3), 0 }, 76 /* 2 Mb */ { AH_TRUE, QUART, 2250, 0x0f, 0x00, 4, 0 }, 77 /* 3 Mb */ { AH_TRUE, QUART, 3000, 0x0a, 0x00, (0x80|6), 2 }, 78 /* 4.5 Mb */ { AH_TRUE, QUART, 4500, 0x0e, 0x00, 9, 2 }, 79 /* 6 Mb */ { AH_TRUE, QUART, 6000, 0x09, 0x00, (0x80|12), 4 }, 80 /* 9 Mb */ { AH_TRUE, QUART, 9000, 0x0d, 0x00, 18, 4 }, 81 /* 12 Mb */ { AH_TRUE, QUART, 12000, 0x08, 0x00, 24, 4 }, 82 /*13.5 Mb */ { AH_TRUE, QUART, 13500, 0x0c, 0x00, 27, 4 } 83 }, 84 }; 85 86 HAL_RATE_TABLE ar5212_turbog_table = { 87 7, /* number of rates */ 88 { 0 }, 89 { 90 /* short ctrl */ 91 /* valid rateCode Preamble dot11Rate Rate */ 92 /* 6 Mb */ { AH_TRUE, TURBO, 12000, 0x0b, 0x00, (0x80|12), 0 }, 93 /* 12 Mb */ { AH_TRUE, TURBO, 24000, 0x0a, 0x00, (0x80|24), 1 }, 94 /* 18 Mb */ { AH_TRUE, TURBO, 36000, 0x0e, 0x00, 36, 1 }, 95 /* 24 Mb */ { AH_TRUE, TURBO, 48000, 0x09, 0x00, (0x80|48), 2 }, 96 /* 36 Mb */ { AH_TRUE, TURBO, 72000, 0x0d, 0x00, 72, 2 }, 97 /* 48 Mb */ { AH_TRUE, TURBO, 96000, 0x08, 0x00, 96, 2 }, 98 /* 54 Mb */ { AH_TRUE, TURBO, 108000, 0x0c, 0x00, 108, 2 } 99 }, 100 }; 101 102 HAL_RATE_TABLE ar5212_turboa_table = { 103 8, /* number of rates */ 104 { 0 }, 105 { 106 /* short ctrl */ 107 /* valid rateCode Preamble dot11Rate Rate */ 108 /* 6 Mb */ { AH_TRUE, TURBO, 12000, 0x0b, 0x00, (0x80|12), 0 }, 109 /* 9 Mb */ { AH_TRUE, TURBO, 18000, 0x0f, 0x00, 18, 0 }, 110 /* 12 Mb */ { AH_TRUE, TURBO, 24000, 0x0a, 0x00, (0x80|24), 2 }, 111 /* 18 Mb */ { AH_TRUE, TURBO, 36000, 0x0e, 0x00, 36, 2 }, 112 /* 24 Mb */ { AH_TRUE, TURBO, 48000, 0x09, 0x00, (0x80|48), 4 }, 113 /* 36 Mb */ { AH_TRUE, TURBO, 72000, 0x0d, 0x00, 72, 4 }, 114 /* 48 Mb */ { AH_TRUE, TURBO, 96000, 0x08, 0x00, 96, 4 }, 115 /* 54 Mb */ { AH_TRUE, TURBO, 108000, 0x0c, 0x00, 108, 4 } 116 }, 117 }; 118 119 HAL_RATE_TABLE ar5212_11b_table = { 120 4, /* number of rates */ 121 { 0 }, 122 { 123 /* short ctrl */ 124 /* valid rateCode Preamble dot11Rate Rate */ 125 /* 1 Mb */ { AH_TRUE, CCK, 1000, 0x1b, 0x00, (0x80| 2), 0 }, 126 /* 2 Mb */ { AH_TRUE, CCK, 2000, 0x1a, 0x04, (0x80| 4), 1 }, 127 /* 5.5 Mb */ { AH_TRUE, CCK, 5500, 0x19, 0x04, (0x80|11), 1 }, 128 /* 11 Mb */ { AH_TRUE, CCK, 11000, 0x18, 0x04, (0x80|22), 1 } 129 }, 130 }; 131 132 /* Venice TODO: roundUpRate() is broken when the rate table does not represent rates 133 * in increasing order e.g. 5.5, 11, 6, 9. 134 * An average rate of 6 Mbps will currently map to 11 Mbps. 135 */ 136 HAL_RATE_TABLE ar5212_11g_table = { 137 12, /* number of rates */ 138 { 0 }, 139 { 140 /* short ctrl */ 141 /* valid rateCode Preamble dot11Rate Rate */ 142 /* 1 Mb */ { AH_TRUE, CCK, 1000, 0x1b, 0x00, (0x80| 2), 0 }, 143 /* 2 Mb */ { AH_TRUE, CCK, 2000, 0x1a, 0x04, (0x80| 4), 1 }, 144 /* 5.5 Mb */ { AH_TRUE, CCK, 5500, 0x19, 0x04, (0x80|11), 2 }, 145 /* 11 Mb */ { AH_TRUE, CCK, 11000, 0x18, 0x04, (0x80|22), 3 }, 146 /* remove rates 6, 9 from rate ctrl */ 147 /* 6 Mb */ { AH_FALSE, OFDM, 6000, 0x0b, 0x00, 12, 4 }, 148 /* 9 Mb */ { AH_FALSE, OFDM, 9000, 0x0f, 0x00, 18, 4 }, 149 /* 12 Mb */ { AH_TRUE, OFDM, 12000, 0x0a, 0x00, 24, 6 }, 150 /* 18 Mb */ { AH_TRUE, OFDM, 18000, 0x0e, 0x00, 36, 6 }, 151 /* 24 Mb */ { AH_TRUE, OFDM, 24000, 0x09, 0x00, 48, 8 }, 152 /* 36 Mb */ { AH_TRUE, OFDM, 36000, 0x0d, 0x00, 72, 8 }, 153 /* 48 Mb */ { AH_TRUE, OFDM, 48000, 0x08, 0x00, 96, 8 }, 154 /* 54 Mb */ { AH_TRUE, OFDM, 54000, 0x0c, 0x00, 108, 8 } 155 }, 156 }; 157 158 #undef OFDM 159 #undef CCK 160 #undef TURBO 161 #undef XR 162 163 const HAL_RATE_TABLE * 164 ar5212GetRateTable(struct ath_hal *ah, u_int mode) 165 { 166 HAL_RATE_TABLE *rt; 167 switch (mode) { 168 case HAL_MODE_11A: 169 rt = &ar5212_11a_table; 170 break; 171 case HAL_MODE_11B: 172 rt = &ar5212_11b_table; 173 break; 174 case HAL_MODE_11G: 175 #ifdef notdef 176 case HAL_MODE_PUREG: 177 #endif 178 rt = &ar5212_11g_table; 179 break; 180 case HAL_MODE_108A: 181 case HAL_MODE_TURBO: 182 rt = &ar5212_turboa_table; 183 break; 184 case HAL_MODE_108G: 185 rt = &ar5212_turbog_table; 186 break; 187 case HAL_MODE_11A_HALF_RATE: 188 case HAL_MODE_11G_HALF_RATE: 189 rt = &ar5212_half_table; 190 break; 191 case HAL_MODE_11A_QUARTER_RATE: 192 case HAL_MODE_11G_QUARTER_RATE: 193 rt = &ar5212_quarter_table; 194 break; 195 default: 196 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid mode 0x%x\n", 197 __func__, mode); 198 return AH_NULL; 199 } 200 ath_hal_setupratetable(ah, rt); 201 return rt; 202 } 203