From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 3E56CA00E6 for ; Wed, 20 Mar 2019 16:39:17 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9A7621B150; Wed, 20 Mar 2019 16:39:13 +0100 (CET) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80074.outbound.protection.outlook.com [40.107.8.74]) by dpdk.org (Postfix) with ESMTP id E761E1B131 for ; Wed, 20 Mar 2019 16:39:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cRp6ciLAWEr+TX30tWPaNg5bRaCdzF9tiFnNZLZU6qk=; b=idv0M1yO6MJP69WZgtW6kgW5LT4evZ+T1/L2pkFidMka1vLnBMDqeYaFopy0QEgs1qsdIP8nvP5g+bGMAXce38iICzWvkqrGb7wvamAVdzwnj8NFIvx1FpOExDl3kTWjfoRK6d67Pm4XhFyKHW02Bml+vwhSM8XpFHjQP2TXYsc= Received: from AM4PR05MB3425.eurprd05.prod.outlook.com (10.171.190.15) by AM4PR05MB3156.eurprd05.prod.outlook.com (10.171.186.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.14; Wed, 20 Mar 2019 15:39:07 +0000 Received: from AM4PR05MB3425.eurprd05.prod.outlook.com ([fe80::4cb3:d1fa:a6a:1d11]) by AM4PR05MB3425.eurprd05.prod.outlook.com ([fe80::4cb3:d1fa:a6a:1d11%3]) with mapi id 15.20.1709.015; Wed, 20 Mar 2019 15:39:06 +0000 From: Ori Kam To: Shahaf Shuler , Yongseok Koh , Matan Azrad CC: "dev@dpdk.org" , Ori Kam , Slava Ovsiienko Thread-Topic: [PATCH 1/3] net/mlx5: prepare Direct Verbs for Direct Rule Thread-Index: AQHU3zMNBO7tol9WYk2HjvoDIqhSZw== Date: Wed, 20 Mar 2019 15:39:06 +0000 Message-ID: <1553096315-91832-2-git-send-email-orika@mellanox.com> References: <1553096315-91832-1-git-send-email-orika@mellanox.com> In-Reply-To: <1553096315-91832-1-git-send-email-orika@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LNXP123CA0004.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::16) To AM4PR05MB3425.eurprd05.prod.outlook.com (2603:10a6:205:b::15) authentication-results: spf=none (sender IP is ) smtp.mailfrom=orika@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [37.142.13.130] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9449fbc6-3e2d-45e2-786e-08d6ad4a3007 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM4PR05MB3156; x-ms-traffictypediagnostic: AM4PR05MB3156: x-microsoft-antispam-prvs: x-forefront-prvs: 098291215C x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(376002)(136003)(396003)(366004)(51234002)(189003)(199004)(106356001)(99286004)(36756003)(105586002)(53946003)(50226002)(446003)(11346002)(478600001)(4720700003)(305945005)(316002)(6512007)(54906003)(107886003)(110136005)(6636002)(186003)(66066001)(7736002)(26005)(30864003)(71190400001)(14454004)(71200400001)(8936002)(68736007)(76176011)(3846002)(6486002)(52116002)(102836004)(5660300002)(6506007)(386003)(6116002)(4326008)(81166006)(81156014)(476003)(2616005)(486006)(256004)(53936002)(8676002)(86362001)(6436002)(2906002)(97736004)(25786009)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3156; H:AM4PR05MB3425.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: wcnQtwmlgukjj9uiGqmHz2dv9Vfwen+MA92ew4EOdmDskR3SJJ+jSUzVtL11Ah15y3tbGNiuPtpYahoYGk9lFJ6CDFmT7IYVP8ccSefQb6qfJG8aLs7qyCY1PE+T9/WU393j0nBjD6zXu9UThstlwWhTD2jelFRxrbZ2SAEQenOFTXxa132esK2U0M3SQFUanbbF4rmigiphoFQ79vE8inp5e7vlK1KXW6hm87gbnOSmqYO6YJ3aPqKHVdZ6s4oLZwJvcMErukwmxsQJdlBTWAyKH1oxQmR8DV9aqkRJa+ih4JC0Q5HlNt25J00CCRbA2yVdq7FBN9I6zxiTNODyqyGBJKCLnl6f3n/EZZ6wJam2MC3mueqA6L3VLsh5aBzc/zC21rOVGR52eqaqUxHsV+gEuVmTqPPTU8JYf3Pmc14= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9449fbc6-3e2d-45e2-786e-08d6ad4a3007 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Mar 2019 15:39:06.8837 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB3156 Subject: [dpdk-dev] [PATCH 1/3] net/mlx5: prepare Direct Verbs for Direct Rule X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190320153906.-yQ5Ld80wEd6MarXexhZJacQB0_l0uwm9RsiicE-Vng@z> This is the first patch of a series that is designed to enable the Direct Rules API. The main difference between Direct Verbs and Direct Rules from API prespective, is that in Direct Rules each action has it's own create function and the object itself is of type void. In this patch I'm adding functions to generate actions that currenlty are done without create action, and I'm changing the action type to be void *, so in next patches only the glue functions will need to change. Signed-off-by: Ori Kam --- drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_flow.h | 17 +++- drivers/net/mlx5/mlx5_flow_dv.c | 188 ++++++++++++++++++++++++++++--------= ---- drivers/net/mlx5/mlx5_glue.c | 141 ++++++++++++++++++++++++------ drivers/net/mlx5/mlx5_glue.h | 26 +++--- 5 files changed, 278 insertions(+), 96 deletions(-) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 88ffb19..c0aa891 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -239,6 +239,8 @@ struct mlx5_priv { LIST_HEAD(matchers, mlx5_flow_dv_matcher) matchers; LIST_HEAD(encap_decap, mlx5_flow_dv_encap_decap_resource) encaps_decaps; LIST_HEAD(modify_cmd, mlx5_flow_dv_modify_hdr_resource) modify_cmds; + LIST_HEAD(tag, mlx5_flow_dv_tag_resource) tags; + /* Tags resources cache. */ uint32_t link_speed_capa; /* Link speed capabilities. */ struct mlx5_xstats_ctrl xstats_ctrl; /* Extended stats control. */ struct mlx5_stats_ctrl stats_ctrl; /* Stats control. */ diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index e1e798b..4f69ae2 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -214,7 +214,7 @@ struct mlx5_flow_dv_encap_decap_resource { LIST_ENTRY(mlx5_flow_dv_encap_decap_resource) next; /* Pointer to next element. */ rte_atomic32_t refcnt; /**< Reference counter. */ - struct ibv_flow_action *verbs_action; + void *verbs_action; /**< Verbs encap/decap action object. */ uint8_t buf[MLX5_ENCAP_MAX_LEN]; size_t size; @@ -222,6 +222,16 @@ struct mlx5_flow_dv_encap_decap_resource { uint8_t ft_type; }; =20 +/* Tag resource structure. */ +struct mlx5_flow_dv_tag_resource { + LIST_ENTRY(mlx5_flow_dv_tag_resource) next; + /* Pointer to next element. */ + rte_atomic32_t refcnt; /**< Reference counter. */ + void *action; + /**< Verbs tag action object. */ + uint32_t tag; /**< the tag value. */ +}; + /* Number of modification commands. */ #define MLX5_MODIFY_NUM 8 =20 @@ -259,7 +269,7 @@ struct mlx5_flow_dv { /**< Pointer to modify header resource in cache. */ struct ibv_flow *flow; /**< Installed flow. */ #ifdef HAVE_IBV_FLOW_DV_SUPPORT - struct mlx5dv_flow_action_attr actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS]; + void *actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS]; /**< Action list. */ #endif int actions_n; /**< number of actions. */ @@ -332,6 +342,7 @@ struct mlx5_flow_counter { }; uint64_t hits; /**< Number of packets matched by the rule. */ uint64_t bytes; /**< Number of bytes matched by the rule. */ + void *action; /**< Pointer to the dv action. */ }; =20 /* Flow structure. */ @@ -339,6 +350,8 @@ struct rte_flow { TAILQ_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */ enum mlx5_flow_drv_type drv_type; /**< Drvier type. */ struct mlx5_flow_counter *counter; /**< Holds flow counter. */ + struct mlx5_flow_dv_tag_resource *tag_resource; + /**< pointer to the tag action. */ struct rte_flow_action_rss rss;/**< RSS context. */ uint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */ uint16_t (*queue)[]; /**< Destination queues to redirect traffic to. */ diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_d= v.c index ebcdd15..0eb3a28 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -32,13 +32,8 @@ #include "mlx5_prm.h" #include "mlx5_glue.h" #include "mlx5_flow.h" - #ifdef HAVE_IBV_FLOW_DV_SUPPORT =20 -#ifndef HAVE_IBV_FLOW_DEVX_COUNTERS -#define MLX5DV_FLOW_ACTION_COUNTER_DEVX 0 -#endif - union flow_dv_attr { struct { uint32_t valid:1; @@ -1537,6 +1532,11 @@ struct field_modify_info modify_tcp[] =3D { .id =3D id, .dcs =3D dcs, }; + tmpl.action =3D mlx5_glue->dv_create_flow_action_counter(dcs->obj, 0); + if (!tmpl.action) { + ret =3D errno; + goto error_exit; + } *cnt =3D tmpl; LIST_INSERT_HEAD(&priv->flow_counters, cnt, next); return cnt; @@ -2805,6 +2805,97 @@ struct field_modify_info modify_tcp[] =3D { } =20 /** + * Find existing tag resource or create and register a new one. + * + * @param dev[in, out] + * Pointer to rte_eth_dev structure. + * @param[in, out] resource + * Pointer to tag resource. + * @parm[in, out] dev_flow + * Pointer to the dev_flow. + * @param[out] error + * pointer to error structure. + * + * @return + * 0 on success otherwise -errno and errno is set. + */ +static int +flow_dv_tag_resource_register + (struct rte_eth_dev *dev, + struct mlx5_flow_dv_tag_resource *resource, + struct mlx5_flow *dev_flow, + struct rte_flow_error *error) +{ + struct mlx5_priv *priv =3D dev->data->dev_private; + struct mlx5_flow_dv_tag_resource *cache_resource; + + /* Lookup a matching resource from cache. */ + LIST_FOREACH(cache_resource, &priv->tags, next) { + if (resource->tag =3D=3D cache_resource->tag) { + DRV_LOG(DEBUG, "tag resource %p: refcnt %d++", + (void *)cache_resource, + rte_atomic32_read(&cache_resource->refcnt)); + rte_atomic32_inc(&cache_resource->refcnt); + dev_flow->flow->tag_resource =3D cache_resource; + return 0; + } + } + /* Register new resource. */ + cache_resource =3D rte_calloc(__func__, 1, sizeof(*cache_resource), 0); + if (!cache_resource) + return rte_flow_error_set(error, ENOMEM, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "cannot allocate resource memory"); + *cache_resource =3D *resource; + cache_resource->action =3D mlx5_glue->dv_create_flow_action_tag + (resource->tag); + if (!cache_resource->action) { + rte_free(cache_resource); + return rte_flow_error_set(error, ENOMEM, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "cannot create action"); + } + rte_atomic32_init(&cache_resource->refcnt); + rte_atomic32_inc(&cache_resource->refcnt); + LIST_INSERT_HEAD(&priv->tags, cache_resource, next); + dev_flow->flow->tag_resource =3D cache_resource; + DRV_LOG(DEBUG, "new tag resource %p: refcnt %d++", + (void *)cache_resource, + rte_atomic32_read(&cache_resource->refcnt)); + return 0; +} + +/** + * Release the tag. + * + * @param dev + * Pointer to Ethernet device. + * @param flow + * Pointer to mlx5_flow. + * + * @return + * 1 while a reference on it exists, 0 when freed. + */ +static int +flow_dv_tag_release(struct rte_eth_dev *dev, + struct mlx5_flow_dv_tag_resource *tag) +{ + assert(tag); + DRV_LOG(DEBUG, "port %u tag %p: refcnt %d--", + dev->data->port_id, (void *)tag, + rte_atomic32_read(&tag->refcnt)); + if (rte_atomic32_dec_and_test(&tag->refcnt)) { + claim_zero(mlx5_glue->destroy_flow_action(tag->action)); + LIST_REMOVE(tag, next); + DRV_LOG(DEBUG, "port %u tag %p: removed", + dev->data->port_id, (void *)tag); + rte_free(tag); + return 0; + } + return 1; +} + +/** * Fill the flow with DV spec. * * @param[in] dev @@ -2849,6 +2940,7 @@ struct field_modify_info modify_tcp[] =3D { MLX5DV_FLOW_TABLE_TYPE_NIC_RX }; union flow_dv_attr flow_attr =3D { .attr =3D 0 }; + struct mlx5_flow_dv_tag_resource tag_resource; =20 if (priority =3D=3D MLX5_FLOW_PRIO_RSVD) priority =3D priv->config.flow_prio - 1; @@ -2863,26 +2955,29 @@ struct field_modify_info modify_tcp[] =3D { case RTE_FLOW_ACTION_TYPE_VOID: break; case RTE_FLOW_ACTION_TYPE_FLAG: - dev_flow->dv.actions[actions_n].type =3D - MLX5DV_FLOW_ACTION_TAG; - dev_flow->dv.actions[actions_n].tag_value =3D + tag_resource.tag =3D mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT); - actions_n++; + if (!flow->tag_resource) + if (flow_dv_tag_resource_register + (dev, &tag_resource, dev_flow, error)) + return errno; + dev_flow->dv.actions[actions_n++] =3D + flow->tag_resource->action; action_flags |=3D MLX5_FLOW_ACTION_FLAG; break; case RTE_FLOW_ACTION_TYPE_MARK: - dev_flow->dv.actions[actions_n].type =3D - MLX5DV_FLOW_ACTION_TAG; - dev_flow->dv.actions[actions_n].tag_value =3D - mlx5_flow_mark_set - (((const struct rte_flow_action_mark *) - (actions->conf))->id); - actions_n++; + tag_resource.tag =3D mlx5_flow_mark_set + (((const struct rte_flow_action_mark *) + (actions->conf))->id); + if (!flow->tag_resource) + if (flow_dv_tag_resource_register + (dev, &tag_resource, dev_flow, error)) + return errno; + dev_flow->dv.actions[actions_n++] =3D + flow->tag_resource->action; action_flags |=3D MLX5_FLOW_ACTION_MARK; break; case RTE_FLOW_ACTION_TYPE_DROP: - dev_flow->dv.actions[actions_n].type =3D - MLX5DV_FLOW_ACTION_DROP; action_flags |=3D MLX5_FLOW_ACTION_DROP; break; case RTE_FLOW_ACTION_TYPE_QUEUE: @@ -2910,17 +3005,13 @@ struct field_modify_info modify_tcp[] =3D { rte_errno =3D ENOTSUP; goto cnt_err; } - flow->counter =3D - flow_dv_counter_new(dev, - count->shared, count->id); + flow->counter =3D flow_dv_counter_new(dev, count->shared, + count->id); if (flow->counter =3D=3D NULL) goto cnt_err; - dev_flow->dv.actions[actions_n].type =3D - MLX5DV_FLOW_ACTION_COUNTER_DEVX; - dev_flow->dv.actions[actions_n].obj =3D - flow->counter->dcs->obj; + dev_flow->dv.actions[actions_n++] =3D + flow->counter->action; action_flags |=3D MLX5_FLOW_ACTION_COUNT; - ++actions_n; break; cnt_err: if (rte_errno =3D=3D ENOTSUP) @@ -2941,11 +3032,8 @@ struct field_modify_info modify_tcp[] =3D { if (flow_dv_create_action_l2_encap(dev, actions, dev_flow, error)) return -rte_errno; - dev_flow->dv.actions[actions_n].type =3D - MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION; - dev_flow->dv.actions[actions_n].action =3D + dev_flow->dv.actions[actions_n++] =3D dev_flow->dv.encap_decap->verbs_action; - actions_n++; action_flags |=3D actions->type =3D=3D RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP ? MLX5_FLOW_ACTION_VXLAN_ENCAP : @@ -2956,11 +3044,8 @@ struct field_modify_info modify_tcp[] =3D { if (flow_dv_create_action_l2_decap(dev, dev_flow, error)) return -rte_errno; - dev_flow->dv.actions[actions_n].type =3D - MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION; - dev_flow->dv.actions[actions_n].action =3D + dev_flow->dv.actions[actions_n++] =3D dev_flow->dv.encap_decap->verbs_action; - actions_n++; action_flags |=3D actions->type =3D=3D RTE_FLOW_ACTION_TYPE_VXLAN_DECAP ? MLX5_FLOW_ACTION_VXLAN_DECAP : @@ -2972,9 +3057,7 @@ struct field_modify_info modify_tcp[] =3D { if (flow_dv_create_action_raw_encap (dev, actions, dev_flow, attr, error)) return -rte_errno; - dev_flow->dv.actions[actions_n].type =3D - MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION; - dev_flow->dv.actions[actions_n].action =3D + dev_flow->dv.actions[actions_n++] =3D dev_flow->dv.encap_decap->verbs_action; } else { /* Handle encap without preceding decap. */ @@ -2982,12 +3065,9 @@ struct field_modify_info modify_tcp[] =3D { dev_flow, error)) return -rte_errno; - dev_flow->dv.actions[actions_n].type =3D - MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION; - dev_flow->dv.actions[actions_n].action =3D + dev_flow->dv.actions[actions_n++] =3D dev_flow->dv.encap_decap->verbs_action; } - actions_n++; action_flags |=3D MLX5_FLOW_ACTION_RAW_ENCAP; break; case RTE_FLOW_ACTION_TYPE_RAW_DECAP: @@ -3002,11 +3082,8 @@ struct field_modify_info modify_tcp[] =3D { dev_flow, error)) return -rte_errno; - dev_flow->dv.actions[actions_n].type =3D - MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION; - dev_flow->dv.actions[actions_n].action =3D + dev_flow->dv.actions[actions_n++] =3D dev_flow->dv.encap_decap->verbs_action; - actions_n++; } /* If decap is followed by encap, handle it at encap. */ action_flags |=3D MLX5_FLOW_ACTION_RAW_DECAP; @@ -3075,11 +3152,8 @@ struct field_modify_info modify_tcp[] =3D { dev_flow, error)) return -rte_errno; - dev_flow->dv.actions[actions_n].type =3D - MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION; - dev_flow->dv.actions[actions_n].action =3D + dev_flow->dv.actions[actions_n++] =3D dev_flow->dv.modify_hdr->verbs_action; - actions_n++; } break; default: @@ -3241,9 +3315,9 @@ struct field_modify_info modify_tcp[] =3D { "cannot get drop hash queue"); goto error; } - dv->actions[n].type =3D MLX5DV_FLOW_ACTION_DEST_IBV_QP; - dv->actions[n].qp =3D dv->hrxq->qp; - n++; + dv->actions[n++] =3D + mlx5_glue->dv_create_flow_action_dest_ibv_qp + (dv->hrxq->qp); } else if (flow->actions & (MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)) { struct mlx5_hrxq *hrxq; @@ -3268,9 +3342,9 @@ struct field_modify_info modify_tcp[] =3D { goto error; } dv->hrxq =3D hrxq; - dv->actions[n].type =3D MLX5DV_FLOW_ACTION_DEST_IBV_QP; - dv->actions[n].qp =3D hrxq->qp; - n++; + dv->actions[n++] =3D + mlx5_glue->dv_create_flow_action_dest_ibv_qp + (dv->hrxq->qp); } dv->flow =3D mlx5_glue->dv_create_flow(dv->matcher->matcher_object, @@ -3448,6 +3522,10 @@ struct field_modify_info modify_tcp[] =3D { flow_dv_counter_release(flow->counter); flow->counter =3D NULL; } + if (flow->tag_resource) { + flow_dv_tag_release(dev, flow->tag_resource); + flow->tag_resource =3D NULL; + } while (!LIST_EMPTY(&flow->dev_flows)) { dev_flow =3D LIST_FIRST(&flow->dev_flows); LIST_REMOVE(dev_flow, next); diff --git a/drivers/net/mlx5/mlx5_glue.c b/drivers/net/mlx5/mlx5_glue.c index c817d86..cfd939d 100644 --- a/drivers/net/mlx5/mlx5_glue.c +++ b/drivers/net/mlx5/mlx5_glue.c @@ -175,10 +175,20 @@ } =20 static int -mlx5_glue_destroy_flow_action(struct ibv_flow_action *action) +mlx5_glue_destroy_flow_action(void *action) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT - return ibv_destroy_flow_action(action); + struct mlx5dv_flow_action_attr *attr =3D action; + int res =3D 0; + switch (attr->type) { + case MLX5DV_FLOW_ACTION_TAG: + break; + default: + res =3D ibv_destroy_flow_action(attr->action); + break; + } + free(action); + return res; #else (void)action; return ENOTSUP; @@ -430,16 +440,23 @@ mlx5_glue_dv_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) + void *actions[]) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT + struct mlx5dv_flow_action_attr actions_attr[8]; + + if (num_actions > 8) + return NULL; + for (size_t i =3D 0; i < num_actions; i++) + actions_attr[i] =3D + *((struct mlx5dv_flow_action_attr *)(actions[i])); return mlx5dv_create_flow(matcher, match_value, num_actions, actions_attr); #else (void)matcher; (void)match_value; (void)num_actions; - (void)actions_attr; + (void)actions; return NULL; #endif } @@ -455,31 +472,45 @@ #endif } =20 -static struct ibv_flow_action * -mlx5_glue_dv_create_flow_action_packet_reformat - (struct ibv_context *ctx, - size_t data_sz, - void *data, - enum mlx5dv_flow_action_packet_reformat_type reformat_type, - enum mlx5dv_flow_table_type ft_type) +static void * +mlx5_glue_dv_create_flow_action_counter(void *counter_obj, uint32_t offset= ) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT - return mlx5dv_create_flow_action_packet_reformat(ctx, - data_sz, - data, - reformat_type, - ft_type); + struct mlx5dv_flow_action_attr *action; + + (void)offset; + action =3D malloc(sizeof(*action)); + if (!action) + return NULL; + action->type =3D MLX5DV_FLOW_ACTION_COUNTER_DEVX; + action->obj =3D counter_obj; + return action; #else - (void)ctx; - (void)data_sz; - (void)data; - (void)reformat_type; - (void)ft_type; + (void)counter_obj; + (void)offset; return NULL; #endif } =20 -static struct ibv_flow_action * +static void * +mlx5_glue_dv_create_flow_action_dest_ibv_qp(void *qp) +{ +#ifdef HAVE_IBV_FLOW_DV_SUPPORT + struct mlx5dv_flow_action_attr *action; + + action =3D malloc(sizeof(*action)); + if (!action) + return NULL; + action->type =3D MLX5DV_FLOW_ACTION_DEST_IBV_QP; + action->obj =3D qp; + return action; +#else + (void)qp; + return NULL; +#endif +} + +static void * mlx5_glue_dv_create_flow_action_modify_header (struct ibv_context *ctx, size_t actions_sz, @@ -487,8 +518,15 @@ enum mlx5dv_flow_table_type ft_type) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT - return mlx5dv_create_flow_action_modify_header(ctx, actions_sz, - actions, ft_type); + struct mlx5dv_flow_action_attr *action; + + action =3D malloc(sizeof(*action)); + if (!action) + return NULL; + action->type =3D MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION; + action->action =3D mlx5dv_create_flow_action_modify_header + (ctx, actions_sz, actions, ft_type); + return action; #else (void)ctx; (void)actions_sz; @@ -498,6 +536,50 @@ #endif } =20 +static void * +mlx5_glue_dv_create_flow_action_packet_reformat + (struct ibv_context *ctx, + size_t data_sz, + void *data, + enum mlx5dv_flow_action_packet_reformat_type reformat_type, + enum mlx5dv_flow_table_type ft_type) +{ +#ifdef HAVE_IBV_FLOW_DV_SUPPORT + struct mlx5dv_flow_action_attr *action; + + action =3D malloc(sizeof(*action)); + if (!action) + return NULL; + action->type =3D MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION; + action->action =3D mlx5dv_create_flow_action_packet_reformat + (ctx, data_sz, data, reformat_type, ft_type); + return action; +#else + (void)ctx; + (void)data_sz; + (void)data; + (void)reformat_type; + (void)ft_type; + return NULL; +#endif +} + +static void * +mlx5_glue_dv_create_flow_action_tag(uint32_t tag) +{ +#ifdef HAVE_IBV_FLOW_DV_SUPPORT + struct mlx5dv_flow_action_attr *action; + action =3D malloc(sizeof(*action)); + if (!action) + return NULL; + action->type =3D MLX5DV_FLOW_ACTION_TAG; + action->tag_value =3D tag; + return action; +#endif + (void)tag; + return NULL; +} + static struct ibv_context * mlx5_glue_dv_open_device(struct ibv_device *device) { @@ -645,10 +727,15 @@ .dv_create_flow_matcher =3D mlx5_glue_dv_create_flow_matcher, .dv_destroy_flow_matcher =3D mlx5_glue_dv_destroy_flow_matcher, .dv_create_flow =3D mlx5_glue_dv_create_flow, - .dv_create_flow_action_packet_reformat =3D - mlx5_glue_dv_create_flow_action_packet_reformat, + .dv_create_flow_action_counter =3D + mlx5_glue_dv_create_flow_action_counter, + .dv_create_flow_action_dest_ibv_qp =3D + mlx5_glue_dv_create_flow_action_dest_ibv_qp, .dv_create_flow_action_modify_header =3D - mlx5_glue_dv_create_flow_action_modify_header, + mlx5_glue_dv_create_flow_action_modify_header, + .dv_create_flow_action_packet_reformat =3D + mlx5_glue_dv_create_flow_action_packet_reformat, + .dv_create_flow_action_tag =3D mlx5_glue_dv_create_flow_action_tag, .dv_open_device =3D mlx5_glue_dv_open_device, .devx_obj_create =3D mlx5_glue_devx_obj_create, .devx_obj_destroy =3D mlx5_glue_devx_obj_destroy, diff --git a/drivers/net/mlx5/mlx5_glue.h b/drivers/net/mlx5/mlx5_glue.h index b118960..167f1f7 100644 --- a/drivers/net/mlx5/mlx5_glue.h +++ b/drivers/net/mlx5/mlx5_glue.h @@ -55,6 +55,10 @@ enum mlx5dv_flow_table_type { flow_table_type =3D 0, }; #endif =20 +#ifndef HAVE_IBV_FLOW_DEVX_COUNTERS +#define MLX5DV_FLOW_ACTION_COUNTER_DEVX 0 +#endif + #ifndef HAVE_IBV_DEVX_OBJ struct mlx5dv_devx_obj; #endif @@ -98,7 +102,7 @@ struct mlx5_glue { struct ibv_flow *(*create_flow)(struct ibv_qp *qp, struct ibv_flow_attr *flow); int (*destroy_flow)(struct ibv_flow *flow_id); - int (*destroy_flow_action)(struct ibv_flow_action *action); + int (*destroy_flow_action)(void *action); struct ibv_qp *(*create_qp)(struct ibv_pd *pd, struct ibv_qp_init_attr *qp_init_attr); struct ibv_qp *(*create_qp_ex) @@ -160,19 +164,17 @@ struct mlx5_glue { int (*dv_destroy_flow_matcher)(struct mlx5dv_flow_matcher *matcher); struct ibv_flow *(*dv_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 *(*dv_create_flow_action_packet_reformat) - (struct ibv_context *ctx, - size_t data_sz, - void *data, + size_t num_actions, void *actions[]); + void *(*dv_create_flow_action_counter)(void *obj, uint32_t offset); + void *(*dv_create_flow_action_dest_ibv_qp)(void *qp); + void *(*dv_create_flow_action_modify_header) + (struct ibv_context *ctx, size_t actions_sz, uint64_t actions[], + enum mlx5dv_flow_table_type ft_type); + void *(*dv_create_flow_action_packet_reformat) + (struct ibv_context *ctx, size_t data_sz, void *data, enum mlx5dv_flow_action_packet_reformat_type reformat_type, enum mlx5dv_flow_table_type ft_type); - struct ibv_flow_action *(*dv_create_flow_action_modify_header) - (struct ibv_context *ctx, - size_t actions_sz, - uint64_t actions[], - enum mlx5dv_flow_table_type ft_type); + void *(*dv_create_flow_action_tag)(uint32_t tag); struct ibv_context *(*dv_open_device)(struct ibv_device *device); struct mlx5dv_devx_obj *(*devx_obj_create) (struct ibv_context *ctx, --=20 1.8.3.1