Skip to contentSkip to conversation

staging: r8188eu: remove SetHwReg8188EU()

PATCH In review Michael Straube 3 participants 8 messages Jul 15, 2022 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: r8188eu: remove SetHwReg8188EU()

This series finally removes SetHwReg8188EU().

Tested on x86_64 with Inter-Tech DMG-02.

Michael Straube (5):
staging: r8188eu: remove HW_VAR_SET_OPMODE from SetHwReg8188EU()
staging: r8188eu: remove unused parameter from correct_TSF()
staging: r8188eu: remove unused parameter from update_TSF()
staging: r8188eu: make update_TSF() and correct_TSF() static
staging: r8188eu: remove SetHwReg8188EU()

 drivers/staging/r8188eu/core/rtw_mlme_ext.c   | 163 +++++++++++++++++-
 drivers/staging/r8188eu/core/rtw_wlan_util.c  |  20 ---
 drivers/staging/r8188eu/hal/usb_halinit.c     | 152 +---------------
 drivers/staging/r8188eu/include/hal_intf.h    |   7 -
 .../staging/r8188eu/include/rtw_mlme_ext.h    |   5 +-
 5 files changed, 161 insertions(+), 186 deletions(-)
Signature · 1 line
2.37.0
#1 lore raw

PATCH 1/5 staging: r8188eu: remove HW_VAR_SET_OPMODE from SetHwReg8188EU()

Remove the HW_VAR_SET_OPMODE case from SetHwReg8188EU() and move the functions that are called by that case to rtw_mlme_ext.c. This is part of the ongoing effort to get rid of SetHwReg8188EU().

---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c   | 103 +++++++++++++++-
 drivers/staging/r8188eu/hal/usb_halinit.c     | 111 +-----------------
 drivers/staging/r8188eu/include/hal_intf.h    |   1 -
 .../staging/r8188eu/include/rtw_mlme_ext.h    |   2 +
 4 files changed, 107 insertions(+), 110 deletions(-)
drivers/staging/r8188eu/core/rtw_mlme_ext.c +102 -1
index 771910763fec..0edcf84db16d 100644
@@ -5674,6 +5674,107 @@ void clear_beacon_valid_bit(struct adapter *adapter)
 	rtw_write8(adapter, REG_TDECTRL + 2, reg | BIT(0));
 }
 
