DPDK patches and discussions
 help / color / mirror / Atom feed
From: Qiming Yang <qiming.yang@intel.com>
To: dev@dpdk.org
Cc: qi.z.zhang@intel.com, Qiming Yang <qiming.yang@intel.com>
Subject: [dpdk-dev] [PATCH 2/2] net/ice: add VLAN config for DCF
Date: Wed,  2 Sep 2020 14:38:02 +0800	[thread overview]
Message-ID: <20200902063802.102428-3-qiming.yang@intel.com> (raw)
In-Reply-To: <20200902063802.102428-1-qiming.yang@intel.com>

This patch add support for VF VLAN offload, port VLAN id set and
VLAN ethertype set in DCF.

This patch depend on base code update.

Signed-off-by: Qiming Yang <qiming.yang@intel.com>
---
 drivers/net/ice/ice_dcf.h                |   1 +
 drivers/net/ice/ice_dcf_vf_representor.c | 120 +++++++++++++++++++++++
 2 files changed, 121 insertions(+)

diff --git a/drivers/net/ice/ice_dcf.h b/drivers/net/ice/ice_dcf.h
index a44a01e90..b960cf7cf 100644
--- a/drivers/net/ice/ice_dcf.h
+++ b/drivers/net/ice/ice_dcf.h
@@ -59,6 +59,7 @@ struct ice_dcf_hw {
 	uint16_t nb_msix;
 	uint16_t rxq_map[16];
 	struct virtchnl_eth_stats eth_stats_offset;
+	struct virtchnl_dcf_vlan_offload vlan_config;
 };
 
 int ice_dcf_execute_virtchnl_cmd(struct ice_dcf_hw *hw,
diff --git a/drivers/net/ice/ice_dcf_vf_representor.c b/drivers/net/ice/ice_dcf_vf_representor.c
index ceb54ab15..53d0db85f 100644
--- a/drivers/net/ice/ice_dcf_vf_representor.c
+++ b/drivers/net/ice/ice_dcf_vf_representor.c
@@ -185,6 +185,123 @@ ice_dcf_representor_dev_info_get(struct rte_eth_dev *dev,
 	return 0;
 }
 
+static int
+ice_dcf_config_vlan_offload(struct ice_dcf_hw *hw,
+		struct virtchnl_dcf_vlan_offload *vlan_config)
+{
+	struct dcf_virtchnl_cmd args;
+	int err;
+
+	memset(&args, 0, sizeof(args));
+	args.v_op = VIRTCHNL_OP_DCF_VLAN_OFFLOAD;
+	args.req_msg = (uint8_t *)vlan_config;
+	args.req_msglen = sizeof(vlan_config);
+	err = ice_dcf_execute_virtchnl_cmd(hw, &args);
+	if (err)
+		PMD_DRV_LOG(ERR, "fail to execute command %s",
+				 "VIRTCHNL_OP_DCF_VLAN_OFFLOAD");
+	return err;
+}
+
+static int
+ice_dcf_representor_vlan_offload_set(struct rte_eth_dev *dev, int mask)
+{
+	struct ice_dcf_vf_representor *representor = dev->data->dev_private;
+	struct ice_dcf_hw *hw = &representor->adapter->real_hw;
+	struct virtchnl_dcf_vlan_offload vlan_config;
+	int ret = 0;
+
+	vlan_config.vf_id = representor->vf_id;
+
+	if (hw->vlan_config.tx_flags == VIRTCHNL_VLAN_TX_INSERT) {
+		PMD_DRV_LOG(ERR, "Please clear pvid before set vlan offload.");
+		return -EINVAL;
+	}
+
+	if (mask & ETH_VLAN_STRIP_MASK) {
+		if (hw->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN) {
+			vlan_config.type = VIRTCHNL_VLAN_OUTER_TYPE;
+			vlan_config.rx_flags = VIRTCHNL_VLAN_RX_STRIP_IN_DESC;
+			vlan_config.tx_flags = VIRTCHNL_VLAN_TX_INSERT_BY_DESC;
+		} else {
+			vlan_config.type = VIRTCHNL_VLAN_OUTER_TYPE;
+			vlan_config.rx_flags = VIRTCHNL_VLAN_RX_NO_STRIP;
+			vlan_config.tx_flags = VIRTCHNL_VLAN_TX_INSERT_BY_DESC;
+		}
+		ret = ice_dcf_config_vlan_offload(hw, &vlan_config);
+		if (ret < 0) {
+			PMD_DRV_LOG(ERR, "Failed to set vlan offload.");
+			return -EINVAL;
+		}
+	}
+
+	rte_memcpy(&hw->vlan_config, &vlan_config, sizeof(vlan_config));
+
+	return ret;
+}
+
+static int
+ice_dcf_representor_vlan_pvid_set(struct rte_eth_dev *dev,
+				  uint16_t pvid, int on)
+{
+	struct ice_dcf_vf_representor *representor = dev->data->dev_private;
+	struct ice_dcf_hw *hw = &representor->adapter->real_hw;
+	struct virtchnl_dcf_vlan_offload vlan_config;
+	int ret;
+
+	vlan_config.vf_id = representor->vf_id;
+	vlan_config.type = VIRTCHNL_VLAN_OUTER_TYPE;
+	vlan_config.vlan_id = pvid;
+	if (on) {
+		vlan_config.rx_flags = VIRTCHNL_VLAN_RX_STRIP_ONLY;
+		vlan_config.tx_flags = VIRTCHNL_VLAN_TX_INSERT;
+	} else {
+		vlan_config.rx_flags = VIRTCHNL_VLAN_RX_NO_STRIP;
+		vlan_config.tx_flags = VIRTCHNL_VLAN_TX_INSERT_BY_DESC;
+	}
+
+	ret = ice_dcf_config_vlan_offload(hw, &vlan_config);
+	if (ret < 0) {
+		PMD_DRV_LOG(ERR, "Failed to set pvid.");
+		return -EINVAL;
+	}
+
+	rte_memcpy(&hw->vlan_config, &vlan_config, sizeof(vlan_config));
+
+	return 0;
+}
+
+static int
+ice_dcf_representor_vlan_tpid_set(struct rte_eth_dev *dev,
+				  enum rte_vlan_type vlan_type,
+				  uint16_t tpid)
+{
+	struct ice_dcf_vf_representor *representor = dev->data->dev_private;
+	struct ice_dcf_hw *hw = &representor->adapter->real_hw;
+	struct virtchnl_dcf_vlan_offload vlan_config;
+	int ret;
+
+	if (vlan_type != ETH_VLAN_TYPE_INNER &&
+	    vlan_type != ETH_VLAN_TYPE_OUTER) {
+		PMD_DRV_LOG(ERR,
+			    "Unsupported vlan type.");
+		return -EINVAL;
+	}
+
+	vlan_config.vf_id = representor->vf_id;
+	vlan_config.ether_type = tpid;
+	ret = ice_dcf_config_vlan_offload(hw, &vlan_config);
+	if (ret < 0) {
+		PMD_DRV_LOG(ERR,
+			    "Set tpid fail\n");
+		return ret;
+	}
+
+	rte_memcpy(&hw->vlan_config, &vlan_config, sizeof(vlan_config));
+
+	return ret;
+}
+
 static const struct eth_dev_ops ice_dcf_representor_dev_ops = {
 	.dev_configure        = ice_dcf_representor_dev_configure,
 	.dev_start            = ice_dcf_representor_dev_start,
@@ -195,6 +312,9 @@ static const struct eth_dev_ops ice_dcf_representor_dev_ops = {
 	.promiscuous_enable   = ice_dcf_representor_promiscuous_enable,
 	.promiscuous_disable  = ice_dcf_representor_promiscuous_disable,
 	.link_update          = ice_dcf_representor_link_update,
+	.vlan_offload_set     = ice_dcf_representor_vlan_offload_set,
+	.vlan_pvid_set        = ice_dcf_representor_vlan_pvid_set,
+	.vlan_tpid_set        = ice_dcf_representor_vlan_tpid_set,
 };
 
 int
-- 
2.17.1


      parent reply	other threads:[~2020-09-02  6:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02  6:38 [dpdk-dev] [PATCH 0/2] enable VLAN offload in DCF Qiming Yang
2020-09-02  6:38 ` [dpdk-dev] [PATCH 1/2] net/ice: add dcf port representor infrastructure Qiming Yang
2020-09-08 11:35   ` Xing, Beilei
2020-09-09  7:18     ` Yang, Qiming
2020-10-20  8:18   ` Xing, Beilei
2020-09-02  6:38 ` Qiming Yang [this message]

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=20200902063802.102428-3-qiming.yang@intel.com \
    --to=qiming.yang@intel.com \
    --cc=dev@dpdk.org \
    --cc=qi.z.zhang@intel.com \
    /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).