DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jie Wang <jie1x.wang@intel.com>
To: dev@dpdk.org
Cc: qiming.yang@intel.com, qi.z.zhang@intel.com,
	jingjing.wu@intel.com, beilei.xing@intel.com,
	stevex.yang@intel.com, Jie Wang <jie1x.wang@intel.com>
Subject: [PATCH v2 4/5] net/iavf: support flow subscription rule
Date: Sat, 13 Aug 2022 01:04:46 +0800	[thread overview]
Message-ID: <20220812170447.186992-5-jie1x.wang@intel.com> (raw)
In-Reply-To: <20220812170447.186992-1-jie1x.wang@intel.com>

Support flow subscribption create/destroy/validation flow
rule for AVF.

For examples:
testpmd> flow create 0 ingress pattern eth / ipv4 / udp src is 11
          / end actions represented_port port_id 1 / end
testpmd> flow validate 1 ingress pattern eth / ipv4 / tcp src is 22
          / end actions represented_port port_id 1 / end
testpmd> flow destroy 1 rule 0

Signed-off-by: Jie Wang <jie1x.wang@intel.com>
---
 drivers/net/iavf/iavf.h       |   6 ++
 drivers/net/iavf/iavf_fsub.c  |  75 +++++++++++++++----
 drivers/net/iavf/iavf_vchnl.c | 132 ++++++++++++++++++++++++++++++++++
 3 files changed, 201 insertions(+), 12 deletions(-)

diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h
index f79c7f9f6e..26b858f6f0 100644
--- a/drivers/net/iavf/iavf.h
+++ b/drivers/net/iavf/iavf.h
@@ -489,4 +489,10 @@ int iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
 extern const struct rte_tm_ops iavf_tm_ops;
 int iavf_get_ptp_cap(struct iavf_adapter *adapter);
 int iavf_get_phc_time(struct iavf_rx_queue *rxq);
+int iavf_flow_sub(struct iavf_adapter *adapter,
+		  struct iavf_fsub_conf *filter);
+int iavf_flow_unsub(struct iavf_adapter *adapter,
+		    struct iavf_fsub_conf *filter);
+int iavf_flow_sub_check(struct iavf_adapter *adapter,
+			struct iavf_fsub_conf *filter);
 #endif /* _IAVF_ETHDEV_H_ */
diff --git a/drivers/net/iavf/iavf_fsub.c b/drivers/net/iavf/iavf_fsub.c
index 89e60c5d57..441bf478be 100644
--- a/drivers/net/iavf/iavf_fsub.c
+++ b/drivers/net/iavf/iavf_fsub.c
@@ -69,29 +69,80 @@ iavf_pattern_match_item iavf_fsub_pattern_list[] = {
 };
 
 static int
-iavf_fsub_create(__rte_unused struct iavf_adapter *ad,
-		 __rte_unused struct rte_flow *flow,
-		 __rte_unused void *meta,
-		 __rte_unused struct rte_flow_error *error)
+iavf_fsub_create(struct iavf_adapter *ad, struct rte_flow *flow,
+		 void *meta, struct rte_flow_error *error)
 {
+	struct iavf_fsub_conf *filter = meta;
+	struct iavf_fsub_conf *rule;
+	int ret;
+
+	rule = rte_zmalloc("fsub_entry", sizeof(*rule), 0);
+	if (!rule) {
+		rte_flow_error_set(error, ENOMEM,
+				RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+				"Failed to allocate memory for fsub rule");
+		return -rte_errno;
+	}
+
+	ret = iavf_flow_sub(ad, filter);
+	if (ret) {
+		rte_flow_error_set(error, -ret,
+				   RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+				   "Failed to subscribe flow rule.");
+		goto free_entry;
+	}
+
+	rte_memcpy(rule, filter, sizeof(*rule));
+	flow->rule = rule;
+
+	return ret;
+
+free_entry:
+	rte_free(rule);
 	return -rte_errno;
 }
 
 static int
