From patchwork Mon Jul 9 15:52:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10515049 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C63A6032A for ; Mon, 9 Jul 2018 15:52:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEC9E28C79 for ; Mon, 9 Jul 2018 15:52:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E22C828D49; Mon, 9 Jul 2018 15:52:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7091A28D43 for ; Mon, 9 Jul 2018 15:52:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933652AbeGIPwi (ORCPT ); Mon, 9 Jul 2018 11:52:38 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:42486 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933351AbeGIPwg (ORCPT ); Mon, 9 Jul 2018 11:52:36 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 9 Jul 2018 18:55:27 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w69FqWme007120; Mon, 9 Jul 2018 18:52:32 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w69FqVU2019315; Mon, 9 Jul 2018 18:52:31 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w69FqVqG019314; Mon, 9 Jul 2018 18:52:31 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, majd@mellanox.com, jgg@mellanox.com Subject: [PATCH rdma-core 4/4] mlx5: Introduce mlx5dv_create_flow Date: Mon, 9 Jul 2018 18:52:10 +0300 Message-Id: <1531151530-19188-5-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1531151530-19188-1-git-send-email-yishaih@mellanox.com> References: <1531151530-19188-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce mlx5dv_create_flow API to be used for creating ibv_flow object with device specific properties. The common ibv_destroy_flow should be used to destroy the created object. Signed-off-by: Yishai Hadas --- debian/ibverbs-providers.symbols | 1 + providers/mlx5/libmlx5.map | 1 + providers/mlx5/mlx5dv.h | 24 ++++++++++++++++++ providers/mlx5/verbs.c | 55 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) diff --git a/debian/ibverbs-providers.symbols b/debian/ibverbs-providers.symbols index f0c54f8..11ea417 100644 --- a/debian/ibverbs-providers.symbols +++ b/debian/ibverbs-providers.symbols @@ -23,3 +23,4 @@ libmlx5.so.1 ibverbs-providers #MINVER# mlx5dv_create_flow_action_esp@MLX5_1.5 18 mlx5dv_create_flow_matcher@MLX5_1.6 20 mlx5dv_destroy_flow_matcher@MLX5_1.6 20 + mlx5dv_create_flow@MLX5_1.6 20 diff --git a/providers/mlx5/libmlx5.map b/providers/mlx5/libmlx5.map index 8538f5e..7501fa7 100644 --- a/providers/mlx5/libmlx5.map +++ b/providers/mlx5/libmlx5.map @@ -38,4 +38,5 @@ MLX5_1.6 { global: mlx5dv_create_flow_matcher; mlx5dv_destroy_flow_matcher; + mlx5dv_create_flow; } MLX5_1.5; diff --git a/providers/mlx5/mlx5dv.h b/providers/mlx5/mlx5dv.h index 9710133..fa0fca2 100644 --- a/providers/mlx5/mlx5dv.h +++ b/providers/mlx5/mlx5dv.h @@ -216,6 +216,30 @@ mlx5dv_create_flow_matcher(struct ibv_context *context, int mlx5dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *matcher); +enum mlx5dv_flow_action_type { + MLX5DV_FLOW_ACTION_DEST_IBV_QP, + MLX5DV_FLOW_ACTION_DROP, + MLX5DV_FLOW_ACTION_IBV_COUNTER, + MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION, + MLX5DV_FLOW_ACTION_TAG, +}; + +struct mlx5dv_flow_action_attr { + enum mlx5dv_flow_action_type type; + union { + struct ibv_qp *qp; + struct ibv_counters *counter; + struct ibv_flow_action *action; + uint32_t tag_value; + }; +}; + +struct ibv_flow * +mlx5dv_create_flow(struct mlx5dv_flow_matcher *matcher, + struct mlx5dv_flow_match_parameters *match_value, + size_t num_actions, + struct mlx5dv_flow_action_attr actions_attr[]); + struct ibv_flow_action *mlx5dv_create_flow_action_esp(struct ibv_context *ctx, struct ibv_flow_action_esp_attr *esp, struct mlx5dv_flow_action_esp *mlx5_attr); diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 2654c45..2913de5 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -3611,3 +3611,58 @@ int mlx5dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *flow_matcher) free(flow_matcher); return 0; } + +struct ibv_flow * +mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher, + struct mlx5dv_flow_match_parameters *match_value, + size_t num_actions, + struct mlx5dv_flow_action_attr actions_attr[]) +{ + struct mlx5_flow *mflow; + int ret; + DECLARE_COMMAND_BUFFER_LINK(cmd, UVERBS_OBJECT_FLOW, + MLX5_IB_METHOD_CREATE_FLOW, + 4, + NULL); + struct ib_uverbs_attr *handle; + enum mlx5dv_flow_action_type type; + + if (num_actions != 1) { + errno = EOPNOTSUPP; + return NULL; + } + + mflow = calloc(1, sizeof(*mflow)); + if (!mflow) { + errno = ENOMEM; + return NULL; + } + + handle = fill_attr_out_obj(cmd, MLX5_IB_ATTR_CREATE_FLOW_HANDLE); + fill_attr_in(cmd, MLX5_IB_ATTR_CREATE_FLOW_MATCH_VALUE, + match_value->match_buf, + match_value->match_sz); + fill_attr_in_obj(cmd, MLX5_IB_ATTR_CREATE_FLOW_MATCHER, flow_matcher->handle); + + type = actions_attr[0].type; + switch (type) { + case MLX5DV_FLOW_ACTION_DEST_IBV_QP: + fill_attr_in_obj(cmd, MLX5_IB_ATTR_CREATE_FLOW_DEST_QP, + actions_attr[0].qp->handle); + break; + default: + errno = EOPNOTSUPP; + goto err; + } + + ret = execute_ioctl(flow_matcher->context, cmd); + if (ret) + goto err; + + mflow->flow_id.handle = read_attr_obj(MLX5_IB_ATTR_CREATE_FLOW_HANDLE, handle); + mflow->flow_id.context = flow_matcher->context; + return &mflow->flow_id; +err: + free(mflow); + return NULL; +}