+void rtw_resume_tx_beacon(struct adapter *adapt)
+{
+	struct hal_data_8188e *haldata = &adapt->haldata;
+
+	/*  2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */
+	/*  which should be read from register to a global variable. */
+
+	rtw_write8(adapt, REG_FWHW_TXQ_CTRL + 2, (haldata->RegFwHwTxQCtrl) | BIT(6));
+	haldata->RegFwHwTxQCtrl |= BIT(6);
+	rtw_write8(adapt, REG_TBTT_PROHIBIT + 1, 0xff);
+	haldata->RegReg542 |= BIT(0);
+	rtw_write8(adapt, REG_TBTT_PROHIBIT + 2, haldata->RegReg542);
+}
+
+void rtw_stop_tx_beacon(struct adapter *adapt)
+{
+	struct hal_data_8188e *haldata = &adapt->haldata;
+
+	/*  2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */
+	/*  which should be read from register to a global variable. */
+
+	rtw_write8(adapt, REG_FWHW_TXQ_CTRL + 2, (haldata->RegFwHwTxQCtrl) & (~BIT(6)));
+	haldata->RegFwHwTxQCtrl &= (~BIT(6));
+	rtw_write8(adapt, REG_TBTT_PROHIBIT + 1, 0x64);
+	haldata->RegReg542 &= ~(BIT(0));
+	rtw_write8(adapt, REG_TBTT_PROHIBIT + 2, haldata->RegReg542);
+
+	 /* todo: CheckFwRsvdPageContent(Adapter);  2010.06.23. Added by tynli. */
+}
+
+static void rtw_set_opmode(struct adapter *adapter, u8 mode)
+{
+	u8 val8;
+	int res;
+
+	/*  disable Port0 TSF update */
+	res = rtw_read8(adapter, REG_BCN_CTRL, &val8);
+	if (res)
+		return;
+
+	rtw_write8(adapter, REG_BCN_CTRL, val8 | BIT(4));
+
+	/*  set net_type */
+	res = rtw_read8(adapter, MSR, &val8);
+	if (res)
+		return;
+
+	val8 &= 0x0c;
+	val8 |= mode;
+	rtw_write8(adapter, MSR, val8);
+
+	if ((mode == _HW_STATE_STATION_) || (mode == _HW_STATE_NOLINK_)) {
+		rtw_stop_tx_beacon(adapter);
+
+		rtw_write8(adapter, REG_BCN_CTRL, 0x19);/* disable atim wnd */
+	} else if (mode == _HW_STATE_ADHOC_) {
+		rtw_resume_tx_beacon(adapter);
+		rtw_write8(adapter, REG_BCN_CTRL, 0x1a);
+	} else if (mode == _HW_STATE_AP_) {
+		rtw_resume_tx_beacon(adapter);
+
+		rtw_write8(adapter, REG_BCN_CTRL, 0x12);
+
+		/* Set RCR */
+		rtw_write32(adapter, REG_RCR, 0x7000208e);/* CBSSID_DATA must set to 0,reject ICV_ERR packet */
+		/* enable to rx data frame */
+		rtw_write16(adapter, REG_RXFLTMAP2, 0xFFFF);
+		/* enable to rx ps-poll */
+		rtw_write16(adapter, REG_RXFLTMAP1, 0x0400);
+
+		/* Beacon Control related register for first time */
+		rtw_write8(adapter, REG_BCNDMATIM, 0x02); /*  2ms */
+
+		rtw_write8(adapter, REG_ATIMWND, 0x0a); /*  10ms */
+		rtw_write16(adapter, REG_BCNTCFG, 0x00);
+		rtw_write16(adapter, REG_TBTT_PROHIBIT, 0xff04);
+		rtw_write16(adapter, REG_TSFTR_SYN_OFFSET, 0x7fff);/*  +32767 (~32ms) */
+
+		/* reset TSF */
+		rtw_write8(adapter, REG_DUAL_TSF_RST, BIT(0));
+
+		/* BIT(3) - If set 0, hw will clr bcnq when tx becon ok/fail or port 0 */
+		res = rtw_read8(adapter, REG_MBID_NUM, &val8);
+		if (res)
+			return;
+
+		rtw_write8(adapter, REG_MBID_NUM, val8 | BIT(3) | BIT(4));
+
+		/* enable BCN0 Function for if1 */
+		/* don't enable update TSF0 for if1 (due to TSF update when beacon/probe rsp are received) */
+		rtw_write8(adapter, REG_BCN_CTRL, (DIS_TSF_UDT0_NORMAL_CHIP | EN_BCN_FUNCTION | BIT(1)));
+
+		/* dis BCN1 ATIM  WND if if2 is station */
+		res = rtw_read8(adapter, REG_BCN_CTRL_1, &val8);
+		if (res)
+			return;
+
+		rtw_write8(adapter, REG_BCN_CTRL_1, val8 | BIT(0));
+	}
+}
+
 /****************************************************************************
 
 Following are some utitity fuctions for WiFi MLME
@@ -7142,7 +7243,7 @@ u8 setopmode_hdl(struct adapter *padapter, u8 *pbuf)
 		type = _HW_STATE_NOLINK_;
 	}
 
-	SetHwReg8188EU(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type));
+	rtw_set_opmode(padapter, type);
 
 	return H2C_SUCCESS;
 }
drivers/staging/r8188eu/hal/usb_halinit.c +3 -108

141 lines not on this page · raw message

drivers/staging/r8188eu/include/hal_intf.h +0 -1
index 819d0dc6e6dc..e1dfd621a5cb 100644
@@ -9,7 +9,6 @@
 #include "Hal8188EPhyCfg.h"
 
 enum hw_variables {
-	HW_VAR_SET_OPMODE,
 	HW_VAR_CORRECT_TSF,
 };
 
drivers/staging/r8188eu/include/rtw_mlme_ext.h +2 -0
index c630700ea657..28416d1bd15c 100644
@@ -532,6 +532,8 @@ unsigned int send_delba(struct adapter *padapter, u8 initiator, u8 *addr);
 unsigned int send_beacon(struct adapter *padapter);
 bool get_beacon_valid_bit(struct adapter *adapter);
 void clear_beacon_valid_bit(struct adapter *adapter);
+void rtw_resume_tx_beacon(struct adapter *adapt);
+void rtw_stop_tx_beacon(struct adapter *adapt);
 
 void start_clnt_assoc(struct adapter *padapter);
 void start_clnt_auth(struct adapter *padapter);
Signature · 1 line
2.37.0
#2 lore raw

PATCH 2/5 staging: r8188eu: remove unused parameter from correct_TSF()

In reply to Michael Straube

The parameter 'pmlmeext' of correct_TSF() is unused. Remove it.

---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c    | 4 ++--
 drivers/staging/r8188eu/core/rtw_wlan_util.c   | 2 +-
 drivers/staging/r8188eu/include/rtw_mlme_ext.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/r8188eu/core/rtw_mlme_ext.c +2 -2
index 0edcf84db16d..985cb3b4ba30 100644
@@ -6893,7 +6893,7 @@ void mlmeext_joinbss_event_callback(struct adapter *padapter, int join_res)
 
 	if ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE) {
 		/*  correcting TSF */
