From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0069.outbound.protection.outlook.com [104.47.0.69]) by dpdk.org (Postfix) with ESMTP id 05B301B12C for ; Mon, 24 Sep 2018 21:50:27 +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=sUaZ7n4NnlZWtb5rDyQCm/sF7MksgNI4fk2gvaFj+sw=; b=Biee2OheRp1sGwAngfzwe6P9vPZR2IRSnekrGjGKViy2MRG1mh5Pmmspjwe+c2s2HOXPsgEDi6QesrDnTnj6ErKcNNmYqkny8iVwRXypg8HSI+j7L28MxWhcK6Q4gKlNOBhtLePf9jD2FUXwQpcncI/6b5f1mKO3mMjAjJdY/CI= Received: from DB3PR0502MB3980.eurprd05.prod.outlook.com (52.134.72.27) by DB3PR0502MB3963.eurprd05.prod.outlook.com (52.134.72.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.20; Mon, 24 Sep 2018 19:50:25 +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 19:50:25 +0000 From: Yongseok Koh To: Thomas Monjalon , Shahaf Shuler CC: "dev@dpdk.org" , Ori Kam Thread-Topic: [PATCH v2 10/11] net/mlx5: add Direct Verbs final functions Thread-Index: AQHUVD/VD93IXdUCr0SuUl6/n085jw== Date: Mon, 24 Sep 2018 19:50:24 +0000 Message-ID: <20180924194951.18650-11-yskoh@mellanox.com> References: <20180919064814.21645-1-yskoh@mellanox.com> <20180924194951.18650-1-yskoh@mellanox.com> In-Reply-To: <20180924194951.18650-1-yskoh@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR2001CA0039.namprd20.prod.outlook.com (2603:10b6:405:16::25) 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; DB3PR0502MB3963; 6:GvqRqPzJFa0CgbypaKSUJ6Vb/4GWJdps6jKs+1l9nWxFuclkz26VWvxtYgM3sgeVCo93QLz5xg68cgHav5yXv3trw/uLxBl1oFOOQv7wfclnziOoGj4dxFBEn76X9eolvAB6TzecpPq9j8qTI8Q86QndL9PhKI2oYwKflmEnZA50SGEhgmcTzV0glp2QwFSQEC4IPSu2OTm5k/kbrWdzXpwD0wMZcYzkWWAN90VB59HSzKWEolAW+lFYXHRGtKWlqitpLnKPuQOhW/l5GKyR20aU6nfoaCgaw+RdDz2+wPtxBznTYV7o/PUkJcrjdkDfazzwZI1j9itUU5dOwYhxuHt3G1LrfrhISWI6FrOamF7Wr67IPQXsGozbPcwNFqec8Bu5cEWX6u0e324fZjcWqBARyDwqmeoOWcUrCdyvIffW823ywxKPUt814gnWafhx/pt47wXECdM8sI0QcdEW8g==; 5:dHC1jvV5xJ9NIki5Fw65Z6u95J1Y9DyMrxPzwjprKadyLzba1KrHDd5ryEqNdhmOurQ6l9sxRsS3YVfARLqxwBrfyTKIguoMlOtUJAw26Ok6RpqNTsA8/12pQi8A6FLSaW2QIDT9cl5r3D3ZBd9ae8wgjLuqiucrS6BZ8+he4cI=; 7:oRZtzK8eLEX4XmvWbsjhPHnt4rWoCuEkdpmBd97hQ3SJW+ywlgP09nS2Sl/n0qBq/ggmoTkYp9a365DtoTI9uBKTXablo3E9hJr5bWrjY5yT9pbpDOMQJqS41Xbru+xFH7t52whCei6fYeBav5k5KHM8AxGcPDG9JcsK0d9REs4hLIcsHNfqBEGm3zPJHwe923gzmlmpOXRRmZE/Tu/omoOkgtGaFik91dJj+UMULUNoxO4SWO3vfQDnpHm03XbC x-ms-office365-filtering-correlation-id: 95cb2656-f67d-41a7-f78b-08d62256f82a x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB3PR0502MB3963; x-ms-traffictypediagnostic: DB3PR0502MB3963: 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)(93006095)(93001095)(10201501046)(3231355)(944501410)(52105095)(3002001)(6055026)(149066)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(201708071742011)(7699051); SRVR:DB3PR0502MB3963; BCL:0; PCL:0; RULEID:; SRVR:DB3PR0502MB3963; x-forefront-prvs: 0805EC9467 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(1496009)(39860400002)(376002)(346002)(136003)(396003)(366004)(189003)(199004)(71190400001)(71200400001)(2906002)(97736004)(6486002)(107886003)(105586002)(8676002)(81156014)(8936002)(6636002)(81166006)(106356001)(53936002)(6512007)(6436002)(68736007)(2900100001)(5660300001)(66066001)(52116002)(478600001)(5250100002)(316002)(76176011)(386003)(6506007)(1076002)(14454004)(6116002)(54906003)(110136005)(99286004)(3846002)(26005)(7736002)(256004)(476003)(446003)(14444005)(36756003)(86362001)(102836004)(2616005)(305945005)(186003)(25786009)(486006)(11346002)(4326008)(575784001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR0502MB3963; H:DB3PR0502MB3980.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-microsoft-antispam-message-info: j96z+GNyD+PfM65yP19qizaX7xK0pX+fnlxX2ydMaf4Ew9xx18bR5JDEV/dOI6pR8hgmMyu4QkRdlvktUM8eSNnL9sl4pj+T5E4YVw+LSK1eWd554Fs9QEZIpRqeifTZEp6MHil+sB4id23UqRMoO/ONhXEsyIVwBWulxdvA6R2SlbkUuFFsBs12W4Xa/yzDC1m//i/nMNzvheU62fOhuY/++45XekDjJ+JZD8a9K+nDwMKJdmPpdmh/wWIdmlcqBsndslbxkFd9YNZBnFwdWa77OrM8V11U+Ff8C8OtV69B+rGwuPbLVKX/3JqN/T69yLHc3aecY20bJsyI/S9TtEThmQtALz+/XODKil4MRS8= 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: 95cb2656-f67d-41a7-f78b-08d62256f82a X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Sep 2018 19:50:24.9507 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0502MB3963 Subject: [dpdk-dev] [PATCH v2 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 19:50:27 -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 196d9fcbe..1990d7acc 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -2473,5 +2473,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