* [PATCH net-next 0/3] Introduce supported interfaces bitmap
@ 2021-10-26 10:05 Russell King (Oracle)
2021-10-26 10:06 ` [PATCH net-next 1/3] net: phy: add phy_interface_t bitmap support Russell King (Oracle)
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Russell King (Oracle) @ 2021-10-26 10:05 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Sean Anderson
Cc: David S. Miller, Jakub Kicinski, netdev
This series introduces a new bitmap to allow us to indicate which
phy_interface_t modes are supported.
Currently, phylink will call ->validate with PHY_INTERFACE_MODE_NA to
request all link mode capabilities from the MAC driver before choosing
an interface to use. This leads in some cases to some rather hairly
code. This can be simplified if phylink is aware of the interface modes
that the MAC supports, and it can instead walk those modes, calling
->validate for each one, and combining the results.
This series merely introduces the support; there is no change of
behaviour until MAC drivers populate their supported_interfaces bitmap.
drivers/net/phy/phylink.c | 36 ++++++++++++++++++++++++++++++++++++
include/linux/phy.h | 34 ++++++++++++++++++++++++++++++++++
include/linux/phylink.h | 13 +++++++++++--
3 files changed, 81 insertions(+), 2 deletions(-)
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 1/3] net: phy: add phy_interface_t bitmap support
2021-10-26 10:05 [PATCH net-next 0/3] Introduce supported interfaces bitmap Russell King (Oracle)
@ 2021-10-26 10:06 ` Russell King (Oracle)
2021-10-26 10:06 ` [PATCH net-next 2/3] net: phylink: add MAC phy_interface_t bitmap Russell King
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Russell King (Oracle) @ 2021-10-26 10:06 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Sean Anderson; +Cc: netdev
Add support for a bitmap for phy interface modes, which includes:
- a macro to declare the interface bitmap
- an inline helper to zero the interface bitmap
- an inline helper to detect an empty interface bitmap
- inline helpers to do a bitwise AND and OR operations on two interface
bitmaps
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
include/linux/phy.h | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 04e90423fa88..96e43fbb2dd8 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -155,6 +155,40 @@ typedef enum {
PHY_INTERFACE_MODE_MAX,
} phy_interface_t;
+/* PHY interface mode bitmap handling */
+#define DECLARE_PHY_INTERFACE_MASK(name) \
+ DECLARE_BITMAP(name, PHY_INTERFACE_MODE_MAX)
+
+static inline void phy_interface_zero(unsigned long *intf)
+{
+ bitmap_zero(intf, PHY_INTERFACE_MODE_MAX);
+}
+
+static inline bool phy_interface_empty(const unsigned long *intf)
+{
+ return bitmap_empty(intf, PHY_INTERFACE_MODE_MAX);
+}
+
+static inline void phy_interface_and(unsigned long *dst, const unsigned long *a,
+ const unsigned long *b)
+{
+ bitmap_and(dst, a, b, PHY_INTERFACE_MODE_MAX);
+}
+
+static inline void phy_interface_or(unsigned long *dst, const unsigned long *a,
+ const unsigned long *b)
+{
+ bitmap_or(dst, a, b, PHY_INTERFACE_MODE_MAX);
+}
+
+static inline void phy_interface_set_rgmii(unsigned long *intf)
+{
+ __set_bit(PHY_INTERFACE_MODE_RGMII, intf);
+ __set_bit(PHY_INTERFACE_MODE_RGMII_ID, intf);
+ __set_bit(PHY_INTERFACE_MODE_RGMII_RXID, intf);
+ __set_bit(PHY_INTERFACE_MODE_RGMII_TXID, intf);
+}
+
/*
* phy_supported_speeds - return all speeds currently supported by a PHY device
*/
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 2/3] net: phylink: add MAC phy_interface_t bitmap
2021-10-26 10:05 [PATCH net-next 0/3] Introduce supported interfaces bitmap Russell King (Oracle)
2021-10-26 10:06 ` [PATCH net-next 1/3] net: phy: add phy_interface_t bitmap support Russell King (Oracle)
@ 2021-10-26 10:06 ` Russell King
2021-10-26 10:06 ` [PATCH net-next 3/3] net: phylink: use supported_interfaces for phylink validation Russell King (Oracle)
2021-10-26 14:20 ` [PATCH net-next 0/3] Introduce supported interfaces bitmap patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Russell King @ 2021-10-26 10:06 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Sean Anderson; +Cc: netdev
Add a phy_interface_t bitmap so the MAC driver can specifiy which PHY
interface modes it supports.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
include/linux/phylink.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index f7b5ed06a815..bc4b866cd99b 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -76,6 +76,7 @@ struct phylink_config {
bool ovr_an_inband;
void (*get_fixed_state)(struct phylink_config *config,
struct phylink_link_state *state);
+ DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
};
/**
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 3/3] net: phylink: use supported_interfaces for phylink validation
2021-10-26 10:05 [PATCH net-next 0/3] Introduce supported interfaces bitmap Russell King (Oracle)
2021-10-26 10:06 ` [PATCH net-next 1/3] net: phy: add phy_interface_t bitmap support Russell King (Oracle)
2021-10-26 10:06 ` [PATCH net-next 2/3] net: phylink: add MAC phy_interface_t bitmap Russell King
@ 2021-10-26 10:06 ` Russell King (Oracle)
2021-10-26 14:20 ` [PATCH net-next 0/3] Introduce supported interfaces bitmap patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Russell King (Oracle) @ 2021-10-26 10:06 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Sean Anderson
Cc: David S. Miller, Jakub Kicinski, netdev
If the network device supplies a supported interface bitmap, we can use
that during phylink's validation to simplify MAC drivers in two ways by
using the supported_interfaces bitmap to:
1. reject unsupported interfaces before calling into the MAC driver.
2. generate the set of all supported link modes across all supported
interfaces (used mainly for SFP, but also some 10G PHYs.)
Suggested-by: Sean Anderson <sean.anderson@seco.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/phy/phylink.c | 36 ++++++++++++++++++++++++++++++++++++
include/linux/phylink.h | 12 ++++++++++--
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 14c7d73790b4..6da245dacca4 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -166,9 +166,45 @@ static const char *phylink_an_mode_str(unsigned int mode)
return mode < ARRAY_SIZE(modestr) ? modestr[mode] : "unknown";
}
+static int phylink_validate_any(struct phylink *pl, unsigned long *supported,
+ struct phylink_link_state *state)
+{
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(all_adv) = { 0, };
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(all_s) = { 0, };
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(s);
+ struct phylink_link_state t;
+ int intf;
+
+ for (intf = 0; intf < PHY_INTERFACE_MODE_MAX; intf++) {
+ if (test_bit(intf, pl->config->supported_interfaces)) {
+ linkmode_copy(s, supported);
+
+ t = *state;
+ t.interface = intf;
+ pl->mac_ops->validate(pl->config, s, &t);
+ linkmode_or(all_s, all_s, s);
+ linkmode_or(all_adv, all_adv, t.advertising);
+ }
+ }
+
+ linkmode_copy(supported, all_s);
+ linkmode_copy(state->advertising, all_adv);
+
+ return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
+}
+
static int phylink_validate(struct phylink *pl, unsigned long *supported,
struct phylink_link_state *state)
{
+ if (!phy_interface_empty(pl->config->supported_interfaces)) {
+ if (state->interface == PHY_INTERFACE_MODE_NA)
+ return phylink_validate_any(pl, supported, state);
+
+ if (!test_bit(state->interface,
+ pl->config->supported_interfaces))
+ return -EINVAL;
+ }
+
pl->mac_ops->validate(pl->config, supported, state);
return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index bc4b866cd99b..f037470b6fb3 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -67,6 +67,8 @@ enum phylink_op_type {
* @ovr_an_inband: if true, override PCS to MLO_AN_INBAND
* @get_fixed_state: callback to execute to determine the fixed link state,
* if MAC link is at %MLO_AN_FIXED mode.
+ * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx
+ * are supported by the MAC/PCS.
*/
struct phylink_config {
struct device *dev;
@@ -134,8 +136,14 @@ struct phylink_mac_ops {
* based on @state->advertising and/or @state->speed and update
* @state->interface accordingly. See phylink_helper_basex_speed().
*
- * When @state->interface is %PHY_INTERFACE_MODE_NA, phylink expects the
- * MAC driver to return all supported link modes.
+ * When @config->supported_interfaces has been set, phylink will iterate
+ * over the supported interfaces to determine the full capability of the
+ * MAC. The validation function must not print errors if @state->interface
+ * is set to an unexpected value.
+ *
+ * When @config->supported_interfaces is empty, phylink will call this
+ * function with @state->interface set to %PHY_INTERFACE_MODE_NA, and
+ * expects the MAC driver to return all supported link modes.
*
* If the @state->interface mode is not supported, then the @supported
* mask must be cleared.
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 0/3] Introduce supported interfaces bitmap
2021-10-26 10:05 [PATCH net-next 0/3] Introduce supported interfaces bitmap Russell King (Oracle)
` (2 preceding siblings ...)
2021-10-26 10:06 ` [PATCH net-next 3/3] net: phylink: use supported_interfaces for phylink validation Russell King (Oracle)
@ 2021-10-26 14:20 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-10-26 14:20 UTC (permalink / raw)
To: Russell King; +Cc: andrew, hkallweit1, sean.anderson, davem, kuba, netdev
Hello:
This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:
On Tue, 26 Oct 2021 11:05:36 +0100 you wrote:
> This series introduces a new bitmap to allow us to indicate which
> phy_interface_t modes are supported.
>
> Currently, phylink will call ->validate with PHY_INTERFACE_MODE_NA to
> request all link mode capabilities from the MAC driver before choosing
> an interface to use. This leads in some cases to some rather hairly
> code. This can be simplified if phylink is aware of the interface modes
> that the MAC supports, and it can instead walk those modes, calling
> ->validate for each one, and combining the results.
>
> [...]
Here is the summary with links:
- [net-next,1/3] net: phy: add phy_interface_t bitmap support
https://git.kernel.org/netdev/net-next/c/8e20f591f204
- [net-next,2/3] net: phylink: add MAC phy_interface_t bitmap
https://git.kernel.org/netdev/net-next/c/38c310eb46f5
- [net-next,3/3] net: phylink: use supported_interfaces for phylink validation
https://git.kernel.org/netdev/net-next/c/d25f3a74f30a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-10-26 14:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-26 10:05 [PATCH net-next 0/3] Introduce supported interfaces bitmap Russell King (Oracle)
2021-10-26 10:06 ` [PATCH net-next 1/3] net: phy: add phy_interface_t bitmap support Russell King (Oracle)
2021-10-26 10:06 ` [PATCH net-next 2/3] net: phylink: add MAC phy_interface_t bitmap Russell King
2021-10-26 10:06 ` [PATCH net-next 3/3] net: phylink: use supported_interfaces for phylink validation Russell King (Oracle)
2021-10-26 14:20 ` [PATCH net-next 0/3] Introduce supported interfaces bitmap patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.