staging: rtl8723bs: remove struct _io_ops
cover staging: rtl8723bs: remove struct _io_ops
I don't have hardware. Tested only by compiling.
So, in this series I've attempted to simplify a bunch of abstractions in core/rtw_io.c (and hal/sdio_ops.c and os_dep/sdio_ops_linux.c files).
In general, the logic is as follows:
1. Functions from core/rtw_io.c (with the 'rtw_*' prefix) call functions from hal/sdio_ops.c (with the 'sdio_*' prefix), obtaining them from a pointer in 'struct _io_ops'.
2. Functions from hal/sdio_ops.c convert the passed address (call _cvrt2ftaddr()) and call functions from os_dep/sdio_ops_linux.c (with the 'sd_*' prefix).
3. Only functions from os_dep/sdio_ops_linux.c perform the work we're interested in - they call other functions from the kernel MMC subsystem (sdio_readb(), sdio_writeb(), and so on)
For the rtw_read8() (rtw_write8()) functions, I was able to remove all these abstraction layers (this is the only place where this happens) by directly calling sdio_readb() (sdio_writeb()).
For the rtw_read16() (rtw_write16()) functions, I had to retain the sd_cmd52_read() (sd_cmd52_write()) calls from os_dep/sdio_ops_linux.c, since there are no equivalents for them.
rtw_read32() (rtw_write32()) calls differet read (write) functions depending on the address alignment. I simply pasted everything from sdio_read32() (sdio_write32()) into them.
I described some details in the comments to the corresponding patches.
I also slightly formatted the modified code to avoid creating new checkpatch.pl warnings.
In any case, this will completely eliminate the 'struct _io_ops' and consolidate the reading (writing) code in one place so that error hadling can be found and corrected.
This series is marked as RFC because I need your opinion on it and also maybe someone wants to test it?
Nikolay Kulikov (11):
staging: rtl8723bs: remove unused sdio_local_read()
staging: rtl8723bs: declare helper sdio functions in .h files
staging: rtl8723bs: inline sd_read8() and sdio_read8() into
rtw_read8()
staging: rtl8723bs: inline sdio_read16() into rtw_read16()
staging: rtl8723bs: inline sdio_read32() into rtw_read32()
staging: rtl8723bs: inline sd_write8() and sdio_write8() in
rtw_write8() staging: rtl8723bs: inline sdio_write16() into rtw_write16()
staging: rtl8723bs: inline sdio_write32() into rtw_write32()
staging: rtl8723bs: inline sdio_write_port() into rtw_write_port()
staging: rtl8723bs: remove the empty function set_intf_ops()
staging: rtl8723bs: remove empty struct _io_ops
drivers/staging/rtl8723bs/core/rtw_io.c | 208 +++++++++++----- drivers/staging/rtl8723bs/hal/sdio_ops.c | 235 +----------------- drivers/staging/rtl8723bs/include/rtw_io.h | 16 +- drivers/staging/rtl8723bs/include/sdio_hal.h | 3 + drivers/staging/rtl8723bs/include/sdio_ops.h | 3 - .../rtl8723bs/include/sdio_ops_linux.h | 2 + drivers/staging/rtl8723bs/os_dep/sdio_intf.c | 2 +- .../staging/rtl8723bs/os_dep/sdio_ops_linux.c | 55 +--- 8 files changed, 162 insertions(+), 362 deletions(-)
base-commit: 81f55766523e5293604cb96c5e98d10da345ff33
Signature · 1 line
2.54.0
RFC PATCH 1/11 staging: rtl8723bs: remove unused sdio_local_read()
This function is never called in the driver, so remove it to get rid of dead code.
--- drivers/staging/rtl8723bs/hal/sdio_ops.c | 41 -------------------- drivers/staging/rtl8723bs/include/sdio_ops.h | 1 - 2 files changed, 42 deletions(-)
drivers/staging/rtl8723bs/hal/sdio_ops.c +0 -41
@@ -396,47 +396,6 @@ static s32 _sdio_local_read(return err; } -/* -* Todo: align address to 4 bytes. -*/ -s32 sdio_local_read ( -struct adapter *adapter, -u32 addr, -u32 cnt, -u8 *buf -) -{ -struct intf_hdl *intfhdl; -u8 mac_pwr_ctrl_on; -s32 err; -u8 *tmpbuf; -u32 n; - - intfhdl = &adapter->iopriv.intf; - -hal_sdio_get_cmd_addr_8723b (adapter,SDIO_LOCAL_DEVICE_ID , addr, &addr); - -rtw_hal_get_hwreg (adapter,HW_VAR_APFM_ON_MAC , &mac_pwr_ctrl_on); -if ( - (!mac_pwr_ctrl_on) || - (adapter_to_pwrctl (adapter)->fw_current_in_ps_mode) - ) -return sd_cmd52_read (intfhdl, addr, cnt, buf); - - n =round_up (cnt,4 ); - tmpbuf =kmalloc (n,GFP_ATOMIC ); -if (!tmpbuf) -return -ENOMEM ; - - err =sd_read (intfhdl, addr, n, tmpbuf); -if (!err) -memcpy (buf, tmpbuf, cnt); - -kfree (tmpbuf); - -return err; -} -/* * Todo: align address to 4 bytes. */
drivers/staging/rtl8723bs/include/sdio_ops.h +0 -1
@@ -16,7 +16,6 @@ extern void sdio_set_intf_ops(struct adapter *padapter, struct _io_ops *pops);/* extern void sdio_func1cmd52_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem); */ extern u8 SdioLocalCmd52Read1Byte (struct adapter *padapter,u32 addr);extern void SdioLocalCmd52Write1Byte (struct adapter *padapter,u32 addr,u8 v); -extern s32 sdio_local_read (struct adapter *padapter,u32 addr,u32 cnt,u8 *pbuf);extern s32 sdio_local_write (struct adapter *padapter,u32 addr,u32 cnt,u8 *pbuf);u32 _sdio_read32 (struct adapter *padapter,u32 addr);
Signature · 1 line
2.54.0
RFC PATCH 2/11 staging: rtl8723bs: declare helper sdio functions in .h files
In reply to Nikolay KulikovThese functions may be needed in the future in other files when fixing a large numbrer of abstractions over SDIO in this driver.
--- drivers/staging/rtl8723bs/hal/sdio_ops.c | 5 ++--- drivers/staging/rtl8723bs/include/sdio_hal.h | 3 +++ drivers/staging/rtl8723bs/include/sdio_ops_linux.h | 2 ++ drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-)
drivers/staging/rtl8723bs/hal/sdio_ops.c +2 -3
@@ -13,8 +13,7 @@/* */ /* Creadted by Roger, 2011.01.31. */ /* */ -static void hal_sdio_get_cmd_addr_8723b (struct adapter *adapter,u8 device_id, -u32 addr,u32 *cmdaddr) +void hal_sdio_get_cmd_addr_8723b (struct adapter *adapter,u8 device_id,u32 addr,u32 *cmdaddr) {switch (device_id) {case SDIO_LOCAL_DEVICE_ID :
@@ -85,7 +84,7 @@ static u8 get_deviceid(u32 addr)return devide_id; } -static u32 _cvrt2ftaddr (const u32 addr,u8 *pdevice_id,u16 *poffset) +u32 _cvrt2ftaddr (const u32 addr,u8 *pdevice_id,u16 *poffset) {u8 device_id;u16 offset;
drivers/staging/rtl8723bs/include/sdio_hal.h +3 -0
@@ -7,6 +7,9 @@#ifndef __SDIO_HAL_H__#define __SDIO_HAL_H__ +u32 _cvrt2ftaddr (const u32 addr,u8 *pdevice_id,u16 *poffset); +void hal_sdio_get_cmd_addr_8723b (struct adapter *adapter,u8 device_id,u32 addr,u32 *cmdaddr); +u8 sd_int_isr (struct adapter *padapter);void sd_int_dpc (struct adapter *padapter);void rtw_set_hal_ops (struct adapter *padapter);
drivers/staging/rtl8723bs/include/sdio_ops_linux.h +2 -0
@@ -11,6 +11,8 @@#define SDIO_ERR_VAL16 0xEAEA#define SDIO_ERR_VAL32 0xEAEAEAEA +bool rtw_sdio_claim_host_needed (struct sdio_func *func); +s32 _sd_cmd52_read (struct intf_hdl *pintfhdl,u32 addr,u32 cnt,u8 *pdata);s32 _sd_cmd52_write (struct intf_hdl *pintfhdl,u32 addr,u32 cnt,u8 *pdata);s32 sd_cmd52_read (struct intf_hdl *pintfhdl,u32 addr,u32 cnt,u8 *pdata);
drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c +1 -1
@@ -7,7 +7,7 @@#include <drv_types.h> -static bool rtw_sdio_claim_host_needed (struct sdio_func *func) +bool rtw_sdio_claim_host_needed (struct sdio_func *func) {struct dvobj_priv *dvobj =sdio_get_drvdata (func);struct sdio_data *sdio_data = &dvobj->intf_data;
Signature · 1 line
2.54.0
RFC PATCH 3/11 staging: rtl8723bs: inline sd_read8() and sdio_read8() into rtw_read8()
In reply to Nikolay KulikovThe rtw_read8() func calls sdio_read8(), which performs address conversation and calls sd_read8(), which calls sdio_readb()
Remove this deep level of indirection by directly handling the address translation and the sdio_readb() call from rtw_read8() to significantly reduce the number of abstractions and simplify the code.
--- drivers/staging/rtl8723bs/core/rtw_io.c | 22 +++++++++++---- drivers/staging/rtl8723bs/hal/sdio_ops.c | 10 ------- drivers/staging/rtl8723bs/include/rtw_io.h | 1 - .../staging/rtl8723bs/os_dep/sdio_ops_linux.c | 28 ------------------- 4 files changed, 17 insertions(+), 44 deletions(-)
drivers/staging/rtl8723bs/core/rtw_io.c +17 -5
@@ -27,13 +27,25 @@u8 rtw_read8 (struct adapter *adapter,u32 addr) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -u8 (*_read8)(struct intf_hdl *pintfhdl,u32 addr); +struct sdio_data *sdio = &adapter->dvobj->intf_data; +struct sdio_func *func = sdio->func; +bool claim_needed; +u32 ftaddr; +u8 ret =0 ; + +if (adapter->bSurpriseRemoved) +return ret; + + ftaddr =_cvrt2ftaddr (addr,NULL ,NULL ); + claim_needed =rtw_sdio_claim_host_needed (func); - _read8 = pintfhdl->io_ops._read8; +if (claim_needed) +sdio_claim_host (func); + ret =sdio_readb (func, addr,NULL ); +if (claim_needed) +sdio_release_host (func); -return _read8 (pintfhdl, addr); +return ret; }u16 rtw_read16 (struct adapter *adapter,u32 addr)
drivers/staging/rtl8723bs/hal/sdio_ops.c +0 -10
@@ -124,15 +124,6 @@ u32 _cvrt2ftaddr(const u32 addr, u8 *pdevice_id, u16 *poffset)return ftaddr; } -static u8 sdio_read8 (struct intf_hdl *intfhdl,u32 addr) -{ -u32 ftaddr; - - ftaddr =_cvrt2ftaddr (addr,NULL ,NULL ); - -return sd_read8 (intfhdl, ftaddr,NULL ); -} -static u16 sdio_read16 (struct intf_hdl *intfhdl,u32 addr) {u32 ftaddr;
@@ -347,7 +338,6 @@ static u32 sdio_write_port(void sdio_set_intf_ops (struct adapter *adapter,struct _io_ops *ops) { - ops->_read8 = &sdio_read8; ops->_read16 = &sdio_read16; ops->_read32 = &sdio_read32;
drivers/staging/rtl8723bs/include/rtw_io.h +0 -1
@@ -11,7 +11,6 @@struct intf_hdl ;struct _io_ops { -u8 (*_read8)(struct intf_hdl *pintfhdl,u32 addr);u16 (*_read16)(struct intf_hdl *pintfhdl,u32 addr);u32 (*_read32)(struct intf_hdl *pintfhdl,u32 addr);
drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c +0 -28
@@ -152,34 +152,6 @@ s32 sd_cmd52_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pdata)return err; } -u8 sd_read8 (struct intf_hdl *pintfhdl,u32 addr,s32 *err) -{ -struct adapter *padapter; -struct dvobj_priv *psdiodev; -struct sdio_data *psdio; - -u8 v =0 ; -struct sdio_func *func; -bool claim_needed; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - -if (padapter->bSurpriseRemoved) -return v; - - func = psdio->func; - claim_needed =rtw_sdio_claim_host_needed (func); - -if (claim_needed) -sdio_claim_host (func); - v =sdio_readb (func, addr, err); -if (claim_needed) -sdio_release_host (func); -return v; -} -u32 sd_read32 (struct intf_hdl *pintfhdl,u32 addr,s32 *err) {struct adapter *padapter;
Signature · 1 line
2.54.0
RFC PATCH 4/11 staging: rtl8723bs: inline sdio_read16() into rtw_read16()
In reply to Nikolay Kulikovrtw_read16() is just a wrapper around sdio_read16(), combining them will simplify the code and reduce the number of indirect calls.
--- drivers/staging/rtl8723bs/core/rtw_io.c | 11 ++++++----- drivers/staging/rtl8723bs/hal/sdio_ops.c | 12 ------------ drivers/staging/rtl8723bs/include/rtw_io.h | 1 - 3 files changed, 6 insertions(+), 18 deletions(-)
drivers/staging/rtl8723bs/core/rtw_io.c +6 -5
@@ -50,13 +50,14 @@ u8 rtw_read8(struct adapter *adapter, u32 addr)u16 rtw_read16 (struct adapter *adapter,u32 addr) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -u16 (*_read16)(struct intf_hdl *pintfhdl,u32 addr); +struct intf_hdl *intfhdl = &adapter->iopriv.intf; +__le16 le_tmp; +u32 ftaddr; - _read16 = pintfhdl->io_ops._read16; + ftaddr =_cvrt2ftaddr (addr,NULL ,NULL ); +sd_cmd52_read (intfhdl, ftaddr,2 , (u8 *)&le_tmp); -return _read16 (pintfhdl, addr); +return le16_to_cpu (le_tmp); }u32 rtw_read32 (struct adapter *adapter,u32 addr)
drivers/staging/rtl8723bs/hal/sdio_ops.c +0 -12
@@ -124,17 +124,6 @@ u32 _cvrt2ftaddr(const u32 addr, u8 *pdevice_id, u16 *poffset)return ftaddr; } -static u16 sdio_read16 (struct intf_hdl *intfhdl,u32 addr) -{ -u32 ftaddr; -__le16 le_tmp; - - ftaddr =_cvrt2ftaddr (addr,NULL ,NULL ); -sd_cmd52_read (intfhdl, ftaddr,2 , (u8 *)&le_tmp); - -return le16_to_cpu (le_tmp); -} -static u32 sdio_read32 (struct intf_hdl *intfhdl,u32 addr) {struct adapter *adapter;
@@ -338,7 +327,6 @@ static u32 sdio_write_port(void sdio_set_intf_ops (struct adapter *adapter,struct _io_ops *ops) { - ops->_read16 = &sdio_read16; ops->_read32 = &sdio_read32; ops->_write8 = &sdio_write8;
drivers/staging/rtl8723bs/include/rtw_io.h +0 -1
@@ -11,7 +11,6 @@struct intf_hdl ;struct _io_ops { -u16 (*_read16)(struct intf_hdl *pintfhdl,u32 addr);u32 (*_read32)(struct intf_hdl *pintfhdl,u32 addr);int (*_write8)(struct intf_hdl *pintfhdl,u32 addr,u8 val);
Signature · 1 line
2.54.0
RFC PATCH 5/11 staging: rtl8723bs: inline sdio_read32() into rtw_read32()
In reply to Nikolay Kulikovrtw_read32() is just a wrapper around sdio_read32(), combining them will simplify the code and reduce the number of indirect calls.
--- drivers/staging/rtl8723bs/core/rtw_io.c | 45 ++++++++++++++++---- drivers/staging/rtl8723bs/hal/sdio_ops.c | 48 ---------------------- drivers/staging/rtl8723bs/include/rtw_io.h | 2 - 3 files changed, 38 insertions(+), 57 deletions(-)
drivers/staging/rtl8723bs/core/rtw_io.c +38 -7
@@ -62,13 +62,44 @@ u16 rtw_read16(struct adapter *adapter, u32 addr)u32 rtw_read32 (struct adapter *adapter,u32 addr) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -u32 (*_read32)(struct intf_hdl *pintfhdl,u32 addr); - - _read32 = pintfhdl->io_ops._read32; - -return _read32 (pintfhdl, addr); +struct intf_hdl *intfhdl = &adapter->iopriv.intf; +s32 __maybe_unused err; +u8 device_id, shift; +u8 mac_pwr_ctrl_on; +u32 ftaddr, val; +__le32 le_tmp; +u16 offset; + + ftaddr =_cvrt2ftaddr (addr, &device_id, &offset); + +rtw_hal_get_hwreg (adapter,HW_VAR_APFM_ON_MAC , &mac_pwr_ctrl_on); +if (((device_id ==WLAN_IOREG_DEVICE_ID ) && (offset <0x100 )) || + (!mac_pwr_ctrl_on) || + (adapter_to_pwrctl (adapter)->fw_current_in_ps_mode)) { + err =sd_cmd52_read (intfhdl, ftaddr,4 , (u8 *)&le_tmp); +return le32_to_cpu (le_tmp); + } + +/* 4 bytes alignment */ + shift = ftaddr &0x3 ; +if (shift ==0 ) { + val =sd_read32 (intfhdl, ftaddr,NULL ); + }else { +u8 *tmpbuf; + + tmpbuf =kmalloc (8 ,GFP_ATOMIC ); +if (!tmpbuf) +return SDIO_ERR_VAL32 ; + + ftaddr &= ~(u16 )0x3 ; +sd_read (intfhdl, ftaddr,8 , tmpbuf); +memcpy (&le_tmp, tmpbuf + shift,4 ); + val =le32_to_cpu (le_tmp); + +kfree (tmpbuf); + } + +return val; }int rtw_write8 (struct adapter *adapter,u32 addr,u8 val)
drivers/staging/rtl8723bs/hal/sdio_ops.c +0 -48
60 lines not on this page · raw message
drivers/staging/rtl8723bs/include/rtw_io.h +0 -2
@@ -11,8 +11,6 @@struct intf_hdl ;struct _io_ops { -u32 (*_read32)(struct intf_hdl *pintfhdl,u32 addr); -int (*_write8)(struct intf_hdl *pintfhdl,u32 addr,u8 val);int (*_write16)(struct intf_hdl *pintfhdl,u32 addr,u16 val);int (*_write32)(struct intf_hdl *pintfhdl,u32 addr,u32 val);
Signature · 1 line
2.54.0
RFC PATCH 6/11 staging: rtl8723bs: inline sd_write8() and sdio_write8() in rtw_write8()
In reply to Nikolay KulikovThe rtw_write8() function calls sdio_write8(), which performs address conversion and call sd_write8(), which calls sdio_writeb()
Remove this large number of indirect calls by combining the address conversion and the sdio_writeb() call, which will make the code much easier to understand.
---
I left the RTW_STATUS_CODE() calls for the return value here so as not to change the call site of this function (_SUCCESS/_FAIL are expected there).
This function now returns an error when the condition:
if (adapter->bSurpriseRemoved) return RTW_STATUS_CODE(-ENODEV);
Initially, sd_write8() didn't have this; it returned an uninitialized variable.
drivers/staging/rtl8723bs/core/rtw_io.c | 24 ++++++++++++------ drivers/staging/rtl8723bs/hal/sdio_ops.c | 12 --------- drivers/staging/rtl8723bs/include/rtw_io.h | 1 - .../staging/rtl8723bs/os_dep/sdio_ops_linux.c | 25 ------------------- 4 files changed, 17 insertions(+), 45 deletions(-)
drivers/staging/rtl8723bs/core/rtw_io.c +17 -7
@@ -104,16 +104,26 @@ u32 rtw_read32(struct adapter *adapter, u32 addr)int rtw_write8 (struct adapter *adapter,u32 addr,u8 val) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -int (*_write8)(struct intf_hdl *pintfhdl,u32 addr,u8 val); -int ret; +struct sdio_data *sdio = &adapter->dvobj->intf_data; +struct sdio_func *func; +bool claim_needed; +u32 ftaddr; +s32 err; - _write8 = pintfhdl->io_ops._write8; +if (adapter->bSurpriseRemoved) +return RTW_STATUS_CODE (-ENODEV ); - ret =_write8 (pintfhdl, addr, val); + ftaddr =_cvrt2ftaddr (addr,NULL ,NULL ); + func = sdio->func; + claim_needed =rtw_sdio_claim_host_needed (func); -return RTW_STATUS_CODE (ret); +if (claim_needed) +sdio_claim_host (func); +sdio_writeb (func, val, addr, &err); +if (claim_needed) +sdio_release_host (func); + +return RTW_STATUS_CODE (err); }int rtw_write16 (struct adapter *adapter,u32 addr,u16 val)
drivers/staging/rtl8723bs/hal/sdio_ops.c +0 -12
@@ -124,17 +124,6 @@ u32 _cvrt2ftaddr(const u32 addr, u8 *pdevice_id, u16 *poffset)return ftaddr; } -static s32 sdio_write8 (struct intf_hdl *intfhdl,u32 addr,u8 val) -{ -u32 ftaddr; -s32 err; - - ftaddr =_cvrt2ftaddr (addr,NULL ,NULL ); -sd_write8 (intfhdl, ftaddr, val, &err); - -return err; -} -static s32 sdio_write16 (struct intf_hdl *intfhdl,u32 addr,u16 val) {u32 ftaddr;
@@ -281,7 +270,6 @@ static u32 sdio_write_port(void sdio_set_intf_ops (struct adapter *adapter,struct _io_ops *ops) { - ops->_write8 = &sdio_write8; ops->_write16 = &sdio_write16; ops->_write32 = &sdio_write32; ops->_write_port = &sdio_write_port;
drivers/staging/rtl8723bs/include/rtw_io.h +0 -1
@@ -11,7 +11,6 @@struct intf_hdl ;struct _io_ops { -int (*_write8)(struct intf_hdl *pintfhdl,u32 addr,u8 val);int (*_write16)(struct intf_hdl *pintfhdl,u32 addr,u16 val);int (*_write32)(struct intf_hdl *pintfhdl,u32 addr,u32 val);
drivers/staging/rtl8723bs/os_dep/sdio_ops_linux.c +0 -25
@@ -205,31 +205,6 @@ u32 sd_read32(struct intf_hdl *pintfhdl, u32 addr, s32 *err)return v; } -void sd_write8 (struct intf_hdl *pintfhdl,u32 addr,u8 v,s32 *err) -{ -struct adapter *padapter; -struct dvobj_priv *psdiodev; -struct sdio_data *psdio; -struct sdio_func *func; -bool claim_needed; - - padapter = pintfhdl->padapter; - psdiodev = pintfhdl->pintf_dev; - psdio = &psdiodev->intf_data; - -if (padapter->bSurpriseRemoved) -return ; - - func = psdio->func; - claim_needed =rtw_sdio_claim_host_needed (func); - -if (claim_needed) -sdio_claim_host (func); -sdio_writeb (func, v, addr, err); -if (claim_needed) -sdio_release_host (func); -} -void sd_write32 (struct intf_hdl *pintfhdl,u32 addr,u32 v,s32 *err) {struct adapter *padapter;
Signature · 1 line
2.54.0
RFC PATCH 7/11 staging: rtl8723bs: inline sdio_write16() into rtw_write16()
In reply to Nikolay Kulikovrtw_write16() is just a wrapper around sdio_write16(), so combine them to simplify the code.
---
The return value of this function is never read (I checked with commands
git grep -rn -C2 "\brtw_write16\b" git grep -rn -C2 "= \brtw_write16\b"
from the drivers/staging/rtl8723bs/ directory), so perhaps normal error handling can be done here?
drivers/staging/rtl8723bs/core/rtw_io.c | 12 ++++++------ drivers/staging/rtl8723bs/hal/sdio_ops.c | 11 ----------- drivers/staging/rtl8723bs/include/rtw_io.h | 1 - 3 files changed, 6 insertions(+), 18 deletions(-)
drivers/staging/rtl8723bs/core/rtw_io.c +6 -6
@@ -128,14 +128,14 @@ int rtw_write8(struct adapter *adapter, u32 addr, u8 val)int rtw_write16 (struct adapter *adapter,u32 addr,u16 val) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -int (*_write16)(struct intf_hdl *pintfhdl,u32 addr,u16 val); +struct intf_hdl *intfhdl = &adapter->iopriv.intf; +__le16 le_tmp; +u32 ftaddr;int ret; - _write16 = pintfhdl->io_ops._write16; - - ret =_write16 (pintfhdl, addr, val); + ftaddr =_cvrt2ftaddr (addr,NULL ,NULL ); + le_tmp =cpu_to_le16 (val); + ret =sd_cmd52_write (intfhdl, ftaddr,2 , (u8 *)&le_tmp);return RTW_STATUS_CODE (ret); }
drivers/staging/rtl8723bs/hal/sdio_ops.c +0 -11
@@ -124,16 +124,6 @@ u32 _cvrt2ftaddr(const u32 addr, u8 *pdevice_id, u16 *poffset)return ftaddr; } -static s32 sdio_write16 (struct intf_hdl *intfhdl,u32 addr,u16 val) -{ -u32 ftaddr; -__le16 le_tmp; - - ftaddr =_cvrt2ftaddr (addr,NULL ,NULL ); - le_tmp =cpu_to_le16 (val); -return sd_cmd52_write (intfhdl, ftaddr,2 , (u8 *)&le_tmp); -} -static s32 sdio_write32 (struct intf_hdl *intfhdl,u32 addr,u32 val) {struct adapter *adapter;
@@ -270,7 +260,6 @@ static u32 sdio_write_port(void sdio_set_intf_ops (struct adapter *adapter,struct _io_ops *ops) { - ops->_write16 = &sdio_write16; ops->_write32 = &sdio_write32; ops->_write_port = &sdio_write_port; }
drivers/staging/rtl8723bs/include/rtw_io.h +0 -1
@@ -11,7 +11,6 @@struct intf_hdl ;struct _io_ops { -int (*_write16)(struct intf_hdl *pintfhdl,u32 addr,u16 val);int (*_write32)(struct intf_hdl *pintfhdl,u32 addr,u32 val);u32 (*_write_port)(struct intf_hdl *pintfhdl,u32 addr,u32 cnt,u8 *pmem);
Signature · 1 line
2.54.0
RFC PATCH 8/11 staging: rtl8723bs: inline sdio_write32() into rtw_write32()
In reply to Nikolay Kulikovrtw_write32() is a wrapper around sdio_write32(), combining them will simplify the code and reduce the number of indirect calls.
---
The call sites of rtw_write32() also require _SUCCESS/_FAIL, so we need to use RTW_STATUS_CODE().
drivers/staging/rtl8723bs/core/rtw_io.c | 32 ++++++++++++++---- drivers/staging/rtl8723bs/hal/sdio_ops.c | 39 ---------------------- drivers/staging/rtl8723bs/include/rtw_io.h | 2 -- 3 files changed, 25 insertions(+), 48 deletions(-)
drivers/staging/rtl8723bs/core/rtw_io.c +25 -7
@@ -141,16 +141,34 @@ int rtw_write16(struct adapter *adapter, u32 addr, u16 val)int rtw_write32 (struct adapter *adapter,u32 addr,u32 val) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -int (*_write32)(struct intf_hdl *pintfhdl,u32 addr,u32 val); -int ret; +struct intf_hdl *intfhdl = &adapter->iopriv.intf; +u8 mac_pwr_ctrl_on, device_id, shift; +__le32 le_tmp; +s32 err =0 ; +u16 offset; +u32 ftaddr; - _write32 = pintfhdl->io_ops._write32; + ftaddr =_cvrt2ftaddr (addr, &device_id, &offset); - ret =_write32 (pintfhdl, addr, val); +rtw_hal_get_hwreg (adapter,HW_VAR_APFM_ON_MAC , &mac_pwr_ctrl_on); +if (((device_id ==WLAN_IOREG_DEVICE_ID ) && (offset <0x100 )) || + (!mac_pwr_ctrl_on) || + (adapter_to_pwrctl (adapter)->fw_current_in_ps_mode)) { + le_tmp =cpu_to_le32 (val); + err =sd_cmd52_write (intfhdl, ftaddr,4 , (u8 *)&le_tmp); +return RTW_STATUS_CODE (err); + } -return RTW_STATUS_CODE (ret); +/* 4 bytes alignment */ + shift = ftaddr &0x3 ; +if (shift ==0 ) { +sd_write32 (intfhdl, ftaddr, val, &err); + }else { + le_tmp =cpu_to_le32 (val); + err =sd_cmd52_write (intfhdl, ftaddr,4 , (u8 *)&le_tmp); + } + +return RTW_STATUS_CODE (err); }u32 rtw_write_port (struct adapter *adapter,u32 addr,u32 cnt,u8 *pmem)
drivers/staging/rtl8723bs/hal/sdio_ops.c +0 -39
@@ -124,44 +124,6 @@ u32 _cvrt2ftaddr(const u32 addr, u8 *pdevice_id, u16 *poffset)return ftaddr; } -static s32 sdio_write32 (struct intf_hdl *intfhdl,u32 addr,u32 val) -{ -struct adapter *adapter; -u8 mac_pwr_ctrl_on; -u8 device_id; -u16 offset; -u32 ftaddr; -u8 shift; -s32 err; -__le32 le_tmp; - - adapter = intfhdl->padapter; - err =0 ; - - ftaddr =_cvrt2ftaddr (addr, &device_id, &offset); - -rtw_hal_get_hwreg (adapter,HW_VAR_APFM_ON_MAC , &mac_pwr_ctrl_on); -if ( - ((device_id ==WLAN_IOREG_DEVICE_ID ) && (offset <0x100 )) || - (!mac_pwr_ctrl_on) || - (adapter_to_pwrctl (adapter)->fw_current_in_ps_mode) - ) { - le_tmp =cpu_to_le32 (val); - -return sd_cmd52_write (intfhdl, ftaddr,4 , (u8 *)&le_tmp); - } - -/* 4 bytes alignment */ - shift = ftaddr &0x3 ; -if (shift ==0 ) { -sd_write32 (intfhdl, ftaddr, val, &err); - }else { - le_tmp =cpu_to_le32 (val); - err =sd_cmd52_write (intfhdl, ftaddr,4 , (u8 *)&le_tmp); - } -return err; -} -/* * Description: *Read from RX FIFO
@@ -260,7 +222,6 @@ static u32 sdio_write_port(void sdio_set_intf_ops (struct adapter *adapter,struct _io_ops *ops) { - ops->_write32 = &sdio_write32; ops->_write_port = &sdio_write_port; }
drivers/staging/rtl8723bs/include/rtw_io.h +0 -2
@@ -11,8 +11,6 @@struct intf_hdl ;struct _io_ops { -int (*_write32)(struct intf_hdl *pintfhdl,u32 addr,u32 val); -u32 (*_write_port)(struct intf_hdl *pintfhdl,u32 addr,u32 cnt,u8 *pmem); };
Signature · 1 line
2.54.0
RFC PATCH 9/11 staging: rtl8723bs: inline sdio_write_port() into rtw_write_port()
In reply to Nikolay Kulikovrtw_write_port() is just a wrapper around sdio_write_port(). Combine them to reduce the number of abstractions and simplify the code.
Update the function description to match the actual parameters.
--- drivers/staging/rtl8723bs/core/rtw_io.c | 41 ++++++++++++++-- drivers/staging/rtl8723bs/hal/sdio_ops.c | 54 +--------------------- drivers/staging/rtl8723bs/include/rtw_io.h | 1 - 3 files changed, 37 insertions(+), 59 deletions(-)
drivers/staging/rtl8723bs/core/rtw_io.c +36 -5
@@ -171,15 +171,46 @@ int rtw_write32(struct adapter *adapter, u32 addr, u32 val)return RTW_STATUS_CODE (err); } +/* +* Description: +* Write to TX FIFO +* Align write size block size, +* and make sure data could be written in one command. +* +* Parameters: +* @adapter: adapter +* @addr: port ID +* @cnt: size to write +* @pmem: pointer to struct xmit_buf +* +* Return: +* _SUCCESS(1) Success +* _FAIL(0) Fail +*/ u32 rtw_write_port (struct adapter *adapter,u32 addr,u32 cnt,u8 *pmem) { -u32 (*_write_port)(struct intf_hdl *pintfhdl,u32 addr,u32 cnt,u8 *pmem); -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; +struct sdio_data *sdio = &adapter->dvobj->intf_data; +struct xmit_buf *xmitbuf = (struct xmit_buf *)pmem; +struct intf_hdl *intfhdl = &adapter->iopriv.intf; +s32 err; - _write_port = pintfhdl->io_ops._write_port; +if (!adapter->hw_init_completed || !xmitbuf) +return _FAIL; + + cnt =round_up (cnt,4 ); +hal_sdio_get_cmd_addr_8723b (adapter, addr, cnt >>2 , &addr); + +if (cnt > sdio->block_transfer_len) + cnt =_RND (cnt, sdio->block_transfer_len); + + err =sd_write (intfhdl, addr, cnt, xmitbuf->pdata); -return _write_port (pintfhdl, addr, cnt, pmem); +rtw_sctx_done_err (&xmitbuf->sctx, + err ?RTW_SCTX_DONE_WRITE_PORT_ERR :RTW_SCTX_DONE_SUCCESS ); + +if (err) +return _FAIL; +return _SUCCESS; } int rtw_init_io_priv(struct adapter *padapter,
drivers/staging/rtl8723bs/hal/sdio_ops.c +1 -53
62 lines not on this page · raw message
drivers/staging/rtl8723bs/include/rtw_io.h +0 -1
@@ -11,7 +11,6 @@struct intf_hdl ;struct _io_ops { -u32 (*_write_port)(struct intf_hdl *pintfhdl,u32 addr,u32 cnt,u8 *pmem); };struct intf_hdl {
Signature · 1 line
2.54.0
RFC PATCH 10/11 staging: rtl8723bs: remove the empty function set_intf_ops()
In reply to Nikolay KulikovThe body of this function was removed earlier, so remove it to get rid of dead code.
This also updates the rtw_init_io_priv() function, as it receives a pointer to set_intf_ops(), which is no longer neede.
--- drivers/staging/rtl8723bs/core/rtw_io.c | 9 +-------- drivers/staging/rtl8723bs/hal/sdio_ops.c | 5 ----- drivers/staging/rtl8723bs/include/rtw_io.h | 2 +- drivers/staging/rtl8723bs/include/sdio_ops.h | 2 -- drivers/staging/rtl8723bs/os_dep/sdio_intf.c | 2 +- 5 files changed, 3 insertions(+), 17 deletions(-)
drivers/staging/rtl8723bs/core/rtw_io.c +1 -8
@@ -213,22 +213,15 @@ u32 rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)return _SUCCESS; } -int rtw_init_io_priv (struct adapter *padapter, -void (*set_intf_ops)(struct adapter *padapter, -struct _io_ops *pops)) +int rtw_init_io_priv (struct adapter *padapter) {struct io_priv *piopriv = &padapter->iopriv;struct intf_hdl *pintf = &piopriv->intf; -if (!set_intf_ops) -return _FAIL; - piopriv->padapter = padapter; pintf->padapter = padapter; pintf->pintf_dev =adapter_to_dvobj (padapter); -set_intf_ops (padapter, &pintf->io_ops); -return _SUCCESS; }
drivers/staging/rtl8723bs/hal/sdio_ops.c +0 -5
@@ -168,11 +168,6 @@ static u32 sdio_read_port(return _SUCCESS; } -void sdio_set_intf_ops (struct adapter *adapter,struct _io_ops *ops) -{ -return ; -} -/* * Todo: align address to 4 bytes. */
drivers/staging/rtl8723bs/include/rtw_io.h +1 -1
@@ -44,6 +44,6 @@ extern int rtw_write32(struct adapter *adapter, u32 addr, u32 val);extern u32 rtw_write_port (struct adapter *adapter,u32 addr,u32 cnt,u8 *pmem); -int rtw_init_io_priv (struct adapter *padapter,void (*set_intf_ops)(struct adapter *padapter,struct _io_ops *pops)); +int rtw_init_io_priv (struct adapter *padapter);#endif /* _RTL8711_IO_H_ */
drivers/staging/rtl8723bs/include/sdio_ops.h +0 -2
@@ -10,8 +10,6 @@#include <sdio_ops_linux.h> -extern void sdio_set_intf_ops (struct adapter *padapter,struct _io_ops *pops); -/* extern void sdio_func1cmd52_read(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem); */ /* extern void sdio_func1cmd52_write(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem); */ extern u8 SdioLocalCmd52Read1Byte (struct adapter *padapter,u32 addr);
drivers/staging/rtl8723bs/os_dep/sdio_intf.c +1 -1
@@ -258,7 +258,7 @@ static struct adapter *rtw_sdio_if1_init(struct dvobj_priv *dvobj, const struct padapter->intf_alloc_irq = &sdio_alloc_irq; padapter->intf_free_irq = &sdio_free_irq; -if (rtw_init_io_priv (padapter, sdio_set_intf_ops) == _FAIL) +if (rtw_init_io_priv (padapter) == _FAIL) goto free_hal_data;rtl8723b_read_chip_version (padapter);
Signature · 1 line
2.54.0
RFC PATCH 11/11 staging: rtl8723bs: remove empty struct _io_ops
In reply to Nikolay KulikovAll fields of this structure were removed earlier, so remove this unused struct.
--- drivers/staging/rtl8723bs/include/rtw_io.h | 5 ----- 1 file changed, 5 deletions(-)
drivers/staging/rtl8723bs/include/rtw_io.h +0 -5
@@ -10,14 +10,9 @@struct intf_hdl ; -struct _io_ops { -}; -struct intf_hdl {struct adapter *padapter;struct dvobj_priv *pintf_dev;/* pointer to &(padapter->dvobjpriv); */ - -struct _io_ops io_ops; };#define SD_IO_TRY_CNT (8)
Signature · 1 line
2.54.0