linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/14] clean up efuse reading
@ 2022-07-09 17:09 Martin Kaiser
  2022-07-09 17:09 ` [PATCH 01/14] staging: r8188eu: remove unused eeprom defines Martin Kaiser
                   ` (13 more replies)
  0 siblings, 14 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 01/14] staging: r8188eu: remove unused eeprom defines
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:09 ` [PATCH 02/14] staging: r8188eu: remove EepromOrEfuse from struct eeprom_priv Martin Kaiser
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

Remove some eeprom-related defines which are not used by the r8188eu
driver. This driver uses BOOT_FROM_EEPROM and EEPROM_EN instead of the
defines that this patch removes.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/include/rtl8188e_spec.h | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/r8188eu/include/rtl8188e_spec.h b/drivers/staging/r8188eu/include/rtl8188e_spec.h
index ce5dd2e5b72a..9e7b1f89037c 100644
--- a/drivers/staging/r8188eu/include/rtl8188e_spec.h
+++ b/drivers/staging/r8188eu/include/rtl8188e_spec.h
@@ -426,12 +426,6 @@
 #define	MAX_MSS_DENSITY_2T		0x13
 #define	MAX_MSS_DENSITY_1T		0x0A
 
-/*  EEPROM enable when set 1 */
-#define	CmdEEPROM_En			BIT(5)
-/*  System EEPROM select, 0: boot from E-FUSE, 1: The EEPROM used is 9346 */
-#define	CmdEERPOMSEL			BIT(4)
-#define	Cmd9346CR_9356SEL		BIT(4)
-
 /*        8192C GPIO MUX Configuration Register (offset 0x40, 4 byte) */
 #define	GPIOSEL_GPIO			0
 #define	GPIOSEL_ENBT			BIT(5)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 02/14] staging: r8188eu: remove EepromOrEfuse from struct eeprom_priv
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
  2022-07-09 17:09 ` [PATCH 01/14] staging: r8188eu: remove unused eeprom defines Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:09 ` [PATCH 03/14] staging: r8188eu: remove eeprom function prototypes Martin Kaiser
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

The EepromOrEfuse flag in struct eeprom_priv is used only in the
ReadAdapterInfo8188EU function. We can remove EepromOrEfuse from struct
eeprom_priv.

As the meaning of EepromOrEfuse isn't obvious, there is a macro
is_boot_from_eeprom that's used for checking the value. We don't need the
macro, writing the check as !(eeValue & BOOT_FROM_EEPROM) makes it clear
what is checked.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/hal/usb_halinit.c    | 3 +--
 drivers/staging/r8188eu/include/hal_intf.h   | 2 --
 drivers/staging/r8188eu/include/rtw_eeprom.h | 1 -
 3 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/usb_halinit.c b/drivers/staging/r8188eu/hal/usb_halinit.c
index 1a08de85a6ae..2bfd9751c685 100644
--- a/drivers/staging/r8188eu/hal/usb_halinit.c
+++ b/drivers/staging/r8188eu/hal/usb_halinit.c
@@ -937,10 +937,9 @@ void ReadAdapterInfo8188EU(struct adapter *Adapter)
 	if (res)
 		return;
 
-	eeprom->EepromOrEfuse		= (eeValue & BOOT_FROM_EEPROM);
 	eeprom->bautoload_fail_flag	= !(eeValue & EEPROM_EN);
 
-	if (!is_boot_from_eeprom(Adapter))
+	if (!(eeValue & BOOT_FROM_EEPROM))
 		EFUSE_ShadowMapUpdate(Adapter);
 
 	/* parse the eeprom/efuse content */
diff --git a/drivers/staging/r8188eu/include/hal_intf.h b/drivers/staging/r8188eu/include/hal_intf.h
index b81144932d9a..fc972d65189f 100644
--- a/drivers/staging/r8188eu/include/hal_intf.h
+++ b/drivers/staging/r8188eu/include/hal_intf.h
@@ -21,8 +21,6 @@ enum hw_variables {
 
 typedef s32 (*c2h_id_filter)(u8 id);
 
-#define is_boot_from_eeprom(adapter) (adapter->eeprompriv.EepromOrEfuse)
-
 void rtl8188eu_interface_configure(struct adapter *adapt);
 void ReadAdapterInfo8188EU(struct adapter *Adapter);
 void rtl8188eu_init_default_value(struct adapter *adapt);
diff --git a/drivers/staging/r8188eu/include/rtw_eeprom.h b/drivers/staging/r8188eu/include/rtw_eeprom.h
index d8d48ace356c..40c61f7a03be 100644
--- a/drivers/staging/r8188eu/include/rtw_eeprom.h
+++ b/drivers/staging/r8188eu/include/rtw_eeprom.h
@@ -12,7 +12,6 @@
 struct eeprom_priv {
 	u8		bautoload_fail_flag;
 	u8		mac_addr[ETH_ALEN] __aligned(2); /* PermanentAddress */
-	u8		EepromOrEfuse;
 	u8		efuse_eeprom_data[HWSET_MAX_SIZE_512] __aligned(4);
 };
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 03/14] staging: r8188eu: remove eeprom function prototypes
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
  2022-07-09 17:09 ` [PATCH 01/14] staging: r8188eu: remove unused eeprom defines Martin Kaiser
  2022-07-09 17:09 ` [PATCH 02/14] staging: r8188eu: remove EepromOrEfuse from struct eeprom_priv Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:09 ` [PATCH 04/14] staging: r8188eu: merge EFUSE_ShadowMapUpdate with its caller Martin Kaiser
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

