From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
To: Vladimir Oltean <olteanv@gmail.com>
Cc: davem@davemloft.net, jakub.kicinski@netronome.com,
andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com,
alexandru.marginean@nxp.com, claudiu.manoil@nxp.com,
xiaoliang.yang_1@nxp.com, yangbo.lu@nxp.com,
netdev@vger.kernel.org, alexandre.belloni@bootlin.com,
horatiu.vultur@microchip.com,
Vladimir Oltean <vladimir.oltean@nxp.com>
Subject: Re: [RFC PATCH v2 1/8] mii: Add helpers for parsing SGMII auto-negotiation
Date: Wed, 18 Dec 2019 18:50:58 +0000 [thread overview]
Message-ID: <20191218185058.GW25745@shell.armlinux.org.uk> (raw)
In-Reply-To: <20191217221831.10923-2-olteanv@gmail.com>
On Wed, Dec 18, 2019 at 12:18:24AM +0200, Vladimir Oltean wrote:
> From: Vladimir Oltean <vladimir.oltean@nxp.com>
>
> Typically a MAC PCS auto-configures itself after it receives the
> negotiated copper-side link settings from the PHY, but some MAC devices
> are more special and need manual interpretation of the SGMII AN result.
>
> In other cases, the PCS exposes the entire tx_config_reg base page as it
> is transmitted on the wire during auto-negotiation, so it makes sense to
> be able to decode the equivalent lp_advertised bit mask from the raw u16
> (of course, "lp" considering the PCS to be the local PHY).
>
> Therefore, add the bit definitions for the SGMII registers 4 and 5
> (local device ability, link partner ability), as well as a link_mode
> conversion helper that can be used to feed the AN results into
> phy_resolve_aneg_linkmode.
>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---
> include/linux/mii.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
> include/uapi/linux/mii.h | 10 ++++++++++
> 2 files changed, 60 insertions(+)
>
> diff --git a/include/linux/mii.h b/include/linux/mii.h
> index 4ce8901a1af6..18c6208f56fc 100644
> --- a/include/linux/mii.h
> +++ b/include/linux/mii.h
> @@ -373,6 +373,56 @@ static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa)
> }
>
> /**
> + * mii_lpa_mod_linkmode_adv_sgmii
> + * @lp_advertising: pointer to destination link mode.
> + * @lpa: value of the MII_LPA register
> + *
> + * A small helper function that translates MII_LPA bits to
> + * linkmode advertisement settings for SGMII.
> + * Leaves other bits unchanged.
> + */
> +static inline void
> +mii_lpa_mod_linkmode_lpa_sgmii(unsigned long *lp_advertising, u32 lpa)
> +{
> + u32 speed_duplex = lpa & LPA_SGMII_DPX_SPD_MASK;
> +
> + linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, lp_advertising,
> + speed_duplex == LPA_SGMII_1000HALF);
> +
> + linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, lp_advertising,
> + speed_duplex == LPA_SGMII_1000FULL);
> +
> + linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, lp_advertising,
> + speed_duplex == LPA_SGMII_100HALF);
> +
> + linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, lp_advertising,
> + speed_duplex == LPA_SGMII_100FULL);
> +
> + linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, lp_advertising,
> + speed_duplex == LPA_SGMII_10HALF);
> +
> + linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, lp_advertising,
> + speed_duplex == LPA_SGMII_10FULL);
> +}
> +
> +/**
> + * mii_lpa_to_linkmode_adv_sgmii
> + * @advertising: pointer to destination link mode.
> + * @lpa: value of the MII_LPA register
> + *
> + * A small helper function that translates MII_ADVERTISE bits
> + * to linkmode advertisement settings when in SGMII mode.
> + * Clears the old value of advertising.
> + */
> +static inline void mii_lpa_to_linkmode_lpa_sgmii(unsigned long *lp_advertising,
> + u32 lpa)
> +{
> + linkmode_zero(lp_advertising);
> +
> + mii_lpa_mod_linkmode_lpa_sgmii(lp_advertising, lpa);
> +}
> +
> +/**
> * mii_adv_mod_linkmode_adv_t
> * @advertising:pointer to destination link mode.
> * @adv: value of the MII_ADVERTISE register
> diff --git a/include/uapi/linux/mii.h b/include/uapi/linux/mii.h
> index 51b48e4be1f2..dc3b5d635beb 100644
> --- a/include/uapi/linux/mii.h
> +++ b/include/uapi/linux/mii.h
> @@ -71,6 +71,7 @@
> /* Advertisement control register. */
> #define ADVERTISE_SLCT 0x001f /* Selector bits */
> #define ADVERTISE_CSMA 0x0001 /* Only selector supported */
> +#define ADVERTISE_SGMII 0x0001 /* Can do SGMII */
> #define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
> #define ADVERTISE_1000XFULL 0x0020 /* Try for 1000BASE-X full-duplex */
> #define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
> @@ -94,6 +95,7 @@
>
> /* Link partner ability register. */
> #define LPA_SLCT 0x001f /* Same as advertise selector */
> +#define LPA_SGMII 0x0001 /* Can do SGMII */
> #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
> #define LPA_1000XFULL 0x0020 /* Can do 1000BASE-X full-duplex */
> #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
> @@ -104,11 +106,19 @@
> #define LPA_1000XPAUSE_ASYM 0x0100 /* Can do 1000BASE-X pause asym*/
> #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
> #define LPA_PAUSE_CAP 0x0400 /* Can pause */
> +#define LPA_SGMII_DPX_SPD_MASK 0x1C00 /* SGMII duplex and speed bits */
> +#define LPA_SGMII_10HALF 0x0000 /* Can do SGMII 10mbps half-duplex */
> +#define LPA_SGMII_10FULL 0x1000 /* Can do SGMII 10mbps full-duplex */
> +#define LPA_SGMII_100HALF 0x0400 /* Can do SGMII 100mbps half-duplex */
> +#define LPA_SGMII_100FULL 0x1400 /* Can do SGMII 100mbps full-duplex */
> #define LPA_PAUSE_ASYM 0x0800 /* Can pause asymetrically */
> +#define LPA_SGMII_1000HALF 0x0800 /* Can do SGMII 1000mbps half-duplex */
> +#define LPA_SGMII_1000FULL 0x1800 /* Can do SGMII 1000mbps full-duplex */
> #define LPA_RESV 0x1000 /* Unused... */
> #define LPA_RFAULT 0x2000 /* Link partner faulted */
> #define LPA_LPACK 0x4000 /* Link partner acked us */
> #define LPA_NPAGE 0x8000 /* Next page bit */
> +#define LPA_SGMII_LINK 0x8000 /* Link partner has link */
I wonder whether mixing these definitions together is really such a
good idea, or whether separately grouping them would be better.
I already find the mixture of Clause 37 and Clause 22 definitions to
be a little difficult to spot which are which.
>
> #define LPA_DUPLEX (LPA_10FULL | LPA_100FULL)
> #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
> --
> 2.7.4
>
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
next prev parent reply other threads:[~2019-12-18 18:51 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-17 22:18 [RFC PATCH v2 0/8] Convert Felix DSA switch to PHYLINK Vladimir Oltean
2019-12-17 22:18 ` [RFC PATCH v2 1/8] mii: Add helpers for parsing SGMII auto-negotiation Vladimir Oltean
2019-12-18 18:50 ` Russell King - ARM Linux admin [this message]
2019-12-19 9:10 ` Andrew Lunn
2019-12-17 22:18 ` [RFC PATCH v2 2/8] net: phylink: make QSGMII a valid PHY mode for in-band AN Vladimir Oltean
2019-12-17 22:18 ` [RFC PATCH v2 3/8] net: phylink: call mac_an_restart for SGMII/QSGMII inband interfaces too Vladimir Oltean
2019-12-17 23:25 ` Russell King - ARM Linux admin
2019-12-17 22:18 ` [RFC PATCH v2 4/8] enetc: Make MDIO accessors more generic and export to include/linux/fsl Vladimir Oltean
2019-12-17 23:39 ` Jakub Kicinski
2019-12-17 22:18 ` [RFC PATCH v2 5/8] enetc: Set MDIO_CFG_HOLD to the recommended value of 2 Vladimir Oltean
2019-12-17 22:18 ` [RFC PATCH v2 6/8] net: mscc: ocelot: make phy_mode a member of the common struct ocelot_port Vladimir Oltean
2019-12-17 22:18 ` [RFC PATCH v2 7/8] net: mscc: ocelot: export ANA, DEV and QSYS registers to include/soc/mscc Vladimir Oltean
2019-12-17 22:18 ` [RFC PATCH v2 8/8] net: dsa: felix: Add PCS operations for PHYLINK Vladimir Oltean
2019-12-18 10:40 ` [RFC PATCH v2 0/8] Convert Felix DSA switch to PHYLINK Russell King - ARM Linux admin
2019-12-18 13:21 ` Vladimir Oltean
2019-12-18 13:29 ` Russell King - ARM Linux admin
2019-12-18 15:00 ` Alexandru Marginean
2019-12-18 17:22 ` Russell King - ARM Linux admin
2019-12-18 20:15 ` Alexandru Marginean
2019-12-18 23:21 ` Russell King - ARM Linux admin
2019-12-19 11:38 ` Alexandru Marginean
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=20191218185058.GW25745@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=alexandre.belloni@bootlin.com \
--cc=alexandru.marginean@nxp.com \
--cc=andrew@lunn.ch \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=horatiu.vultur@microchip.com \
--cc=jakub.kicinski@netronome.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=vivien.didelot@gmail.com \
--cc=vladimir.oltean@nxp.com \
--cc=xiaoliang.yang_1@nxp.com \
--cc=yangbo.lu@nxp.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).