Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Gerhard Engleder <gerhard@engleder-embedded.com>
Cc: davem@davemloft.net, kuba@kernel.org, robh+dt@kernel.org,
	michal.simek@xilinx.com, netdev@vger.kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH net-next 4/5] tsnep: Add TSN endpoint Ethernet MAC driver
Date: Mon, 26 Jul 2021 23:15:21 +0200	[thread overview]
Message-ID: <YP8l6cWaQU/2NoIA@lunn.ch> (raw)
In-Reply-To: <20210726194603.14671-5-gerhard@engleder-embedded.com>

> +static int tsnep_mdiobus_read(struct mii_bus *bus, int addr, int regnum)
> +{
> +	struct tsnep_adapter *adapter = bus->priv;
> +	u16 data;
> +	int retval;
> +
> +	if (adapter->loopback)
> +		return 0;
> +
> +	retval = tsnep_read_md(adapter, addr, regnum, &data);
> +	if (retval != 0)
> +		return retval;

It appears your MDIO bus can only do C22. Please add a test for C45 and return -EOPNOTSUPP.

> +static void tsnep_phy_link_status_change(struct net_device *netdev)
> +{
> +	struct tsnep_adapter *adapter = netdev_priv(netdev);
> +	struct phy_device *phydev = netdev->phydev;
> +
> +	if (adapter->loopback)
> +		return;
> +
> +	if (adapter->gmii2rgmii) {
> +		u16 val;
> +
> +		if (phydev->link && phydev->speed == 1000)
> +			val = BMCR_SPEED1000;
> +		else
> +			val = BMCR_SPEED100;
> +		tsnep_write_md(adapter, ECM_GMII2RGMII_ADDR,
> +			       ECM_GMII2RGMII_BMCR, val);
> +	}

I _think_ this is wrong. They way the PHYs are chained means you
should not need to do this, the xgmiitorgmii_read_status() does it.
Maybe you have the chaining setup wrong?

> +static int tsnep_phy_open(struct tsnep_adapter *adapter)
> +{
> +	__ETHTOOL_DECLARE_LINK_MODE_MASK(mask);
> +	struct ethtool_eee ethtool_eee;
> +	int retval;
> +
> +	retval = phy_connect_direct(adapter->netdev, adapter->phydev,
> +				    tsnep_phy_link_status_change,
> +				    adapter->phy_mode);
> +	if (retval)
> +		return -EIO;

phy_connect_direct() returns an error code. Use it, rather than
changing it to something else. This applies everywhere. You must have
a good reason to change error codes, and then it is wise to put a
comment why you change it.

> +
> +	/* MAC supports only 100Mbps|1000Mbps full duplex
> +	 * SPE (Single Pair Ethernet) is also an option but not implemented yet
> +	 */
> +	linkmode_zero(mask);
> +	linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, mask);
> +	linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, mask);
> +	linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, mask);
> +	linkmode_and(mask, adapter->phydev->supported, mask);
> +	linkmode_copy(adapter->phydev->supported, mask);
> +	linkmode_copy(adapter->phydev->advertising, mask);

You should not be accessing the phydev directly. Use
phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT),
etc.

