Commit 59098055 authored by Fuyun Liang's avatar Fuyun Liang Committed by David S. Miller

net: hns3: add existence check when remove old uc mac address

When driver is in initial state, the mac_vlan table table is empty.
So the delete operation for mac address must fail. Existence check
is needed here. Otherwise, the error message will make user confused.

Fixes: 46a3df9f ("net: hns3: Add HNS3 Acceleration Engine & Compatibility Layer Support")
Signed-off-by: default avatarFuyun Liang <liangfuyun1@huawei.com>
Signed-off-by: default avatarPeng Li <lipeng321@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent daa13701
...@@ -338,7 +338,8 @@ struct hnae3_ae_ops { ...@@ -338,7 +338,8 @@ struct hnae3_ae_ops {
u32 *tx_usecs_high, u32 *rx_usecs_high); u32 *tx_usecs_high, u32 *rx_usecs_high);
void (*get_mac_addr)(struct hnae3_handle *handle, u8 *p); void (*get_mac_addr)(struct hnae3_handle *handle, u8 *p);
int (*set_mac_addr)(struct hnae3_handle *handle, void *p); int (*set_mac_addr)(struct hnae3_handle *handle, void *p,
bool is_first);
int (*add_uc_addr)(struct hnae3_handle *handle, int (*add_uc_addr)(struct hnae3_handle *handle,
const unsigned char *addr); const unsigned char *addr);
int (*rm_uc_addr)(struct hnae3_handle *handle, int (*rm_uc_addr)(struct hnae3_handle *handle,
......
...@@ -1120,7 +1120,7 @@ static int hns3_nic_net_set_mac_address(struct net_device *netdev, void *p) ...@@ -1120,7 +1120,7 @@ static int hns3_nic_net_set_mac_address(struct net_device *netdev, void *p)
if (!mac_addr || !is_valid_ether_addr((const u8 *)mac_addr->sa_data)) if (!mac_addr || !is_valid_ether_addr((const u8 *)mac_addr->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
ret = h->ae_algo->ops->set_mac_addr(h, mac_addr->sa_data); ret = h->ae_algo->ops->set_mac_addr(h, mac_addr->sa_data, false);
if (ret) { if (ret) {
netdev_err(netdev, "set_mac_address fail, ret=%d!\n", ret); netdev_err(netdev, "set_mac_address fail, ret=%d!\n", ret);
return ret; return ret;
...@@ -3048,7 +3048,7 @@ static void hns3_init_mac_addr(struct net_device *netdev) ...@@ -3048,7 +3048,7 @@ static void hns3_init_mac_addr(struct net_device *netdev)
} }
if (h->ae_algo->ops->set_mac_addr) if (h->ae_algo->ops->set_mac_addr)
h->ae_algo->ops->set_mac_addr(h, netdev->dev_addr); h->ae_algo->ops->set_mac_addr(h, netdev->dev_addr, true);
} }
......
...@@ -4378,7 +4378,8 @@ static void hclge_get_mac_addr(struct hnae3_handle *handle, u8 *p) ...@@ -4378,7 +4378,8 @@ static void hclge_get_mac_addr(struct hnae3_handle *handle, u8 *p)
ether_addr_copy(p, hdev->hw.mac.mac_addr); ether_addr_copy(p, hdev->hw.mac.mac_addr);
} }
static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p) static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p,
bool is_first)
{ {
const unsigned char *new_addr = (const unsigned char *)p; const unsigned char *new_addr = (const unsigned char *)p;
struct hclge_vport *vport = hclge_get_vport(handle); struct hclge_vport *vport = hclge_get_vport(handle);
...@@ -4395,11 +4396,9 @@ static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p) ...@@ -4395,11 +4396,9 @@ static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p)
return -EINVAL; return -EINVAL;
} }
ret = hclge_rm_uc_addr(handle, hdev->hw.mac.mac_addr); if (!is_first && hclge_rm_uc_addr(handle, hdev->hw.mac.mac_addr))
if (ret)
dev_warn(&hdev->pdev->dev, dev_warn(&hdev->pdev->dev,
"remove old uc mac address fail, ret =%d.\n", "remove old uc mac address fail.\n");
ret);
ret = hclge_add_uc_addr(handle, new_addr); ret = hclge_add_uc_addr(handle, new_addr);
if (ret) { if (ret) {
...@@ -4407,12 +4406,10 @@ static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p) ...@@ -4407,12 +4406,10 @@ static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p)
"add uc mac address fail, ret =%d.\n", "add uc mac address fail, ret =%d.\n",
ret); ret);
ret = hclge_add_uc_addr(handle, hdev->hw.mac.mac_addr); if (!is_first &&
if (ret) { hclge_add_uc_addr(handle, hdev->hw.mac.mac_addr))
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"restore uc mac address fail, ret =%d.\n", "restore uc mac address fail.\n");
ret);
}
return -EIO; return -EIO;
} }
......
...@@ -196,6 +196,8 @@ static int hclge_set_vf_uc_mac_addr(struct hclge_vport *vport, ...@@ -196,6 +196,8 @@ static int hclge_set_vf_uc_mac_addr(struct hclge_vport *vport,
hclge_rm_uc_addr_common(vport, old_addr); hclge_rm_uc_addr_common(vport, old_addr);
status = hclge_add_uc_addr_common(vport, mac_addr); status = hclge_add_uc_addr_common(vport, mac_addr);
if (status)
hclge_add_uc_addr_common(vport, old_addr);
} else if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_UC_ADD) { } else if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_UC_ADD) {
status = hclge_add_uc_addr_common(vport, mac_addr); status = hclge_add_uc_addr_common(vport, mac_addr);
} else if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_UC_REMOVE) { } else if (mbx_req->msg[1] == HCLGE_MBX_MAC_VLAN_UC_REMOVE) {
......
...@@ -734,20 +734,24 @@ static void hclgevf_get_mac_addr(struct hnae3_handle *handle, u8 *p) ...@@ -734,20 +734,24 @@ static void hclgevf_get_mac_addr(struct hnae3_handle *handle, u8 *p)
ether_addr_copy(p, hdev->hw.mac.mac_addr); ether_addr_copy(p, hdev->hw.mac.mac_addr);
} }
static int hclgevf_set_mac_addr(struct hnae3_handle *handle, void *p) static int hclgevf_set_mac_addr(struct hnae3_handle *handle, void *p,
bool is_first)
{ {
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle); struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
u8 *old_mac_addr = (u8 *)hdev->hw.mac.mac_addr; u8 *old_mac_addr = (u8 *)hdev->hw.mac.mac_addr;
u8 *new_mac_addr = (u8 *)p; u8 *new_mac_addr = (u8 *)p;
u8 msg_data[ETH_ALEN * 2]; u8 msg_data[ETH_ALEN * 2];
u16 subcode;
int status; int status;
ether_addr_copy(msg_data, new_mac_addr); ether_addr_copy(msg_data, new_mac_addr);
ether_addr_copy(&msg_data[ETH_ALEN], old_mac_addr); ether_addr_copy(&msg_data[ETH_ALEN], old_mac_addr);
subcode = is_first ? HCLGE_MBX_MAC_VLAN_UC_ADD :
HCLGE_MBX_MAC_VLAN_UC_MODIFY;
status = hclgevf_send_mbx_msg(hdev, HCLGE_MBX_SET_UNICAST, status = hclgevf_send_mbx_msg(hdev, HCLGE_MBX_SET_UNICAST,
HCLGE_MBX_MAC_VLAN_UC_MODIFY, subcode, msg_data, ETH_ALEN * 2,
msg_data, ETH_ALEN * 2,
false, NULL, 0); false, NULL, 0);
if (!status) if (!status)
ether_addr_copy(hdev->hw.mac.mac_addr, new_mac_addr); ether_addr_copy(hdev->hw.mac.mac_addr, new_mac_addr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment