patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Lijun Ou <oulijun@huawei.com>
To: <luca.boccassi@gmail.com>, <stable@dpdk.org>
Cc: <linuxarm@huawei.com>
Subject: [dpdk-stable] [PATCH 19.11.6 04/13] net/hns3: support promiscuous and allmulticast mode for VF
Date: Fri, 13 Nov 2020 21:37:01 +0800	[thread overview]
Message-ID: <1605274630-23414-5-git-send-email-oulijun@huawei.com> (raw)
In-Reply-To: <1605274630-23414-1-git-send-email-oulijun@huawei.com>

From: Chengchang Tang <tangchengchang@huawei.com>

[ 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 <eth num> vf <vf id> 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 <tangchengchang@huawei.com>
Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
---
 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 <eth num> vf <vf id> 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


  parent reply	other threads:[~2020-11-13 13:37 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 13:36 [dpdk-stable] [PATCH 19.11.6 00/13] backport for 19.11.6 Lijun Ou
2020-11-13 13:36 ` [dpdk-stable] [PATCH 19.11.6 01/13] net/hns3: support TSO Lijun Ou
2020-11-13 13:36 ` [dpdk-stable] [PATCH 19.11.6 02/13] net/hns3: check TSO segment size during Tx Lijun Ou
2020-11-13 13:37 ` [dpdk-stable] [PATCH 19.11.6 03/13] net/hns3: fix reassembling multiple segment packets in Tx Lijun Ou
2020-11-13 13:37 ` Lijun Ou [this message]
2020-11-13 13:37 ` [dpdk-stable] [PATCH 19.11.6 05/13] net/hns3: decrease non-nearby memory access in Rx Lijun Ou
2020-11-13 13:37 ` [dpdk-stable] [PATCH 19.11.6 06/13] net/hns3: cleanup duplicated code on processing TSO in Tx Lijun Ou
2020-11-13 13:37 ` [dpdk-stable] [PATCH 19.11.6 07/13] net/hns3: fix inserted VLAN tag position " Lijun Ou
2020-11-13 13:37 ` [dpdk-stable] [PATCH 19.11.6 08/13] net/hns3: report Tx descriptor segment limitations Lijun Ou
2020-11-13 13:37 ` [dpdk-stable] [PATCH 19.11.6 09/13] net/hns3: report Rx drop packets enable configuration Lijun Ou
2020-11-13 13:37 ` [dpdk-stable] [PATCH 19.11.6 10/13] net/hns3: report Rx free threshold Lijun Ou
2020-11-13 13:37 ` [dpdk-stable] [PATCH 19.11.6 11/13] net/hns3: reduce address calculation in Rx Lijun Ou
2020-11-13 13:37 ` [dpdk-stable] [PATCH 19.11.6 12/13] net/hns3: fix Tx checksum outer header prepare Lijun Ou
2020-11-13 13:37 ` [dpdk-stable] [PATCH 19.11.6 13/13] net/hns3: fix Tx checksum with fixed header length Lijun Ou
2020-11-23 15:52 ` [dpdk-stable] [PATCH 19.11.6 00/13] backport for 19.11.6 Luca Boccassi
2020-11-24 14:27   ` oulijun
2020-11-24 15:35     ` Luca Boccassi
2020-11-25  3:24 ` [dpdk-stable] [PATCH v2 19.11.6 0/7] " Lijun Ou
2020-11-25  3:24   ` [dpdk-stable] [PATCH v2 19.11.6 1/7] net/hns3: fix reassembling multiple segment packets in Tx Lijun Ou
2020-11-25  3:24   ` [dpdk-stable] [PATCH v2 19.11.6 2/7] net/hns3: decrease non-nearby memory access in Rx Lijun Ou
2020-11-25  3:24   ` [dpdk-stable] [PATCH v2 19.11.6 3/7] net/hns3: report Tx descriptor segment limitations Lijun Ou
2020-11-25  9:16     ` Luca Boccassi
2020-11-25 10:59       ` oulijun
2020-11-25  3:24   ` [dpdk-stable] [PATCH v2 19.11.6 4/7] net/hns3: report Rx drop packets enable configuration Lijun Ou
2020-11-25  3:24   ` [dpdk-stable] [PATCH v2 19.11.6 5/7] net/hns3: report Rx free threshold Lijun Ou
2020-11-25  3:24   ` [dpdk-stable] [PATCH v2 19.11.6 6/7] net/hns3: reduce address calculation in Rx Lijun Ou
2020-11-25  3:24   ` [dpdk-stable] [PATCH v2 19.11.6 7/7] net/hns3: fix TX checksum with fix header length Lijun Ou
2020-11-25 10:58   ` [dpdk-stable] [PATCH v3 19.11.6 0/6] backport for 19.11.6 Lijun Ou
2020-11-25 10:58     ` [dpdk-stable] [PATCH v3 19.11.6 1/6] net/hns3: fix reassembling multiple segment packets in Tx Lijun Ou
2020-11-25 10:58     ` [dpdk-stable] [PATCH v3 19.11.6 2/6] net/hns3: decrease non-nearby memory access in Rx Lijun Ou
2020-11-25 10:58     ` [dpdk-stable] [PATCH v3 19.11.6 3/6] net/hns3: report Rx drop packets enable configuration Lijun Ou
2020-11-25 10:58     ` [dpdk-stable] [PATCH v3 19.11.6 4/6] net/hns3: report Rx free threshold Lijun Ou
2020-11-25 10:58     ` [dpdk-stable] [PATCH v3 19.11.6 5/6] net/hns3: reduce address calculation in Rx Lijun Ou
2020-11-25 10:58     ` [dpdk-stable] [PATCH v3 19.11.6 6/6] net/hns3: fix TX checksum with fix header length Lijun Ou
2020-11-25 11:15     ` [dpdk-stable] [PATCH v4 19.11.6 0/6] backport for 19.11.6 Lijun Ou
2020-11-25 11:15       ` [dpdk-stable] [PATCH v4 19.11.6 1/6] net/hns3: fix reassembling multiple segment packets in Tx Lijun Ou
2020-11-25 11:15       ` [dpdk-stable] [PATCH v4 19.11.6 2/6] net/hns3: decrease non-nearby memory access in Rx Lijun Ou
2020-11-25 11:15       ` [dpdk-stable] [PATCH v4 19.11.6 3/6] net/hns3: report Rx drop packets enable configuration Lijun Ou
2020-11-25 11:15       ` [dpdk-stable] [PATCH v4 19.11.6 4/6] net/hns3: report Rx free threshold Lijun Ou
2020-11-25 11:15       ` [dpdk-stable] [PATCH v4 19.11.6 5/6] net/hns3: reduce address calculation in Rx Lijun Ou
2020-11-25 11:15       ` [dpdk-stable] [PATCH v4 19.11.6 6/6] net/hns3: fix TX checksum with fix header length Lijun Ou
2020-11-26  9:21       ` [dpdk-stable] [PATCH v4 19.11.6 0/6] backport for 19.11.6 Luca Boccassi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1605274630-23414-5-git-send-email-oulijun@huawei.com \
    --to=oulijun@huawei.com \
    --cc=linuxarm@huawei.com \
    --cc=luca.boccassi@gmail.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).