-		correct_TSF(padapter, pmlmeext);
+		correct_TSF(padapter);
 	}
 	rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_CONNECT, 0);
 }
@@ -6908,7 +6908,7 @@ void mlmeext_sta_add_event_callback(struct adapter *padapter, struct sta_info *p
 			/* nothing to do */
 		} else { /* adhoc client */
 			/*  correcting TSF */
-			correct_TSF(padapter, pmlmeext);
+			correct_TSF(padapter);
 
 			/* start beacon */
 			if (send_beacon(padapter) == _FAIL) {
drivers/staging/r8188eu/core/rtw_wlan_util.c +1 -1
index b48e0b9dfd7b..7b705e2ea04a 100644
@@ -1586,7 +1586,7 @@ void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
 	pmlmeext->TSFValue |= le32_to_cpu(*pbuf);
 }
 
-void correct_TSF(struct adapter *padapter, struct mlme_ext_priv *pmlmeext)
+void correct_TSF(struct adapter *padapter)
 {
 	SetHwReg8188EU(padapter, HW_VAR_CORRECT_TSF, NULL);
 }
drivers/staging/r8188eu/include/rtw_mlme_ext.h +1 -1
index 28416d1bd15c..2110affc180f 100644
@@ -597,7 +597,7 @@ bool cckrates_included(unsigned char *rate, int ratelen);
 bool cckratesonly_included(unsigned char *rate, int ratelen);
 
 void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len);
-void correct_TSF(struct adapter *padapter, struct mlme_ext_priv *pmlmeext);
+void correct_TSF(struct adapter *padapter);
 
 struct cmd_hdl {
 	uint	parmsize;
Signature · 1 line
2.37.0
#3 lore raw

PATCH 3/5 staging: r8188eu: remove unused parameter from update_TSF()

In reply to Michael Straube

The parameter 'len' of update_TSF() is unused. Remove it.

---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c    | 4 ++--
 drivers/staging/r8188eu/core/rtw_wlan_util.c   | 2 +-
 drivers/staging/r8188eu/include/rtw_mlme_ext.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/r8188eu/core/rtw_mlme_ext.c +2 -2
index 985cb3b4ba30..c23be5d9eaaf 100644
@@ -582,7 +582,7 @@ unsigned int OnBeacon(struct adapter *padapter, struct recv_frame *precv_frame)
 			pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pframe + sizeof(struct ieee80211_hdr_3addr), len - sizeof(struct ieee80211_hdr_3addr));
 
 			/* update TSF Value */
-			update_TSF(pmlmeext, pframe, len);
+			update_TSF(pmlmeext, pframe);
 
 			/* start auth */
 			start_clnt_auth(padapter);
@@ -625,7 +625,7 @@ unsigned int OnBeacon(struct adapter *padapter, struct recv_frame *precv_frame)
 				}
 
 				/* update TSF Value */
-				update_TSF(pmlmeext, pframe, len);
+				update_TSF(pmlmeext, pframe);
 
 				/* report sta add event */
 				report_add_sta_event(padapter, GetAddr2Ptr(pframe), cam_idx);