> +static int tsnep_phy_init(struct tsnep_adapter *adapter)
> +{
> +	struct device_node *dn;
> +	u16 val;
> +	u32 id;
> +	int retval;
> +
> +	retval = of_get_phy_mode(adapter->pdev->dev.of_node,
> +				 &adapter->phy_mode);
> +	if (retval)
> +		adapter->phy_mode = PHY_INTERFACE_MODE_GMII;
> +
> +	dn = of_parse_phandle(adapter->pdev->dev.of_node, "phy-handle", 0);
> +	adapter->phydev = of_phy_find_device(dn);
> +	if (!adapter->phydev)
> +		adapter->phydev = phy_find_first(adapter->mdiobus);
> +	if (!adapter->phydev)
> +		return -EIO;
> +
> +	/* detect optional GMII2RGMII */
> +	retval = tsnep_read_md(adapter, ECM_GMII2RGMII_ADDR, MII_PHYSID1, &val);
> +	if (retval)
> +		return retval;
> +	id = val << 16;
> +	retval = tsnep_read_md(adapter, ECM_GMII2RGMII_ADDR, MII_PHYSID2, &val);
> +	if (retval)
> +		return retval;
> +	id |= val;
> +	if (id == 0)
> +		adapter->gmii2rgmii = true;

This is where i think GMII2RGMII goes wrong. MAC phy-handle should
point to the GMII2RGMII device in DT. The GMII2RGMII should have a
phy-handle which points to the PHY.

> +	/* reset PHY */
> +	retval = tsnep_write_md(adapter, adapter->phydev->mdio.addr, MII_BMCR,
> +				BMCR_RESET);
> +	if (retval)
> +		return retval;
> +
> +	/* reset GMII2RGMII */
> +	if (adapter->gmii2rgmii) {
> +		retval = tsnep_write_md(adapter, ECM_GMII2RGMII_ADDR,
> +					ECM_GMII2RGMII_BMCR, BMCR_RESET);
> +		if (retval)
> +			return retval;
> +		retval = tsnep_write_md(adapter, ECM_GMII2RGMII_ADDR,
> +					ECM_GMII2RGMII_BMCR, BMCR_SPEED100);
> +		if (retval)
> +			return retval;
> +	}

The PHY driver is in control of the PHY, not the MAC. Please remove.

    Andrew

  parent reply	other threads:[~2021-07-26 21:15 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-26 19:45 [PATCH net-next 0/5] " Gerhard Engleder
2021-07-26 19:45 ` [PATCH net-next 1/5] dt-bindings: Add vendor prefix for Engleder Gerhard Engleder
2021-07-26 19:46 ` [PATCH net-next 2/5] dt-bindings: net: Add tsnep Ethernet controller Gerhard Engleder
2021-07-26 23:35   ` Rob Herring
2021-07-27 18:34     ` Gerhard Engleder
2021-07-27 20:25       ` Rob Herring
2021-07-27 20:33         ` Gerhard Engleder
2021-07-28  5:13         ` Michal Simek
2021-07-28  7:44           ` Gerhard Engleder
2021-07-28 10:55             ` Michal Simek
2021-07-28 20:14               ` Gerhard Engleder
2021-07-29  5:07                 ` Michal Simek
2021-07-29  7:07                   ` Gerhard Engleder
2021-07-29  7:57                     ` Michal Simek
2021-07-26 19:46 ` [PATCH net-next 3/5] dt-bindings: arm: Add Engleder bindings Gerhard Engleder
2021-07-26 19:46 ` [PATCH net-next 4/5] tsnep: Add TSN endpoint Ethernet MAC driver Gerhard Engleder
2021-07-26 20:49   ` Andrew Lunn
2021-07-27 20:18     ` Gerhard Engleder
2021-07-26 21:15   ` Andrew Lunn [this message]
2021-07-27 20:49     ` Gerhard Engleder
2021-07-26 21:29   ` Andrew Lunn
2021-07-27 22:05     ` Gerhard Engleder
2021-07-27 22:41       ` Andrew Lunn
2021-07-28  8:24         ` Gerhard Engleder
2021-07-26 23:25   ` kernel test robot
2021-07-26 19:46 ` [PATCH net-next 5/5] arm64: dts: zynqmp: Add ZCU104 based TSN endpoint Gerhard Engleder
2021-07-26 23:40   ` Rob Herring
2021-07-27 20:10     ` Gerhard Engleder
2021-07-27 20:17       ` Rob Herring
2021-07-27 20:23         ` Gerhard Engleder
2021-07-28  5:10           ` Michal Simek
2021-07-28  8:19             ` Gerhard Engleder
2021-07-28 10:58               ` Michal Simek
2021-07-28 20:51                 ` Gerhard Engleder
2021-07-29  5:22                   ` Michal Simek
2021-07-29  6:47                     ` Gerhard Engleder

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=YP8l6cWaQU/2NoIA@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=gerhard@engleder-embedded.com \
    --cc=kuba@kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=netdev@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --subject='Re: [PATCH net-next 4/5] tsnep: Add TSN endpoint Ethernet MAC driver' \
    /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

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).