From 48b223d0de297af9ed4a20f6455c53d4ede14419 Mon Sep 17 00:00:00 2001 From: Larry Finger Date: Sat, 24 Nov 2018 11:52:48 -0600 Subject: [PATCH] rtl8188eu: Fix error in call to memset One usage reverses the order of the second and third arguments. Signed-off-by: Larry Finger --- core/rtw_efuse.c | 1075 +--------------------------------------------- 1 file changed, 2 insertions(+), 1073 deletions(-) diff --git a/core/rtw_efuse.c b/core/rtw_efuse.c index 5ebe3a6..8de4746 100644 --- a/core/rtw_efuse.c +++ b/core/rtw_efuse.c @@ -120,1046 +120,6 @@ u8 rtw_efuse_mask_map_read(PADAPTER padapter, u16 addr, u16 cnts, u8 *data) } -#ifdef RTW_HALMAC -#include "../../hal/hal_halmac.h" - -void Efuse_PowerSwitch(PADAPTER adapter, u8 write, u8 pwrstate) -{ -} - -void BTEfuse_PowerSwitch(PADAPTER adapter, u8 write, u8 pwrstate) -{ -} - -u8 efuse_GetCurrentSize(PADAPTER adapter, u16 *size) -{ - *size = 0; - - return _FAIL; -} - -u16 efuse_GetMaxSize(PADAPTER adapter) -{ - struct dvobj_priv *d; - u32 size = 0; - int err; - - d = adapter_to_dvobj(adapter); - err = rtw_halmac_get_physical_efuse_size(d, &size); - if (err) - return 0; - - return size; -} - -u16 efuse_GetavailableSize(PADAPTER adapter) -{ - struct dvobj_priv *d; - u32 size = 0; - int err; - - d = adapter_to_dvobj(adapter); - err = rtw_halmac_get_available_efuse_size(d, &size); - if (err) - return 0; - - return size; -} - - -u8 efuse_bt_GetCurrentSize(PADAPTER adapter, u16 *usesize) -{ - u8 *efuse_map; - - *usesize = 0; - efuse_map = rtw_malloc(EFUSE_BT_MAP_LEN); - if (efuse_map == NULL) { - RTW_DBG("%s: malloc FAIL\n", __func__); - return _FAIL; - } - - /* for get bt phy efuse last use byte */ - hal_ReadEFuse_BT_logic_map(adapter, 0x00, EFUSE_BT_MAP_LEN, efuse_map); - *usesize = fakeBTEfuseUsedBytes; - - if (efuse_map) - rtw_mfree(efuse_map, EFUSE_BT_MAP_LEN); - - return _SUCCESS; -} - -u16 efuse_bt_GetMaxSize(PADAPTER adapter) -{ - return EFUSE_BT_REAL_CONTENT_LEN; -} - -void EFUSE_GetEfuseDefinition(PADAPTER adapter, u8 efusetype, u8 type, void *out, bool test) -{ - struct dvobj_priv *d; - u32 v32 = 0; - - - d = adapter_to_dvobj(adapter); - - if (adapter->hal_func.EFUSEGetEfuseDefinition) { - adapter->hal_func.EFUSEGetEfuseDefinition(adapter, efusetype, type, out, test); - return; - } - - if (EFUSE_WIFI == efusetype) { - switch (type) { - case TYPE_EFUSE_MAP_LEN: - rtw_halmac_get_logical_efuse_size(d, &v32); - *(u16 *)out = (u16)v32; - return; - - case TYPE_EFUSE_REAL_CONTENT_LEN: - rtw_halmac_get_physical_efuse_size(d, &v32); - *(u16 *)out = (u16)v32; - return; - } - } else if (EFUSE_BT == efusetype) { - switch (type) { - case TYPE_EFUSE_MAP_LEN: - *(u16 *)out = EFUSE_BT_MAP_LEN; - return; - - case TYPE_EFUSE_REAL_CONTENT_LEN: - *(u16 *)out = EFUSE_BT_REAL_CONTENT_LEN; - return; - } - } -} - -/* - * read/write raw efuse data - */ -u8 rtw_efuse_access(PADAPTER adapter, u8 write, u16 addr, u16 cnts, u8 *data) -{ - struct dvobj_priv *d; - u8 *efuse = NULL; - u32 size, i; - int err; - - - d = adapter_to_dvobj(adapter); - err = rtw_halmac_get_physical_efuse_size(d, &size); - if (err) - size = EFUSE_MAX_SIZE; - - if ((addr + cnts) > size) - return _FAIL; - - if (_TRUE == write) { - err = rtw_halmac_write_physical_efuse(d, addr, cnts, data); - if (err) - return _FAIL; - } else { - if (cnts > 16) - efuse = rtw_zmalloc(size); - - if (efuse) { - err = rtw_halmac_read_physical_efuse_map(d, efuse, size); - if (err) { - rtw_mfree(efuse, size); - return _FAIL; - } - - _rtw_memcpy(data, efuse + addr, cnts); - rtw_mfree(efuse, size); - } else { - err = rtw_halmac_read_physical_efuse(d, addr, cnts, data); - if (err) - return _FAIL; - } - } - - return _SUCCESS; -} - -static inline void dump_buf(u8 *buf, u32 len) -{ - u32 i; - - RTW_INFO("-----------------Len %d----------------\n", len); - for (i = 0; i < len; i++) - RTW_INFO("%2.2x-", *(buf + i)); - RTW_INFO("\n"); -} - -/* - * read/write raw efuse data - */ -u8 rtw_efuse_bt_access(PADAPTER adapter, u8 write, u16 addr, u16 cnts, u8 *data) -{ - struct dvobj_priv *d; - u8 *efuse = NULL; - u32 size, i; - int err = _FAIL; - - - d = adapter_to_dvobj(adapter); - - size = EFUSE_BT_REAL_CONTENT_LEN; - - if ((addr + cnts) > size) - return _FAIL; - - if (_TRUE == write) { - err = rtw_halmac_write_bt_physical_efuse(d, addr, cnts, data); - if (err == -1) { - RTW_ERR("%s: rtw_halmac_write_bt_physical_efuse fail!\n", __func__); - return _FAIL; - } - RTW_INFO("%s: rtw_halmac_write_bt_physical_efuse OK! data 0x%x\n", __func__, *data); - } else { - efuse = rtw_zmalloc(size); - - if (efuse) { - err = rtw_halmac_read_bt_physical_efuse_map(d, efuse, size); - - if (err == -1) { - RTW_ERR("%s: rtw_halmac_read_bt_physical_efuse_map fail!\n", __func__); - rtw_mfree(efuse, size); - return _FAIL; - } - dump_buf(efuse + addr, cnts); - - _rtw_memcpy(data, efuse + addr, cnts); - - RTW_INFO("%s: rtw_halmac_read_bt_physical_efuse_map ok! data 0x%x\n", __func__, *data); - rtw_mfree(efuse, size); - } - } - - return _SUCCESS; -} - -u8 rtw_efuse_map_read(PADAPTER adapter, u16 addr, u16 cnts, u8 *data) -{ - struct dvobj_priv *d; - u8 *efuse = NULL; - u32 size, i; - int err; - - - d = adapter_to_dvobj(adapter); - err = rtw_halmac_get_logical_efuse_size(d, &size); - if (err) - return _FAIL; - - /* size error handle */ - if ((addr + cnts) > size) { - if (addr < size) - cnts = size - addr; - else - return _FAIL; - } - - if (cnts > 16) - efuse = rtw_zmalloc(size); - - if (efuse) { - err = rtw_halmac_read_logical_efuse_map(d, efuse, size); - if (err) { - rtw_mfree(efuse, size); - return _FAIL; - } - - _rtw_memcpy(data, efuse + addr, cnts); - rtw_mfree(efuse, size); - } else { - err = rtw_halmac_read_logical_efuse(d, addr, cnts, data); - if (err) - return _FAIL; - } - - return _SUCCESS; -} - -u8 rtw_efuse_map_write(PADAPTER adapter, u16 addr, u16 cnts, u8 *data) -{ - struct dvobj_priv *d; - u8 *efuse = NULL; - u32 size, i; - int err; - u8 mask_buf[64] = ""; - u16 mask_len = sizeof(u8) * rtw_get_efuse_mask_arraylen(adapter); - - d = adapter_to_dvobj(adapter); - err = rtw_halmac_get_logical_efuse_size(d, &size); - if (err) - return _FAIL; - - if ((addr + cnts) > size) - return _FAIL; - - efuse = rtw_zmalloc(size); - if (!efuse) - return _FAIL; - - err = rtw_halmac_read_logical_efuse_map(d, efuse, size); - if (err) { - rtw_mfree(efuse, size); - return _FAIL; - } - - _rtw_memcpy(efuse + addr, data, cnts); - - if (adapter->registrypriv.boffefusemask == 0) { - RTW_INFO("Use mask Array Len: %d\n", mask_len); - - if (mask_len != 0) { - if (adapter->registrypriv.bFileMaskEfuse == _TRUE) - _rtw_memcpy(mask_buf, maskfileBuffer, mask_len); - else - rtw_efuse_mask_array(adapter, mask_buf); - - err = rtw_halmac_write_logical_efuse_map(d, efuse, size, mask_buf, mask_len); - } else - err = rtw_halmac_write_logical_efuse_map(d, efuse, size, NULL, 0); - } else { - _rtw_memset(mask_buf, 0xFF, sizeof(mask_buf)); - RTW_INFO("Efuse mask off\n"); - err = rtw_halmac_write_logical_efuse_map(d, efuse, size, mask_buf, size/16); - } - - if (err) { - rtw_mfree(efuse, size); - return _FAIL; - } - - rtw_mfree(efuse, size); - - return _SUCCESS; -} - -int Efuse_PgPacketRead(PADAPTER adapter, u8 offset, u8 *data, bool test) -{ - return _FALSE; -} - -int Efuse_PgPacketWrite(PADAPTER adapter, u8 offset, u8 word_en, u8 *data, bool test) -{ - return _FALSE; -} - -u8 rtw_BT_efuse_map_read(PADAPTER adapter, u16 addr, u16 cnts, u8 *data) -{ - hal_ReadEFuse_BT_logic_map(adapter,addr, cnts, data); - - return _SUCCESS; -} - -u8 rtw_BT_efuse_map_write(PADAPTER adapter, u16 addr, u16 cnts, u8 *data) -{ -#define RT_ASSERT_RET(expr) \ - if (!(expr)) { \ - RTW_INFO("Assertion failed! %s at ......\n", #expr); \ - RTW_INFO(" ......%s,%s, line=%d\n",__FILE__, __func__, __LINE__); \ - return _FAIL; \ - } - - u8 offset, word_en; - u8 *map; - u8 newdata[PGPKT_DATA_SIZE]; - s32 i = 0, j = 0, idx; - u8 ret = _SUCCESS; - u16 mapLen = 1024; - - if ((addr + cnts) > mapLen) - return _FAIL; - - RT_ASSERT_RET(PGPKT_DATA_SIZE == 8); /* have to be 8 byte alignment */ - RT_ASSERT_RET((mapLen & 0x7) == 0); /* have to be PGPKT_DATA_SIZE alignment for memcpy */ - - map = rtw_zmalloc(mapLen); - if (map == NULL) - return _FAIL; - - ret = rtw_BT_efuse_map_read(adapter, 0, mapLen, map); - if (ret == _FAIL) - goto exit; - RTW_INFO("OFFSET\tVALUE(hex)\n"); - for (i = 0; i < mapLen; i += 16) { /* set 512 because the iwpriv's extra size have limit 0x7FF */ - RTW_INFO("0x%03x\t", i); - for (j = 0; j < 8; j++) - RTW_INFO("%02X ", map[i + j]); - RTW_INFO("\t"); - for (; j < 16; j++) - RTW_INFO("%02X ", map[i + j]); - RTW_INFO("\n"); - } - RTW_INFO("\n"); - - idx = 0; - offset = (addr >> 3); - while (idx < cnts) { - word_en = 0xF; - j = (addr + idx) & 0x7; - _rtw_memcpy(newdata, &map[offset << 3], PGPKT_DATA_SIZE); - for (i = j; i < PGPKT_DATA_SIZE && idx < cnts; i++, idx++) { - if (data[idx] != map[addr + idx]) { - word_en &= ~BIT(i >> 1); - newdata[i] = data[idx]; - } - } - - if (word_en != 0xF) { - ret = EfusePgPacketWrite_BT(adapter, offset, word_en, newdata, _FALSE); - RTW_INFO("offset=%x\n", offset); - RTW_INFO("word_en=%x\n", word_en); - RTW_INFO("%s: data=", __func__); - for (i = 0; i < PGPKT_DATA_SIZE; i++) - RTW_INFO("0x%02X ", newdata[i]); - RTW_INFO("\n"); - if (ret == _FAIL) - break; - } - offset++; - } -exit: - rtw_mfree(map, mapLen); - return _SUCCESS; -} - -void hal_ReadEFuse_BT_logic_map( - PADAPTER padapter, - u16 _offset, - u16 _size_byte, - u8 *pbuf -) -{ - - PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter); - PEFUSE_HAL pEfuseHal = &pHalData->EfuseHal; - - u8 *efuseTbl, *phyefuse; - u8 bank; - u16 eFuse_Addr = 0; - u8 efuseHeader, efuseExtHdr, efuseData; - u8 offset, wden; - u16 i, total, used; - u8 efuse_usage; - - - /* */ - /* Do NOT excess total size of EFuse table. Added by Roger, 2008.11.10. */ - /* */ - if ((_offset + _size_byte) > EFUSE_BT_MAP_LEN) { - RTW_INFO("%s: Invalid offset(%#x) with read bytes(%#x)!!\n", __func__, _offset, _size_byte); - return; - } - - efuseTbl = rtw_malloc(EFUSE_BT_MAP_LEN); - phyefuse = rtw_malloc(EFUSE_BT_REAL_CONTENT_LEN); - if (efuseTbl == NULL || phyefuse == NULL) { - RTW_INFO("%s: efuseTbl or phyefuse malloc fail!\n", __func__); - goto exit; - } - - /* 0xff will be efuse default value instead of 0x00. */ - _rtw_memset(efuseTbl, 0xFF, EFUSE_BT_MAP_LEN); - _rtw_memset(phyefuse, 0xFF, EFUSE_BT_REAL_CONTENT_LEN); - - if (rtw_efuse_bt_access(padapter, _FALSE, 0, EFUSE_BT_REAL_CONTENT_LEN, phyefuse)) - dump_buf(phyefuse, EFUSE_BT_REAL_BANK_CONTENT_LEN); - - total = BANK_NUM; - for (bank = 1; bank <= total; bank++) { /* 8723d Max bake 0~2 */ - eFuse_Addr = 0; - - while (AVAILABLE_EFUSE_ADDR(eFuse_Addr)) { - /* ReadEFuseByte(padapter, eFuse_Addr++, &efuseHeader, bPseudoTest); */ - efuseHeader = phyefuse[eFuse_Addr++]; - - if (efuseHeader == 0xFF) - break; - RTW_INFO("%s: efuse[%#X]=0x%02x (header)\n", __func__, (((bank - 1) * EFUSE_BT_REAL_CONTENT_LEN) + eFuse_Addr - 1), efuseHeader); - - /* Check PG header for section num. */ - if (EXT_HEADER(efuseHeader)) { /* extended header */ - offset = GET_HDR_OFFSET_2_0(efuseHeader); - RTW_INFO("%s: extended header offset_2_0=0x%X\n", __func__, offset); - - /* ReadEFuseByte(padapter, eFuse_Addr++, &efuseExtHdr, bPseudoTest); */ - efuseExtHdr = phyefuse[eFuse_Addr++]; - - RTW_INFO("%s: efuse[%#X]=0x%02x (ext header)\n", __func__, (((bank - 1) * EFUSE_BT_REAL_CONTENT_LEN) + eFuse_Addr - 1), efuseExtHdr); - if (ALL_WORDS_DISABLED(efuseExtHdr)) - continue; - - offset |= ((efuseExtHdr & 0xF0) >> 1); - wden = (efuseExtHdr & 0x0F); - } else { - offset = ((efuseHeader >> 4) & 0x0f); - wden = (efuseHeader & 0x0f); - } - - if (offset < EFUSE_BT_MAX_SECTION) { - u16 addr; - - /* Get word enable value from PG header */ - RTW_INFO("%s: Offset=%d Worden=%#X\n", __func__, offset, wden); - - addr = offset * PGPKT_DATA_SIZE; - for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { - /* Check word enable condition in the section */ - if (!(wden & (0x01 << i))) { - efuseData = 0; - /* ReadEFuseByte(padapter, eFuse_Addr++, &efuseData, bPseudoTest); */ - efuseData = phyefuse[eFuse_Addr++]; - - RTW_INFO("%s: efuse[%#X]=0x%02X\n", __func__, eFuse_Addr - 1, efuseData); - efuseTbl[addr] = efuseData; - - efuseData = 0; - /* ReadEFuseByte(padapter, eFuse_Addr++, &efuseData, bPseudoTest); */ - efuseData = phyefuse[eFuse_Addr++]; - - RTW_INFO("%s: efuse[%#X]=0x%02X\n", __func__, eFuse_Addr - 1, efuseData); - efuseTbl[addr + 1] = efuseData; - } - addr += 2; - } - } else { - RTW_INFO("%s: offset(%d) is illegal!!\n", __func__, offset); - eFuse_Addr += Efuse_CalculateWordCnts(wden) * 2; - } - } - - if ((eFuse_Addr - 1) < total) { - RTW_INFO("%s: bank(%d) data end at %#x\n", __func__, bank, eFuse_Addr - 1); - break; - } - } - - /* switch bank back to bank 0 for later BT and wifi use. */ - //hal_EfuseSwitchToBank(padapter, 0, bPseudoTest); - - /* Copy from Efuse map to output pointer memory!!! */ - for (i = 0; i < _size_byte; i++) - pbuf[i] = efuseTbl[_offset + i]; - /* Calculate Efuse utilization */ - total = EFUSE_BT_REAL_BANK_CONTENT_LEN; - - used = eFuse_Addr - 1; - - if (total) - efuse_usage = (u8)((used * 100) / total); - else - efuse_usage = 100; - - fakeBTEfuseUsedBytes = used; - RTW_INFO("%s: BTEfuseUsed last Bytes = %#x\n", __func__, fakeBTEfuseUsedBytes); - -exit: - if (efuseTbl) - rtw_mfree(efuseTbl, EFUSE_BT_MAP_LEN); - if (phyefuse) - rtw_mfree(phyefuse, EFUSE_BT_REAL_BANK_CONTENT_LEN); -} - - -static u8 hal_EfusePartialWriteCheck( - PADAPTER padapter, - u8 efuseType, - u16 *pAddr, - PPGPKT_STRUCT pTargetPkt, - u8 bPseudoTest) -{ - PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter); - PEFUSE_HAL pEfuseHal = &pHalData->EfuseHal; - u8 bRet = _FALSE; - u16 startAddr = 0, efuse_max_available_len = EFUSE_BT_REAL_BANK_CONTENT_LEN, efuse_max = EFUSE_BT_REAL_BANK_CONTENT_LEN; - u8 efuse_data = 0; - - startAddr = (u16)fakeBTEfuseUsedBytes; - - startAddr %= efuse_max; - RTW_INFO("%s: startAddr=%#X\n", __func__, startAddr); - - while (1) { - if (startAddr >= efuse_max_available_len) { - bRet = _FALSE; - RTW_INFO("%s: startAddr(%d) >= efuse_max_available_len(%d)\n", - __func__, startAddr, efuse_max_available_len); - break; - } - if (rtw_efuse_bt_access(padapter, _FALSE, startAddr, 1, &efuse_data)&& (efuse_data != 0xFF)) { - bRet = _FALSE; - RTW_INFO("%s: Something Wrong! last bytes(%#X=0x%02X) is not 0xFF\n", - __func__, startAddr, efuse_data); - break; - } else { - /* not used header, 0xff */ - *pAddr = startAddr; - /* RTW_INFO("%s: Started from unused header offset=%d\n", __func__, startAddr)); */ - bRet = _TRUE; - break; - } - } - - return bRet; -} - - -static u8 hal_EfusePgPacketWrite2ByteHeader( - PADAPTER padapter, - u8 efuseType, - u16 *pAddr, - PPGPKT_STRUCT pTargetPkt, - u8 bPseudoTest) -{ - u16 efuse_addr, efuse_max_available_len = EFUSE_BT_REAL_BANK_CONTENT_LEN; - u8 pg_header = 0, tmp_header = 0; - u8 repeatcnt = 0; - - /* RTW_INFO("%s\n", __func__); */ - - efuse_addr = *pAddr; - if (efuse_addr >= efuse_max_available_len) { - RTW_INFO("%s: addr(%d) over avaliable(%d)!!\n", __func__, efuse_addr, efuse_max_available_len); - return _FALSE; - } - - pg_header = ((pTargetPkt->offset & 0x07) << 5) | 0x0F; - /* RTW_INFO("%s: pg_header=0x%x\n", __func__, pg_header); */ - - do { - - rtw_efuse_bt_access(padapter, _TRUE, efuse_addr, 1, &pg_header); - rtw_efuse_bt_access(padapter, _FALSE, efuse_addr, 1, &tmp_header); - - if (tmp_header != 0xFF) - break; - if (repeatcnt++ > EFUSE_REPEAT_THRESHOLD_) { - RTW_INFO("%s: Repeat over limit for pg_header!!\n", __func__); - return _FALSE; - } - } while (1); - - if (tmp_header != pg_header) { - RTW_ERR("%s: PG Header Fail!!(pg=0x%02X read=0x%02X)\n", __func__, pg_header, tmp_header); - return _FALSE; - } - - /* to write ext_header */ - efuse_addr++; - pg_header = ((pTargetPkt->offset & 0x78) << 1) | pTargetPkt->word_en; - - do { - rtw_efuse_bt_access(padapter, _TRUE, efuse_addr, 1, &pg_header); - rtw_efuse_bt_access(padapter, _FALSE, efuse_addr, 1, &tmp_header); - - if (tmp_header != 0xFF) - break; - if (repeatcnt++ > EFUSE_REPEAT_THRESHOLD_) { - RTW_INFO("%s: Repeat over limit for ext_header!!\n", __func__); - return _FALSE; - } - } while (1); - - if (tmp_header != pg_header) { /* offset PG fail */ - RTW_ERR("%s: PG EXT Header Fail!!(pg=0x%02X read=0x%02X)\n", __func__, pg_header, tmp_header); - return _FALSE; - } - - *pAddr = efuse_addr; - - return _TRUE; -} - - -static u8 hal_EfusePgPacketWrite1ByteHeader( - PADAPTER pAdapter, - u8 efuseType, - u16 *pAddr, - PPGPKT_STRUCT pTargetPkt, - u8 bPseudoTest) -{ - u8 bRet = _FALSE; - u8 pg_header = 0, tmp_header = 0; - u16 efuse_addr = *pAddr; - u8 repeatcnt = 0; - - - /* RTW_INFO("%s\n", __func__); */ - pg_header = ((pTargetPkt->offset << 4) & 0xf0) | pTargetPkt->word_en; - - do { - rtw_efuse_bt_access(pAdapter, _TRUE, efuse_addr, 1, &pg_header); - rtw_efuse_bt_access(pAdapter, _FALSE, efuse_addr, 1, &tmp_header); - - if (tmp_header != 0xFF) - break; - if (repeatcnt++ > EFUSE_REPEAT_THRESHOLD_) { - RTW_INFO("%s: Repeat over limit for pg_header!!\n", __func__); - return _FALSE; - } - } while (1); - - if (tmp_header != pg_header) { - RTW_ERR("%s: PG Header Fail!!(pg=0x%02X read=0x%02X)\n", __func__, pg_header, tmp_header); - return _FALSE; - } - - *pAddr = efuse_addr; - - return _TRUE; -} - -static u8 hal_EfusePgPacketWriteHeader( - PADAPTER padapter, - u8 efuseType, - u16 *pAddr, - PPGPKT_STRUCT pTargetPkt, - u8 bPseudoTest) -{ - u8 bRet = _FALSE; - - if (pTargetPkt->offset >= EFUSE_MAX_SECTION_BASE) - bRet = hal_EfusePgPacketWrite2ByteHeader(padapter, efuseType, pAddr, pTargetPkt, bPseudoTest); - else - bRet = hal_EfusePgPacketWrite1ByteHeader(padapter, efuseType, pAddr, pTargetPkt, bPseudoTest); - - return bRet; -} - - -static u8 -Hal_EfuseWordEnableDataWrite( - PADAPTER padapter, - u16 efuse_addr, - u8 word_en, - u8 *data, - u8 bPseudoTest) -{ - u16 tmpaddr = 0; - u16 start_addr = efuse_addr; - u8 badworden = 0x0F; - u8 tmpdata[PGPKT_DATA_SIZE]; - - - /* RTW_INFO("%s: efuse_addr=%#x word_en=%#x\n", __func__, efuse_addr, word_en); */ - _rtw_memset(tmpdata, 0xFF, PGPKT_DATA_SIZE); - - if (!(word_en & BIT(0))) { - tmpaddr = start_addr; - rtw_efuse_bt_access(padapter, _TRUE, start_addr++, 1, &data[0]); - rtw_efuse_bt_access(padapter, _TRUE, start_addr++, 1, &data[1]); - rtw_efuse_bt_access(padapter, _FALSE, tmpaddr, 1, &tmpdata[0]); - rtw_efuse_bt_access(padapter, _FALSE, tmpaddr + 1, 1, &tmpdata[1]); - if ((data[0] != tmpdata[0]) || (data[1] != tmpdata[1])) - badworden &= (~BIT(0)); - } - if (!(word_en & BIT(1))) { - tmpaddr = start_addr; - rtw_efuse_bt_access(padapter, _TRUE, start_addr++, 1, &data[2]); - rtw_efuse_bt_access(padapter, _TRUE, start_addr++, 1, &data[3]); - rtw_efuse_bt_access(padapter, _FALSE, tmpaddr, 1, &tmpdata[2]); - rtw_efuse_bt_access(padapter, _FALSE, tmpaddr + 1, 1, &tmpdata[3]); - if ((data[2] != tmpdata[2]) || (data[3] != tmpdata[3])) - badworden &= (~BIT(1)); - } - if (!(word_en & BIT(2))) { - tmpaddr = start_addr; - rtw_efuse_bt_access(padapter, _TRUE, start_addr++, 1, &data[4]); - rtw_efuse_bt_access(padapter, _TRUE, start_addr++, 1, &data[5]); - rtw_efuse_bt_access(padapter, _FALSE, tmpaddr, 1, &tmpdata[4]); - rtw_efuse_bt_access(padapter, _FALSE, tmpaddr + 1, 1, &tmpdata[5]); - if ((data[4] != tmpdata[4]) || (data[5] != tmpdata[5])) - badworden &= (~BIT(2)); - } - if (!(word_en & BIT(3))) { - tmpaddr = start_addr; - rtw_efuse_bt_access(padapter, _TRUE, start_addr++, 1, &data[6]); - rtw_efuse_bt_access(padapter, _TRUE, start_addr++, 1, &data[7]); - rtw_efuse_bt_access(padapter, _FALSE, tmpaddr, 1, &tmpdata[6]); - rtw_efuse_bt_access(padapter, _FALSE, tmpaddr + 1, 1, &tmpdata[7]); - - if ((data[6] != tmpdata[6]) || (data[7] != tmpdata[7])) - badworden &= (~BIT(3)); - } - - return badworden; -} - -static void -hal_EfuseConstructPGPkt( - u8 offset, - u8 word_en, - u8 *pData, - PPGPKT_STRUCT pTargetPkt) -{ - _rtw_memset(pTargetPkt->data, 0xFF, PGPKT_DATA_SIZE); - pTargetPkt->offset = offset; - pTargetPkt->word_en = word_en; - efuse_WordEnableDataRead(word_en, pData, pTargetPkt->data); - pTargetPkt->word_cnts = Efuse_CalculateWordCnts(pTargetPkt->word_en); -} - -static u8 -hal_EfusePgPacketWriteData( - PADAPTER pAdapter, - u8 efuseType, - u16 *pAddr, - PPGPKT_STRUCT pTargetPkt, - u8 bPseudoTest) -{ - u16 efuse_addr; - u8 badworden; - - efuse_addr = *pAddr; - badworden = Hal_EfuseWordEnableDataWrite(pAdapter, efuse_addr + 1, pTargetPkt->word_en, pTargetPkt->data, bPseudoTest); - if (badworden != 0x0F) { - RTW_INFO("%s: Fail!!\n", __func__); - return _FALSE; - } else - RTW_INFO("%s: OK!!\n", __func__); - - return _TRUE; -} - -/* *********************************************************** - * Efuse related code - * *********************************************************** */ -static u8 -hal_EfuseSwitchToBank( - PADAPTER padapter, - u8 bank, - u8 bPseudoTest) -{ - u8 bRet = _FALSE; - u32 value32 = 0; -#ifdef HAL_EFUSE_MEMORY - PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter); - PEFUSE_HAL pEfuseHal = &pHalData->EfuseHal; -#endif - - - RTW_INFO("%s: Efuse switch bank to %d\n", __func__, bank); - if (bPseudoTest) { -#ifdef HAL_EFUSE_MEMORY - pEfuseHal->fakeEfuseBank = bank; -#else - fakeEfuseBank = bank; -#endif - bRet = _TRUE; - } else { - value32 = rtw_read32(padapter, 0x34); - bRet = _TRUE; - switch (bank) { - case 0: - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_WIFI_SEL_0); - break; - case 1: - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_BT_SEL_0); - break; - case 2: - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_BT_SEL_1); - break; - case 3: - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_BT_SEL_2); - break; - default: - value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_WIFI_SEL_0); - bRet = _FALSE; - break; - } - rtw_write32(padapter, 0x34, value32); - } - - return bRet; -} - - -#define EFUSE_CTRL 0x30 /* E-Fuse Control. */ - -/* 11/16/2008 MH Read one byte from real Efuse. */ -u8 -efuse_OneByteRead( - PADAPTER pAdapter, - u16 addr, - u8 *data, - bool bPseudoTest) -{ - u32 tmpidx = 0; - u8 bResult; - u8 readbyte; - HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter); - - if ((IS_VENDOR_8188E_I_CUT_SERIES(pAdapter)) || - (IS_CHIP_VENDOR_SMIC(pHalData->version_id))) { - /* <20130121, Kordan> For SMIC EFUSE specificatoin. */ - /* 0x34[11]: SW force PGMEN input of efuse to high. (for the bank selected by 0x34[9:8]) */ - /* phy_set_mac_reg(pAdapter, 0x34, BIT11, 0); */ - rtw_write16(pAdapter, 0x34, rtw_read16(pAdapter, 0x34) & (~BIT11)); - } - - /* -----------------e-fuse reg ctrl --------------------------------- */ - /* address */ - rtw_write8(pAdapter, EFUSE_CTRL + 1, (u8)(addr & 0xff)); - rtw_write8(pAdapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) | - (rtw_read8(pAdapter, EFUSE_CTRL + 2) & 0xFC)); - - /* rtw_write8(pAdapter, EFUSE_CTRL+3, 0x72); */ /* read cmd */ - /* Write bit 32 0 */ - readbyte = rtw_read8(pAdapter, EFUSE_CTRL + 3); - rtw_write8(pAdapter, EFUSE_CTRL + 3, (readbyte & 0x7f)); - - while (!(0x80 & rtw_read8(pAdapter, EFUSE_CTRL + 3)) && (tmpidx < 1000)) { - rtw_mdelay_os(1); - tmpidx++; - } - if (tmpidx < 100) { - *data = rtw_read8(pAdapter, EFUSE_CTRL); - bResult = _TRUE; - } else { - *data = 0xff; - bResult = _FALSE; - RTW_INFO("%s: [ERROR] addr=0x%x bResult=%d time out 1s !!!\n", __func__, addr, bResult); - RTW_INFO("%s: [ERROR] EFUSE_CTRL =0x%08x !!!\n", __func__, rtw_read32(pAdapter, EFUSE_CTRL)); - } - - return bResult; -} - - -static u16 -hal_EfuseGetCurrentSize_BT( - PADAPTER padapter, - u8 bPseudoTest) -{ -#ifdef HAL_EFUSE_MEMORY - PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter); - PEFUSE_HAL pEfuseHal = &pHalData->EfuseHal; -#endif - u16 btusedbytes; - u16 efuse_addr; - u8 bank, startBank; - u8 hoffset = 0, hworden = 0; - u8 efuse_data, word_cnts = 0; - u16 retU2 = 0; - u8 bContinual = _TRUE; - - - btusedbytes = fakeBTEfuseUsedBytes; - - efuse_addr = (u16)((btusedbytes % EFUSE_BT_REAL_BANK_CONTENT_LEN)); - startBank = (u8)(1 + (btusedbytes / EFUSE_BT_REAL_BANK_CONTENT_LEN)); - - RTW_INFO("%s: start from bank=%d addr=0x%X\n", __func__, startBank, efuse_addr); - retU2 = EFUSE_BT_REAL_CONTENT_LEN - EFUSE_PROTECT_BYTES_BANK; - - for (bank = startBank; bank < 3; bank++) { - if (hal_EfuseSwitchToBank(padapter, bank, bPseudoTest) == _FALSE) { - RTW_ERR("%s: switch bank(%d) Fail!!\n", __func__, bank); - /* bank = EFUSE_MAX_BANK; */ - break; - } - - /* only when bank is switched we have to reset the efuse_addr. */ - if (bank != startBank) - efuse_addr = 0; - - - while (AVAILABLE_EFUSE_ADDR(efuse_addr)) { - if (rtw_efuse_bt_access(padapter, _FALSE, efuse_addr, 1, &efuse_data) == _FALSE) { - RTW_ERR("%s: efuse_OneByteRead Fail! addr=0x%X !!\n", __func__, efuse_addr); - /* bank = EFUSE_MAX_BANK; */ - break; - } - RTW_INFO("%s: efuse_OneByteRead ! addr=0x%X !efuse_data=0x%X! bank =%d\n", __func__, efuse_addr, efuse_data, bank); - - if (efuse_data == 0xFF) - break; - - if (EXT_HEADER(efuse_data)) { - hoffset = GET_HDR_OFFSET_2_0(efuse_data); - efuse_addr++; - rtw_efuse_bt_access(padapter, _FALSE, efuse_addr, 1, &efuse_data); - RTW_INFO("%s: efuse_OneByteRead EXT_HEADER ! addr=0x%X !efuse_data=0x%X! bank =%d\n", __func__, efuse_addr, efuse_data, bank); - - if (ALL_WORDS_DISABLED(efuse_data)) { - efuse_addr++; - continue; - } - - /* hoffset = ((hoffset & 0xE0) >> 5) | ((efuse_data & 0xF0) >> 1); */ - hoffset |= ((efuse_data & 0xF0) >> 1); - hworden = efuse_data & 0x0F; - } else { - hoffset = (efuse_data >> 4) & 0x0F; - hworden = efuse_data & 0x0F; - } - - RTW_INFO(FUNC_ADPT_FMT": Offset=%d Worden=%#X\n", - FUNC_ADPT_ARG(padapter), hoffset, hworden); - - word_cnts = Efuse_CalculateWordCnts(hworden); - /* read next header */ - efuse_addr += (word_cnts * 2) + 1; - } - /* Check if we need to check next bank efuse */ - if (efuse_addr < retU2) - break;/* don't need to check next bank. */ - } - retU2 = ((bank - 1) * EFUSE_BT_REAL_BANK_CONTENT_LEN) + efuse_addr; - - fakeBTEfuseUsedBytes = retU2; - RTW_INFO("%s: CurrentSize=%d\n", __func__, retU2); - return retU2; -} - - -static u8 -hal_BT_EfusePgCheckAvailableAddr( - PADAPTER pAdapter, - u8 bPseudoTest) -{ - u16 max_available = EFUSE_BT_REAL_CONTENT_LEN - EFUSE_PROTECT_BYTES_BANK; - u16 current_size = 0; - - RTW_INFO("%s: max_available=%d\n", __func__, max_available); - current_size = hal_EfuseGetCurrentSize_BT(pAdapter, bPseudoTest); - if (current_size >= max_available) { - RTW_INFO("%s: Error!! current_size(%d)>max_available(%d)\n", __func__, current_size, max_available); - return _FALSE; - } - return _TRUE; -} - -u8 EfusePgPacketWrite_BT( - PADAPTER pAdapter, - u8 offset, - u8 word_en, - u8 *pData, - u8 bPseudoTest) -{ - PGPKT_STRUCT targetPkt; - u16 startAddr = 0; - u8 efuseType = EFUSE_BT; - - if (!hal_BT_EfusePgCheckAvailableAddr(pAdapter, bPseudoTest)) - return _FALSE; - - hal_EfuseConstructPGPkt(offset, word_en, pData, &targetPkt); - - if (!hal_EfusePartialWriteCheck(pAdapter, efuseType, &startAddr, &targetPkt, bPseudoTest)) - return _FALSE; - - if (!hal_EfusePgPacketWriteHeader(pAdapter, efuseType, &startAddr, &targetPkt, bPseudoTest)) - return _FALSE; - - if (!hal_EfusePgPacketWriteData(pAdapter, efuseType, &startAddr, &targetPkt, bPseudoTest)) - return _FALSE; - - return _TRUE; -} - - -#else /* !RTW_HALMAC */ /* ------------------------------------------------------------------------------ */ #define REG_EFUSE_CTRL 0x0030 #define EFUSE_CTRL REG_EFUSE_CTRL /* E-Fuse Control. */ @@ -2182,7 +1142,7 @@ Efuse_InitSomeVar( _rtw_memset((void *)&fakeEfuseModifiedMap[0], 0xff, EFUSE_MAX_MAP_LEN); for (i = 0; i < EFUSE_MAX_BT_BANK; i++) - _rtw_memset((void *)&BTEfuseContent[i][0], EFUSE_MAX_HW_SIZE, 0xff); + _rtw_memset((void *)&BTEfuseContent[i][0], 0xff, EFUSE_MAX_HW_SIZE); _rtw_memset((void *)&BTEfuseInitMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN); _rtw_memset((void *)&BTEfuseModifiedMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN); @@ -2191,7 +1151,7 @@ Efuse_InitSomeVar( _rtw_memset((void *)&fakeBTEfuseInitMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN); _rtw_memset((void *)&fakeBTEfuseModifiedMap[0], 0xff, EFUSE_BT_MAX_MAP_LEN); } -#endif /* !RTW_HALMAC */ + /* 11/16/2008 MH Add description. Get current efuse area enabled word!!. */ u8 Efuse_CalculateWordCnts(u8 word_en) @@ -2271,33 +1231,6 @@ void EFUSE_ShadowMapUpdate( { PHAL_DATA_TYPE pHalData = GET_HAL_DATA(pAdapter); u16 mapLen = 0; -#ifdef RTW_HALMAC - u8 *efuse_map = NULL; - int err; - - - mapLen = EEPROM_MAX_SIZE; - efuse_map = pHalData->efuse_eeprom_data; - /* efuse default content is 0xFF */ - _rtw_memset(efuse_map, 0xFF, EEPROM_MAX_SIZE); - - EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, bPseudoTest); - if (!mapLen) { - RTW_WARN("%s: fail to get efuse size!\n", __func__); - mapLen = EEPROM_MAX_SIZE; - } - if (mapLen > EEPROM_MAX_SIZE) { - RTW_WARN("%s: size of efuse data(%d) is large than expected(%d)!\n", - __func__, mapLen, EEPROM_MAX_SIZE); - mapLen = EEPROM_MAX_SIZE; - } - - if (pHalData->bautoload_fail_flag == _FALSE) { - err = rtw_halmac_read_logical_efuse_map(adapter_to_dvobj(pAdapter), efuse_map, mapLen); - if (err) - RTW_ERR("%s: fail to get efuse map!\n", __func__); - } -#else /* !RTW_HALMAC */ EFUSE_GetEfuseDefinition(pAdapter, efuseType, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, bPseudoTest); if (pHalData->bautoload_fail_flag == _TRUE) @@ -2315,10 +1248,6 @@ void EFUSE_ShadowMapUpdate( #endif } - /* PlatformMoveMemory((void *)&pHalData->EfuseMap[EFUSE_MODIFY_MAP][0], */ - /* (void *)&pHalData->EfuseMap[EFUSE_INIT_MAP][0], mapLen); */ -#endif /* !RTW_HALMAC */ - rtw_dump_cur_efuse(pAdapter); } /* EFUSE_ShadowMapUpdate */