All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Daniel Golle <daniel@makrotopia.org>
Cc: Felix Fietkau <nbd@nbd.name>, John Crispin <john@phrozen.org>,
	Sean Wang <sean.wang@mediatek.com>,
	Mark Lee <Mark-MC.Lee@mediatek.com>,
	Lorenzo Bianconi <lorenzo@kernel.org>,
	"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>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH RFC net-next v2] net: ethernet: mtk_eth_soc: add paths and SerDes modes for MT7988
Date: Sun, 27 Aug 2023 17:35:23 +0200	[thread overview]
Message-ID: <20230827153523.GS3523530@kernel.org> (raw)
In-Reply-To: <8b05b606aa37cd30445b8a6d73caef1b0d0cfbfa.1692908556.git.daniel@makrotopia.org>

On Thu, Aug 24, 2023 at 09:24:48PM +0100, Daniel Golle wrote:
> MT7988 comes with a built-in 2.5G PHY as well as SerDes lanes to
> connect external PHYs or transceivers in USXGMII, 10GBase-R, 5GBase-R,
> 2500Base-X, 1000Base-X and Cisco SGMII interface modes.
> 
> Implement support for configuring for the new paths to SerDes interfaces
> and the internal 2.5G PHY.
> 
> Add USXGMII PCS driver for 10GBase-R, 5GBase-R and USXGMII mode, and
> setup the new PHYA on MT7988 to access the also still existing old
> LynxI PCS for 1000Base-X, 2500Base-X and Cisco SGMII PCS interface
> modes.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>

Hi Daniel,

some minor feedback from my side.

...

> diff --git a/drivers/net/ethernet/mediatek/mtk_usxgmii.c b/drivers/net/ethernet/mediatek/mtk_usxgmii.c

...

