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