1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3
4 #include "../include/odm_precomp.h"
5 #include "../include/rtw_iol.h"
6
Checkcondition(const u32 condition,const u32 hex)7 static bool Checkcondition(const u32 condition, const u32 hex)
8 {
9 u32 _board = (hex & 0x000000FF);
10 u32 _interface = (hex & 0x0000FF00) >> 8;
11 u32 _platform = (hex & 0x00FF0000) >> 16;
12 u32 cond = condition;
13
14 if (condition == 0xCDCDCDCD)
15 return true;
16
17 cond = condition & 0x000000FF;
18 if ((_board == cond) && cond != 0x00)
19 return false;
20
21 cond = condition & 0x0000FF00;
22 cond = cond >> 8;
23 if ((_interface & cond) == 0 && cond != 0x07)
24 return false;
25
26 cond = condition & 0x00FF0000;
27 cond = cond >> 16;
28 if ((_platform & cond) == 0 && cond != 0x0F)
29 return false;
30 return true;
31 }
32
33 /******************************************************************************
34 * MAC_REG.TXT
35 ******************************************************************************/
36
37 static u32 array_MAC_REG_8188E[] = {
38 0x026, 0x00000041,
39 0x027, 0x00000035,
40 0x428, 0x0000000A,
41 0x429, 0x00000010,
42 0x430, 0x00000000,
43 0x431, 0x00000001,
44 0x432, 0x00000002,
45 0x433, 0x00000004,
46 0x434, 0x00000005,
47 0x435, 0x00000006,
48 0x436, 0x00000007,
49 0x437, 0x00000008,
50 0x438, 0x00000000,
51 0x439, 0x00000000,
52 0x43A, 0x00000001,
53 0x43B, 0x00000002,
54 0x43C, 0x00000004,
55 0x43D, 0x00000005,
56 0x43E, 0x00000006,
57 0x43F, 0x00000007,
58 0x440, 0x0000005D,
59 0x441, 0x00000001,
60 0x442, 0x00000000,
61 0x444, 0x00000015,
62 0x445, 0x000000F0,
63 0x446, 0x0000000F,
64 0x447, 0x00000000,
65 0x458, 0x00000041,
66 0x459, 0x000000A8,
67 0x45A, 0x00000072,
68 0x45B, 0x000000B9,
69 0x460, 0x00000066,
70 0x461, 0x00000066,
71 0x480, 0x00000008,
72 0x4C8, 0x000000FF,
73 0x4C9, 0x00000008,
74 0x4CC, 0x000000FF,
75 0x4CD, 0x000000FF,
76 0x4CE, 0x00000001,
77 0x4D3, 0x00000001,
78 0x500, 0x00000026,
79 0x501, 0x000000A2,
80 0x502, 0x0000002F,
81 0x503, 0x00000000,
82 0x504, 0x00000028,
83 0x505, 0x000000A3,
84 0x506, 0x0000005E,
85 0x507, 0x00000000,
86 0x508, 0x0000002B,
87 0x509, 0x000000A4,
88 0x50A, 0x0000005E,
89 0x50B, 0x00000000,
90 0x50C, 0x0000004F,
91 0x50D, 0x000000A4,
92 0x50E, 0x00000000,
93 0x50F, 0x00000000,
94 0x512, 0x0000001C,
95 0x514, 0x0000000A,
96 0x516, 0x0000000A,
97 0x525, 0x0000004F,
98 0x550, 0x00000010,
99 0x551, 0x00000010,
100 0x559, 0x00000002,
101 0x55D, 0x000000FF,
102 0x605, 0x00000030,
103 0x608, 0x0000000E,
104 0x609, 0x0000002A,
105 0x620, 0x000000FF,
106 0x621, 0x000000FF,
107 0x622, 0x000000FF,
108 0x623, 0x000000FF,
109 0x624, 0x000000FF,
110 0x625, 0x000000FF,
111 0x626, 0x000000FF,
112 0x627, 0x000000FF,
113 0x652, 0x00000020,
114 0x63C, 0x0000000A,
115 0x63D, 0x0000000A,
116 0x63E, 0x0000000E,
117 0x63F, 0x0000000E,
118 0x640, 0x00000040,
119 0x66E, 0x00000005,
120 0x700, 0x00000021,
121 0x701, 0x00000043,
122 0x702, 0x00000065,
123 0x703, 0x00000087,
124 0x708, 0x00000021,
125 0x709, 0x00000043,
126 0x70A, 0x00000065,
127 0x70B, 0x00000087,
128 };
129
ODM_ReadAndConfig_MAC_REG_8188E(struct odm_dm_struct * dm_odm)130 enum HAL_STATUS ODM_ReadAndConfig_MAC_REG_8188E(struct odm_dm_struct *dm_odm)
131 {
132 #define READ_NEXT_PAIR(v1, v2, i) do { i += 2; v1 = array[i]; v2 = array[i + 1]; } while (0)
133
134 u32 hex = 0;
135 u32 i;
136 u8 platform = dm_odm->SupportPlatform;
137 u8 interface_val = dm_odm->SupportInterface;
138 u8 board = dm_odm->BoardType;
139 u32 array_len = sizeof(array_MAC_REG_8188E) / sizeof(u32);
140 u32 *array = array_MAC_REG_8188E;
141 bool biol = false;
142
143 struct adapter *adapt = dm_odm->Adapter;
144 struct xmit_frame *pxmit_frame = NULL;
145 u8 bndy_cnt = 1;
146 enum HAL_STATUS rst = HAL_STATUS_SUCCESS;
147 hex += board;
148 hex += interface_val << 8;
149 hex += platform << 16;
150 hex += 0xFF000000;
151
152 biol = rtw_IOL_applied(adapt);
153
154 if (biol) {
155 pxmit_frame = rtw_IOL_accquire_xmit_frame(adapt);
156 if (!pxmit_frame) {
157 pr_info("rtw_IOL_accquire_xmit_frame failed\n");
158 return HAL_STATUS_FAILURE;
159 }
160 }
161
162 for (i = 0; i < array_len; i += 2) {
163 u32 v1 = array[i];
164 u32 v2 = array[i + 1];
165
166 /* This (offset, data) pair meets the condition. */
167 if (v1 < 0xCDCDCDCD) {
168 if (biol) {
169 if (rtw_IOL_cmd_boundary_handle(pxmit_frame))
170 bndy_cnt++;
171 rtw_IOL_append_WB_cmd(pxmit_frame, (u16)v1, (u8)v2, 0xFF);
172 } else {
173 odm_ConfigMAC_8188E(dm_odm, v1, (u8)v2);
174 }
175 continue;
176 } else { /* This line is the start line of branch. */
177 if (!Checkcondition(array[i], hex)) {
178 /* Discard the following (offset, data) pairs. */
179 READ_NEXT_PAIR(v1, v2, i);
180 while (v2 != 0xDEAD &&
181 v2 != 0xCDEF &&
182 v2 != 0xCDCD && i < array_len - 2) {
183 READ_NEXT_PAIR(v1, v2, i);
184 }
185 i -= 2; /* prevent from for-loop += 2 */
186 } else { /* Configure matched pairs and skip to end of if-else. */
187 READ_NEXT_PAIR(v1, v2, i);
188 while (v2 != 0xDEAD &&
189 v2 != 0xCDEF &&
190 v2 != 0xCDCD && i < array_len - 2) {
191 if (biol) {
192 if (rtw_IOL_cmd_boundary_handle(pxmit_frame))
193 bndy_cnt++;
194 rtw_IOL_append_WB_cmd(pxmit_frame, (u16)v1, (u8)v2, 0xFF);
195 } else {
196 odm_ConfigMAC_8188E(dm_odm, v1, (u8)v2);
197 }
198
199 READ_NEXT_PAIR(v1, v2, i);
200 }
201 while (v2 != 0xDEAD && i < array_len - 2)
202 READ_NEXT_PAIR(v1, v2, i);
203 }
204 }
205 }
206 if (biol) {
207 if (!rtw_IOL_exec_cmds_sync(dm_odm->Adapter, pxmit_frame, 1000, bndy_cnt)) {
208 pr_info("~~~ MAC IOL_exec_cmds Failed !!!\n");
209 rst = HAL_STATUS_FAILURE;
210 }
211 }
212 return rst;
213 }
214