// SPDX-License-Identifier: GPL-2.0
/******************************************************************************
*
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
*
******************************************************************************/
#include <linux/kernel.h>
#include <drv_types.h>
#include "hal_com_h2c.h"
#include "odm_precomp.h"
u8 rtw_hal_data_init(struct adapter *padapter)
{
padapter->hal_data_sz = sizeof(struct hal_com_data);
padapter->HalData = vzalloc(padapter->hal_data_sz);
if (!padapter->HalData)
return _FAIL;
return _SUCCESS;
}
void rtw_hal_data_deinit(struct adapter *padapter)
{
if (padapter->HalData) {
vfree(padapter->HalData);
padapter->HalData = NULL;
padapter->hal_data_sz = 0;
}
}
void dump_chip_info(struct hal_version ChipVersion)
{
char buf[128];
size_t cnt = 0;
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "Chip Version Info: CHIP_8723B_%s_",
IS_NORMAL_CHIP(ChipVersion) ? "Normal_Chip" : "Test_Chip");
if (IS_CHIP_VENDOR_TSMC(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "TSMC_");
else if (IS_CHIP_VENDOR_UMC(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "UMC_");
else if (IS_CHIP_VENDOR_SMIC(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "SMIC_");
if (IS_A_CUT(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "A_CUT_");
else if (IS_B_CUT(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "B_CUT_");
else if (IS_C_CUT(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "C_CUT_");
else if (IS_D_CUT(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "D_CUT_");
else if (IS_E_CUT(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "E_CUT_");
else if (IS_I_CUT(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "I_CUT_");
else if (IS_J_CUT(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "J_CUT_");
else if (IS_K_CUT(ChipVersion))
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "K_CUT_");
else
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt,
"UNKNOWN_CUT(%d)_", ChipVersion.CUTVersion);
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "1T1R_");
cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "RomVer(%d)\n", ChipVersion.ROMVer);
}
#define EEPROM_CHANNEL_PLAN_BY_HW_MASK 0x80
/*
* Description:
*Use hardware(efuse), driver parameter(registry) and default channel plan
*to decide which one should be used.
*
* Parameters:
*padapter pointer of adapter
*hw_channel_plan channel plan from HW (efuse/eeprom)
* BIT[7] software configure mode; 0:Enable, 1:disable
* BIT[6:0] Channel Plan
*sw_channel_plan channel plan from SW (registry/module param)
*def_channel_plan channel plan used when HW/SW both invalid
*AutoLoadFail efuse autoload fail or not
*
* Return:
*Final channel plan decision
*
*/
u8 hal_com_config_channel_plan(
struct adapter *padapter,
u8 hw_channel_plan,
u8 sw_channel_plan,
u8 def_channel_plan,
bool AutoLoadFail
)
{
struct hal_com_data *pHalData;
u8 chnlPlan;
pHalData = GET_HAL_DATA(padapter);
pHalData->bDisableSWChannelPlan = false;
chnlPlan = def_channel_plan;
if (0xFF == hw_channel_plan)
AutoLoadFail = true;
if (!AutoLoadFail) {
u8 hw_chnlPlan;
hw_chnlPlan = hw_channel_plan & (~EEPROM_CHANNEL_PLAN_BY_HW_MASK);
if (rtw_is_channel_plan_valid(hw_chnlPlan)) {
if (hw_channel_plan & EEPROM_CHANNEL_PLAN_BY_HW_MASK)
pHalData->bDisableSWChannelPlan = true;
chnlPlan = hw_chnlPlan;
}
}
if (
(false == pHalData->bDisableSWChannelPlan) &&
rtw_is_channel_plan_valid(sw_channel_plan)
)
chnlPlan = sw_channel_plan;
return chnlPlan;
}
bool HAL_IsLegalChannel(struct adapter *adapter, u32 Channel)
{
bool bLegalChannel = true;
if ((Channel <= 14) && (Channel >= 1)) {
if (is_supported_24g(adapter->registrypriv.wireless_mode) == false)
bLegalChannel = false;
} else {
bLegalChannel = false;
}
return bLegalChannel;
}
u8 MRateToHwRate(u8 rate)
{
u8 ret = DESC_RATE1M;
switch (rate)