-iavf_fsub_destroy(__rte_unused struct iavf_adapter *ad,
-		  __rte_unused struct rte_flow *flow,
-		  __rte_unused struct rte_flow_error *error)
+iavf_fsub_destroy(struct iavf_adapter *ad, struct rte_flow *flow,
+		  struct rte_flow_error *error)
 {
-	return -rte_errno;
+	struct iavf_fsub_conf *filter;
+	int ret;
+
+	filter = (struct iavf_fsub_conf *)flow->rule;
+
+	ret = iavf_flow_unsub(ad, filter);
+	if (ret) {
+		rte_flow_error_set(error, -ret,
+				   RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+				   "Failed to unsubscribe flow rule.");
+		return -rte_errno;
+	}
+
+	flow->rule = NULL;
+	rte_free(filter);
+
+	return ret;
 }
 
 static int
-iavf_fsub_validation(__rte_unused struct iavf_adapter *ad,
+iavf_fsub_validation(struct iavf_adapter *ad,
 		     __rte_unused struct rte_flow *flow,
-		     __rte_unused void *meta,
-		     __rte_unused struct rte_flow_error *error)
+		     void *meta,
+		     struct rte_flow_error *error)
 {
-	return -rte_errno;
+	struct iavf_fsub_conf *filter = meta;
+	int ret;
+
+	ret = iavf_flow_sub_check(ad, filter);
+	if (ret) {
+		rte_flow_error_set(error, -ret,
+				   RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
+				   "Failed to validate filter rule.");
+		return -rte_errno;
+	}
+
+	return ret;
 };
 
 static int
diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c
index 6d84add423..cc0db8d093 100644
--- a/drivers/net/iavf/iavf_vchnl.c
+++ b/drivers/net/iavf/iavf_vchnl.c
@@ -1534,6 +1534,138 @@ iavf_fdir_check(struct iavf_adapter *adapter,
 	return 0;
 }
 
