1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 
8 #include "odm_precomp.h"
9 
10 /*  Global var */
11 
12 u32 OFDMSwingTable[OFDM_TABLE_SIZE] = {
13 	0x7f8001fe, /*  0, +6.0dB */
14 	0x788001e2, /*  1, +5.5dB */
15 	0x71c001c7, /*  2, +5.0dB */
16 	0x6b8001ae, /*  3, +4.5dB */
17 	0x65400195, /*  4, +4.0dB */
18 	0x5fc0017f, /*  5, +3.5dB */
19 	0x5a400169, /*  6, +3.0dB */
20 	0x55400155, /*  7, +2.5dB */
21 	0x50800142, /*  8, +2.0dB */
22 	0x4c000130, /*  9, +1.5dB */
23 	0x47c0011f, /*  10, +1.0dB */
24 	0x43c0010f, /*  11, +0.5dB */
25 	0x40000100, /*  12, +0dB */
26 	0x3c8000f2, /*  13, -0.5dB */
27 	0x390000e4, /*  14, -1.0dB */
28 	0x35c000d7, /*  15, -1.5dB */
29 	0x32c000cb, /*  16, -2.0dB */
30 	0x300000c0, /*  17, -2.5dB */
31 	0x2d4000b5, /*  18, -3.0dB */
32 	0x2ac000ab, /*  19, -3.5dB */
33 	0x288000a2, /*  20, -4.0dB */
34 	0x26000098, /*  21, -4.5dB */
35 	0x24000090, /*  22, -5.0dB */
36 	0x22000088, /*  23, -5.5dB */
37 	0x20000080, /*  24, -6.0dB */
38 	0x1e400079, /*  25, -6.5dB */
39 	0x1c800072, /*  26, -7.0dB */
40 	0x1b00006c, /*  27. -7.5dB */
41 	0x19800066, /*  28, -8.0dB */
42 	0x18000060, /*  29, -8.5dB */
43 	0x16c0005b, /*  30, -9.0dB */
44 	0x15800056, /*  31, -9.5dB */
45 	0x14400051, /*  32, -10.0dB */
46 	0x1300004c, /*  33, -10.5dB */
47 	0x12000048, /*  34, -11.0dB */
48 	0x11000044, /*  35, -11.5dB */
49 	0x10000040, /*  36, -12.0dB */
50 };
51 
52 u8 CCKSwingTable_Ch1_Ch13[CCK_TABLE_SIZE][8] = {
53 	{0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, /*  0, +0dB */
54 	{0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /*  1, -0.5dB */
55 	{0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /*  2, -1.0dB */
56 	{0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /*  3, -1.5dB */
57 	{0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /*  4, -2.0dB */
58 	{0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /*  5, -2.5dB */
59 	{0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /*  6, -3.0dB */
60 	{0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /*  7, -3.5dB */
61 	{0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /*  8, -4.0dB */
62 	{0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /*  9, -4.5dB */
63 	{0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /*  10, -5.0dB */
64 	{0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /*  11, -5.5dB */
65 	{0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /*  12, -6.0dB <== default */
66 	{0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /*  13, -6.5dB */
67 	{0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /*  14, -7.0dB */
68 	{0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /*  15, -7.5dB */
69 	{0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /*  16, -8.0dB */
70 	{0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /*  17, -8.5dB */
71 	{0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /*  18, -9.0dB */
72 	{0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /*  19, -9.5dB */
73 	{0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /*  20, -10.0dB */
74 	{0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /*  21, -10.5dB */
75 	{0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /*  22, -11.0dB */
76 	{0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /*  23, -11.5dB */
77 	{0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /*  24, -12.0dB */
78 	{0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /*  25, -12.5dB */
79 	{0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /*  26, -13.0dB */
80 	{0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /*  27, -13.5dB */
81 	{0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /*  28, -14.0dB */
82 	{0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /*  29, -14.5dB */
83 	{0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /*  30, -15.0dB */
84 	{0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /*  31, -15.5dB */
85 	{0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}	/*  32, -16.0dB */
86 };
87 
88 u8 CCKSwingTable_Ch14[CCK_TABLE_SIZE][8] = {
89 	{0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, /*  0, +0dB */
90 	{0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /*  1, -0.5dB */
91 	{0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /*  2, -1.0dB */
92 	{0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /*  3, -1.5dB */
93 	{0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /*  4, -2.0dB */
94 	{0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /*  5, -2.5dB */
95 	{0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /*  6, -3.0dB */
96 	{0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /*  7, -3.5dB */
97 	{0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /*  8, -4.0dB */
98 	{0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /*  9, -4.5dB */
99 	{0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /*  10, -5.0dB */
100 	{0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /*  11, -5.5dB */
101 	{0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /*  12, -6.0dB  <== default */
102 	{0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /*  13, -6.5dB */
103 	{0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /*  14, -7.0dB */
104 	{0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /*  15, -7.5dB */
105 	{0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /*  16, -8.0dB */
106 	{0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /*  17, -8.5dB */
107 	{0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /*  18, -9.0dB */
108 	{0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /*  19, -9.5dB */
109 	{0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /*  20, -10.0dB */
110 	{0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /*  21, -10.5dB */
111 	{0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /*  22, -11.0dB */
112 	{0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /*  23, -11.5dB */
113 	{0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /*  24, -12.0dB */
114 	{0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /*  25, -12.5dB */
115 	{0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /*  26, -13.0dB */
116 	{0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /*  27, -13.5dB */
117 	{0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /*  28, -14.0dB */
118 	{0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /*  29, -14.5dB */
119 	{0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /*  30, -15.0dB */
120 	{0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /*  31, -15.5dB */
121 	{0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}	/*  32, -16.0dB */
122 };
123 
124 u32 OFDMSwingTable_New[OFDM_TABLE_SIZE] = {
125 	0x0b40002d, /*  0,  -15.0dB */
126 	0x0c000030, /*  1,  -14.5dB */
127 	0x0cc00033, /*  2,  -14.0dB */
128 	0x0d800036, /*  3,  -13.5dB */
129 	0x0e400039, /*  4,  -13.0dB */
130 	0x0f00003c, /*  5,  -12.5dB */
131 	0x10000040, /*  6,  -12.0dB */
132 	0x11000044, /*  7,  -11.5dB */
133 	0x12000048, /*  8,  -11.0dB */
134 	0x1300004c, /*  9,  -10.5dB */
135 	0x14400051, /*  10, -10.0dB */
136 	0x15800056, /*  11, -9.5dB */
137 	0x16c0005b, /*  12, -9.0dB */
138 	0x18000060, /*  13, -8.5dB */
139 	0x19800066, /*  14, -8.0dB */
140 	0x1b00006c, /*  15, -7.5dB */
141 	0x1c800072, /*  16, -7.0dB */
142 	0x1e400079, /*  17, -6.5dB */
143 	0x20000080, /*  18, -6.0dB */
144 	0x22000088, /*  19, -5.5dB */
145 	0x24000090, /*  20, -5.0dB */
146 	0x26000098, /*  21, -4.5dB */
147 	0x288000a2, /*  22, -4.0dB */
148 	0x2ac000ab, /*  23, -3.5dB */
149 	0x2d4000b5, /*  24, -3.0dB */
150 	0x300000c0, /*  25, -2.5dB */
151 	0x32c000cb, /*  26, -2.0dB */
152 	0x35c000d7, /*  27, -1.5dB */
153 	0x390000e4, /*  28, -1.0dB */
154 	0x3c8000f2, /*  29, -0.5dB */
155 	0x40000100, /*  30, +0dB */
156 	0x43c0010f, /*  31, +0.5dB */
157 	0x47c0011f, /*  32, +1.0dB */
158 	0x4c000130, /*  33, +1.5dB */
159 	0x50800142, /*  34, +2.0dB */
160 	0x55400155, /*  35, +2.5dB */
161 	0x5a400169, /*  36, +3.0dB */
162 	0x5fc0017f, /*  37, +3.5dB */
163 	0x65400195, /*  38, +4.0dB */
164 	0x6b8001ae, /*  39, +4.5dB */
165 	0x71c001c7, /*  40, +5.0dB */
166 	0x788001e2, /*  41, +5.5dB */
167 	0x7f8001fe  /*  42, +6.0dB */
168 };
169 
170 u8 CCKSwingTable_Ch1_Ch13_New[CCK_TABLE_SIZE][8] = {
171 	{0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /*   0, -16.0dB */
172 	{0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /*   1, -15.5dB */
173 	{0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /*   2, -15.0dB */
174 	{0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /*   3, -14.5dB */
175 	{0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /*   4, -14.0dB */
176 	{0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /*   5, -13.5dB */
177 	{0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /*   6, -13.0dB */
178 	{0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /*   7, -12.5dB */
179 	{0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /*   8, -12.0dB */
180 	{0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /*   9, -11.5dB */
181 	{0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /*  10, -11.0dB */
182 	{0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /*  11, -10.5dB */
183 	{0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /*  12, -10.0dB */
184 	{0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /*  13, -9.5dB */
185 	{0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /*  14, -9.0dB */
186 	{0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /*  15, -8.5dB */
187 	{0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /*  16, -8.0dB */
188 	{0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /*  17, -7.5dB */
189 	{0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /*  18, -7.0dB */
190 	{0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /*  19, -6.5dB */
191 	{0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /*  20, -6.0dB */
192 	{0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /*  21, -5.5dB */
193 	{0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /*  22, -5.0dB */
194 	{0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /*  23, -4.5dB */
195 	{0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /*  24, -4.0dB */
196 	{0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /*  25, -3.5dB */
197 	{0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /*  26, -3.0dB */
198 	{0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /*  27, -2.5dB */
199 	{0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /*  28, -2.0dB */
200 	{0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /*  29, -1.5dB */
201 	{0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /*  30, -1.0dB */
202 	{0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /*  31, -0.5dB */
203 	{0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}	/*  32, +0dB */
204 };
205 
206 u8 CCKSwingTable_Ch14_New[CCK_TABLE_SIZE][8] = {
207 	{0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /*   0, -16.0dB */
208 	{0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /*   1, -15.5dB */
209 	{0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /*   2, -15.0dB */
210 	{0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /*   3, -14.5dB */
211 	{0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /*   4, -14.0dB */
212 	{0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /*   5, -13.5dB */
213 	{0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /*   6, -13.0dB */
214 	{0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /*   7, -12.5dB */
215 	{0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /*   8, -12.0dB */
216 	{0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /*   9, -11.5dB */
217 	{0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /*  10, -11.0dB */
218 	{0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /*  11, -10.5dB */
219 	{0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /*  12, -10.0dB */
220 	{0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /*  13, -9.5dB */
221 	{0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /*  14, -9.0dB */
222 	{0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /*  15, -8.5dB */
223 	{0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /*  16, -8.0dB */
224 	{0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /*  17, -7.5dB */
225 	{0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /*  18, -7.0dB */
226 	{0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /*  19, -6.5dB */
227 	{0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /*  20, -6.0dB */
228 	{0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /*  21, -5.5dB */
229 	{0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /*  22, -5.0dB */
230 	{0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /*  23, -4.5dB */
231 	{0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /*  24, -4.0dB */
232 	{0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /*  25, -3.5dB */
233 	{0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /*  26, -3.0dB */
234 	{0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /*  27, -2.5dB */
235 	{0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /*  28, -2.0dB */
236 	{0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /*  29, -1.5dB */
237 	{0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /*  30, -1.0dB */
238 	{0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /*  31, -0.5dB */
239 	{0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}	/*  32, +0dB */
240 };
241 
242 u32 TxScalingTable_Jaguar[TXSCALE_TABLE_SIZE] = {
243 	0x081, /*  0,  -12.0dB */
244 	0x088, /*  1,  -11.5dB */
245 	0x090, /*  2,  -11.0dB */
246 	0x099, /*  3,  -10.5dB */
247 	0x0A2, /*  4,  -10.0dB */
248 	0x0AC, /*  5,  -9.5dB */
249 	0x0B6, /*  6,  -9.0dB */
250 	0x0C0, /*  7,  -8.5dB */
251 	0x0CC, /*  8,  -8.0dB */
252 	0x0D8, /*  9,  -7.5dB */
253 	0x0E5, /*  10, -7.0dB */
254 	0x0F2, /*  11, -6.5dB */
255 	0x101, /*  12, -6.0dB */
256 	0x110, /*  13, -5.5dB */
257 	0x120, /*  14, -5.0dB */
258 	0x131, /*  15, -4.5dB */
259 	0x143, /*  16, -4.0dB */
260 	0x156, /*  17, -3.5dB */
261 	0x16A, /*  18, -3.0dB */
262 	0x180, /*  19, -2.5dB */
263 	0x197, /*  20, -2.0dB */
264 	0x1AF, /*  21, -1.5dB */
265 	0x1C8, /*  22, -1.0dB */
266 	0x1E3, /*  23, -0.5dB */
267 	0x200, /*  24, +0  dB */
268 	0x21E, /*  25, +0.5dB */
269 	0x23E, /*  26, +1.0dB */
270 	0x261, /*  27, +1.5dB */
271 	0x285, /*  28, +2.0dB */
272 	0x2AB, /*  29, +2.5dB */
273 	0x2D3, /*  30, +3.0dB */
274 	0x2FE, /*  31, +3.5dB */
275 	0x32B, /*  32, +4.0dB */
276 	0x35C, /*  33, +4.5dB */
277 	0x38E, /*  34, +5.0dB */
278 	0x3C4, /*  35, +5.5dB */
279 	0x3FE  /*  36, +6.0dB */
280 };
281 
282 /* Remove Edca by Yu Chen */
283 
odm_CommonInfoSelfInit(struct dm_odm_t * pDM_Odm)284 static void odm_CommonInfoSelfInit(struct dm_odm_t *pDM_Odm)
285 {
286 	pDM_Odm->bCckHighPower = (bool) PHY_QueryBBReg(pDM_Odm->Adapter, ODM_REG(CCK_RPT_FORMAT, pDM_Odm), ODM_BIT(CCK_RPT_FORMAT, pDM_Odm));
287 	pDM_Odm->RFPathRxEnable = (u8) PHY_QueryBBReg(pDM_Odm->Adapter, ODM_REG(BB_RX_PATH, pDM_Odm), ODM_BIT(BB_RX_PATH, pDM_Odm));
288 
289 	pDM_Odm->TxRate = 0xFF;
290 }
291 
odm_CommonInfoSelfUpdate(struct dm_odm_t * pDM_Odm)292 static void odm_CommonInfoSelfUpdate(struct dm_odm_t *pDM_Odm)
293 {
294 	u8 EntryCnt = 0;
295 	u8 i;
296 	PSTA_INFO_T	pEntry;
297 
298 	if (*(pDM_Odm->pBandWidth) == ODM_BW40M) {
299 		if (*(pDM_Odm->pSecChOffset) == 1)
300 			pDM_Odm->ControlChannel = *(pDM_Odm->pChannel)-2;
301 		else if (*(pDM_Odm->pSecChOffset) == 2)
302 			pDM_Odm->ControlChannel = *(pDM_Odm->pChannel)+2;
303 	} else
304 		pDM_Odm->ControlChannel = *(pDM_Odm->pChannel);
305 
306 	for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
307 		pEntry = pDM_Odm->pODM_StaInfo[i];
308 		if (IS_STA_VALID(pEntry))
309 			EntryCnt++;
310 	}
311 
312 	if (EntryCnt == 1)
313 		pDM_Odm->bOneEntryOnly = true;
314 	else
315 		pDM_Odm->bOneEntryOnly = false;
316 }
317 
odm_CmnInfoInit_Debug(struct dm_odm_t * pDM_Odm)318 static void odm_CmnInfoInit_Debug(struct dm_odm_t *pDM_Odm)
319 {
320 }
321 
odm_BasicDbgMessage(struct dm_odm_t * pDM_Odm)322 static void odm_BasicDbgMessage(struct dm_odm_t *pDM_Odm)
323 {
324 }
325 
326 /* 3 ============================================================ */
327 /* 3 RATR MASK */
328 /* 3 ============================================================ */
329 /* 3 ============================================================ */
330 /* 3 Rate Adaptive */
331 /* 3 ============================================================ */
332 
odm_RateAdaptiveMaskInit(struct dm_odm_t * pDM_Odm)333 static void odm_RateAdaptiveMaskInit(struct dm_odm_t *pDM_Odm)
334 {
335 	struct odm_rate_adaptive *pOdmRA = &pDM_Odm->RateAdaptive;
336 
337 	pOdmRA->Type = DM_Type_ByDriver;
338 	if (pOdmRA->Type == DM_Type_ByDriver)
339 		pDM_Odm->bUseRAMask = true;
340 	else
341 		pDM_Odm->bUseRAMask = false;
342 
343 	pOdmRA->RATRState = DM_RATR_STA_INIT;
344 	pOdmRA->LdpcThres = 35;
345 	pOdmRA->bUseLdpc = false;
346 	pOdmRA->HighRSSIThresh = 50;
347 	pOdmRA->LowRSSIThresh = 20;
348 }
349 
ODM_Get_Rate_Bitmap(struct dm_odm_t * pDM_Odm,u32 macid,u32 ra_mask,u8 rssi_level)350 u32 ODM_Get_Rate_Bitmap(
351 	struct dm_odm_t *pDM_Odm,
352 	u32 macid,
353 	u32 ra_mask,
354 	u8 rssi_level
355 )
356 {
357 	PSTA_INFO_T	pEntry;
358 	u32 rate_bitmap = 0;
359 	u8 WirelessMode;
360 
361 	pEntry = pDM_Odm->pODM_StaInfo[macid];
362 	if (!IS_STA_VALID(pEntry))
363 		return ra_mask;
364 
365 	WirelessMode = pEntry->wireless_mode;
366 
367 	switch (WirelessMode) {
368 	case ODM_WM_B:
369 		if (ra_mask & 0x0000000c)		/* 11M or 5.5M enable */
370 			rate_bitmap = 0x0000000d;
371 		else
372 			rate_bitmap = 0x0000000f;
373 		break;
374 
375 	case (ODM_WM_G):
376 		if (rssi_level == DM_RATR_STA_HIGH)
377 			rate_bitmap = 0x00000f00;
378 		else
379 			rate_bitmap = 0x00000ff0;
380 		break;
381 
382 	case (ODM_WM_B|ODM_WM_G):
383 		if (rssi_level == DM_RATR_STA_HIGH)
384 			rate_bitmap = 0x00000f00;
385 		else if (rssi_level == DM_RATR_STA_MIDDLE)
386 			rate_bitmap = 0x00000ff0;
387 		else
388 			rate_bitmap = 0x00000ff5;
389 		break;
390 
391 	case (ODM_WM_B|ODM_WM_G|ODM_WM_N24G):
392 	case (ODM_WM_B|ODM_WM_N24G):
393 	case (ODM_WM_G|ODM_WM_N24G):
394 		if (rssi_level == DM_RATR_STA_HIGH)
395 			rate_bitmap = 0x000f0000;
396 		else if (rssi_level == DM_RATR_STA_MIDDLE)
397 			rate_bitmap = 0x000ff000;
398 		else {
399 			if (*(pDM_Odm->pBandWidth) == ODM_BW40M)
400 				rate_bitmap = 0x000ff015;
401 			else
402 				rate_bitmap = 0x000ff005;
403 		}
404 		break;
405 
406 	default:
407 		rate_bitmap = 0x0fffffff;
408 		break;
409 	}
410 
411 	return ra_mask & rate_bitmap;
412 
413 }
414 
odm_RefreshRateAdaptiveMaskCE(struct dm_odm_t * pDM_Odm)415 static void odm_RefreshRateAdaptiveMaskCE(struct dm_odm_t *pDM_Odm)
416 {
417 	u8 i;
418 	struct adapter *padapter =  pDM_Odm->Adapter;
419 
420 	if (padapter->bDriverStopped) {
421 		return;
422 	}
423 
424 	if (!pDM_Odm->bUseRAMask) {
425 		return;
426 	}
427 
428 	for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
429 		PSTA_INFO_T pstat = pDM_Odm->pODM_StaInfo[i];
430 
431 		if (IS_STA_VALID(pstat)) {
432 			if (IS_MCAST(pstat->hwaddr))  /* if (psta->mac_id == 1) */
433 				continue;
434 
435 			if (true == ODM_RAStateCheck(pDM_Odm, pstat->rssi_stat.UndecoratedSmoothedPWDB, false, &pstat->rssi_level)) {
436 				/* printk("RSSI:%d, RSSI_LEVEL:%d\n", pstat->rssi_stat.UndecoratedSmoothedPWDB, pstat->rssi_level); */
437 				rtw_hal_update_ra_mask(pstat, pstat->rssi_level);
438 			}
439 
440 		}
441 	}
442 }
443 
444 /*-----------------------------------------------------------------------------
445 * Function:	odm_RefreshRateAdaptiveMask()
446 *
447 * Overview:	Update rate table mask according to rssi
448 *
449 * Input:		NONE
450 *
451 * Output:		NONE
452 *
453 * Return:		NONE
454 *
455 * Revised History:
456 *When		Who		Remark
457 *05/27/2009	hpfan	Create Version 0.
458 *
459 * --------------------------------------------------------------------------
460 */
odm_RefreshRateAdaptiveMask(struct dm_odm_t * pDM_Odm)461 static void odm_RefreshRateAdaptiveMask(struct dm_odm_t *pDM_Odm)
462 {
463 
464 	if (!(pDM_Odm->SupportAbility & ODM_BB_RA_MASK)) {
465 		return;
466 	}
467 	odm_RefreshRateAdaptiveMaskCE(pDM_Odm);
468 }
469 
470 /*  Return Value: bool */
471 /*  - true: RATRState is changed. */
ODM_RAStateCheck(struct dm_odm_t * pDM_Odm,s32 RSSI,bool bForceUpdate,u8 * pRATRState)472 bool ODM_RAStateCheck(
473 	struct dm_odm_t *pDM_Odm,
474 	s32 RSSI,
475 	bool bForceUpdate,
476 	u8 *pRATRState
477 )
478 {
479 	struct odm_rate_adaptive *pRA = &pDM_Odm->RateAdaptive;
480 	const u8 GoUpGap = 5;
481 	u8 HighRSSIThreshForRA = pRA->HighRSSIThresh;
482 	u8 LowRSSIThreshForRA = pRA->LowRSSIThresh;
483 	u8 RATRState;
484 
485 	/*  Threshold Adjustment: */
486 	/*  when RSSI state trends to go up one or two levels, make sure RSSI is high enough. */
487 	/*  Here GoUpGap is added to solve the boundary's level alternation issue. */
488 	switch (*pRATRState) {
489 	case DM_RATR_STA_INIT:
490 	case DM_RATR_STA_HIGH:
491 		break;
492 
493 	case DM_RATR_STA_MIDDLE:
494 		HighRSSIThreshForRA += GoUpGap;
495 		break;
496 
497 	case DM_RATR_STA_LOW:
498 		HighRSSIThreshForRA += GoUpGap;
499 		LowRSSIThreshForRA += GoUpGap;
500 		break;
501 
502 	default:
503 		netdev_dbg(pDM_Odm->Adapter->pnetdev,
504 			   "wrong rssi level setting %d !", *pRATRState);
505 		break;
506 	}
507 
508 	/*  Decide RATRState by RSSI. */
509 	if (RSSI > HighRSSIThreshForRA)
510 		RATRState = DM_RATR_STA_HIGH;
511 	else if (RSSI > LowRSSIThreshForRA)
512 		RATRState = DM_RATR_STA_MIDDLE;
513 	else
514 		RATRState = DM_RATR_STA_LOW;
515 	/* printk("==>%s, RATRState:0x%02x , RSSI:%d\n", __func__, RATRState, RSSI); */
516 
517 	if (*pRATRState != RATRState || bForceUpdate) {
518 		*pRATRState = RATRState;
519 		return true;
520 	}
521 
522 	return false;
523 }
524 
525 /*  */
526 
527 /* 3 ============================================================ */
528 /* 3 RSSI Monitor */
529 /* 3 ============================================================ */
530 
odm_RSSIMonitorInit(struct dm_odm_t * pDM_Odm)531 static void odm_RSSIMonitorInit(struct dm_odm_t *pDM_Odm)
532 {
533 	struct ra_t *pRA_Table = &pDM_Odm->DM_RA_Table;
534 
535 	pRA_Table->firstconnect = false;
536 
537 }
538 
FindMinimumRSSI(struct adapter * padapter)539 static void FindMinimumRSSI(struct adapter *padapter)
540 {
541 	struct hal_com_data	*pHalData = GET_HAL_DATA(padapter);
542 	struct dm_priv *pdmpriv = &pHalData->dmpriv;
543 	struct dm_odm_t *pDM_Odm = &pHalData->odmpriv;
544 
545 	/* 1 1.Determine the minimum RSSI */
546 
547 	if (
548 		(pDM_Odm->bLinked != true) &&
549 		(pdmpriv->EntryMinUndecoratedSmoothedPWDB == 0)
550 	) {
551 		pdmpriv->MinUndecoratedPWDBForDM = 0;
552 	} else
553 		pdmpriv->MinUndecoratedPWDBForDM = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
554 }
555 
odm_RSSIMonitorCheckCE(struct dm_odm_t * pDM_Odm)556 static void odm_RSSIMonitorCheckCE(struct dm_odm_t *pDM_Odm)
557 {
558 	struct adapter *Adapter = pDM_Odm->Adapter;
559 	struct hal_com_data	*pHalData = GET_HAL_DATA(Adapter);
560 	struct dm_priv *pdmpriv = &pHalData->dmpriv;
561 	int i;
562 	int tmpEntryMaxPWDB = 0, tmpEntryMinPWDB = 0xff;
563 	u8 sta_cnt = 0;
564 	u32 PWDB_rssi[NUM_STA] = {0};/* 0~15]:MACID, [16~31]:PWDB_rssi */
565 	struct ra_t *pRA_Table = &pDM_Odm->DM_RA_Table;
566 
567 	if (pDM_Odm->bLinked != true)
568 		return;
569 
570 	pRA_Table->firstconnect = pDM_Odm->bLinked;
571 
572 	/* if (check_fwstate(&Adapter->mlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE) == true) */
573 	{
574 		struct sta_info *psta;
575 
576 		for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
577 			psta = pDM_Odm->pODM_StaInfo[i];
578 			if (IS_STA_VALID(psta)) {
579 				if (IS_MCAST(psta->hwaddr))  /* if (psta->mac_id == 1) */
580 					continue;
581 
582 				if (psta->rssi_stat.UndecoratedSmoothedPWDB == (-1))
583 					continue;
584 
585 				if (psta->rssi_stat.UndecoratedSmoothedPWDB < tmpEntryMinPWDB)
586 					tmpEntryMinPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
587 
588 				if (psta->rssi_stat.UndecoratedSmoothedPWDB > tmpEntryMaxPWDB)
589 					tmpEntryMaxPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
590 
591 				if (psta->rssi_stat.UndecoratedSmoothedPWDB != (-1))
592 					PWDB_rssi[sta_cnt++] = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16));
593 			}
594 		}
595 
596 		/* printk("%s ==> sta_cnt(%d)\n", __func__, sta_cnt); */
597 
598 		for (i = 0; i < sta_cnt; i++) {
599 			if (PWDB_rssi[i] != (0)) {
600 				if (pHalData->fw_ractrl == true)/*  Report every sta's RSSI to FW */
601 					rtl8723b_set_rssi_cmd(Adapter, (u8 *)(&PWDB_rssi[i]));
602 			}
603 		}
604 	}
605 
606 
607 
608 	if (tmpEntryMaxPWDB != 0)	/*  If associated entry is found */
609 		pdmpriv->EntryMaxUndecoratedSmoothedPWDB = tmpEntryMaxPWDB;
610 	else
611 		pdmpriv->EntryMaxUndecoratedSmoothedPWDB = 0;
612 
613 	if (tmpEntryMinPWDB != 0xff) /*  If associated entry is found */
614 		pdmpriv->EntryMinUndecoratedSmoothedPWDB = tmpEntryMinPWDB;
615 	else
616 		pdmpriv->EntryMinUndecoratedSmoothedPWDB = 0;
617 
618 	FindMinimumRSSI(Adapter);/* get pdmpriv->MinUndecoratedPWDBForDM */
619 
620 	pDM_Odm->RSSI_Min = pdmpriv->MinUndecoratedPWDBForDM;
621 	/* ODM_CmnInfoUpdate(&pHalData->odmpriv , ODM_CMNINFO_RSSI_MIN, pdmpriv->MinUndecoratedPWDBForDM); */
622 }
623 
odm_RSSIMonitorCheck(struct dm_odm_t * pDM_Odm)624 static void odm_RSSIMonitorCheck(struct dm_odm_t *pDM_Odm)
625 {
626 	if (!(pDM_Odm->SupportAbility & ODM_BB_RSSI_MONITOR))
627 		return;
628 
629 	odm_RSSIMonitorCheckCE(pDM_Odm);
630 
631 }	/*  odm_RSSIMonitorCheck */
632 
633 /* 3 ============================================================ */
634 /* 3 SW Antenna Diversity */
635 /* 3 ============================================================ */
odm_SwAntDetectInit(struct dm_odm_t * pDM_Odm)636 static void odm_SwAntDetectInit(struct dm_odm_t *pDM_Odm)
637 {
638 	struct swat_t *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
639 
640 	pDM_SWAT_Table->SWAS_NoLink_BK_Reg92c = rtw_read32(pDM_Odm->Adapter, rDPDT_control);
641 	pDM_SWAT_Table->PreAntenna = MAIN_ANT;
642 	pDM_SWAT_Table->CurAntenna = MAIN_ANT;
643 	pDM_SWAT_Table->SWAS_NoLink_State = 0;
644 }
645 
646 /* 3 ============================================================ */
647 /* 3 Tx Power Tracking */
648 /* 3 ============================================================ */
649 
getSwingIndex(struct dm_odm_t * pDM_Odm)650 static u8 getSwingIndex(struct dm_odm_t *pDM_Odm)
651 {
652 	struct adapter *Adapter = pDM_Odm->Adapter;
653 	u8 i = 0;
654 	u32 bbSwing;
655 	u32 swingTableSize;
656 	u32 *pSwingTable;
657 
658 	bbSwing = PHY_QueryBBReg(Adapter, rOFDM0_XATxIQImbalance, 0xFFC00000);
659 
660 	pSwingTable = OFDMSwingTable_New;
661 	swingTableSize = OFDM_TABLE_SIZE;
662 
663 	for (i = 0; i < swingTableSize; ++i) {
664 		u32 tableValue = pSwingTable[i];
665 
666 		if (tableValue >= 0x100000)
667 			tableValue >>= 22;
668 		if (bbSwing == tableValue)
669 			break;
670 	}
671 	return i;
672 }
673 
odm_TXPowerTrackingInit(struct dm_odm_t * pDM_Odm)674 void odm_TXPowerTrackingInit(struct dm_odm_t *pDM_Odm)
675 {
676 	u8 defaultSwingIndex = getSwingIndex(pDM_Odm);
677 	u8 p = 0;
678 	struct adapter *Adapter = pDM_Odm->Adapter;
679 	struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
680 
681 
682 	struct dm_priv *pdmpriv = &pHalData->dmpriv;
683 
684 	pdmpriv->bTXPowerTracking = true;
685 	pdmpriv->TXPowercount = 0;
686 	pdmpriv->bTXPowerTrackingInit = false;
687 
688 	if (*(pDM_Odm->mp_mode) != 1)
689 		pdmpriv->TxPowerTrackControl = true;
690 	else
691 		pdmpriv->TxPowerTrackControl = false;
692 
693 	/* pDM_Odm->RFCalibrateInfo.TxPowerTrackControl = true; */
694 	pDM_Odm->RFCalibrateInfo.ThermalValue = pHalData->EEPROMThermalMeter;
695 	pDM_Odm->RFCalibrateInfo.ThermalValue_IQK = pHalData->EEPROMThermalMeter;
696 	pDM_Odm->RFCalibrateInfo.ThermalValue_LCK = pHalData->EEPROMThermalMeter;
697 
698 	/*  The index of "0 dB" in SwingTable. */
699 	pDM_Odm->DefaultOfdmIndex = (defaultSwingIndex >= OFDM_TABLE_SIZE) ? 30 : defaultSwingIndex;
700 	pDM_Odm->DefaultCckIndex = 20;
701 
702 	pDM_Odm->BbSwingIdxCckBase = pDM_Odm->DefaultCckIndex;
703 	pDM_Odm->RFCalibrateInfo.CCK_index = pDM_Odm->DefaultCckIndex;
704 
705 	for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) {
706 		pDM_Odm->BbSwingIdxOfdmBase[p] = pDM_Odm->DefaultOfdmIndex;
707 		pDM_Odm->RFCalibrateInfo.OFDM_index[p] = pDM_Odm->DefaultOfdmIndex;
708 		pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[p] = 0;
709 		pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[p] = 0;
710 		pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0;
711 	}
712 
713 }
714 
ODM_TXPowerTrackingCheck(struct dm_odm_t * pDM_Odm)715 void ODM_TXPowerTrackingCheck(struct dm_odm_t *pDM_Odm)
716 {
717 	struct adapter *Adapter = pDM_Odm->Adapter;
718 
719 	if (!(pDM_Odm->SupportAbility & ODM_RF_TX_PWR_TRACK))
720 		return;
721 
722 	if (!pDM_Odm->RFCalibrateInfo.TM_Trigger) { /* at least delay 1 sec */
723 		PHY_SetRFReg(pDM_Odm->Adapter, RF_PATH_A, RF_T_METER_NEW, (BIT17 | BIT16), 0x03);
724 
725 		pDM_Odm->RFCalibrateInfo.TM_Trigger = 1;
726 		return;
727 	} else {
728 		ODM_TXPowerTrackingCallback_ThermalMeter(Adapter);
729 		pDM_Odm->RFCalibrateInfo.TM_Trigger = 0;
730 	}
731 }
732 
733 /*  */
734 /* 3 Export Interface */
735 /*  */
736 
737 /*  */
738 /*  2011/09/21 MH Add to describe different team necessary resource allocate?? */
739 /*  */
ODM_DMInit(struct dm_odm_t * pDM_Odm)740 void ODM_DMInit(struct dm_odm_t *pDM_Odm)
741 {
742 
743 	odm_CommonInfoSelfInit(pDM_Odm);
744 	odm_CmnInfoInit_Debug(pDM_Odm);
745 	odm_DIGInit(pDM_Odm);
746 	odm_NHMCounterStatisticsInit(pDM_Odm);
747 	odm_AdaptivityInit(pDM_Odm);
748 	odm_RateAdaptiveMaskInit(pDM_Odm);
749 	ODM_CfoTrackingInit(pDM_Odm);
750 	ODM_EdcaTurboInit(pDM_Odm);
751 	odm_RSSIMonitorInit(pDM_Odm);
752 	odm_TXPowerTrackingInit(pDM_Odm);
753 
754 	ODM_ClearTxPowerTrackingState(pDM_Odm);
755 
756 	odm_DynamicBBPowerSavingInit(pDM_Odm);
757 	odm_DynamicTxPowerInit(pDM_Odm);
758 
759 	odm_SwAntDetectInit(pDM_Odm);
760 }
761 
762 /*  */
763 /*  2011/09/20 MH This is the entry pointer for all team to execute HW out source DM. */
764 /*  You can not add any dummy function here, be care, you can only use DM structure */
765 /*  to perform any new ODM_DM. */
766 /*  */
ODM_DMWatchdog(struct dm_odm_t * pDM_Odm)767 void ODM_DMWatchdog(struct dm_odm_t *pDM_Odm)
768 {
769 	odm_CommonInfoSelfUpdate(pDM_Odm);
770 	odm_BasicDbgMessage(pDM_Odm);
771 	odm_FalseAlarmCounterStatistics(pDM_Odm);
772 	odm_NHMCounterStatistics(pDM_Odm);
773 
774 	odm_RSSIMonitorCheck(pDM_Odm);
775 
776 	/* For CE Platform(SPRD or Tablet) */
777 	/* 8723A or 8189ES platform */
778 	/* NeilChen--2012--08--24-- */
779 	/* Fix Leave LPS issue */
780 	if ((adapter_to_pwrctl(pDM_Odm->Adapter)->pwr_mode != PS_MODE_ACTIVE) /*  in LPS mode */
781 		/*  */
782 		/* (pDM_Odm->SupportICType & (ODM_RTL8723A))|| */
783 		/* (pDM_Odm->SupportICType & (ODM_RTL8188E) &&(&&(((pDM_Odm->SupportInterface  == ODM_ITRF_SDIO))) */
784 		/*  */
785 	) {
786 			odm_DIGbyRSSI_LPS(pDM_Odm);
787 	} else
788 		odm_DIG(pDM_Odm);
789 
790 	{
791 		struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable;
792 
793 		odm_Adaptivity(pDM_Odm, pDM_DigTable->CurIGValue);
794 	}
795 	odm_CCKPacketDetectionThresh(pDM_Odm);
796 
797 	if (*(pDM_Odm->pbPowerSaving) == true)
798 		return;
799 
800 
801 	odm_RefreshRateAdaptiveMask(pDM_Odm);
802 	odm_EdcaTurboCheck(pDM_Odm);
803 	ODM_CfoTracking(pDM_Odm);
804 
805 	ODM_TXPowerTrackingCheck(pDM_Odm);
806 
807 	/* odm_EdcaTurboCheck(pDM_Odm); */
808 
809 	/* 2010.05.30 LukeLee: For CE platform, files in IC subfolders may not be included to be compiled, */
810 	/*  so compile flags must be left here to prevent from compile errors */
811 	pDM_Odm->PhyDbgInfo.NumQryBeaconPkt = 0;
812 }
813 
814 
815 /*  */
816 /*  Init /.. Fixed HW value. Only init time. */
817 /*  */
ODM_CmnInfoInit(struct dm_odm_t * pDM_Odm,enum odm_cmninfo_e CmnInfo,u32 Value)818 void ODM_CmnInfoInit(struct dm_odm_t *pDM_Odm, enum odm_cmninfo_e CmnInfo, u32 Value)
819 {
820 	/*  */
821 	/*  This section is used for init value */
822 	/*  */
823 	switch (CmnInfo) {
824 	/*  */
825 	/*  Fixed ODM value. */
826 	/*  */
827 	case ODM_CMNINFO_ABILITY:
828 		pDM_Odm->SupportAbility = (u32)Value;
829 		break;
830 
831 	case ODM_CMNINFO_PLATFORM:
832 		pDM_Odm->SupportPlatform = (u8)Value;
833 		break;
834 
835 	case ODM_CMNINFO_INTERFACE:
836 		pDM_Odm->SupportInterface = (u8)Value;
837 		break;
838 
839 	case ODM_CMNINFO_IC_TYPE:
840 		pDM_Odm->SupportICType = Value;
841 		break;
842 
843 	case ODM_CMNINFO_CUT_VER:
844 		pDM_Odm->CutVersion = (u8)Value;
845 		break;
846 
847 	case ODM_CMNINFO_FAB_VER:
848 		pDM_Odm->FabVersion = (u8)Value;
849 		break;
850 
851 	case ODM_CMNINFO_RFE_TYPE:
852 		pDM_Odm->RFEType = (u8)Value;
853 		break;
854 
855 	case    ODM_CMNINFO_RF_ANTENNA_TYPE:
856 		pDM_Odm->AntDivType = (u8)Value;
857 		break;
858 
859 	case ODM_CMNINFO_PACKAGE_TYPE:
860 		pDM_Odm->PackageType = (u8)Value;
861 		break;
862 
863 	case ODM_CMNINFO_EXT_LNA:
864 		pDM_Odm->ExtLNA = (u8)Value;
865 		break;
866 
867 	case ODM_CMNINFO_EXT_PA:
868 		pDM_Odm->ExtPA = (u8)Value;
869 		break;
870 
871 	case ODM_CMNINFO_GPA:
872 		pDM_Odm->TypeGPA = (enum odm_type_gpa_e)Value;
873 		break;
874 	case ODM_CMNINFO_APA:
875 		pDM_Odm->TypeAPA = (enum odm_type_apa_e)Value;
876 		break;
877 	case ODM_CMNINFO_GLNA:
878 		pDM_Odm->TypeGLNA = (enum odm_type_glna_e)Value;
879 		break;
880 	case ODM_CMNINFO_ALNA:
881 		pDM_Odm->TypeALNA = (enum odm_type_alna_e)Value;
882 		break;
883 
884 	case ODM_CMNINFO_EXT_TRSW:
885 		pDM_Odm->ExtTRSW = (u8)Value;
886 		break;
887 	case ODM_CMNINFO_PATCH_ID:
888 		pDM_Odm->PatchID = (u8)Value;
889 		break;
890 	case ODM_CMNINFO_BINHCT_TEST:
891 		pDM_Odm->bInHctTest = (bool)Value;
892 		break;
893 	case ODM_CMNINFO_BWIFI_TEST:
894 		pDM_Odm->bWIFITest = (bool)Value;
895 		break;
896 
897 	case ODM_CMNINFO_SMART_CONCURRENT:
898 		pDM_Odm->bDualMacSmartConcurrent = (bool)Value;
899 		break;
900 
901 	/* To remove the compiler warning, must add an empty default statement to handle the other values. */
902 	default:
903 		/* do nothing */
904 		break;
905 	}
906 
907 }
908 
909 
ODM_CmnInfoHook(struct dm_odm_t * pDM_Odm,enum odm_cmninfo_e CmnInfo,void * pValue)910 void ODM_CmnInfoHook(struct dm_odm_t *pDM_Odm, enum odm_cmninfo_e CmnInfo, void *pValue)
911 {
912 	/*  */
913 	/*  Hook call by reference pointer. */
914 	/*  */
915 	switch (CmnInfo) {
916 	/*  */
917 	/*  Dynamic call by reference pointer. */
918 	/*  */
919 	case ODM_CMNINFO_MAC_PHY_MODE:
920 		pDM_Odm->pMacPhyMode = pValue;
921 		break;
922 
923 	case ODM_CMNINFO_TX_UNI:
924 		pDM_Odm->pNumTxBytesUnicast = pValue;
925 		break;
926 
927 	case ODM_CMNINFO_RX_UNI:
928 		pDM_Odm->pNumRxBytesUnicast = pValue;
929 		break;
930 
931 	case ODM_CMNINFO_WM_MODE:
932 		pDM_Odm->pwirelessmode = pValue;
933 		break;
934 
935 	case ODM_CMNINFO_SEC_CHNL_OFFSET:
936 		pDM_Odm->pSecChOffset = pValue;
937 		break;
938 
939 	case ODM_CMNINFO_SEC_MODE:
940 		pDM_Odm->pSecurity = pValue;
941 		break;
942 
943 	case ODM_CMNINFO_BW:
944 		pDM_Odm->pBandWidth = pValue;
945 		break;
946 
947 	case ODM_CMNINFO_CHNL:
948 		pDM_Odm->pChannel = pValue;
949 		break;
950 
951 	case ODM_CMNINFO_DMSP_GET_VALUE:
952 		pDM_Odm->pbGetValueFromOtherMac = pValue;
953 		break;
954 
955 	case ODM_CMNINFO_BUDDY_ADAPTOR:
956 		pDM_Odm->pBuddyAdapter = pValue;
957 		break;
958 
959 	case ODM_CMNINFO_DMSP_IS_MASTER:
960 		pDM_Odm->pbMasterOfDMSP = pValue;
961 		break;
962 
963 	case ODM_CMNINFO_SCAN:
964 		pDM_Odm->pbScanInProcess = pValue;
965 		break;
966 
967 	case ODM_CMNINFO_POWER_SAVING:
968 		pDM_Odm->pbPowerSaving = pValue;
969 		break;
970 
971 	case ODM_CMNINFO_ONE_PATH_CCA:
972 		pDM_Odm->pOnePathCCA = pValue;
973 		break;
974 
975 	case ODM_CMNINFO_DRV_STOP:
976 		pDM_Odm->pbDriverStopped =  pValue;
977 		break;
978 
979 	case ODM_CMNINFO_PNP_IN:
980 		pDM_Odm->pbDriverIsGoingToPnpSetPowerSleep =  pValue;
981 		break;
982 
983 	case ODM_CMNINFO_INIT_ON:
984 		pDM_Odm->pinit_adpt_in_progress =  pValue;
985 		break;
986 
987 	case ODM_CMNINFO_ANT_TEST:
988 		pDM_Odm->pAntennaTest =  pValue;
989 		break;
990 
991 	case ODM_CMNINFO_NET_CLOSED:
992 		pDM_Odm->pbNet_closed = pValue;
993 		break;
994 
995 	case ODM_CMNINFO_FORCED_RATE:
996 		pDM_Odm->pForcedDataRate = pValue;
997 		break;
998 
999 	case ODM_CMNINFO_FORCED_IGI_LB:
1000 		pDM_Odm->pu1ForcedIgiLb = pValue;
1001 		break;
1002 
1003 	case ODM_CMNINFO_MP_MODE:
1004 		pDM_Odm->mp_mode = pValue;
1005 		break;
1006 
1007 	/* case ODM_CMNINFO_RTSTA_AID: */
1008 	/* pDM_Odm->pAidMap =  (u8 *)pValue; */
1009 	/* break; */
1010 
1011 	/* case ODM_CMNINFO_BT_COEXIST: */
1012 	/* pDM_Odm->BTCoexist = (bool *)pValue; */
1013 
1014 	/* case ODM_CMNINFO_STA_STATUS: */
1015 	/* pDM_Odm->pODM_StaInfo[] = (PSTA_INFO_T)pValue; */
1016 	/* break; */
1017 
1018 	/* case ODM_CMNINFO_PHY_STATUS: */
1019 	/* pDM_Odm->pPhyInfo = (ODM_PHY_INFO *)pValue; */
1020 	/* break; */
1021 
1022 	/* case ODM_CMNINFO_MAC_STATUS: */
1023 	/* pDM_Odm->pMacInfo = (struct odm_mac_status_info *)pValue; */
1024 	/* break; */
1025 	/* To remove the compiler warning, must add an empty default statement to handle the other values. */
1026 	default:
1027 		/* do nothing */
1028 		break;
1029 	}
1030 
1031 }
1032 
1033 
ODM_CmnInfoPtrArrayHook(struct dm_odm_t * pDM_Odm,enum odm_cmninfo_e CmnInfo,u16 Index,void * pValue)1034 void ODM_CmnInfoPtrArrayHook(
1035 	struct dm_odm_t *pDM_Odm,
1036 	enum odm_cmninfo_e CmnInfo,
1037 	u16 Index,
1038 	void *pValue
1039 )
1040 {
1041 	/*  */
1042 	/*  Hook call by reference pointer. */
1043 	/*  */
1044 	switch (CmnInfo) {
1045 	/*  */
1046 	/*  Dynamic call by reference pointer. */
1047 	/*  */
1048 	case ODM_CMNINFO_STA_STATUS:
1049 		pDM_Odm->pODM_StaInfo[Index] = (PSTA_INFO_T)pValue;
1050 		break;
1051 	/* To remove the compiler warning, must add an empty default statement to handle the other values. */
1052 	default:
1053 		/* do nothing */
1054 		break;
1055 	}
1056 
1057 }
1058 
1059 
1060 /*  */
1061 /*  Update Band/CHannel/.. The values are dynamic but non-per-packet. */
1062 /*  */
ODM_CmnInfoUpdate(struct dm_odm_t * pDM_Odm,u32 CmnInfo,u64 Value)1063 void ODM_CmnInfoUpdate(struct dm_odm_t *pDM_Odm, u32 CmnInfo, u64 Value)
1064 {
1065 	/*  */
1066 	/*  This init variable may be changed in run time. */
1067 	/*  */
1068 	switch (CmnInfo) {
1069 	case ODM_CMNINFO_LINK_IN_PROGRESS:
1070 		pDM_Odm->bLinkInProcess = (bool)Value;
1071 		break;
1072 
1073 	case ODM_CMNINFO_ABILITY:
1074 		pDM_Odm->SupportAbility = (u32)Value;
1075 		break;
1076 
1077 	case ODM_CMNINFO_WIFI_DIRECT:
1078 		pDM_Odm->bWIFI_Direct = (bool)Value;
1079 		break;
1080 
1081 	case ODM_CMNINFO_WIFI_DISPLAY:
1082 		pDM_Odm->bWIFI_Display = (bool)Value;
1083 		break;
1084 
1085 	case ODM_CMNINFO_LINK:
1086 		pDM_Odm->bLinked = (bool)Value;
1087 		break;
1088 
1089 	case ODM_CMNINFO_STATION_STATE:
1090 		pDM_Odm->bsta_state = (bool)Value;
1091 		break;
1092 
1093 	case ODM_CMNINFO_RSSI_MIN:
1094 		pDM_Odm->RSSI_Min = (u8)Value;
1095 		break;
1096 
1097 	case ODM_CMNINFO_RA_THRESHOLD_HIGH:
1098 		pDM_Odm->RateAdaptive.HighRSSIThresh = (u8)Value;
1099 		break;
1100 
1101 	case ODM_CMNINFO_RA_THRESHOLD_LOW:
1102 		pDM_Odm->RateAdaptive.LowRSSIThresh = (u8)Value;
1103 		break;
1104 	/*  The following is for BT HS mode and BT coexist mechanism. */
1105 	case ODM_CMNINFO_BT_ENABLED:
1106 		pDM_Odm->bBtEnabled = (bool)Value;
1107 		break;
1108 
1109 	case ODM_CMNINFO_BT_HS_CONNECT_PROCESS:
1110 		pDM_Odm->bBtConnectProcess = (bool)Value;
1111 		break;
1112 
1113 	case ODM_CMNINFO_BT_HS_RSSI:
1114 		pDM_Odm->btHsRssi = (u8)Value;
1115 		break;
1116 
1117 	case ODM_CMNINFO_BT_OPERATION:
1118 		pDM_Odm->bBtHsOperation = (bool)Value;
1119 		break;
1120 
1121 	case ODM_CMNINFO_BT_LIMITED_DIG:
1122 		pDM_Odm->bBtLimitedDig = (bool)Value;
1123 		break;
1124 
1125 	case ODM_CMNINFO_BT_DISABLE_EDCA:
1126 		pDM_Odm->bBtDisableEdcaTurbo = (bool)Value;
1127 		break;
1128 
1129 /*
1130 	case	ODM_CMNINFO_OP_MODE:
1131 		pDM_Odm->OPMode = (u8)Value;
1132 		break;
1133 
1134 	case	ODM_CMNINFO_WM_MODE:
1135 		pDM_Odm->WirelessMode = (u8)Value;
1136 		break;
1137 
1138 	case	ODM_CMNINFO_SEC_CHNL_OFFSET:
1139 		pDM_Odm->SecChOffset = (u8)Value;
1140 		break;
1141 
1142 	case	ODM_CMNINFO_SEC_MODE:
1143 		pDM_Odm->Security = (u8)Value;
1144 		break;
1145 
1146 	case	ODM_CMNINFO_BW:
1147 		pDM_Odm->BandWidth = (u8)Value;
1148 		break;
1149 
1150 	case	ODM_CMNINFO_CHNL:
1151 		pDM_Odm->Channel = (u8)Value;
1152 		break;
1153 */
1154 	default:
1155 		/* do nothing */
1156 		break;
1157 	}
1158 
1159 
1160 }
1161 
1162 /* 3 ============================================================ */
1163 /* 3 DIG */
1164 /* 3 ============================================================ */
1165 /*-----------------------------------------------------------------------------
1166  * Function:	odm_DIGInit()
1167  *
1168  * Overview:	Set DIG scheme init value.
1169  *
1170  * Input:		NONE
1171  *
1172  * Output:		NONE
1173  *
1174  * Return:		NONE
1175  *
1176  * Revised History:
1177  *When		Who		Remark
1178  *
1179  *---------------------------------------------------------------------------
1180  */
1181 
1182 /* Remove DIG by yuchen */
1183 
1184 /* Remove DIG and FA check by Yu Chen */
1185 
1186 /* 3 ============================================================ */
1187 /* 3 BB Power Save */
1188 /* 3 ============================================================ */
1189 
1190 /* Remove BB power saving by Yuchen */
1191 
1192 /* 3 ============================================================ */
1193 /* 3 Dynamic Tx Power */
1194 /* 3 ============================================================ */
1195 
1196 /* Remove BY YuChen */
1197 
1198