diff mbox series

[net-next] net: phylink: Add phylinksetfixed_link() to configure fixed link state in phylink

Message ID 20240819052335.346184-1-Raju.Lakkaraju@microchip.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: phylink: Add phylinksetfixed_link() to configure fixed link state in phylink | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 21 this patch: 21
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 98 this patch: 98
netdev/checkpatch warning WARNING: function definition argument 'const struct phylink_link_state *' should also have an identifier name WARNING: function definition argument 'struct phylink *' should also have an identifier name
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc fail Errors and warnings before: 28 this patch: 29
netdev/source_inline success Was 0 now: 0

Commit Message

Raju Lakkaraju - I30499 Aug. 19, 2024, 5:23 a.m. UTC
From: Russell King <linux@armlinux.org.uk>

The function allows for the configuration of a fixed link state for a given
phylink instance. This addition is particularly useful for network devices that
operate with a fixed link configuration, where the link parameters do not change
dynamically. By using `phylink_set_fixed_link()`, drivers can easily set up
the fixed link state during initialization or configuration changes.

Signed-off-by: Russell King <linux@armlinux.org.uk> 
Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
---
Note: This code was developed by Mr.Russell King.

 drivers/net/phy/phylink.c | 42 +++++++++++++++++++++++++++++++++++++++
 include/linux/phylink.h   |  2 ++
 2 files changed, 44 insertions(+)

Comments

