From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20049.outbound.protection.outlook.com [40.107.2.49]) by dpdk.org (Postfix) with ESMTP id EA9F95911 for ; Thu, 18 Apr 2019 14:19:52 +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=lWJNj8CzrzPftHANQz8A9FyJYyHZ9DYq+rGqmJ0a25s=; b=yMghMTsahwBT40Q4B7WM8hrGOLTEAlp/q9lX3vy/0bey5i48ITHsUP71yzWObGtl+PqiwdE7lYVfFR2P937mNnytY99I87ppDXDmIAoepj1cVo2dEPX0PxuBMcxwnZZvARNz9FF53AEEM12ICzWNAxjematuRtLdcghDM0RIacQ= Received: from AM0PR0502MB3971.eurprd05.prod.outlook.com (52.133.40.151) by AM0PR0502MB3764.eurprd05.prod.outlook.com (52.133.47.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1792.19; Thu, 18 Apr 2019 12:19:49 +0000 Received: from AM0PR0502MB3971.eurprd05.prod.outlook.com ([fe80::7da6:9e13:922a:9d88]) by AM0PR0502MB3971.eurprd05.prod.outlook.com ([fe80::7da6:9e13:922a:9d88%5]) with mapi id 15.20.1813.013; Thu, 18 Apr 2019 12:19:49 +0000 From: Yongseok Koh To: Ori Kam CC: Shahaf Shuler , Matan Azrad , Slava Ovsiienko , Moti Haimovsky , "dev@dpdk.org" Thread-Topic: [PATCH v2 7/9] net/mlx5: add E-Switch port ID action to Direct Verbs Thread-Index: AQHU9doSFyIAUzmrh0yo2okm18sSgKZB1kkA Date: Thu, 18 Apr 2019 12:19:49 +0000 Message-ID: <20190418121939.GM31179@mtidpdk.mti.labs.mlnx> References: <1555276357-4892-1-git-send-email-orika@mellanox.com> <1555586930-109097-1-git-send-email-orika@mellanox.com> <1555586930-109097-8-git-send-email-orika@mellanox.com> In-Reply-To: <1555586930-109097-8-git-send-email-orika@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR08CA0061.namprd08.prod.outlook.com (2603:10b6:a03:117::38) To AM0PR0502MB3971.eurprd05.prod.outlook.com (2603:10a6:208:11::23) 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-ms-office365-filtering-correlation-id: 501101c2-8628-4843-fe75-08d6c3f826c5 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:AM0PR0502MB3764; x-ms-traffictypediagnostic: AM0PR0502MB3764: x-microsoft-antispam-prvs: x-forefront-prvs: 0011612A55 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(396003)(376002)(366004)(346002)(199004)(189003)(26005)(102836004)(66066001)(6506007)(386003)(86362001)(2906002)(76176011)(52116002)(6636002)(186003)(99286004)(97736004)(229853002)(8936002)(3846002)(6116002)(33656002)(71200400001)(71190400001)(7736002)(68736007)(6436002)(81156014)(81166006)(8676002)(305945005)(316002)(6486002)(54906003)(1076003)(478600001)(6862004)(9686003)(4326008)(6512007)(256004)(6246003)(14454004)(53936002)(5660300002)(476003)(446003)(11346002)(486006)(25786009); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB3764; H:AM0PR0502MB3971.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: Tq78XKQmjy6qA3bNXrKHrHKfnSVib9IrbQ7SeVs1Nav/Rh1RT68mXNiJduPQzwx9n7scIy6yPeDZIC/22OqqB9YAUOAUtuFQ0yNtgJMEKqxiHIHzCacDXesIKSBa0xa58uRR7BKFz7E9lxyuOq6lVp3dEIvLYOUU3I+jVdCpgdJUU4OW1SrySgQXqfnBVAkVXk1+k+XhxjFb175tpPPU+UcMcB7t7G69x6bqz5K/nLrsYPEFs9VhoYBTytldS/BgTiFAEaWL/rcG0/1zgdP4eltG+73lLtPwXW0VgLe6NjKVd96JtMIi0ilB5ov0K9aGhE2RWRritg7Mlx+VNH1HA5cri8bBT18PbmzR4aDcLdSKL25z0c+9uxnbcVqnEllI0/75rW8mFf/1aon2YB1ydoQSJxhV9+IMlwnfCdPZLRQ= Content-Type: text/plain; charset="us-ascii" Content-ID: <0D47EB611F69B14EA41733D8793EAC16@eurprd05.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 501101c2-8628-4843-fe75-08d6c3f826c5 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Apr 2019 12:19:49.3562 (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: AM0PR0502MB3764 Subject: Re: [dpdk-dev] [PATCH v2 7/9] net/mlx5: add E-Switch port ID action to Direct Verbs 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: Thu, 18 Apr 2019 12:19:53 -0000 On Thu, Apr 18, 2019 at 11:28:48AM +0000, Ori Kam wrote: > This commits adds matching on source port, using DV API. >=20 > Signed-off-by: Ori Kam > --- Acked-by: Yongseok Koh > v2: > * Address ML comments. > --- > drivers/net/mlx5/mlx5.h | 2 + > drivers/net/mlx5/mlx5_flow.h | 12 ++++ > drivers/net/mlx5/mlx5_flow_dv.c | 149 ++++++++++++++++++++++++++++++++++= ++++++ > drivers/net/mlx5/mlx5_glue.c | 14 ++++ > drivers/net/mlx5/mlx5_glue.h | 1 + > 5 files changed, 178 insertions(+) >=20 > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h > index dd22bb6..4b6dbc2 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -281,6 +281,8 @@ struct mlx5_ibv_shared { > LIST_HEAD(modify_cmd, mlx5_flow_dv_modify_hdr_resource) modify_cmds; > LIST_HEAD(tag, mlx5_flow_dv_tag_resource) tags; > LIST_HEAD(jump, mlx5_flow_dv_jump_tbl_resource) jump_tbl; > + LIST_HEAD(port_id_action_list, mlx5_flow_dv_port_id_action_resource) > + port_id_action_list; /* List of port ID actions. */ > /* Shared interrupt handler section. */ > pthread_mutex_t intr_mutex; /* Interrupt config mutex. */ > uint32_t intr_cnt; /* Interrupt handler reference counter. */ > diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h > index 9d72024..c419e6b 100644 > --- a/drivers/net/mlx5/mlx5_flow.h > +++ b/drivers/net/mlx5/mlx5_flow.h > @@ -267,6 +267,16 @@ struct mlx5_flow_dv_jump_tbl_resource { > struct mlx5_flow_tbl_resource *tbl; /**< The target table. */ > }; > =20 > +/* Port ID resource structure. */ > +struct mlx5_flow_dv_port_id_action_resource { > + LIST_ENTRY(mlx5_flow_dv_port_id_action_resource) next; > + /* Pointer to next element. */ > + rte_atomic32_t refcnt; /**< Reference counter. */ > + void *action; > + /**< Verbs tag action object. */ > + uint32_t port_id; /**< Port ID value. */ > +}; > + > /* > * Max number of actions per DV flow. > * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED > @@ -289,6 +299,8 @@ struct mlx5_flow_dv { > struct ibv_flow *flow; /**< Installed flow. */ > struct mlx5_flow_dv_jump_tbl_resource *jump; > /**< Pointer to the jump action resource. */ > + struct mlx5_flow_dv_port_id_action_resource *port_id_action; > + /**< Pointer to port ID action resource. */ > #ifdef HAVE_IBV_FLOW_DV_SUPPORT > void *actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS]; > /**< Action list. */ > diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow= _dv.c > index 182abb3..9c5826c 100644 > --- a/drivers/net/mlx5/mlx5_flow_dv.c > +++ b/drivers/net/mlx5/mlx5_flow_dv.c > @@ -1054,6 +1054,70 @@ struct field_modify_info modify_tcp[] =3D { > } > =20 > /** > + * Find existing table port ID resource or create and register a new one= . > + * > + * @param dev[in, out] > + * Pointer to rte_eth_dev structure. > + * @param[in, out] resource > + * Pointer to port ID action 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_port_id_action_resource_register > + (struct rte_eth_dev *dev, > + struct mlx5_flow_dv_port_id_action_resource *resource, > + struct mlx5_flow *dev_flow, > + struct rte_flow_error *error) > +{ > + struct mlx5_priv *priv =3D dev->data->dev_private; > + struct mlx5_ibv_shared *sh =3D priv->sh; > + struct mlx5_flow_dv_port_id_action_resource *cache_resource; > + > + /* Lookup a matching resource from cache. */ > + LIST_FOREACH(cache_resource, &sh->port_id_action_list, next) { > + if (resource->port_id =3D=3D cache_resource->port_id) { > + DRV_LOG(DEBUG, "port id action resource resource %p: " > + "refcnt %d++", > + (void *)cache_resource, > + rte_atomic32_read(&cache_resource->refcnt)); > + rte_atomic32_inc(&cache_resource->refcnt); > + dev_flow->dv.port_id_action =3D cache_resource; > + return 0; > + } > + } > + /* Register new port id action 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->dr_create_flow_action_dest_vport(priv->sh->fdb_ns, > + resource->port_id); > + 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(&sh->port_id_action_list, cache_resource, next); > + dev_flow->dv.port_id_action =3D cache_resource; > + DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++", > + (void *)cache_resource, > + rte_atomic32_read(&cache_resource->refcnt)); > + return 0; > +} > + > +/** > * Get the size of specific rte_flow_item_type > * > * @param[in] item_type > @@ -3456,6 +3520,44 @@ struct field_modify_info modify_tcp[] =3D { > } > =20 > /** > + * Translate port ID action to vport. > + * > + * @param[in] dev > + * Pointer to rte_eth_dev structure. > + * @param[in] action > + * Pointer to the port ID action. > + * @param[out] dst_port_id > + * The target port ID. > + * @param[out] error > + * Pointer to the error structure. > + * > + * @return > + * 0 on success, a negative errno value otherwise and rte_errno is set= . > + */ > +static int > +flow_dv_translate_action_port_id(struct rte_eth_dev *dev, > + const struct rte_flow_action *action, > + uint32_t *dst_port_id, > + struct rte_flow_error *error) > +{ > + uint32_t port; > + uint16_t port_id; > + int ret; > + const struct rte_flow_action_port_id *conf =3D > + (const struct rte_flow_action_port_id *)action->conf; > + > + port =3D conf->original ? dev->data->port_id : conf->id; > + ret =3D mlx5_port_to_eswitch_info(port, NULL, &port_id); > + if (ret) > + return rte_flow_error_set(error, -ret, > + RTE_FLOW_ERROR_TYPE_ACTION, > + NULL, > + "No eswitch info was found for port"); > + *dst_port_id =3D port_id; > + return 0; > +} > + > +/** > * Fill the flow with DV spec. > * > * @param[in] dev > @@ -3513,10 +3615,24 @@ struct field_modify_info modify_tcp[] =3D { > const struct rte_flow_action_jump *jump_data; > struct mlx5_flow_dv_jump_tbl_resource jump_tbl_resource; > struct mlx5_flow_tbl_resource *tbl; > + uint32_t port_id =3D 0; > + struct mlx5_flow_dv_port_id_action_resource port_id_resource; > =20 > switch (actions->type) { > case RTE_FLOW_ACTION_TYPE_VOID: > break; > + case RTE_FLOW_ACTION_TYPE_PORT_ID: > + if (flow_dv_translate_action_port_id(dev, action, > + &port_id, error)) > + return -rte_errno; > + port_id_resource.port_id =3D port_id; > + if (flow_dv_port_id_action_resource_register > + (dev, &port_id_resource, dev_flow, error)) > + return -rte_errno; > + dev_flow->dv.actions[actions_n++] =3D > + dev_flow->dv.port_id_action->action; > + action_flags |=3D MLX5_FLOW_ACTION_PORT_ID; > + break; > case RTE_FLOW_ACTION_TYPE_FLAG: > tag_resource.tag =3D > mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT); > @@ -4116,6 +4232,37 @@ struct field_modify_info modify_tcp[] =3D { > } > =20 > /** > + * Release port ID action resource. > + * > + * @param flow > + * Pointer to mlx5_flow. > + * > + * @return > + * 1 while a reference on it exists, 0 when freed. > + */ > +static int > +flow_dv_port_id_action_resource_release(struct mlx5_flow *flow) > +{ > + struct mlx5_flow_dv_port_id_action_resource *cache_resource =3D > + flow->dv.port_id_action; > + > + assert(cache_resource->action); > + DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--", > + (void *)cache_resource, > + rte_atomic32_read(&cache_resource->refcnt)); > + if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) { > + claim_zero(mlx5_glue->destroy_flow_action > + (cache_resource->action)); > + LIST_REMOVE(cache_resource, next); > + rte_free(cache_resource); > + DRV_LOG(DEBUG, "port id action resource %p: removed", > + (void *)cache_resource); > + return 0; > + } > + return 1; > +} > + > +/** > * Remove the flow from the NIC but keeps it in memory. > * > * @param[in] dev > @@ -4182,6 +4329,8 @@ struct field_modify_info modify_tcp[] =3D { > flow_dv_modify_hdr_resource_release(dev_flow); > if (dev_flow->dv.jump) > flow_dv_jump_tbl_resource_release(dev_flow); > + if (dev_flow->dv.port_id_action) > + flow_dv_port_id_action_resource_release(dev_flow); > rte_free(dev_flow); > } > } > diff --git a/drivers/net/mlx5/mlx5_glue.c b/drivers/net/mlx5/mlx5_glue.c > index a508faa..117190f 100644 > --- a/drivers/net/mlx5/mlx5_glue.c > +++ b/drivers/net/mlx5/mlx5_glue.c > @@ -382,6 +382,18 @@ > } > =20 > static void * > +mlx5_glue_dr_create_flow_action_dest_vport(void *ns, uint32_t vport) > +{ > +#ifdef HAVE_MLX5DV_DR_ESWITCH > + return mlx5dv_dr_create_action_dest_vport(ns, vport); > +#else > + (void)ns; > + (void)vport; > + return NULL; > +#endif > +} > + > +static void * > mlx5_glue_dr_create_flow_tbl(void *ns, uint32_t level) > { > #ifdef HAVE_MLX5DV_DR > @@ -847,6 +859,8 @@ > .cq_ex_to_cq =3D mlx5_glue_cq_ex_to_cq, > .dr_create_flow_action_dest_flow_tbl =3D > mlx5_glue_dr_create_flow_action_dest_flow_tbl, > + .dr_create_flow_action_dest_vport =3D > + mlx5_glue_dr_create_flow_action_dest_vport, > .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, > diff --git a/drivers/net/mlx5/mlx5_glue.h b/drivers/net/mlx5/mlx5_glue.h > index 058e9b1..26f5cb3 100644 > --- a/drivers/net/mlx5/mlx5_glue.h > +++ b/drivers/net/mlx5/mlx5_glue.h > @@ -146,6 +146,7 @@ struct mlx5_glue { > 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_action_dest_flow_tbl)(void *tbl); > + void *(*dr_create_flow_action_dest_vport)(void *ns, uint32_t vport); > 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, > --=20 > 1.8.3.1 >=20 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 B7442A00E6 for ; Thu, 18 Apr 2019 14:19:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 857931B9E0; Thu, 18 Apr 2019 14:19:54 +0200 (CEST) Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20049.outbound.protection.outlook.com [40.107.2.49]) by dpdk.org (Postfix) with ESMTP id EA9F95911 for ; Thu, 18 Apr 2019 14:19:52 +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=lWJNj8CzrzPftHANQz8A9FyJYyHZ9DYq+rGqmJ0a25s=; b=yMghMTsahwBT40Q4B7WM8hrGOLTEAlp/q9lX3vy/0bey5i48ITHsUP71yzWObGtl+PqiwdE7lYVfFR2P937mNnytY99I87ppDXDmIAoepj1cVo2dEPX0PxuBMcxwnZZvARNz9FF53AEEM12ICzWNAxjematuRtLdcghDM0RIacQ= Received: from AM0PR0502MB3971.eurprd05.prod.outlook.com (52.133.40.151) by AM0PR0502MB3764.eurprd05.prod.outlook.com (52.133.47.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1792.19; Thu, 18 Apr 2019 12:19:49 +0000 Received: from AM0PR0502MB3971.eurprd05.prod.outlook.com ([fe80::7da6:9e13:922a:9d88]) by AM0PR0502MB3971.eurprd05.prod.outlook.com ([fe80::7da6:9e13:922a:9d88%5]) with mapi id 15.20.1813.013; Thu, 18 Apr 2019 12:19:49 +0000 From: Yongseok Koh To: Ori Kam CC: Shahaf Shuler , Matan Azrad , Slava Ovsiienko , Moti Haimovsky , "dev@dpdk.org" Thread-Topic: [PATCH v2 7/9] net/mlx5: add E-Switch port ID action to Direct Verbs Thread-Index: AQHU9doSFyIAUzmrh0yo2okm18sSgKZB1kkA Date: Thu, 18 Apr 2019 12:19:49 +0000 Message-ID: <20190418121939.GM31179@mtidpdk.mti.labs.mlnx> References: <1555276357-4892-1-git-send-email-orika@mellanox.com> <1555586930-109097-1-git-send-email-orika@mellanox.com> <1555586930-109097-8-git-send-email-orika@mellanox.com> In-Reply-To: <1555586930-109097-8-git-send-email-orika@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BYAPR08CA0061.namprd08.prod.outlook.com (2603:10b6:a03:117::38) To AM0PR0502MB3971.eurprd05.prod.outlook.com (2603:10a6:208:11::23) 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-ms-office365-filtering-correlation-id: 501101c2-8628-4843-fe75-08d6c3f826c5 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:AM0PR0502MB3764; x-ms-traffictypediagnostic: AM0PR0502MB3764: x-microsoft-antispam-prvs: x-forefront-prvs: 0011612A55 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(396003)(376002)(366004)(346002)(199004)(189003)(26005)(102836004)(66066001)(6506007)(386003)(86362001)(2906002)(76176011)(52116002)(6636002)(186003)(99286004)(97736004)(229853002)(8936002)(3846002)(6116002)(33656002)(71200400001)(71190400001)(7736002)(68736007)(6436002)(81156014)(81166006)(8676002)(305945005)(316002)(6486002)(54906003)(1076003)(478600001)(6862004)(9686003)(4326008)(6512007)(256004)(6246003)(14454004)(53936002)(5660300002)(476003)(446003)(11346002)(486006)(25786009); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB3764; H:AM0PR0502MB3971.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: Tq78XKQmjy6qA3bNXrKHrHKfnSVib9IrbQ7SeVs1Nav/Rh1RT68mXNiJduPQzwx9n7scIy6yPeDZIC/22OqqB9YAUOAUtuFQ0yNtgJMEKqxiHIHzCacDXesIKSBa0xa58uRR7BKFz7E9lxyuOq6lVp3dEIvLYOUU3I+jVdCpgdJUU4OW1SrySgQXqfnBVAkVXk1+k+XhxjFb175tpPPU+UcMcB7t7G69x6bqz5K/nLrsYPEFs9VhoYBTytldS/BgTiFAEaWL/rcG0/1zgdP4eltG+73lLtPwXW0VgLe6NjKVd96JtMIi0ilB5ov0K9aGhE2RWRritg7Mlx+VNH1HA5cri8bBT18PbmzR4aDcLdSKL25z0c+9uxnbcVqnEllI0/75rW8mFf/1aon2YB1ydoQSJxhV9+IMlwnfCdPZLRQ= Content-Type: text/plain; charset="UTF-8" Content-ID: <0D47EB611F69B14EA41733D8793EAC16@eurprd05.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 501101c2-8628-4843-fe75-08d6c3f826c5 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Apr 2019 12:19:49.3562 (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: AM0PR0502MB3764 Subject: Re: [dpdk-dev] [PATCH v2 7/9] net/mlx5: add E-Switch port ID action to Direct Verbs 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: <20190418121949.mfVlqHZJxBhp_lbt-gn4zdTI8FYZx4yOPfhNw3Rv3mg@z> On Thu, Apr 18, 2019 at 11:28:48AM +0000, Ori Kam wrote: > This commits adds matching on source port, using DV API. >=20 > Signed-off-by: Ori Kam > --- Acked-by: Yongseok Koh > v2: > * Address ML comments. > --- > drivers/net/mlx5/mlx5.h | 2 + > drivers/net/mlx5/mlx5_flow.h | 12 ++++ > drivers/net/mlx5/mlx5_flow_dv.c | 149 ++++++++++++++++++++++++++++++++++= ++++++ > drivers/net/mlx5/mlx5_glue.c | 14 ++++ > drivers/net/mlx5/mlx5_glue.h | 1 + > 5 files changed, 178 insertions(+) >=20 > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h > index dd22bb6..4b6dbc2 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -281,6 +281,8 @@ struct mlx5_ibv_shared { > LIST_HEAD(modify_cmd, mlx5_flow_dv_modify_hdr_resource) modify_cmds; > LIST_HEAD(tag, mlx5_flow_dv_tag_resource) tags; > LIST_HEAD(jump, mlx5_flow_dv_jump_tbl_resource) jump_tbl; > + LIST_HEAD(port_id_action_list, mlx5_flow_dv_port_id_action_resource) > + port_id_action_list; /* List of port ID actions. */ > /* Shared interrupt handler section. */ > pthread_mutex_t intr_mutex; /* Interrupt config mutex. */ > uint32_t intr_cnt; /* Interrupt handler reference counter. */ > diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h > index 9d72024..c419e6b 100644 > --- a/drivers/net/mlx5/mlx5_flow.h > +++ b/drivers/net/mlx5/mlx5_flow.h > @@ -267,6 +267,16 @@ struct mlx5_flow_dv_jump_tbl_resource { > struct mlx5_flow_tbl_resource *tbl; /**< The target table. */ > }; > =20 > +/* Port ID resource structure. */ > +struct mlx5_flow_dv_port_id_action_resource { > + LIST_ENTRY(mlx5_flow_dv_port_id_action_resource) next; > + /* Pointer to next element. */ > + rte_atomic32_t refcnt; /**< Reference counter. */ > + void *action; > + /**< Verbs tag action object. */ > + uint32_t port_id; /**< Port ID value. */ > +}; > + > /* > * Max number of actions per DV flow. > * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED > @@ -289,6 +299,8 @@ struct mlx5_flow_dv { > struct ibv_flow *flow; /**< Installed flow. */ > struct mlx5_flow_dv_jump_tbl_resource *jump; > /**< Pointer to the jump action resource. */ > + struct mlx5_flow_dv_port_id_action_resource *port_id_action; > + /**< Pointer to port ID action resource. */ > #ifdef HAVE_IBV_FLOW_DV_SUPPORT > void *actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS]; > /**< Action list. */ > diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow= _dv.c > index 182abb3..9c5826c 100644 > --- a/drivers/net/mlx5/mlx5_flow_dv.c > +++ b/drivers/net/mlx5/mlx5_flow_dv.c > @@ -1054,6 +1054,70 @@ struct field_modify_info modify_tcp[] =3D { > } > =20 > /** > + * Find existing table port ID resource or create and register a new one= . > + * > + * @param dev[in, out] > + * Pointer to rte_eth_dev structure. > + * @param[in, out] resource > + * Pointer to port ID action 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_port_id_action_resource_register > + (struct rte_eth_dev *dev, > + struct mlx5_flow_dv_port_id_action_resource *resource, > + struct mlx5_flow *dev_flow, > + struct rte_flow_error *error) > +{ > + struct mlx5_priv *priv =3D dev->data->dev_private; > + struct mlx5_ibv_shared *sh =3D priv->sh; > + struct mlx5_flow_dv_port_id_action_resource *cache_resource; > + > + /* Lookup a matching resource from cache. */ > + LIST_FOREACH(cache_resource, &sh->port_id_action_list, next) { > + if (resource->port_id =3D=3D cache_resource->port_id) { > + DRV_LOG(DEBUG, "port id action resource resource %p: " > + "refcnt %d++", > + (void *)cache_resource, > + rte_atomic32_read(&cache_resource->refcnt)); > + rte_atomic32_inc(&cache_resource->refcnt); > + dev_flow->dv.port_id_action =3D cache_resource; > + return 0; > + } > + } > + /* Register new port id action 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->dr_create_flow_action_dest_vport(priv->sh->fdb_ns, > + resource->port_id); > + 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(&sh->port_id_action_list, cache_resource, next); > + dev_flow->dv.port_id_action =3D cache_resource; > + DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++", > + (void *)cache_resource, > + rte_atomic32_read(&cache_resource->refcnt)); > + return 0; > +} > + > +/** > * Get the size of specific rte_flow_item_type > * > * @param[in] item_type > @@ -3456,6 +3520,44 @@ struct field_modify_info modify_tcp[] =3D { > } > =20 > /** > + * Translate port ID action to vport. > + * > + * @param[in] dev > + * Pointer to rte_eth_dev structure. > + * @param[in] action > + * Pointer to the port ID action. > + * @param[out] dst_port_id > + * The target port ID. > + * @param[out] error > + * Pointer to the error structure. > + * > + * @return > + * 0 on success, a negative errno value otherwise and rte_errno is set= . > + */ > +static int > +flow_dv_translate_action_port_id(struct rte_eth_dev *dev, > + const struct rte_flow_action *action, > + uint32_t *dst_port_id, > + struct rte_flow_error *error) > +{ > + uint32_t port; > + uint16_t port_id; > + int ret; > + const struct rte_flow_action_port_id *conf =3D > + (const struct rte_flow_action_port_id *)action->conf; > + > + port =3D conf->original ? dev->data->port_id : conf->id; > + ret =3D mlx5_port_to_eswitch_info(port, NULL, &port_id); > + if (ret) > + return rte_flow_error_set(error, -ret, > + RTE_FLOW_ERROR_TYPE_ACTION, > + NULL, > + "No eswitch info was found for port"); > + *dst_port_id =3D port_id; > + return 0; > +} > + > +/** > * Fill the flow with DV spec. > * > * @param[in] dev > @@ -3513,10 +3615,24 @@ struct field_modify_info modify_tcp[] =3D { > const struct rte_flow_action_jump *jump_data; > struct mlx5_flow_dv_jump_tbl_resource jump_tbl_resource; > struct mlx5_flow_tbl_resource *tbl; > + uint32_t port_id =3D 0; > + struct mlx5_flow_dv_port_id_action_resource port_id_resource; > =20 > switch (actions->type) { > case RTE_FLOW_ACTION_TYPE_VOID: > break; > + case RTE_FLOW_ACTION_TYPE_PORT_ID: > + if (flow_dv_translate_action_port_id(dev, action, > + &port_id, error)) > + return -rte_errno; > + port_id_resource.port_id =3D port_id; > + if (flow_dv_port_id_action_resource_register > + (dev, &port_id_resource, dev_flow, error)) > + return -rte_errno; > + dev_flow->dv.actions[actions_n++] =3D > + dev_flow->dv.port_id_action->action; > + action_flags |=3D MLX5_FLOW_ACTION_PORT_ID; > + break; > case RTE_FLOW_ACTION_TYPE_FLAG: > tag_resource.tag =3D > mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT); > @@ -4116,6 +4232,37 @@ struct field_modify_info modify_tcp[] =3D { > } > =20 > /** > + * Release port ID action resource. > + * > + * @param flow > + * Pointer to mlx5_flow. > + * > + * @return > + * 1 while a reference on it exists, 0 when freed. > + */ > +static int > +flow_dv_port_id_action_resource_release(struct mlx5_flow *flow) > +{ > + struct mlx5_flow_dv_port_id_action_resource *cache_resource =3D > + flow->dv.port_id_action; > + > + assert(cache_resource->action); > + DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--", > + (void *)cache_resource, > + rte_atomic32_read(&cache_resource->refcnt)); > + if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) { > + claim_zero(mlx5_glue->destroy_flow_action > + (cache_resource->action)); > + LIST_REMOVE(cache_resource, next); > + rte_free(cache_resource); > + DRV_LOG(DEBUG, "port id action resource %p: removed", > + (void *)cache_resource); > + return 0; > + } > + return 1; > +} > + > +/** > * Remove the flow from the NIC but keeps it in memory. > * > * @param[in] dev > @@ -4182,6 +4329,8 @@ struct field_modify_info modify_tcp[] =3D { > flow_dv_modify_hdr_resource_release(dev_flow); > if (dev_flow->dv.jump) > flow_dv_jump_tbl_resource_release(dev_flow); > + if (dev_flow->dv.port_id_action) > + flow_dv_port_id_action_resource_release(dev_flow); > rte_free(dev_flow); > } > } > diff --git a/drivers/net/mlx5/mlx5_glue.c b/drivers/net/mlx5/mlx5_glue.c > index a508faa..117190f 100644 > --- a/drivers/net/mlx5/mlx5_glue.c > +++ b/drivers/net/mlx5/mlx5_glue.c > @@ -382,6 +382,18 @@ > } > =20 > static void * > +mlx5_glue_dr_create_flow_action_dest_vport(void *ns, uint32_t vport) > +{ > +#ifdef HAVE_MLX5DV_DR_ESWITCH > + return mlx5dv_dr_create_action_dest_vport(ns, vport); > +#else > + (void)ns; > + (void)vport; > + return NULL; > +#endif > +} > + > +static void * > mlx5_glue_dr_create_flow_tbl(void *ns, uint32_t level) > { > #ifdef HAVE_MLX5DV_DR > @@ -847,6 +859,8 @@ > .cq_ex_to_cq =3D mlx5_glue_cq_ex_to_cq, > .dr_create_flow_action_dest_flow_tbl =3D > mlx5_glue_dr_create_flow_action_dest_flow_tbl, > + .dr_create_flow_action_dest_vport =3D > + mlx5_glue_dr_create_flow_action_dest_vport, > .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, > diff --git a/drivers/net/mlx5/mlx5_glue.h b/drivers/net/mlx5/mlx5_glue.h > index 058e9b1..26f5cb3 100644 > --- a/drivers/net/mlx5/mlx5_glue.h > +++ b/drivers/net/mlx5/mlx5_glue.h > @@ -146,6 +146,7 @@ struct mlx5_glue { > 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_action_dest_flow_tbl)(void *tbl); > + void *(*dr_create_flow_action_dest_vport)(void *ns, uint32_t vport); > 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, > --=20 > 1.8.3.1 >=20