drivers/staging/r8188eu/core/rtw_wlan_util.c +1 -1
index 7b705e2ea04a..9e920a320d71 100644
@@ -1571,7 +1571,7 @@ int update_sta_support_rate(struct adapter *padapter, u8 *pvar_ie, uint var_ie_l
 	return _SUCCESS;
 }
 
-void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len)
+void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe)
 {
 	u8 *pIE;
 	__le32 *pbuf;
drivers/staging/r8188eu/include/rtw_mlme_ext.h +1 -1
index 2110affc180f..54384b4c6b1a 100644
@@ -596,7 +596,7 @@ void addba_timer_hdl(struct sta_info *psta);
 bool cckrates_included(unsigned char *rate, int ratelen);
 bool cckratesonly_included(unsigned char *rate, int ratelen);
 
-void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len);
+void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe);
 void correct_TSF(struct adapter *padapter);
 
 struct cmd_hdl {
Signature · 1 line
2.37.0
#4 lore raw

Re: [PATCH 3/5] staging: r8188eu: remove unused parameter from update_TSF()

Quoted 2 lines · Michael Straube

The parameter 'len' of update_TSF() is unused. Remove it.

I really do think this driver should do a lot of more checking on len.

It's not totally clear to me if this len can even be trusted though...

regards,
dan carpenter

#5 lore raw

PATCH 4/5 staging: r8188eu: make update_TSF() and correct_TSF() static

In reply to Michael Straube

The functions update_TSF() and correct_TSF() are only used in rtw_mlme_ext.c. Make them static.

---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c   | 20 +++++++++++++++++++
 drivers/staging/r8188eu/core/rtw_wlan_util.c  | 20 -------------------
 .../staging/r8188eu/include/rtw_mlme_ext.h    |  3 ---
 3 files changed, 20 insertions(+), 23 deletions(-)
drivers/staging/r8188eu/core/rtw_mlme_ext.c +20 -0
index c23be5d9eaaf..7b69d9ad75e9 100644
@@ -428,6 +428,26 @@ static u32 p2p_listen_state_process(struct adapter *padapter, unsigned char *da)
 	return _SUCCESS;
 }
 
+static void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe)
+{
+	u8 *pIE;
+	__le32 *pbuf;
+
+	pIE = pframe + sizeof(struct ieee80211_hdr_3addr);
+	pbuf = (__le32 *)pIE;
+
+	pmlmeext->TSFValue = le32_to_cpu(*(pbuf + 1));
+
+	pmlmeext->TSFValue = pmlmeext->TSFValue << 32;
+
+	pmlmeext->TSFValue |= le32_to_cpu(*pbuf);
+}
+
+static void correct_TSF(struct adapter *padapter)
+{
+	SetHwReg8188EU(padapter, HW_VAR_CORRECT_TSF, NULL);
+}
+
 /****************************************************************************
 
 Following are the callback functions for each subtype of the management frames
drivers/staging/r8188eu/core/rtw_wlan_util.c +0 -20
index 9e920a320d71..3a002cb6834f 100644
@@ -1571,26 +1571,6 @@ int update_sta_support_rate(struct adapter *padapter, u8 *pvar_ie, uint var_ie_l
 	return _SUCCESS;
 }
 
-void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe)
-{
-	u8 *pIE;
-	__le32 *pbuf;
-
-	pIE = pframe + sizeof(struct ieee80211_hdr_3addr);
-	pbuf = (__le32 *)pIE;
-
-	pmlmeext->TSFValue = le32_to_cpu(*(pbuf + 1));
-
-	pmlmeext->TSFValue = pmlmeext->TSFValue << 32;
-
-	pmlmeext->TSFValue |= le32_to_cpu(*pbuf);
-}
-
-void correct_TSF(struct adapter *padapter)
-{
-	SetHwReg8188EU(padapter, HW_VAR_CORRECT_TSF, NULL);
-}
-
 void beacon_timing_control(struct adapter *padapter)
 {
 	SetBeaconRelatedRegisters8188EUsb(padapter);
drivers/staging/r8188eu/include/rtw_mlme_ext.h +0 -3
index 54384b4c6b1a..bf952755ba35 100644
@@ -596,9 +596,6 @@ void addba_timer_hdl(struct sta_info *psta);
 bool cckrates_included(unsigned char *rate, int ratelen);
 bool cckratesonly_included(unsigned char *rate, int ratelen);
 
-void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe);
-void correct_TSF(struct adapter *padapter);
-
 struct cmd_hdl {
 	uint	parmsize;
 	u8 (*h2cfuns)(struct adapter  *padapter, u8 *pbuf);
Signature · 1 line
2.37.0
#6 lore raw

PATCH 5/5 staging: r8188eu: remove SetHwReg8188EU()

In reply to Michael Straube

Remove the case HW_VAR_CORRECT_TSF from SetHwReg8188EU() and move the functionality to the function that calls SetHwReg8188EU() with HW_VAR_CORRECT_TSF. SetHwReg8188EU() is empty now and we can finally remove it.

---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c | 34 +++++++++++++++-
 drivers/staging/r8188eu/hal/usb_halinit.c   | 45 ---------------------
 drivers/staging/r8188eu/include/hal_intf.h  |  6 ---
 3 files changed, 33 insertions(+), 52 deletions(-)
drivers/staging/r8188eu/core/rtw_mlme_ext.c +33 -1
index 7b69d9ad75e9..32d0e101d0c2 100644
@@ -445,7 +445,39 @@ static void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe)
 
 static void correct_TSF(struct adapter *padapter)
 {
-	SetHwReg8188EU(padapter, HW_VAR_CORRECT_TSF, NULL);
+	u8 reg;
+	int res;
+	u64 tsf;
+	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
+	struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
+
+	tsf = pmlmeext->TSFValue - do_div(pmlmeext->TSFValue,
+					  pmlmeinfo->bcn_interval * 1024) - 1024; /* us */
+
+	if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) ||
+	    ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
+		rtw_stop_tx_beacon(padapter);
+
+	/* disable related TSF function */
+	res = rtw_read8(padapter, REG_BCN_CTRL, &reg);
+	if (res)
+		return;
+
+	rtw_write8(padapter, REG_BCN_CTRL, reg & (~BIT(3)));
+
+	rtw_write32(padapter, REG_TSFTR, tsf);
+	rtw_write32(padapter, REG_TSFTR + 4, tsf >> 32);
+
+	/* enable related TSF function */
+	res = rtw_read8(padapter, REG_BCN_CTRL, &reg);
+	if (res)
+		return;
+
+	rtw_write8(padapter, REG_BCN_CTRL, reg | BIT(3));
+
+	if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) ||
+	    ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
+		rtw_resume_tx_beacon(padapter);
 }
 
 /****************************************************************************
drivers/staging/r8188eu/hal/usb_halinit.c +0 -45

51 lines not on this page · raw message

drivers/staging/r8188eu/include/hal_intf.h +0 -6
index e1dfd621a5cb..ab6856d8a090 100644
@@ -8,10 +8,6 @@
 #include "drv_types.h"
 #include "Hal8188EPhyCfg.h"
 
-enum hw_variables {
-	HW_VAR_CORRECT_TSF,
-};
-
 typedef s32 (*c2h_id_filter)(u8 id);
 
 void rtl8188eu_interface_configure(struct adapter *adapt);
@@ -32,8 +28,6 @@ int rtl8188e_IOL_exec_cmds_sync(struct adapter *adapter,
 
 unsigned int rtl8188eu_inirp_init(struct adapter *Adapter);
 
-void SetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val);
-
 uint rtw_hal_init(struct adapter *padapter);
 uint rtw_hal_deinit(struct adapter *padapter);
 void rtw_hal_stop(struct adapter *padapter);
Signature · 1 line
2.37.0
Tested-by on v1 5/5
#7 lore raw

Hi Michael,

Thus wrote Michael Straube ([email protected]):

Quoted 4 lines

Remove the case HW_VAR_CORRECT_TSF from SetHwReg8188EU() and move the functionality to the function that calls SetHwReg8188EU() with HW_VAR_CORRECT_TSF. SetHwReg8188EU() is empty now and we can finally remove it.

nice work :-)

For the whole series: