netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Golle <daniel@makrotopia.org>
To: arinc9.unal@gmail.com
Cc: "Sean Wang" <sean.wang@mediatek.com>,
	"Landen Chao" <Landen.Chao@mediatek.com>,
	"DENG Qingfang" <dqfext@gmail.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Vladimir Oltean" <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"AngeloGioacchino Del Regno"
	<angelogioacchino.delregno@collabora.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Arınç ÜNAL" <arinc.unal@arinc9.com>,
	"Richard van Schagen" <richard@routerhints.com>,
	"Richard van Schagen" <vschagen@cs.com>,
	"Frank Wunderlich" <frank-w@public-files.de>,
	erkin.bozoglu@xeront.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [RFC PATCH net-next 03/22] net: dsa: mt7530: properly support MT7531AE and MT7531BE
Date: Fri, 21 Apr 2023 16:22:07 +0100	[thread overview]
Message-ID: <ZEKqH2oELsJKANkh@makrotopia.org> (raw)
In-Reply-To: <20230421143648.87889-4-arinc.unal@arinc9.com>

On Fri, Apr 21, 2023 at 05:36:29PM +0300, arinc9.unal@gmail.com wrote:
> From: Arınç ÜNAL <arinc.unal@arinc9.com>
> 
> Introduce the p5_sgmii pointer to store the information for whether port 5
> has got SGMII or not. Print "found MT7531AE" if it's got it, print "found
> MT7531BE" if it hasn't.
> 
> Move the comment about MT7531AE and MT7531BE to mt7531_setup(), where the
> switch is identified.
> 
> Get rid of mt7531_dual_sgmii_supported() now that priv->p5_sgmii stores the
> information. Address the code where mt7531_dual_sgmii_supported() is used.
> 
> Get rid of mt7531_is_rgmii_port() which just prints the opposite of
> priv->p5_sgmii.
> 
> Remove P5_INTF_SEL_GMAC5_SGMII. The p5_interface_select enum is supposed to
> represent the mode that port 5 is used in, not the hardware information of
> port 5. Set p5_intf_sel to P5_INTF_SEL_GMAC5 instead, if port 5 is not
> dsa_is_unused_port().
> 
> Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
> ---
>  drivers/net/dsa/mt7530-mdio.c |  7 ++---
>  drivers/net/dsa/mt7530.c      | 49 +++++++++++++++--------------------
>  drivers/net/dsa/mt7530.h      |  6 +++--
>  3 files changed, 27 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c
> index 088533663b83..fa3ee85a99c1 100644
> --- a/drivers/net/dsa/mt7530-mdio.c
> +++ b/drivers/net/dsa/mt7530-mdio.c
> @@ -81,17 +81,14 @@ static const struct regmap_bus mt7530_regmap_bus = {
>  };
>  
>  static int
> -mt7531_create_sgmii(struct mt7530_priv *priv, bool dual_sgmii)
> +mt7531_create_sgmii(struct mt7530_priv *priv)
>  {
>  	struct regmap_config *mt7531_pcs_config[2] = {};
>  	struct phylink_pcs *pcs;
>  	struct regmap *regmap;
>  	int i, ret = 0;
>  
> -	/* MT7531AE has two SGMII units for port 5 and port 6
> -	 * MT7531BE has only one SGMII unit for port 6
> -	 */
> -	for (i = dual_sgmii ? 0 : 1; i < 2; i++) {
> +	for (i = priv->p5_sgmii ? 0 : 1; i < 2; i++) {
>  		mt7531_pcs_config[i] = devm_kzalloc(priv->dev,
>  						    sizeof(struct regmap_config),
>  						    GFP_KERNEL);
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index c680873819b0..edc34be745b2 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -473,15 +473,6 @@ mt7530_pad_clk_setup(struct dsa_switch *ds, phy_interface_t interface)
>  	return 0;
>  }
>  
> -static bool mt7531_dual_sgmii_supported(struct mt7530_priv *priv)
> -{
> -	u32 val;
> -
> -	val = mt7530_read(priv, MT7531_TOP_SIG_SR);
> -
> -	return (val & PAD_DUAL_SGMII_EN) != 0;
> -}
> -
>  static int
>  mt7531_pad_setup(struct dsa_switch *ds, phy_interface_t interface)
>  {
> @@ -496,7 +487,7 @@ mt7531_pll_setup(struct mt7530_priv *priv)
>  	u32 xtal;
>  	u32 val;
>  
> -	if (mt7531_dual_sgmii_supported(priv))
> +	if (priv->p5_sgmii)
>  		return;
>  
>  	val = mt7530_read(priv, MT7531_CREV);
> @@ -907,8 +898,6 @@ static const char *p5_intf_modes(unsigned int p5_interface)
>  		return "PHY P4";
>  	case P5_INTF_SEL_GMAC5:
>  		return "GMAC5";
> -	case P5_INTF_SEL_GMAC5_SGMII:
> -		return "GMAC5_SGMII";
>  	default:
>  		return "unknown";
>  	}
> @@ -2440,6 +2429,18 @@ mt7531_setup(struct dsa_switch *ds)
>  		return -ENODEV;
>  	}
>  
> +	/* MT7531AE has got two SGMII units. One for port 5, one for port 6.
> +	 * MT7531BE has got only one SGMII unit which is for port 6.
> +	 */
> +	val = mt7530_read(priv, MT7531_TOP_SIG_SR);
> +
> +	if ((val & PAD_DUAL_SGMII_EN) != 0) {
> +		priv->p5_sgmii = true;
> +		dev_info(priv->dev, "found MT7531AE\n");
> +	} else {
> +		dev_info(priv->dev, "found MT7531BE\n");

I don't think dev_info is useful here for regular users.
If you really want this output, use dev_dbg to reduce log pollution.
Imho completely removing the else branch and only silently
setting priv->p5_sgmii is sufficient, as users can also turn on
dyndbg for drivers/net/pcs/pcs-mtk-lynxi.c and will then be informed
about the created SGMII/1000Base-X/2500Base-X PCS instances.


> +	}
> +
>  	/* all MACs must be forced link-down before sw reset */
>  	for (i = 0; i < MT7530_NUM_PORTS; i++)
>  		mt7530_write(priv, MT7530_PMCR_P(i), MT7531_FORCE_LNK);
> @@ -2451,19 +2452,16 @@ mt7531_setup(struct dsa_switch *ds)
>  
>  	mt7531_pll_setup(priv);
>  
> -	if (mt7531_dual_sgmii_supported(priv)) {
> -		priv->p5_intf_sel = P5_INTF_SEL_GMAC5_SGMII;
> -
> +	if (priv->p5_sgmii) {
>  		/* Let ds->slave_mii_bus be able to access external phy. */
>  		mt7530_rmw(priv, MT7531_GPIO_MODE1, MT7531_GPIO11_RG_RXD2_MASK,
>  			   MT7531_EXT_P_MDC_11);
>  		mt7530_rmw(priv, MT7531_GPIO_MODE1, MT7531_GPIO12_RG_RXD3_MASK,
>  			   MT7531_EXT_P_MDIO_12);
> -	} else {
> -		priv->p5_intf_sel = P5_INTF_SEL_GMAC5;
>  	}
> -	dev_dbg(ds->dev, "P5 support %s interface\n",
> -		p5_intf_modes(priv->p5_intf_sel));
> +
> +	if (!dsa_is_unused_port(ds, 5))
> +		priv->p5_intf_sel = P5_INTF_SEL_GMAC5;
>  
>  	mt7530_rmw(priv, MT7531_GPIO_MODE0, MT7531_GPIO0_MASK,
>  		   MT7531_GPIO0_INTERRUPT);
> @@ -2523,11 +2521,6 @@ static void mt7530_mac_port_get_caps(struct dsa_switch *ds, int port,
>  	}
>  }
>  
> -static bool mt7531_is_rgmii_port(struct mt7530_priv *priv, u32 port)
> -{
> -	return (port == 5) && (priv->p5_intf_sel != P5_INTF_SEL_GMAC5_SGMII);
> -}
> -
>  static void mt7531_mac_port_get_caps(struct dsa_switch *ds, int port,
>  				     struct phylink_config *config)
>  {
> @@ -2540,7 +2533,7 @@ static void mt7531_mac_port_get_caps(struct dsa_switch *ds, int port,
>  		break;
>  
>  	case 5: /* 2nd cpu port supports either rgmii or sgmii/8023z */
> -		if (mt7531_is_rgmii_port(priv, port)) {
> +		if (!priv->p5_sgmii) {
>  			phy_interface_set_rgmii(config->supported_interfaces);
>  			break;
>  		}
> @@ -2607,7 +2600,7 @@ static int mt7531_rgmii_setup(struct mt7530_priv *priv, u32 port,
>  {
>  	u32 val;
>  
> -	if (!mt7531_is_rgmii_port(priv, port)) {
> +	if (priv->p5_sgmii) {
>  		dev_err(priv->dev, "RGMII mode is not available for port %d\n",
>  			port);
>  		return -EINVAL;
> @@ -2860,7 +2853,7 @@ mt7531_cpu_port_config(struct dsa_switch *ds, int port)
>  
>  	switch (port) {
>  	case 5:
> -		if (mt7531_is_rgmii_port(priv, port))
> +		if (!priv->p5_sgmii)
>  			interface = PHY_INTERFACE_MODE_RGMII;
>  		else
>  			interface = PHY_INTERFACE_MODE_2500BASEX;
> @@ -3019,7 +3012,7 @@ mt753x_setup(struct dsa_switch *ds)
>  		mt7530_free_irq_common(priv);
>  
>  	if (priv->create_sgmii) {
> -		ret = priv->create_sgmii(priv, mt7531_dual_sgmii_supported(priv));
> +		ret = priv->create_sgmii(priv);
>  		if (ret && priv->irq)
>  			mt7530_free_irq(priv);
>  	}
> diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h
> index 703f8a528317..f58828577520 100644
> --- a/drivers/net/dsa/mt7530.h
> +++ b/drivers/net/dsa/mt7530.h
> @@ -679,7 +679,6 @@ typedef enum {
>  	P5_INTF_SEL_PHY_P0,
>  	P5_INTF_SEL_PHY_P4,
>  	P5_INTF_SEL_GMAC5,
> -	P5_INTF_SEL_GMAC5_SGMII,
>  } p5_interface_select;
>  
>  struct mt7530_priv;
> @@ -749,6 +748,8 @@ struct mt753x_info {
>   * @p6_interface:	Holding the current port 6 interface
>   * @p5_interface:	Holding the current port 5 interface
>   * @p5_intf_sel:	Holding the current port 5 interface select
> + * @p5_sgmii:		Flag for distinguishing if port 5 of the MT7531 switch
> + *			has got SGMII
>   * @irq:		IRQ number of the switch
>   * @irq_domain:		IRQ domain of the switch irq_chip
>   * @irq_enable:		IRQ enable bits, synced to SYS_INT_EN
> @@ -769,6 +770,7 @@ struct mt7530_priv {
>  	phy_interface_t		p6_interface;
>  	phy_interface_t		p5_interface;
>  	p5_interface_select	p5_intf_sel;
> +	bool			p5_sgmii;
>  	u8			mirror_rx;
>  	u8			mirror_tx;
>  	struct mt7530_port	ports[MT7530_NUM_PORTS];
> @@ -778,7 +780,7 @@ struct mt7530_priv {
>  	int irq;
>  	struct irq_domain *irq_domain;
>  	u32 irq_enable;
> -	int (*create_sgmii)(struct mt7530_priv *priv, bool dual_sgmii);
> +	int (*create_sgmii)(struct mt7530_priv *priv);
>  };
>  
>  struct mt7530_hw_vlan_entry {
> -- 
> 2.37.2
> 

  reply	other threads:[~2023-04-21 15:22 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-21 14:36 [RFC PATCH net-next 00/22] net: dsa: MT7530, MT7531, and MT7988 improvements arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 01/22] net: dsa: mt7530: add missing @p5_interface to mt7530_priv description arinc9.unal
2023-04-21 16:21   ` Daniel Golle
2023-04-21 14:36 ` [RFC PATCH net-next 02/22] net: dsa: mt7530: use p5_interface_select as data type for p5_intf_sel arinc9.unal
2023-04-21 16:23   ` Daniel Golle
2023-04-21 18:27     ` Arınç ÜNAL
2023-04-21 14:36 ` [RFC PATCH net-next 03/22] net: dsa: mt7530: properly support MT7531AE and MT7531BE arinc9.unal
2023-04-21 15:22   ` Daniel Golle [this message]
2023-04-21 18:29     ` Arınç ÜNAL
2023-04-21 14:36 ` [RFC PATCH net-next 04/22] net: dsa: mt7530: improve comments regarding port 5 and 6 arinc9.unal
2023-04-21 16:24   ` Daniel Golle
2023-04-21 14:36 ` [RFC PATCH net-next 05/22] net: dsa: mt7530: read XTAL value from correct register arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 06/22] net: dsa: mt7530: improve code path for setting up port 5 arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 07/22] net: dsa: mt7530: do not run mt7530_setup_port5() if port 5 is disabled arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 08/22] net: dsa: mt7530: change p{5,6}_interface to p{5,6}_configured arinc9.unal
2023-04-21 17:28   ` Daniel Golle
2023-04-21 18:17     ` Arınç ÜNAL
2023-04-21 18:20       ` Arınç ÜNAL
2023-04-21 18:25         ` Arınç ÜNAL
2023-04-21 19:03           ` Daniel Golle
2023-04-21 14:36 ` [RFC PATCH net-next 09/22] net: dsa: mt7530: empty default case on mt7530_setup_port5() arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 10/22] net: dsa: mt7530: call port 6 setup from mt7530_mac_config() arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 11/22] net: dsa: mt7530: remove pad_setup function pointer arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 12/22] net: dsa: mt7530: move XTAL check to mt7530_setup() arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 13/22] net: dsa: mt7530: move enabling port 6 to mt7530_setup_port6() arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 14/22] net: dsa: mt7530: switch to if/else statements on mt7530_setup_port6() arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 15/22] net: dsa: mt7530: set TRGMII RD TAP if trgmii is being used arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 16/22] net: dsa: mt7530: move lowering port 5 RGMII driving to mt7530_setup() arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 17/22] net: dsa: mt7530: fix port capabilities for MT7988 arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 18/22] net: dsa: mt7530: remove .mac_port_config for MT7988 and make it optional arinc9.unal
2023-04-21 14:36 ` [RFC PATCH net-next 19/22] net: dsa: mt7530: set interrupt register only for MT7530 arinc9.unal
2023-04-21 18:32   ` Daniel Golle
2023-04-21 14:36 ` [RFC PATCH net-next 20/22] net: dsa: mt7530: force link-down on MACs before reset on MT7530 arinc9.unal
2023-04-21 18:42   ` Daniel Golle
2023-04-21 18:47     ` Arınç ÜNAL
2023-04-21 19:06       ` Daniel Golle
2023-04-29 15:37     ` Arınç ÜNAL
2023-04-21 14:36 ` [RFC PATCH net-next 21/22] net: dsa: mt7530: get rid of useless error returns on phylink code path arinc9.unal
2023-04-21 18:58   ` Daniel Golle
2023-04-21 14:36 ` [RFC PATCH net-next 22/22] net: dsa: mt7530: rename p5_intf_sel and use only for MT7530 switch arinc9.unal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZEKqH2oELsJKANkh@makrotopia.org \
    --to=daniel@makrotopia.org \
    --cc=Landen.Chao@mediatek.com \
    --cc=andrew@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=arinc.unal@arinc9.com \
    --cc=arinc9.unal@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dqfext@gmail.com \
    --cc=edumazet@google.com \
    --cc=erkin.bozoglu@xeront.com \
    --cc=f.fainelli@gmail.com \
    --cc=frank-w@public-files.de \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=richard@routerhints.com \
    --cc=sean.wang@mediatek.com \
    --cc=vschagen@cs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).