From: Huazhong Tan tanhuazhong@huawei.com
driver inclusion category: bugfix bugzilla: NA CVE: NA
This patch merges back some code from net-next about below patches: net: hns3: add support for configuring VF MAC from the host net: hns3: add support for spoof check setting net: hns3: add support for setting VF trust net: hns3: add support for configuring bandwidth of VF on the host net: hns3: add support for setting VF link status on the host net: hns3: support tx-scatter-gather-fraglist feature net: hns3: fix spelling mistake "undeflow" -> "underflow"
Signed-off-by: Huazhong Tan tanhuazhong@huawei.com Reviewed-by: Peng Li lipeng321@huawei.com Reviewed-by: Zhong Zhaohui zhongzhaohui@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/net/ethernet/hisilicon/hns3/hnae3.h | 8 +- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 59 +++-- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 2 +- .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 252 ++++++++++----------- .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h | 16 +- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 33 ++- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c | 2 +- .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 12 - 8 files changed, 200 insertions(+), 184 deletions(-)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethernet/hisilicon/hns3/hnae3.h index ad1274e..c7ac3f8 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h @@ -364,6 +364,10 @@ struct hnae3_ae_dev { * Enable/disable HW GRO * add_arfs_entry * Check the 5-tuples of flow, and create flow director rule + * get_vf_config + * Get the VF configuration setting by the host + * set_vf_link_state + * Set VF link status * set_vf_spoofchk * Enable/disable spoof check for specified vf * set_vf_trust @@ -371,6 +375,8 @@ struct hnae3_ae_dev { * it can enable promisc mode * set_vf_rate * Set the max tx rate of specified vf. + * set_vf_mac + * Configure the default MAC for specified VF */ struct hnae3_ae_ops { int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev); @@ -551,10 +557,10 @@ struct hnae3_ae_ops { int link_state); int (*set_vf_spoofchk)(struct hnae3_handle *handle, int vf, bool enable); - int (*set_vf_mac)(struct hnae3_handle *handle, int vf, u8 *p); int (*set_vf_trust)(struct hnae3_handle *handle, int vf, bool enable); int (*set_vf_rate)(struct hnae3_handle *handle, int vf, int min_tx_rate, int max_tx_rate, bool force); + int (*set_vf_mac)(struct hnae3_handle *handle, int vf, u8 *p); };
struct hnae3_dcb_ops { diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 2b22c0e..573cc0b 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -1259,15 +1259,13 @@ static bool hns3_skb_need_linearized(struct sk_buff *skb, unsigned int *bd_size, for (i = 0; i < HNS3_MAX_NON_TSO_BD_NUM - 1U; i++) tot_len += bd_size[i];
- /* ensure the first 8 frags is greater than mss + header the first - * 7 frags is greater than mss. - */ + /* ensure the first 8 frags is greater than mss + header */ if (tot_len + bd_size[HNS3_MAX_NON_TSO_BD_NUM - 1U] < skb_shinfo(skb)->gso_size + hns3_gso_hdr_len(skb)) return true;
- /* ensure the remaining continuous 7 buffer is greater than mss - * except the last 7 frags. + /* ensure every continuous 7 buffer is greater than mss + * except the last one. */ for (i = 0; i < bd_num - HNS3_MAX_NON_TSO_BD_NUM; i++) { tot_len -= bd_size[i]; @@ -1494,6 +1492,16 @@ static int hns3_nic_net_set_mac_address(struct net_device *netdev, void *p) return 0; }
+ /* For VF device, if there is a perm_addr, then the user will not + * be allowed to change the address. + */ + if (!hns3_is_phys_func(h->pdev) && + !is_zero_ether_addr(netdev->perm_addr)) { + netdev_err(netdev, "has permanent MAC %pM, user MAC %pM not allow\n", + netdev->perm_addr, mac_addr->sa_data); + return -EPERM; + } + ret = h->ae_algo->ops->set_mac_addr(h, mac_addr->sa_data, false); if (ret) { netdev_err(netdev, "set_mac_address fail, ret=%d!\n", ret); @@ -2007,6 +2015,18 @@ static int hns3_nic_set_vf_link_state(struct net_device *ndev, int vf, return h->ae_algo->ops->set_vf_link_state(h, vf, link_state); }
+static int hns3_nic_set_vf_rate(struct net_device *ndev, int vf, + int min_tx_rate, int max_tx_rate) +{ + struct hnae3_handle *h = hns3_get_handle(ndev); + + if (!h->ae_algo->ops->set_vf_rate) + return -EOPNOTSUPP; + + return h->ae_algo->ops->set_vf_rate(h, vf, min_tx_rate, max_tx_rate, + false); +} + static int hns3_nic_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac) { struct hnae3_handle *h = hns3_get_handle(netdev); @@ -2014,28 +2034,16 @@ static int hns3_nic_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac) if (!h->ae_algo->ops->set_vf_mac) return -EOPNOTSUPP;
- if (is_broadcast_ether_addr(mac) || - is_multicast_ether_addr(mac)) { + if (is_multicast_ether_addr(mac)) { netdev_err(netdev, - "Set VF MAC error! invalid mac:%pM.\n", mac); + "Invalid MAC:%pM specified. Could not set MAC\n", + mac); return -EINVAL; }
return h->ae_algo->ops->set_vf_mac(h, vf_id, mac); }
-static int hns3_nic_set_vf_rate(struct net_device *ndev, int vf, - int min_tx_rate, int max_tx_rate) -{ - struct hnae3_handle *h = hns3_get_handle(ndev); - - if (!h->ae_algo->ops->set_vf_rate) - return -EOPNOTSUPP; - - return h->ae_algo->ops->set_vf_rate(h, vf, min_tx_rate, max_tx_rate, - false); -} - struct net_device_ops hns3_nic_netdev_ops = { .ndo_open = hns3_nic_net_open, .ndo_stop = hns3_nic_net_stop, @@ -2061,8 +2069,8 @@ struct net_device_ops hns3_nic_netdev_ops = { #endif .ndo_get_vf_config = hns3_nic_get_vf_config, .ndo_set_vf_link_state = hns3_nic_set_vf_link_state, - .ndo_set_vf_mac = hns3_nic_set_vf_mac, .ndo_set_vf_rate = hns3_nic_set_vf_rate, + .ndo_set_vf_mac = hns3_nic_set_vf_mac, };
bool hns3_is_phys_func(struct pci_dev *pdev) @@ -3934,16 +3942,17 @@ static int hns3_init_mac_addr(struct net_device *netdev) u8 mac_addr_temp[ETH_ALEN]; int ret = 0;
- if (h->ae_algo->ops->get_mac_addr) { + if (h->ae_algo->ops->get_mac_addr) h->ae_algo->ops->get_mac_addr(h, mac_addr_temp); - ether_addr_copy(netdev->dev_addr, mac_addr_temp); - }
/* Check if the MAC address is valid, if not get a random one */ - if (!is_valid_ether_addr(netdev->dev_addr)) { + if (!is_valid_ether_addr(mac_addr_temp)) { eth_hw_addr_random(netdev); dev_warn(priv->dev, "using random MAC address %pM\n", netdev->dev_addr); + } else { + ether_addr_copy(netdev->dev_addr, mac_addr_temp); + ether_addr_copy(netdev->perm_addr, mac_addr_temp); }
if (h->ae_algo->ops->set_mac_addr) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c index 3af3b06..d017d9a 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c @@ -98,7 +98,7 @@ .reset_level = HNAE3_GLOBAL_RESET }, { .int_msk = BIT(1), .msg = "rx_stp_fifo_overflow", .reset_level = HNAE3_GLOBAL_RESET }, - { .int_msk = BIT(2), .msg = "rx_stp_fifo_undeflow", + { .int_msk = BIT(2), .msg = "rx_stp_fifo_underflow", .reset_level = HNAE3_GLOBAL_RESET }, { .int_msk = BIT(3), .msg = "tx_buf_overflow", .reset_level = HNAE3_GLOBAL_RESET }, diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index 2f0025a..5e21b38 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -65,8 +65,6 @@ static void hclge_rfs_filter_expire(struct hclge_dev *hdev); static void hclge_clear_arfs_rules(struct hnae3_handle *handle); static int hclge_set_default_loopback(struct hclge_dev *hdev); -static int hclge_resume_vf_rate(struct hclge_dev *hdev); -static void hclge_reset_vf_rate(struct hclge_dev *hdev);
static void hclge_sync_mac_table(struct hclge_dev *hdev); static int hclge_restore_hw_table(struct hclge_dev *hdev); @@ -1708,7 +1706,7 @@ static int hclge_alloc_vport(struct hclge_dev *hdev) for (i = 0; i < num_vport; i++) { vport->back = hdev; vport->vport_id = i; - vport->link_state = IFLA_VF_LINK_STATE_AUTO; + vport->vf_info.link_state = IFLA_VF_LINK_STATE_AUTO; vport->mps = HCLGE_MAC_DEFAULT_FRAME; vport->port_base_vlan_cfg.state = HNAE3_PORT_BASE_VLAN_DISABLE; vport->rxvlan_cfg.rx_vlan_offload_en = true; @@ -2945,7 +2943,7 @@ static struct hclge_vport *hclge_get_vf_vport(struct hclge_dev *hdev, int vf) return NULL; }
- /* vf start from 1 in vport */ + /* VF start from 1 in vport */ vf += HCLGE_VF_VPORT_START_NUM; return &hdev->vport[vf]; } @@ -2961,15 +2959,15 @@ static int hclge_get_vf_config(struct hnae3_handle *handle, int vf, return -EINVAL;
ivf->vf = vf; - ivf->linkstate = vport->link_state; - ivf->spoofchk = vport->spoofchk; - ivf->trusted = vport->trusted; + ivf->linkstate = vport->vf_info.link_state; + ivf->spoofchk = vport->vf_info.spoofchk; + ivf->trusted = vport->vf_info.trusted; ivf->min_tx_rate = 0; - ivf->max_tx_rate = vport->max_tx_rate; + ivf->max_tx_rate = vport->vf_info.max_tx_rate; ivf->vlan = vport->port_base_vlan_cfg.vlan_info.vlan_tag; ivf->vlan_proto = htons(vport->port_base_vlan_cfg.vlan_info.vlan_proto); ivf->qos = vport->port_base_vlan_cfg.vlan_info.qos; - ether_addr_copy(ivf->mac, vport->mac); + ether_addr_copy(ivf->mac, vport->vf_info.mac);
return 0; } @@ -2984,7 +2982,7 @@ static int hclge_set_vf_link_state(struct hnae3_handle *handle, int vf, if (!vport) return -EINVAL;
- vport->link_state = link_state; + vport->vf_info.link_state = link_state;
return 0; } @@ -8100,20 +8098,14 @@ static bool hclge_check_vf_mac_exist(struct hclge_vport *vport, int vf_idx, req.egress_port = cpu_to_le16(egress_port); hclge_prepare_mac_addr(&req, mac_addr, false);
- if (hclge_lookup_mac_vlan_tbl(vport, &req, &desc, false) != -ENOENT) { - dev_info(&hdev->pdev->dev, "Specified MAC(=%pM) exists!\n", - mac_addr); + if (hclge_lookup_mac_vlan_tbl(vport, &req, &desc, false) != -ENOENT) return true; - }
+ vf_idx += HCLGE_VF_VPORT_START_NUM; for (i = hdev->num_vmdq_vport + 1; i < hdev->num_alloc_vport; i++) if (i != vf_idx && - ether_addr_equal(mac_addr, hdev->vport[i].mac)) { - dev_info(&hdev->pdev->dev, - "Specified MAC(=%pM) is same as vport%d, no change committed!\n", - mac_addr, i); + ether_addr_equal(mac_addr, hdev->vport[i].vf_info.mac)) return true; - }
return false; } @@ -8124,27 +8116,29 @@ static int hclge_set_vf_mac(struct hnae3_handle *handle, int vf, struct hclge_vport *vport = hclge_get_vport(handle); struct hclge_dev *hdev = vport->back;
- if (hclge_check_vf_mac_exist(vport, vf + HCLGE_VF_VPORT_START_NUM, - mac_addr)) - return -EEXIST; - vport = hclge_get_vf_vport(hdev, vf); if (!vport) return -EINVAL;
- if (ether_addr_equal(mac_addr, vport->mac)) { + if (ether_addr_equal(mac_addr, vport->vf_info.mac)) { dev_info(&hdev->pdev->dev, "Specified MAC(=%pM) is same as before, no change committed!\n", - vport->mac); + mac_addr); return 0; }
- ether_addr_copy(vport->mac, mac_addr); + if (hclge_check_vf_mac_exist(vport, vf, mac_addr)) { + dev_err(&hdev->pdev->dev, "Specified MAC(=%pM) exists!\n", + mac_addr); + return -EEXIST; + } + + ether_addr_copy(vport->vf_info.mac, mac_addr); dev_info(&hdev->pdev->dev, - "VF %d has been set to %pM. Please reload/reset VF\n", - vf, vport->mac); + "MAC of VF %d has been set to %pM, and it will be reinitialized!\n", + vf, mac_addr);
- return 0; + return hclge_inform_reset_assert_to_vf(vport); }
static int hclge_add_mgr_tbl(struct hclge_dev *hdev, @@ -8404,7 +8398,7 @@ static int hclge_set_vf_vlan_common(struct hclge_dev *hdev, u16 vfid, * new vlan, because tx packets with these vlan id will be dropped. */ if (test_bit(vfid, hdev->vf_vlan_full) && !is_kill) { - if (vport->spoofchk && vlan) { + if (vport->vf_info.spoofchk && vlan) { dev_err(&hdev->pdev->dev, "Can't add vlan due to spoof check is on and vf vlan table is full\n"); return -EPERM; @@ -10240,7 +10234,7 @@ static int hclge_set_vf_spoofchk(struct hnae3_handle *handle, int vf, if (!vport) return -EINVAL;
- if (vport->spoofchk == new_spoofchk) + if (vport->vf_info.spoofchk == new_spoofchk) return 0;
if (enable && test_bit(vport->vport_id, hdev->vf_vlan_full)) @@ -10256,7 +10250,7 @@ static int hclge_set_vf_spoofchk(struct hnae3_handle *handle, int vf, if (ret) return ret;
- vport->spoofchk = new_spoofchk; + vport->vf_info.spoofchk = new_spoofchk; return 0; }
@@ -10272,12 +10266,13 @@ static int hclge_reset_vport_spoofchk(struct hclge_dev *hdev) /* resume the vf spoof check state after reset */ for (i = 0; i < hdev->num_alloc_vport; i++) { ret = hclge_set_vf_spoofchk_hw(hdev, vport->vport_id, - vport->spoofchk); + vport->vf_info.spoofchk); if (ret) return ret;
vport++; } + return 0; }
@@ -10293,21 +10288,113 @@ static int hclge_set_vf_trust(struct hnae3_handle *handle, int vf, bool enable) if (!vport) return -EINVAL;
- if (vport->trusted == new_trusted) + if (vport->vf_info.trusted == new_trusted) return 0;
/* Disable promisc mode for VF if it is not trusted any more. */ - if (!enable && vport->promisc_enable) { + if (!enable && vport->vf_info.promisc_enable) { en_bc_pmc = hdev->pdev->revision != 0x20; ret = hclge_set_vport_promisc_mode(vport, false, false, en_bc_pmc); if (ret) return ret; - vport->promisc_enable = 0; + vport->vf_info.promisc_enable = 0; hclge_inform_vf_promisc_info(vport); }
- vport->trusted = new_trusted; + vport->vf_info.trusted = new_trusted; + + return 0; +} + +static void hclge_reset_vf_rate(struct hclge_dev *hdev) +{ + int ret; + int vf; + + /* reset vf rate to default value */ + for (vf = HCLGE_VF_VPORT_START_NUM; vf < hdev->num_alloc_vport; vf++) { + struct hclge_vport *vport = &hdev->vport[vf]; + + vport->vf_info.max_tx_rate = 0; + ret = hclge_tm_qs_shaper_cfg(vport, vport->vf_info.max_tx_rate); + if (ret) + dev_err(&hdev->pdev->dev, + "vf%d failed to reset to default, ret=%d\n", + vf - HCLGE_VF_VPORT_START_NUM, ret); + } +} + +static int hclge_vf_rate_param_check(struct hclge_dev *hdev, int vf, + int min_tx_rate, int max_tx_rate) +{ + if (min_tx_rate != 0 || + max_tx_rate < 0 || max_tx_rate > hdev->hw.mac.max_speed) { + dev_err(&hdev->pdev->dev, + "min_tx_rate:%d [0], max_tx_rate:%d [0, %u]\n", + min_tx_rate, max_tx_rate, hdev->hw.mac.max_speed); + return -EINVAL; + } + + return 0; +} + +static int hclge_set_vf_rate(struct hnae3_handle *handle, int vf, + int min_tx_rate, int max_tx_rate, bool force) +{ + struct hclge_vport *vport = hclge_get_vport(handle); + struct hclge_dev *hdev = vport->back; + int ret; + + ret = hclge_vf_rate_param_check(hdev, vf, min_tx_rate, max_tx_rate); + if (ret) + return ret; + + vport = hclge_get_vf_vport(hdev, vf); + if (!vport) + return -EINVAL; + + if (!force && max_tx_rate == vport->vf_info.max_tx_rate) + return 0; + + ret = hclge_tm_qs_shaper_cfg(vport, max_tx_rate); + if (ret) + return ret; + + vport->vf_info.max_tx_rate = max_tx_rate; + + return 0; +} + +static int hclge_resume_vf_rate(struct hclge_dev *hdev) +{ + struct hnae3_handle *handle = &hdev->vport->nic; + struct hclge_vport *vport; + int ret; + int vf; + + /* resume the vf max_tx_rate after reset */ + for (vf = 0; vf < pci_num_vf(hdev->pdev); vf++) { + vport = hclge_get_vf_vport(hdev, vf); + if (!vport) + return -EINVAL; + + /* zero means max rate, after reset, firmware already set it to + * max rate, so just continue. + */ + if (!vport->vf_info.max_tx_rate) + continue; + + ret = hclge_set_vf_rate(handle, vf, 0, + vport->vf_info.max_tx_rate, true); + if (ret) { + dev_err(&hdev->pdev->dev, + "vf%d failed to resume tx_rate:%u, ret=%d\n", + vf, vport->vf_info.max_tx_rate, ret); + return ret; + } + } + return 0; }
@@ -11074,97 +11161,6 @@ static int hclge_gro_en(struct hnae3_handle *handle, bool enable) return hclge_config_gro(hdev, enable); }
-static int hclge_vf_rate_param_check(struct hclge_dev *hdev, int vf, - int min_tx_rate, int max_tx_rate) -{ - if (min_tx_rate != 0 || - max_tx_rate < 0 || max_tx_rate > hdev->hw.mac.max_speed) { - dev_err(&hdev->pdev->dev, - "min_tx_rate:%d [0], max_tx_rate:%d [0, %u]\n", - min_tx_rate, max_tx_rate, hdev->hw.mac.max_speed); - return -EINVAL; - } - - return 0; -} - -static int hclge_set_vf_rate(struct hnae3_handle *handle, int vf, - int min_tx_rate, int max_tx_rate, bool force) -{ - struct hclge_vport *vport = hclge_get_vport(handle); - struct hclge_dev *hdev = vport->back; - int ret; - - ret = hclge_vf_rate_param_check(hdev, vf, min_tx_rate, max_tx_rate); - if (ret) - return ret; - - vport = hclge_get_vf_vport(hdev, vf); - if (!vport) - return -EINVAL; - - if (!force && max_tx_rate == vport->max_tx_rate) - return 0; - - ret = hclge_tm_qs_shaper_cfg(vport, max_tx_rate); - if (ret) - return ret; - - vport->max_tx_rate = max_tx_rate; - - return 0; -} - -static int hclge_resume_vf_rate(struct hclge_dev *hdev) -{ - struct hnae3_handle *handle = &hdev->vport->nic; - struct hclge_vport *vport; - int ret; - int vf; - - /* resume the vf max_tx_rate after reset */ - for (vf = 0; vf < pci_num_vf(hdev->pdev); vf++) { - vport = hclge_get_vf_vport(hdev, vf); - if (!vport) - return -EINVAL; - - /* zero means max rate, after reset, firmware already set it to - * max rate, so just continue. - */ - if (!vport->max_tx_rate) - continue; - - ret = hclge_set_vf_rate(handle, vf, 0, vport->max_tx_rate, - true); - if (ret) { - dev_err(&hdev->pdev->dev, - "vf%d failed to resume tx_rate:%u, ret=%d\n", - vf, vport->max_tx_rate, ret); - return ret; - } - } - - return 0; -} - -static void hclge_reset_vf_rate(struct hclge_dev *hdev) -{ - int ret; - int vf; - - /* reset vf rate to default value */ - for (vf = HCLGE_VF_VPORT_START_NUM; vf < hdev->num_alloc_vport; vf++) { - struct hclge_vport *vport = &hdev->vport[vf]; - - vport->max_tx_rate = 0; - ret = hclge_tm_qs_shaper_cfg(vport, vport->max_tx_rate); - if (ret) - dev_err(&hdev->pdev->dev, - "vf%d failed to reset to default, ret=%d\n", - vf - HCLGE_VF_VPORT_START_NUM, ret); - } -} - static void hclge_sync_promisc_mode(struct hclge_dev *hdev) { struct hclge_vport *vport = &hdev->vport[0]; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h index 0040d6d..a82c6fc 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h @@ -905,6 +905,15 @@ struct hclge_port_base_vlan_config { struct hclge_vlan_info vlan_info; };
+struct hclge_vf_info { + int link_state; + u8 mac[ETH_ALEN]; + u32 spoofchk; + u32 max_tx_rate; + u32 trusted; + u16 promisc_enable; +}; + struct hclge_vport { u16 alloc_tqps; /* Allocated Tx/Rx queues */
@@ -936,16 +945,11 @@ struct hclge_vport {
unsigned long state; unsigned long last_active_jiffies; - int link_state; - u8 mac[ETH_ALEN]; int mps; /* Max packet size */
- u32 spoofchk; - u32 max_tx_rate; - u32 trusted; - u16 promisc_enable; u8 overflow_promisc_flags; u8 last_promisc_flags; + struct hclge_vf_info vf_info;
spinlock_t mac_list_lock; /* protect mac address need to add/detele */ struct list_head uc_mac_list; /* Store VF unicast table */ diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c index 7636411..8f302fa 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c @@ -240,14 +240,14 @@ static int hclge_set_vf_promisc_mode(struct hclge_vport *vport, bool en_mc = req->msg.en_mc ? true : false; int ret;
- if (!vport->trusted) { + if (!vport->vf_info.trusted) { en_uc = false; en_mc = false; }
ret = hclge_set_vport_promisc_mode(vport, en_uc, en_mc, en_bc);
- vport->promisc_enable = (en_uc || en_mc) ? 1 : 0; + vport->vf_info.promisc_enable = (en_uc || en_mc) ? 1 : 0;
return ret; } @@ -257,10 +257,10 @@ void hclge_inform_vf_promisc_info(struct hclge_vport *vport) u8 dest_vfid = (u8)vport->vport_id; u8 msg_data[2];
- memcpy(&msg_data[0], &vport->promisc_enable, sizeof(u16)); + memcpy(&msg_data[0], &vport->vf_info.promisc_enable, sizeof(u16));
- (void)hclge_send_mbx_msg(vport, msg_data, sizeof(msg_data), - HCLGE_MBX_PUSH_PROMISC_INFO, dest_vfid); + hclge_send_mbx_msg(vport, msg_data, sizeof(msg_data), + HCLGE_MBX_PUSH_PROMISC_INFO, dest_vfid); }
static int hclge_modify_vf_mac_addr(struct hclge_vport *vport, @@ -305,9 +305,19 @@ static int hclge_set_vf_uc_mac_addr(struct hclge_vport *vport, const u8 *old_addr = (const u8 *) (&mbx_req->msg.data[HCLGE_MBX_VF_OLD_MAC_ADDR_OFFSET]);
- if (!is_zero_ether_addr(vport->mac) && - !ether_addr_equal(mac_addr, vport->mac)) - return -EPERM; + /* If VF MAC has been configured by the host then it + * cannot be overridden by the MAC specified by the VM. + */ + if (!is_zero_ether_addr(vport->vf_info.mac) && + !ether_addr_equal(mac_addr, vport->vf_info.mac)) { + status = -EPERM; + goto out; + } + + if (!is_valid_ether_addr(mac_addr)) { + status = -EINVAL; + goto out; + }
if (is_zero_ether_addr(old_addr)) { status = hclge_add_uc_addr_common(vport, mac_addr); @@ -334,6 +344,8 @@ static int hclge_set_vf_uc_mac_addr(struct hclge_vport *vport, mbx_req->msg.subcode); return -EIO; } + +out: return status; }
@@ -467,7 +479,7 @@ static void hclge_get_vf_queue_info(struct hclge_vport *vport, static void hclge_get_vf_mac_addr(struct hclge_vport *vport, struct hclge_respond_to_vf_msg *resp_msg) { - ether_addr_copy(resp_msg->data, vport->mac); + ether_addr_copy(resp_msg->data, vport->vf_info.mac); resp_msg->len = ETH_ALEN; }
@@ -507,6 +519,7 @@ static int hclge_get_link_info(struct hclge_vport *vport, { #define HCLGE_VF_LINK_STATE_UP 1U #define HCLGE_VF_LINK_STATE_DOWN 0U + struct hclge_dev *hdev = vport->back; u16 link_status; u8 msg_data[8]; @@ -514,7 +527,7 @@ static int hclge_get_link_info(struct hclge_vport *vport, u16 duplex;
/* mac.link can only be 0 or 1 */ - switch (vport->link_state) { + switch (vport->vf_info.link_state) { case IFLA_VF_LINK_STATE_ENABLE: link_status = HCLGE_VF_LINK_STATE_UP; break; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c index 62b0206..fbc39a2 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c @@ -46,7 +46,7 @@ static int hclge_shaper_para_calc(u32 ir, u8 shaper_level, #define DIVISOR_CLK (1000 * 8) #define DIVISOR_IR_B_126 (126 * DIVISOR_CLK)
- const u16 tick_array[HCLGE_SHAPER_LVL_CNT] = { + static const u16 tick_array[HCLGE_SHAPER_LVL_CNT] = { 6 * 256, /* Prioriy level */ 6 * 32, /* Prioriy group level */ 6 * 8, /* Port level */ diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c index aa6541e..c61e3c1 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c @@ -1259,20 +1259,8 @@ static int hclgevf_set_mac_addr(struct hnae3_handle *handle, void *p, u8 *old_mac_addr = (u8 *)hdev->hw.mac.mac_addr; struct hclge_vf_to_pf_msg send_msg; u8 *new_mac_addr = (u8 *)p; - u8 host_mac_addr[ETH_ALEN]; int status;
- status = hclgevf_get_host_mac_addr(hdev, host_mac_addr); - if (status) - return status; - - if (!is_first && hdev->has_pf_mac) { - dev_err(&hdev->pdev->dev, - "has host VF mac %pM, user MAC %pM not allow\n", - old_mac_addr, p); - return -EPERM; - } - hclgevf_build_send_msg(&send_msg, HCLGE_MBX_SET_UNICAST, 0); send_msg.subcode = HCLGE_MBX_MAC_VLAN_UC_MODIFY; ether_addr_copy(send_msg.data, new_mac_addr);