Remove prototypes for non-existing eeprom functions. It seems that r8188eu
has efuses but no eeprom.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/include/rtw_eeprom.h | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/r8188eu/include/rtw_eeprom.h b/drivers/staging/r8188eu/include/rtw_eeprom.h
index 40c61f7a03be..0a8792428927 100644
--- a/drivers/staging/r8188eu/include/rtw_eeprom.h
+++ b/drivers/staging/r8188eu/include/rtw_eeprom.h
@@ -15,10 +15,4 @@ struct eeprom_priv {
 	u8		efuse_eeprom_data[HWSET_MAX_SIZE_512] __aligned(4);
 };
 
-void eeprom_write16(struct adapter *padapter, u16 reg, u16 data);
-u16 eeprom_read16(struct adapter *padapter, u16 reg);
-void read_eeprom_content(struct adapter *padapter);
-void eeprom_read_sz(struct adapter *adapt, u16 reg, u8 *data, u32 sz);
-void read_eeprom_content_by_attrib(struct adapter *padapter);
-
 #endif  /* __RTL871X_EEPROM_H__ */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 04/14] staging: r8188eu: merge EFUSE_ShadowMapUpdate with its caller
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (2 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 03/14] staging: r8188eu: remove eeprom function prototypes Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:09 ` [PATCH 05/14] staging: r8188eu: use a local buffer for efuse data Martin Kaiser
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

Merge the EFUSE_ShadowMapUpdate function into ReadAdapterInfo8188EU, which
is the only caller.

Merging the two functions makes it clearer that eeprom->efuse_eeprom_data
is in fact a temporary buffer that stores info read from efuses.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_efuse.c    | 30 ---------------------
 drivers/staging/r8188eu/hal/usb_halinit.c   | 11 ++++++--
 drivers/staging/r8188eu/include/rtw_efuse.h |  2 --
 3 files changed, 9 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_efuse.c b/drivers/staging/r8188eu/core/rtw_efuse.c
index 8005ed8d3a20..df9534dd25cb 100644
--- a/drivers/staging/r8188eu/core/rtw_efuse.c
+++ b/drivers/staging/r8188eu/core/rtw_efuse.c
@@ -72,33 +72,3 @@ ReadEFuseByte(
 
 	/* FIXME: return an error to caller */
 }
-
-/*-----------------------------------------------------------------------------
- * Function:	EFUSE_ShadowMapUpdate
- *
- * Overview:	Transfer current EFUSE content to shadow init and modify map.
- *
- * Input:       NONE
- *
- * Output:      NONE
- *
- * Return:      NONE
- *
- * Revised History:
- * When			Who		Remark
- * 11/13/2008	MHC		Create Version 0.
- *
- *---------------------------------------------------------------------------*/
-void EFUSE_ShadowMapUpdate(struct adapter *pAdapter)
-{
-	struct eeprom_priv *pEEPROM = &pAdapter->eeprompriv;
-
-	if (pEEPROM->bautoload_fail_flag) {
-		memset(pEEPROM->efuse_eeprom_data, 0xFF, EFUSE_MAP_LEN_88E);
-		return;
-	}
-
-	rtl8188e_EfusePowerSwitch(pAdapter, true);
-	rtl8188e_ReadEFuse(pAdapter, 0, EFUSE_MAP_LEN_88E, pEEPROM->efuse_eeprom_data);
-	rtl8188e_EfusePowerSwitch(pAdapter, false);
-}
diff --git a/drivers/staging/r8188eu/hal/usb_halinit.c b/drivers/staging/r8188eu/hal/usb_halinit.c
index 2bfd9751c685..18c2817bf1e3 100644
--- a/drivers/staging/r8188eu/hal/usb_halinit.c
+++ b/drivers/staging/r8188eu/hal/usb_halinit.c
@@ -939,8 +939,15 @@ void ReadAdapterInfo8188EU(struct adapter *Adapter)
 
 	eeprom->bautoload_fail_flag	= !(eeValue & EEPROM_EN);
 
-	if (!(eeValue & BOOT_FROM_EEPROM))
-		EFUSE_ShadowMapUpdate(Adapter);
+	if (!(eeValue & BOOT_FROM_EEPROM)) {
+		if (eeprom->bautoload_fail_flag) {
+			memset(eeprom->efuse_eeprom_data, 0xFF, EFUSE_MAP_LEN_88E);
+		} else {
+			rtl8188e_EfusePowerSwitch(Adapter, true);
+			rtl8188e_ReadEFuse(Adapter, 0, EFUSE_MAP_LEN_88E, eeprom->efuse_eeprom_data);
+			rtl8188e_EfusePowerSwitch(Adapter, false);
+		}
+	}
 
 	/* parse the eeprom/efuse content */
 	Hal_EfuseParseIDCode88E(Adapter, eeprom->efuse_eeprom_data);
diff --git a/drivers/staging/r8188eu/include/rtw_efuse.h b/drivers/staging/r8188eu/include/rtw_efuse.h
index 2daf69f554d5..3d688a0e6dfb 100644
--- a/drivers/staging/r8188eu/include/rtw_efuse.h
+++ b/drivers/staging/r8188eu/include/rtw_efuse.h
@@ -8,6 +8,4 @@
 
 void ReadEFuseByte(struct adapter *adapter, u16 _offset, u8 *pbuf);
 
-void EFUSE_ShadowMapUpdate(struct adapter *adapter);
-
 #endif
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 05/14] staging: r8188eu: use a local buffer for efuse data
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (3 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 04/14] staging: r8188eu: merge EFUSE_ShadowMapUpdate with its caller Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-12 12:25   ` Dan Carpenter
  2022-07-09 17:09 ` [PATCH 06/14] staging: r8188eu: always initialise efuse buffer with 0xff Martin Kaiser
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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 <martin@kaiser.cx>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 06/14] staging: r8188eu: always initialise efuse buffer with 0xff
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (4 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 05/14] staging: r8188eu: use a local buffer for efuse data Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:09 ` [PATCH 07/14] staging: r8188eu: use memcpy for fallback mac address Martin Kaiser
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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 <martin@kaiser.cx>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 07/14] staging: r8188eu: use memcpy for fallback mac address
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (5 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 06/14] staging: r8188eu: always initialise efuse buffer with 0xff Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-12 16:28   ` Joe Perches
  2022-07-09 17:09 ` [PATCH 08/14] staging: r8188eu: merge ReadEFuseByIC into rtl8188e_ReadEFuse Martin Kaiser
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 08/14] staging: r8188eu: merge ReadEFuseByIC into rtl8188e_ReadEFuse
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (6 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 07/14] staging: r8188eu: use memcpy for fallback mac address Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:09 ` [PATCH 09/14] staging: r8188eu: txpktbuf_bndy is always 0 Martin Kaiser
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 09/14] staging: r8188eu: txpktbuf_bndy is always 0
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (7 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 08/14] staging: r8188eu: merge ReadEFuseByIC into rtl8188e_ReadEFuse Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:09 ` [PATCH 10/14] staging: r8188eu: offset is always 0 in rtl8188e_ReadEFuse Martin Kaiser
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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 <martin@kaiser.cx>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 10/14] staging: r8188eu: offset is always 0 in rtl8188e_ReadEFuse
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (8 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 09/14] staging: r8188eu: txpktbuf_bndy is always 0 Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:09 ` [PATCH 11/14] staging: r8188eu: offset is always 0 in iol_read_efuse Martin Kaiser
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 11/14] staging: r8188eu: offset is always 0 in iol_read_efuse
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (9 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 10/14] staging: r8188eu: offset is always 0 in rtl8188e_ReadEFuse Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:09 ` [PATCH 12/14] staging: r8188eu: _offset is always 0 in efuse_phymap_to_logical Martin Kaiser
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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 <martin@kaiser.cx>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 12/14] staging: r8188eu: _offset is always 0 in efuse_phymap_to_logical
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (10 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 11/14] staging: r8188eu: offset is always 0 in iol_read_efuse Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:09 ` [PATCH 13/14] staging: r8188eu: efuse_utilized is never read Martin Kaiser
  2022-07-09 17:10 ` [PATCH 14/14] staging: r8188eu: the bcnhead parameter is always 0 Martin Kaiser
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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 <martin@kaiser.cx>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 13/14] staging: r8188eu: efuse_utilized is never read
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (11 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 12/14] staging: r8188eu: _offset is always 0 in efuse_phymap_to_logical Martin Kaiser
@ 2022-07-09 17:09 ` Martin Kaiser
  2022-07-09 17:10 ` [PATCH 14/14] staging: r8188eu: the bcnhead parameter is always 0 Martin Kaiser
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 14/14] staging: r8188eu: the bcnhead parameter is always 0
  2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
                   ` (12 preceding siblings ...)
  2022-07-09 17:09 ` [PATCH 13/14] staging: r8188eu: efuse_utilized is never read Martin Kaiser
@ 2022-07-09 17:10 ` Martin Kaiser
  13 siblings, 0 replies; 18+ messages in thread
From: Martin Kaiser @ 2022-07-09 17:10 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

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 <martin@kaiser.cx>
---
 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


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 05/14] staging: r8188eu: use a local buffer for efuse data
  2022-07-09 17:09 ` [PATCH 05/14] staging: r8188eu: use a local buffer for efuse data Martin Kaiser
@ 2022-07-12 12:25   ` Dan Carpenter
  2022-07-12 13:45     ` Larry Finger
  0 siblings, 1 reply; 18+ messages in thread
From: Dan Carpenter @ 2022-07-12 12:25 UTC (permalink / raw)
  To: Martin Kaiser
  Cc: Greg Kroah-Hartman, Larry Finger, Phillip Potter,
	Michael Straube, Pavel Skripkin, linux-staging, linux-kernel

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 <martin@kaiser.cx>
> ---
>  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


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 05/14] staging: r8188eu: use a local buffer for efuse data
  2022-07-12 12:25   ` Dan Carpenter
@ 2022-07-12 13:45     ` Larry Finger
  0 siblings, 0 replies; 18+ messages in thread
From: Larry Finger @ 2022-07-12 13:45 UTC (permalink / raw)
  To: Dan Carpenter, Martin Kaiser
  Cc: Greg Kroah-Hartman, Phillip Potter, Michael Straube,
	Pavel Skripkin, linux-staging, linux-kernel

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 <martin@kaiser.cx>
>> ---
>>   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


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 07/14] staging: r8188eu: use memcpy for fallback mac address
  2022-07-09 17:09 ` [PATCH 07/14] staging: r8188eu: use memcpy for fallback mac address Martin Kaiser
@ 2022-07-12 16:28   ` Joe Perches
  0 siblings, 0 replies; 18+ messages in thread
