From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, andrew@lunn.ch,
Florian Fainelli <f.fainelli@gmail.com>
Subject: [PATCH net-next 1/3] net: phy: Create sysfs reciprocal links for attached_dev/phydev
Date: Wed, 24 May 2017 12:33:52 -0700 [thread overview]
Message-ID: <20170524193354.10739-2-f.fainelli@gmail.com> (raw)
In-Reply-To: <20170524193354.10739-1-f.fainelli@gmail.com>
There is currently no way for a program scanning /sys to know whether a
network device is attached to a particular PHY device, just like the PHY
device is not pointed back to its attached network device.
Create a symbolic link in the network device's namespace named "phydev"
which points to the PHY device and create a symbolic link in the PHY
device's namespace named "attached_dev" that points back to the network
device. These links are set up during phy_attach_direct() and removed
during phy_detach() for symetry.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/phy/phy_device.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 1219eeab69d1..8151477c7027 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -960,6 +960,15 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
phydev->attached_dev = dev;
dev->phydev = phydev;
+ err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj,
+ "attached_dev");
+ if (err)
+ goto error;
+
+ err = sysfs_create_link(&dev->dev.kobj, &phydev->mdio.dev.kobj,
+ "phydev");
+ if (err)
+ goto error;
phydev->dev_flags = flags;
@@ -1050,6 +1059,8 @@ void phy_detach(struct phy_device *phydev)
struct mii_bus *bus;
int i;
+ sysfs_remove_link(&dev->dev.kobj, "phydev");
+ sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev");
phydev->attached_dev->phydev = NULL;
phydev->attached_dev = NULL;
phy_suspend(phydev);
--
2.9.3
next prev parent reply other threads:[~2017-05-24 19:34 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-24 19:33 [PATCH net-next 0/3] net: phy: Create sysfs reciprocal links for attached_dev/phydev Florian Fainelli
2017-05-24 19:33 ` Florian Fainelli [this message]
2017-05-26 23:34 ` [PATCH net-next 1/3] " Woojung.Huh
2017-05-26 23:44 ` Florian Fainelli
2017-05-26 23:52 ` Woojung.Huh
2017-05-27 0:02 ` Florian Fainelli
2017-05-27 0:20 ` Woojung.Huh
2017-05-27 0:33 ` Florian Fainelli
2017-05-27 0:43 ` Woojung.Huh
2017-05-27 0:46 ` Florian Fainelli
2017-05-27 1:00 ` Woojung.Huh
2017-05-27 1:26 ` Florian Fainelli
2017-05-27 1:31 ` Woojung.Huh
2017-05-27 3:22 ` Florian Fainelli
2017-05-24 19:33 ` [PATCH net-next 2/3] net: sysfs: Document "phydev" symbolic link Florian Fainelli
2017-05-24 19:33 ` [PATCH net-next 3/3] net: sysfs: Document PHY device sysfs attributes Florian Fainelli
2017-05-24 20:10 ` Andrew Lunn
2017-05-24 23:07 ` Florian Fainelli
2017-05-25 0:03 ` Florian Fainelli
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=20170524193354.10739-2-f.fainelli@gmail.com \
--to=f.fainelli@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--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).