mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Anderson <sean.anderson@seco.com>
To: netdev@vger.kernel.org, Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>
Cc: "David S . Miller" <davem@davemloft.net>,
	Paolo Abeni <pabeni@redhat.com>,
	Vladimir Oltean <olteanv@gmail.com>,
	linux-kernel@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Alexandru Marginean <alexandru.marginean@nxp.com>,
	Russell King <rmk+kernel@armlinux.org.uk>
Subject: Re: [PATCH net-next v4 05/10] net: phylink: Add some helpers for working with mac caps
Date: Thu, 18 Aug 2022 12:55:05 -0400	[thread overview]
Message-ID: <965bdb53-834b-2e53-f272-b338cebe08be@seco.com> (raw)
In-Reply-To: <20220818164616.2064242-6-sean.anderson@seco.com>



On 8/18/22 12:46 PM, Sean Anderson wrote:
> This adds a table for converting between speed/duplex and mac
> capabilities. It also adds a helper for getting the max speed/duplex
> from some caps. It is intended to be used by Russell King's DSA phylink
> series. The table will be used directly later in this series.
> 
> Co-developed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> [ adapted to live in phylink.c ]
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> ---
> This is adapted from [1].
> 
> [1] https://lore.kernel.org/netdev/E1oCNlE-006e3z-3T@rmk-PC.armlinux.org.uk/
> 
> Changes in v4:
> - Wrap docstring to 80 columns
> 
> Changes in v3:
> - New
> 
>  drivers/net/phy/phylink.c | 57 +++++++++++++++++++++++++++++++++++++++
>  include/linux/phylink.h   |  2 ++
>  2 files changed, 59 insertions(+)
> 
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 68a58ab6a8ed..8a9da7449c73 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
> @@ -304,6 +304,63 @@ void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps)
>  }
>  EXPORT_SYMBOL_GPL(phylink_caps_to_linkmodes);
>  
> +static struct {
> +	unsigned long mask;
> +	int speed;
> +	unsigned int duplex;
> +} phylink_caps_params[] = {
> +	{ MAC_400000FD, SPEED_400000, DUPLEX_FULL },
> +	{ MAC_200000FD, SPEED_200000, DUPLEX_FULL },
> +	{ MAC_100000FD, SPEED_100000, DUPLEX_FULL },
> +	{ MAC_56000FD,  SPEED_56000,  DUPLEX_FULL },
> +	{ MAC_50000FD,  SPEED_50000,  DUPLEX_FULL },
> +	{ MAC_40000FD,  SPEED_40000,  DUPLEX_FULL },
> +	{ MAC_25000FD,  SPEED_25000,  DUPLEX_FULL },
> +	{ MAC_20000FD,  SPEED_20000,  DUPLEX_FULL },
> +	{ MAC_10000FD,  SPEED_10000,  DUPLEX_FULL },
> +	{ MAC_5000FD,   SPEED_5000,   DUPLEX_FULL },
> +	{ MAC_2500FD,   SPEED_2500,   DUPLEX_FULL },
> +	{ MAC_1000FD,   SPEED_1000,   DUPLEX_FULL },
> +	{ MAC_1000HD,   SPEED_1000,   DUPLEX_HALF },
> +	{ MAC_100FD,    SPEED_100,    DUPLEX_FULL },
> +	{ MAC_100HD,    SPEED_100,    DUPLEX_HALF },
> +	{ MAC_10FD,     SPEED_10,     DUPLEX_FULL },
> +	{ MAC_10HD,     SPEED_10,     DUPLEX_HALF },
> +};
> +
> +/**
> + * phylink_caps_find_max_speed() - Find the max speed/duplex of mac capabilities
> + * @caps: A mask of mac capabilities
> + * @speed: Variable to store the maximum speed
> + * @duplex: Variable to store the maximum duplex
> + *
> + * Find the maximum speed (and associated duplex) supported by a mask of mac
> + * capabilities. @speed and @duplex are always set, even if no matching mac
> + * capability was found.
> + *
> + * Return: 0 on success, or %-EINVAL if the maximum speed/duplex could not be
> + *         determined.
> + */
> +int phylink_caps_find_max_speed(unsigned long caps, int *speed,
> +				unsigned int *duplex)
> +{
> +	int i;
> +
> +	*speed = SPEED_UNKNOWN;
> +	*duplex = DUPLEX_UNKNOWN;
> +
> +	for (i = 0; i < ARRAY_SIZE(phylink_caps_params); i++) {
> +		if (caps & phylink_caps_params[i].mask) {
> +			*speed = phylink_caps_params[i].speed;
> +			*duplex = phylink_caps_params[i].duplex;
> +			return 0;
> +		}
> +	}
> +
> +	return -EINVAL;
> +}
> +EXPORT_SYMBOL_GPL(phylink_caps_find_max_speed);
> +
>  /**
>   * phylink_get_capabilities() - get capabilities for a given MAC
>   * @interface: phy interface mode defined by &typedef phy_interface_t
> diff --git a/include/linux/phylink.h b/include/linux/phylink.h
> index 661d1d4fdbec..a5a236cfacb6 100644
> --- a/include/linux/phylink.h
> +++ b/include/linux/phylink.h
> @@ -535,6 +535,8 @@ void pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
>  #endif
>  
>  void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
> +int phylink_caps_find_max_speed(unsigned long caps, int *speed,
> +				unsigned int *duplex);
>  unsigned long phylink_get_capabilities(phy_interface_t interface,
>  				       unsigned long mac_capabilities);
>  void phylink_generic_validate(struct phylink_config *config,
> 

...and it looks like I removed the wrong helper function

(that is, phylink_cap_from_speed_duplex was removed instead of
 phylink_caps_find_max_speed)

Will be fixed in v5

--Sean

  reply	other threads:[~2022-08-18 16:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18 16:46 [PATCH net-next v4 00/10] net: phy: Add support for rate adaptation Sean Anderson
2022-08-18 16:46 ` [PATCH net-next v4 01/10] net: phy: Add 1000BASE-KX interface mode Sean Anderson
2022-08-18 16:46 ` [PATCH net-next v4 02/10] net: phylink: Document MAC_(A)SYM_PAUSE Sean Anderson
2022-08-18 16:46 ` [PATCH net-next v4 03/10] net: phylink: Export phylink_caps_to_linkmodes Sean Anderson
2022-08-18 16:46 ` [PATCH net-next v4 04/10] net: phylink: Generate caps and convert to linkmodes separately Sean Anderson
2022-08-18 16:46 ` [PATCH net-next v4 05/10] net: phylink: Add some helpers for working with mac caps Sean Anderson
2022-08-18 16:55   ` Sean Anderson [this message]
2022-08-18 16:46 ` [PATCH net-next v4 06/10] net: phy: Add support for rate adaptation Sean Anderson
2022-08-18 16:46 ` [PATCH net-next v4 07/10] net: phylink: Adjust link settings based on " Sean Anderson
2022-08-18 16:46 ` [PATCH net-next v4 08/10] net: phylink: Adjust advertisement " Sean Anderson
2022-08-18 19:00   ` kernel test robot
2022-08-18 19:31   ` kernel test robot
2022-08-18 16:46 ` [PATCH net-next v4 09/10] net: phy: aquantia: Add some additional phy interfaces Sean Anderson
2022-08-18 16:46 ` [PATCH net-next v4 10/10] net: phy: aquantia: Add support for rate adaptation Sean Anderson

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=965bdb53-834b-2e53-f272-b338cebe08be@seco.com \
    --to=sean.anderson@seco.com \
    --cc=alexandru.marginean@nxp.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=rmk+kernel@armlinux.org.uk \
    /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

all inboxes | Powered by JetHome®