> +static int mtk_usxgmii_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
> +				  phy_interface_t interface,
> +				  const unsigned long *advertising,
> +				  bool permit_pause_to_mac)
> +{
> +	struct mtk_usxgmii_pcs *mpcs = pcs_to_mtk_usxgmii_pcs(pcs);
> +	struct mtk_eth *eth = mpcs->eth;
> +	struct regmap *pextp = eth->regmap_pextp[mpcs->id];
> +	unsigned int an_ctrl = 0, link_timer = 0, xfi_mode = 0, adapt_mode = 0;
> +	bool mode_changed = false;
> +
> +	if (!pextp)
> +		return -ENODEV;
> +
> +	if (interface == PHY_INTERFACE_MODE_USXGMII) {
> +		an_ctrl = FIELD_PREP(USXGMII_AN_SYNC_CNT, 0x1FF) |
> +			  (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) ?
> +			  USXGMII_AN_ENABLE : 0;

clang-16 W=1 suggests using parentheses here:

 drivers/net/ethernet/mediatek/mtk_usxgmii.c:468:51: warning: operator '?:' has lower precedence than '|'; '|' will be evaluated first [-Wbitwise-conditional-parentheses]
                           (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) ?
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
 drivers/net/ethernet/mediatek/mtk_usxgmii.c:468:51: note: place parentheses around the '|' expression to silence this warning
                           (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) ?
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
 drivers/net/ethernet/mediatek/mtk_usxgmii.c:468:51: note: place parentheses around the '?:' expression to evaluate it first
                           (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) ?
                                                                        ^
                           (

> +		link_timer = FIELD_PREP(USXGMII_LINK_TIMER_IDLE_DETECT, 0x7B) |
> +			     FIELD_PREP(USXGMII_LINK_TIMER_COMP_ACK_DETECT, 0x7B) |
> +			     FIELD_PREP(USXGMII_LINK_TIMER_AN_RESTART, 0x7B);
> +		xfi_mode = FIELD_PREP(USXGMII_XFI_RX_MODE, USXGMII_XFI_RX_MODE_10G) |
> +			   FIELD_PREP(USXGMII_XFI_TX_MODE, USXGMII_XFI_TX_MODE_10G);

...

> +int mtk_usxgmii_init(struct mtk_eth *eth)
> +{
> +	struct device_node *r = eth->dev->of_node;
> +	struct device *dev = eth->dev;
> +	struct device_node *np;
> +	int i, ret;
> +
> +	for (i = 0; i < MTK_MAX_DEVS; i++) {
> +		np = of_parse_phandle(r, "mediatek,usxgmiisys", i);
> +		if (!np)
> +			break;
> +
> +		eth->usxgmii_pcs[i] = devm_kzalloc(dev, sizeof(*eth->usxgmii_pcs), GFP_KERNEL);

Smatch warns that only 8 bytes are allocated, whereas 64 are needed.
I think one more defference of the parameter to sizeof().

e.g.:

		eth->usxgmii_pcs[i] = devm_kzalloc(dev,
						   sizeof(*eth->usxgmii_pcs[i]),
						   GFP_KERNEL);

> +		if (!eth->usxgmii_pcs[i])
> +			return -ENOMEM;
> +
> +		eth->usxgmii_pcs[i]->id = i;
> +		eth->usxgmii_pcs[i]->eth = eth;
> +		eth->usxgmii_pcs[i]->regmap = syscon_node_to_regmap(np);
> +		if (IS_ERR(eth->usxgmii_pcs[i]->regmap))
> +			return PTR_ERR(eth->usxgmii_pcs[i]->regmap);
> +
> +		eth->usxgmii_pcs[i]->pcs.ops = &mtk_usxgmii_pcs_ops;
> +		eth->usxgmii_pcs[i]->pcs.poll = true;
> +		eth->usxgmii_pcs[i]->pcs.neg_mode = true;
> +		eth->usxgmii_pcs[i]->interface = PHY_INTERFACE_MODE_NA;
> +		eth->usxgmii_pcs[i]->neg_mode = -1;
> +
> +		of_node_put(np);
> +	}

...


WARNING: multiple messages have this Message-ID (diff)
From: Simon Horman <horms@kernel.org>
To: Daniel Golle <daniel@makrotopia.org>
Cc: Felix Fietkau <nbd@nbd.name>, John Crispin <john@phrozen.org>,
	Sean Wang <sean.wang@mediatek.com>,
	Mark Lee <Mark-MC.Lee@mediatek.com>,
	Lorenzo Bianconi <lorenzo@kernel.org>,
	"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>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH RFC net-next v2] net: ethernet: mtk_eth_soc: add paths and SerDes modes for MT7988
Date: Sun, 27 Aug 2023 17:35:23 +0200	[thread overview]
Message-ID: <20230827153523.GS3523530@kernel.org> (raw)
In-Reply-To: <8b05b606aa37cd30445b8a6d73caef1b0d0cfbfa.1692908556.git.daniel@makrotopia.org>

On Thu, Aug 24, 2023 at 09:24:48PM +0100, Daniel Golle wrote:
> MT7988 comes with a built-in 2.5G PHY as well as SerDes lanes to
> connect external PHYs or transceivers in USXGMII, 10GBase-R, 5GBase-R,
> 2500Base-X, 1000Base-X and Cisco SGMII interface modes.
> 
> Implement support for configuring for the new paths to SerDes interfaces
> and the internal 2.5G PHY.
> 
> Add USXGMII PCS driver for 10GBase-R, 5GBase-R and USXGMII mode, and
> setup the new PHYA on MT7988 to access the also still existing old
> LynxI PCS for 1000Base-X, 2500Base-X and Cisco SGMII PCS interface
> modes.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>

Hi Daniel,

some minor feedback from my side.

...

> diff --git a/drivers/net/ethernet/mediatek/mtk_usxgmii.c b/drivers/net/ethernet/mediatek/mtk_usxgmii.c

...

> +static int mtk_usxgmii_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
> +				  phy_interface_t interface,
> +				  const unsigned long *advertising,
> +				  bool permit_pause_to_mac)
> +{
> +	struct mtk_usxgmii_pcs *mpcs = pcs_to_mtk_usxgmii_pcs(pcs);
> +	struct mtk_eth *eth = mpcs->eth;
> +	struct regmap *pextp = eth->regmap_pextp[mpcs->id];
> +	unsigned int an_ctrl = 0, link_timer = 0, xfi_mode = 0, adapt_mode = 0;
> +	bool mode_changed = false;
> +
> +	if (!pextp)
> +		return -ENODEV;
> +
> +	if (interface == PHY_INTERFACE_MODE_USXGMII) {
> +		an_ctrl = FIELD_PREP(USXGMII_AN_SYNC_CNT, 0x1FF) |
> +			  (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) ?
> +			  USXGMII_AN_ENABLE : 0;

clang-16 W=1 suggests using parentheses here:

 drivers/net/ethernet/mediatek/mtk_usxgmii.c:468:51: warning: operator '?:' has lower precedence than '|'; '|' will be evaluated first [-Wbitwise-conditional-parentheses]
                           (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) ?
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
 drivers/net/ethernet/mediatek/mtk_usxgmii.c:468:51: note: place parentheses around the '|' expression to silence this warning
                           (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) ?
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
 drivers/net/ethernet/mediatek/mtk_usxgmii.c:468:51: note: place parentheses around the '?:' expression to evaluate it first
                           (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) ?
                                                                        ^
                           (

> +		link_timer = FIELD_PREP(USXGMII_LINK_TIMER_IDLE_DETECT, 0x7B) |
> +			     FIELD_PREP(USXGMII_LINK_TIMER_COMP_ACK_DETECT, 0x7B) |
> +			     FIELD_PREP(USXGMII_LINK_TIMER_AN_RESTART, 0x7B);
> +		xfi_mode = FIELD_PREP(USXGMII_XFI_RX_MODE, USXGMII_XFI_RX_MODE_10G) |
> +			   FIELD_PREP(USXGMII_XFI_TX_MODE, USXGMII_XFI_TX_MODE_10G);

...

> +int mtk_usxgmii_init(struct mtk_eth *eth)
> +{
> +	struct device_node *r = eth->dev->of_node;
> +	struct device *dev = eth->dev;
> +	struct device_node *np;
> +	int i, ret;
> +
> +	for (i = 0; i < MTK_MAX_DEVS; i++) {
> +		np = of_parse_phandle(r, "mediatek,usxgmiisys", i);
> +		if (!np)
> +			break;
> +
> +		eth->usxgmii_pcs[i] = devm_kzalloc(dev, sizeof(*eth->usxgmii_pcs), GFP_KERNEL);

Smatch warns that only 8 bytes are allocated, whereas 64 are needed.
I think one more defference of the parameter to sizeof().

e.g.:

		eth->usxgmii_pcs[i] = devm_kzalloc(dev,
						   sizeof(*eth->usxgmii_pcs[i]),
						   GFP_KERNEL);

> +		if (!eth->usxgmii_pcs[i])
> +			return -ENOMEM;
> +
> +		eth->usxgmii_pcs[i]->id = i;
> +		eth->usxgmii_pcs[i]->eth = eth;
> +		eth->usxgmii_pcs[i]->regmap = syscon_node_to_regmap(np);
> +		if (IS_ERR(eth->usxgmii_pcs[i]->regmap))
> +			return PTR_ERR(eth->usxgmii_pcs[i]->regmap);
> +
> +		eth->usxgmii_pcs[i]->pcs.ops = &mtk_usxgmii_pcs_ops;
> +		eth->usxgmii_pcs[i]->pcs.poll = true;
> +		eth->usxgmii_pcs[i]->pcs.neg_mode = true;
> +		eth->usxgmii_pcs[i]->interface = PHY_INTERFACE_MODE_NA;
> +		eth->usxgmii_pcs[i]->neg_mode = -1;
> +
> +		of_node_put(np);
> +	}

...

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-08-27 15:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24 20:24 [PATCH RFC net-next v2] net: ethernet: mtk_eth_soc: add paths and SerDes modes for MT7988 Daniel Golle
2023-08-24 20:24 ` Daniel Golle
2023-08-27 15:35 ` Simon Horman [this message]
2023-08-27 15:35   ` Simon Horman
2023-08-27 16:09   ` Daniel Golle
2023-08-27 16:09     ` Daniel Golle

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=20230827153523.GS3523530@kernel.org \
    --to=horms@kernel.org \
    --cc=Mark-MC.Lee@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=john@phrozen.org \
    --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=lorenzo@kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nbd@nbd.name \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sean.wang@mediatek.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 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.