From: Joe Perches @ 2022-07-12 16:28 UTC (permalink / raw)
  To: Martin Kaiser, Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel

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);


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-07-12 16:29 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-09 17:09 [PATCH 00/14] clean up efuse reading Martin Kaiser
2022-07-09 17:09 ` [PATCH 01/14] staging: r8188eu: remove unused eeprom defines Martin Kaiser
2022-07-09 17:09 ` [PATCH 02/14] staging: r8188eu: remove EepromOrEfuse from struct eeprom_priv Martin Kaiser
2022-07-09 17:09 ` [PATCH 03/14] staging: r8188eu: remove eeprom function prototypes Martin Kaiser
2022-07-09 17:09 ` [PATCH 04/14] staging: r8188eu: merge EFUSE_ShadowMapUpdate with its caller Martin Kaiser
2022-07-09 17:09 ` [PATCH 05/14] staging: r8188eu: use a local buffer for efuse data Martin Kaiser
2022-07-12 12:25   ` Dan Carpenter
2022-07-12 13:45     ` Larry Finger
2022-07-09 17:09 ` [PATCH 06/14] staging: r8188eu: always initialise efuse buffer with 0xff Martin Kaiser
2022-07-09 17:09 ` [PATCH 07/14] staging: r8188eu: use memcpy for fallback mac address Martin Kaiser
2022-07-12 16:28   ` Joe Perches
2022-07-09 17:09 ` [PATCH 08/14] staging: r8188eu: merge ReadEFuseByIC into rtl8188e_ReadEFuse Martin Kaiser
2022-07-09 17:09 ` [PATCH 09/14] staging: r8188eu: txpktbuf_bndy is always 0 Martin Kaiser
2022-07-09 17:09 ` [PATCH 10/14] staging: r8188eu: offset is always 0 in rtl8188e_ReadEFuse Martin Kaiser
2022-07-09 17:09 ` [PATCH 11/14] staging: r8188eu: offset is always 0 in iol_read_efuse Martin Kaiser
2022-07-09 17:09 ` [PATCH 12/14] staging: r8188eu: _offset is always 0 in efuse_phymap_to_logical Martin Kaiser
2022-07-09 17:09 ` [PATCH 13/14] staging: r8188eu: efuse_utilized is never read Martin Kaiser
2022-07-09 17:10 ` [PATCH 14/14] staging: r8188eu: the bcnhead parameter is always 0 Martin Kaiser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).