2022-07-09 17:11:26

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 00/14] clean up efuse reading

Simplify the code that reads config data from the efuses.

Martin Kaiser (14):
staging: r8188eu: remove unused eeprom defines
staging: r8188eu: remove EepromOrEfuse from struct eeprom_priv
staging: r8188eu: remove eeprom function prototypes
staging: r8188eu: merge EFUSE_ShadowMapUpdate with its caller
staging: r8188eu: use a local buffer for efuse data
staging: r8188eu: always initialise efuse buffer with 0xff
staging: r8188eu: use memcpy for fallback mac address
staging: r8188eu: merge ReadEFuseByIC into rtl8188e_ReadEFuse
staging: r8188eu: txpktbuf_bndy is always 0
staging: r8188eu: offset is always 0 in rtl8188e_ReadEFuse
staging: r8188eu: offset is always 0 in iol_read_efuse
staging: r8188eu: _offset is always 0 in efuse_phymap_to_logical
staging: r8188eu: efuse_utilized is never read
staging: r8188eu: the bcnhead parameter is always 0

drivers/staging/r8188eu/core/rtw_efuse.c | 30 ------------
.../staging/r8188eu/hal/rtl8188e_hal_init.c | 47 ++++---------------
drivers/staging/r8188eu/hal/usb_halinit.c | 33 +++++++------
drivers/staging/r8188eu/include/hal_intf.h | 4 +-
.../staging/r8188eu/include/rtl8188e_spec.h | 6 ---
drivers/staging/r8188eu/include/rtw_eeprom.h | 10 ----
drivers/staging/r8188eu/include/rtw_efuse.h | 2 -
7 files changed, 29 insertions(+), 103 deletions(-)

--
2.30.2


2022-07-09 17:11:37

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 08/14] staging: r8188eu: merge ReadEFuseByIC into rtl8188e_ReadEFuse

The rtl8188e_ReadEFuse function is just a wrapper to call ReadEFuseByIC.
Copy ReadEFuseByIC into rtl8188e_ReadEFuse and remove ReadEFuseByIC.

Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/hal/rtl8188e_hal_init.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
index 5b65313e0b9d..0cb653002660 100644
--- a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
+++ b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
@@ -531,7 +531,7 @@ static void Hal_EfuseReadEFuse88E(struct adapter *Adapter,
kfree(eFuseWord);
}

-static void ReadEFuseByIC(struct adapter *Adapter, u16 _offset, u16 _size_byte, u8 *pbuf)
+void rtl8188e_ReadEFuse(struct adapter *Adapter, u16 _offset, u16 _size_byte, u8 *pbuf)
{
int ret = _FAIL;
if (rtw_IOL_applied(Adapter)) {
@@ -548,11 +548,6 @@ static void ReadEFuseByIC(struct adapter *Adapter, u16 _offset, u16 _size_byte,
Hal_EfuseReadEFuse88E(Adapter, _offset, _size_byte, pbuf);
}

-void rtl8188e_ReadEFuse(struct adapter *Adapter, u16 _offset, u16 _size_byte, u8 *pbuf)
-{
- ReadEFuseByIC(Adapter, _offset, _size_byte, pbuf);
-}
-
void rtl8188e_read_chip_version(struct adapter *padapter)
{
u32 value32;
--
2.30.2

2022-07-09 17:28:37

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 11/14] staging: r8188eu: offset is always 0 in iol_read_efuse

The offset parameter of iol_read_efuse is always 0. Remove the
parameter and use 0 in the function body.

Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/hal/rtl8188e_hal_init.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
index 674ba420a272..f552b9adece3 100644
--- a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
+++ b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
@@ -299,7 +299,7 @@ static int efuse_read_phymap_from_txpktbuf(
return 0;
}

-static s32 iol_read_efuse(struct adapter *padapter, u16 offset, u16 size_byte, u8 *logical_map)
+static s32 iol_read_efuse(struct adapter *padapter, u16 size_byte, u8 *logical_map)
{
s32 status = _FAIL;
u8 physical_map[512];
@@ -311,7 +311,7 @@ static s32 iol_read_efuse(struct adapter *padapter, u16 offset, u16 size_byte, u
status = iol_execute(padapter, CMD_READ_EFUSE_MAP);
if (status == _SUCCESS)
efuse_read_phymap_from_txpktbuf(padapter, 0, physical_map, &size);
- efuse_phymap_to_logical(physical_map, offset, size_byte, logical_map);
+ efuse_phymap_to_logical(physical_map, 0, size_byte, logical_map);
return status;
}

@@ -538,7 +538,7 @@ void rtl8188e_ReadEFuse(struct adapter *Adapter, u16 _size_byte, u8 *pbuf)
rtl8188eu_InitPowerOn(Adapter);

iol_mode_enable(Adapter, 1);
- ret = iol_read_efuse(Adapter, 0, _size_byte, pbuf);
+ ret = iol_read_efuse(Adapter, _size_byte, pbuf);
iol_mode_enable(Adapter, 0);

if (_SUCCESS == ret)
--
2.30.2

2022-07-09 17:28:59

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 06/14] staging: r8188eu: always initialise efuse buffer with 0xff

If BOOT_FROM_EEPROM is set, efuse_buf is not initialised before it is
passed to functions that read from it.

The buffer will be filled with 0x00 in this case like all local variables.
However, the parsing functions expect the buffer to be filled with 0xFF if
reading eeprom/efuse data failed. Fill the buffer with 0xFF before we try
to read the data.

Please note that this problem existed before we started using a local
buffer. Adapter->eeprompriv->efuse_eeprom_data was allocated as a part of
struct adapter by a vzalloc call in rtw_usb_if1_init.

Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/hal/usb_halinit.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/usb_halinit.c b/drivers/staging/r8188eu/hal/usb_halinit.c
index 807d8ce8cbfc..258ab963cf8a 100644
--- a/drivers/staging/r8188eu/hal/usb_halinit.c
+++ b/drivers/staging/r8188eu/hal/usb_halinit.c
@@ -940,14 +940,12 @@ void ReadAdapterInfo8188EU(struct adapter *Adapter)

eeprom->bautoload_fail_flag = !(eeValue & EEPROM_EN);

- if (!(eeValue & BOOT_FROM_EEPROM)) {
- if (eeprom->bautoload_fail_flag) {
- memset(efuse_buf, 0xFF, sizeof(efuse_buf));
- } else {
- rtl8188e_EfusePowerSwitch(Adapter, true);
- rtl8188e_ReadEFuse(Adapter, 0, EFUSE_MAP_LEN_88E, efuse_buf);
- rtl8188e_EfusePowerSwitch(Adapter, false);
- }
+ memset(efuse_buf, 0xFF, sizeof(efuse_buf));
+
+ if (!(eeValue & BOOT_FROM_EEPROM) && !eeprom->bautoload_fail_flag) {
+ rtl8188e_EfusePowerSwitch(Adapter, true);
+ rtl8188e_ReadEFuse(Adapter, 0, EFUSE_MAP_LEN_88E, efuse_buf);
+ rtl8188e_EfusePowerSwitch(Adapter, false);
}

/* parse the eeprom/efuse content */
--
2.30.2

2022-07-09 17:29:18

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 13/14] staging: r8188eu: efuse_utilized is never read

The efuse_utilized variable in function efuse_phymap_to_logical is
written to but never read. Remove it.

Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/hal/rtl8188e_hal_init.c | 9 ---------
1 file changed, 9 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
index 87ebfb013193..ddda3f994fa7 100644
--- a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
+++ b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
@@ -91,7 +91,6 @@ efuse_phymap_to_logical(u8 *phymap, u16 _size_byte, u8 *pbuf)
u8 offset, wren;
u16 i, j;
u16 **eFuseWord = NULL;
- u16 efuse_utilized = 0;
u8 u1temp = 0;

efuseTbl = kzalloc(EFUSE_MAP_LEN_88E, GFP_KERNEL);
@@ -113,7 +112,6 @@ efuse_phymap_to_logical(u8 *phymap, u16 _size_byte, u8 *pbuf)
/* */
rtemp8 = *(phymap + eFuse_Addr);
if (rtemp8 != 0xFF) {
- efuse_utilized++;
eFuse_Addr++;
} else {
goto exit;
@@ -151,13 +149,11 @@ efuse_phymap_to_logical(u8 *phymap, u16 _size_byte, u8 *pbuf)
if (!(wren & 0x01)) {
rtemp8 = *(phymap + eFuse_Addr);
eFuse_Addr++;
- efuse_utilized++;
eFuseWord[offset][i] = (rtemp8 & 0xff);
if (eFuse_Addr >= EFUSE_REAL_CONTENT_LEN_88E)
break;
rtemp8 = *(phymap + eFuse_Addr);
eFuse_Addr++;
- efuse_utilized++;
eFuseWord[offset][i] |= (((u16)rtemp8 << 8) & 0xff00);

if (eFuse_Addr >= EFUSE_REAL_CONTENT_LEN_88E)
@@ -170,7 +166,6 @@ efuse_phymap_to_logical(u8 *phymap, u16 _size_byte, u8 *pbuf)
rtemp8 = *(phymap + eFuse_Addr);

if (rtemp8 != 0xFF && (eFuse_Addr < EFUSE_REAL_CONTENT_LEN_88E)) {
- efuse_utilized++;
eFuse_Addr++;
}
}
@@ -190,10 +185,6 @@ efuse_phymap_to_logical(u8 *phymap, u16 _size_byte, u8 *pbuf)
/* */
memcpy(pbuf, efuseTbl, _size_byte);

- /* */
- /* 5. Calculate Efuse utilization. */
- /* */
-
exit:
kfree(efuseTbl);
kfree(eFuseWord);
--
2.30.2

2022-07-09 17:30:07

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 05/14] staging: r8188eu: use a local buffer for efuse data

The efuse_eeprom_data array in struct eeprom_priv is used only by
ReadAdapterInfo8188EU. We can remove efuse_eeprom_data and use a local
buffer instead.

Use EFUSE_MAP_LEN_88E as buffer size. Its value is the same as
HWSET_MAX_SIZE_512. The functions that access the buffer use
EFUSE_MAP_LEN_88E for its size.

Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/hal/usb_halinit.c | 23 ++++++++++----------
drivers/staging/r8188eu/include/rtw_eeprom.h | 3 ---
2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/usb_halinit.c b/drivers/staging/r8188eu/hal/usb_halinit.c
index 18c2817bf1e3..807d8ce8cbfc 100644
--- a/drivers/staging/r8188eu/hal/usb_halinit.c
+++ b/drivers/staging/r8188eu/hal/usb_halinit.c
@@ -929,6 +929,7 @@ void ReadAdapterInfo8188EU(struct adapter *Adapter)
{
struct eeprom_priv *eeprom = &Adapter->eeprompriv;
struct led_priv *ledpriv = &Adapter->ledpriv;
+ u8 efuse_buf[EFUSE_MAP_LEN_88E] __aligned(4);
u8 eeValue;
int res;

@@ -941,24 +942,24 @@ void ReadAdapterInfo8188EU(struct adapter *Adapter)

if (!(eeValue & BOOT_FROM_EEPROM)) {
if (eeprom->bautoload_fail_flag) {
- memset(eeprom->efuse_eeprom_data, 0xFF, EFUSE_MAP_LEN_88E);
+ memset(efuse_buf, 0xFF, sizeof(efuse_buf));
} else {
rtl8188e_EfusePowerSwitch(Adapter, true);
- rtl8188e_ReadEFuse(Adapter, 0, EFUSE_MAP_LEN_88E, eeprom->efuse_eeprom_data);
+ rtl8188e_ReadEFuse(Adapter, 0, EFUSE_MAP_LEN_88E, efuse_buf);
rtl8188e_EfusePowerSwitch(Adapter, false);
}
}

/* parse the eeprom/efuse content */
- Hal_EfuseParseIDCode88E(Adapter, eeprom->efuse_eeprom_data);
- Hal_EfuseParseMACAddr_8188EU(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
-
- Hal_ReadPowerSavingMode88E(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
- Hal_ReadTxPowerInfo88E(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
- rtl8188e_EfuseParseChnlPlan(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
- Hal_EfuseParseXtal_8188E(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
- Hal_ReadAntennaDiversity88E(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
- Hal_ReadThermalMeter_88E(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
+ Hal_EfuseParseIDCode88E(Adapter, efuse_buf);
+ Hal_EfuseParseMACAddr_8188EU(Adapter, efuse_buf, eeprom->bautoload_fail_flag);
+
+ Hal_ReadPowerSavingMode88E(Adapter, efuse_buf, eeprom->bautoload_fail_flag);
+ Hal_ReadTxPowerInfo88E(Adapter, efuse_buf, eeprom->bautoload_fail_flag);
+ rtl8188e_EfuseParseChnlPlan(Adapter, efuse_buf, eeprom->bautoload_fail_flag);
+ Hal_EfuseParseXtal_8188E(Adapter, efuse_buf, eeprom->bautoload_fail_flag);
+ Hal_ReadAntennaDiversity88E(Adapter, efuse_buf, eeprom->bautoload_fail_flag);
+ Hal_ReadThermalMeter_88E(Adapter, efuse_buf, eeprom->bautoload_fail_flag);

ledpriv->bRegUseLed = true;
}
diff --git a/drivers/staging/r8188eu/include/rtw_eeprom.h b/drivers/staging/r8188eu/include/rtw_eeprom.h
index 0a8792428927..94d735b1d0db 100644
--- a/drivers/staging/r8188eu/include/rtw_eeprom.h
+++ b/drivers/staging/r8188eu/include/rtw_eeprom.h
@@ -7,12 +7,9 @@
#include "osdep_service.h"
#include "drv_types.h"

-#define HWSET_MAX_SIZE_512 512
-
struct eeprom_priv {
u8 bautoload_fail_flag;
u8 mac_addr[ETH_ALEN] __aligned(2); /* PermanentAddress */
- u8 efuse_eeprom_data[HWSET_MAX_SIZE_512] __aligned(4);
};

#endif /* __RTL871X_EEPROM_H__ */
--
2.30.2

2022-07-09 17:30:21

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 09/14] staging: r8188eu: txpktbuf_bndy is always 0

The only caller of iol_read_efuse sets the txpktbuf_bndy parameter to 0.
Remove the parameter from iol_read_efuse and use 0 in the function body.

Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/hal/rtl8188e_hal_init.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
index 0cb653002660..24699e99edff 100644
--- a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
+++ b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
@@ -299,18 +299,18 @@ static int efuse_read_phymap_from_txpktbuf(
return 0;
}

-static s32 iol_read_efuse(struct adapter *padapter, u8 txpktbuf_bndy, u16 offset, u16 size_byte, u8 *logical_map)
+static s32 iol_read_efuse(struct adapter *padapter, u16 offset, u16 size_byte, u8 *logical_map)
{
s32 status = _FAIL;
u8 physical_map[512];
u16 size = 512;

- rtw_write8(padapter, REG_TDECTRL + 1, txpktbuf_bndy);
+ rtw_write8(padapter, REG_TDECTRL + 1, 0);
memset(physical_map, 0xFF, 512);
rtw_write8(padapter, REG_PKT_BUFF_ACCESS_CTRL, TXPKT_BUF_SELECT);
status = iol_execute(padapter, CMD_READ_EFUSE_MAP);
if (status == _SUCCESS)
- efuse_read_phymap_from_txpktbuf(padapter, txpktbuf_bndy, physical_map, &size);
+ efuse_read_phymap_from_txpktbuf(padapter, 0, physical_map, &size);
efuse_phymap_to_logical(physical_map, offset, size_byte, logical_map);
return status;
}
@@ -538,7 +538,7 @@ void rtl8188e_ReadEFuse(struct adapter *Adapter, u16 _offset, u16 _size_byte, u8
rtl8188eu_InitPowerOn(Adapter);

iol_mode_enable(Adapter, 1);
- ret = iol_read_efuse(Adapter, 0, _offset, _size_byte, pbuf);
+ ret = iol_read_efuse(Adapter, _offset, _size_byte, pbuf);
iol_mode_enable(Adapter, 0);

if (_SUCCESS == ret)
--
2.30.2

2022-07-09 17:30:56

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 14/14] staging: r8188eu: the bcnhead parameter is always 0

The only caller of efuse_read_phymap_from_txpktbuf sets bcnhead to 0.
Remove this function parameter and simplify the function body.

Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/hal/rtl8188e_hal_init.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
index ddda3f994fa7..fe477438899e 100644
--- a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
+++ b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
@@ -193,13 +193,11 @@ efuse_phymap_to_logical(u8 *phymap, u16 _size_byte, u8 *pbuf)
/* FIXME: add error handling in callers */
static int efuse_read_phymap_from_txpktbuf(
struct adapter *adapter,
- int bcnhead, /* beacon head, where FW store len(2-byte) and efuse physical map. */
u8 *content, /* buffer to store efuse physical map */
u16 *size /* for efuse content: the max byte to read. will update to byte read */
)
{
unsigned long timeout;
- u16 dbg_addr = 0;
__le32 lo32 = 0, hi32 = 0;
u16 len = 0, count = 0;
int i = 0, res;
@@ -208,20 +206,10 @@ static int efuse_read_phymap_from_txpktbuf(
u8 *pos = content;
u32 reg32;

- if (bcnhead < 0) { /* if not valid */
- res = rtw_read8(adapter, REG_TDECTRL + 1, &reg);
- if (res)
- return res;
-
- bcnhead = reg;
- }
-
rtw_write8(adapter, REG_PKT_BUFF_ACCESS_CTRL, TXPKT_BUF_SELECT);

- dbg_addr = bcnhead * 128 / 8; /* 8-bytes addressing */
-
while (1) {
- rtw_write16(adapter, REG_PKTBUF_DBG_ADDR, dbg_addr + i);
+ rtw_write16(adapter, REG_PKTBUF_DBG_ADDR, i);

rtw_write8(adapter, REG_TXPKTBUF_DBG, 0);
timeout = jiffies + msecs_to_jiffies(1000);
@@ -300,7 +288,7 @@ static s32 iol_read_efuse(struct adapter *padapter, u16 size_byte, u8 *logical_m
rtw_write8(padapter, REG_PKT_BUFF_ACCESS_CTRL, TXPKT_BUF_SELECT);
status = iol_execute(padapter, CMD_READ_EFUSE_MAP);
if (status == _SUCCESS)
- efuse_read_phymap_from_txpktbuf(padapter, 0, physical_map, &size);
+ efuse_read_phymap_from_txpktbuf(padapter, physical_map, &size);
efuse_phymap_to_logical(physical_map, size_byte, logical_map);
return status;
}
--
2.30.2

2022-07-09 17:31:57

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 10/14] staging: r8188eu: offset is always 0 in rtl8188e_ReadEFuse

The offset parameter of rtl8188e_ReadEFuse is always 0. Remove the
parameter and use 0 in the function body.

Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/hal/rtl8188e_hal_init.c | 6 +++---
drivers/staging/r8188eu/hal/usb_halinit.c | 2 +-
drivers/staging/r8188eu/include/hal_intf.h | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
index 24699e99edff..674ba420a272 100644
--- a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
+++ b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
@@ -531,21 +531,21 @@ static void Hal_EfuseReadEFuse88E(struct adapter *Adapter,
kfree(eFuseWord);
}

-void rtl8188e_ReadEFuse(struct adapter *Adapter, u16 _offset, u16 _size_byte, u8 *pbuf)
+void rtl8188e_ReadEFuse(struct adapter *Adapter, u16 _size_byte, u8 *pbuf)
{
int ret = _FAIL;
if (rtw_IOL_applied(Adapter)) {
rtl8188eu_InitPowerOn(Adapter);

iol_mode_enable(Adapter, 1);
- ret = iol_read_efuse(Adapter, _offset, _size_byte, pbuf);
+ ret = iol_read_efuse(Adapter, 0, _size_byte, pbuf);
iol_mode_enable(Adapter, 0);

if (_SUCCESS == ret)
return;
}

- Hal_EfuseReadEFuse88E(Adapter, _offset, _size_byte, pbuf);
+ Hal_EfuseReadEFuse88E(Adapter, 0, _size_byte, pbuf);
}

void rtl8188e_read_chip_version(struct adapter *padapter)
diff --git a/drivers/staging/r8188eu/hal/usb_halinit.c b/drivers/staging/r8188eu/hal/usb_halinit.c
index 5151cded145b..1821ec4440cd 100644
--- a/drivers/staging/r8188eu/hal/usb_halinit.c
+++ b/drivers/staging/r8188eu/hal/usb_halinit.c
@@ -942,7 +942,7 @@ void ReadAdapterInfo8188EU(struct adapter *Adapter)

if (!(eeValue & BOOT_FROM_EEPROM) && !eeprom->bautoload_fail_flag) {
rtl8188e_EfusePowerSwitch(Adapter, true);
- rtl8188e_ReadEFuse(Adapter, 0, EFUSE_MAP_LEN_88E, efuse_buf);
+ rtl8188e_ReadEFuse(Adapter, EFUSE_MAP_LEN_88E, efuse_buf);
rtl8188e_EfusePowerSwitch(Adapter, false);
}

diff --git a/drivers/staging/r8188eu/include/hal_intf.h b/drivers/staging/r8188eu/include/hal_intf.h
index fc972d65189f..a8499c643c76 100644
--- a/drivers/staging/r8188eu/include/hal_intf.h
+++ b/drivers/staging/r8188eu/include/hal_intf.h
@@ -27,7 +27,7 @@ void rtl8188eu_init_default_value(struct adapter *adapt);
void rtl8188e_SetHalODMVar(struct adapter *Adapter, void *pValue1, bool bSet);
u32 rtl8188eu_InitPowerOn(struct adapter *adapt);
void rtl8188e_EfusePowerSwitch(struct adapter *pAdapter, u8 PwrState);
-void rtl8188e_ReadEFuse(struct adapter *Adapter, u16 _offset, u16 _size_byte, u8 *pbuf);
+void rtl8188e_ReadEFuse(struct adapter *Adapter, u16 _size_byte, u8 *pbuf);

void hal_notch_filter_8188e(struct adapter *adapter, bool enable);

--
2.30.2

2022-07-09 17:37:01

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 12/14] staging: r8188eu: _offset is always 0 in efuse_phymap_to_logical

The _offset parameter of iol_read_efuse is always 0. Remove the
parameter and use 0 in the function body.

We can now replace the bytewise copy from efuseTbl to pbuf with memcpy.

Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/hal/rtl8188e_hal_init.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
index f552b9adece3..87ebfb013193 100644
--- a/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
+++ b/drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
@@ -83,7 +83,7 @@ static s32 iol_InitLLTTable(struct adapter *padapter, u8 txpktbuf_bndy)
}

static void
-efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
+efuse_phymap_to_logical(u8 *phymap, u16 _size_byte, u8 *pbuf)
{
u8 *efuseTbl = NULL;
u8 rtemp8;
@@ -188,8 +188,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
/* */
/* 4. Copy from Efuse map to output pointer memory!!! */
/* */
- for (i = 0; i < _size_byte; i++)
- pbuf[i] = efuseTbl[_offset + i];
+ memcpy(pbuf, efuseTbl, _size_byte);

/* */
/* 5. Calculate Efuse utilization. */
@@ -311,7 +310,7 @@ static s32 iol_read_efuse(struct adapter *padapter, u16 size_byte, u8 *logical_m
status = iol_execute(padapter, CMD_READ_EFUSE_MAP);
if (status == _SUCCESS)
efuse_read_phymap_from_txpktbuf(padapter, 0, physical_map, &size);
- efuse_phymap_to_logical(physical_map, 0, size_byte, logical_map);
+ efuse_phymap_to_logical(physical_map, size_byte, logical_map);
return status;
}

--
2.30.2

2022-07-09 17:37:03

by Martin Kaiser

[permalink] [raw]
Subject: [PATCH 07/14] staging: r8188eu: use memcpy for fallback mac address

Use memcpy to store the fallback mac address in eeprom->mac_addr. Do not
copy byte by byte.

Signed-off-by: Martin Kaiser <[email protected]>
---
drivers/staging/r8188eu/hal/usb_halinit.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/usb_halinit.c b/drivers/staging/r8188eu/hal/usb_halinit.c
index 258ab963cf8a..5151cded145b 100644
--- a/drivers/staging/r8188eu/hal/usb_halinit.c
+++ b/drivers/staging/r8188eu/hal/usb_halinit.c
@@ -912,13 +912,11 @@ unsigned int rtl8188eu_inirp_init(struct adapter *Adapter)

static void Hal_EfuseParseMACAddr_8188EU(struct adapter *adapt, u8 *hwinfo, bool AutoLoadFail)
{
- u16 i;
u8 sMacAddr[6] = {0x00, 0xE0, 0x4C, 0x81, 0x88, 0x02};
struct eeprom_priv *eeprom = &adapt->eeprompriv;

if (AutoLoadFail) {
- for (i = 0; i < 6; i++)
- eeprom->mac_addr[i] = sMacAddr[i];
+ memcpy(eeprom->mac_addr, sMacAddr, ETH_ALEN);
} else {
/* Read Permanent MAC address */
memcpy(eeprom->mac_addr, &hwinfo[EEPROM_MAC_ADDR_88EU], ETH_ALEN);
--
2.30.2

2022-07-12 12:58:30

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 05/14] staging: r8188eu: use a local buffer for efuse data

On Sat, Jul 09, 2022 at 07:09:51PM +0200, Martin Kaiser wrote:
> The efuse_eeprom_data array in struct eeprom_priv is used only by
> ReadAdapterInfo8188EU. We can remove efuse_eeprom_data and use a local
> buffer instead.
>
> Use EFUSE_MAP_LEN_88E as buffer size. Its value is the same as
> HWSET_MAX_SIZE_512. The functions that access the buffer use
> EFUSE_MAP_LEN_88E for its size.
>
> Signed-off-by: Martin Kaiser <[email protected]>
> ---
> drivers/staging/r8188eu/hal/usb_halinit.c | 23 ++++++++++----------
> drivers/staging/r8188eu/include/rtw_eeprom.h | 3 ---
> 2 files changed, 12 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/hal/usb_halinit.c b/drivers/staging/r8188eu/hal/usb_halinit.c
> index 18c2817bf1e3..807d8ce8cbfc 100644
> --- a/drivers/staging/r8188eu/hal/usb_halinit.c
> +++ b/drivers/staging/r8188eu/hal/usb_halinit.c
> @@ -929,6 +929,7 @@ void ReadAdapterInfo8188EU(struct adapter *Adapter)
> {
> struct eeprom_priv *eeprom = &Adapter->eeprompriv;
> struct led_priv *ledpriv = &Adapter->ledpriv;
> + u8 efuse_buf[EFUSE_MAP_LEN_88E] __aligned(4);

This is 512 bytes. We used to be slightly worried about declaring 512
bytes on the stack, but I'm not sure the situation now.

regards,
dan carpenter

2022-07-12 14:00:03

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH 05/14] staging: r8188eu: use a local buffer for efuse data

On 7/12/22 07:25, Dan Carpenter wrote:
> On Sat, Jul 09, 2022 at 07:09:51PM +0200, Martin Kaiser wrote:
>> The efuse_eeprom_data array in struct eeprom_priv is used only by
>> ReadAdapterInfo8188EU. We can remove efuse_eeprom_data and use a local
>> buffer instead.
>>
>> Use EFUSE_MAP_LEN_88E as buffer size. Its value is the same as
>> HWSET_MAX_SIZE_512. The functions that access the buffer use
>> EFUSE_MAP_LEN_88E for its size.
>>
>> Signed-off-by: Martin Kaiser <[email protected]>
>> ---
>> drivers/staging/r8188eu/hal/usb_halinit.c | 23 ++++++++++----------
>> drivers/staging/r8188eu/include/rtw_eeprom.h | 3 ---
>> 2 files changed, 12 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/staging/r8188eu/hal/usb_halinit.c b/drivers/staging/r8188eu/hal/usb_halinit.c
>> index 18c2817bf1e3..807d8ce8cbfc 100644
>> --- a/drivers/staging/r8188eu/hal/usb_halinit.c
>> +++ b/drivers/staging/r8188eu/hal/usb_halinit.c
>> @@ -929,6 +929,7 @@ void ReadAdapterInfo8188EU(struct adapter *Adapter)
>> {
>> struct eeprom_priv *eeprom = &Adapter->eeprompriv;
>> struct led_priv *ledpriv = &Adapter->ledpriv;
>> + u8 efuse_buf[EFUSE_MAP_LEN_88E] __aligned(4);
>
> This is 512 bytes. We used to be slightly worried about declaring 512
> bytes on the stack, but I'm not sure the situation now.
>

I think we should still avoid using an on-stack buffer of that size. It is
better to use a local pointer, and kmalloc() the buffer and free it before exit.

Larry

2022-07-12 16:38:35

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 07/14] staging: r8188eu: use memcpy for fallback mac address

On Sat, 2022-07-09 at 19:09 +0200, Martin Kaiser wrote:
> Use memcpy to store the fallback mac address in eeprom->mac_addr. Do not
> copy byte by byte.
[]
> diff --git a/drivers/staging/r8188eu/hal/usb_halinit.c b/drivers/staging/r8188eu/hal/usb_halinit.c
[]
> @@ -912,13 +912,11 @@ unsigned int rtl8188eu_inirp_init(struct adapter *Adapter)
>
> static void Hal_EfuseParseMACAddr_8188EU(struct adapter *adapt, u8 *hwinfo, bool AutoLoadFail)
> {
> - u16 i;
> u8 sMacAddr[6] = {0x00, 0xE0, 0x4C, 0x81, 0x88, 0x02};

static const sMacAddr[ETH_ALEN] = {...};

But maybe this should use eth_random_addr instead as there might
be more than one of these in a network.

> struct eeprom_priv *eeprom = &adapt->eeprompriv;
>
> if (AutoLoadFail) {
> - for (i = 0; i < 6; i++)
> - eeprom->mac_addr[i] = sMacAddr[i];
> + memcpy(eeprom->mac_addr, sMacAddr, ETH_ALEN);
> } else {
> /* Read Permanent MAC address */
> memcpy(eeprom->mac_addr, &hwinfo[EEPROM_MAC_ADDR_88EU], ETH_ALEN);

So perhaps something like:

{
static const u8 sMacAddr[ETH_ALEN] = {
0x00, 0xE0, 0x4C, 0x81, 0x88, 0x02
};

/* Not ether_addr_copy - EEPROM_MAC_ADDR_88EU isn't __aligned(2) */

memcpy(adapt->eeprompriv.mac_addr,
AutoLoadFail ? sMacAddr : &hwinfo[EEPROM_MAC_ADDR_88EU],
ETH_ALEN);
}

or maybe:

{
if (AutoLoadFail)
eth_random_addr(adapt->eeprompriv.mac_addr);
else
memcpy(adapt->eeprompriv.mac_addr,
&hwinfo[EEPROM_MAC_ADDR_88EU], ETH_ALEN);