diff mbox series

[v3,06/11] net: phylink: Add some helpers for working with mac caps

Message ID 20220725153730.2604096-7-sean.anderson@seco.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: phy: Add support for rate adaptation | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 94 this patch: 94
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 17 this patch: 17
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
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: 94 this patch: 94
netdev/checkpatch warning WARNING: line length of 89 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sean Anderson July 25, 2022, 3:37 p.m. UTC
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: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
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 v3:
- New

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

Comments

Vladimir Oltean July 25, 2022, 3:41 p.m. UTC | #1
On Mon, Jul 25, 2022 at 11:37:24AM -0400, 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: Vladimir Oltean <vladimir.oltean@nxp.com>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> 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/

I did not write even one line of code from this patch, please drop my
name from the next revision when there will be one.
Sean Anderson July 25, 2022, 3:42 p.m. UTC | #2
Hi Vladmir,

On 7/25/22 11:41 AM, Vladimir Oltean wrote:
> On Mon, Jul 25, 2022 at 11:37:24AM -0400, 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: Vladimir Oltean <vladimir.oltean@nxp.com>
>> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
>> 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/
> 
> I did not write even one line of code from this patch, please drop my
> name from the next revision when there will be one.
> 

I merely retained your CDB/SoB from [1].

--Sean
Vladimir Oltean July 25, 2022, 3:46 p.m. UTC | #3
On Mon, Jul 25, 2022 at 11:42:25AM -0400, Sean Anderson wrote:
> Hi Vladmir,
> 
> On 7/25/22 11:41 AM, Vladimir Oltean wrote:
> > On Mon, Jul 25, 2022 at 11:37:24AM -0400, 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: Vladimir Oltean <vladimir.oltean@nxp.com>
> >> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> >> 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/
> > 
> > I did not write even one line of code from this patch, please drop my
> > name from the next revision when there will be one.
> > 
> 
> I merely retained your CDB/SoB from [1].

Yes, but context matters, the logic that you cropped out from that patch
was exactly my contribution to that change, the result no longer has anything
to do with me. Maybe you didn't have any way to know this, but now you do.
Russell King (Oracle) July 25, 2022, 3:49 p.m. UTC | #4
On Mon, Jul 25, 2022 at 11:42:25AM -0400, Sean Anderson wrote:
> Hi Vladmir,
> 
> On 7/25/22 11:41 AM, Vladimir Oltean wrote:
> > On Mon, Jul 25, 2022 at 11:37:24AM -0400, 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: Vladimir Oltean <vladimir.oltean@nxp.com>
> >> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> >> 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/
> > 
> > I did not write even one line of code from this patch, please drop my
> > name from the next revision when there will be one.
> > 
> 
> I merely retained your CDB/SoB from [1].

What Vladimir is trying to say is that the code in this patch copied
from [1] was not written by him (although other bits in [1] were), and
thus this patch should not carry a Co-developed-by or s-o-b for him.

Thanks.
Sean Anderson July 25, 2022, 3:50 p.m. UTC | #5
On 7/25/22 11:46 AM, Vladimir Oltean wrote:
> On Mon, Jul 25, 2022 at 11:42:25AM -0400, Sean Anderson wrote:
>> Hi Vladmir,
>> 
>> On 7/25/22 11:41 AM, Vladimir Oltean wrote:
>> > On Mon, Jul 25, 2022 at 11:37:24AM -0400, 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: Vladimir Oltean <vladimir.oltean@nxp.com>
>> >> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
>> >> 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/
>> > 
>> > I did not write even one line of code from this patch, please drop my
>> > name from the next revision when there will be one.
>> > 
>> 
>> I merely retained your CDB/SoB from [1].
> 
> Yes, but context matters, the logic that you cropped out from that patch
> was exactly my contribution to that change, the result no longer has anything
> to do with me. Maybe you didn't have any way to know this, but now you do.
> 

OK, I will remove those lines from the next revision.

--Sean
diff mbox series

Patch

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 68a58ab6a8ed..72bf6b607320 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -304,6 +304,62 @@  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,