+int
+iavf_flow_sub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
+{
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	struct virtchnl_flow_sub *fsub_cfg;
+	struct iavf_cmd_info args;
+	int err;
+
+	filter->sub_fltr.vsi_id = vf->vsi_res->vsi_id;
+	filter->sub_fltr.validate_only = 0;
+
+	memset(&args, 0, sizeof(args));
+	args.ops = VIRTCHNL_OP_FLOW_SUBSCRIBE;
+	args.in_args = (uint8_t *)(&filter->sub_fltr);
+	args.in_args_size = sizeof(*(&filter->sub_fltr));
+	args.out_buffer = vf->aq_resp;
+	args.out_size = IAVF_AQ_BUF_SZ;
+
+	err = iavf_execute_vf_cmd(adapter, &args, 0);
+	if (err)
+		PMD_DRV_LOG(ERR, "Failed to execute command of "
+				 "OP_FLOW_SUBSCRIBE");
+
+	fsub_cfg = (struct virtchnl_flow_sub *)args.out_buffer;
+	filter->flow_id = fsub_cfg->flow_id;
+
+	if (fsub_cfg->status == VIRTCHNL_FSUB_SUCCESS) {
+		PMD_DRV_LOG(INFO, "Succeed in adding rule request by PF");
+	} else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_NORESOURCE) {
+		PMD_DRV_LOG(ERR, "Failed to add rule request due to no hw "
+				 "resource");
+		err = -1;
+	} else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_EXIST) {
+		PMD_DRV_LOG(ERR, "Failed to add rule request due to the rule "
+				 "is already existed");
+		err = -1;
+	} else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_INVALID) {
+		PMD_DRV_LOG(ERR, "Failed to add rule request due to the hw "
+				 "doesn't support");
+		err = -1;
+	} else {
+		PMD_DRV_LOG(ERR, "Failed to add rule request due to other "
+				 "reasons");
+		err = -1;
+	}
+
+	return err;
+}
+
+int
+iavf_flow_unsub(struct iavf_adapter *adapter, struct iavf_fsub_conf *filter)
+{
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	struct virtchnl_flow_unsub *unsub_cfg;
+	struct iavf_cmd_info args;
+	int err;
+
+	filter->unsub_fltr.vsi_id = vf->vsi_res->vsi_id;
+	filter->unsub_fltr.flow_id = filter->flow_id;
+
+	memset(&args, 0, sizeof(args));
+	args.ops = VIRTCHNL_OP_FLOW_UNSUBSCRIBE;
+	args.in_args = (uint8_t *)(&filter->unsub_fltr);
+	args.in_args_size = sizeof(filter->unsub_fltr);
+	args.out_buffer = vf->aq_resp;
+	args.out_size = IAVF_AQ_BUF_SZ;
+
+	err = iavf_execute_vf_cmd(adapter, &args, 0);
+	if (err)
+		PMD_DRV_LOG(ERR, "Failed to execute command of "
+				 "OP_FLOW_UNSUBSCRIBE");
+
+	unsub_cfg = (struct virtchnl_flow_unsub *)args.out_buffer;
+
+	if (unsub_cfg->status == VIRTCHNL_FSUB_SUCCESS) {
+		PMD_DRV_LOG(INFO, "Succeed in deleting rule request by PF");
+	} else if (unsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_NONEXIST) {
+		PMD_DRV_LOG(ERR, "Failed to delete rule request due to this "
+				 "rule doesn't exist");
+		err = -1;
+	} else {
+		PMD_DRV_LOG(ERR, "Failed to delete rule request due to other "
+				 "reasons");
+		err = -1;
+	}
+
+	return err;
+}
+
+int
+iavf_flow_sub_check(struct iavf_adapter *adapter,
+		    struct iavf_fsub_conf *filter)
+{
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	struct virtchnl_flow_sub *fsub_cfg;
+
+	struct iavf_cmd_info args;
+	int err;
+
+	filter->sub_fltr.vsi_id = vf->vsi_res->vsi_id;
+	filter->sub_fltr.validate_only = 1;
+
+	args.ops = VIRTCHNL_OP_FLOW_SUBSCRIBE;
+	args.in_args = (uint8_t *)(&filter->sub_fltr);
+	args.in_args_size = sizeof(*(&filter->sub_fltr));
+	args.out_buffer = vf->aq_resp;
+	args.out_size = IAVF_AQ_BUF_SZ;
+
+	err = iavf_execute_vf_cmd(adapter, &args, 0);
+	if (err) {
+		PMD_DRV_LOG(ERR, "fail to check flow director rule");
+		return err;
+	}
+
+	fsub_cfg = (struct virtchnl_flow_sub *)args.out_buffer;
+
+	if (fsub_cfg->status == VIRTCHNL_FSUB_SUCCESS) {
+		PMD_DRV_LOG(INFO, "Succeed in checking rule request by PF");
+	} else if (fsub_cfg->status == VIRTCHNL_FSUB_FAILURE_RULE_INVALID) {
+		PMD_DRV_LOG(ERR, "Failed to check rule request due to "
+				 "parameters validation or HW doesn't "
+				 "support");
+		err = -1;
+	} else {
+		PMD_DRV_LOG(ERR, "Failed to check rule request due to other "
+				 "reasons");
+		err = -1;
+	}
+
+	return err;
+}
+
 int
 iavf_add_del_rss_cfg(struct iavf_adapter *adapter,
 		     struct virtchnl_rss_cfg *rss_cfg, bool add)
