DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: liwencheng <liwencheng@phytium.com.cn>
Cc: dev@dpdk.org
Subject: Re: [PATCH v2 1/3] net/macb: add new driver
Date: Fri, 22 Nov 2024 12:44:40 -0800	[thread overview]
Message-ID: <20241122124440.281cac24@hermes.local> (raw)
In-Reply-To: <1730796099-1235390-1-git-send-email-liwencheng@phytium.com.cn>

On Tue,  5 Nov 2024 08:41:38 +0000
liwencheng <liwencheng@phytium.com.cn> wrote:

> +
> +int genphy_read_status(struct phy_device *phydev)
> +{
> +	struct macb *bp = phydev->bp;
> +	uint16_t bmcr, bmsr, ctrl1000 = 0, stat1000 = 0;
> +	uint32_t advertising, lp_advertising;
> +	uint32_t nego;
> +	uint16_t phyad = phydev->phyad;
> +
> +	/* Do a fake read */
> +	bmsr = macb_mdio_read(bp, phyad, GENERIC_PHY_BMSR);
> +
> +	bmsr = macb_mdio_read(bp, phyad, GENERIC_PHY_BMSR);
> +	bmcr = macb_mdio_read(bp, phyad, GENERIC_PHY_BMCR);
> +
> +	if (bmcr & BMCR_ANENABLE) {
> +		ctrl1000 = macb_mdio_read(bp, phyad, GENERIC_PHY_CTRL1000);
> +		stat1000 = macb_mdio_read(bp, phyad, GENERIC_PHY_STAT1000);
> +
> +		advertising = ADVERTISED_Autoneg;
> +		advertising |= genphy_get_an(bp, phyad, GENERIC_PHY_ADVERISE);
> +		advertising |= genphy_ctrl1000_to_ethtool_adv_t(ctrl1000);
> +
> +		if (bmsr & BMSR_ANEGCOMPLETE) {
> +			lp_advertising = genphy_get_an(bp, phyad, GENERIC_PHY_LPA);
> +			lp_advertising |= genphy_stat1000_to_ethtool_lpa_t(stat1000);
> +		} else {
> +			lp_advertising = 0;
> +		}
> +
> +		nego = advertising & lp_advertising;
> +		if (nego & (ADVERTISED_1000baseT_Full | ADVERTISED_1000baseT_Half)) {
> +			phydev->speed = SPEED_1000;
> +			phydev->duplex = !!(nego & ADVERTISED_1000baseT_Full);
> +		} else if (nego &
> +				(ADVERTISED_100baseT_Full | ADVERTISED_100baseT_Half)) {
> +			phydev->speed = SPEED_100;
> +			phydev->duplex = !!(nego & ADVERTISED_100baseT_Full);
> +		} else {
> +			phydev->speed = SPEED_10;
> +			phydev->duplex = !!(nego & ADVERTISED_10baseT_Full);
> +		}
> +	} else {
> +		phydev->speed = ((bmcr & BMCR_SPEED1000 && (bmcr & BMCR_SPEED100) == 0)
> +						 ? SPEED_1000
> +						 : ((bmcr & BMCR_SPEED100) ? SPEED_100 : SPEED_10));
> +		phydev->duplex = (bmcr & BMCR_FULLDPLX) ? DUPLEX_FULL : DUPLEX_HALF;
> +	}
> +
> +	return 0;
> +}

Always returns 0 can be void function?

> +int macb_usxgmii_pcs_resume(struct phy_device *phydev)
> +{
> +	u32 config;
> +	struct macb *bp = phydev->bp;
> +
> +	config = gem_readl(bp, USX_CONTROL);
> +
> +	/* enable signal */
> +	config &= ~(GEM_BIT(RX_SYNC_RESET));
> +	config |= GEM_BIT(SIGNAL_OK) | GEM_BIT(TX_EN);
> +	gem_writel(bp, USX_CONTROL, config);
> +
> +	return 0;
> +}

Always returns 0 can be void function?

> +int macb_usxgmii_pcs_suspend(struct phy_device *phydev)
> +{
> +	uint32_t config;
> +	struct macb *bp = phydev->bp;
> +
> +	config = gem_readl(bp, USX_CONTROL);
> +	config |= GEM_BIT(RX_SYNC_RESET);
> +	/* disable signal */
> +	config &= ~(GEM_BIT(SIGNAL_OK) | GEM_BIT(TX_EN));
> +	gem_writel(bp, USX_CONTROL, config);
> +	rte_delay_ms(1);
> +	return 0;
> +}

Always returns 0 should be void?

> +
> +int macb_usxgmii_pcs_check_for_link(struct phy_device *phydev)
> +{
> +	int value;
> +	int link;
> +	struct macb *bp = phydev->bp;
> +	value = gem_readl(bp, USX_STATUS);
> +	link = GEM_BFEXT(BLOCK_LOCK, value);
> +	return link;
> +}

The driver is sloppy in using int where unsigned value is possible.
You lose precision doing that and are prone to sign extension bugs.

Since gem_readl() is wrapper around macb_reg_readl() and that returns u32;
this function should be returning u32 and value should be u32
The temporary variable value is not needed.

> +int macb_gbe_pcs_check_for_link(struct phy_device *phydev)
> +{
> +	int value;
> +	int link;
> +	struct macb *bp = phydev->bp;
> +
> +	value = macb_readl(bp, NSR);
> +	link = MACB_BFEXT(NSR_LINK, value);
> +	return link;
> +}

      parent reply	other threads:[~2024-11-22 20:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-01 10:07 [PATCH v1 1/2] " liwencheng
2024-11-01 10:07 ` [PATCH v1 2/2] /usertools/dpdk-devbind:add the binding and unbinding of platform device liwencheng
2024-11-05  8:43   ` [PATCH v2 3/3] usertools/dpdk-devbind: add platform device bind/unbind liwencheng
2024-11-06  3:34     ` [PATCH v2 3/3] usertools/dpdk-devbind: add bind/unbind for platform device liwencheng
2024-11-11  7:43       ` liwencheng
2024-11-06  3:55   ` [PATCH v1 2/2] /usertools/dpdk-devbind:add the binding and unbinding of " Stephen Hemminger
2024-11-12  1:08     ` liwencheng
2024-11-01 16:13 ` [PATCH v1 1/2] net/macb: add new driver Stephen Hemminger
2024-11-01 17:42 ` Stephen Hemminger
2024-11-02  5:43 ` Stephen Hemminger
2024-11-05  8:41 ` [PATCH v2 1/3] " liwencheng
2024-11-05  8:41   ` [PATCH v2 2/3] net/macb: add NEON vectorized Rx/Tx liwencheng
2024-11-06  3:33     ` liwencheng
2024-11-11  7:42       ` liwencheng
2024-11-06  3:32   ` [PATCH v2 1/3] net/macb: add new driver liwencheng
2024-11-11  7:42     ` liwencheng
2024-11-22 17:55   ` Stephen Hemminger
2024-11-22 20:38   ` Stephen Hemminger
2024-11-22 20:44   ` Stephen Hemminger [this message]

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=20241122124440.281cac24@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=liwencheng@phytium.com.cn \
    /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).