From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>, Heiner Kallweit <hkallweit1@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Daniel Scally <djrscally@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Jakub Kicinski <kuba@kernel.org>,
linux-acpi@vger.kernel.org, netdev@vger.kernel.org,
Paolo Abeni <pabeni@redhat.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Vladimir Oltean <olteanv@gmail.com>
Subject: [PATCH RFC net-next 6/7] net: dsa: mv88e6xxx: provide software node for default settings
Date: Wed, 22 Mar 2023 12:00:21 +0000 [thread overview]
Message-ID: <E1pex8f-00Dvo9-KT@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <ZBrtqPW29NnxVoEc@shell.armlinux.org.uk>
Provide a software node for default settings when no phy, sfp or
fixed link is specified.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/dsa/mv88e6xxx/chip.c | 109 +++++++++++++++++++++++++++++++
1 file changed, 109 insertions(+)
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index b73d1d6747b7..dde0c306fb3a 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -26,6 +26,7 @@
#include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/of_mdio.h>
+#include <linux/of_net.h>
#include <linux/platform_data/mv88e6xxx.h>
#include <linux/netdevice.h>
#include <linux/gpio/consumer.h>
@@ -841,6 +842,113 @@ static void mv88e6xxx_get_caps(struct dsa_switch *ds, int port,
}
}
+static struct fwnode_handle *mv88e6xxx_create_fixed_swnode(struct fwnode_handle *parent,
+ int speed,
+ int duplex)
+{
+ struct property_entry fixed_link_props[3] = { };
+
+ fixed_link_props[0] = PROPERTY_ENTRY_U32("speed", speed);
+ if (duplex == DUPLEX_FULL)
+ fixed_link_props[1] = PROPERTY_ENTRY_BOOL("full-duplex");
+
+ return fwnode_create_named_software_node(fixed_link_props, parent,
+ "fixed-link");
+}
+
+static struct fwnode_handle *mv88e6xxx_create_port_swnode(phy_interface_t mode,
+ int speed,
+ int duplex)
+{
+ struct property_entry port_props[2] = {};
+ struct fwnode_handle *fixed_link_fwnode;
+ struct fwnode_handle *new_port_fwnode;
+
+ port_props[0] = PROPERTY_ENTRY_STRING("phy-mode", phy_modes(mode));
+ new_port_fwnode = fwnode_create_software_node(port_props, NULL);
+ if (IS_ERR(new_port_fwnode))
+ return new_port_fwnode;
+
+ fixed_link_fwnode = mv88e6xxx_create_fixed_swnode(new_port_fwnode,
+ speed, duplex);
+ if (IS_ERR(fixed_link_fwnode)) {
+ fwnode_remove_software_node(new_port_fwnode);
+ return fixed_link_fwnode;
+ }
+
+ return new_port_fwnode;
+}
+
+static unsigned long mv88e6xxx_get_max_caps(struct phylink_config *config,
+ phy_interface_t *mode)
+{
+ unsigned long max_caps, caps, mac_caps;
+ phy_interface_t interface;
+
+ mac_caps = config->mac_capabilities;
+ if (*mode != PHY_INTERFACE_MODE_NA)
+ return phylink_get_capabilities(*mode, mac_caps,
+ RATE_MATCH_NONE);
+
+ max_caps = 0;
+ for_each_set_bit(interface, config->supported_interfaces,
+ PHY_INTERFACE_MODE_MAX) {
+ caps = phylink_get_capabilities(interface, mac_caps,
+ RATE_MATCH_NONE);
+ if (caps > max_caps) {
+ max_caps = caps;
+ *mode = interface;
+ }
+ }
+
+ return max_caps;
+}
+
+static struct fwnode_handle *mv88e6xxx_port_get_fwnode(struct dsa_switch *ds,
+ int port,
+ struct fwnode_handle *h)
+{
+ struct mv88e6xxx_chip *chip = ds->priv;
+ struct device_node *np, *phy_node;
+ int speed, duplex, err;
+ phy_interface_t mode;
+ struct dsa_port *dp;
+ unsigned long caps;
+
+ dp = dsa_to_port(ds, port);
+ if (dsa_port_is_user(dp))
+ return h;
+
+ /* No DT? Eh? */
+ np = to_of_node(h);
+ if (!np)
+ return h;
+
+ /* If a PHY, fixed-link specification, or in-band mode, then we
+ * don't need to do any fixup. Simply return the provided fwnode.
+ */
+ phy_node = of_parse_phandle(np, "phy-handle", 0);
+ of_node_put(phy_node);
+ if (phy_node || of_phy_is_fixed_link(np))
+ return h;
+
+ /* Get the DT specified phy-mode. If missing, try the chip's max speed
+ * mode method if implemented, otherwise try the supported_interfaces
+ * mask for the interface mode that gives the fastest speeds.
+ */
+ err = of_get_phy_mode(np, &mode);
+ if (err && chip->info->ops->port_max_speed_mode)
+ mode = chip->info->ops->port_max_speed_mode(port);
+
+ caps = mv88e6xxx_get_max_caps(&dp->pl_config, &mode);
+
+ err = phylink_find_max_speed(caps, &speed, &duplex);
+ if (err)
+ return ERR_PTR(err);
+
+ return mv88e6xxx_create_port_swnode(mode, speed, duplex);
+}
+
static void mv88e6xxx_mac_config(struct dsa_switch *ds, int port,
unsigned int mode,
const struct phylink_link_state *state)
@@ -6994,6 +7102,7 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
.teardown = mv88e6xxx_teardown,
.port_setup = mv88e6xxx_port_setup,
.port_teardown = mv88e6xxx_port_teardown,
+ .port_get_fwnode = mv88e6xxx_port_get_fwnode,
.phylink_get_caps = mv88e6xxx_get_caps,
.phylink_mac_link_state = mv88e6xxx_serdes_pcs_get_state,
.phylink_mac_config = mv88e6xxx_mac_config,
--
2.30.2
next prev parent reply other threads:[~2023-03-22 12:00 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-22 11:59 [PATCH RFC net-next 0/7] Another attempt at moving mv88e6xxx forward Russell King (Oracle)
2023-03-22 11:59 ` [PATCH RFC net-next 1/7] software node: allow named software node to be created Russell King
2023-03-23 13:59 ` Andy Shevchenko
2023-03-23 14:29 ` Russell King (Oracle)
2023-03-23 14:39 ` Andy Shevchenko
2023-03-22 12:00 ` [PATCH RFC net-next 2/7] net: phylink: provide phylink_find_max_speed() Russell King (Oracle)
2023-03-22 18:44 ` Andrew Lunn
2023-03-22 12:00 ` [PATCH RFC net-next 3/7] net: dsa: use fwnode_get_phy_mode() to get phy interface mode Russell King (Oracle)
2023-03-22 18:42 ` Andrew Lunn
2023-03-23 14:03 ` Andy Shevchenko
2023-03-23 14:31 ` Russell King (Oracle)
2023-03-23 14:38 ` Andy Shevchenko
2023-03-23 14:49 ` Russell King (Oracle)
2023-03-23 15:00 ` Andy Shevchenko
2023-03-23 15:23 ` Russell King (Oracle)
2023-03-23 15:33 ` Andy Shevchenko
2023-03-23 16:29 ` Russell King (Oracle)
2023-03-23 16:18 ` Russell King (Oracle)
2023-03-23 16:34 ` Andy Shevchenko
2023-03-23 16:39 ` Andy Shevchenko
2023-03-23 17:06 ` Russell King (Oracle)
2023-03-23 17:28 ` Andy Shevchenko
2023-03-23 17:53 ` Russell King (Oracle)
2023-03-23 18:04 ` Andy Shevchenko
2023-03-23 20:46 ` Russell King (Oracle)
2023-03-22 12:00 ` [PATCH RFC net-next 4/7] net: dsa: add ability for switch driver to provide a swnode Russell King (Oracle)
2023-03-22 12:00 ` [PATCH RFC net-next 5/7] net: dsa: avoid DT validation for drivers which provide default config Russell King (Oracle)
2023-03-22 18:51 ` Andrew Lunn
2023-03-22 20:09 ` Russell King (Oracle)
2023-03-22 20:14 ` Andrew Lunn
2023-03-22 20:20 ` Russell King (Oracle)
2023-03-22 12:00 ` Russell King (Oracle) [this message]
2023-03-22 18:57 ` [PATCH RFC net-next 6/7] net: dsa: mv88e6xxx: provide software node for default settings Andrew Lunn
2023-03-22 20:13 ` Russell King (Oracle)
2023-03-22 20:17 ` Andrew Lunn
2023-03-22 20:22 ` Russell King (Oracle)
2023-03-22 21:40 ` Andrew Lunn
2023-03-23 8:41 ` Russell King (Oracle)
2023-03-23 18:17 ` Andrew Lunn
2023-03-23 18:25 ` Russell King (Oracle)
2023-03-23 18:34 ` Andrew Lunn
2023-03-24 14:49 ` Heikki Krogerus
2023-03-24 17:04 ` Russell King (Oracle)
2023-03-27 10:28 ` Heikki Krogerus
2023-03-27 10:55 ` Russell King (Oracle)
2023-03-27 14:13 ` Heikki Krogerus
2023-03-27 14:32 ` Russell King (Oracle)
2023-03-27 15:45 ` Russell King (Oracle)
2023-03-28 12:09 ` Heikki Krogerus
2023-03-28 13:23 ` Russell King (Oracle)
2023-03-29 14:07 ` Heikki Krogerus
2023-03-29 14:33 ` Russell King (Oracle)
2023-03-30 13:54 ` Heikki Krogerus
2023-04-03 13:02 ` Russell King (Oracle)
2023-04-05 17:51 ` Greg Kroah-Hartman
2023-03-22 12:00 ` [PATCH RFC net-next 7/7] net: dsa: mv88e6xxx: remove handling for DSA and CPU ports Russell King (Oracle)
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=E1pex8f-00Dvo9-KT@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux.org.uk \
--cc=andrew@lunn.ch \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=djrscally@gmail.com \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=rafael@kernel.org \
--cc=sakari.ailus@linux.intel.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).