All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs
@ 2020-07-14 14:22 Marek Behún
  2020-07-14 14:22 ` [PATCH net-next v1 2/2] Documentation: ABI: document MDIO bus debugfs files Marek Behún
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Marek Behún @ 2020-07-14 14:22 UTC (permalink / raw)
  To: netdev; +Cc: Russell King, David S . Miller, Andrew Lunn, Marek Behún

This adds config option CONFIG_MDIO_BUS_DEBUGFS which, when enabled,
adds support to communicate with the devices connected to the MDIO
via debugfs.

For every MDIO bus this creates directory
  /sys/kernel/debug/mdio_bus/MDIO_BUS_NAME
with files "addr", "reg" and "val".
User can write device address to the "addr" file and register number to
the "reg" file, and then can read the value of the register from the
"val" file, or can write new value by writing to the "val" file.

This is useful when debugging various PHYs or switches.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 drivers/net/phy/Kconfig    |  8 ++++++++
 drivers/net/phy/Makefile   |  2 ++
 drivers/net/phy/mdio_bus.c | 31 ++++++++++++++++++++++++++-----
 include/linux/phy.h        |  5 +++++
 4 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index dd20c2c27c2f..aca4b52225b1 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -24,6 +24,14 @@ if MDIO_BUS
 config MDIO_DEVRES
 	tristate
 
+config MDIO_BUS_DEBUGFS
+	bool "MDIO bus debugfs support"
+	depends on DEBUG_FS
+	help
+	  This adds support to communicate via the MDIO bus via files in
+	  debugfs. Note that using this on a PHY device that is being handled by
+	  a driver can break the state of the PHY.
+
 config MDIO_ASPEED
 	tristate "ASPEED MDIO bus controller"
 	depends on ARCH_ASPEED || COMPILE_TEST
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index d84bab489a53..4500050faf64 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -5,6 +5,8 @@ libphy-y			:= phy.o phy-c45.o phy-core.o phy_device.o \
 				   linkmode.o
 mdio-bus-y			+= mdio_bus.o mdio_device.o
 
+obj-$(CONFIG_MDIO_BUS_DEBUGFS)	+= mdio_debugfs.o
+
 ifdef CONFIG_MDIO_DEVICE
 obj-y				+= mdio-boardinfo.o
 endif
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 46b33701ad4b..b31fa70dbd95 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -39,6 +39,7 @@
 #include <trace/events/mdio.h>
 
 #include "mdio-boardinfo.h"
+#include "mdio_debugfs.h"
 
 static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
 {
@@ -576,6 +577,12 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
 		}
 	}
 
+	err = mdiobus_register_debugfs(bus);
+	if (err) {
+		dev_err(&bus->dev, "mii_bus %s couldn't create debugfs entries\n", bus->id);
+		goto error;
+	}
+
 	mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device);
 
 	bus->state = MDIOBUS_REGISTERED;
@@ -609,6 +616,8 @@ void mdiobus_unregister(struct mii_bus *bus)
 	BUG_ON(bus->state != MDIOBUS_REGISTERED);
 	bus->state = MDIOBUS_UNREGISTERED;
 
+	mdiobus_unregister_debugfs(bus);
+
 	for (i = 0; i < PHY_MAX_ADDR; i++) {
 		mdiodev = bus->mdio_map[i];
 		if (!mdiodev)
@@ -1005,12 +1014,23 @@ int __init mdio_bus_init(void)
 	int ret;
 
 	ret = class_register(&mdio_bus_class);
-	if (!ret) {
-		ret = bus_register(&mdio_bus_type);
-		if (ret)
-			class_unregister(&mdio_bus_class);
-	}
+	if (ret)
+		return ret;
 
+	ret = bus_register(&mdio_bus_type);
+	if (ret)
+		goto err_class;
+
+	ret = mdiobus_debugfs_init();
+	if (ret)
+		goto err_bus;
+
+	return 0;
+
+err_bus:
+	bus_unregister(&mdio_bus_type);
+err_class:
+	class_unregister(&mdio_bus_class);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(mdio_bus_init);
@@ -1018,6 +1038,7 @@ EXPORT_SYMBOL_GPL(mdio_bus_init);
 #if IS_ENABLED(CONFIG_PHYLIB)
 void mdio_bus_exit(void)
 {
+	mdiobus_debugfs_exit();
 	class_unregister(&mdio_bus_class);
 	bus_unregister(&mdio_bus_type);
 }
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 0403eb799913..e281099fb526 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -309,6 +309,11 @@ struct mii_bus {
 
 	/* shared state across different PHYs */
 	struct phy_package_shared *shared[PHY_MAX_ADDR];
+
+#if IS_ENABLED(CONFIG_MDIO_BUS_DEBUGFS)
+	/* address and regnum for debugfs */
+	u32 debug_addr, debug_reg;
+#endif
 };
 #define to_mii_bus(d) container_of(d, struct mii_bus, dev)
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v1 2/2] Documentation: ABI: document MDIO bus debugfs files
  2020-07-14 14:22 [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs Marek Behún
@ 2020-07-14 14:22 ` Marek Behún
  2020-07-14 14:40 ` [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs Andrew Lunn
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Marek Behún @ 2020-07-14 14:22 UTC (permalink / raw)
  To: netdev; +Cc: Russell King, David S . Miller, Andrew Lunn, Marek Behún

This adds the documentation for debugfs files residing in
/sys/kernel/debug/mdio_bus. These files are created when
CONFIG_MDIO_BUS_DEBUGFS option is enabled.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 Documentation/ABI/testing/debugfs-mdio_bus | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/ABI/testing/debugfs-mdio_bus

diff --git a/Documentation/ABI/testing/debugfs-mdio_bus b/Documentation/ABI/testing/debugfs-mdio_bus
new file mode 100644
index 000000000000..4cd60869c896
--- /dev/null
+++ b/Documentation/ABI/testing/debugfs-mdio_bus
@@ -0,0 +1,29 @@
+What:		/sys/kernel/debug/mdio_bus/<MDIO_BUS>/addr
+Date:		July 2020
+KernelVersion:	5.9
+Contact:	Marek Behún <marek.behun@nic.cz>
+Description:	(RW) Address of the PHY device on the MDIO bus which should be
+		read from/written to when accessing the "val" file in this
+		directory.
+		Format: %u
+
+What:		/sys/kernel/debug/mdio_bus/<MDIO_BUS>/reg
+Date:		July 2020
+KernelVersion:	5.9
+Contact:	Marek Behún <marek.behun@nic.cz>
+Description:	(RW) Register number of the PHY device selected by the "addr"
+		file in this directory, which should be read from/written to
+		when accessing the "val" file in this directory.
+		To access Clause 45 register do a bitwise or with MII_ADDR_C45
+		(=0x40000000).
+		Format: %u
+
+What:		/sys/kernel/debug/mdio_bus/<MDIO_BUS>/val
+Date:		July 2020
+KernelVersion:	5.9
+Contact:	Marek Behún <marek.behun@nic.cz>
+Description:	(RW) Value of the register specified by the "reg" file of the
+		PHY device specified by the "addr" file in this directory.
+		Reading/writing this file calls directly function
+		mdiobus_read/mdiobus_write with arguments from these files.
+		Format: 0x%04x
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs
  2020-07-14 14:22 [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs Marek Behún
  2020-07-14 14:22 ` [PATCH net-next v1 2/2] Documentation: ABI: document MDIO bus debugfs files Marek Behún
