linux/drivers/staging/rtl8723bs/hal/hal_intf.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/******************************************************************************
   3 *
   4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
   5 *
   6 ******************************************************************************/
   7
   8#define _HAL_INTF_C_
   9
  10#include <drv_types.h>
  11#include <rtw_debug.h>
  12#include <hal_data.h>
  13
  14void rtw_hal_chip_configure(struct adapter *padapter)
  15{
  16        if (padapter->HalFunc.intf_chip_configure)
  17                padapter->HalFunc.intf_chip_configure(padapter);
  18}
  19
  20void rtw_hal_read_chip_info(struct adapter *padapter)
  21{
  22        if (padapter->HalFunc.read_adapter_info)
  23                padapter->HalFunc.read_adapter_info(padapter);
  24}
  25
  26void rtw_hal_read_chip_version(struct adapter *padapter)
  27{
  28        if (padapter->HalFunc.read_chip_version)
  29                padapter->HalFunc.read_chip_version(padapter);
  30}
  31
  32void rtw_hal_def_value_init(struct adapter *padapter)
  33{
  34        if (is_primary_adapter(padapter))
  35                if (padapter->HalFunc.init_default_value)
  36                        padapter->HalFunc.init_default_value(padapter);
  37}
  38
  39void rtw_hal_free_data(struct adapter *padapter)
  40{
  41        /* free HAL Data */
  42        rtw_hal_data_deinit(padapter);
  43
  44        if (is_primary_adapter(padapter))
  45                if (padapter->HalFunc.free_hal_data)
  46                        padapter->HalFunc.free_hal_data(padapter);
  47}
  48
  49void rtw_hal_dm_init(struct adapter *padapter)
  50{
  51        if (is_primary_adapter(padapter))
  52                if (padapter->HalFunc.dm_init)
  53                        padapter->HalFunc.dm_init(padapter);
  54}
  55
  56void rtw_hal_dm_deinit(struct adapter *padapter)
  57{
  58        /*  cancel dm  timer */
  59        if (is_primary_adapter(padapter))
  60                if (padapter->HalFunc.dm_deinit)
  61                        padapter->HalFunc.dm_deinit(padapter);
  62}
  63
  64static void rtw_hal_init_opmode(struct adapter *padapter)
  65{
  66        enum NDIS_802_11_NETWORK_INFRASTRUCTURE networkType = Ndis802_11InfrastructureMax;
  67        struct  mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  68        sint fw_state;
  69
  70        fw_state = get_fwstate(pmlmepriv);
  71
  72        if (fw_state & WIFI_ADHOC_STATE)
  73                networkType = Ndis802_11IBSS;
  74        else if (fw_state & WIFI_STATION_STATE)
  75                networkType = Ndis802_11Infrastructure;
  76        else if (fw_state & WIFI_AP_STATE)
  77                networkType = Ndis802_11APMode;
  78        else
  79                return;
  80
  81        rtw_setopmode_cmd(padapter, networkType, false);
  82}
  83
  84uint rtw_hal_init(struct adapter *padapter)
  85{
  86        uint status;
  87        struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  88
  89        status = padapter->HalFunc.hal_init(padapter);
  90
  91        if (status == _SUCCESS) {
  92                rtw_hal_init_opmode(padapter);
  93
  94                dvobj->padapters->hw_init_completed = true;
  95
  96                if (padapter->registrypriv.notch_filter == 1)
  97                        rtw_hal_notch_filter(padapter, 1);
  98
  99                rtw_hal_reset_security_engine(padapter);
 100
 101                rtw_sec_restore_wep_key(dvobj->padapters);
 102
 103                init_hw_mlme_ext(padapter);
 104
 105                rtw_bb_rf_gain_offset(padapter);
 106        } else {
 107                dvobj->padapters->hw_init_completed = false;
 108                DBG_871X("rtw_hal_init: hal__init fail\n");
 109        }
 110
 111        RT_TRACE(_module_hal_init_c_, _drv_err_, ("-rtl871x_hal_init:status = 0x%x\n", status));
 112
 113        return status;
 114
 115}
 116
 117uint rtw_hal_deinit(struct adapter *padapter)
 118{
 119        uint    status = _SUCCESS;
 120        struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
 121
 122        status = padapter->HalFunc.hal_deinit(padapter);
 123
 124        if (status == _SUCCESS) {
 125                padapter = dvobj->padapters;
 126                padapter->hw_init_completed = false;
 127        } else {
 128                DBG_871X("\n rtw_hal_deinit: hal_init fail\n");
 129        }
 130        return status;
 131}
 132
 133void rtw_hal_set_hwreg(struct adapter *padapter, u8 variable, u8 *val)
 134{
 135        if (padapter->HalFunc.SetHwRegHandler)
 136                padapter->HalFunc.SetHwRegHandler(padapter, variable, val);
 137}
 138
 139void rtw_hal_get_hwreg(struct adapter *padapter, u8 variable, u8 *val)
 140{
 141        if (padapter->HalFunc.GetHwRegHandler)
 142                padapter->HalFunc.GetHwRegHandler(padapter, variable, val);
 143}
 144
 145void rtw_hal_set_hwreg_with_buf(struct adapter *padapter, u8 variable, u8 *pbuf, int len)
 146{
 147        if (padapter->HalFunc.SetHwRegHandlerWithBuf)
 148                padapter->HalFunc.SetHwRegHandlerWithBuf(padapter, variable, pbuf, len);
 149}
 150
 151u8 rtw_hal_set_def_var(struct adapter *padapter, enum HAL_DEF_VARIABLE eVariable, void *pValue)
 152{
 153        if (padapter->HalFunc.SetHalDefVarHandler)
 154                return padapter->HalFunc.SetHalDefVarHandler(padapter, eVariable, pValue);
 155        return _FAIL;
 156}
 157
 158u8 rtw_hal_get_def_var(struct adapter *padapter, enum HAL_DEF_VARIABLE eVariable, void *pValue)
 159{
 160        if (padapter->HalFunc.GetHalDefVarHandler)
 161                return padapter->HalFunc.GetHalDefVarHandler(padapter, eVariable, pValue);
 162        return _FAIL;
 163}
 164
 165void rtw_hal_set_odm_var(struct adapter *padapter, enum HAL_ODM_VARIABLE eVariable, void *pValue1, bool bSet)
 166{
 167        if (padapter->HalFunc.SetHalODMVarHandler)
 168                padapter->HalFunc.SetHalODMVarHandler(padapter, eVariable, pValue1, bSet);
 169}
 170
 171void rtw_hal_get_odm_var(struct adapter *padapter, enum HAL_ODM_VARIABLE eVariable, void *pValue1, void *pValue2)
 172{
 173        if (padapter->HalFunc.GetHalODMVarHandler)
 174                padapter->HalFunc.GetHalODMVarHandler(padapter, eVariable, pValue1, pValue2);
 175}
 176
 177void rtw_hal_enable_interrupt(struct adapter *padapter)
 178{
 179        if (padapter->HalFunc.enable_interrupt)
 180                padapter->HalFunc.enable_interrupt(padapter);
 181        else
 182                DBG_871X("%s: HalFunc.enable_interrupt is NULL!\n", __func__);
 183
 184}
 185
 186void rtw_hal_disable_interrupt(struct adapter *padapter)
 187{
 188        if (padapter->HalFunc.disable_interrupt)
 189                padapter->HalFunc.disable_interrupt(padapter);
 190        else
 191                DBG_871X("%s: HalFunc.disable_interrupt is NULL!\n", __func__);
 192
 193}
 194
 195u8 rtw_hal_check_ips_status(struct adapter *padapter)
 196{
 197        u8 val = false;
 198        if (padapter->HalFunc.check_ips_status)
 199                val = padapter->HalFunc.check_ips_status(padapter);
 200        else
 201                DBG_871X("%s: HalFunc.check_ips_status is NULL!\n", __func__);
 202
 203        return val;
 204}
 205
 206s32     rtw_hal_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe)
 207{
 208        if (padapter->HalFunc.hal_xmitframe_enqueue)
 209                return padapter->HalFunc.hal_xmitframe_enqueue(padapter, pxmitframe);
 210
 211        return false;
 212}
 213
 214s32     rtw_hal_xmit(struct adapter *padapter, struct xmit_frame *pxmitframe)
 215{
 216        if (padapter->HalFunc.hal_xmit)
 217                return padapter->HalFunc.hal_xmit(padapter, pxmitframe);
 218
 219        return false;
 220}
 221
 222/*
 223 * [IMPORTANT] This function would be run in interrupt context.
 224 */
 225s32     rtw_hal_mgnt_xmit(struct adapter *padapter, struct xmit_frame *pmgntframe)
 226{
 227        s32 ret = _FAIL;
 228        update_mgntframe_attrib_addr(padapter, pmgntframe);
 229        /* pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; */
 230        /* pwlanhdr = (struct rtw_ieee80211_hdr *)pframe; */
 231        /* memcpy(pmgntframe->attrib.ra, pwlanhdr->addr1, ETH_ALEN); */
 232
 233        if (padapter->securitypriv.binstallBIPkey == true) {
 234                if (IS_MCAST(pmgntframe->attrib.ra)) {
 235                        pmgntframe->attrib.encrypt = _BIP_;
 236                        /* pmgntframe->attrib.bswenc = true; */
 237                } else {
 238                        pmgntframe->attrib.encrypt = _AES_;
 239                        pmgntframe->attrib.bswenc = true;
 240                }
 241                rtw_mgmt_xmitframe_coalesce(padapter, pmgntframe->pkt, pmgntframe);
 242        }
 243
 244        if (padapter->HalFunc.mgnt_xmit)
 245                ret = padapter->HalFunc.mgnt_xmit(padapter, pmgntframe);
 246        return ret;
 247}
 248
 249s32     rtw_hal_init_xmit_priv(struct adapter *padapter)
 250{
 251        if (padapter->HalFunc.init_xmit_priv != NULL)
 252                return padapter->HalFunc.init_xmit_priv(padapter);
 253        return _FAIL;
 254}
 255
 256void rtw_hal_free_xmit_priv(struct adapter *padapter)
 257{
 258        if (padapter->HalFunc.free_xmit_priv != NULL)
 259                padapter->HalFunc.free_xmit_priv(padapter);
 260}
 261
 262s32     rtw_hal_init_recv_priv(struct adapter *padapter)
 263{
 264        if (padapter->HalFunc.init_recv_priv)
 265                return padapter->HalFunc.init_recv_priv(padapter);
 266
 267        return _FAIL;
 268}
 269
 270void rtw_hal_free_recv_priv(struct adapter *padapter)
 271{
 272
 273        if (padapter->HalFunc.free_recv_priv)
 274                padapter->HalFunc.free_recv_priv(padapter);
 275}
 276
 277void rtw_hal_update_ra_mask(struct sta_info *psta, u8 rssi_level)
 278{
 279        struct adapter *padapter;
 280        struct mlme_priv *pmlmepriv;
 281
 282        if (!psta)
 283                return;
 284
 285        padapter = psta->padapter;
 286
 287        pmlmepriv = &(padapter->mlmepriv);
 288
 289        if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
 290                add_RATid(padapter, psta, rssi_level);
 291        else {
 292                if (padapter->HalFunc.UpdateRAMaskHandler)
 293                        padapter->HalFunc.UpdateRAMaskHandler(padapter, psta->mac_id, rssi_level);
 294        }
 295}
 296
 297void rtw_hal_add_ra_tid(struct adapter *padapter, u32 bitmap, u8 *arg, u8 rssi_level)
 298{
 299        if (padapter->HalFunc.Add_RateATid)
 300                padapter->HalFunc.Add_RateATid(padapter, bitmap, arg, rssi_level);
 301}
 302
 303/*Start specifical interface thread             */
 304void rtw_hal_start_thread(struct adapter *padapter)
 305{
 306        if (padapter->HalFunc.run_thread)
 307                padapter->HalFunc.run_thread(padapter);
 308}
 309/*Start specifical interface thread             */
 310void rtw_hal_stop_thread(struct adapter *padapter)
 311{
 312        if (padapter->HalFunc.cancel_thread)
 313                padapter->HalFunc.cancel_thread(padapter);
 314}
 315
 316u32 rtw_hal_read_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask)
 317{
 318        u32 data = 0;
 319        if (padapter->HalFunc.read_bbreg)
 320                 data = padapter->HalFunc.read_bbreg(padapter, RegAddr, BitMask);
 321        return data;
 322}
 323void rtw_hal_write_bbreg(struct adapter *padapter, u32 RegAddr, u32 BitMask, u32 Data)
 324{
 325        if (padapter->HalFunc.write_bbreg)
 326                padapter->HalFunc.write_bbreg(padapter, RegAddr, BitMask, Data);
 327}
 328
 329u32 rtw_hal_read_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask)
 330{
 331        u32 data = 0;
 332        if (padapter->HalFunc.read_rfreg)
 333                data = padapter->HalFunc.read_rfreg(padapter, eRFPath, RegAddr, BitMask);
 334        return data;
 335}
 336void rtw_hal_write_rfreg(struct adapter *padapter, u32 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
 337{
 338        if (padapter->HalFunc.write_rfreg)
 339                padapter->HalFunc.write_rfreg(padapter, eRFPath, RegAddr, BitMask, Data);
 340}
 341
 342void rtw_hal_set_chan(struct adapter *padapter, u8 channel)
 343{
 344        if (padapter->HalFunc.set_channel_handler)
 345                padapter->HalFunc.set_channel_handler(padapter, channel);
 346}
 347
 348void rtw_hal_set_chnl_bw(struct adapter *padapter, u8 channel,
 349                         enum CHANNEL_WIDTH Bandwidth, u8 Offset40, u8 Offset80)
 350{
 351        if (padapter->HalFunc.set_chnl_bw_handler)
 352                padapter->HalFunc.set_chnl_bw_handler(padapter, channel,
 353                                                      Bandwidth, Offset40,
 354                                                      Offset80);
 355}
 356
 357void rtw_hal_dm_watchdog(struct adapter *padapter)
 358{
 359        if (padapter->HalFunc.hal_dm_watchdog)
 360                padapter->HalFunc.hal_dm_watchdog(padapter);
 361
 362}
 363
 364void rtw_hal_dm_watchdog_in_lps(struct adapter *padapter)
 365{
 366        if (adapter_to_pwrctl(padapter)->bFwCurrentInPSMode == true) {
 367                if (padapter->HalFunc.hal_dm_watchdog_in_lps)
 368                        padapter->HalFunc.hal_dm_watchdog_in_lps(padapter); /* this fuction caller is in interrupt context */
 369        }
 370}
 371
 372void rtw_hal_bcn_related_reg_setting(struct adapter *padapter)
 373{
 374        if (padapter->HalFunc.SetBeaconRelatedRegistersHandler)
 375                padapter->HalFunc.SetBeaconRelatedRegistersHandler(padapter);
 376}
 377
 378
 379s32 rtw_hal_xmit_thread_handler(struct adapter *padapter)
 380{
 381        if (padapter->HalFunc.xmit_thread_handler)
 382                return padapter->HalFunc.xmit_thread_handler(padapter);
 383        return _FAIL;
 384}
 385
 386void rtw_hal_notch_filter(struct adapter *adapter, bool enable)
 387{
 388        if (adapter->HalFunc.hal_notch_filter)
 389                adapter->HalFunc.hal_notch_filter(adapter, enable);
 390}
 391
 392void rtw_hal_reset_security_engine(struct adapter *adapter)
 393{
 394        if (adapter->HalFunc.hal_reset_security_engine)
 395                adapter->HalFunc.hal_reset_security_engine(adapter);
 396}
 397
 398bool rtw_hal_c2h_valid(struct adapter *adapter, u8 *buf)
 399{
 400        return c2h_evt_valid((struct c2h_evt_hdr_88xx *)buf);
 401}
 402
 403s32 rtw_hal_c2h_evt_read(struct adapter *adapter, u8 *buf)
 404{
 405        return c2h_evt_read_88xx(adapter, buf);
 406}
 407
 408s32 rtw_hal_c2h_handler(struct adapter *adapter, u8 *c2h_evt)
 409{
 410        s32 ret = _FAIL;
 411        if (adapter->HalFunc.c2h_handler)
 412                ret = adapter->HalFunc.c2h_handler(adapter, c2h_evt);
 413        return ret;
 414}
 415
 416c2h_id_filter rtw_hal_c2h_id_filter_ccx(struct adapter *adapter)
 417{
 418        return adapter->HalFunc.c2h_id_filter_ccx;
 419}
 420
 421s32 rtw_hal_is_disable_sw_channel_plan(struct adapter *padapter)
 422{
 423        return GET_HAL_DATA(padapter)->bDisableSWChannelPlan;
 424}
 425
 426s32 rtw_hal_macid_sleep(struct adapter *padapter, u32 macid)
 427{
 428        u8 support;
 429
 430
 431        support = false;
 432        rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support);
 433        if (false == support)
 434                return _FAIL;
 435
 436        rtw_hal_set_hwreg(padapter, HW_VAR_MACID_SLEEP, (u8 *)&macid);
 437
 438        return _SUCCESS;
 439}
 440
 441s32 rtw_hal_macid_wakeup(struct adapter *padapter, u32 macid)
 442{
 443        u8 support;
 444
 445
 446        support = false;
 447        rtw_hal_get_def_var(padapter, HAL_DEF_MACID_SLEEP, &support);
 448        if (false == support)
 449                return _FAIL;
 450
 451        rtw_hal_set_hwreg(padapter, HW_VAR_MACID_WAKEUP, (u8 *)&macid);
 452
 453        return _SUCCESS;
 454}
 455
 456s32 rtw_hal_fill_h2c_cmd(struct adapter *padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer)
 457{
 458        s32 ret = _FAIL;
 459
 460        if (padapter->HalFunc.fill_h2c_cmd)
 461                ret = padapter->HalFunc.fill_h2c_cmd(padapter, ElementID, CmdLen, pCmdBuffer);
 462        else
 463                DBG_871X("%s:  func[fill_h2c_cmd] not defined!\n", __func__);
 464
 465        return ret;
 466}
 467