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 04DD3A0350; Tue, 22 Feb 2022 09:53:05 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0DA4C41168; Tue, 22 Feb 2022 09:52:34 +0100 (CET) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2060.outbound.protection.outlook.com [40.107.220.60]) by mails.dpdk.org (Postfix) with ESMTP id EC09640DF4 for ; Tue, 22 Feb 2022 09:52:31 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nEywD7/29o5Ns7TiaMew3FZoe19PGHSyVj0dzP1zyqzNGRDOd9E/IpQUHimZ27N8LF6Pke3BILq+ljdA4ydPaAcVZVB3OILwx0IjmkFXvm8yEXkXBRy4nyJfFQSEQULxdox1in05g2Is+a4xtKYpGXHO31ZKb26QwR9z8fKzO2BMvQlAX+aMqcg5hkvZU7/MONbi2SKjTIHB9Q6vYsKWIuzPbhpoMPW3DpDbXjjwcdpIGKippfs7f46llq8XLR4rsS477y/sMbesgpzSEQZFkPtCdw7y8YZfyywzMnY2mFQVTnMfHig5HzHSSrOPG6GrLg5Zp9sO6dasXHXHpiZ+PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8B26ueK/M6ANJKiBe/nVE5EZBV1i6JUbuVYfvUaZp0k=; b=RvvCQzo1R5PdhzMn3u5Rx1MU7Pe1UsaETY8dxAgRZNbPnpYmty+qFPriCpnBPKkRRr89YXYfVZPOJpIg+ZnLRRt/A5D+VK7N4tu0/U7rx7b2ZwicV2vIMixaZgHQI39dNjCLkPYR3yISWwpou4kMEh2NEQRdgprYTES0CXPv4+EzidzmP2B18ILIDKZpPO9y8hMx+r34HbpWHo6VFS0lvFtir4J0wkmohKtTmYfAWyrKZlbhgYyhtlk+9P2ZJBtn+2YGuGzlJ9zzHQwW3Dqj4RJBnkCEPlmVVVaLaca+vfk9/TEND9+zfXuFz9f9YjrjKexlZLJ4UhPJpueustKdnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8B26ueK/M6ANJKiBe/nVE5EZBV1i6JUbuVYfvUaZp0k=; b=hD91at7va1HcM+biq/XftI4rg8bHTdYc7+oyTPZ/5UtQXr8mCulJcKOz1vAZEF4Sr0V44YbisxLpigi929aAipRYYX/CJEpc/OJjJP2yrzzSaAMeuMlEw4udwu3c6O/HiFE0JFftNblzr4LYzc73m1S4xjvjjpmZGeYkcDEQJwe5ZTIlzkU/LKYKOA0jJIzZhrqlBGwpojDVb6G1eOSGnDgYdh8At94ExCt9clrvV0yEvRrWcF0/HM2SdBdzncq2RG9AQ6o0MzKWGR5cLhUfORzzNvYfKQ7GLYJFl24aXXjy91mho1cnlA3iptp6iibl/AF+s+IiDm2HYbNhQ6MkPw== Received: from MWHPR17CA0061.namprd17.prod.outlook.com (2603:10b6:300:93::23) by CY4PR12MB1445.namprd12.prod.outlook.com (2603:10b6:910:11::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.24; Tue, 22 Feb 2022 08:52:29 +0000 Received: from CO1NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:300:93:cafe::84) by MWHPR17CA0061.outlook.office365.com (2603:10b6:300:93::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21 via Frontend Transport; Tue, 22 Feb 2022 08:52:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT027.mail.protection.outlook.com (10.13.174.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4995.15 via Frontend Transport; Tue, 22 Feb 2022 08:52:29 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 22 Feb 2022 08:52:28 +0000 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Tue, 22 Feb 2022 00:52:25 -0800 From: Suanming Mou To: , CC: , , Subject: [PATCH v2 06/14] net/mlx5: add action template management Date: Tue, 22 Feb 2022 10:51:48 +0200 Message-ID: <20220222085156.27137-7-suanmingm@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20220222085156.27137-1-suanmingm@nvidia.com> References: <20220210162926.20436-1-suanmingm@nvidia.com> <20220222085156.27137-1-suanmingm@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0b07fc0f-e7af-48ff-5153-08d9f5e0a850 X-MS-TrafficTypeDiagnostic: CY4PR12MB1445:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k9BNYA/ekUueOtKXC9nzIz7oyTq7LRdcps/sGdYuXZ4c6zBFvLYHOQoGSy9/Bgo+oE2EtYbkjntS2/Zz67A2Ps8/2E7zBWKA9md4hy9LDs/NO5AbdpOrJbV/6FGWw84KqhPYdGomPzxlcMyp9u5kO+0aSYMc3DGDeTyGP9gtqYkrPXLJw6kR1HyMBzs1o9qfPgvclMzFkmJa2lm9UR3qJ2kPkRU/MMtooaKHlLlwIbKkxJzAa37WQLMZ542EjI5EGj7vqWgFZyzbw2HR7JkaGVUVFmjiKbFL9zcN5AlBVVKRm8m+Vpl+CZ35oENzKIN+1kWKY+NrqeCjU6CAnHrYWOTWT/f5Id7OzA2U5K0N5jZ69xhLNRINkZBmBplboDIszlG9MI2+a2HZwZkuttfc68Ctg2tez23JidyDkQzH6/TItOOudXl3VjQKskSEvxa7ItAGxt+l3uQc9ny0c/wKw/JAepZZiIBfkQEeFp28sKhezcOyeliOm2j53HTtpkia88IlbbOeNMXeKeYTcdbce8hHvae9UHUVt5RxDCaohLTypUwaSScHMzyk8Mw4kkbvo1tquvQ/s9fcWQwkE1WrcIglgU+2JanX3/c6mDuVIYFQmIywsmdBRsxo4t8850kxHIUpRaEjpOg8cOve8vzg6yTVjoFnWqU35KXYBTcPidL8Z4Ows4NKKIK3qskCMiGWPYnUXz99eH1L7jxfL/e2dA== X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(36756003)(8676002)(426003)(336012)(2906002)(1076003)(86362001)(26005)(16526019)(6286002)(82310400004)(70586007)(6666004)(5660300002)(2616005)(186003)(4326008)(508600001)(7696005)(81166007)(70206006)(356005)(8936002)(30864003)(6636002)(83380400001)(47076005)(316002)(36860700001)(55016003)(54906003)(110136005)(40460700003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2022 08:52:29.3701 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b07fc0f-e7af-48ff-5153-08d9f5e0a850 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1445 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 The action template holds a list of action types that will be used together on the same rule. The template's actions instances will be created only when the template bind to the dedicated group. And the created actions will be saved to each individual group in order for best performance. The actions in a group will not be shared with each other unless shared actions are specified. This commit adds the action template management which stores the flow action template. Signed-off-by: Suanming Mou Acked-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_flow.c | 78 +++++++++++++++++++++ drivers/net/mlx5/mlx5_flow.h | 22 ++++++ drivers/net/mlx5/mlx5_flow_hw.c | 116 ++++++++++++++++++++++++++++++++ 4 files changed, 218 insertions(+) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 44694daf1b..8e36805e54 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1501,6 +1501,8 @@ struct mlx5_priv { #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) /* Item template list. */ LIST_HEAD(flow_hw_itt, rte_flow_pattern_template) flow_hw_itt; + /* Action template list. */ + LIST_HEAD(flow_hw_at, rte_flow_actions_template) flow_hw_at; struct mlx5dr_context *dr_ctx; /**< HW steering DR context. */ uint32_t nb_queue; /* HW steering queue number. */ /* HW steering queue polling mechanism job descriptor LIFO. */ diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index e6363ec765..e937110054 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -827,6 +827,16 @@ static int mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev, struct rte_flow_pattern_template *template, struct rte_flow_error *error); +static struct rte_flow_actions_template * +mlx5_flow_actions_template_create(struct rte_eth_dev *dev, + const struct rte_flow_actions_template_attr *attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error); +static int +mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev, + struct rte_flow_actions_template *template, + struct rte_flow_error *error); static const struct rte_flow_ops mlx5_flow_ops = { .validate = mlx5_flow_validate, @@ -852,6 +862,8 @@ static const struct rte_flow_ops mlx5_flow_ops = { .configure = mlx5_flow_port_configure, .pattern_template_create = mlx5_flow_pattern_template_create, .pattern_template_destroy = mlx5_flow_pattern_template_destroy, + .actions_template_create = mlx5_flow_actions_template_create, + .actions_template_destroy = mlx5_flow_actions_template_destroy, }; /* Tunnel information. */ @@ -7997,6 +8009,72 @@ mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev, return fops->pattern_template_destroy(dev, template, error); } +/** + * Create flow item template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] attr + * Pointer to the action template attributes. + * @param[in] actions + * Associated actions (list terminated by the END action). + * @param[in] masks + * List of actions that marks which of the action's member is constant. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static struct rte_flow_actions_template * +mlx5_flow_actions_template_create(struct rte_eth_dev *dev, + const struct rte_flow_actions_template_attr *attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error) +{ + const struct mlx5_flow_driver_ops *fops; + + if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) { + rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "action create with incorrect steering mode"); + return NULL; + } + fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW); + return fops->actions_template_create(dev, attr, actions, masks, error); +} + +/** + * Destroy flow action template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] template + * Pointer to the action template to be destroyed. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev, + struct rte_flow_actions_template *template, + struct rte_flow_error *error) +{ + const struct mlx5_flow_driver_ops *fops; + + if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "action destroy with incorrect steering mode"); + fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW); + return fops->actions_template_destroy(dev, template, error); +} + /** * Allocate a new memory for the counter values wrapped by all the needed * management. diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 12dbb4655b..7e2d6bf4eb 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -1026,6 +1026,16 @@ struct rte_flow_pattern_template { uint32_t refcnt; /* Reference counter. */ }; +/* Flow action template struct. */ +struct rte_flow_actions_template { + LIST_ENTRY(rte_flow_actions_template) next; + /* Template attributes. */ + struct rte_flow_actions_template_attr attr; + struct rte_flow_action *actions; /* Cached flow actions. */ + struct rte_flow_action *masks; /* Cached action masks.*/ + uint32_t refcnt; /* Reference counter. */ +}; + #endif /* @@ -1290,6 +1300,16 @@ typedef int (*mlx5_flow_pattern_template_destroy_t) (struct rte_eth_dev *dev, struct rte_flow_pattern_template *template, struct rte_flow_error *error); +typedef struct rte_flow_actions_template *(*mlx5_flow_actions_template_create_t) + (struct rte_eth_dev *dev, + const struct rte_flow_actions_template_attr *attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error); +typedef int (*mlx5_flow_actions_template_destroy_t) + (struct rte_eth_dev *dev, + struct rte_flow_actions_template *template, + struct rte_flow_error *error); struct mlx5_flow_driver_ops { mlx5_flow_validate_t validate; @@ -1332,6 +1352,8 @@ struct mlx5_flow_driver_ops { mlx5_flow_port_configure_t configure; mlx5_flow_pattern_template_create_t pattern_template_create; mlx5_flow_pattern_template_destroy_t pattern_template_destroy; + mlx5_flow_actions_template_create_t actions_template_create; + mlx5_flow_actions_template_destroy_t actions_template_destroy; }; /* mlx5_flow.c */ diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c index 66c5825084..4214a63a73 100644 --- a/drivers/net/mlx5/mlx5_flow_hw.c +++ b/drivers/net/mlx5/mlx5_flow_hw.c @@ -12,6 +12,115 @@ const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops; +/** + * Create flow action template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] attr + * Pointer to the action template attributes. + * @param[in] actions + * Associated actions (list terminated by the END action). + * @param[in] masks + * List of actions that marks which of the action's member is constant. + * @param[out] error + * Pointer to error structure. + * + * @return + * Action template pointer on success, NULL otherwise and rte_errno is set. + */ +static struct rte_flow_actions_template * +flow_hw_actions_template_create(struct rte_eth_dev *dev, + const struct rte_flow_actions_template_attr *attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error) +{ + struct mlx5_priv *priv = dev->data->dev_private; + int len, act_len, mask_len, i; + struct rte_flow_actions_template *at; + + act_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, + NULL, 0, actions, error); + if (act_len <= 0) + return NULL; + len = RTE_ALIGN(act_len, 16); + mask_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, + NULL, 0, masks, error); + if (mask_len <= 0) + return NULL; + len += RTE_ALIGN(mask_len, 16); + at = mlx5_malloc(MLX5_MEM_ZERO, len + sizeof(*at), 64, rte_socket_id()); + if (!at) { + rte_flow_error_set(error, ENOMEM, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "cannot allocate action template"); + return NULL; + } + at->attr = *attr; + at->actions = (struct rte_flow_action *)(at + 1); + act_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, at->actions, len, + actions, error); + if (act_len <= 0) + goto error; + at->masks = (struct rte_flow_action *) + (((uint8_t *)at->actions) + act_len); + mask_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, at->masks, + len - act_len, masks, error); + if (mask_len <= 0) + goto error; + /* + * mlx5 PMD hacks indirect action index directly to the action conf. + * The rte_flow_conv() function copies the content from conf pointer. + * Need to restore the indirect action index from action conf here. + */ + for (i = 0; actions->type != RTE_FLOW_ACTION_TYPE_END; + actions++, masks++, i++) { + if (actions->type == RTE_FLOW_ACTION_TYPE_INDIRECT) { + at->actions[i].conf = actions->conf; + at->masks[i].conf = masks->conf; + } + } + __atomic_fetch_add(&at->refcnt, 1, __ATOMIC_RELAXED); + LIST_INSERT_HEAD(&priv->flow_hw_at, at, next); + return at; +error: + mlx5_free(at); + return NULL; +} + +/** + * Destroy flow action template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] template + * Pointer to the action template to be destroyed. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +flow_hw_actions_template_destroy(struct rte_eth_dev *dev __rte_unused, + struct rte_flow_actions_template *template, + struct rte_flow_error *error __rte_unused) +{ + if (__atomic_load_n(&template->refcnt, __ATOMIC_RELAXED) > 1) { + DRV_LOG(WARNING, "Action template %p is still in use.", + (void *)template); + return rte_flow_error_set(error, EBUSY, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "action template in using"); + } + LIST_REMOVE(template, next); + mlx5_free(template); + return 0; +} + /** * Create flow item template. * @@ -234,6 +343,7 @@ flow_hw_resource_release(struct rte_eth_dev *dev) { struct mlx5_priv *priv = dev->data->dev_private; struct rte_flow_pattern_template *it; + struct rte_flow_actions_template *at; if (!priv->dr_ctx) return; @@ -241,6 +351,10 @@ flow_hw_resource_release(struct rte_eth_dev *dev) it = LIST_FIRST(&priv->flow_hw_itt); flow_hw_pattern_template_destroy(dev, it, NULL); } + while (!LIST_EMPTY(&priv->flow_hw_at)) { + at = LIST_FIRST(&priv->flow_hw_at); + flow_hw_actions_template_destroy(dev, at, NULL); + } mlx5_free(priv->hw_q); priv->hw_q = NULL; claim_zero(mlx5dr_context_close(priv->dr_ctx)); @@ -253,6 +367,8 @@ const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops = { .configure = flow_hw_configure, .pattern_template_create = flow_hw_pattern_template_create, .pattern_template_destroy = flow_hw_pattern_template_destroy, + .actions_template_create = flow_hw_actions_template_create, + .actions_template_destroy = flow_hw_actions_template_destroy, }; #endif -- 2.25.1