From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC711C433E6 for ; Sun, 10 Jan 2021 11:00:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B09322054F for ; Sun, 10 Jan 2021 11:00:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726511AbhAJLAE (ORCPT ); Sun, 10 Jan 2021 06:00:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726490AbhAJLAD (ORCPT ); Sun, 10 Jan 2021 06:00:03 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83BA3C0617A3 for ; Sun, 10 Jan 2021 02:59:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=byUmT7RpX9et6XWUN5HRGOng9DCQCSrMo2ayMfx02Yg=; b=1uBsrBRuvwHPHN6WJWv51Sf/k HzKVN+zFTQ9RwuGbm8SSX2IkP3W97IwCfFFq/5K5jX07w6cK3cIsJXc8LFPd+z8INwd59ESFbTWme X6AeanrkTnzanIxU1t4GUI5ph7ZZMpbYhYu9EdpzX/Drh2b7T20nddBawxmo1x0DNswh5fTyqhuSu /ACeNXHBz7Z3RqLpq43XUgEcjqyYq4bZMy3Q9IzhAY3N72rXlTbHm5T+gqKp3IuUTgPNgXaNetxXI Jm7eZcQOJBnUAts+bP7LtI+2Z00O3qZ5xYEfFFFomkN8ig9vUqaxmTuwDAzpxKClaA4+jU7BhZn3G eoWjpPcuw==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:46118) by pandora.armlinux.org.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kyYR8-0005mX-T5; Sun, 10 Jan 2021 10:59:07 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1kyYR8-00048u-Ey; Sun, 10 Jan 2021 10:59:06 +0000 Date: Sun, 10 Jan 2021 10:59:06 +0000 From: Russell King - ARM Linux admin To: Andrew Lunn , Heiner Kallweit Cc: "David S. Miller" , netdev@vger.kernel.org, Jakub Kicinski Subject: Re: [PATCH RESEND] net: sfp: add debugfs support Message-ID: <20210110105906.GF1551@shell.armlinux.org.uk> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: Russell King - ARM Linux admin Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 > Signed-off-by: Russell King > --- > 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 > #include > +#include > #include > #include > #include > @@ -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!