@ 2020-07-14 14:40 ` Andrew Lunn
  2020-07-14 15:23 ` Marek Behún
  2020-07-14 16:56   ` kernel test robot
  3 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2020-07-14 14:40 UTC (permalink / raw)
  To: Marek Behún; +Cc: netdev, Russell King, David S . Miller

On Tue, Jul 14, 2020 at 04:22:12PM +0200, Marek Behún wrote:
> This adds config option CONFIG_MDIO_BUS_DEBUGFS which, when enabled,
> adds support to communicate with the devices connected to the MDIO
> via debugfs.
> 
> For every MDIO bus this creates directory
>   /sys/kernel/debug/mdio_bus/MDIO_BUS_NAME
> with files "addr", "reg" and "val".
> User can write device address to the "addr" file and register number to
> the "reg" file, and then can read the value of the register from the
> "val" file, or can write new value by writing to the "val" file.
> 
> This is useful when debugging various PHYs or switches.

Hi Marek

Please work with Tobias Waldekranz <tobias@waldekranz.com>.

I'm not particularly keen on allowing write access to such registers,
but it seems like there is demand. But we don't want two ways to do
this.

>  static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
>  {
> @@ -576,6 +577,12 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
>  		}
>  	}
>  
> +	err = mdiobus_register_debugfs(bus);
> +	if (err) {
> +		dev_err(&bus->dev, "mii_bus %s couldn't create debugfs entries\n", bus->id);
> +		goto error;
> +	}

FYI: You should never error out for debugfs. You should not even check
the return values from debugfs calls.

    Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs
  2020-07-14 14:22 [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs Marek Behún
  2020-07-14 14:22 ` [PATCH net-next v1 2/2] Documentation: ABI: document MDIO bus debugfs files Marek Behún
  2020-07-14 14:40 ` [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs Andrew Lunn
@ 2020-07-14 15:23 ` Marek Behún
  2020-07-14 16:56   ` kernel test robot
  3 siblings, 0 replies; 6+ messages in thread
From: Marek Behún @ 2020-07-14 15:23 UTC (permalink / raw)
  To: netdev; +Cc: Russell King, David S . Miller, Andrew Lunn

OMG, this won't even compile, I lost the newly added files
mdio_debugfs.c/h when rebasing!!! AAAAAARRGH

Please ignore these patches

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs
  2020-07-14 14:22 [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs Marek Behún
@ 2020-07-14 16:56   ` kernel test robot
  2020-07-14 14:40 ` [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs Andrew Lunn
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2020-07-14 16:56 UTC (permalink / raw)
  To: Marek Behún, netdev
  Cc: kbuild-all, Russell King, David S . Miller, Andrew Lunn,
	Marek Behún

[-- Attachment #1: Type: text/plain, Size: 2132 bytes --]

Hi "Marek,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Marek-Beh-n/net-mdiobus-add-support-to-access-PHY-registers-via-debugfs/20200714-222419
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 07dd1b7e68e4b83a1004b14dffd7e142c0bc79bd
config: ia64-randconfig-r003-20200714 (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=ia64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from arch/ia64/include/asm/pgtable.h:154,
                    from include/linux/pgtable.h:6,
                    from include/linux/mm.h:32,
                    from include/linux/bvec.h:13,
                    from include/linux/skbuff.h:17,
                    from include/linux/if_ether.h:19,
                    from include/linux/etherdevice.h:20,
                    from drivers/net/phy/mdio_bus.c:14:
   arch/ia64/include/asm/mmu_context.h: In function 'reload_context':
   arch/ia64/include/asm/mmu_context.h:137:41: warning: variable 'old_rr4' set but not used [-Wunused-but-set-variable]
     137 |  unsigned long rr0, rr1, rr2, rr3, rr4, old_rr4;
         |                                         ^~~~~~~
   drivers/net/phy/mdio_bus.c: At top level:
>> drivers/net/phy/mdio_bus.c:42:10: fatal error: mdio_debugfs.h: No such file or directory
      42 | #include "mdio_debugfs.h"
         |          ^~~~~~~~~~~~~~~~
   compilation terminated.

vim +42 drivers/net/phy/mdio_bus.c

    40	
    41	#include "mdio-boardinfo.h"
  > 42	#include "mdio_debugfs.h"
    43	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 29521 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs
@ 2020-07-14 16:56   ` kernel test robot
  0 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2020-07-14 16:56 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2183 bytes --]

