[net-next,v8] net: stmmac: optimize check in ops '.begin'

Subsystems: networking drivers, stmmac ethernet driver, the rest

4 messages, 3 authors, 2021-08-03 · open the first message on its own page

[net-next,v8] net: stmmac: optimize check in ops '.begin'

From: Hao Chen <hidden>
Date: 2021-08-03 02:39:46

I want to get permanent MAC address when the interface is down. And I think
it is more convenient to get statistics in the down state by 'ethtool -S'.
But current all of the ethool command return -EBUSY.

I don't think we should check that the network interface is up in '.begin',
which will cause that all the ethtool commands can't be used when the
network interface is down. If some ethtool commands can only be used in the
up state, check it in the corresponding ethool OPS function is better.
This is too rude and unreasonable.

Compile-tested on arm64. Tested on an arm64 system with an on-board
STMMAC chip.

Changes v7 ... v8:
- Optimize commit description information, optimization parameters of
  pm_runtime function.

Changes v6 ... v7:
- fix arg type error of 'dev' to 'priv->device'.

Changes v5 ... v6:
- The 4.19.90 kernel not support pm_runtime, so implemente '.begin' and
  '.complete' again. Add return value check of pm_runtime function.

Changes v4 ... v5:
- test the '.begin' will return -13 error on my machine based on 4.19.90
  kernel. The platform driver does not supported pm_runtime. So remove the
  implementation of '.begin' and '.complete'.

Changes v3 ... v4:
- implement '.complete' ethtool OPS.

Changes v2 ... v3:
- add linux/pm_runtime.h head file.

Changes v1 ... v2:
- fix spell error of dev.

Signed-off-by: Hao Chen <redacted>
---
 .../ethernet/stmicro/stmmac/stmmac_ethtool.c    | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index d0ce608b81c3..8e2ae0ff7f8f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -12,8 +12,9 @@
 #include <linux/ethtool.h>
 #include <linux/interrupt.h>
 #include <linux/mii.h>
-#include <linux/phylink.h>
 #include <linux/net_tstamp.h>
+#include <linux/phylink.h>
+#include <linux/pm_runtime.h>
 #include <asm/io.h>
 
 #include "stmmac.h"
@@ -410,11 +411,14 @@ static void stmmac_ethtool_setmsglevel(struct net_device *dev, u32 level)
 
 }
 
-static int stmmac_check_if_running(struct net_device *dev)
+static int stmmac_ethtool_begin(struct net_device *dev)
 {
-	if (!netif_running(dev))
-		return -EBUSY;
-	return 0;
+	return pm_runtime_resume_and_get(dev->dev);
+}
+
+static void stmmac_ethtool_complete(struct net_device *dev)
+{
+	pm_runtime_put(dev->dev);
 }
 
 static int stmmac_ethtool_get_regs_len(struct net_device *dev)
@@ -1073,7 +1077,8 @@ static int stmmac_set_tunable(struct net_device *dev,
 static const struct ethtool_ops stmmac_ethtool_ops = {
 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
 				     ETHTOOL_COALESCE_MAX_FRAMES,
-	.begin = stmmac_check_if_running,
+	.begin = stmmac_ethtool_begin,
+	.complete = stmmac_ethtool_complete,
 	.get_drvinfo = stmmac_ethtool_getdrvinfo,
 	.get_msglevel = stmmac_ethtool_getmsglevel,
 	.set_msglevel = stmmac_ethtool_setmsglevel,
-- 
2.20.1


Re: [net-next,v8] net: stmmac: optimize check in ops '.begin'

From: Heiner Kallweit <hkallweit1@gmail.com>
Date: 2021-08-03 06:04:55

On 03.08.2021 04:38, Hao Chen wrote:
I want to get permanent MAC address when the interface is down. And I think
it is more convenient to get statistics in the down state by 'ethtool -S'.
But current all of the ethool command return -EBUSY.

I don't think we should check that the network interface is up in '.begin',
which will cause that all the ethtool commands can't be used when the
network interface is down. If some ethtool commands can only be used in the
up state, check it in the corresponding ethool OPS function is better.
This is too rude and unreasonable.

Compile-tested on arm64. Tested on an arm64 system with an on-board
STMMAC chip.
I doubt it's compile-tested, at least not with rpm enabled.
See comment below.
quoted hunk
Changes v7 ... v8:
- Optimize commit description information, optimization parameters of
  pm_runtime function.

Changes v6 ... v7:
- fix arg type error of 'dev' to 'priv->device'.

Changes v5 ... v6:
- The 4.19.90 kernel not support pm_runtime, so implemente '.begin' and
  '.complete' again. Add return value check of pm_runtime function.

Changes v4 ... v5:
- test the '.begin' will return -13 error on my machine based on 4.19.90
  kernel. The platform driver does not supported pm_runtime. So remove the
  implementation of '.begin' and '.complete'.

Changes v3 ... v4:
- implement '.complete' ethtool OPS.

Changes v2 ... v3:
- add linux/pm_runtime.h head file.

Changes v1 ... v2:
- fix spell error of dev.

Signed-off-by: Hao Chen <redacted>
---
 .../ethernet/stmicro/stmmac/stmmac_ethtool.c    | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index d0ce608b81c3..8e2ae0ff7f8f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -12,8 +12,9 @@
 #include <linux/ethtool.h>
 #include <linux/interrupt.h>
 #include <linux/mii.h>
-#include <linux/phylink.h>
 #include <linux/net_tstamp.h>
+#include <linux/phylink.h>
+#include <linux/pm_runtime.h>
 #include <asm/io.h>
 
 #include "stmmac.h"
@@ -410,11 +411,14 @@ static void stmmac_ethtool_setmsglevel(struct net_device *dev, u32 level)
 
 }
 
-static int stmmac_check_if_running(struct net_device *dev)
+static int stmmac_ethtool_begin(struct net_device *dev)
 {
-	if (!netif_running(dev))
-		return -EBUSY;
-	return 0;
+	return pm_runtime_resume_and_get(dev->dev);
This is wrong in two ways:
- There is a type mismatch and the code won't compile.
- I talked about the netdev parent.
quoted hunk
+}
+
+static void stmmac_ethtool_complete(struct net_device *dev)
+{
+	pm_runtime_put(dev->dev);
 }
 
 static int stmmac_ethtool_get_regs_len(struct net_device *dev)
@@ -1073,7 +1077,8 @@ static int stmmac_set_tunable(struct net_device *dev,
 static const struct ethtool_ops stmmac_ethtool_ops = {
 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
 				     ETHTOOL_COALESCE_MAX_FRAMES,
-	.begin = stmmac_check_if_running,
+	.begin = stmmac_ethtool_begin,
+	.complete = stmmac_ethtool_complete,
 	.get_drvinfo = stmmac_ethtool_getdrvinfo,
 	.get_msglevel = stmmac_ethtool_getmsglevel,
 	.set_msglevel = stmmac_ethtool_setmsglevel,
Again you missed to send the patch to the maintainers.
Read the basics about how to submit a patch.

Last but not least please wait for feedback on
https://lore.kernel.org/netdev/106547ef-7a61-2064-33f5-3cc8d12adb34@gmail.com/

Re: [net-next,v8] net: stmmac: optimize check in ops '.begin'

From: kernel test robot <hidden>
Date: 2021-08-03 09:02:27

Hi Hao,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on ipvs/master]
[also build test ERROR on linus/master v5.14-rc4 next-20210802]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Hao-Chen/net-stmmac-optimize-check-in-ops-begin/20210803-104151
base:   https://git.kernel.org/pub/scm/linux/kernel/git/horms/ipvs.git master
config: x86_64-randconfig-a003-20210802 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 4f71f59bf3d9914188a11d0c41bedbb339d36ff5)
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
        # https://github.com/0day-ci/linux/commit/a618eda31260a301aadf7987885767f905c5320a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Hao-Chen/net-stmmac-optimize-check-in-ops-begin/20210803-104151
        git checkout a618eda31260a301aadf7987885767f905c5320a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <redacted>

All errors (new ones prefixed by >>):

   drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c:378:7: warning: variable 'mask' set but not used [-Wunused-but-set-variable]
                   u32 mask = ADVERTISED_Autoneg | ADVERTISED_Pause;
                       ^
quoted
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c:416:35: error: passing 'struct device' to parameter of incompatible type 'struct device *'; take the address with &
           return pm_runtime_resume_and_get(dev->dev);
                                            ^~~~~~~~
                                            &
   include/linux/pm_runtime.h:400:60: note: passing argument to parameter 'dev' here
   static inline int pm_runtime_resume_and_get(struct device *dev)
                                                              ^
   drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c:421:17: error: passing 'struct device' to parameter of incompatible type 'struct device *'; take the address with &
           pm_runtime_put(dev->dev);
                          ^~~~~~~~
                          &
   include/linux/pm_runtime.h:420:49: note: passing argument to parameter 'dev' here
   static inline int pm_runtime_put(struct device *dev)
                                                   ^
   1 warning and 2 errors generated.


vim +416 drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c

   413	
   414	static int stmmac_ethtool_begin(struct net_device *dev)
   415	{
 > 416		return pm_runtime_resume_and_get(dev->dev);
   417	}
   418	

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

Re: [net-next,v8] net: stmmac: optimize check in ops '.begin'

From: kernel test robot <hidden>
Date: 2021-08-03 10:34:41

Hi Hao,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on ipvs/master]
[also build test ERROR on linus/master v5.14-rc4 next-20210802]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Hao-Chen/net-stmmac-optimize-check-in-ops-begin/20210803-104151
base:   https://git.kernel.org/pub/scm/linux/kernel/git/horms/ipvs.git master
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 10.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
        # https://github.com/0day-ci/linux/commit/a618eda31260a301aadf7987885767f905c5320a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Hao-Chen/net-stmmac-optimize-check-in-ops-begin/20210803-104151
        git checkout a618eda31260a301aadf7987885767f905c5320a
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross O=build_dir ARCH=m68k SHELL=/bin/bash drivers/net/ethernet/stmicro/stmmac/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <redacted>

