1185377Ssam/*
2185377Ssam * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3185377Ssam * Copyright (c) 2002-2006 Atheros Communications, Inc.
4185377Ssam *
5185377Ssam * Permission to use, copy, modify, and/or distribute this software for any
6185377Ssam * purpose with or without fee is hereby granted, provided that the above
7185377Ssam * copyright notice and this permission notice appear in all copies.
8185377Ssam *
9185377Ssam * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10185377Ssam * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11185377Ssam * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12185377Ssam * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13185377Ssam * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14185377Ssam * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15185377Ssam * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16185377Ssam *
17191022Ssam * $FreeBSD$
18185377Ssam */
19185377Ssam#include "opt_ah.h"
20185377Ssam
21185377Ssam#include "ah.h"
22185377Ssam#include "ah_internal.h"
23185377Ssam
24185377Ssam#include "ar5211/ar5211.h"
25185377Ssam
26185377Ssam/* shorthands to compact tables for readability */
27185377Ssam#define	OFDM	IEEE80211_T_OFDM
28185377Ssam#define	CCK	IEEE80211_T_CCK
29185377Ssam#define	TURBO	IEEE80211_T_TURBO
30185377Ssam
31185377SsamHAL_RATE_TABLE ar5211_11a_table = {
32185377Ssam	8,  /* number of rates */
33185377Ssam	{ 0 },
34185377Ssam	{
35185377Ssam/*                                                  short            ctrl  */
36185377Ssam/*                valid                 rateCode Preamble  dot11Rate Rate */
37185377Ssam/*   6 Mb */ {  AH_TRUE, OFDM,    6000,     0x0b,    0x00, (0x80|12),   0 },
38185377Ssam/*   9 Mb */ {  AH_TRUE, OFDM,    9000,     0x0f,    0x00,        18,   0 },
39185377Ssam/*  12 Mb */ {  AH_TRUE, OFDM,   12000,     0x0a,    0x00, (0x80|24),   2 },
40185377Ssam/*  18 Mb */ {  AH_TRUE, OFDM,   18000,     0x0e,    0x00,        36,   2 },
41185377Ssam/*  24 Mb */ {  AH_TRUE, OFDM,   24000,     0x09,    0x00, (0x80|48),   4 },
42185377Ssam/*  36 Mb */ {  AH_TRUE, OFDM,   36000,     0x0d,    0x00,        72,   4 },
43185377Ssam/*  48 Mb */ {  AH_TRUE, OFDM,   48000,     0x08,    0x00,        96,   4 },
44185377Ssam/*  54 Mb */ {  AH_TRUE, OFDM,   54000,     0x0c,    0x00,       108,   4 }
45185377Ssam	},
46185377Ssam};
47185377Ssam
48185377SsamHAL_RATE_TABLE ar5211_turbo_table = {
49185377Ssam	8,  /* number of rates */
50185377Ssam	{ 0 },
51185377Ssam	{
52185377Ssam/*                                                 short            ctrl  */
53185377Ssam/*                valid                rateCode Preamble  dot11Rate Rate */
54191022Ssam/*   6 Mb */ {  AH_TRUE, TURBO,  12000,    0x0b,    0x00, (0x80|12),   0 },
55191022Ssam/*   9 Mb */ {  AH_TRUE, TURBO,  18000,    0x0f,    0x00,        18,   0 },
56191022Ssam/*  12 Mb */ {  AH_TRUE, TURBO,  24000,    0x0a,    0x00, (0x80|24),   2 },
57191022Ssam/*  18 Mb */ {  AH_TRUE, TURBO,  36000,    0x0e,    0x00,        36,   2 },
58191022Ssam/*  24 Mb */ {  AH_TRUE, TURBO,  48000,    0x09,    0x00, (0x80|48),   4 },
59191022Ssam/*  36 Mb */ {  AH_TRUE, TURBO,  72000,    0x0d,    0x00,        72,   4 },
60191022Ssam/*  48 Mb */ {  AH_TRUE, TURBO,  96000,    0x08,    0x00,        96,   4 },
61191022Ssam/*  54 Mb */ {  AH_TRUE, TURBO, 108000,    0x0c,    0x00,       108,   4 }
62185377Ssam	},
63185377Ssam};
64185377Ssam
65185377SsamHAL_RATE_TABLE ar5211_11b_table = {
66185377Ssam	4,  /* number of rates */
67185377Ssam	{ 0 },
68185377Ssam	{
69185377Ssam/*                                                 short            ctrl  */
70185377Ssam/*                valid                rateCode Preamble  dot11Rate Rate */
71185377Ssam/*   1 Mb */ {  AH_TRUE,  CCK,    1000,    0x0b,    0x00, (0x80| 2),   0 },
72185377Ssam/*   2 Mb */ {  AH_TRUE,  CCK,    2000,    0x0a,    0x04, (0x80| 4),   1 },
73185377Ssam/* 5.5 Mb */ {  AH_TRUE,  CCK,    5500,    0x09,    0x04, (0x80|11),   1 },
74185377Ssam/*  11 Mb */ {  AH_TRUE,  CCK,   11000,    0x08,    0x04, (0x80|22),   1 }
75185377Ssam	},
76185377Ssam};
77185377Ssam
78185377Ssam#undef	OFDM
79185377Ssam#undef	CCK
80185377Ssam#undef	TURBO
81185377Ssam
82185377Ssam
83185377Ssamconst HAL_RATE_TABLE *
84185377Ssamar5211GetRateTable(struct ath_hal *ah, u_int mode)
85185377Ssam{
86185377Ssam	HAL_RATE_TABLE *rt;
87185377Ssam	switch (mode) {
88185377Ssam	case HAL_MODE_11A:
89185377Ssam		rt = &ar5211_11a_table;
90185377Ssam		break;
91185377Ssam	case HAL_MODE_11B:
92185377Ssam		rt = &ar5211_11b_table;
93185377Ssam		break;
94185377Ssam	case HAL_MODE_TURBO:
95185377Ssam		rt =  &ar5211_turbo_table;
96185377Ssam		break;
97185377Ssam	default:
98185377Ssam		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid mode 0x%x\n",
99185377Ssam		    __func__, mode);
100185377Ssam		return AH_NULL;
101185377Ssam	}
102185377Ssam	ath_hal_setupratetable(ah, rt);
103185377Ssam	return rt;
104185377Ssam}
105