From patchwork Thu Feb 24 03:10:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suanming Mou X-Patchwork-Id: 108206 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B3DB9A0353; Thu, 24 Feb 2022 04:11:17 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5AB244116E; Thu, 24 Feb 2022 04:11:05 +0100 (CET) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2077.outbound.protection.outlook.com [40.107.223.77]) by mails.dpdk.org (Postfix) with ESMTP id D263D4116E for ; Thu, 24 Feb 2022 04:11:00 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oCJJq1AKBQta5+UckZHuHTcmp4hDAr6n+IbHVttSykwRFhpztYlctfApCeo5vF2GYAYK/hJlLe0v+5Llpq3E6utkgOMfbsLd+BSwPkIBRtQxVEvlRyNeDFFIoMmlchZmOvvf69QUZT8ftXcGsUnxa0R24y4rLEwsWoA8mnm9cUPp4DfnAfvdAEtg53BaUdmHDiBFCm+sKcD9nRHDi0dcG3DGYP8Z1gwZta1wtBCTp1Zeg+6GibB51FTaj/OL5U54LpWtH2Uj2hJu2IY/OWxhg7t42HOX11OYzrH0vpxi3Ry2XoryQjii5B73nVFW/Ln6/LYzDSvOJ8HXIBDWGlry3g== 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=3zU/w9bfK+UWLxQMP4HNaWQD4v23TxpQOD9Fh9Z5BJA=; b=ZfBG0dc7T92uPNkr+2j4i4RqDGiwF2OOrhCXOIwcp5FtskIDIamKHlJxtM6yJzdmB0OWMajTWOjBp/hjxd7oJbU3Vnn+T5+6SgLdIW+0Ia+c7W2vBgjee6meHvfbGEmUF5RuDjUBQYghGotlzlLiBGFvmigjE+rZcaXqcrlPRyrfg+uDCT0dzaMCAODO5CfXy2wadsqdxOsS1zuhRnFPdZYyLXHltIvaGYqE7wMvwCYWV2g1HGvECuVKgx7UXIW/6K+FUNW3cQonuFwWVuNI0kHC25DLuLU1NggYj5QUj7J+H6R3I04GRbQ9GqULbYUbIyoKWMu9hgl04e2MJwtLGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) 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=3zU/w9bfK+UWLxQMP4HNaWQD4v23TxpQOD9Fh9Z5BJA=; b=pQXAaywo1m6DU1n/+0OC7e3ci97PTNBWGOjJ76Y+eDKbcgyOuBv4R9fWdTGwjcPVUGfY8bnMjjLWfVyTv6sQwke0GED7f5J7e6PYgcqrUx3MRo9uUlNkBx3dyNJKL70HH05Mr5lm/uN+QU10fg894VwLP8xNANYfJSZMW2IBpi/OQdgU5DnqGVxczSRFEwzYMEEPh6oGBALEO7nwHbXUIKn2mkf4LtrvHL9i8S8B9QhRclvjNkez9XJXKTc+MZLfNi+3jsV/Zdoz0gPombjvI/GWO/J5Qecj5CGJAQav2UYzvSWAv2MQn67yEpQ0qW1TIHXXhzJqtJhw64KTEN4E1Q== Received: from CO2PR18CA0064.namprd18.prod.outlook.com (2603:10b6:104:2::32) by CY4PR12MB1893.namprd12.prod.outlook.com (2603:10b6:903:127::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.24; Thu, 24 Feb 2022 03:10:58 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:104:2:cafe::37) by CO2PR18CA0064.outlook.office365.com (2603:10b6:104:2::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19 via Frontend Transport; Thu, 24 Feb 2022 03:10:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) 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.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.234) by CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 03:10:57 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 24 Feb 2022 03:10:56 +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; Wed, 23 Feb 2022 19:10:54 -0800 From: Suanming Mou To: , CC: , , Subject: [PATCH v3 06/14] net/mlx5: add action template management Date: Thu, 24 Feb 2022 05:10:21 +0200 Message-ID: <20220224031029.14049-7-suanmingm@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20220224031029.14049-1-suanmingm@nvidia.com> References: <20220210162926.20436-1-suanmingm@nvidia.com> <20220224031029.14049-1-suanmingm@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7ec49afe-267e-4cd8-db35-08d9f7434723 X-MS-TrafficTypeDiagnostic: CY4PR12MB1893: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: cHMmZbcXZr0XnThXSDiH3S1fXyL7FMiBT+hdCQRopOm3fOe7hZVU0W78VMVaFXG+yRjimi7bsIas6FXj5ctZdK2yERU1KB/n5ZYZ2byfQfJIByZ1EReVzUzwa+2YFTpgs42UiiXKzmEKfYSB+KIsFWLK7YIITbFqLtiC0Wzi/t+/9AStxQQnV7P3zfzRDOgu+ingnEc4b3swnuBchMaxyiVZ18kZV8RLGca/k85eIPyneP2IJe/NSkWKenZE6Q7rlJL7Bhgxhnmkdj0BHvaItEUuMsv4VvJcHctTl9HzXcODZaxigt0Bs55KZzBqACNXNRQ9feVQpTvGvV3KpGK0sToYuh0in3cNPj9+bGNjQ+Vx58W4+izhiS6DmV4yPlxpt+56go/LYIPoiK+/rePKR8RjrOabwgXPz/BKWOU3y7hye00VuBp5SaYgn7vN/BmIUXjUPVpskIzFpwUqmkCo0Tp7EAiEn5InbJgEiwBNsttyCr6TFuZ86S8kfOXtOz0W+BnpDhl+IgoZV+3ucNT5UM5+Mg5J07/T47DmikicbBd8tSSfu0yLcz/H4tlm8m/ZXkwNENfFzqDDsnm3hrqRA4M2c8uE8FmBSerFAWo5iBq/DDyx8RdV5PJtwke0z4wN7REenTHp59MF+3+E3TaVkVVeQ68yUjiL5+kQyG3Ov2DbgGg8F17K/2H5g/+iXhbyDeA30n72EOrlQBlQIiDi+Q== X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(55016003)(5660300002)(30864003)(6666004)(83380400001)(7696005)(40460700003)(6636002)(2906002)(110136005)(336012)(54906003)(426003)(8936002)(47076005)(36860700001)(36756003)(1076003)(86362001)(81166007)(8676002)(70586007)(2616005)(316002)(4326008)(508600001)(356005)(82310400004)(186003)(26005)(16526019)(70206006)(6286002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 03:10:57.6631 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7ec49afe-267e-4cd8-db35-08d9f7434723 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.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1893 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 e36adde708..156b8613d8 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1504,6 +1504,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 673e0ec55f..18c313c6f0 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. */ @@ -8000,6 +8012,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 49027d6a3a..9a643fe0a8 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