From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10050.outbound.protection.outlook.com [40.107.1.50]) by dpdk.org (Postfix) with ESMTP id 4D8E31B113 for ; Tue, 25 Sep 2018 01:18:07 +0200 (CEST) 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=ZwrlPraEIvkhXlhZTSi4GgjGy43NrYoVHPNg8mDV1Hs=; b=QOgvUQhqiezzv/f7rTBTXxli+HQtYOS+92uzvEkn4CpGFt0ZYJXzBBoKhJesEZjOyhZjgQvl2YR652wNWdiFmPTPiY24tFeLORF2UY71eQDbGThpbbOVABEVUYWsPAs2LJ84IO7S/ATKaYZMS6gMQvP8VKi2Wxkfi004BVGn4PU= Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com (52.134.72.27) by DB3PR0502MB3996.eurprd05.prod.outlook.com (52.134.65.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.25; Mon, 24 Sep 2018 23:18:06 +0000 Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com ([fe80::1cb0:661b:ecab:6045]) by DB3PR0502MB3980.eurprd05.prod.outlook.com ([fe80::1cb0:661b:ecab:6045%2]) with mapi id 15.20.1164.017; Mon, 24 Sep 2018 23:18:06 +0000 From: Yongseok Koh To: Thomas Monjalon , Shahaf Shuler CC: "dev@dpdk.org" , Ori Kam Thread-Topic: [PATCH v3 10/11] net/mlx5: add Direct Verbs final functions Thread-Index: AQHUVFzRjEBP2fBfhE2PC/JzgLidBg== Date: Mon, 24 Sep 2018 23:17:52 +0000 Message-ID: <20180924231721.15799-11-yskoh@mellanox.com> References: <20180919072143.23211-1-yskoh@mellanox.com> <20180924231721.15799-1-yskoh@mellanox.com> In-Reply-To: <20180924231721.15799-1-yskoh@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR03CA0021.namprd03.prod.outlook.com (2603:10b6:404:23::31) To DB3PR0502MB3980.eurprd05.prod.outlook.com (2603:10a6:8:10::27) authentication-results: spf=none (sender IP is ) smtp.mailfrom=yskoh@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [209.116.155.178] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB3PR0502MB3996; 6:tfNrgYZwt4M5OGKAAewaNP7TSLhRxQSh2MDRYzYsU2cJtv7jur1TPWq3kGDbm+npG0sOlvUwLCcGYYX0AeqMHUxqxhQYvA8j7+G20r+M6Xs1Macwck5ZAMb4y/bWUHSGkTGn7PEsdIVlEVWmHPqxqwxcW4Gta5G+6WsBSXTy84GXGTuaUuMydlNvX0Dv/frdjJMVtULgjzIHS72iOqD13eZd4ZBjWTG6m5mD7SSx1BDaEAU8fH+ZSNYp0culWUwP7HGnUKhFvJy5Li/2vYF9PT3gFtFb+o1lrMKhHtNxUra1T0Fdvt670DUWgj+O8luLz7eAoR1RAeftzkC6aKqmCRDsc6QDsbQ+huxmZYy0BbDlaYduajL1DBGP/NzD21e8KpS+xmbefHELf/+cijQ5qI7+m1HiuPR+d1bZpy1lxnXVbLY0aeekh79EYoiDZaY26gxO0tSwhHmhh4s4HxwEdA==; 5:Sew9hS0XZKpymmXCVQBw4tp7wc8BZ9acb1oX7t6ye4Z8Tf2l9HAFtMJqjGaBH9wQ8R2sgclKQFnSQpq8/W/hL/XdZqRdgvwyzmLr1OV2vGAS4c+9I3HQU9YSYQvBNBSQemRc/uNh9KZPUCx9Gtaf2QnFEGO3SAqa4wAtYqR/ghY=; 7:0QqRFhZUwaPOfbXnjhV4RfYrmu5ZgZIieCBCGMfJD0jkEOU+xulLrcgjQuoh5ggkC2rdb7vkJiNv2TEOll9VOfo4lfxsJFd5+xxujYcC5QU08Q7RwEogcUzLrR6+dkC/MLFKe4BSEj98Dw1La7UecKTxESiVCQgHp1poXjldJ4oVaUhhj7yKr01pDmOxcyBx0N48cA6WHfx47oCVE0qbUzeWw+IvPP6tX6KIPJ6at73Z8tpif+UDf8SgyJuELjtn x-ms-office365-filtering-correlation-id: 712efcb8-37b2-4527-5e08-08d62273f39d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DB3PR0502MB3996; x-ms-traffictypediagnostic: DB3PR0502MB3996: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231355)(944501410)(52105095)(6055026)(149066)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(201708071742011)(7699051); SRVR:DB3PR0502MB3996; BCL:0; PCL:0; RULEID:; SRVR:DB3PR0502MB3996; x-forefront-prvs: 0805EC9467 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(1496009)(396003)(376002)(346002)(366004)(39860400002)(136003)(199004)(189003)(66066001)(2616005)(476003)(446003)(486006)(11346002)(6436002)(305945005)(7736002)(575784001)(386003)(6506007)(6486002)(6512007)(186003)(102836004)(5250100002)(76176011)(25786009)(26005)(68736007)(6116002)(54906003)(110136005)(99286004)(1076002)(3846002)(71200400001)(52116002)(86362001)(53936002)(71190400001)(97736004)(8936002)(107886003)(14444005)(256004)(4326008)(316002)(2900100001)(81156014)(8676002)(36756003)(81166006)(105586002)(2906002)(106356001)(6636002)(478600001)(5660300001)(14454004)(6666003); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR0502MB3996; H:DB3PR0502MB3980.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-microsoft-antispam-message-info: UpapwfWVzwAckIcYCDm8oPh+MnxmMgP9YUvXR4GefOEKQyWjI5C1IRlN5osdY8sZIJ6v179ZzNVjuo6EOjvEWVhnrnO2rMjOsLTEXwvwB+A0PPHBeaKvno1RxV823EqrfuubFgaTJMscmo7NPb2ML9UzKil11CkE1gAZrSUNEQhZ6Jn9T30YO2v1kYjdQvu1riJVh7SzO1QAVtpT6jZ7vx7F5vRo0tANIz4NFJdkhkvT5ekkXm25NrzkVt/3t/YY/M+YJIGy/d7exH7vavUuYlI4vssV02H/YIO+LlcrJoric3via5GkARIhnxv/OV12B1yonItS0WBGNM3wXK2MnLCdbVMYZ57hr9kpnRgjpQo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 712efcb8-37b2-4527-5e08-08d62273f39d X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Sep 2018 23:17:52.7638 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0502MB3996 Subject: [dpdk-dev] [PATCH v3 10/11] net/mlx5: add Direct Verbs final functions 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: , X-List-Received-Date: Mon, 24 Sep 2018 23:18:07 -0000 From: Ori Kam This commits add the missing function which are apply, remove, and destroy. Signed-off-by: Ori Kam Acked-by: Yongseok Koh --- drivers/net/mlx5/mlx5_flow.c | 4 + drivers/net/mlx5/mlx5_flow.h | 2 + drivers/net/mlx5/mlx5_flow_dv.c | 192 ++++++++++++++++++++++++++++++++++++= +++- 3 files changed, 194 insertions(+), 4 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 5632e31c5..c6c145021 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -2489,5 +2489,9 @@ mlx5_dev_filter_ctrl(struct rte_eth_dev *dev, void mlx5_flow_init_driver_ops(struct rte_eth_dev *dev __rte_unused) { +#ifdef HAVE_IBV_FLOW_DV_SUPPORT + mlx5_flow_dv_get_driver_ops(&nic_ops); +#else mlx5_flow_verbs_get_driver_ops(&nic_ops); +#endif } diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index ec860ef4b..53c0eeb56 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -189,7 +189,9 @@ struct mlx5_flow { struct rte_flow *flow; /**< Pointer to the main flow. */ uint32_t layers; /**< Bit-fields that holds the detected layers. */ union { +#ifdef HAVE_IBV_FLOW_DV_SUPPORT struct mlx5_flow_dv dv; +#endif struct mlx5_flow_verbs verbs; }; }; diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_d= v.c index 916989988..71af410b2 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -2,6 +2,7 @@ * Copyright 2018 Mellanox Technologies, Ltd */ =20 + #include #include #include @@ -1095,7 +1096,7 @@ flow_dv_matcher_register(struct rte_eth_dev *dev, if (matcher->egress) dv_attr.flags |=3D IBV_FLOW_ATTR_FLAGS_EGRESS; cache->cache.resource =3D - mlx5dv_create_flow_matcher(priv->ctx, &dv_attr); + mlx5_glue->dv_create_flow_matcher(priv->ctx, &dv_attr); if (!cache->cache.resource) return rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, @@ -1168,6 +1169,189 @@ flow_dv_translate(struct rte_eth_dev *dev, } =20 /** + * Apply the flow to the NIC. + * + * @param[in] dev + * Pointer to the Ethernet device structure. + * @param[in, out] flow + * Pointer to flow structure. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow, + struct rte_flow_error *error) +{ + struct mlx5_flow_dv *dv; + struct mlx5_flow *dev_flow; + int n; + int err; + + LIST_FOREACH(dev_flow, &flow->dev_flows, next) { + dv =3D &dev_flow->dv; + n =3D dv->actions_n; + if (flow->actions & MLX5_ACTION_DROP) { + dv->hrxq =3D mlx5_hrxq_drop_new(dev); + if (!dv->hrxq) { + rte_flow_error_set + (error, errno, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "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++; + } else { + struct mlx5_hrxq *hrxq; + hrxq =3D mlx5_hrxq_get(dev, flow->key, + MLX5_RSS_HASH_KEY_LEN, + dv->hash_fields, + (*flow->queue), + flow->rss.queue_num); + if (!hrxq) + hrxq =3D mlx5_hrxq_new + (dev, flow->key, MLX5_RSS_HASH_KEY_LEN, + dv->hash_fields, (*flow->queue), + flow->rss.queue_num, + !!(flow->layers & + MLX5_FLOW_LAYER_TUNNEL)); + if (!hrxq) { + rte_flow_error_set + (error, rte_errno, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "cannot get hash queue"); + 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->flow =3D + mlx5_glue->dv_create_flow(dv->matcher->cache.resource, + (void *)&dv->value, n, + dv->actions); + if (!dv->flow) { + rte_flow_error_set(error, errno, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "hardware refuses to create flow"); + goto error; + } + } + return 0; +error: + err =3D rte_errno; /* Save rte_errno before cleanup. */ + LIST_FOREACH(dev_flow, &flow->dev_flows, next) { + struct mlx5_flow_dv *dv =3D &dev_flow->dv; + if (dv->hrxq) { + if (flow->actions & MLX5_FLOW_FATE_DROP) + mlx5_hrxq_drop_release(dev); + else + mlx5_hrxq_release(dev, dv->hrxq); + dv->hrxq =3D NULL; + } + } + rte_errno =3D err; /* Restore rte_errno. */ + return -rte_errno; +} + +/** + * Release the flow matcher. + * + * @param dev + * Pointer to Ethernet device. + * @param matcher + * Pointer to flow matcher. + * + * @return + * 1 while a reference on it exists, 0 when freed. + */ +static int +flow_dv_matcher_release(struct rte_eth_dev *dev, + struct mlx5_flow_dv_matcher *matcher) +{ + struct mlx5_cache *cache =3D &matcher->cache; + + assert(cache->resource); + DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--", + dev->data->port_id, (void *)cache, + rte_atomic32_read(&cache->refcnt)); + if (rte_atomic32_dec_and_test(&cache->refcnt)) { + claim_zero(mlx5_glue->dv_destroy_flow_matcher(cache->resource)); + LIST_REMOVE(cache, next); + rte_free(cache); + DRV_LOG(DEBUG, "port %u matcher %p: removed", + dev->data->port_id, (void *)cache); + return 0; + } + return 1; +} + +/** + * Remove the flow from the NIC but keeps it in memory. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[in, out] flow + * Pointer to flow structure. + */ +static void +flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow) +{ + struct mlx5_flow_dv *dv; + struct mlx5_flow *dev_flow; + + if (!flow) + return; + LIST_FOREACH(dev_flow, &flow->dev_flows, next) { + dv =3D &dev_flow->dv; + if (dv->flow) { + claim_zero(mlx5_glue->destroy_flow(dv->flow)); + dv->flow =3D NULL; + } + if (dv->hrxq) { + if (flow->actions & MLX5_ACTION_DROP) + mlx5_hrxq_drop_release(dev); + else + mlx5_hrxq_release(dev, dv->hrxq); + dv->hrxq =3D NULL; + } + } + if (flow->counter) + flow->counter =3D NULL; +} + +/** + * Remove the flow from the NIC and the memory. + * + * @param[in] dev + * Pointer to the Ethernet device structure. + * @param[in, out] flow + * Pointer to flow structure. + */ +static void +flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow) +{ + struct mlx5_flow *dev_flow; + + if (!flow) + return; + flow_dv_remove(dev, flow); + while (!LIST_EMPTY(&flow->dev_flows)) { + dev_flow =3D LIST_FIRST(&flow->dev_flows); + LIST_REMOVE(dev_flow, next); + if (dev_flow->dv.matcher) + flow_dv_matcher_release(dev, dev_flow->dv.matcher); + rte_free(dev_flow); + } +} + +/** * Fills the flow_ops with the function pointers. * * @param[out] flow_ops @@ -1180,9 +1364,9 @@ mlx5_flow_dv_get_driver_ops(struct mlx5_flow_driver_o= ps *flow_ops) .validate =3D flow_dv_validate, .prepare =3D flow_dv_prepare, .translate =3D flow_dv_translate, - .apply =3D NULL, - .remove =3D NULL, - .destroy =3D NULL, + .apply =3D flow_dv_apply, + .remove =3D flow_dv_remove, + .destroy =3D flow_dv_destroy, }; } =20 --=20 2.11.0