From b023f0c0f81dbdf3860f41c9d85b0125dfe2e6c9 Mon Sep 17 00:00:00 2001 From: Bhadram Varka Date: Mon, 25 Mar 2019 14:16:39 +0530 Subject: [PATCH] nvethernet: support to change MAC address Adds support for dynamic MAC address change. Gets MAC address from userspace and update in OSI core structure. Automatically MAC address will be picked up from OSI core structure and program the same in HW registers. Bug 200512251 Change-Id: Ie49fd56c3d219637fc4bf33c818c380a8f1c7bf3 Signed-off-by: Bhadram Varka Reviewed-on: https://git-master.nvidia.com/r/2080718 Reviewed-by: Rakesh Goyal Reviewed-by: Narayan Reddy Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Srinivas Ramachandran GVS: Gerrit_Virtual_Submit Reviewed-by: Ashutosh Jha Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../ethernet/nvidia/nvethernet/ether_linux.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c b/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c index d29420a5..2e4302cf 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c +++ b/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c @@ -1117,11 +1117,45 @@ static int ether_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) return ret; } +/** + * ether_set_mac_addr - Set MAC address + * @ndev: Network device structure + * @addr: MAC address to be programmed. + * + * Algorithm: + * 1) Checks whether given MAC address is valid or not + * 2) Stores the MAC address in OSI core structure + * + * Dependencies: Ethernet interface need to be down to set MAC address + * + * Protection: None. + * + * Return: 0 - success, negative value - failure. + */ +static int ether_set_mac_addr(struct net_device *ndev, void *addr) +{ + struct ether_priv_data *pdata = netdev_priv(ndev); + struct osi_core_priv_data *osi_core = pdata->osi_core; + int ret = 0; + + ret = eth_mac_addr(ndev, addr); + if (ret) { + dev_err(pdata->dev, "failed to set MAC address\n"); + return ret; + } + + /* MAC address programmed in HW registers during osi_hw_core_init() */ + memcpy(osi_core->mac_addr, ndev->dev_addr, ETH_ALEN); + + return ret; +} + static const struct net_device_ops ether_netdev_ops = { .ndo_open = ether_open, .ndo_stop = ether_close, .ndo_start_xmit = ether_start_xmit, .ndo_do_ioctl = ether_ioctl, + .ndo_set_mac_address = ether_set_mac_addr, }; /**