From: "Marek Behún" <kabel@kernel.org>
To: netdev@vger.kernel.org
Cc: linux-leds@vger.kernel.org, "Pavel Machek" <pavel@ucw.cz>,
"Dan Murphy" <dmurphy@ti.com>,
"Russell King" <linux@armlinux.org.uk>,
"Andrew Lunn" <andrew@lunn.ch>,
"Matthias Schiffer" <matthias.schiffer@ew.tq-group.com>,
"David S. Miller" <davem@davemloft.net>,
"Jacek Anaszewski" <jacek.anaszewski@gmail.com>,
"Ben Whitten" <ben.whitten@gmail.com>,
"Marek Behún" <kabel@kernel.org>
Subject: [PATCH RFC leds + net-next 5/7] net: phy: add simple incrementing phyindex member to phy_device struct
Date: Fri, 30 Oct 2020 12:44:33 +0100 [thread overview]
Message-ID: <20201030114435.20169-6-kabel@kernel.org> (raw)
In-Reply-To: <20201030114435.20169-1-kabel@kernel.org>
Add a new integer member phyindex to struct phy_device. This member is
unique for every phy_device. Atomic incrementation occurs in
phy_device_register.
This can be used for example in LED sysfs API. The LED subsystem names
each LED in format `device:color:function`, but currently the PHY device
names are not suited for this, since in some situations a PHY device
name can look like this
d0032004.mdio-mii:01
or even like this
!soc!internal-regs@d0000000!mdio@32004!switch0@10!mdio:08
Clearly this cannot be used as the `device` part of a LED name.
Signed-off-by: Marek Behún <kabel@kernel.org>
---
drivers/net/phy/phy_device.c | 3 +++
include/linux/phy.h | 3 +++
2 files changed, 6 insertions(+)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 5dab6be6fc38..38f581cc9713 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -9,6 +9,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/atomic.h>
#include <linux/bitmap.h>
#include <linux/delay.h>
#include <linux/errno.h>
@@ -892,6 +893,7 @@ EXPORT_SYMBOL(get_phy_device);
*/
int phy_device_register(struct phy_device *phydev)
{
+ static atomic_t phyindex;
int err;
err = mdiobus_register_device(&phydev->mdio);
@@ -908,6 +910,7 @@ int phy_device_register(struct phy_device *phydev)
goto out;
}
+ phydev->phyindex = atomic_inc_return(&phyindex) - 1;
err = device_add(&phydev->mdio.dev);
if (err) {
phydev_err(phydev, "failed to add\n");
diff --git a/include/linux/phy.h b/include/linux/phy.h
index eb3cb1a98b45..6dd4a28135c3 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -480,6 +480,7 @@ struct macsec_ops;
*
* @mdio: MDIO bus this PHY is on
* @drv: Pointer to the driver for this PHY instance
+ * @phyindex: a simple incrementing PHY index
* @phy_id: UID for this device found during discovery
* @c45_ids: 802.3-c45 Device Identifiers if is_c45.
* @is_c45: Set to true if this PHY uses clause 45 addressing.
@@ -551,6 +552,8 @@ struct phy_device {
/* And management functions */
struct phy_driver *drv;
+ int phyindex;
+
u32 phy_id;
struct phy_c45_device_ids c45_ids;
--
2.26.2
next prev parent reply other threads:[~2020-10-30 11:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-30 11:44 [PATCH RFC leds + net-next 0/7] netdev trigger offloading and LEDs on Marvell PHYs Marek Behún
2020-10-30 11:44 ` [PATCH RFC leds + net-next 1/7] leds: trigger: netdev: don't explicitly zero kzalloced data Marek Behún
2020-11-25 12:34 ` Pavel Machek
2020-10-30 11:44 ` [PATCH RFC leds + net-next 2/7] leds: trigger: netdev: simplify the driver by using bit field members Marek Behún
2020-10-30 22:37 ` Jacek Anaszewski
2020-10-30 23:45 ` Marek Behún
2020-11-01 16:40 ` Jacek Anaszewski
2021-03-01 10:30 ` Pavel Machek
2020-10-30 11:44 ` [PATCH RFC leds + net-next 3/7] leds: trigger: add API for HW offloading of triggers Marek Behún
2021-03-01 10:38 ` Pavel Machek
2020-10-30 11:44 ` [PATCH RFC leds + net-next 4/7] leds: trigger: netdev: support HW offloading Marek Behún
2020-11-05 14:44 ` Marek Behún
2021-03-01 10:44 ` Pavel Machek
2020-10-30 11:44 ` Marek Behún [this message]
2021-03-01 10:46 ` [PATCH RFC leds + net-next 5/7] net: phy: add simple incrementing phyindex member to phy_device struct Pavel Machek
2020-10-30 11:44 ` [PATCH RFC leds + net-next 6/7] net: phy: add support for LEDs connected to ethernet PHYs Marek Behún
2021-03-01 10:52 ` Pavel Machek
2020-10-30 11:44 ` [PATCH RFC leds + net-next 7/7] net: phy: marvell: support LEDs connected on Marvell PHYs Marek Behún
2020-11-25 12:38 ` Pavel Machek
2021-03-01 11:05 ` Pavel Machek
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=20201030114435.20169-6-kabel@kernel.org \
--to=kabel@kernel.org \
--cc=andrew@lunn.ch \
--cc=ben.whitten@gmail.com \
--cc=davem@davemloft.net \
--cc=dmurphy@ti.com \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-leds@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=matthias.schiffer@ew.tq-group.com \
--cc=netdev@vger.kernel.org \
--cc=pavel@ucw.cz \
/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).