diff mbox series

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

Message ID 0F90835A90AD58A2+20240726100301.21416-9-mengyuanlou@net-swift.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series add sriov support for wangxun NICs | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
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: 42 this patch: 42
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: 44 this patch: 44
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: 49 this patch: 49
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

Commit Message

Mengyuan Lou July 26, 2024, 10:02 a.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
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;