From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 42B5EA034C; Tue, 30 Aug 2022 12:08:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 514814282B; Tue, 30 Aug 2022 12:08:03 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 694FA40F17 for ; Tue, 30 Aug 2022 12:08:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661854081; x=1693390081; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+GVcso6ZR9QvnAiFZ012SDacEK8nT8e8eaDDj5WcERU=; b=WBHeLpMzF6AJaRlHFBcLMMRbVTNnBkXVEOwXnmg3is7F+sVT+Ba9/fC9 xo1LLegpvBVuPuMxJJTOYO3n3hg+wVIIfOQGqRdw0iRifakNQ+V+AoPYi M5o7yIIg6xlNUoX2ZWoQETMq7emAdXbkedZL4Xe4+UMuud0ZOejwWv6L8 Hzx+W6FtKjeVQzR1XOePs2utAo29Ym1QMM2SEAnqsvFz6dkzwOMBCO9Hi yhjQYW5MMitoOvngyiOmT56zXMJEYTNc3oEroc56ZCyndI4TxxkxZxJih +kiy5UVgHcDeFrWUAngcG/07ekKJ2gr7GX7a6roRlsAKoyCAP/L1uVwdp A==; X-IronPort-AV: E=McAfee;i="6500,9779,10454"; a="295917604" X-IronPort-AV: E=Sophos;i="5.93,274,1654585200"; d="scan'208";a="295917604" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 03:08:00 -0700 X-IronPort-AV: E=Sophos;i="5.93,274,1654585200"; d="scan'208";a="672794897" Received: from intel-cd-odc-gavin.cd.intel.com ([10.240.178.187]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 03:07:58 -0700 From: Jie Wang 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 Subject: [PATCH v3 4/5] net/iavf: support flow subscription rule Date: Wed, 31 Aug 2022 02:05:13 +0800 Message-Id: <20220830180514.693175-5-jie1x.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220830180514.693175-1-jie1x.wang@intel.com> References: <20220809062122.1203281-1-jie1x.wang@intel.com> <20220830180514.693175-1-jie1x.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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 4600d52b91..b9ad3531ff 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