-- 
2.25.1


  parent reply	other threads:[~2022-08-12  9:07 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09  6:21 [PATCH 0/2] support flow subscription Jie Wang
2022-08-09  6:21 ` [PATCH 1/2] common/iavf: " Jie Wang
2022-08-09  6:21 ` [PATCH 2/2] net/iavf: enable flow subscription rule support for AVF Jie Wang
2022-08-12 17:04 ` [PATCH v2 0/5] support flow subscription Jie Wang
2022-08-12 17:04   ` [PATCH v2 1/5] common/iavf: " Jie Wang
2022-08-12 17:04   ` [PATCH v2 2/5] net/iavf: add flow subscription to AVF Jie Wang
2022-08-12 17:04   ` [PATCH v2 3/5] net/iavf: support flow subscrption pattern Jie Wang
2022-08-12 17:04   ` Jie Wang [this message]
2022-08-12 17:04   ` [PATCH v2 5/5] net/iavf: support priority of flow rule Jie Wang
2022-08-30 18:05 ` [PATCH v3 0/5] support flow subscription Jie Wang
2022-08-30 18:05   ` [PATCH v3 1/5] common/iavf: " Jie Wang
2022-08-30 18:05   ` [PATCH v3 2/5] net/iavf: add flow subscription to AVF Jie Wang
2022-08-30 18:05   ` [PATCH v3 3/5] net/iavf: support flow subscrption pattern Jie Wang
2022-09-06  7:30     ` Zhang, Qi Z
2022-08-30 18:05   ` [PATCH v3 4/5] net/iavf: support flow subscription rule Jie Wang
2022-08-30 18:05   ` [PATCH v3 5/5] net/iavf: support priority of flow rule Jie Wang
2022-08-31 10:56   ` [PATCH v3 0/5] support flow subscription Ferruh Yigit
2022-08-31 12:28     ` Zhang, Qi Z
2022-08-31 12:53       ` Ferruh Yigit
2022-09-01  0:59         ` Zhang, Qi Z
2022-09-07  3:35 ` [PATCH v4 " Jie Wang
2022-09-07  3:35   ` [PATCH v4 1/5] common/iavf: " Jie Wang
2022-09-07  3:35   ` [PATCH v4 2/5] net/iavf: add flow subscription to AVF Jie Wang
2022-09-07  3:35   ` [PATCH v4 3/5] net/iavf: support flow subscrption pattern Jie Wang
2022-09-07  3:35   ` [PATCH v4 4/5] net/iavf: support flow subscription rule Jie Wang
2022-09-07  3:35   ` [PATCH v4 5/5] net/iavf: support priority of flow rule Jie Wang
2022-09-07  4:38 ` [PATCH v4 0/5] support flow subscription Jie Wang
2022-09-07  4:38   ` [PATCH v4 1/5] common/iavf: " Jie Wang
2022-09-07  4:38   ` [PATCH v4 2/5] net/iavf: add flow subscription to AVF Jie Wang
2022-09-07  4:38   ` [PATCH v4 3/5] net/iavf: support flow subscrption pattern Jie Wang
2022-09-07  4:38   ` [PATCH v4 4/5] net/iavf: support flow subscription rule Jie Wang
2022-09-07  4:38   ` [PATCH v4 5/5] net/iavf: support priority of flow rule Jie Wang
2022-09-07  5:10 ` [PATCH v5 0/5] support flow subscription Jie Wang
2022-09-07  5:10   ` [PATCH v5 1/5] common/iavf: " Jie Wang
2022-09-07  5:10   ` [PATCH v5 2/5] net/iavf: add flow subscription to AVF Jie Wang
2022-09-07  5:10   ` [PATCH v5 3/5] net/iavf: support flow subscrption pattern Jie Wang
2022-09-07  5:27     ` Zhang, Qi Z
2022-09-07  5:10   ` [PATCH v5 4/5] net/iavf: support flow subscription rule Jie Wang
2022-09-07  5:10   ` [PATCH v5 5/5] net/iavf: support priority of flow rule Jie Wang
2022-09-07  5:28   ` [PATCH v5 0/5] support flow subscription Zhang, Qi Z

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=20220812170447.186992-5-jie1x.wang@intel.com \
    --to=jie1x.wang@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=qi.z.zhang@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=stevex.yang@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).