diff mbox series

[v1,15/16] net-next/yunsilicon: Add ndo_set_mac_address

Message ID 20241218105055.2237645-16-tianx@yunsilicon.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net-next/yunsilicon: ADD Yunsilicon XSC Ethernet Driver | expand

Checks

Context Check Description
netdev/series_format fail Series longer than 15 patches
netdev/tree_selection success Guessed tree name to be 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: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 19 this patch: 19
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: 915 this patch: 915
netdev/checkpatch warning WARNING: Co-developed-by and Signed-off-by: name/email do not match WARNING: Co-developed-by: must be immediately followed by Signed-off-by: WARNING: line length of 82 exceeds 80 columns WARNING: line length of 84 exceeds 80 columns WARNING: line length of 87 exceeds 80 columns WARNING: line length of 98 exceeds 80 columns
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

tianx Dec. 18, 2024, 10:50 a.m. UTC
Add ndo_set_mac_address

 
Co-developed-by: Honggang Wei <weihg@yunsilicon.com>
Co-developed-by: Lei Yan <Jacky@yunsilicon.com>
Signed-off-by: Xin Tian <tianx@yunsilicon.com>
---
 .../ethernet/yunsilicon/xsc/common/xsc_core.h |  2 +
 .../net/ethernet/yunsilicon/xsc/net/main.c    | 22 ++++++
 .../net/ethernet/yunsilicon/xsc/pci/vport.c   | 72 +++++++++++++++++++
 3 files changed, 96 insertions(+)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
index d69be5352..5c60b3126 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
+++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
@@ -612,6 +612,8 @@  int xsc_register_interface(struct xsc_interface *intf);
 void xsc_unregister_interface(struct xsc_interface *intf);
 
 u8 xsc_core_query_vport_state(struct xsc_core_device *xdev, u16 vport);
+int xsc_core_modify_nic_vport_mac_address(struct xsc_core_device *xdev,
+					  u16 vport, u8 *addr, bool perm_mac);
 
 static inline void *xsc_buf_offset(struct xsc_buf *buf, int offset)
 {
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
index 0c6e949b5..6df7ed3bb 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/net/main.c
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
@@ -1647,6 +1647,27 @@  static void xsc_eth_get_stats(struct net_device *netdev, struct rtnl_link_stats6
 	xsc_eth_fold_sw_stats64(adapter, stats);
 }
 
+static int xsc_eth_set_mac(struct net_device *netdev, void *addr)
+{
+	struct xsc_adapter *adapter = netdev_priv(netdev);
+	struct sockaddr *saddr = addr;
+	struct xsc_core_device *xdev = adapter->xdev;
+	int ret;
+
+	if (!is_valid_ether_addr(saddr->sa_data))
+		return -EADDRNOTAVAIL;
+
+	ret = xsc_core_modify_nic_vport_mac_address(xdev, 0, saddr->sa_data, false);
+	if (ret)
+		xsc_core_err(adapter->xdev, "%s: xsc set mac addr failed\n", __func__);
+
+	netif_addr_lock_bh(netdev);
+	eth_hw_addr_set(netdev, saddr->sa_data);
+	netif_addr_unlock_bh(netdev);
+
+	return 0;
+}
+
 static int xsc_eth_set_hw_mtu(struct xsc_core_device *xdev, u16 mtu, u16 rx_buf_sz)
 {
 	struct xsc_set_mtu_mbox_in in;
@@ -1677,6 +1698,7 @@  static const struct net_device_ops xsc_netdev_ops = {
 	.ndo_stop		= xsc_eth_close,
 	.ndo_start_xmit		= xsc_eth_xmit_start,
 	.ndo_get_stats64	= xsc_eth_get_stats,
+	.ndo_set_mac_address	= xsc_eth_set_mac,
 };
 
 static void xsc_eth_build_nic_netdev(struct xsc_adapter *adapter)
diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/vport.c b/drivers/net/ethernet/yunsilicon/xsc/pci/vport.c
index 8200f6c91..f044ac009 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/pci/vport.c
+++ b/drivers/net/ethernet/yunsilicon/xsc/pci/vport.c
@@ -6,6 +6,8 @@ 
 #include "common/xsc_core.h"
 #include "common/xsc_driver.h"
 
+#define LAG_ID_INVALID		U16_MAX
+
 u8 xsc_core_query_vport_state(struct xsc_core_device *xdev, u16 vport)
 {
 	struct xsc_query_vport_state_in in;
@@ -28,3 +30,73 @@  u8 xsc_core_query_vport_state(struct xsc_core_device *xdev, u16 vport)
 	return out.state;
 }
 EXPORT_SYMBOL(xsc_core_query_vport_state);
+
+static int xsc_modify_nic_vport_context(struct xsc_core_device *xdev, void *in,
+					int inlen)
+{
+	struct xsc_modify_nic_vport_context_out out;
+	struct xsc_modify_nic_vport_context_in *tmp;
+	int err;
+
+	memset(&out, 0, sizeof(out));
+	tmp = (struct xsc_modify_nic_vport_context_in *)in;
+	tmp->hdr.opcode = cpu_to_be16(XSC_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
+
+	err = xsc_cmd_exec(xdev, in, inlen, &out, sizeof(out));
+	if (err || out.hdr.status) {
+		xsc_core_err(xdev, "fail to modify nic vport err=%d status=%d\n",
+			     err, out.hdr.status);
+	}
+	return err;
+}
+
+static int __xsc_modify_nic_vport_mac_address(struct xsc_core_device *xdev,
+					      u16 vport, u8 *addr, int force_other, bool perm_mac)
+{
+	struct xsc_modify_nic_vport_context_in *in;
+	int err;
+	int in_sz;
+	u8 *mac_addr;
+	u16 caps = 0;
+	u16 caps_mask = 0;
+	u16 lag_id = LAG_ID_INVALID;
+
+	in_sz = sizeof(struct xsc_modify_nic_vport_context_in) + 2;
+
+	in = kzalloc(in_sz, GFP_KERNEL);
+	if (!in)
+		return -ENOMEM;
+
+	in->lag_id = cpu_to_be16(lag_id);
+
+	if (perm_mac) {
+		in->field_select.permanent_address = 1;
+		mac_addr = in->nic_vport_ctx.permanent_address;
+	} else {
+		in->field_select.current_address = 1;
+		mac_addr = in->nic_vport_ctx.current_address;
+	}
+
+	caps_mask |= BIT(XSC_TBM_CAP_PP_BYPASS);
+	in->caps = cpu_to_be16(caps);
+	in->caps_mask = cpu_to_be16(caps_mask);
+
+	ether_addr_copy(mac_addr, addr);
+
+	in->field_select.addresses_list = 1;
+	in->nic_vport_ctx.vlan_allowed = 0;
+
+	err = xsc_modify_nic_vport_context(xdev, in, in_sz);
+	if (err)
+		xsc_core_err(xdev, "modify nic vport context failed\n");
+
+	kfree(in);
+	return err;
+}
+
+int xsc_core_modify_nic_vport_mac_address(struct xsc_core_device *xdev,
+					  u16 vport, u8 *addr, bool perm_mac)
+{
+	return __xsc_modify_nic_vport_mac_address(xdev, vport, addr, 0, perm_mac);
+}
+EXPORT_SYMBOL(xsc_core_modify_nic_vport_mac_address);