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 CD91CA0679 for ; Thu, 28 Mar 2019 17:33:16 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 98FCE1B3DD; Thu, 28 Mar 2019 17:33:03 +0100 (CET) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150051.outbound.protection.outlook.com [40.107.15.51]) by dpdk.org (Postfix) with ESMTP id 6BFCC1B3D7 for ; Thu, 28 Mar 2019 17:32:58 +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=l5wZ+s2Bc9xyk6h5pv0QxgebTXJjccIzHREWJc87vGQ=; b=hUHeod90r6yIVbM181VxOtgKlyfyt0U86c/BeqsRNNxCYUf8XBQ/JcuXjDum02WycksswlYSMrkFTfDdd1NAewe7sZKBvl0/yDHqW/4zNt6/dT73367ZH04UIdCxU4QqM4ebZard84aVXAZC/I+O2WxOYWO8bzFMsG3cGtaZI5Q= Received: from AM4PR05MB3425.eurprd05.prod.outlook.com (10.171.190.15) by AM4PR05MB3330.eurprd05.prod.outlook.com (10.171.191.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.18; Thu, 28 Mar 2019 16:32:57 +0000 Received: from AM4PR05MB3425.eurprd05.prod.outlook.com ([fe80::5df0:22de:97f0:3827]) by AM4PR05MB3425.eurprd05.prod.outlook.com ([fe80::5df0:22de:97f0:3827%4]) with mapi id 15.20.1750.014; Thu, 28 Mar 2019 16:32:57 +0000 From: Ori Kam To: Matan Azrad , Yongseok Koh , Shahaf Shuler CC: "dev@dpdk.org" , Ori Kam , Slava Ovsiienko Thread-Topic: [PATCH v2 2/3] net/mlx5: add Direct Rules API Thread-Index: AQHU5YPmLWBm08gmA0WDMrYYTl97+Q== Date: Thu, 28 Mar 2019 16:32:56 +0000 Message-ID: <1553790741-69362-3-git-send-email-orika@mellanox.com> References: <1553096315-91832-1-git-send-email-orika@mellanox.com> <1553790741-69362-1-git-send-email-orika@mellanox.com> In-Reply-To: <1553790741-69362-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: LO2P265CA0362.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a3::14) 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: 6be3c430-2c82-4fc4-522a-08d6b39b08a0 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:AM4PR05MB3330; x-ms-traffictypediagnostic: AM4PR05MB3330: x-microsoft-antispam-prvs: x-forefront-prvs: 0990C54589 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(366004)(376002)(346002)(39860400002)(396003)(199004)(189003)(256004)(4326008)(25786009)(2616005)(2906002)(68736007)(26005)(71200400001)(53946003)(476003)(446003)(6512007)(8936002)(71190400001)(14454004)(8676002)(102836004)(81156014)(3846002)(386003)(50226002)(11346002)(81166006)(36756003)(6116002)(30864003)(6436002)(86362001)(6636002)(99286004)(105586002)(5660300002)(6486002)(54906003)(97736004)(316002)(107886003)(52116002)(106356001)(66066001)(486006)(53936002)(478600001)(7736002)(6506007)(14444005)(4720700003)(76176011)(305945005)(110136005)(186003)(579004)(559001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3330; H:AM4PR05MB3425.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: MSr1wvFk6XL239nG/ormDxF44U8VUgbbyoFNjNy0UyDh3x0Rmprygv9XDDVkRteSuaSdy9vqF9OJLI62HI+GrbbbBf3xddNOnwjoKchxY3MM8LnG4thbaGXCvWUPzsSgUFCygXRPVFyXs3DXwLCD/hTmx1sU6q/61mU2EYca8V5tCzsTM1Z95uM90Ll5C3ciseuguulXgu32qIxBRO9eV/PTZ6bU19j0lzJIVbEvhC8jocb67yNBp/yK60v8KlGfS7N9KmbdpGh89qezND7mqNtqgmRss6FrpV3ojZcjvsbrzr+NU+l9j0xJwj1YyMMOWEHh4JEn3U8lmn//htdYpwq+lDJfZMFOnd/qftHkrBR9YVuwSHGPv2YAi0XLZte4yyiqLzoL5c/594LFXX4dRWN/e8QMKyjs+POMF/VIg3E= 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: 6be3c430-2c82-4fc4-522a-08d6b39b08a0 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Mar 2019 16:32:56.8783 (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: AM4PR05MB3330 Subject: [dpdk-dev] [PATCH v2 2/3] net/mlx5: add Direct Rules API 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: <20190328163256.m3bAfYDTNLXhDRl6MAOuN_UiNyhXEPRMzrbjOQlY73A@z> Adds calls to the Direct Rules API inside the glue functions. Due to difference in parameters between the Direct Rules and Direct Verbs some of the glue functions API was updated. Signed-off-by: Ori Kam --- drivers/net/mlx5/Makefile | 5 ++ drivers/net/mlx5/mlx5.c | 16 ++++ drivers/net/mlx5/mlx5.h | 15 ++++ drivers/net/mlx5/mlx5_flow.c | 1 + drivers/net/mlx5/mlx5_flow.h | 6 +- drivers/net/mlx5/mlx5_flow_dv.c | 103 ++++++++++++++++++++---- drivers/net/mlx5/mlx5_glue.c | 170 ++++++++++++++++++++++++++++++++++--= ---- drivers/net/mlx5/mlx5_glue.h | 31 +++++--- drivers/net/mlx5/mlx5_prm.h | 24 +++++- 9 files changed, 318 insertions(+), 53 deletions(-) diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile index c326494..3dd7e38 100644 --- a/drivers/net/mlx5/Makefile +++ b/drivers/net/mlx5/Makefile @@ -156,6 +156,11 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config= -h.sh func mlx5dv_create_flow_action_packet_reformat \ $(AUTOCONF_OUTPUT) $Q sh -- '$<' '$@' \ + HAVE_MLX5DV_DR \ + infiniband/mlx5dv.h \ + enum MLX5DV_DR_NS_TYPE_TERMINATING \ + $(AUTOCONF_OUTPUT) + $Q sh -- '$<' '$@' \ HAVE_IBV_DEVX_OBJ \ infiniband/mlx5dv.h \ func mlx5dv_devx_obj_create \ diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 7d1a21e..70e37b5 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1362,6 +1362,22 @@ struct mlx5_dev_spawn_data { priv->tcf_context =3D NULL; } } +#ifdef HAVE_MLX5DV_DR + priv->rx_ns =3D mlx5dv_dr_create_ns + (sh->ctx, MLX5DV_DR_NS_DOMAIN_INGRESS_BYPASS); + if (priv->rx_ns =3D=3D NULL) { + DRV_LOG(ERR, "mlx5dv_dr_create_ns failed"); + err =3D errno; + goto error; + } + priv->tx_ns =3D mlx5dv_dr_create_ns(sh->ctx, + MLX5DV_DR_NS_DOMAIN_EGRESS_BYPASS); + if (priv->tx_ns =3D=3D NULL) { + DRV_LOG(ERR, "mlx5dv_dr_create_ns failed"); + err =3D errno; + goto error; + } +#endif TAILQ_INIT(&priv->flows); TAILQ_INIT(&priv->ctrl_flows); /* Hint libmlx5 to use PMD allocator for data plane resources */ diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index b587359..73f6f0d 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -219,6 +219,15 @@ struct mlx5_ibv_shared { struct mlx5_ibv_shared_port port[]; /* per device port data array. */ }; =20 +/* Table structure. */ +struct mlx5_flow_tbl_resource { + void *obj; /**< Pointer to DR table object. */ + rte_atomic32_t refcnt; /**< Reference counter. */ +}; + +#define MLX5_MAX_TABLES 1024 +#define MLX5_GROUP_FACTOR 1 + struct mlx5_priv { LIST_ENTRY(mlx5_priv) mem_event_cb; /**< Called by memory event callback. */ @@ -289,6 +298,12 @@ struct mlx5_priv { /* UAR same-page access control required in 32bit implementations. */ #endif struct mlx5_flow_tcf_context *tcf_context; /* TC flower context. */ + void *rx_ns; /* RX Direct Rules name space handle. */ + struct mlx5_flow_tbl_resource rx_tbl[MLX5_MAX_TABLES]; + /* RX Direct Rules tables. */ + void *tx_ns; /* TX Direct Rules name space handle. */ + struct mlx5_flow_tbl_resource tx_tbl[MLX5_MAX_TABLES]; + /* TX Direct Rules tables/ */ }; =20 #define PORT_ID(priv) ((priv)->dev_data->port_id) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index d09fdff..40d6818 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -2084,6 +2084,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev= *dev, int32_t priority, flow_size +=3D RTE_ALIGN_CEIL(sizeof(uint16_t), sizeof(void *)); flow =3D rte_calloc(__func__, 1, flow_size, 0); flow->drv_type =3D flow_get_drv_type(dev, attr); + flow->ingress =3D attr->ingress; assert(flow->drv_type > MLX5_FLOW_TYPE_MIN && flow->drv_type < MLX5_FLOW_TYPE_MAX); flow->queue =3D (void *)(flow + 1); diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 4f69ae2..8ba37a0 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -204,6 +204,7 @@ struct mlx5_flow_dv_matcher { uint16_t crc; /**< CRC of key. */ uint16_t priority; /**< Priority of matcher. */ uint8_t egress; /**< Egress matcher. */ + uint32_t group; /**< The matcher group. */ struct mlx5_flow_dv_match_params mask; /**< Matcher mask. */ }; =20 @@ -220,6 +221,7 @@ struct mlx5_flow_dv_encap_decap_resource { size_t size; uint8_t reformat_type; uint8_t ft_type; + uint64_t flags; /**< Flags for RDMA API. */ }; =20 /* Tag resource structure. */ @@ -348,7 +350,7 @@ struct mlx5_flow_counter { /* Flow structure. */ struct rte_flow { TAILQ_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */ - enum mlx5_flow_drv_type drv_type; /**< Drvier type. */ + enum mlx5_flow_drv_type drv_type; /**< Driver type. */ struct mlx5_flow_counter *counter; /**< Holds flow counter. */ struct mlx5_flow_dv_tag_resource *tag_resource; /**< pointer to the tag action. */ @@ -360,6 +362,8 @@ struct rte_flow { uint64_t actions; /**< Bit-fields of detected actions, see MLX5_FLOW_ACTION_*. */ struct mlx5_fdir *fdir; /**< Pointer to associated FDIR if any. */ + uint8_t ingress; /**< 1 if the flow is ingress. */ + uint32_t group; /**< The group index. */ }; =20 typedef int (*mlx5_flow_validate_t)(struct rte_eth_dev *dev, diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_d= v.c index b0c50a7..6e4f6c4 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -805,11 +805,20 @@ struct field_modify_info modify_tcp[] =3D { { struct mlx5_priv *priv =3D dev->data->dev_private; struct mlx5_flow_dv_encap_decap_resource *cache_resource; + struct rte_flow *flow =3D dev_flow->flow; + struct mlx5dv_dr_ns *ns; + + resource->flags =3D flow->group ? 0 : 1; + if (flow->ingress) + ns =3D priv->rx_ns; + else + ns =3D priv->tx_ns; =20 /* Lookup a matching resource from cache. */ LIST_FOREACH(cache_resource, &priv->encaps_decaps, next) { if (resource->reformat_type =3D=3D cache_resource->reformat_type && resource->ft_type =3D=3D cache_resource->ft_type && + resource->flags =3D=3D cache_resource->flags && resource->size =3D=3D cache_resource->size && !memcmp((const void *)resource->buf, (const void *)cache_resource->buf, @@ -831,10 +840,10 @@ struct field_modify_info modify_tcp[] =3D { *cache_resource =3D *resource; cache_resource->verbs_action =3D mlx5_glue->dv_create_flow_action_packet_reformat - (priv->sh->ctx, cache_resource->size, - (cache_resource->size ? cache_resource->buf : NULL), - cache_resource->reformat_type, - cache_resource->ft_type); + (priv->sh->ctx, cache_resource->reformat_type, + cache_resource->ft_type, ns, cache_resource->flags, + cache_resource->size, + (cache_resource->size ? cache_resource->buf : NULL)); if (!cache_resource->verbs_action) { rte_free(cache_resource); return rte_flow_error_set(error, ENOMEM, @@ -1438,6 +1447,10 @@ struct field_modify_info modify_tcp[] =3D { struct mlx5_priv *priv =3D dev->data->dev_private; struct mlx5_flow_dv_modify_hdr_resource *cache_resource; =20 + struct mlx5dv_dr_ns *ns =3D + resource->ft_type =3D=3D MLX5DV_FLOW_TABLE_TYPE_NIC_TX ? + priv->tx_ns : priv->rx_ns; + /* Lookup a matching resource from cache. */ LIST_FOREACH(cache_resource, &priv->modify_cmds, next) { if (resource->ft_type =3D=3D cache_resource->ft_type && @@ -1463,11 +1476,11 @@ struct field_modify_info modify_tcp[] =3D { *cache_resource =3D *resource; cache_resource->verbs_action =3D mlx5_glue->dv_create_flow_action_modify_header - (priv->sh->ctx, + (priv->sh->ctx, cache_resource->ft_type, + ns, 0, cache_resource->actions_num * sizeof(cache_resource->actions[0]), - (uint64_t *)cache_resource->actions, - cache_resource->ft_type); + (uint64_t *)cache_resource->actions); if (!cache_resource->verbs_action) { rte_free(cache_resource); return rte_flow_error_set(error, ENOMEM, @@ -1592,11 +1605,13 @@ struct field_modify_info modify_tcp[] =3D { struct mlx5_priv *priv =3D dev->data->dev_private; uint32_t priority_max =3D priv->config.flow_prio - 1; =20 +#ifdef HAVE_MLX5DV_DR if (attributes->group) return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL, "groups is not supported"); +#endif if (attributes->priority !=3D MLX5_FLOW_PRIO_RSVD && attributes->priority >=3D priority_max) return rte_flow_error_set(error, ENOTSUP, @@ -2169,11 +2184,13 @@ struct field_modify_info modify_tcp[] =3D { * Flow pattern to translate. * @param[in] inner * Item is inner pattern. + * @param[in] group + * The group to insert the rule. */ static void flow_dv_translate_item_ipv4(void *matcher, void *key, const struct rte_flow_item *item, - int inner) + int inner, uint32_t group) { const struct rte_flow_item_ipv4 *ipv4_m =3D item->mask; const struct rte_flow_item_ipv4 *ipv4_v =3D item->spec; @@ -2200,7 +2217,10 @@ struct field_modify_info modify_tcp[] =3D { outer_headers); headers_v =3D MLX5_ADDR_OF(fte_match_param, key, outer_headers); } - MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf); + if (group =3D=3D 0) + MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf); + else + MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0x4); MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 4); if (!ipv4_v) return; @@ -2242,11 +2262,13 @@ struct field_modify_info modify_tcp[] =3D { * Flow pattern to translate. * @param[in] inner * Item is inner pattern. + * @param[in] group + * The group to insert the rule. */ static void flow_dv_translate_item_ipv6(void *matcher, void *key, const struct rte_flow_item *item, - int inner) + int inner, uint32_t group) { const struct rte_flow_item_ipv6 *ipv6_m =3D item->mask; const struct rte_flow_item_ipv6 *ipv6_v =3D item->spec; @@ -2283,7 +2305,10 @@ struct field_modify_info modify_tcp[] =3D { outer_headers); headers_v =3D MLX5_ADDR_OF(fte_match_param, key, outer_headers); } - MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf); + if (group =3D=3D 0) + MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0xf); + else + MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 0x6); MLX5_SET(fte_match_set_lyr_2_4, headers_v, ip_version, 6); if (!ipv6_v) return; @@ -2723,7 +2748,11 @@ struct field_modify_info modify_tcp[] =3D { match_criteria_enable |=3D (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT; - +#ifdef HAVE_MLX5DV_DR + match_criteria_enable |=3D + (!HEADER_IS_ZERO(match_criteria, misc_parameters_3)) << + MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT; +#endif return match_criteria_enable; } =20 @@ -2754,12 +2783,14 @@ struct field_modify_info modify_tcp[] =3D { .type =3D IBV_FLOW_ATTR_NORMAL, .match_mask =3D (void *)&matcher->mask, }; + struct mlx5_flow_tbl_resource *tbl =3D NULL; =20 /* Lookup from cache. */ LIST_FOREACH(cache_matcher, &priv->matchers, next) { if (matcher->crc =3D=3D cache_matcher->crc && matcher->priority =3D=3D cache_matcher->priority && matcher->egress =3D=3D cache_matcher->egress && + matcher->group =3D=3D cache_matcher->group && !memcmp((const void *)matcher->mask.buf, (const void *)cache_matcher->mask.buf, cache_matcher->mask.size)) { @@ -2774,6 +2805,27 @@ struct field_modify_info modify_tcp[] =3D { return 0; } } +#ifdef HAVE_MLX5DV_DR + if (matcher->egress) { + tbl =3D &priv->tx_tbl[matcher->group]; + if (!tbl->obj) + tbl->obj =3D mlx5_glue->dr_create_flow_tbl + (priv->tx_ns, + matcher->group * MLX5_GROUP_FACTOR); + } else { + tbl =3D &priv->rx_tbl[matcher->group]; + if (!tbl->obj) + tbl->obj =3D mlx5_glue->dr_create_flow_tbl + (priv->rx_ns, + matcher->group * MLX5_GROUP_FACTOR); + } + if (!tbl->obj) + return rte_flow_error_set(error, ENOMEM, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "cannot create table"); + + rte_atomic32_inc(&tbl->refcnt); +#endif /* Register new matcher. */ cache_matcher =3D rte_calloc(__func__, 1, sizeof(*cache_matcher), 0); if (!cache_matcher) @@ -2787,9 +2839,16 @@ struct field_modify_info modify_tcp[] =3D { if (matcher->egress) dv_attr.flags |=3D IBV_FLOW_ATTR_FLAGS_EGRESS; cache_matcher->matcher_object =3D - mlx5_glue->dv_create_flow_matcher(priv->sh->ctx, &dv_attr); + mlx5_glue->dv_create_flow_matcher(priv->sh->ctx, &dv_attr, + tbl->obj); if (!cache_matcher->matcher_object) { rte_free(cache_matcher); +#ifdef HAVE_MLX5DV_DR + if (rte_atomic32_dec_and_test(&tbl->refcnt)) { + mlx5_glue->dr_destroy_flow_tbl(tbl->obj); + tbl->obj =3D NULL; + } +#endif return rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "cannot create matcher"); @@ -2801,6 +2860,7 @@ struct field_modify_info modify_tcp[] =3D { cache_matcher->priority, cache_matcher->egress ? "tx" : "rx", (void *)cache_matcher, rte_atomic32_read(&cache_matcher->refcnt)); + rte_atomic32_inc(&tbl->refcnt); return 0; } =20 @@ -3222,7 +3282,7 @@ struct field_modify_info modify_tcp[] =3D { break; case RTE_FLOW_ITEM_TYPE_IPV4: flow_dv_translate_item_ipv4(match_mask, match_value, - items, tunnel); + items, tunnel, attr->group); matcher.priority =3D MLX5_PRIORITY_MAP_L3; dev_flow->dv.hash_fields |=3D mlx5_flow_hashfields_adjust @@ -3234,7 +3294,7 @@ struct field_modify_info modify_tcp[] =3D { break; case RTE_FLOW_ITEM_TYPE_IPV6: flow_dv_translate_item_ipv6(match_mask, match_value, - items, tunnel); + items, tunnel, attr->group); matcher.priority =3D MLX5_PRIORITY_MAP_L3; dev_flow->dv.hash_fields |=3D mlx5_flow_hashfields_adjust @@ -3312,6 +3372,7 @@ struct field_modify_info modify_tcp[] =3D { matcher.priority =3D mlx5_flow_adjust_priority(dev, priority, matcher.priority); matcher.egress =3D attr->egress; + matcher.group =3D attr->group; if (flow_dv_matcher_register(dev, &matcher, dev_flow, error)) return -rte_errno; return 0; @@ -3427,6 +3488,8 @@ struct field_modify_info modify_tcp[] =3D { struct mlx5_flow *flow) { struct mlx5_flow_dv_matcher *matcher =3D flow->dv.matcher; + struct mlx5_priv *priv =3D dev->data->dev_private; + struct mlx5_flow_tbl_resource *tbl; =20 assert(matcher->matcher_object); DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--", @@ -3436,6 +3499,14 @@ struct field_modify_info modify_tcp[] =3D { claim_zero(mlx5_glue->dv_destroy_flow_matcher (matcher->matcher_object)); LIST_REMOVE(matcher, next); + if (matcher->egress) + tbl =3D &priv->tx_tbl[matcher->group]; + else + tbl =3D &priv->rx_tbl[matcher->group]; + if (rte_atomic32_dec_and_test(&tbl->refcnt)) { + mlx5_glue->dr_destroy_flow_tbl(tbl->obj); + tbl->obj =3D NULL; + } rte_free(matcher); DRV_LOG(DEBUG, "port %u matcher %p: removed", dev->data->port_id, (void *)matcher); @@ -3525,7 +3596,7 @@ struct field_modify_info modify_tcp[] =3D { LIST_FOREACH(dev_flow, &flow->dev_flows, next) { dv =3D &dev_flow->dv; if (dv->flow) { - claim_zero(mlx5_glue->destroy_flow(dv->flow)); + claim_zero(mlx5_glue->dv_destroy_flow(dv->flow)); dv->flow =3D NULL; } if (dv->hrxq) { diff --git a/drivers/net/mlx5/mlx5_glue.c b/drivers/net/mlx5/mlx5_glue.c index cfd939d..f509f85 100644 --- a/drivers/net/mlx5/mlx5_glue.c +++ b/drivers/net/mlx5/mlx5_glue.c @@ -178,6 +178,9 @@ mlx5_glue_destroy_flow_action(void *action) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_destroy_action(action); +#else struct mlx5dv_flow_action_attr *attr =3D action; int res =3D 0; switch (attr->type) { @@ -189,6 +192,7 @@ } free(action); return res; +#endif #else (void)action; return ENOTSUP; @@ -365,6 +369,53 @@ return ibv_cq_ex_to_cq(cq); } =20 +static void * +mlx5_glue_dr_create_flow_tbl(void *ns, uint32_t level) +{ +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_create_ft(ns, level); +#else + (void)ns; + (void)level; + return NULL; +#endif +} + +static int +mlx5_glue_dr_destroy_flow_tbl(void *tbl) +{ +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_destroy_ft(tbl); +#else + (void)tbl; + return 0; +#endif +} + +static void * +mlx5_glue_dr_create_ns(struct ibv_context *ctx, + enum mlx5dv_dr_ns_domain domain) +{ +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_create_ns(ctx, domain); +#else + (void)ctx; + (void)domain; + return NULL; +#endif +} + +static int +mlx5_glue_dr_destroy_ns(void *ns) +{ +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_destroy_ns(ns); +#else + (void)ns; + return 0; +#endif +} + static struct ibv_cq_ex * mlx5_glue_dv_create_cq(struct ibv_context *context, struct ibv_cq_init_attr_ex *cq_attr, @@ -423,26 +474,40 @@ #endif } =20 -static struct mlx5dv_flow_matcher * +static void * mlx5_glue_dv_create_flow_matcher(struct ibv_context *context, - struct mlx5dv_flow_matcher_attr *matcher_attr) + struct mlx5dv_flow_matcher_attr *matcher_attr, + void *tbl) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT +#ifdef HAVE_MLX5DV_DR + (void)context; + return mlx5dv_dr_create_matcher(tbl, matcher_attr->priority, + matcher_attr->match_criteria_enable, + matcher_attr->match_mask); +#else + (void)tbl; return mlx5dv_create_flow_matcher(context, matcher_attr); +#endif #else (void)context; (void)matcher_attr; + (void)tbl; return NULL; #endif } =20 -static struct ibv_flow * -mlx5_glue_dv_create_flow(struct mlx5dv_flow_matcher *matcher, - struct mlx5dv_flow_match_parameters *match_value, +static void * +mlx5_glue_dv_create_flow(void *matcher, + void *match_value, size_t num_actions, void *actions[]) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_create_rule(matcher, match_value, num_actions, + (struct mlx5dv_dr_action **)actions); +#else struct mlx5dv_flow_action_attr actions_attr[8]; =20 if (num_actions > 8) @@ -452,6 +517,7 @@ *((struct mlx5dv_flow_action_attr *)(actions[i])); return mlx5dv_create_flow(matcher, match_value, num_actions, actions_attr); +#endif #else (void)matcher; (void)match_value; @@ -461,21 +527,13 @@ #endif } =20 -static int -mlx5_glue_dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *matcher) -{ -#ifdef HAVE_IBV_FLOW_DV_SUPPORT - return mlx5dv_destroy_flow_matcher(matcher); -#else - (void)matcher; - return 0; -#endif -} - static void * mlx5_glue_dv_create_flow_action_counter(void *counter_obj, uint32_t offset= ) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_create_action_devx_counter(counter_obj, offset); +#else struct mlx5dv_flow_action_attr *action; =20 (void)offset; @@ -485,6 +543,7 @@ action->type =3D MLX5DV_FLOW_ACTION_COUNTER_DEVX; action->obj =3D counter_obj; return action; +#endif #else (void)counter_obj; (void)offset; @@ -496,6 +555,9 @@ mlx5_glue_dv_create_flow_action_dest_ibv_qp(void *qp) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_create_action_dest_ibv_qp(qp); +#else struct mlx5dv_flow_action_attr *action; =20 action =3D malloc(sizeof(*action)); @@ -504,6 +566,7 @@ action->type =3D MLX5DV_FLOW_ACTION_DEST_IBV_QP; action->obj =3D qp; return action; +#endif #else (void)qp; return NULL; @@ -513,13 +576,22 @@ static void * mlx5_glue_dv_create_flow_action_modify_header (struct ibv_context *ctx, + enum mlx5dv_flow_table_type ft_type, + void *ns, uint64_t flags, size_t actions_sz, - uint64_t actions[], - enum mlx5dv_flow_table_type ft_type) + uint64_t actions[]) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT +#ifdef HAVE_MLX5DV_DR + (void)ctx; + (void)ft_type; + return mlx5dv_dr_create_action_modify_header(ns, flags, actions_sz, + actions); +#else struct mlx5dv_flow_action_attr *action; =20 + (void)ns; + (void)flags; action =3D malloc(sizeof(*action)); if (!action) return NULL; @@ -527,11 +599,14 @@ action->action =3D mlx5dv_create_flow_action_modify_header (ctx, actions_sz, actions, ft_type); return action; +#endif #else (void)ctx; + (void)ft_type; + (void)ns; + (void)flags; (void)actions_sz; (void)actions; - (void)ft_type; return NULL; #endif } @@ -539,12 +614,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) + enum mlx5dv_flow_table_type ft_type, struct mlx5dv_dr_ns *ns, + uint32_t flags, size_t data_sz, void *data) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT +#ifdef HAVE_MLX5DV_DR + (void)ctx; + (void)ft_type; + return mlx5dv_dr_create_action_packet_reformat(ns, flags, + reformat_type, data_sz, + data); +#else + (void)ns; + (void)flags; struct mlx5dv_flow_action_attr *action; =20 action =3D malloc(sizeof(*action)); @@ -554,12 +637,15 @@ action->action =3D mlx5dv_create_flow_action_packet_reformat (ctx, data_sz, data, reformat_type, ft_type); return action; +#endif #else (void)ctx; - (void)data_sz; - (void)data; (void)reformat_type; (void)ft_type; + (void)ns; + (void)flags; + (void)data_sz; + (void)data; return NULL; #endif } @@ -568,6 +654,9 @@ mlx5_glue_dv_create_flow_action_tag(uint32_t tag) { #ifdef HAVE_IBV_FLOW_DV_SUPPORT +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_create_action_tag(tag); +#else struct mlx5dv_flow_action_attr *action; action =3D malloc(sizeof(*action)); if (!action) @@ -576,10 +665,36 @@ action->tag_value =3D tag; return action; #endif +#endif (void)tag; return NULL; } =20 +static int +mlx5_glue_dv_destroy_flow(void *flow_id) +{ +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_destroy_rule(flow_id); +#else + return ibv_destroy_flow(flow_id); +#endif +} + +static int +mlx5_glue_dv_destroy_flow_matcher(void *matcher) +{ +#ifdef HAVE_IBV_FLOW_DV_SUPPORT +#ifdef HAVE_MLX5DV_DR + return mlx5dv_dr_destroy_matcher(matcher); +#else + return mlx5dv_destroy_flow_matcher(matcher); +#endif +#else + (void)matcher; + return 0; +#endif +} + static struct ibv_context * mlx5_glue_dv_open_device(struct ibv_device *device) { @@ -718,6 +833,10 @@ .get_async_event =3D mlx5_glue_get_async_event, .port_state_str =3D mlx5_glue_port_state_str, .cq_ex_to_cq =3D mlx5_glue_cq_ex_to_cq, + .dr_create_flow_tbl =3D mlx5_glue_dr_create_flow_tbl, + .dr_destroy_flow_tbl =3D mlx5_glue_dr_destroy_flow_tbl, + .dr_create_ns =3D mlx5_glue_dr_create_ns, + .dr_destroy_ns =3D mlx5_glue_dr_destroy_ns, .dv_create_cq =3D mlx5_glue_dv_create_cq, .dv_create_wq =3D mlx5_glue_dv_create_wq, .dv_query_device =3D mlx5_glue_dv_query_device, @@ -725,7 +844,6 @@ .dv_init_obj =3D mlx5_glue_dv_init_obj, .dv_create_qp =3D mlx5_glue_dv_create_qp, .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_counter =3D mlx5_glue_dv_create_flow_action_counter, @@ -736,6 +854,8 @@ .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_destroy_flow =3D mlx5_glue_dv_destroy_flow, + .dv_destroy_flow_matcher =3D mlx5_glue_dv_destroy_flow_matcher, .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 167f1f7..7115575 100644 --- a/drivers/net/mlx5/mlx5_glue.h +++ b/drivers/net/mlx5/mlx5_glue.h @@ -63,6 +63,11 @@ struct mlx5dv_devx_obj; #endif =20 +#ifndef HAVE_MLX5DV_DR +struct mlx5dv_dr_ns; +enum mlx5dv_dr_ns_domain { unused, }; +#endif + /* LIB_GLUE_VERSION must be updated every time this structure is modified.= */ struct mlx5_glue { const char *version; @@ -140,6 +145,11 @@ struct mlx5_glue { struct ibv_async_event *event); const char *(*port_state_str)(enum ibv_port_state port_state); struct ibv_cq *(*cq_ex_to_cq)(struct ibv_cq_ex *cq); + void *(*dr_create_flow_tbl)(void *ns, uint32_t level); + int (*dr_destroy_flow_tbl)(void *tbl); + void *(*dr_create_ns)(struct ibv_context *ctx, + enum mlx5dv_dr_ns_domain domain); + int (*dr_destroy_ns)(void *ns); struct ibv_cq_ex *(*dv_create_cq) (struct ibv_context *context, struct ibv_cq_init_attr_ex *cq_attr, @@ -158,23 +168,26 @@ struct mlx5_glue { (struct ibv_context *context, struct ibv_qp_init_attr_ex *qp_init_attr_ex, struct mlx5dv_qp_init_attr *dv_qp_init_attr); - struct mlx5dv_flow_matcher *(*dv_create_flow_matcher) + void *(*dv_create_flow_matcher) (struct ibv_context *context, - struct mlx5dv_flow_matcher_attr *matcher_attr); - 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, + struct mlx5dv_flow_matcher_attr *matcher_attr, + void *tbl); + void *(*dv_create_flow)(void *matcher, void *match_value, 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); + (struct ibv_context *ctx, enum mlx5dv_flow_table_type ft_type, + void *ns, uint64_t flags, size_t actions_sz, + uint64_t actions[]); void *(*dv_create_flow_action_packet_reformat) - (struct ibv_context *ctx, size_t data_sz, void *data, + (struct ibv_context *ctx, enum mlx5dv_flow_action_packet_reformat_type reformat_type, - enum mlx5dv_flow_table_type ft_type); + enum mlx5dv_flow_table_type ft_type, struct mlx5dv_dr_ns *ns, + uint32_t flags, size_t data_sz, void *data); void *(*dv_create_flow_action_tag)(uint32_t tag); + int (*dv_destroy_flow)(void *flow); + int (*dv_destroy_flow_matcher)(void *matcher); struct ibv_context *(*dv_open_device)(struct ibv_device *device); struct mlx5dv_devx_obj *(*devx_obj_create) (struct ibv_context *ctx, diff --git a/drivers/net/mlx5/mlx5_prm.h b/drivers/net/mlx5/mlx5_prm.h index da1219e..b15266f 100644 --- a/drivers/net/mlx5/mlx5_prm.h +++ b/drivers/net/mlx5/mlx5_prm.h @@ -492,20 +492,40 @@ struct mlx5_ifc_fte_match_set_misc2_bits { u8 reserved_at_1a0[0x60]; }; =20 +struct mlx5_ifc_fte_match_set_misc3_bits { + u8 inner_tcp_seq_num[0x20]; + u8 outer_tcp_seq_num[0x20]; + u8 inner_tcp_ack_num[0x20]; + u8 outer_tcp_ack_num[0x20]; + u8 reserved_at_auto1[0x8]; + u8 outer_vxlan_gpe_vni[0x18]; + u8 outer_vxlan_gpe_next_protocol[0x8]; + u8 outer_vxlan_gpe_flags[0x8]; + u8 reserved_at_a8[0x10]; + u8 icmp_header_data[0x20]; + u8 icmpv6_header_data[0x20]; + u8 icmp_type[0x8]; + u8 icmp_code[0x8]; + u8 icmpv6_type[0x8]; + u8 icmpv6_code[0x8]; + u8 reserved_at_1a0[0xe0]; +}; + /* Flow matcher. */ struct mlx5_ifc_fte_match_param_bits { struct mlx5_ifc_fte_match_set_lyr_2_4_bits outer_headers; struct mlx5_ifc_fte_match_set_misc_bits misc_parameters; struct mlx5_ifc_fte_match_set_lyr_2_4_bits inner_headers; struct mlx5_ifc_fte_match_set_misc2_bits misc_parameters_2; - u8 reserved_at_800[0x800]; + struct mlx5_ifc_fte_match_set_misc3_bits misc_parameters_3; }; =20 enum { MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT, MLX5_MATCH_CRITERIA_ENABLE_MISC_BIT, MLX5_MATCH_CRITERIA_ENABLE_INNER_BIT, - MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT + MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT, + MLX5_MATCH_CRITERIA_ENABLE_MISC3_BIT }; =20 enum { --=20 1.8.3.1