Hi "Marek,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Marek-Beh-n/net-mdiobus-add-support-to-access-PHY-registers-via-debugfs/20200714-222419
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 07dd1b7e68e4b83a1004b14dffd7e142c0bc79bd
config: ia64-randconfig-r003-20200714 (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=ia64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from arch/ia64/include/asm/pgtable.h:154,
                    from include/linux/pgtable.h:6,
                    from include/linux/mm.h:32,
                    from include/linux/bvec.h:13,
                    from include/linux/skbuff.h:17,
                    from include/linux/if_ether.h:19,
                    from include/linux/etherdevice.h:20,
                    from drivers/net/phy/mdio_bus.c:14:
   arch/ia64/include/asm/mmu_context.h: In function 'reload_context':
   arch/ia64/include/asm/mmu_context.h:137:41: warning: variable 'old_rr4' set but not used [-Wunused-but-set-variable]
     137 |  unsigned long rr0, rr1, rr2, rr3, rr4, old_rr4;
         |                                         ^~~~~~~
   drivers/net/phy/mdio_bus.c: At top level:
>> drivers/net/phy/mdio_bus.c:42:10: fatal error: mdio_debugfs.h: No such file or directory
      42 | #include "mdio_debugfs.h"
         |          ^~~~~~~~~~~~~~~~
   compilation terminated.

vim +42 drivers/net/phy/mdio_bus.c

    40	
    41	#include "mdio-boardinfo.h"
  > 42	#include "mdio_debugfs.h"
    43	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 29521 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-14 17:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-14 14:22 [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs Marek Behún
2020-07-14 14:22 ` [PATCH net-next v1 2/2] Documentation: ABI: document MDIO bus debugfs files Marek Behún
2020-07-14 14:40 ` [PATCH net-next v1 1/2] net: mdiobus: add support to access PHY registers via debugfs Andrew Lunn
2020-07-14 15:23 ` Marek Behún
2020-07-14 16:56 ` kernel test robot
2020-07-14 16:56   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.