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 56874A054A; Wed, 7 Sep 2022 06:39:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 17AA942836; Wed, 7 Sep 2022 06:39:42 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 7BD40427FF for ; Wed, 7 Sep 2022 06:39:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662525580; x=1694061580; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uZZPixTAgVSMVXRBaRLoXo1SLC8cd0pAEnWSgHKg3yM=; b=mRNNj1Rf/Z5/xOzGL8DAKoOFajlquo4OQrJL3a2K1xvi9XZbEbB+oYLF 9XfSvbaX+wc9kYFiZ/Lzqqzosg4Zm6A6abZaTkFWsxNWAKs4GgQtjRkTI u08xh7ZL1ZiJCbdk2m4nf/jSmh+ryKFvmerbBy7xmzdFAXonhdQxywm9E P49Uikv9yJLBIVurKxFEDLxJWY+SeKolGV2PblWS/YlG9pT66kvbPDECD S9EmUkOGX18vzQuSJo/RUZuIK5x2Y8wgXik9HNzz7dZfn2/f6JnPdqkgH /8r5SPPdDwTiBlNPAPJOB8eal1jniKyjad0g50TMUjRWb0oa69Orrr47I g==; X-IronPort-AV: E=McAfee;i="6500,9779,10462"; a="294362052" X-IronPort-AV: E=Sophos;i="5.93,295,1654585200"; d="scan'208";a="294362052" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2022 21:39:40 -0700 X-IronPort-AV: E=Sophos;i="5.93,295,1654585200"; d="scan'208";a="676005156" 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; 06 Sep 2022 21:39:38 -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 v4 4/5] net/iavf: support flow subscription rule Date: Wed, 7 Sep 2022 12:38:53 +0800 Message-Id: <20220907043854.119441-5-jie1x.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220907043854.119441-1-jie1x.wang@intel.com> References: <20220809062122.1203281-1-jie1x.wang@intel.com> <20220907043854.119441-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 VF subscribes to a rule, which means the packets will be sent to VF instead of PF, and only VF will receive the packets. It is allowed multiple VF subscribe to same rule, the packets will be replicated and received by each VF. PF will destroy all subscriptions during VF reset. 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 66e403d585..28857d7577 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