From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8CC61A09E0 for ; Fri, 13 Nov 2020 14:37:05 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 290E3C8C6; Fri, 13 Nov 2020 14:37:01 +0100 (CET) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by dpdk.org (Postfix) with ESMTP id 16250C88E for ; Fri, 13 Nov 2020 14:36:58 +0100 (CET) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CXfdQ1fbcz76P1 for ; Fri, 13 Nov 2020 21:36:42 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Fri, 13 Nov 2020 21:36:44 +0800 From: Lijun Ou To: , CC: Date: Fri, 13 Nov 2020 21:37:01 +0800 Message-ID: <1605274630-23414-5-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1605274630-23414-1-git-send-email-oulijun@huawei.com> References: <1605274630-23414-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-stable] [PATCH 19.11.6 04/13] net/hns3: support promiscuous and allmulticast mode for VF X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" From: Chengchang Tang [ upstream commit 40486d38496241711955fc752ff4a6db4c89da7f ] Currently, we only support VF device is bound to vfio_pci or igb_uio and then driven by DPDK driver when PF is driven by kernel mode hns3 ethdev driver, VF is not supported when PF is driven by hns3 DPDK driver. This patch adds promiscuous and allmulticast mode support for hns3 VF PMD driver. 1) The promiscuous/allmulticast mode can be configured successfully only based on the trusted VF device. If based on the non trusted VF device, configuring promiscuous/allmulticast mode will fail. The hns3 VF device can be configured as trusted device by hns3 PF kernel ethdev driver on the host by "ip link set vf turst on" command. 2) After the promiscuous mode is configured successfully, hns3 VF PMD driver can receive the ingress and outgoing traffic. In the words, all the ingress packets, all the packets sent from the PF and other VFs on the same physical port. 3) Note: Because of the hardware constraints, By default vlan filter is enabled and couldn't be turned off based on VF device, so vlan filter is still effective even in promiscuous mode. If upper applications don't call rte_eth_dev_vlan_filter API function to set vlan based on VF device, hns3 VF PMD driver will can't receive the packets with vlan tag in promiscuous mode. Signed-off-by: Chengchang Tang Signed-off-by: Wei Hu (Xavier) --- doc/guides/nics/features/hns3_vf.ini | 2 + drivers/net/hns3/hns3_ethdev_vf.c | 117 +++++++++++++++++++++++++++++++++-- drivers/net/hns3/hns3_mbx.c | 23 +++++++ drivers/net/hns3/hns3_mbx.h | 2 + 4 files changed, 139 insertions(+), 5 deletions(-) diff --git a/doc/guides/nics/features/hns3_vf.ini b/doc/guides/nics/features/hns3_vf.ini index e4e7738..80773ac 100644 --- a/doc/guides/nics/features/hns3_vf.ini +++ b/doc/guides/nics/features/hns3_vf.ini @@ -9,6 +9,8 @@ Rx interrupt = Y MTU update = Y Jumbo frame = Y TSO = Y +Promiscuous mode = Y +Allmulticast mode = Y Unicast MAC filter = Y Multicast MAC filter = Y RSS hash = Y diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c index 736d8a7..5663a58 100644 --- a/drivers/net/hns3/hns3_ethdev_vf.c +++ b/drivers/net/hns3/hns3_ethdev_vf.c @@ -566,7 +566,8 @@ hns3vf_configure_all_mc_mac_addr(struct hns3_adapter *hns, bool del) } static int -hns3vf_set_promisc_mode(struct hns3_hw *hw, bool en_bc_pmc) +hns3vf_set_promisc_mode(struct hns3_hw *hw, bool en_bc_pmc, + bool en_uc_pmc, bool en_mc_pmc) { struct hns3_mbx_vf_to_pf_cmd *req; struct hns3_cmd_desc desc; @@ -574,18 +575,116 @@ hns3vf_set_promisc_mode(struct hns3_hw *hw, bool en_bc_pmc) req = (struct hns3_mbx_vf_to_pf_cmd *)desc.data; + /* + * The hns3 VF PMD driver depends on the hns3 PF kernel ethdev driver, + * so there are some features for promiscuous/allmulticast mode in hns3 + * VF PMD driver as below: + * 1. The promiscuous/allmulticast mode can be configured successfully + * only based on the trusted VF device. If based on the non trusted + * VF device, configuring promiscuous/allmulticast mode will fail. + * The hns3 VF device can be confiruged as trusted device by hns3 PF + * kernel ethdev driver on the host by the following command: + * "ip link set vf turst on" + * 2. After the promiscuous mode is configured successfully, hns3 VF PMD + * driver can receive the ingress and outgoing traffic. In the words, + * all the ingress packets, all the packets sent from the PF and + * other VFs on the same physical port. + * 3. Note: Because of the hardware constraints, By default vlan filter + * is enabled and couldn't be turned off based on VF device, so vlan + * filter is still effective even in promiscuous mode. If upper + * applications don't call rte_eth_dev_vlan_filter API function to + * set vlan based on VF device, hns3 VF PMD driver will can't receive + * the packets with vlan tag in promiscuoue mode. + */ hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MBX_VF_TO_PF, false); req->msg[0] = HNS3_MBX_SET_PROMISC_MODE; req->msg[1] = en_bc_pmc ? 1 : 0; + req->msg[2] = en_uc_pmc ? 1 : 0; + req->msg[3] = en_mc_pmc ? 1 : 0; ret = hns3_cmd_send(hw, &desc, 1); if (ret) - hns3_err(hw, "Set promisc mode fail, status is %d", ret); + hns3_err(hw, "Set promisc mode fail, ret = %d", ret); + + return ret; +} + +static int +hns3vf_dev_promiscuous_enable(struct rte_eth_dev *dev) +{ + struct hns3_adapter *hns = dev->data->dev_private; + struct hns3_hw *hw = &hns->hw; + int ret; + + ret = hns3vf_set_promisc_mode(hw, true, true, true); + if (ret) + hns3_err(hw, "Failed to enable promiscuous mode, ret = %d", + ret); + return ret; +} + +static int +hns3vf_dev_promiscuous_disable(struct rte_eth_dev *dev) +{ + bool allmulti = dev->data->all_multicast ? true : false; + struct hns3_adapter *hns = dev->data->dev_private; + struct hns3_hw *hw = &hns->hw; + int ret; + + ret = hns3vf_set_promisc_mode(hw, true, false, allmulti); + if (ret) + hns3_err(hw, "Failed to disable promiscuous mode, ret = %d", + ret); + return ret; +} + +static int +hns3vf_dev_allmulticast_enable(struct rte_eth_dev *dev) +{ + struct hns3_adapter *hns = dev->data->dev_private; + struct hns3_hw *hw = &hns->hw; + int ret; + + if (dev->data->promiscuous) + return 0; + + ret = hns3vf_set_promisc_mode(hw, true, false, true); + if (ret) + hns3_err(hw, "Failed to enable allmulticast mode, ret = %d", + ret); + return ret; +} + +static int +hns3vf_dev_allmulticast_disable(struct rte_eth_dev *dev) +{ + struct hns3_adapter *hns = dev->data->dev_private; + struct hns3_hw *hw = &hns->hw; + int ret; + + if (dev->data->promiscuous) + return 0; + ret = hns3vf_set_promisc_mode(hw, true, false, false); + if (ret) + hns3_err(hw, "Failed to disable allmulticast mode, ret = %d", + ret); return ret; } static int +hns3vf_restore_promisc(struct hns3_adapter *hns) +{ + struct hns3_hw *hw = &hns->hw; + bool allmulti = hw->data->all_multicast ? true : false; + + if (hw->data->promiscuous) + return hns3vf_set_promisc_mode(hw, true, true, true); + + return hns3vf_set_promisc_mode(hw, true, false, allmulti); +} + +static int hns3vf_bind_ring_with_vector(struct hns3_hw *hw, uint8_t vector_id, bool mmap, enum hns3_ring_type queue_type, uint16_t queue_id) @@ -1390,7 +1489,7 @@ hns3vf_init_hardware(struct hns3_adapter *hns) uint16_t mtu = hw->data->mtu; int ret; - ret = hns3vf_set_promisc_mode(hw, true); + ret = hns3vf_set_promisc_mode(hw, true, false, false); if (ret) return ret; @@ -1432,7 +1531,7 @@ hns3vf_init_hardware(struct hns3_adapter *hns) return 0; err_init_hardware: - (void)hns3vf_set_promisc_mode(hw, false); + (void)hns3vf_set_promisc_mode(hw, false, false, false); return ret; } @@ -1539,7 +1638,7 @@ hns3vf_uninit_vf(struct rte_eth_dev *eth_dev) hns3_rss_uninit(hns); (void)hns3vf_set_alive(hw, false); - (void)hns3vf_set_promisc_mode(hw, false); + (void)hns3vf_set_promisc_mode(hw, false, false, false); hns3vf_disable_irq0(hw); rte_intr_disable(&pci_dev->intr_handle); hns3_intr_unregister(&pci_dev->intr_handle, hns3vf_interrupt_handler, @@ -2044,6 +2143,10 @@ hns3vf_restore_conf(struct hns3_adapter *hns) if (ret) goto err_mc_mac; + ret = hns3vf_restore_promisc(hns); + if (ret) + goto err_vlan_table; + ret = hns3vf_restore_vlan_conf(hns); if (ret) goto err_vlan_table; @@ -2198,6 +2301,10 @@ static const struct eth_dev_ops hns3vf_eth_dev_ops = { .dev_stop = hns3vf_dev_stop, .dev_close = hns3vf_dev_close, .mtu_set = hns3vf_dev_mtu_set, + .promiscuous_enable = hns3vf_dev_promiscuous_enable, + .promiscuous_disable = hns3vf_dev_promiscuous_disable, + .allmulticast_enable = hns3vf_dev_allmulticast_enable, + .allmulticast_disable = hns3vf_dev_allmulticast_disable, .stats_get = hns3_stats_get, .stats_reset = hns3_stats_reset, .xstats_get = hns3_dev_xstats_get, diff --git a/drivers/net/hns3/hns3_mbx.c b/drivers/net/hns3/hns3_mbx.c index 64996c9..34c8c68 100644 --- a/drivers/net/hns3/hns3_mbx.c +++ b/drivers/net/hns3/hns3_mbx.c @@ -326,6 +326,21 @@ hns3_handle_link_change_event(struct hns3_hw *hw, hns3_update_link_status(hw); } +static void +hns3_handle_promisc_info(struct hns3_hw *hw, uint16_t promisc_en) +{ + if (!promisc_en) { + /* + * When promisc/allmulti mode is closed by the hns3 PF kernel + * ethdev driver for untrusted, modify VF's related status. + */ + hns3_warn(hw, "Promisc mode will be closed by host for being " + "untrusted."); + hw->data->promiscuous = 0; + hw->data->all_multicast = 0; + } +} + void hns3_dev_handle_mbx_msg(struct hns3_hw *hw) { @@ -384,6 +399,14 @@ hns3_dev_handle_mbx_msg(struct hns3_hw *hw) case HNS3_MBX_PUSH_LINK_STATUS: hns3_handle_link_change_event(hw, req); break; + case HNS3_MBX_PUSH_PROMISC_INFO: + /* + * When the trust status of VF device changed by the + * hns3 PF kernel driver, VF driver will receive this + * mailbox message from PF driver. + */ + hns3_handle_promisc_info(hw, req->msg[1]); + break; default: hns3_err(hw, "VF received unsupported(%d) mbx msg from PF", diff --git a/drivers/net/hns3/hns3_mbx.h b/drivers/net/hns3/hns3_mbx.h index b01eaac..d6d70f6 100644 --- a/drivers/net/hns3/hns3_mbx.h +++ b/drivers/net/hns3/hns3_mbx.h @@ -40,6 +40,8 @@ enum HNS3_MBX_OPCODE { HNS3_MBX_SET_MTU, /* (VF -> PF) set mtu */ HNS3_MBX_GET_QID_IN_PF, /* (VF -> PF) get queue id in pf */ + HNS3_MBX_PUSH_PROMISC_INFO = 36, /* (PF -> VF) push vf promisc info */ + HNS3_MBX_HANDLE_VF_TBL = 38, /* (VF -> PF) store/clear hw cfg tbl */ HNS3_MBX_GET_RING_VECTOR_MAP, /* (VF -> PF) get ring-to-vector map */ HNS3_MBX_PUSH_LINK_STATUS = 201, /* (IMP -> PF) get port link status */ -- 2.7.4