* [PATCH] net: dsa: realtek: rtl8366rb: Serialize indirect PHY register access
@ 2022-05-07 7:39 Linus Walleij
2022-05-07 12:10 ` kernel test robot
0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2022-05-07 7:39 UTC (permalink / raw)
To: Andrew Lunn, Vivien Didelot, Florian Fainelli, Vladimir Oltean,
David S . Miller, Jakub Kicinski
Cc: netdev, Alvin Šipraga, Linus Walleij
From: Alvin Šipraga <alsi@bang-olufsen.dk>
Lock the regmap during the whole PHY register access routines in
rtl8366rb.
Signed-off-by: Alvin Šipraga <alsi@bang-olufsen.dk>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
I have tested that this does not create any regressions,
it makes more sense to have this applied than not. First
it is related to the same family as the other ASICs, also
it makes perfect logical sense to enforce serialization
of these reads/writes.
---
drivers/net/dsa/realtek/rtl8366rb.c | 33 +++++++++++++++++++----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c
index 1a3406b9e64c..1298661abf2d 100644
--- a/drivers/net/dsa/realtek/rtl8366rb.c
+++ b/drivers/net/dsa/realtek/rtl8366rb.c
@@ -1653,28 +1653,34 @@ static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum)
if (phy > RTL8366RB_PHY_NO_MAX)
return -EINVAL;
- ret = regmap_write(priv->map, RTL8366RB_PHY_ACCESS_CTRL_REG,
+ mutex_lock(&priv->map_lock);
+
+ ret = regmap_write(priv->map_nolock, RTL8366RB_PHY_ACCESS_CTRL_REG,
RTL8366RB_PHY_CTRL_READ);
if (ret)
- return ret;
+ goto out;
reg = 0x8000 | (1 << (phy + RTL8366RB_PHY_NO_OFFSET)) | regnum;
- ret = regmap_write(priv->map, reg, 0);
+ ret = regmap_write(priv->map_nolock, reg, 0);
if (ret) {
dev_err(priv->dev,
"failed to write PHY%d reg %04x @ %04x, ret %d\n",
phy, regnum, reg, ret);
- return ret;
+ goto out;
}
- ret = regmap_read(priv->map, RTL8366RB_PHY_ACCESS_DATA_REG, &val);
+ ret = regmap_read(priv->map_nolock, RTL8366RB_PHY_ACCESS_DATA_REG,
+ &val);
if (ret)
- return ret;
+ goto out;
dev_dbg(priv->dev, "read PHY%d register 0x%04x @ %08x, val <- %04x\n",
phy, regnum, reg, val);
+out:
+ mutex_unlock(&priv->map_lock);
+
return val;
}
@@ -1687,21 +1693,26 @@ static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum,
if (phy > RTL8366RB_PHY_NO_MAX)
return -EINVAL;
- ret = regmap_write(priv->map, RTL8366RB_PHY_ACCESS_CTRL_REG,
+ mutex_lock(&priv->map_lock);
+
+ ret = regmap_write(priv->map_nolock, RTL8366RB_PHY_ACCESS_CTRL_REG,
RTL8366RB_PHY_CTRL_WRITE);
if (ret)
- return ret;
+ goto out;
reg = 0x8000 | (1 << (phy + RTL8366RB_PHY_NO_OFFSET)) | regnum;
dev_dbg(priv->dev, "write PHY%d register 0x%04x @ %04x, val -> %04x\n",
phy, regnum, reg, val);
- ret = regmap_write(priv->map, reg, val);
+ ret = regmap_write(priv->map_nolock, reg, val);
if (ret)
- return ret;
+ goto out;
- return 0;
+out:
+ mutex_unlock(&priv->map_lock);
+
+ return ret;
}
static int rtl8366rb_dsa_phy_read(struct dsa_switch *ds, int phy, int regnum)
--
2.35.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: dsa: realtek: rtl8366rb: Serialize indirect PHY register access
2022-05-07 7:39 [PATCH] net: dsa: realtek: rtl8366rb: Serialize indirect PHY register access Linus Walleij
@ 2022-05-07 12:10 ` kernel test robot
0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2022-05-07 12:10 UTC (permalink / raw)
To: Linus Walleij, Andrew Lunn, Vivien Didelot, Florian Fainelli,
Vladimir Oltean, David S . Miller, Jakub Kicinski
Cc: llvm, kbuild-all, netdev, Alvin Šipraga, Linus Walleij
Hi Linus,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.18-rc5 next-20220506]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Linus-Walleij/net-dsa-realtek-rtl8366rb-Serialize-indirect-PHY-register-access/20220507-154616
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 4b97bac0756a81cda5afd45417a99b5bccdcff67
config: riscv-randconfig-c006-20220506 (https://download.01.org/0day-ci/archive/20220507/202205071955.IM81bph1-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project af4cf1c6b8ed0d8102fc5e69acdc2fcbbcdaa9a7)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/5858edf68f246841b19173d0a30ebc5651f7b0c2
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Linus-Walleij/net-dsa-realtek-rtl8366rb-Serialize-indirect-PHY-register-access/20220507-154616
git checkout 5858edf68f246841b19173d0a30ebc5651f7b0c2
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/net/dsa/realtek/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
In file included from drivers/net/dsa/realtek/rtl8366rb.c:16:
In file included from include/linux/etherdevice.h:20:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:17:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:464:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:477:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
^
In file included from drivers/net/dsa/realtek/rtl8366rb.c:16:
In file included from include/linux/etherdevice.h:20:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:17:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
^
In file included from drivers/net/dsa/realtek/rtl8366rb.c:16:
In file included from include/linux/etherdevice.h:20:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:17:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:1024:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
~~~~~~~~~~ ^
>> drivers/net/dsa/realtek/rtl8366rb.c:1666:6: warning: variable 'val' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (ret) {
^~~
drivers/net/dsa/realtek/rtl8366rb.c:1684:9: note: uninitialized use occurs here
return val;
^~~
drivers/net/dsa/realtek/rtl8366rb.c:1666:2: note: remove the 'if' if its condition is always false
if (ret) {
^~~~~~~~~~
drivers/net/dsa/realtek/rtl8366rb.c:1660:6: warning: variable 'val' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (ret)
^~~
drivers/net/dsa/realtek/rtl8366rb.c:1684:9: note: uninitialized use occurs here
return val;
^~~
drivers/net/dsa/realtek/rtl8366rb.c:1660:2: note: remove the 'if' if its condition is always false
if (ret)
^~~~~~~~
drivers/net/dsa/realtek/rtl8366rb.c:1649:9: note: initialize the variable 'val' to silence this warning
u32 val;
^
= 0
9 warnings generated.
vim +1666 drivers/net/dsa/realtek/rtl8366rb.c
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1646
f5f119077b1cd6 drivers/net/dsa/realtek/rtl8366rb.c Luiz Angelo Daros de Luca 2022-01-28 1647 static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum)
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1648 {
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1649 u32 val;
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1650 u32 reg;
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1651 int ret;
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1652
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1653 if (phy > RTL8366RB_PHY_NO_MAX)
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1654 return -EINVAL;
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1655
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1656 mutex_lock(&priv->map_lock);
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1657
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1658 ret = regmap_write(priv->map_nolock, RTL8366RB_PHY_ACCESS_CTRL_REG,
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1659 RTL8366RB_PHY_CTRL_READ);
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1660 if (ret)
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1661 goto out;
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1662
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1663 reg = 0x8000 | (1 << (phy + RTL8366RB_PHY_NO_OFFSET)) | regnum;
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1664
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1665 ret = regmap_write(priv->map_nolock, reg, 0);
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 @1666 if (ret) {
f5f119077b1cd6 drivers/net/dsa/realtek/rtl8366rb.c Luiz Angelo Daros de Luca 2022-01-28 1667 dev_err(priv->dev,
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1668 "failed to write PHY%d reg %04x @ %04x, ret %d\n",
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1669 phy, regnum, reg, ret);
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1670 goto out;
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1671 }
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1672
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1673 ret = regmap_read(priv->map_nolock, RTL8366RB_PHY_ACCESS_DATA_REG,
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1674 &val);
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1675 if (ret)
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1676 goto out;
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1677
f5f119077b1cd6 drivers/net/dsa/realtek/rtl8366rb.c Luiz Angelo Daros de Luca 2022-01-28 1678 dev_dbg(priv->dev, "read PHY%d register 0x%04x @ %08x, val <- %04x\n",
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1679 phy, regnum, reg, val);
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1680
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1681 out:
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1682 mutex_unlock(&priv->map_lock);
5858edf68f2468 drivers/net/dsa/realtek/rtl8366rb.c Alvin Šipraga 2022-05-07 1683
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1684 return val;
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1685 }
d8652956cf37c5 drivers/net/dsa/rtl8366rb.c Linus Walleij 2018-07-14 1686
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-07 12:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-07 7:39 [PATCH] net: dsa: realtek: rtl8366rb: Serialize indirect PHY register access Linus Walleij
2022-05-07 12:10 ` kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.