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