From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>, Heiner Kallweit <hkallweit1@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: Re: [PATCH RESEND] net: sfp: add debugfs support
Date: Sun, 10 Jan 2021 10:59:06 +0000 [thread overview]
Message-ID: <20210110105906.GF1551@shell.armlinux.org.uk> (raw)
In-Reply-To: <E1kyYPT-0004fo-W5@rmk-PC.armlinux.org.uk>
Hi,
This should've had net-next in the subject line! I'll re-send.
On Sun, Jan 10, 2021 at 10:57:23AM +0000, Russell King wrote:
> Add debugfs support to SFP so that the internal state of the SFP state
> machines and hardware signal state can be viewed from userspace, rather
> than having to compile a debug kernel to view state state transitions
> in the kernel log. The 'state' output looks like:
>
> Module state: empty
> Module probe attempts: 0 0
> Device state: up
> Main state: down
> Fault recovery remaining retries: 5
> PHY probe remaining retries: 12
> moddef0: 0
> rx_los: 1
> tx_fault: 1
> tx_disable: 1
>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
> ---
> drivers/net/phy/sfp.c | 55 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 55 insertions(+)
>
> diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
> index 91d74c1a920a..374351de2063 100644
> --- a/drivers/net/phy/sfp.c
> +++ b/drivers/net/phy/sfp.c
> @@ -1,6 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0
> #include <linux/acpi.h>
> #include <linux/ctype.h>
> +#include <linux/debugfs.h>
> #include <linux/delay.h>
> #include <linux/gpio/consumer.h>
> #include <linux/hwmon.h>
> @@ -258,6 +259,9 @@ struct sfp {
> char *hwmon_name;
> #endif
>
> +#if IS_ENABLED(CONFIG_DEBUG_FS)
> + struct dentry *debugfs_dir;
> +#endif
> };
>
> static bool sff_module_supported(const struct sfp_eeprom_id *id)
> @@ -1390,6 +1394,54 @@ static void sfp_module_tx_enable(struct sfp *sfp)
> sfp_set_state(sfp, sfp->state);
> }
>
> +#if IS_ENABLED(CONFIG_DEBUG_FS)
> +static int sfp_debug_state_show(struct seq_file *s, void *data)
> +{
> + struct sfp *sfp = s->private;
> +
> + seq_printf(s, "Module state: %s\n",
> + mod_state_to_str(sfp->sm_mod_state));
> + seq_printf(s, "Module probe attempts: %d %d\n",
> + R_PROBE_RETRY_INIT - sfp->sm_mod_tries_init,
> + R_PROBE_RETRY_SLOW - sfp->sm_mod_tries);
> + seq_printf(s, "Device state: %s\n",
> + dev_state_to_str(sfp->sm_dev_state));
> + seq_printf(s, "Main state: %s\n",
> + sm_state_to_str(sfp->sm_state));
> + seq_printf(s, "Fault recovery remaining retries: %d\n",
> + sfp->sm_fault_retries);
> + seq_printf(s, "PHY probe remaining retries: %d\n",
> + sfp->sm_phy_retries);
> + seq_printf(s, "moddef0: %d\n", !!(sfp->state & SFP_F_PRESENT));
> + seq_printf(s, "rx_los: %d\n", !!(sfp->state & SFP_F_LOS));
> + seq_printf(s, "tx_fault: %d\n", !!(sfp->state & SFP_F_TX_FAULT));
> + seq_printf(s, "tx_disable: %d\n", !!(sfp->state & SFP_F_TX_DISABLE));
> + return 0;
> +}
> +DEFINE_SHOW_ATTRIBUTE(sfp_debug_state);
> +
> +static void sfp_debugfs_init(struct sfp *sfp)
> +{
> + sfp->debugfs_dir = debugfs_create_dir(dev_name(sfp->dev), NULL);
> +
> + debugfs_create_file("state", 0600, sfp->debugfs_dir, sfp,
> + &sfp_debug_state_fops);
> +}
> +
> +static void sfp_debugfs_exit(struct sfp *sfp)
> +{
> + debugfs_remove_recursive(sfp->debugfs_dir);
> +}
> +#else
> +static void sfp_debugfs_init(struct sfp *sfp)
> +{
> +}
> +
> +static void sfp_debugfs_exit(struct sfp *sfp)
> +{
> +}
> +#endif
> +
> static void sfp_module_tx_fault_reset(struct sfp *sfp)
> {
> unsigned int state = sfp->state;
> @@ -2483,6 +2535,8 @@ static int sfp_probe(struct platform_device *pdev)
> if (!sfp->sfp_bus)
> return -ENOMEM;
>
> + sfp_debugfs_init(sfp);
> +
> return 0;
> }
>
> @@ -2490,6 +2544,7 @@ static int sfp_remove(struct platform_device *pdev)
> {
> struct sfp *sfp = platform_get_drvdata(pdev);
>
> + sfp_debugfs_exit(sfp);
> sfp_unregister_socket(sfp->sfp_bus);
>
> rtnl_lock();
> --
> 2.20.1
>
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
prev parent reply other threads:[~2021-01-10 11:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-10 10:57 [PATCH RESEND] net: sfp: add debugfs support Russell King
2021-01-10 10:59 ` Russell King - ARM Linux admin [this message]
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=20210110105906.GF1551@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=hkallweit1@gmail.com \
--cc=kuba@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).