diff mbox series

[net-next,v5,08/10] net: libwx: add eswitch switch api for devlink ops

Message ID 5DD6E0A4F173D3D3+20240804124841.71177-9-mengyuanlou@net-swift.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v5,01/10] net: libwx: Add malibox api for wangxun pf drivers | expand

Checks

Context Check Description
netdev/series_format warning Series does not have a cover letter
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 29 this patch: 29
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 4 maintainers not CCed: jiawenwu@trustnetic.com edumazet@google.com pabeni@redhat.com kuba@kernel.org
netdev/build_clang success Errors and warnings before: 30 this patch: 30
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 35 this patch: 35
netdev/checkpatch warning WARNING: Missing commit description - Add an appropriate one WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-08-04--21-00 (tests: 701)

Commit Message

Mengyuan Lou Aug. 4, 2024, 12:48 p.m. UTC
Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>
---
 drivers/net/ethernet/wangxun/libwx/Makefile   |  3 +-
 .../net/ethernet/wangxun/libwx/wx_devlink.c   |  3 ++
 .../net/ethernet/wangxun/libwx/wx_eswitch.c   | 53 +++++++++++++++++++
 .../net/ethernet/wangxun/libwx/wx_eswitch.h   | 13 +++++
 drivers/net/ethernet/wangxun/libwx/wx_type.h  |  1 +
 5 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
 create mode 100644 drivers/net/ethernet/wangxun/libwx/wx_eswitch.h

Comments

Simon Horman Aug. 5, 2024, 4:43 p.m. UTC | #1
On Sun, Aug 04, 2024 at 08:48:39PM +0800, Mengyuan Lou wrote:

Each patch needs a patch description describing not just what is done
but why.

Also, please seed the CC list for patch submissions
using get_maintainer this.patch. I believe that b4
will do that for you.

> Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>

...

>  static void wx_devlink_free(void *devlink_ptr)
> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
> new file mode 100644
> index 000000000000..a426a352bf96
> --- /dev/null
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
> @@ -0,0 +1,53 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (C) 2019-2021, Intel Corporation. */

Are you sure Intel holds the copyright on this code?

> +
> +#include <linux/pci.h>
> +
> +#include "wx_type.h"
> +#include "wx_eswitch.h"
> +#include "wx_devlink.h"
> +
> +int wx_eswitch_mode_set(struct devlink *devlink, u16 mode,
> +			struct netlink_ext_ack *extack)
> +{
> +	struct wx_dl_priv *dl_priv = devlink_priv(devlink);
> +	struct wx *wx = dl_priv->priv_wx;
> +
> +	if (wx->eswitch_mode == mode)
> +		return 0;
> +
> +	if (wx->num_vfs) {
> +		dev_info(&(wx)->pdev->dev,
> +			 "Change eswitch mode is allowed if there is no VFs.");

maybe: Changing eswitch mode is only allowed if there are no VFs.

> +		return -EOPNOTSUPP;
> +	}
> +
> +	switch (mode) {
> +	case DEVLINK_ESWITCH_MODE_LEGACY:
> +		dev_info(&(wx)->pdev->dev,
> +			 "PF%d changed eswitch mode to legacy",
> +			 wx->bus.func);
> +		NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to legacy");
> +		break;
> +	case DEVLINK_ESWITCH_MODE_SWITCHDEV:
> +		dev_info(&(wx)->pdev->dev,
> +			 "Do not support switchdev in eswitch mode.");
> +		NL_SET_ERR_MSG_MOD(extack, "Do not support switchdev mode.");

maybe: eswitch mode switchdev is not supported

I am curious to know if you are planning to implement eswitch mode in the
near future.  If not, is wx_eswitch_mode_set() needed: it seems unused in
this patchset: it should probably be added in a patchset that uses it.

> +		return -EINVAL;
> +	default:
> +		NL_SET_ERR_MSG_MOD(extack, "Unknown eswitch mode");
> +		return -EINVAL;
> +	}
> +
> +	wx->eswitch_mode = mode;
> +	return 0;
> +}
> +
> +int wx_eswitch_mode_get(struct devlink *devlink, u16 *mode)
> +{
> +	struct wx_dl_priv *dl_priv = devlink_priv(devlink);
> +	struct wx *wx = dl_priv->priv_wx;
> +
> +	*mode = wx->eswitch_mode;
> +	return 0;
> +}

...
kernel test robot Aug. 5, 2024, 5:03 p.m. UTC | #2
Hi Mengyuan,

kernel test robot noticed the following build errors:

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

url:    https://github.com/intel-lab-lkp/linux/commits/Mengyuan-Lou/net-libwx-Add-sriov-api-for-wangxun-nics/20240804-214836
base:   net-next/main
patch link:    https://lore.kernel.org/r/5DD6E0A4F173D3D3%2B20240804124841.71177-9-mengyuanlou%40net-swift.com
patch subject: [PATCH net-next v5 08/10] net: libwx: add eswitch switch api for devlink ops
config: loongarch-defconfig (https://download.01.org/0day-ci/archive/20240806/202408060023.UYl4fu6N-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240806/202408060023.UYl4fu6N-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408060023.UYl4fu6N-lkp@intel.com/

All errors (new ones prefixed by >>):

   loongarch64-linux-ld: drivers/net/ethernet/wangxun/libwx/wx_devlink.o: in function `wx_devlink_free':
   wx_devlink.c:(.text+0x58): undefined reference to `devlink_unregister'
   loongarch64-linux-ld: wx_devlink.c:(.text+0x6c): undefined reference to `devlink_free'
   loongarch64-linux-ld: drivers/net/ethernet/wangxun/libwx/wx_devlink.o: in function `wx_devlink_create_pf_port':
   wx_devlink.c:(.text+0xa0): undefined reference to `priv_to_devlink'
   loongarch64-linux-ld: wx_devlink.c:(.text+0xfc): undefined reference to `devlink_port_attrs_set'
   loongarch64-linux-ld: wx_devlink.c:(.text+0x110): undefined reference to `devlink_port_register_with_ops'
   loongarch64-linux-ld: drivers/net/ethernet/wangxun/libwx/wx_devlink.o: in function `wx_devlink_destroy_pf_port':
   wx_devlink.c:(.text+0x174): undefined reference to `devl_port_unregister'
   loongarch64-linux-ld: drivers/net/ethernet/wangxun/libwx/wx_devlink.o: in function `wx_create_devlink':
   wx_devlink.c:(.text+0x2a0): undefined reference to `devlink_alloc_ns'
   loongarch64-linux-ld: wx_devlink.c:(.text+0x2d4): undefined reference to `devlink_unregister'
   loongarch64-linux-ld: wx_devlink.c:(.text+0x2dc): undefined reference to `devlink_free'
   loongarch64-linux-ld: wx_devlink.c:(.text+0x304): undefined reference to `devlink_register'
   loongarch64-linux-ld: wx_devlink.c:(.text+0x31c): undefined reference to `devlink_priv'
   loongarch64-linux-ld: drivers/net/ethernet/wangxun/libwx/wx_devlink.o: in function `wx_devlink_create_vf_port':
   wx_devlink.c:(.text+0x354): undefined reference to `priv_to_devlink'
   loongarch64-linux-ld: wx_devlink.c:(.text+0x3d0): undefined reference to `devlink_port_attrs_set'
   loongarch64-linux-ld: wx_devlink.c:(.text+0x3e8): undefined reference to `devl_port_register_with_ops'
   loongarch64-linux-ld: drivers/net/ethernet/wangxun/libwx/wx_devlink.o: in function `wx_devlink_destroy_vf_port':
   wx_devlink.c:(.text+0x47c): undefined reference to `devl_port_unregister'
   loongarch64-linux-ld: drivers/net/ethernet/wangxun/libwx/wx_eswitch.o: in function `wx_eswitch_mode_set':
>> wx_eswitch.c:(.text+0x1c): undefined reference to `devlink_priv'
   loongarch64-linux-ld: drivers/net/ethernet/wangxun/libwx/wx_eswitch.o: in function `wx_eswitch_mode_get':
   wx_eswitch.c:(.text+0x138): undefined reference to `devlink_priv'
Jiri Pirko Aug. 6, 2024, 11:42 a.m. UTC | #3
Mon, Aug 05, 2024 at 06:43:50PM CEST, horms@kernel.org wrote:
>On Sun, Aug 04, 2024 at 08:48:39PM +0800, Mengyuan Lou wrote:
>
>Each patch needs a patch description describing not just what is done
>but why.
>
>Also, please seed the CC list for patch submissions
>using get_maintainer this.patch. I believe that b4
>will do that for you.
>
>> Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>
>
>...
>
>>  static void wx_devlink_free(void *devlink_ptr)
>> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
>> new file mode 100644
>> index 000000000000..a426a352bf96
>> --- /dev/null
>> +++ b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
>> @@ -0,0 +1,53 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright (C) 2019-2021, Intel Corporation. */
>
>Are you sure Intel holds the copyright on this code?
>
>> +
>> +#include <linux/pci.h>
>> +
>> +#include "wx_type.h"
>> +#include "wx_eswitch.h"
>> +#include "wx_devlink.h"
>> +
>> +int wx_eswitch_mode_set(struct devlink *devlink, u16 mode,
>> +			struct netlink_ext_ack *extack)
>> +{
>> +	struct wx_dl_priv *dl_priv = devlink_priv(devlink);
>> +	struct wx *wx = dl_priv->priv_wx;
>> +
>> +	if (wx->eswitch_mode == mode)
>> +		return 0;
>> +
>> +	if (wx->num_vfs) {
>> +		dev_info(&(wx)->pdev->dev,
>> +			 "Change eswitch mode is allowed if there is no VFs.");
>
>maybe: Changing eswitch mode is only allowed if there are no VFs.
>
>> +		return -EOPNOTSUPP;
>> +	}
>> +
>> +	switch (mode) {
>> +	case DEVLINK_ESWITCH_MODE_LEGACY:
>> +		dev_info(&(wx)->pdev->dev,
>> +			 "PF%d changed eswitch mode to legacy",
>> +			 wx->bus.func);
>> +		NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to legacy");
>> +		break;
>> +	case DEVLINK_ESWITCH_MODE_SWITCHDEV:
>> +		dev_info(&(wx)->pdev->dev,
>> +			 "Do not support switchdev in eswitch mode.");
>> +		NL_SET_ERR_MSG_MOD(extack, "Do not support switchdev mode.");
>
>maybe: eswitch mode switchdev is not supported
>
>I am curious to know if you are planning to implement eswitch mode in the
>near future.  If not, is wx_eswitch_mode_set() needed: it seems unused in
>this patchset: it should probably be added in a patchset that uses it.

This is wrong.

switchdev mode should be supported from the beginning. There is some odd
hybrid mode supported, VF gets devlink port created for representors,
yet no netdev. I'm very sure this triggers:

static void devlink_port_type_warn(struct work_struct *work)
{
        struct devlink_port *port = container_of(to_delayed_work(work),
                                                 struct devlink_port,
                                                 type_warn_dw);
        dev_warn(port->devlink->dev, "Type was not set for devlink port.");
}

So, if you don't see this message, leads to my assuptions this patchset
was not tested. Certainly odd.



>
>> +		return -EINVAL;
>> +	default:
>> +		NL_SET_ERR_MSG_MOD(extack, "Unknown eswitch mode");
>> +		return -EINVAL;
>> +	}
>> +
>> +	wx->eswitch_mode = mode;
>> +	return 0;
>> +}
>> +
>> +int wx_eswitch_mode_get(struct devlink *devlink, u16 *mode)
>> +{
>> +	struct wx_dl_priv *dl_priv = devlink_priv(devlink);
>> +	struct wx *wx = dl_priv->priv_wx;
>> +
>> +	*mode = wx->eswitch_mode;
>> +	return 0;
>> +}
>
>...
>
Mengyuan Lou Aug. 7, 2024, 7:41 a.m. UTC | #4
> 2024年8月6日 19:42,Jiri Pirko <jiri@resnulli.us> 写道:
> 
> Mon, Aug 05, 2024 at 06:43:50PM CEST, horms@kernel.org wrote:
>> On Sun, Aug 04, 2024 at 08:48:39PM +0800, Mengyuan Lou wrote:
>> 
>> Each patch needs a patch description describing not just what is done
>> but why.
>> 
>> Also, please seed the CC list for patch submissions
>> using get_maintainer this.patch. I believe that b4
>> will do that for you.
>> 
>>> Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>
>> 
>> ...
>> 
>>> static void wx_devlink_free(void *devlink_ptr)
>>> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
>>> new file mode 100644
>>> index 000000000000..a426a352bf96
>>> --- /dev/null
>>> +++ b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
>>> @@ -0,0 +1,53 @@
>>> +// SPDX-License-Identifier: GPL-2.0
>>> +/* Copyright (C) 2019-2021, Intel Corporation. */
>> 
>> Are you sure Intel holds the copyright on this code?
>> 
>>> +
>>> +#include <linux/pci.h>
>>> +
>>> +#include "wx_type.h"
>>> +#include "wx_eswitch.h"
>>> +#include "wx_devlink.h"
>>> +
>>> +int wx_eswitch_mode_set(struct devlink *devlink, u16 mode,
>>> + struct netlink_ext_ack *extack)
>>> +{
>>> + struct wx_dl_priv *dl_priv = devlink_priv(devlink);
>>> + struct wx *wx = dl_priv->priv_wx;
>>> +
>>> + if (wx->eswitch_mode == mode)
>>> + return 0;
>>> +
>>> + if (wx->num_vfs) {
>>> + dev_info(&(wx)->pdev->dev,
>>> + "Change eswitch mode is allowed if there is no VFs.");
>> 
>> maybe: Changing eswitch mode is only allowed if there are no VFs.
>> 
>>> + return -EOPNOTSUPP;
>>> + }
>>> +
>>> + switch (mode) {
>>> + case DEVLINK_ESWITCH_MODE_LEGACY:
>>> + dev_info(&(wx)->pdev->dev,
>>> + "PF%d changed eswitch mode to legacy",
>>> + wx->bus.func);
>>> + NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to legacy");
>>> + break;
>>> + case DEVLINK_ESWITCH_MODE_SWITCHDEV:
>>> + dev_info(&(wx)->pdev->dev,
>>> + "Do not support switchdev in eswitch mode.");
>>> + NL_SET_ERR_MSG_MOD(extack, "Do not support switchdev mode.");
>> 
>> maybe: eswitch mode switchdev is not supported
>> 
>> I am curious to know if you are planning to implement eswitch mode in the
>> near future.  If not, is wx_eswitch_mode_set() needed: it seems unused in
>> this patchset: it should probably be added in a patchset that uses it.
> 
> This is wrong.
> 
> switchdev mode should be supported from the beginning. There is some odd
> hybrid mode supported, VF gets devlink port created for representors,
> yet no netdev. I'm very sure this triggers:
> 
> static void devlink_port_type_warn(struct work_struct *work)
> {
>        struct devlink_port *port = container_of(to_delayed_work(work),
>                                                 struct devlink_port,
>                                                 type_warn_dw);
>        dev_warn(port->devlink->dev, "Type was not set for devlink port.");
> }
> 
> So, if you don't see this message, leads to my assuptions this patchset
> was not tested. Certainly odd.
> 

I have seen this warnning info.
What I want is that the devlink port Uapi to vfs, but I think the product will
not to support switchdev mode and the representors representors will not be used.

Be like:
https://lore.kernel.org/netdev/20240620002741.1029936-1-kuba@kernel.org/

> 
>> 
>>> + return -EINVAL;
>>> + default:
>>> + NL_SET_ERR_MSG_MOD(extack, "Unknown eswitch mode");
>>> + return -EINVAL;
>>> + }
>>> +
>>> + wx->eswitch_mode = mode;
>>> + return 0;
>>> +}
>>> +
>>> +int wx_eswitch_mode_get(struct devlink *devlink, u16 *mode)
>>> +{
>>> + struct wx_dl_priv *dl_priv = devlink_priv(devlink);
>>> + struct wx *wx = dl_priv->priv_wx;
>>> +
>>> + *mode = wx->eswitch_mode;
>>> + return 0;
>>> +}
>> 
>> ...
>> 
>
Jiri Pirko Aug. 7, 2024, 11:43 a.m. UTC | #5
Wed, Aug 07, 2024 at 09:41:53AM CEST, mengyuanlou@net-swift.com wrote:
>
>
>> 2024年8月6日 19:42,Jiri Pirko <jiri@resnulli.us> 写道:
>> 
>> Mon, Aug 05, 2024 at 06:43:50PM CEST, horms@kernel.org wrote:
>>> On Sun, Aug 04, 2024 at 08:48:39PM +0800, Mengyuan Lou wrote:
>>> 
>>> Each patch needs a patch description describing not just what is done
>>> but why.
>>> 
>>> Also, please seed the CC list for patch submissions
>>> using get_maintainer this.patch. I believe that b4
>>> will do that for you.
>>> 
>>>> Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>
>>> 
>>> ...
>>> 
>>>> static void wx_devlink_free(void *devlink_ptr)
>>>> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
>>>> new file mode 100644
>>>> index 000000000000..a426a352bf96
>>>> --- /dev/null
>>>> +++ b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
>>>> @@ -0,0 +1,53 @@
>>>> +// SPDX-License-Identifier: GPL-2.0
>>>> +/* Copyright (C) 2019-2021, Intel Corporation. */
>>> 
>>> Are you sure Intel holds the copyright on this code?
>>> 
>>>> +
>>>> +#include <linux/pci.h>
>>>> +
>>>> +#include "wx_type.h"
>>>> +#include "wx_eswitch.h"
>>>> +#include "wx_devlink.h"
>>>> +
>>>> +int wx_eswitch_mode_set(struct devlink *devlink, u16 mode,
>>>> + struct netlink_ext_ack *extack)
>>>> +{
>>>> + struct wx_dl_priv *dl_priv = devlink_priv(devlink);
>>>> + struct wx *wx = dl_priv->priv_wx;
>>>> +
>>>> + if (wx->eswitch_mode == mode)
>>>> + return 0;
>>>> +
>>>> + if (wx->num_vfs) {
>>>> + dev_info(&(wx)->pdev->dev,
>>>> + "Change eswitch mode is allowed if there is no VFs.");
>>> 
>>> maybe: Changing eswitch mode is only allowed if there are no VFs.
>>> 
>>>> + return -EOPNOTSUPP;
>>>> + }
>>>> +
>>>> + switch (mode) {
>>>> + case DEVLINK_ESWITCH_MODE_LEGACY:
>>>> + dev_info(&(wx)->pdev->dev,
>>>> + "PF%d changed eswitch mode to legacy",
>>>> + wx->bus.func);
>>>> + NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to legacy");
>>>> + break;
>>>> + case DEVLINK_ESWITCH_MODE_SWITCHDEV:
>>>> + dev_info(&(wx)->pdev->dev,
>>>> + "Do not support switchdev in eswitch mode.");
>>>> + NL_SET_ERR_MSG_MOD(extack, "Do not support switchdev mode.");
>>> 
>>> maybe: eswitch mode switchdev is not supported
>>> 
>>> I am curious to know if you are planning to implement eswitch mode in the
>>> near future.  If not, is wx_eswitch_mode_set() needed: it seems unused in
>>> this patchset: it should probably be added in a patchset that uses it.
>> 
>> This is wrong.
>> 
>> switchdev mode should be supported from the beginning. There is some odd
>> hybrid mode supported, VF gets devlink port created for representors,
>> yet no netdev. I'm very sure this triggers:
>> 
>> static void devlink_port_type_warn(struct work_struct *work)
>> {
>>        struct devlink_port *port = container_of(to_delayed_work(work),
>>                                                 struct devlink_port,
>>                                                 type_warn_dw);
>>        dev_warn(port->devlink->dev, "Type was not set for devlink port.");
>> }
>> 
>> So, if you don't see this message, leads to my assuptions this patchset
>> was not tested. Certainly odd.
>> 
>
>I have seen this warnning info.

Yet you ignore it. Awesome.


>What I want is that the devlink port Uapi to vfs, but I think the product will
>not to support switchdev mode and the representors representors will not be used.

Implement proper netdevs for VF representors in switchdev mode please.
Legacy mode should not create devlink ports.

>
>Be like:
>https://lore.kernel.org/netdev/20240620002741.1029936-1-kuba@kernel.org/
>
>> 
>>> 
>>>> + return -EINVAL;
>>>> + default:
>>>> + NL_SET_ERR_MSG_MOD(extack, "Unknown eswitch mode");
>>>> + return -EINVAL;
>>>> + }
>>>> +
>>>> + wx->eswitch_mode = mode;
>>>> + return 0;
>>>> +}
>>>> +
>>>> +int wx_eswitch_mode_get(struct devlink *devlink, u16 *mode)
>>>> +{
>>>> + struct wx_dl_priv *dl_priv = devlink_priv(devlink);
>>>> + struct wx *wx = dl_priv->priv_wx;
>>>> +
>>>> + *mode = wx->eswitch_mode;
>>>> + return 0;
>>>> +}
>>> 
>>> ...
>>> 
>> 
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/wangxun/libwx/Makefile b/drivers/net/ethernet/wangxun/libwx/Makefile
index 643a5e947ba9..a7065ad924d1 100644
--- a/drivers/net/ethernet/wangxun/libwx/Makefile
+++ b/drivers/net/ethernet/wangxun/libwx/Makefile
@@ -4,4 +4,5 @@ 
 
 obj-$(CONFIG_LIBWX) += libwx.o
 
-libwx-objs := wx_hw.o wx_lib.o wx_ethtool.o wx_mbx.o wx_sriov.o wx_devlink.o
+libwx-objs := wx_hw.o wx_lib.o wx_ethtool.o wx_mbx.o wx_sriov.o wx_devlink.o \
+	      wx_eswitch.o
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_devlink.c b/drivers/net/ethernet/wangxun/libwx/wx_devlink.c
index b39da37c0842..f37362af1449 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_devlink.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_devlink.c
@@ -6,9 +6,12 @@ 
 
 #include "wx_type.h"
 #include "wx_sriov.h"
+#include "wx_eswitch.h"
 #include "wx_devlink.h"
 
 static const struct devlink_ops wx_pf_devlink_ops = {
+	.eswitch_mode_get = wx_eswitch_mode_get,
+	.eswitch_mode_set = wx_eswitch_mode_set,
 };
 
 static void wx_devlink_free(void *devlink_ptr)
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
new file mode 100644
index 000000000000..a426a352bf96
--- /dev/null
+++ b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
@@ -0,0 +1,53 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2019-2021, Intel Corporation. */
+
+#include <linux/pci.h>
+
+#include "wx_type.h"
+#include "wx_eswitch.h"
+#include "wx_devlink.h"
+
+int wx_eswitch_mode_set(struct devlink *devlink, u16 mode,
+			struct netlink_ext_ack *extack)
+{
+	struct wx_dl_priv *dl_priv = devlink_priv(devlink);
+	struct wx *wx = dl_priv->priv_wx;
+
+	if (wx->eswitch_mode == mode)
+		return 0;
+
+	if (wx->num_vfs) {
+		dev_info(&(wx)->pdev->dev,
+			 "Change eswitch mode is allowed if there is no VFs.");
+		return -EOPNOTSUPP;
+	}
+
+	switch (mode) {
+	case DEVLINK_ESWITCH_MODE_LEGACY:
+		dev_info(&(wx)->pdev->dev,
+			 "PF%d changed eswitch mode to legacy",
+			 wx->bus.func);
+		NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to legacy");
+		break;
+	case DEVLINK_ESWITCH_MODE_SWITCHDEV:
+		dev_info(&(wx)->pdev->dev,
+			 "Do not support switchdev in eswitch mode.");
+		NL_SET_ERR_MSG_MOD(extack, "Do not support switchdev mode.");
+		return -EINVAL;
+	default:
+		NL_SET_ERR_MSG_MOD(extack, "Unknown eswitch mode");
+		return -EINVAL;
+	}
+
+	wx->eswitch_mode = mode;
+	return 0;
+}
+
+int wx_eswitch_mode_get(struct devlink *devlink, u16 *mode)
+{
+	struct wx_dl_priv *dl_priv = devlink_priv(devlink);
+	struct wx *wx = dl_priv->priv_wx;
+
+	*mode = wx->eswitch_mode;
+	return 0;
+}
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_eswitch.h b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.h
new file mode 100644
index 000000000000..0323931e7df1
--- /dev/null
+++ b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.h
@@ -0,0 +1,13 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2019-2021, Intel Corporation. */
+
+#ifndef _WX_ESWITCH_H_
+#define _WX_ESWITCH_H_
+
+#include <net/devlink.h>
+
+int wx_eswitch_mode_get(struct devlink *devlink, u16 *mode);
+int wx_eswitch_mode_set(struct devlink *devlink, u16 mode,
+			struct netlink_ext_ack *extack);
+
+#endif /* _WX_ESWITCH_H_ */
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_type.h b/drivers/net/ethernet/wangxun/libwx/wx_type.h
index a8722f69cebb..a3e103e0c365 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_type.h
+++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h
@@ -1141,6 +1141,7 @@  struct wx {
 	/* devlink port data */
 	struct devlink_port devlink_port;
 	struct wx_dl_priv *dl_priv;
+	u16 eswitch_mode;		/* current mode of eswitch */
 
 	struct wx_bus_info bus;
 	struct wx_mbx_info mbx;