Andrew Lunn Aug. 19, 2024, 4:08 p.m. UTC | #1
> +/**
> + * phylink_set_fixed_link() - set the fixed link
> + * @pl: a pointer to a &struct phylink returned from phylink_create()
> + * @state: a pointer to a struct phylink_link_state.
> + *
> + * This function is used when the link parameters are known and do not change,
> + * making it suitable for certain types of network connections.
> + *
> + * Returns zero on success, or negative error code.

kernel doc requires a : after Returns. The tooling is getting more
picky about this and pointing out this error. But there is a lot of
code which gets this wrong, so you probably cut/paste a bad example.

    Andrew

---
pw-bot: cr
Simon Horman Aug. 19, 2024, 4:23 p.m. UTC | #2
On Mon, Aug 19, 2024 at 10:53:35AM +0530, Raju Lakkaraju wrote:
> From: Russell King <linux@armlinux.org.uk>
> 
> The function allows for the configuration of a fixed link state for a given
> phylink instance. This addition is particularly useful for network devices that
> operate with a fixed link configuration, where the link parameters do not change
> dynamically. By using `phylink_set_fixed_link()`, drivers can easily set up
> the fixed link state during initialization or configuration changes.
> 
> Signed-off-by: Russell King <linux@armlinux.org.uk> 
> Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
> ---
> Note: This code was developed by Mr.Russell King.

Hi,

I am wondering if we need a user of this function in order for this patch
to be accepted, as is often the practice for new features.
Raju Lakkaraju - I30499 Aug. 21, 2024, 7:48 a.m. UTC | #3
Hi Andrew,

Thank you for review the patch.

> -----Original Message-----
> From: Andrew Lunn <andrew@lunn.ch>
> Sent: Monday, August 19, 2024 9:39 PM
> To: Raju Lakkaraju - I30499 <Raju.Lakkaraju@microchip.com>
> Cc: netdev@vger.kernel.org; davem@davemloft.net; linux@armlinux.org.uk;
> kuba@kernel.org; horms@kernel.org; hkallweit1@gmail.com;
> richardcochran@gmail.com; rdunlap@infradead.org; Bryan Whitehead -
> C21958 <Bryan.Whitehead@microchip.com>; edumazet@google.com;
> pabeni@redhat.com; linux-kernel@vger.kernel.org; UNGLinuxDriver
> <UNGLinuxDriver@microchip.com>
> Subject: Re: [PATCH net-next] net: phylink: Add phylinksetfixed_link() to
> configure fixed link state in phylink
> 
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> > +/**
> > + * phylink_set_fixed_link() - set the fixed link
> > + * @pl: a pointer to a &struct phylink returned from phylink_create()
> > + * @state: a pointer to a struct phylink_link_state.
> > + *
> > + * This function is used when the link parameters are known and do
> > +not change,
> > + * making it suitable for certain types of network connections.
> > + *
> > + * Returns zero on success, or negative error code.
> 
> kernel doc requires a : after Returns. The tooling is getting more picky about
> this and pointing out this error. But there is a lot of code which gets this
> wrong, so you probably cut/paste a bad example.
> 

Ok. I will fix.
You are correct. I did copy/paste the string.

>     Andrew
> 
> ---
> pw-bot: cr

Thanks,
Raju
Raju Lakkaraju - I30499 Aug. 21, 2024, 7:55 a.m. UTC | #4
Hi Simon,

Thank you for review the patch.

> -----Original Message-----
> From: Simon Horman <horms@kernel.org>
> Sent: Monday, August 19, 2024 9:54 PM
> To: Raju Lakkaraju - I30499 <Raju.Lakkaraju@microchip.com>
> Cc: netdev@vger.kernel.org; davem@davemloft.net; linux@armlinux.org.uk;
> kuba@kernel.org; andrew@lunn.ch; hkallweit1@gmail.com;
> richardcochran@gmail.com; rdunlap@infradead.org; Bryan Whitehead -
> C21958 <Bryan.Whitehead@microchip.com>; edumazet@google.com;
> pabeni@redhat.com; linux-kernel@vger.kernel.org; UNGLinuxDriver
> <UNGLinuxDriver@microchip.com>
> Subject: Re: [PATCH net-next] net: phylink: Add phylinksetfixed_link() to
> configure fixed link state in phylink
> 
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> On Mon, Aug 19, 2024 at 10:53:35AM +0530, Raju Lakkaraju wrote:
> > From: Russell King <linux@armlinux.org.uk>
> >
> > The function allows for the configuration of a fixed link state for a
> > given phylink instance. This addition is particularly useful for
> > network devices that operate with a fixed link configuration, where
> > the link parameters do not change dynamically. By using
> > `phylink_set_fixed_link()`, drivers can easily set up the fixed link state during
> initialization or configuration changes.
> >
> > Signed-off-by: Russell King <linux@armlinux.org.uk>
> > Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
> > ---
> > Note: This code was developed by Mr.Russell King.
> 
> Hi,
> 
> I am wondering if we need a user of this function in order for this patch to be
> accepted, as is often the practice for new features.

This patch is Mr. Russell King's developed code which I'm submitting to Linux community for review.
just following Russell's request. 
i.e.
https://lore.kernel.org/netdev/ZsCMtARGCOLsbF9h@shell.armlinux.org.uk/

if it is required, I can send both together in a single series. Please confirm 

Hi Russell, Do you any concerns about Mr. Simon comments?

Thanks,
Raju
diff mbox series

Patch

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 51c526d227fa..56dc810b8e00 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -1635,6 +1635,48 @@  static int phylink_register_sfp(struct phylink *pl,
 	return ret;
 }
 
+/**
+ * phylink_set_fixed_link() - set the fixed link
+ * @pl: a pointer to a &struct phylink returned from phylink_create()
+ * @state: a pointer to a struct phylink_link_state.
+ *
+ * This function is used when the link parameters are known and do not change,
+ * making it suitable for certain types of network connections.
+ *
+ * Returns zero on success, or negative error code.
+ */
+int phylink_set_fixed_link(struct phylink *pl,
+			   const struct phylink_link_state *state)
+{
+	const struct phy_setting *s;
+	unsigned long *adv;
+
+	if (pl->cfg_link_an_mode != MLO_AN_PHY || !state ||
+	    !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state))
+		return -EINVAL;
+
+	s = phy_lookup_setting(state->speed, state->duplex,
+			       pl->supported, true);
+	if (!s)
+		return -EINVAL;
+
+	adv = pl->link_config.advertising;
+	linkmode_zero(adv);
+	linkmode_set_bit(s->bit, adv);
+	linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, adv);
+
+	pl->link_config.speed = state->speed;
+	pl->link_config.duplex = state->duplex;
+	pl->link_config.link = 1;
+	pl->link_config.an_complete = 1;
+
+	pl->cfg_link_an_mode = MLO_AN_FIXED;
+	pl->cur_link_an_mode = pl->cfg_link_an_mode;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(phylink_set_fixed_link);
+
 /**
  * phylink_create() - create a phylink instance
  * @config: a pointer to the target &struct phylink_config
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index 2381e07429a2..5c01048860c4 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -598,6 +598,8 @@  int phylink_fwnode_phy_connect(struct phylink *pl,
 			       const struct fwnode_handle *fwnode,
 			       u32 flags);
 void phylink_disconnect_phy(struct phylink *);
+int phylink_set_fixed_link(struct phylink *,
+			   const struct phylink_link_state *);
 
 void phylink_mac_change(struct phylink *, bool up);
 void phylink_pcs_change(struct phylink_pcs *, bool up);