diff mbox series

[net-next,05/13] net: dsa: realtek: use phy_read in ds->ops

Message ID 20211216201342.25587-6-luizluca@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: realtek: MDIO interface and RTL8367S | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 4 this patch: 4
netdev/cc_maintainers warning 3 maintainers not CCed: linux@armlinux.org.uk kuba@kernel.org davem@davemloft.net
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 114 lines checked
netdev/kdoc success Errors and warnings before: 21 this patch: 19
netdev/source_inline success Was 0 now: 0

Commit Message

Luiz Angelo Daros de Luca Dec. 16, 2021, 8:13 p.m. UTC
From: Luiz Angelo Daros de Luca <luizluca@gmail.com>

The ds->ops->phy_read will only be used if the ds->slave_mii_bus
was not initialized. Calling realtek_smi_setup_mdio will create a
ds->slave_mii_bus, making ds->ops->phy_read dormant.

Using ds->ops->phy_read will allow switches connected through non-SMI
interfaces (like mdio) to let ds allocate slave_mii_bus and reuse the
same code.

Tested-by: Arınç ÜNAL <arinc.unal@arinc9.com>
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
---
 drivers/net/dsa/realtek/realtek-smi.c |  8 ++++----
 drivers/net/dsa/realtek/realtek.h     |  3 ---
 drivers/net/dsa/realtek/rtl8365mb.c   | 10 ++++++----
 drivers/net/dsa/realtek/rtl8366rb.c   | 10 ++++++----
 4 files changed, 16 insertions(+), 15 deletions(-)

Comments

Linus Walleij Dec. 18, 2021, 2:50 a.m. UTC | #1
On Thu, Dec 16, 2021 at 9:14 PM <luizluca@gmail.com> wrote:
> From: Luiz Angelo Daros de Luca <luizluca@gmail.com>
>
> The ds->ops->phy_read will only be used if the ds->slave_mii_bus
> was not initialized. Calling realtek_smi_setup_mdio will create a
> ds->slave_mii_bus, making ds->ops->phy_read dormant.
>
> Using ds->ops->phy_read will allow switches connected through non-SMI
> interfaces (like mdio) to let ds allocate slave_mii_bus and reuse the
> same code.
>
> Tested-by: Arınç ÜNAL <arinc.unal@arinc9.com>
> Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
(...)
> -static int rtl8365mb_phy_read(struct realtek_priv *priv, int phy, int regnum)
> +static int rtl8365mb_phy_read(struct dsa_switch *ds, int phy, int regnum)
>  {
>         u32 ocp_addr;
>         u16 val;
>         int ret;
> +       struct realtek_priv *priv = ds->priv;

Needs to be on top (reverse christmas tree, christmas is getting close).

> -static int rtl8365mb_phy_write(struct realtek_priv *priv, int phy, int regnum,
> +static int rtl8365mb_phy_write(struct dsa_switch *ds, int phy, int regnum,
>                                u16 val)
>  {
>         u32 ocp_addr;
>         int ret;
> +       struct realtek_priv *priv = (struct realtek_priv *)ds->priv;

Dito.

> -static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum)
> +static int rtl8366rb_phy_read(struct dsa_switch *ds, int phy, int regnum)
>  {
>         u32 val;
>         u32 reg;
>         int ret;
> +       struct realtek_priv *priv = ds->priv;

Dito.

> -static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum,
> +static int rtl8366rb_phy_write(struct dsa_switch *ds, int phy, int regnum,
>                                u16 val)
>  {
>         u32 reg;
>         int ret;
> +       struct realtek_priv *priv = ds->priv;

Dito.

Other than that it's a great patch, so with these nitpicky changes
feel free to add:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij
Luiz Angelo Daros de Luca Dec. 18, 2021, 6:24 a.m. UTC | #2
> On Thu, Dec 16, 2021 at 9:14 PM <luizluca@gmail.com> wrote:
> > From: Luiz Angelo Daros de Luca <luizluca@gmail.com>
> >
> > The ds->ops->phy_read will only be used if the ds->slave_mii_bus
> > was not initialized. Calling realtek_smi_setup_mdio will create a
> > ds->slave_mii_bus, making ds->ops->phy_read dormant.
> >
> > Using ds->ops->phy_read will allow switches connected through non-SMI
> > interfaces (like mdio) to let ds allocate slave_mii_bus and reuse the
> > same code.
> >
> > Tested-by: Arınç ÜNAL <arinc.unal@arinc9.com>
> > Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
> (...)
> > -static int rtl8365mb_phy_read(struct realtek_priv *priv, int phy, int regnum)
> > +static int rtl8365mb_phy_read(struct dsa_switch *ds, int phy, int regnum)
> >  {
> >         u32 ocp_addr;
> >         u16 val;
> >         int ret;
> > +       struct realtek_priv *priv = ds->priv;
>
> Needs to be on top (reverse christmas tree, christmas is getting close).
>
> > -static int rtl8365mb_phy_write(struct realtek_priv *priv, int phy, int regnum,
> > +static int rtl8365mb_phy_write(struct dsa_switch *ds, int phy, int regnum,
> >                                u16 val)
> >  {
> >         u32 ocp_addr;
> >         int ret;
> > +       struct realtek_priv *priv = (struct realtek_priv *)ds->priv;
>
> Dito.
>
> > -static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum)
> > +static int rtl8366rb_phy_read(struct dsa_switch *ds, int phy, int regnum)
> >  {
> >         u32 val;
> >         u32 reg;
> >         int ret;
> > +       struct realtek_priv *priv = ds->priv;
>
> Dito.
>
> > -static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum,
> > +static int rtl8366rb_phy_write(struct dsa_switch *ds, int phy, int regnum,
> >                                u16 val)
> >  {
> >         u32 reg;
> >         int ret;
> > +       struct realtek_priv *priv = ds->priv;
>
> Dito.
>
> Other than that it's a great patch, so with these nitpicky changes
> feel free to add:
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
>

Thanks! Fixed and added.
diff mbox series

Patch

diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c
index 11447096c8dc..f10acd7d3636 100644
--- a/drivers/net/dsa/realtek/realtek-smi.c
+++ b/drivers/net/dsa/realtek/realtek-smi.c
@@ -328,17 +328,17 @@  static const struct regmap_config realtek_smi_mdio_regmap_config = {
 
 static int realtek_smi_mdio_read(struct mii_bus *bus, int addr, int regnum)
 {
-	struct realtek_priv *priv = bus->priv;
+	struct dsa_switch *ds = ((struct realtek_priv *)bus->priv)->ds;
 
-	return priv->ops->phy_read(priv, addr, regnum);
+	return ds->ops->phy_read(ds, addr, regnum);
 }
 
 static int realtek_smi_mdio_write(struct mii_bus *bus, int addr, int regnum,
 				  u16 val)
 {
-	struct realtek_priv *priv = bus->priv;
+	struct dsa_switch *ds = ((struct realtek_priv *)bus->priv)->ds;
 
-	return priv->ops->phy_write(priv, addr, regnum, val);
+	return ds->ops->phy_write(ds, addr, regnum, val);
 }
 
 int realtek_smi_setup_mdio(struct dsa_switch *ds)
diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h
index 766e79151a6c..daca0c0b7ea2 100644
--- a/drivers/net/dsa/realtek/realtek.h
+++ b/drivers/net/dsa/realtek/realtek.h
@@ -103,9 +103,6 @@  struct realtek_ops {
 	int	(*enable_vlan)(struct realtek_priv *priv, bool enable);
 	int	(*enable_vlan4k)(struct realtek_priv *priv, bool enable);
 	int	(*enable_port)(struct realtek_priv *priv, int port, bool enable);
-	int	(*phy_read)(struct realtek_priv *priv, int phy, int regnum);
-	int	(*phy_write)(struct realtek_priv *priv, int phy, int regnum,
-			     u16 val);
 };
 
 struct realtek_variant {
diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c
index d6054f63f204..488b17a68226 100644
--- a/drivers/net/dsa/realtek/rtl8365mb.c
+++ b/drivers/net/dsa/realtek/rtl8365mb.c
@@ -674,11 +674,12 @@  static int rtl8365mb_phy_ocp_write(struct realtek_priv *priv, int phy,
 	return 0;
 }
 
-static int rtl8365mb_phy_read(struct realtek_priv *priv, int phy, int regnum)
+static int rtl8365mb_phy_read(struct dsa_switch *ds, int phy, int regnum)
 {
 	u32 ocp_addr;
 	u16 val;
 	int ret;
+	struct realtek_priv *priv = ds->priv;
 
 	if (phy > RTL8365MB_PHYADDRMAX)
 		return -EINVAL;
@@ -702,11 +703,12 @@  static int rtl8365mb_phy_read(struct realtek_priv *priv, int phy, int regnum)
 	return val;
 }
 
-static int rtl8365mb_phy_write(struct realtek_priv *priv, int phy, int regnum,
+static int rtl8365mb_phy_write(struct dsa_switch *ds, int phy, int regnum,
 			       u16 val)
 {
 	u32 ocp_addr;
 	int ret;
+	struct realtek_priv *priv = (struct realtek_priv *)ds->priv;
 
 	if (phy > RTL8365MB_PHYADDRMAX)
 		return -EINVAL;
@@ -1958,6 +1960,8 @@  static const struct dsa_switch_ops rtl8365mb_switch_ops = {
 	.get_tag_protocol = rtl8365mb_get_tag_protocol,
 	.setup = rtl8365mb_setup,
 	.teardown = rtl8365mb_teardown,
+	.phy_read = rtl8365mb_phy_read,
+	.phy_write = rtl8365mb_phy_write,
 	.phylink_validate = rtl8365mb_phylink_validate,
 	.phylink_mac_config = rtl8365mb_phylink_mac_config,
 	.phylink_mac_link_down = rtl8365mb_phylink_mac_link_down,
@@ -1974,8 +1978,6 @@  static const struct dsa_switch_ops rtl8365mb_switch_ops = {
 
 static const struct realtek_ops rtl8365mb_ops = {
 	.detect = rtl8365mb_detect,
-	.phy_read = rtl8365mb_phy_read,
-	.phy_write = rtl8365mb_phy_write,
 };
 
 const struct realtek_variant rtl8365mb_variant = {
diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c
index 31f1a949c8e7..27f08a5f53d4 100644
--- a/drivers/net/dsa/realtek/rtl8366rb.c
+++ b/drivers/net/dsa/realtek/rtl8366rb.c
@@ -1639,11 +1639,12 @@  static int rtl8366rb_enable_vlan4k(struct realtek_priv *priv, bool enable)
 				  enable ? RTL8366RB_SGCR_EN_VLAN_4KTB : 0);
 }
 
-static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum)
+static int rtl8366rb_phy_read(struct dsa_switch *ds, int phy, int regnum)
 {
 	u32 val;
 	u32 reg;
 	int ret;
+	struct realtek_priv *priv = ds->priv;
 
 	if (phy > RTL8366RB_PHY_NO_MAX)
 		return -EINVAL;
@@ -1673,11 +1674,12 @@  static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum)
 	return val;
 }
 
-static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum,
+static int rtl8366rb_phy_write(struct dsa_switch *ds, int phy, int regnum,
 			       u16 val)
 {
 	u32 reg;
 	int ret;
+	struct realtek_priv *priv = ds->priv;
 
 	if (phy > RTL8366RB_PHY_NO_MAX)
 		return -EINVAL;
@@ -1767,6 +1769,8 @@  static int rtl8366rb_detect(struct realtek_priv *priv)
 static const struct dsa_switch_ops rtl8366rb_switch_ops = {
 	.get_tag_protocol = rtl8366_get_tag_protocol,
 	.setup = rtl8366rb_setup,
+	.phy_read = rtl8366rb_phy_read,
+	.phy_write = rtl8366rb_phy_write,
 	.phylink_mac_link_up = rtl8366rb_mac_link_up,
 	.phylink_mac_link_down = rtl8366rb_mac_link_down,
 	.get_strings = rtl8366_get_strings,
@@ -1799,8 +1803,6 @@  static const struct realtek_ops rtl8366rb_ops = {
 	.is_vlan_valid	= rtl8366rb_is_vlan_valid,
 	.enable_vlan	= rtl8366rb_enable_vlan,
 	.enable_vlan4k	= rtl8366rb_enable_vlan4k,
-	.phy_read	= rtl8366rb_phy_read,
-	.phy_write	= rtl8366rb_phy_write,
 };
 
 const struct realtek_variant rtl8366rb_variant = {