xref: /freebsd/sys/dev/ath/ath_hal/ar5212/ar5212_phy.c (revision d2ce15bd43b3a1dcce08eecbff8d5d359946d972)
1 /*
2  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3  * Copyright (c) 2002-2008 Atheros Communications, Inc.
4  *
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  * $FreeBSD$
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 
131 /* Venice TODO: roundUpRate() is broken when the rate table does not represent rates
132  * in increasing order  e.g.  5.5, 11, 6, 9.
133  * An average rate of 6 Mbps will currently map to 11 Mbps.
134  */
135 HAL_RATE_TABLE ar5212_11g_table = {
136 	12,  /* number of rates */
137 	{ 0 },
138 	{
139 /*                                                 short            ctrl  */
140 /*                valid                rateCode Preamble  dot11Rate Rate */
141 /*   1 Mb */ {  AH_TRUE, CCK,     1000,    0x1b,    0x00, (0x80| 2),   0 },
142 /*   2 Mb */ {  AH_TRUE, CCK,     2000,    0x1a,    0x04, (0x80| 4),   1 },
143 /* 5.5 Mb */ {  AH_TRUE, CCK,     5500,    0x19,    0x04, (0x80|11),   2 },
144 /*  11 Mb */ {  AH_TRUE, CCK,    11000,    0x18,    0x04, (0x80|22),   3 },
145 /* remove rates 6, 9 from rate ctrl */
146 /*   6 Mb */ { AH_FALSE, OFDM,    6000,    0x0b,    0x00,        12,   4 },
147 /*   9 Mb */ { AH_FALSE, OFDM,    9000,    0x0f,    0x00,        18,   4 },
148 /*  12 Mb */ {  AH_TRUE, OFDM,   12000,    0x0a,    0x00,        24,   6 },
149 /*  18 Mb */ {  AH_TRUE, OFDM,   18000,    0x0e,    0x00,        36,   6 },
150 /*  24 Mb */ {  AH_TRUE, OFDM,   24000,    0x09,    0x00,        48,   8 },
151 /*  36 Mb */ {  AH_TRUE, OFDM,   36000,    0x0d,    0x00,        72,   8 },
152 /*  48 Mb */ {  AH_TRUE, OFDM,   48000,    0x08,    0x00,        96,   8 },
153 /*  54 Mb */ {  AH_TRUE, OFDM,   54000,    0x0c,    0x00,       108,   8 }
154 	},
155 };
156 
157 #undef	OFDM
158 #undef	CCK
159 #undef	TURBO
160 #undef	XR
161 
162 const HAL_RATE_TABLE *
163 ar5212GetRateTable(struct ath_hal *ah, u_int mode)
164 {
165 	HAL_RATE_TABLE *rt;
166 	switch (mode) {
167 	case HAL_MODE_11A:
168 		rt = &ar5212_11a_table;
169 		break;
170 	case HAL_MODE_11B:
171 		rt = &ar5212_11b_table;
172 		break;
173 	case HAL_MODE_11G:
174 #ifdef notdef
175 	case HAL_MODE_PUREG:
176 #endif
177 		rt =  &ar5212_11g_table;
178 		break;
179 	case HAL_MODE_108A:
180 	case HAL_MODE_TURBO:
181 		rt =  &ar5212_turboa_table;
182 		break;
183 	case HAL_MODE_108G:
184 		rt =  &ar5212_turbog_table;
185 		break;
186 	case HAL_MODE_11A_HALF_RATE:
187 	case HAL_MODE_11G_HALF_RATE:
188 		rt = &ar5212_half_table;
189 		break;
190 	case HAL_MODE_11A_QUARTER_RATE:
191 	case HAL_MODE_11G_QUARTER_RATE:
192 		rt = &ar5212_quarter_table;
193 		break;
194 	default:
195 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid mode 0x%x\n",
196 		    __func__, mode);
197 		return AH_NULL;
198 	}
199 	ath_hal_setupratetable(ah, rt);
200 	return rt;
201 }
202