All errors (new ones prefixed by >>):

   drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c: In function 'stmmac_ethtool_begin':
quoted
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c:416:38: error: incompatible type for argument 1 of 'pm_runtime_resume_and_get'
     416 |  return pm_runtime_resume_and_get(dev->dev);
         |                                   ~~~^~~~~
         |                                      |
         |                                      struct device
   In file included from drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c:17:
   include/linux/pm_runtime.h:400:60: note: expected 'struct device *' but argument is of type 'struct device'
     400 | static inline int pm_runtime_resume_and_get(struct device *dev)
         |                                             ~~~~~~~~~~~~~~~^~~
   drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c: In function 'stmmac_ethtool_complete':
quoted
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c:421:20: error: incompatible type for argument 1 of 'pm_runtime_put'
     421 |  pm_runtime_put(dev->dev);
         |                 ~~~^~~~~
         |                    |
         |                    struct device
   In file included from drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c:17:
   include/linux/pm_runtime.h:420:49: note: expected 'struct device *' but argument is of type 'struct device'
     420 | static inline int pm_runtime_put(struct device *dev)
         |                                  ~~~~~~~~~~~~~~~^~~
   drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c: In function 'stmmac_ethtool_begin':
   drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c:417:1: error: control reaches end of non-void function [-Werror=return-type]
     417 | }
         | ^
   cc1: some warnings being treated as errors


vim +/pm_runtime_resume_and_get +416 drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c

   413	
   414	static int stmmac_ethtool_begin(struct net_device *dev)
   415	{
 > 416		return pm_runtime_resume_and_get(dev->dev);
   417	}
   418	
   419	static void stmmac_ethtool_complete(struct net_device *dev)
   420	{
 > 421		pm_runtime_put(dev->dev);
   422	}
   423	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help