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