From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60052.outbound.protection.outlook.com [40.107.6.52]) by dpdk.org (Postfix) with ESMTP id 5955858CB for ; Wed, 17 Oct 2018 01:50:21 +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=+Cgps/YTpKxtVDWtwm/VJD3o33D8LHQ1ed1P7XnO3o4=; b=PkxPjaWXFTUZtwFohDikVtGFnfdprlGdsDDjI405tzRQFzWc9zgxBv7AERl/0ywbT+6Vj0IXT3nDHem4WeXMpoT8zshy/vJiYZXU8BozPgRkDJgzFmn4r+J9nESKIRjq/lz94rRBQVJMYkKu4oES5GF410mjwmZXhnNO8NDBjz8= Received: from AM0PR05MB4435.eurprd05.prod.outlook.com (52.134.92.20) by AM0PR05MB4867.eurprd05.prod.outlook.com (20.177.41.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1250.21; Tue, 16 Oct 2018 23:50:20 +0000 Received: from AM0PR05MB4435.eurprd05.prod.outlook.com ([fe80::2549:a872:4864:b84e]) by AM0PR05MB4435.eurprd05.prod.outlook.com ([fe80::2549:a872:4864:b84e%6]) with mapi id 15.20.1207.029; Tue, 16 Oct 2018 23:50:20 +0000 From: Mordechay Haimovsky To: Shahaf Shuler CC: "dev@dpdk.org" , Mordechay Haimovsky Thread-Topic: [PATCH v3 1/2] net/mlx5: refactor TC-flow infrastructure Thread-Index: AQHUZar/eQNqyNXAAU2U5Bph5mDxOw== Date: Tue, 16 Oct 2018 23:50:20 +0000 Message-ID: <1539733797-31468-2-git-send-email-motih@mellanox.com> References: <1539263057-16678-3-git-send-email-motih@mellanox.com> In-Reply-To: <1539263057-16678-3-git-send-email-motih@mellanox.com> Accept-Language: he-IL, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: DB6PR0801CA0063.eurprd08.prod.outlook.com (2603:10a6:4:2b::31) To AM0PR05MB4435.eurprd05.prod.outlook.com (2603:10a6:208:5a::20) authentication-results: spf=none (sender IP is ) smtp.mailfrom=motih@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [37.142.13.130] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM0PR05MB4867; 6:aIEP4/+foT4HN2+kAGgSpffMpYUoNHkVE45Tu38vBdlMvxR1Urqbd+MM+S7MM37IWApiJUs7ogCN1gYh3mTR1vIzkrbFdTxzhxat76m6xN/eY//TvmF9tOtk2oWFFX2Y3RqPIZ1m0KCg55cFqh9uH9GAWuJ35eoqq8t+QAG0V9HZnfOSsOqz8xFtU7zKy3Nmaa+4UZ2FKC37bQA0ntoJ9jQ9EydG/G/tafy49gevFDJxrguW6vnvrffKXfoa7ar7xZPLPbfF2YjEycaAJERinBcbS6Tfx2n2E1D6r0WIk6Dqv5VS0jx+kVHTnLOijkxxe56CSCdROEnLE23kvA2ZK10JZQyNNyaDV4GvU3WOn2RWKFtv3nsno+jh46NrLv41s+IxQ8dal/rFwLIvFY0n2A1QVtqskzWyw1ggDZH49GOE9Zagp0hieQNETJst1Qes5/htrWTOttt3f9XbDjBnvg==; 5:HG7NJIU/PTZahlGc5E7/hgYyqAb+WuxiZ9u+elRSMn9JerQ3kE1wga4CFAELwCyxT87mmhRghfP0BI3n7Yi08U1wmYwVqPyu3R0mDO9hsTYkZdG65MWL613t5aZOsi+KFqCDDH/GjTlGJSbYQa3V1iG2yPapnrmY42mXNfFS1g0=; 7:fbwtLvfIJI9Sl2HpiTisAd3JVwJu2YbPaMUofwAELt0/+ivhZAXhg/kOGq875IACtINE9c6qMu8hryAWmM/Bo+0FBHljYjiSho1/LpgjU5B1fU2yHB5kxi8YSIqzItA0W0c3gJt9eH6YdPclfots4kFwOSd4LeRAOE5rS3/nKJcfJVEaS+cp9odVM3N0fIwGlOQjHtDOCIrFbOukA+lUYeLEntQzA6ed8MFRjKR01YRZ0u+sE0j3dWKMByzMRWwJ x-ms-office365-filtering-correlation-id: af214a5a-0bde-432d-d454-08d633c2217d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM0PR05MB4867; x-ms-traffictypediagnostic: AM0PR05MB4867: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(269456686620040); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231355)(944501410)(52105095)(10201501046)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(201708071742011)(7699051)(76991080); SRVR:AM0PR05MB4867; BCL:0; PCL:0; RULEID:; SRVR:AM0PR05MB4867; x-forefront-prvs: 0827D7ACB9 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(396003)(366004)(376002)(136003)(39860400002)(199004)(189003)(6486002)(6436002)(8676002)(52116002)(53936002)(81156014)(81166006)(8936002)(478600001)(76176011)(6512007)(386003)(6506007)(2616005)(11346002)(476003)(6116002)(3846002)(106356001)(105586002)(446003)(2906002)(102836004)(14454004)(66066001)(186003)(486006)(36756003)(316002)(26005)(2900100001)(37006003)(54906003)(5250100002)(14444005)(5660300001)(68736007)(6862004)(107886003)(25786009)(6636002)(4326008)(99286004)(86362001)(7736002)(305945005)(71190400001)(71200400001)(256004)(97736004)(42262002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR05MB4867; H:AM0PR05MB4435.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: W45uo+GJWcrxrWgzsSfRGbTSkFd2Ul7bGtBx+Sjyddh+cBLDTPUwrXmul4GwCp8tk2YRT3mkF863Uf1bjHDOVx/BNI5gHrwzwdIPqjpz5GWTIHo9Bn7kTTq6D6fTyAfRUriywlQil197IWR1Esn0zGetxkSA+bxTHcYLWpmRS8fkovOnhHrs70GNSPR4UyLqoNnn/nCfe5VqSC4qKFHAEMreQQKU8sAcYcklKFjw4ltJA9QKRkVg3D/0hV3u4IB65d5qgQWOByzE23sw3SwNq/XSygGck3VeHLVHAXky8d3bi37J4url07/4P2TRoqImfZ+coglDE1VFkITy9/r6Hmf6x5VCAMIMdjPtr9BmKL8= 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: af214a5a-0bde-432d-d454-08d633c2217d X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Oct 2018 23:50:20.2363 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4867 Subject: [dpdk-dev] [PATCH v3 1/2] net/mlx5: refactor TC-flow infrastructure 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: Tue, 16 Oct 2018 23:50:21 -0000 This commit refactors tc_flow as a preparation to coming commits that sends different type of messages and expect differ type of replies while still using the same underlying routines. Signed-off-by: Moti Haimovsky --- v3: * Rebase on top of d80c8167c4fe ("net/mlx5: fix compilation issue on ARM SOC") v2: * Rebase on top of 3f4722ee01e7 ("net/mlx5: refactor TC-flow infrastructur= e") --- drivers/net/mlx5/mlx5.c | 18 +++---- drivers/net/mlx5/mlx5.h | 4 +- drivers/net/mlx5/mlx5_flow.h | 8 +-- drivers/net/mlx5/mlx5_flow_tcf.c | 113 ++++++++++++++++++++++++++++++-----= ---- 4 files changed, 102 insertions(+), 41 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 795a219..13f2fd4 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -286,8 +286,8 @@ close(priv->nl_socket_route); if (priv->nl_socket_rdma >=3D 0) close(priv->nl_socket_rdma); - if (priv->mnl_socket) - mlx5_flow_tcf_socket_destroy(priv->mnl_socket); + if (priv->tcf_context) + mlx5_flow_tcf_context_destroy(priv->tcf_context); ret =3D mlx5_hrxq_ibv_verify(dev); if (ret) DRV_LOG(WARNING, "port %u some hash Rx queue still remain", @@ -1139,8 +1139,8 @@ claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0)); if (vf && config.vf_nl_en) mlx5_nl_mac_addr_sync(eth_dev); - priv->mnl_socket =3D mlx5_flow_tcf_socket_create(); - if (!priv->mnl_socket) { + priv->tcf_context =3D mlx5_flow_tcf_context_create(); + if (!priv->tcf_context) { err =3D -rte_errno; DRV_LOG(WARNING, "flow rules relying on switch offloads will not be" @@ -1155,7 +1155,7 @@ error.message =3D "cannot retrieve network interface index"; } else { - err =3D mlx5_flow_tcf_init(priv->mnl_socket, ifindex, + err =3D mlx5_flow_tcf_init(priv->tcf_context, ifindex, &error); } if (err) { @@ -1163,8 +1163,8 @@ "flow rules relying on switch offloads will" " not be supported: %s: %s", error.message, strerror(rte_errno)); - mlx5_flow_tcf_socket_destroy(priv->mnl_socket); - priv->mnl_socket =3D NULL; + mlx5_flow_tcf_context_destroy(priv->tcf_context); + priv->tcf_context =3D NULL; } } TAILQ_INIT(&priv->flows); @@ -1219,8 +1219,8 @@ close(priv->nl_socket_route); if (priv->nl_socket_rdma >=3D 0) close(priv->nl_socket_rdma); - if (priv->mnl_socket) - mlx5_flow_tcf_socket_destroy(priv->mnl_socket); + if (priv->tcf_context) + mlx5_flow_tcf_context_destroy(priv->tcf_context); if (own_domain_id) claim_zero(rte_eth_switch_domain_free(priv->domain_id)); rte_free(priv); diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 2dec88a..d14239c 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -169,7 +169,7 @@ struct mlx5_drop { struct mlx5_rxq_ibv *rxq; /* Verbs Rx queue. */ }; =20 -struct mnl_socket; +struct mlx5_flow_tcf_context; =20 struct priv { LIST_ENTRY(priv) mem_event_cb; /* Called by memory event callback. */ @@ -236,7 +236,7 @@ struct priv { rte_spinlock_t uar_lock[MLX5_UAR_PAGE_NUM_MAX]; /* UAR same-page access control required in 32bit implementations. */ #endif - struct mnl_socket *mnl_socket; /* Libmnl socket. */ + struct mlx5_flow_tcf_context *tcf_context; /* TC flower context. */ }; =20 #define PORT_ID(priv) ((priv)->dev_data->port_id) diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 094f666..5cb05ba 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -346,9 +346,9 @@ int mlx5_flow_validate_item_vxlan_gpe(const struct rte_= flow_item *item, =20 /* mlx5_flow_tcf.c */ =20 -int mlx5_flow_tcf_init(struct mnl_socket *nl, unsigned int ifindex, - struct rte_flow_error *error); -struct mnl_socket *mlx5_flow_tcf_socket_create(void); -void mlx5_flow_tcf_socket_destroy(struct mnl_socket *nl); +int mlx5_flow_tcf_init(struct mlx5_flow_tcf_context *ctx, + unsigned int ifindex, struct rte_flow_error *error); +struct mlx5_flow_tcf_context *mlx5_flow_tcf_context_create(void); +void mlx5_flow_tcf_context_destroy(struct mlx5_flow_tcf_context *ctx); =20 #endif /* RTE_PMD_MLX5_FLOW_H_ */ diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_= tcf.c index 4b51a85..f232373 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -231,6 +231,19 @@ struct tc_pedit_sel { #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */ #endif =20 +/** + * Structure for holding netlink context. + * Note the size of the message buffer which is MNL_SOCKET_BUFFER_SIZE. + * Using this (8KB) buffer size ensures that netlink messages will never b= e + * truncated. + */ +struct mlx5_flow_tcf_context { + struct mnl_socket *nl; /* NETLINK_ROUTE libmnl socket. */ + uint32_t seq; /* Message sequence number. */ + uint32_t buf_size; /* Message buffer size. */ + uint8_t *buf; /* Message buffer. */ +}; + /** Empty masks for known item types. */ static const union { struct rte_flow_item_port_id port_id; @@ -1956,8 +1969,8 @@ struct pedit_parser { /** * Send Netlink message with acknowledgment. * - * @param nl - * Libmnl socket to use. + * @param ctx + * Flow context to use. * @param nlh * Message to send. This function always raises the NLM_F_ACK flag befor= e * sending. @@ -1966,12 +1979,13 @@ struct pedit_parser { * 0 on success, a negative errno value otherwise and rte_errno is set. */ static int -flow_tcf_nl_ack(struct mnl_socket *nl, struct nlmsghdr *nlh) +flow_tcf_nl_ack(struct mlx5_flow_tcf_context *ctx, struct nlmsghdr *nlh) { alignas(struct nlmsghdr) uint8_t ans[mnl_nlmsg_size(sizeof(struct nlmsgerr)) + nlh->nlmsg_len - sizeof(*nlh)]; - uint32_t seq =3D random(); + uint32_t seq =3D ctx->seq++; + struct mnl_socket *nl =3D ctx->nl; int ret; =20 nlh->nlmsg_flags |=3D NLM_F_ACK; @@ -2006,7 +2020,7 @@ struct pedit_parser { struct rte_flow_error *error) { struct priv *priv =3D dev->data->dev_private; - struct mnl_socket *nl =3D priv->mnl_socket; + struct mlx5_flow_tcf_context *nl =3D priv->tcf_context; struct mlx5_flow *dev_flow; struct nlmsghdr *nlh; =20 @@ -2035,7 +2049,7 @@ struct pedit_parser { flow_tcf_remove(struct rte_eth_dev *dev, struct rte_flow *flow) { struct priv *priv =3D dev->data->dev_private; - struct mnl_socket *nl =3D priv->mnl_socket; + struct mlx5_flow_tcf_context *nl =3D priv->tcf_context; struct mlx5_flow *dev_flow; struct nlmsghdr *nlh; =20 @@ -2087,10 +2101,47 @@ struct pedit_parser { }; =20 /** - * Initialize ingress qdisc of a given network interface. + * Create and configure a libmnl socket for Netlink flow rules. + * + * @return + * A valid libmnl socket object pointer on success, NULL otherwise and + * rte_errno is set. + */ +static struct mnl_socket * +mlx5_flow_mnl_socket_create(void) +{ + struct mnl_socket *nl =3D mnl_socket_open(NETLINK_ROUTE); + + if (nl) { + mnl_socket_setsockopt(nl, NETLINK_CAP_ACK, &(int){ 1 }, + sizeof(int)); + if (!mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID)) + return nl; + } + rte_errno =3D errno; + if (nl) + mnl_socket_close(nl); + return NULL; +} + +/** + * Destroy a libmnl socket. * * @param nl * Libmnl socket of the @p NETLINK_ROUTE kind. + */ +static void +mlx5_flow_mnl_socket_destroy(struct mnl_socket *nl) +{ + if (nl) + mnl_socket_close(nl); +} + +/** + * Initialize ingress qdisc of a given network interface. + * + * @param nl + * Pointer to tc-flower context to use. * @param ifindex * Index of network interface to initialize. * @param[out] error @@ -2100,8 +2151,8 @@ struct pedit_parser { * 0 on success, a negative errno value otherwise and rte_errno is set. */ int -mlx5_flow_tcf_init(struct mnl_socket *nl, unsigned int ifindex, - struct rte_flow_error *error) +mlx5_flow_tcf_init(struct mlx5_flow_tcf_context *nl, + unsigned int ifindex, struct rte_flow_error *error) { struct nlmsghdr *nlh; struct tcmsg *tcm; @@ -2143,37 +2194,47 @@ struct pedit_parser { } =20 /** - * Create and configure a libmnl socket for Netlink flow rules. + * Create libmnl context for Netlink flow rules. * * @return * A valid libmnl socket object pointer on success, NULL otherwise and * rte_errno is set. */ -struct mnl_socket * -mlx5_flow_tcf_socket_create(void) +struct mlx5_flow_tcf_context * +mlx5_flow_tcf_context_create(void) { - struct mnl_socket *nl =3D mnl_socket_open(NETLINK_ROUTE); - - if (nl) { - mnl_socket_setsockopt(nl, NETLINK_CAP_ACK, &(int){ 1 }, - sizeof(int)); - if (!mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID)) - return nl; - } - rte_errno =3D errno; - if (nl) - mnl_socket_close(nl); + struct mlx5_flow_tcf_context *ctx =3D rte_zmalloc(__func__, + sizeof(*ctx), + sizeof(uint32_t)); + if (!ctx) + goto error; + ctx->nl =3D mlx5_flow_mnl_socket_create(); + if (!ctx->nl) + goto error; + ctx->buf_size =3D MNL_SOCKET_BUFFER_SIZE; + ctx->buf =3D rte_zmalloc(__func__, + ctx->buf_size, sizeof(uint32_t)); + if (!ctx->buf) + goto error; + ctx->seq =3D random(); + return ctx; +error: + mlx5_flow_tcf_context_destroy(ctx); return NULL; } =20 /** - * Destroy a libmnl socket. + * Destroy a libmnl context. * * @param nl * Libmnl socket of the @p NETLINK_ROUTE kind. */ void -mlx5_flow_tcf_socket_destroy(struct mnl_socket *nl) +mlx5_flow_tcf_context_destroy(struct mlx5_flow_tcf_context *ctx) { - mnl_socket_close(nl); + if (!ctx) + return; + mlx5_flow_mnl_socket_destroy(ctx->nl); + rte_free(ctx->buf); + rte_free(ctx); } --=20 1.8.3.1