From: Moritz Fischer <mdf@kernel.org>
To: davem@davemloft.net
Cc: keescook@chromium.org, f.fainelli@gmail.com,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
alex.williams@ni.com, Moritz Fischer <mdf@kernel.org>
Subject: [PATCH net-next 1/3] net: nixge: Add support for fixed-link subnodes
Date: Wed, 29 Aug 2018 17:40:44 -0700 [thread overview]
Message-ID: <20180830004046.9417-2-mdf@kernel.org> (raw)
In-Reply-To: <20180830004046.9417-1-mdf@kernel.org>
Add support for fixed-link cases where no MDIO is
actually required to run the device.
In that case no MDIO bus is instantiated since the
actual registers are not available in hardware.
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
drivers/net/ethernet/ni/nixge.c | 72 ++++++++++++++++++++++++---------
1 file changed, 53 insertions(+), 19 deletions(-)
diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c
index 74cf52e3fb09..670249313ff0 100644
--- a/drivers/net/ethernet/ni/nixge.c
+++ b/drivers/net/ethernet/ni/nixge.c
@@ -1189,9 +1189,36 @@ static int nixge_mdio_write(struct mii_bus *bus, int phy_id, int reg, u16 val)
return err;
}
+static int nixge_of_get_phy(struct nixge_priv *priv, struct device_node *np)
+{
+ priv->phy_mode = of_get_phy_mode(np);
+ if (priv->phy_mode < 0) {
+ dev_err(priv->dev, "not find \"phy-mode\" property\n");
+ return -EINVAL;
+ }
+
+ if (of_phy_is_fixed_link(np)) {
+ if (of_phy_register_fixed_link(np) < 0) {
+ dev_err(priv->dev, "broken fixed link spec\n");
+ return -EINVAL;
+ }
+
+ priv->phy_node = of_node_get(np);
+ } else {
+ priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
+ if (!priv->phy_node) {
+ dev_err(priv->dev, "not find \"phy-handle\" property\n");
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
static int nixge_mdio_setup(struct nixge_priv *priv, struct device_node *np)
{
struct mii_bus *bus;
+ int err;
bus = devm_mdiobus_alloc(priv->dev);
if (!bus)
@@ -1230,6 +1257,7 @@ static int nixge_probe(struct platform_device *pdev)
struct nixge_priv *priv;
struct net_device *ndev;
struct resource *dmares;
+ struct device_node *np;
const u8 *mac_addr;
int err;
@@ -1237,6 +1265,8 @@ static int nixge_probe(struct platform_device *pdev)
if (!ndev)
return -ENOMEM;
+ np = pdev->dev.of_node;
+
platform_set_drvdata(pdev, ndev);
SET_NETDEV_DEV(ndev, &pdev->dev);
@@ -1286,24 +1316,19 @@ static int nixge_probe(struct platform_device *pdev)
priv->coalesce_count_rx = XAXIDMA_DFT_RX_THRESHOLD;
priv->coalesce_count_tx = XAXIDMA_DFT_TX_THRESHOLD;
- err = nixge_mdio_setup(priv, pdev->dev.of_node);
- if (err) {
- netdev_err(ndev, "error registering mdio bus");
- goto free_netdev;
- }
-
- priv->phy_mode = of_get_phy_mode(pdev->dev.of_node);
- if (priv->phy_mode < 0) {
- netdev_err(ndev, "not find \"phy-mode\" property\n");
- err = -EINVAL;
- goto unregister_mdio;
+ if (np) {
+ err = nixge_of_get_phy(priv, np);
+ if (err)
+ goto free_netdev;
}
- priv->phy_node = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
- if (!priv->phy_node) {
- netdev_err(ndev, "not find \"phy-handle\" property\n");
- err = -EINVAL;
- goto unregister_mdio;
+ /* only if it's not a fixed link, do we care about MDIO at all */
+ if (priv->phy_node && !of_phy_is_fixed_link(np)) {
+ err = nixge_mdio_setup(priv, np);
+ if (err) {
+ dev_err(&pdev->dev, "error registering mdio bus");
+ goto free_phy;
+ }
}
err = register_netdev(priv->ndev);
@@ -1315,8 +1340,13 @@ static int nixge_probe(struct platform_device *pdev)
return 0;
unregister_mdio:
- mdiobus_unregister(priv->mii_bus);
-
+ if (priv->mii_bus)
+ mdiobus_unregister(priv->mii_bus);
+free_phy:
+ if (np && of_phy_is_fixed_link(np)) {
+ of_phy_deregister_fixed_link(np);
+ of_node_put(np);
+ }
free_netdev:
free_netdev(ndev);
@@ -1330,7 +1360,11 @@ static int nixge_remove(struct platform_device *pdev)
unregister_netdev(ndev);
- mdiobus_unregister(priv->mii_bus);
+ if (priv->mii_bus)
+ mdiobus_unregister(priv->mii_bus);
+
+ if (np && of_phy_is_fixed_link(np))
+ of_phy_deregister_fixed_link(np);
free_netdev(ndev);
--
2.18.0
next prev parent reply other threads:[~2018-08-30 0:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-30 0:40 [PATCH net-next 0/3] nixge: fixed-link support Moritz Fischer
2018-08-30 0:40 ` Moritz Fischer [this message]
2018-08-30 3:04 ` [PATCH net-next 1/3] net: nixge: Add support for fixed-link subnodes Andrew Lunn
2018-08-30 17:21 ` Moritz Fischer
2018-08-30 17:54 ` Andrew Lunn
2018-08-30 21:09 ` Moritz Fischer
2018-08-30 17:44 ` kbuild test robot
2018-08-30 0:40 ` [PATCH net-next 2/3] net: nixge: Add support for having nixge as subdevice Moritz Fischer
2018-08-30 1:07 ` Moritz Fischer
2018-08-30 3:11 ` Andrew Lunn
2018-08-30 16:39 ` Moritz Fischer
2018-08-30 17:42 ` Andrew Lunn
2018-08-30 0:40 ` [PATCH net-next 3/3] net: nixge: Use sysdev instead of ndev->dev.parent for DMA Moritz Fischer
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=20180830004046.9417-2-mdf@kernel.org \
--to=mdf@kernel.org \
--cc=alex.williams@ni.com \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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).