From patchwork Thu Oct 18 18:29:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moti Haimovsky X-Patchwork-Id: 47049 X-Patchwork-Delegate: shahafs@mellanox.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7330D1B177; Thu, 18 Oct 2018 20:29:56 +0200 (CEST) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40049.outbound.protection.outlook.com [40.107.4.49]) by dpdk.org (Postfix) with ESMTP id 047B21B16A for ; Thu, 18 Oct 2018 20:29:53 +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=PqYXZ8ILHUPVN+M7iPEPzJ0k8u/iaOfId2gDjDtqA50=; b=iui4eyF3YFrevVQQ4iiiFbBps/uhc1V5U737rrTWLfHfagzNww3NRw6uBjZfi6g6WdpgBJG9kdPUsRv/rx8iGQd1whvNjq2iE83CfXbTQK2lTdSUMjL9uUHmsFH2zxno+VgHET3Cl32opjYrdGB0nQbwyJkROGMPakL+3tHPG2k= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=motih@mellanox.com; Received: from localhost.localdomain (37.142.13.130) by AM0PR05MB4435.eurprd05.prod.outlook.com (2603:10a6:208:5a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.21; Thu, 18 Oct 2018 18:29:50 +0000 From: Moti Haimovsky To: shahafs@mellanox.com Cc: dev@dpdk.org, Moti Haimovsky Date: Thu, 18 Oct 2018 21:29:20 +0300 Message-Id: <1539887363-27858-2-git-send-email-motih@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1539797092-2395-4-git-send-email-motih@mellanox.com> References: <1539797092-2395-4-git-send-email-motih@mellanox.com> MIME-Version: 1.0 X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: LO2P265CA0168.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::36) To AM0PR05MB4435.eurprd05.prod.outlook.com (2603:10a6:208:5a::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5e5d91e1-1ecb-4b3f-2fa7-08d63527b123 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:AM0PR05MB4435; X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4435; 3:Xdz9pQPARsXk7SWwG/XRxLBsxpnTs42oayd9sYemdbSg3Aeuua+ci+HB2jy2dTxhdDakhLloKdR+j1XbYll359uiLcjaVH9QrLrrd+uW1+7z9LWv3FoJolI9KJ3u9/x1KUjfsOZaQRFwbE1RjHCiN+6hF2TqQ4Vj5JAEvnZEaa5OLSg+/RbLVUaGZas+qwcelrt9QZHAJ4/6p/8JXBbum4atEfREeTUm8o32eNc37Rjxdp9gnU0CV0wzng9OOREd; 25:ZAxPptXCUjH2p9AlCDq5CvGcifjvqDhCyISGVJNX8dl9U6+3eMCbqiBIO8ma/bVn34ZoGDHR4NFcCQGA++S0/YGWnvRXXWmTFA2aEKHWO4VXNLJ0AnmlyiSd0JcV3iaUtw07yz9xbhU3nqdimz9mGhIa/0ymyn5svtOOxmlOUGuNpMR1gmh3YyeEBsFlzkE91V9O2QPT+oelPFk+mTknQ0baqWwBnZKmYP2sanpWUT1oNA8DLoWETMSo8HRlLl102sOJxLxVg2YtaY0gaDLlGuZ8LoUe7K4vUXlrVsuAxc48mLscZC72VtXLRtw91/2/WMWuAznax0ZKHW6amOZILA==; 31:3dod1wKT5I74+6xSZiCqFcYJkMF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4EkJPzc8az3tOsuVbWLC1Hjy4wpG9kSDiE2wr/ihk 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)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231355)(944501410)(52105095)(3002001)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:AM0PR05MB4435; BCL:0; PCL:0; RULEID:; SRVR:AM0PR05MB4435; X-Forefront-PRVS: 08296C9B35 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(39860400002)(136003)(396003)(376002)(346002)(366004)(199004)(189003)(3846002)(51416003)(37006003)(2906002)(6636002)(11346002)(76176011)(446003)(2351001)(5660300001)(53936002)(48376002)(6116002)(50466002)(47776003)(478600001)(6512007)(186003)(2616005)(6506007)(105586002)(26005)(14444005)(386003)(50226002)(106356001)(486006)(956004)(16526019)(2361001)(6666004)(97736004)(81166006)(36756003)(81156014)(8936002)(6486002)(4326008)(52116002)(107886003)(66066001)(68736007)(25786009)(69590400006)(16586007)(8676002)(305945005)(316002)(34206002)(86362001)(7736002)(476003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR05MB4435; H:localhost.localdomain; 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-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR05MB4435; 23:1uYN8pckV5xXuugf6WVo7R6u2bgGj0BJU3H/WkoZt?= A5eQbrm2I02vdHwWvJaE1KpKl3IE1u6qDZb17zVgXml/0sleNAzvIneMxQwI6psrdQkOUrToMYXXgqHOSdl9naG+bjs/iSPtgw2A+hEry4BkhMlBOLz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G1b+Mi/2ZpWu1McKnjZN5TyZowJ1j7Qnv0Kyrt/p9h0ylDMSzJW0qtcOCYZK0GKG/BuKvyLjBHX3mU3vifQAoGjf+XD4=; 7:VhPEJj6DduR0vn7ZHOamyCOrsTG6UckeCjCKsLRqRm19/fvxUBNUof3LOozKFp7h8ZlRFaIrb1/emDdPay05rkfW8he+GE305kKtLlrhnyB+kRcgYoWp/+brAk7qIaWVGyugBEIaUc7yrf6wkSLRuUaRE/YvQ39GddySLiAs+LCvXSxNhVzxkZEjSEvTUTxNfF3niNiRHI7jJal9aN4YdlIYo/RcXJ1Q2Xa0fVfl1savu6zn5jMDvnDCQKQb5QSl SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2018 18:29:50.7691 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e5d91e1-1ecb-4b3f-2fa7-08d63527b123 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4435 Subject: [dpdk-dev] [PATCH v5 1/4] 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- v5: * Split the patch, this patch introduces the new infrastructure and performs only basic initializations. data path modifications are now performed in a separate patch. 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 infrastructure") --- drivers/net/mlx5/mlx5.c | 20 ++++---- drivers/net/mlx5/mlx5.h | 4 +- drivers/net/mlx5/mlx5_flow.h | 9 ++-- drivers/net/mlx5/mlx5_flow_tcf.c | 105 +++++++++++++++++++++++++++++++-------- 4 files changed, 99 insertions(+), 39 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 795a219..2c96080 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 >= 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 = 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 = mlx5_flow_tcf_socket_create(); - if (!priv->mnl_socket) { + priv->tcf_context = mlx5_flow_tcf_context_create(); + if (!priv->tcf_context) { err = -rte_errno; DRV_LOG(WARNING, "flow rules relying on switch offloads will not be" @@ -1155,16 +1155,16 @@ error.message = "cannot retrieve network interface index"; } else { - err = mlx5_flow_tcf_init(priv->mnl_socket, ifindex, - &error); + err = mlx5_flow_tcf_init(priv->tcf_context, + ifindex, &error); } if (err) { DRV_LOG(WARNING, "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 = NULL; + mlx5_flow_tcf_context_destroy(priv->tcf_context); + priv->tcf_context = NULL; } } TAILQ_INIT(&priv->flows); @@ -1219,8 +1219,8 @@ close(priv->nl_socket_route); if (priv->nl_socket_rdma >= 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. */ }; -struct mnl_socket; +struct mlx5_flow_tcf_context; 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. */ }; #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 d45fe8d..ee75a80 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -243,7 +243,6 @@ struct rte_flow { struct rte_flow_action_rss rss;/**< RSS context. */ uint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */ uint16_t (*queue)[]; /**< Destination queues to redirect traffic to. */ - void *nl_flow; /**< Netlink flow buffer if relevant. */ LIST_HEAD(dev_flows, mlx5_flow) dev_flows; /**< Device flows that are part of the flow. */ uint32_t actions; /**< Bit-fields which mark all detected actions. */ @@ -350,9 +349,9 @@ int mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item, /* mlx5_flow_tcf.c */ -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); #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 131b62b..5ce2d5f 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -235,6 +235,19 @@ struct tc_pedit_sel { #define TTL_LEN 1 #endif +/** + * 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 be + * 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; @@ -2153,7 +2166,7 @@ struct pedit_parser { struct rte_flow_error *error) { struct priv *priv = dev->data->dev_private; - struct mnl_socket *nl = priv->mnl_socket; + struct mnl_socket *nl = priv->tcf_context->nl; struct mlx5_flow *dev_flow; struct nlmsghdr *nlh; @@ -2182,7 +2195,7 @@ struct pedit_parser { flow_tcf_remove(struct rte_eth_dev *dev, struct rte_flow *flow) { struct priv *priv = dev->data->dev_private; - struct mnl_socket *nl = priv->mnl_socket; + struct mnl_socket *nl = priv->tcf_context->nl; struct mlx5_flow *dev_flow; struct nlmsghdr *nlh; @@ -2234,10 +2247,47 @@ struct pedit_parser { }; /** - * 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 * +flow_tcf_mnl_socket_create(void) +{ + struct mnl_socket *nl = 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 = 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 +flow_tcf_mnl_socket_destroy(struct mnl_socket *nl) +{ + if (nl) + mnl_socket_close(nl); +} + +/** + * Initialize ingress qdisc of a given network interface. + * + * @param ctx + * Pointer to tc-flower context to use. * @param ifindex * Index of network interface to initialize. * @param[out] error @@ -2247,11 +2297,12 @@ 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 *ctx, + unsigned int ifindex, struct rte_flow_error *error) { struct nlmsghdr *nlh; struct tcmsg *tcm; + struct mnl_socket *nl = ctx->nl; alignas(struct nlmsghdr) uint8_t buf[mnl_nlmsg_size(sizeof(*tcm) + 128)]; @@ -2290,37 +2341,47 @@ struct pedit_parser { } /** - * 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 = 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 = errno; - if (nl) - mnl_socket_close(nl); + struct mlx5_flow_tcf_context *ctx = rte_zmalloc(__func__, + sizeof(*ctx), + sizeof(uint32_t)); + if (!ctx) + goto error; + ctx->nl = flow_tcf_mnl_socket_create(); + if (!ctx->nl) + goto error; + ctx->buf_size = MNL_SOCKET_BUFFER_SIZE; + ctx->buf = rte_zmalloc(__func__, + ctx->buf_size, sizeof(uint32_t)); + if (!ctx->buf) + goto error; + ctx->seq = random(); + return ctx; +error: + mlx5_flow_tcf_context_destroy(ctx); return NULL; } /** - * 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; + flow_tcf_mnl_socket_destroy(ctx->nl); + rte_free(ctx->buf); + rte_free(ctx); } From patchwork Thu Oct 18 18:29:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moti Haimovsky X-Patchwork-Id: 47050 X-Patchwork-Delegate: shahafs@mellanox.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AF52A1B17E; Thu, 18 Oct 2018 20:29:58 +0200 (CEST) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40049.outbound.protection.outlook.com [40.107.4.49]) by dpdk.org (Postfix) with ESMTP id 222AA1B150 for ; Thu, 18 Oct 2018 20:29:53 +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=N5Lm0cHSy0bQvM3rsyBM/GIPHH5rhacOIq7SXXA9zXM=; b=BIvPwHmrU1XlVRuCCl9oCbUjIml359elO5KGiJY2LrQF5YCgCLpg+BHCkfN5Zd3SCYHv+Ajfm0ori3qUNmpJi4JlR2gPBGFBi3Dly/2AmGj8h5mXqKVJvk2Yv5+/ZqG/pTRFDjbF8CyzAYYjgp4aI3LBK2fDgQ8Y2KQrtAKcr5U= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=motih@mellanox.com; Received: from localhost.localdomain (37.142.13.130) by AM0PR05MB4435.eurprd05.prod.outlook.com (2603:10a6:208:5a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.21; Thu, 18 Oct 2018 18:29:51 +0000 From: Moti Haimovsky To: shahafs@mellanox.com Cc: dev@dpdk.org, Moti Haimovsky Date: Thu, 18 Oct 2018 21:29:21 +0300 Message-Id: <1539887363-27858-3-git-send-email-motih@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1539797092-2395-4-git-send-email-motih@mellanox.com> References: <1539797092-2395-4-git-send-email-motih@mellanox.com> MIME-Version: 1.0 X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: LO2P265CA0168.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::36) To AM0PR05MB4435.eurprd05.prod.outlook.com (2603:10a6:208:5a::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b24613ff-4b0c-4e61-8c7d-08d63527b18c 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:AM0PR05MB4435; X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4435; 3:hgHLHwdK6Fkmu/C4qUrRhYkE7t0gwh0MLWPAoiziOfmKypCzSAkzEgBQ7AV3E6kwUUWI/5gG8FlUz6ULba9p6n0Wms2ZWkLTdPMCA+kHmNS6vX+eHvA4vZTrN3VTpEM+uiR/qax2ZH2UxWhddjhS/aK71du9T0LwEt2EvTgNCg5cm9ljnwm5ZQZtfMmH2T7zbFffqZ9de898gsEIjfDM8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1eh6u2qtQgL7wdkaiGHS5to2Bv7B55fbXBH4SeQ/7THvBAQqQqyLyDYgXXB3K4kbqAAJS7U/v30w0beajSoAacvqBv66MBo5YL+/3RTe3uKIEu06c+p6NYdDIg2JLESfp+ykxC0EPZmV8NM; 4:qOsLAQD1F+mIpxjPH4z1JjlzBYoGHPtN1gVLE4hFO4BXtzdmufWFH2l1nf/CcmxipFpZuwx8X5sEOl79lC/xJ3M6Bo2OjDORFkWmCOyHXr/d6IDGEezuOhg7ecf+sut0fe87TCF9HbWnaa5ct0V/EXXcrRH4pWnyEJ/JAZ9h5AYHFzUEI9yQlqOfQuEffraQMb8FM1lLRqTWXhd8UbtlDDPOi4xuvPOPq3YZWo8Qtz+NBegUv4cB1ZH+2KWvxpMAwIqgrM7d+975M/MZO2aaPw== 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)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231355)(944501410)(52105095)(3002001)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:AM0PR05MB4435; BCL:0; PCL:0; RULEID:; SRVR:AM0PR05MB4435; X-Forefront-PRVS: 08296C9B35 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(39860400002)(136003)(396003)(376002)(346002)(366004)(199004)(189003)(3846002)(51416003)(37006003)(2906002)(6636002)(11346002)(76176011)(446003)(2351001)(5660300001)(53936002)(48376002)(6116002)(50466002)(47776003)(478600001)(6512007)(186003)(2616005)(6506007)(105586002)(26005)(14444005)(386003)(50226002)(106356001)(486006)(956004)(16526019)(2361001)(6666004)(97736004)(81166006)(36756003)(81156014)(8936002)(6486002)(4326008)(52116002)(107886003)(66066001)(68736007)(25786009)(69590400006)(16586007)(8676002)(305945005)(316002)(34206002)(86362001)(7736002)(476003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR05MB4435; H:localhost.localdomain; 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-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR05MB4435; 23:o+rrbqTGVkqczme0bavQLfVB743akgOT6Bs2No+qh?= 2mHCZK7NMXv+sgQrnQ48j54bIW9H+nwWQc/sxqrP4wDs9Vun4Cosm1OlJ+WU7XCasKzP7adNg32iAMpw3XahCdMrN1Ermjp4tWIYjEIwVaSHvejlJCaek3GJppTBeHyFev6rQT5tQWDVGksHtbuyIbB8IawnfercsvpsUG1RXnu5Nbgeoz7SvSvP65tBqnEBMoa2Gk7O/YO4/YKvfe7JvhQUYTCeMLM0QCZeS2o7r2hcXCUk6ai/tMOssknktJqY6iwZBK+V5wwhAOIQ3sBbVEESuAGuBQxLC9ZUEwPTLpYSOKEqJORkGlnwn27Zz8sffxfx9cfJA3lPc34o313tkW1IR1tUWIMIE6SdlznxUv6Pae3zve2hrYyg/wPfXwz995gf/QLBoJWF9gJwEeFG3otaZgj0G5LOuaMwggTtREQtkz2Eoa5rs8qkhNx4xb4+aAyatq8PfElIun0U8iV5yiNilN+Eqz54qRhS9+v6eUqP9mFJxwrGR8hQ+52jXMBU3Aw9lsSJLVtFF0eLnH9jqbgwOpd5nw2wsJOT1fCpdxwwAhHpqnaGzUbff35axRuHagYxqu99HejBxAI8b/2iuCvB394urm4QnrKaYiu3sW2Jh6TP/+Uz++McTxX0solwcCBx9OWxNYptf9hsp973f0iUWQpGbjsc91HZx9G9J9RwWlX1VuMsbQKtbYuHKAbVlw/tF7rrX3lR0DdZSuyMXomuRNoMMP3QyOd3zCGAGn4N5jnpYOZXU4LWtuabvJfZsB/YQo6b9Ipd+h0ixx4lapgFRV8cwUh+7ER3Fyy1k4Q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JWA8VhS0EARhTk6BASENMv0+JpfXA+XvpVB4xdIp1gJ5qdLi5KSfm+mi/IKRicxrJGqeA/rqR0RasiqeMfDQwjaOMAqdiypr+RvEz43cESiraE/C0bh8Kt8ODgBTjUvdY+tjHNiPZrkCK1WieprQvT16PjBf/67B8CsVlGO5B0kC+z8jTEgPiWtn4vEdltsXlYzoqDGDj0/zG3gWIHdKHoJPoJ6DtF5HOjUD5MjSXcobFWcrTsVXB3juVOBH93P+2JLykiISGkD+upSKFgd1FyAk5FbX+kmrfDJCrpPSO/soc+WG1bnAUCq0ZAA==; 5:CSa0whgd2IWdrfEKOykC9aPiiacEmcApeFt3slO3kzMpIRTnPPEwSCA4BxmcmTTr3ZxJGuiJWFLZQNrpk4elNG4XvzQwO6Cb8mvo7LynbT3AqwIJVBK4aZ2XM/mVScQYc7krdKiT09bIkbcLwOIP6bFXLrjvzB4QFljCE7sZXIU=; 7:u+tZDdny/kShqEKnSDJC5Fy1N3+EDtIxLRWEXuZY1uqoog+aCXuUPj1Rh7eFEI19BofkV02Sy2aczUhuXVT0gntw0zs4EXqLWEqmdBz0fImhOKaSQwUfe8I5VvIylEnW00c90ZPrmOqhfwgn8q/z1K4TI4Y8FWqilTu70086MVSYl5lcWjN5IYA6JnIZipA76Y3kuyWTdDgMh2gqvYqYZnHSAIu98ixsZvfy5vnqG4G9BVnSuaFF5Ml/XRwrNOcY SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2018 18:29:51.4596 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b24613ff-4b0c-4e61-8c7d-08d63527b18c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4435 Subject: [dpdk-dev] [PATCH v5 2/4] net/mlx5: tc flow to use the new 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" modified TC-flow code to use the new infrastructure introduced in "net/mlx5: refactor TC-flow infrastructure" commit. Signed-off-by: Moti Haimovsky --- v5: * Initial version of this patch. --- drivers/net/mlx5/mlx5_flow_tcf.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c index 5ce2d5f..b890aa2 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -2116,8 +2116,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 before * sending. @@ -2126,12 +2126,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 = random(); + uint32_t seq = ctx->seq++; + struct mnl_socket *nl = ctx->nl; int ret; nlh->nlmsg_flags |= NLM_F_ACK; @@ -2166,7 +2167,7 @@ struct pedit_parser { struct rte_flow_error *error) { struct priv *priv = dev->data->dev_private; - struct mnl_socket *nl = priv->tcf_context->nl; + struct mlx5_flow_tcf_context *ctx = priv->tcf_context; struct mlx5_flow *dev_flow; struct nlmsghdr *nlh; @@ -2176,7 +2177,7 @@ struct pedit_parser { nlh = dev_flow->tcf.nlh; nlh->nlmsg_type = RTM_NEWTFILTER; nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; - if (!flow_tcf_nl_ack(nl, nlh)) + if (!flow_tcf_nl_ack(ctx, nlh)) return 0; return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, @@ -2195,7 +2196,7 @@ struct pedit_parser { flow_tcf_remove(struct rte_eth_dev *dev, struct rte_flow *flow) { struct priv *priv = dev->data->dev_private; - struct mnl_socket *nl = priv->tcf_context->nl; + struct mlx5_flow_tcf_context *ctx = priv->tcf_context; struct mlx5_flow *dev_flow; struct nlmsghdr *nlh; @@ -2209,7 +2210,7 @@ struct pedit_parser { nlh = dev_flow->tcf.nlh; nlh->nlmsg_type = RTM_DELTFILTER; nlh->nlmsg_flags = NLM_F_REQUEST; - flow_tcf_nl_ack(nl, nlh); + flow_tcf_nl_ack(ctx, nlh); } /** @@ -2302,7 +2303,6 @@ struct pedit_parser { { struct nlmsghdr *nlh; struct tcmsg *tcm; - struct mnl_socket *nl = ctx->nl; alignas(struct nlmsghdr) uint8_t buf[mnl_nlmsg_size(sizeof(*tcm) + 128)]; @@ -2316,7 +2316,7 @@ struct pedit_parser { tcm->tcm_handle = TC_H_MAKE(TC_H_INGRESS, 0); tcm->tcm_parent = TC_H_INGRESS; /* Ignore errors when qdisc is already absent. */ - if (flow_tcf_nl_ack(nl, nlh) && + if (flow_tcf_nl_ack(ctx, nlh) && rte_errno != EINVAL && rte_errno != ENOENT) return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, @@ -2332,7 +2332,7 @@ struct pedit_parser { tcm->tcm_handle = TC_H_MAKE(TC_H_INGRESS, 0); tcm->tcm_parent = TC_H_INGRESS; mnl_attr_put_strz_check(nlh, sizeof(buf), TCA_KIND, "ingress"); - if (flow_tcf_nl_ack(nl, nlh)) + if (flow_tcf_nl_ack(ctx, nlh)) return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "netlink: failed to create ingress" @@ -2373,7 +2373,7 @@ struct mlx5_flow_tcf_context * /** * Destroy a libmnl context. * - * @param nl + * @param ctx * Libmnl socket of the @p NETLINK_ROUTE kind. */ void From patchwork Thu Oct 18 18:29:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moti Haimovsky X-Patchwork-Id: 47051 X-Patchwork-Delegate: shahafs@mellanox.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5AF6E1B18A; Thu, 18 Oct 2018 20:30:03 +0200 (CEST) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40072.outbound.protection.outlook.com [40.107.4.72]) by dpdk.org (Postfix) with ESMTP id 570B41B192 for ; Thu, 18 Oct 2018 20:30:02 +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=79sJVTezSzhsctgYmOnThO64l9o1wSOLiMBqogIs/G0=; b=vbrakg2Itvfcc1AQrnqPzxtj9z8j2TOrTXgXnYHhPdn1ANXfX/lD5WvZ3K3gOt7XHCCcaMIcZBQbXLScNpqylXa2nAygvNIuqMCaSMTJshxRX8fgexxx2thegBQgDdTWiT60B2e4BwSJq1WOtcxcZtApKS9rRbVFS9D7sq6fqhE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=motih@mellanox.com; Received: from localhost.localdomain (37.142.13.130) by AM0PR05MB4435.eurprd05.prod.outlook.com (2603:10a6:208:5a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.21; Thu, 18 Oct 2018 18:29:52 +0000 From: Moti Haimovsky To: shahafs@mellanox.com Cc: dev@dpdk.org, Moti Haimovsky Date: Thu, 18 Oct 2018 21:29:22 +0300 Message-Id: <1539887363-27858-4-git-send-email-motih@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1539797092-2395-4-git-send-email-motih@mellanox.com> References: <1539797092-2395-4-git-send-email-motih@mellanox.com> MIME-Version: 1.0 X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: LO2P265CA0168.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::36) To AM0PR05MB4435.eurprd05.prod.outlook.com (2603:10a6:208:5a::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4323e66a-a6f9-4e1a-e957-08d63527b1f5 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:AM0PR05MB4435; X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4435; 3:VIHkqw5KUDYJLXKGEJVXH6WjDbeLDlLMoh+CzFL3zzhhg7aSQ4HNCxfLq7SsVrd/+qWEe92jYFnwFiLxx+zb1czqLMx16vxuY0+xVzozPol9489jJquY0FjnxqFICqcvJGF8wG2CAgecrVdgqRmrtYUBcLflp3U03C0wVBpYgZ5peM/6D1Ms7FjYSo7gVnW3N+dZEPYoPYLJqyWbqL9tIdVlFZYBe4mXWchEZMuZAiX6KBFIlWRQHOG/bt+jOXY5; 25:UTlCj4LrDGhGknlyW6vKp5B3o0Z5M3LA1rmEcVTSYkscuC4xj23wTOoJLB2IPkrBHE5dykzcP2OqJOUgZqtTVlqyBfJ6H8lSnIlIA/B3cr4PZUaWPGC+UCNCY4Cte1wRJj1k4yGnQh+pKfUwUa9AnfIGWf2UIkkxFtiCQRUxeBOAT/sC7D61GwOjx8V+LAWLcY9ar41tzw7Yeb18SM7uLVfn05PwfYmsKAW8OG3sMuLSh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TLUW3g9aVtTzrIxQzfeKg4xxYGWVa7B3i13qffTcT3jFV1QdfBDlkQgBwXoTzxXr16SOYHYPon++v9GfCrH1jW9U5Ij/e6a9ARP/Ax3UrLqXMshKi6NIy4DYn5xeSFgGKcw7oyDA== 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)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231355)(944501410)(52105095)(3002001)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:AM0PR05MB4435; BCL:0; PCL:0; RULEID:; SRVR:AM0PR05MB4435; X-Forefront-PRVS: 08296C9B35 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(39860400002)(136003)(396003)(376002)(346002)(366004)(199004)(189003)(3846002)(51416003)(37006003)(2906002)(6636002)(11346002)(76176011)(446003)(2351001)(5660300001)(53936002)(48376002)(6116002)(50466002)(47776003)(478600001)(6512007)(186003)(2616005)(6506007)(105586002)(26005)(14444005)(386003)(50226002)(106356001)(486006)(956004)(16526019)(2361001)(6666004)(97736004)(81166006)(36756003)(81156014)(8936002)(6486002)(4326008)(52116002)(107886003)(66066001)(68736007)(25786009)(69590400006)(16586007)(8676002)(305945005)(575784001)(316002)(34206002)(86362001)(7736002)(476003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR05MB4435; H:localhost.localdomain; 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-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR05MB4435; 23:HxHv6PV9n/o0SQvP2oKMPDV9Ovc2eQAThQJ1HFjE7?= MLHfP3wCpJW/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3ID2oPpH8OZJzgt7+wwZw6IRPwtsgi6875+0gojIilZW1VCDrjkLNmehloe0IDXx9GcmUYY5g5H6ov8E5Jdngw==; 5:Vunh/xjFsq2xZQlc5pm7SFMACGZO/FX+5z1wmW5c55tJrxBCMkUY1QQFSxn+pmZnfvaV9tct0QkvDJ/61qhQA/NmWnLDdZLKi5uEk50erZUQfG/VcF4lSbY9djcFQRaxgpelTCP5scU4V2LJR04ThCamnR4VnNN/N6feZrT/2Lk=; 7:rWUbrEq+aOcZf8GL1Pthp0WkeLjjbHcoIYIKmNCrTMYo7x5fZSbbHHJwKmXhtESF/0fcWLW80/dmtJqgC3VEgxXwHHfcYR7a0aEcAqg4Skn5ycvhQukiKzqqxbGk1AAK9t0lkdKqLG+0fzWirYoW3UGV16ExwY/szzl1DAVSCeGjq42et0gINsU/hv1XEy9a7yzoNKumhjL5ZY2EsWzKgNAP4jATcRT9KbRQnOgirhC+4OJOnXQ+oQ8+V1Itk+o7 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2018 18:29:52.1501 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4323e66a-a6f9-4e1a-e957-08d63527b1f5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4435 Subject: [dpdk-dev] [PATCH v5 3/4] net/mlx5: add flow query abstraction interface 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" Flow engine now supports multiple driver paths with each having its own flow query implantation routine. This patch adds an abstraction to the flow query routine in accordance to commit 0c76d1c9a18d ("net/mlx5: add abstraction for multiple flow drivers") done by Yongseok Koh. Signed-off-by: Moti Haimovsky --- v4: * minor cosmetics. 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 infrastructure") --- drivers/net/mlx5/mlx5_flow.c | 99 ++++++++++++-------------------------- drivers/net/mlx5/mlx5_flow.h | 6 +++ drivers/net/mlx5/mlx5_flow_dv.c | 19 ++++++++ drivers/net/mlx5/mlx5_flow_tcf.c | 18 +++++++ drivers/net/mlx5/mlx5_flow_verbs.c | 87 +++++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+), 67 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index bd70fce..fcabab0 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -1653,6 +1653,17 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority, { } +static int +flow_null_query(struct rte_eth_dev *dev __rte_unused, + struct rte_flow *flow __rte_unused, + const struct rte_flow_action *actions __rte_unused, + void *data __rte_unused, + struct rte_flow_error *error __rte_unused) +{ + rte_errno = ENOTSUP; + return -rte_errno; +} + /* Void driver to protect from null pointer reference. */ const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = { .validate = flow_null_validate, @@ -1661,6 +1672,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority, .apply = flow_null_apply, .remove = flow_null_remove, .destroy = flow_null_destroy, + .query = flow_null_query, }; /** @@ -2344,92 +2356,45 @@ struct rte_flow * } /** - * Query flow counter. - * - * @param flow - * Pointer to the flow. + * Query a flow. * - * @return - * 0 on success, a negative errno value otherwise and rte_errno is set. + * @see rte_flow_query() + * @see rte_flow_ops */ static int -mlx5_flow_query_count(struct rte_flow *flow __rte_unused, - void *data __rte_unused, - struct rte_flow_error *error) +flow_drv_query(struct rte_eth_dev *dev, + struct rte_flow *flow, + const struct rte_flow_action *actions, + void *data, + struct rte_flow_error *error) { -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT - if (flow->actions & MLX5_FLOW_ACTION_COUNT) { - struct rte_flow_query_count *qc = data; - uint64_t counters[2] = {0, 0}; - struct ibv_query_counter_set_attr query_cs_attr = { - .cs = flow->counter->cs, - .query_flags = IBV_COUNTER_SET_FORCE_UPDATE, - }; - struct ibv_counter_set_data query_out = { - .out = counters, - .outlen = 2 * sizeof(uint64_t), - }; - int err = mlx5_glue->query_counter_set(&query_cs_attr, - &query_out); + const struct mlx5_flow_driver_ops *fops; + enum mlx5_flow_drv_type ftype = flow->drv_type; - if (err) - return rte_flow_error_set - (error, err, - RTE_FLOW_ERROR_TYPE_UNSPECIFIED, - NULL, - "cannot read counter"); - qc->hits_set = 1; - qc->bytes_set = 1; - qc->hits = counters[0] - flow->counter->hits; - qc->bytes = counters[1] - flow->counter->bytes; - if (qc->reset) { - flow->counter->hits = counters[0]; - flow->counter->bytes = counters[1]; - } - return 0; - } - return rte_flow_error_set(error, EINVAL, - RTE_FLOW_ERROR_TYPE_UNSPECIFIED, - NULL, - "flow does not have counter"); -#endif - return rte_flow_error_set(error, ENOTSUP, - RTE_FLOW_ERROR_TYPE_UNSPECIFIED, - NULL, - "counters are not available"); + assert(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX); + fops = flow_get_drv_ops(ftype); + + return fops->query(dev, flow, actions, data, error); } /** - * Query a flows. + * Query a flow. * * @see rte_flow_query() * @see rte_flow_ops */ int -mlx5_flow_query(struct rte_eth_dev *dev __rte_unused, +mlx5_flow_query(struct rte_eth_dev *dev, struct rte_flow *flow, const struct rte_flow_action *actions, void *data, struct rte_flow_error *error) { - int ret = 0; + int ret; - for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) { - switch (actions->type) { - case RTE_FLOW_ACTION_TYPE_VOID: - break; - case RTE_FLOW_ACTION_TYPE_COUNT: - ret = mlx5_flow_query_count(flow, data, error); - break; - default: - return rte_flow_error_set(error, ENOTSUP, - RTE_FLOW_ERROR_TYPE_ACTION, - actions, - "action not supported"); - } - if (ret < 0) - return ret; - } + ret = flow_drv_query(dev, flow, actions, data, error); + if (ret < 0) + return ret; return 0; } diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index ee75a80..af0a125 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -268,6 +268,11 @@ typedef void (*mlx5_flow_remove_t)(struct rte_eth_dev *dev, struct rte_flow *flow); typedef void (*mlx5_flow_destroy_t)(struct rte_eth_dev *dev, struct rte_flow *flow); +typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev, + struct rte_flow *flow, + const struct rte_flow_action *actions, + void *data, + struct rte_flow_error *error); struct mlx5_flow_driver_ops { mlx5_flow_validate_t validate; mlx5_flow_prepare_t prepare; @@ -275,6 +280,7 @@ struct mlx5_flow_driver_ops { mlx5_flow_apply_t apply; mlx5_flow_remove_t remove; mlx5_flow_destroy_t destroy; + mlx5_flow_query_t query; }; /* mlx5_flow.c */ diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index becbc57..58e3c33 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -1363,6 +1363,24 @@ } } +/** + * Query a flow. + * + * @see rte_flow_query() + * @see rte_flow_ops + */ +static int +flow_dv_query(struct rte_eth_dev *dev __rte_unused, + struct rte_flow *flow __rte_unused, + const struct rte_flow_action *actions __rte_unused, + void *data __rte_unused, + struct rte_flow_error *error __rte_unused) +{ + rte_errno = ENOTSUP; + return -rte_errno; +} + + const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops = { .validate = flow_dv_validate, .prepare = flow_dv_prepare, @@ -1370,6 +1388,7 @@ .apply = flow_dv_apply, .remove = flow_dv_remove, .destroy = flow_dv_destroy, + .query = flow_dv_query, }; #endif /* HAVE_IBV_FLOW_DV_SUPPORT */ diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c index b890aa2..6b19b2a 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -2238,6 +2238,23 @@ struct pedit_parser { rte_free(dev_flow); } +/** + * Query a flow. + * + * @see rte_flow_query() + * @see rte_flow_ops + */ +static int +flow_tcf_query(struct rte_eth_dev *dev __rte_unused, + struct rte_flow *flow __rte_unused, + const struct rte_flow_action *actions __rte_unused, + void *data __rte_unused, + struct rte_flow_error *error __rte_unused) +{ + rte_errno = ENOTSUP; + return -rte_errno; +} + const struct mlx5_flow_driver_ops mlx5_flow_tcf_drv_ops = { .validate = flow_tcf_validate, .prepare = flow_tcf_prepare, @@ -2245,6 +2262,7 @@ struct pedit_parser { .apply = flow_tcf_apply, .remove = flow_tcf_remove, .destroy = flow_tcf_destroy, + .query = flow_tcf_query, }; /** diff --git a/drivers/net/mlx5/mlx5_flow_verbs.c b/drivers/net/mlx5/mlx5_flow_verbs.c index 65c849c..4ae974b 100644 --- a/drivers/net/mlx5/mlx5_flow_verbs.c +++ b/drivers/net/mlx5/mlx5_flow_verbs.c @@ -1651,6 +1651,92 @@ return -rte_errno; } +/** + * Query a flows. + * + * @see rte_flow_query() + * @see rte_flow_ops + */ +static int +flow_verbs_query_count(struct rte_eth_dev *dev __rte_unused, + struct rte_flow *flow __rte_unused, + void *data __rte_unused, + struct rte_flow_error *error) +{ +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT + if (flow->actions & MLX5_FLOW_ACTION_COUNT) { + struct rte_flow_query_count *qc = data; + uint64_t counters[2] = {0, 0}; + struct ibv_query_counter_set_attr query_cs_attr = { + .cs = flow->counter->cs, + .query_flags = IBV_COUNTER_SET_FORCE_UPDATE, + }; + struct ibv_counter_set_data query_out = { + .out = counters, + .outlen = 2 * sizeof(uint64_t), + }; + int err = mlx5_glue->query_counter_set(&query_cs_attr, + &query_out); + + if (err) + return rte_flow_error_set + (error, err, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "cannot read counter"); + qc->hits_set = 1; + qc->bytes_set = 1; + qc->hits = counters[0] - flow->counter->hits; + qc->bytes = counters[1] - flow->counter->bytes; + if (qc->reset) { + flow->counter->hits = counters[0]; + flow->counter->bytes = counters[1]; + } + return 0; + } + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "flow does not have counter"); +#endif + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "counters are not available"); +} + +/** + * Query a flow. + * + * @see rte_flow_query() + * @see rte_flow_ops + */ +static int +flow_verbs_query(struct rte_eth_dev *dev, + struct rte_flow *flow, + const struct rte_flow_action *actions, + void *data, + struct rte_flow_error *error) +{ + int ret = -EINVAL; + + for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) { + switch (actions->type) { + case RTE_FLOW_ACTION_TYPE_VOID: + break; + case RTE_FLOW_ACTION_TYPE_COUNT: + ret = flow_verbs_query_count(dev, flow, data, error); + break; + default: + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "action not supported"); + } + } + return ret; +} + const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops = { .validate = flow_verbs_validate, .prepare = flow_verbs_prepare, @@ -1658,4 +1744,5 @@ .apply = flow_verbs_apply, .remove = flow_verbs_remove, .destroy = flow_verbs_destroy, + .query = flow_verbs_query, }; From patchwork Thu Oct 18 18:29:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moti Haimovsky X-Patchwork-Id: 47052 X-Patchwork-Delegate: shahafs@mellanox.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 62B191B195; Thu, 18 Oct 2018 20:30:06 +0200 (CEST) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40053.outbound.protection.outlook.com [40.107.4.53]) by dpdk.org (Postfix) with ESMTP id 398AC1B150 for ; Thu, 18 Oct 2018 20:30:03 +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=yc+DC5d1VNMnjBYHlA1LkFDt8E/l/3RpohrR+GadiGE=; b=QozhwkNduqLP6qPfnvXfefrcQtEUycn0kaUBX9IS4tsAj7JvEL3HnfnLAe9BCxJyP4dCnq92G+bG3Z3ATCWRTiQBmmWgBIP7L3zthYs3IkyCtxvZTtUtOGhYjowkiJs/NyHgRJgV7dqXv7V8FwQ4QEjEPvVKRiPfu2OAi6ns0js= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=motih@mellanox.com; Received: from localhost.localdomain (37.142.13.130) by AM0PR05MB4435.eurprd05.prod.outlook.com (2603:10a6:208:5a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.21; Thu, 18 Oct 2018 18:30:01 +0000 From: Moti Haimovsky To: shahafs@mellanox.com Cc: dev@dpdk.org, Moti Haimovsky Date: Thu, 18 Oct 2018 21:29:23 +0300 Message-Id: <1539887363-27858-5-git-send-email-motih@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1539797092-2395-4-git-send-email-motih@mellanox.com> References: <1539797092-2395-4-git-send-email-motih@mellanox.com> MIME-Version: 1.0 X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: LO2P265CA0168.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::36) To AM0PR05MB4435.eurprd05.prod.outlook.com (2603:10a6:208:5a::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 88e6ee0b-e8e6-4c0b-1f9f-08d63527b7a7 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:AM0PR05MB4435; X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4435; 3:K5JeFyZmSSDC+YsOga+ZSNmYWjfLYrWswkMMnyKCV8tFOfcFd3MTHOclRSiGccBEhpMJh31PVLyCFqAnM1WkPJgwKwbvX4MH/2thfvikdzRDXVaAvpwdn9to0mMPcwNm2Hedn0lLJwnaqo/B6DKMl2Au3G5zNZnAgbCrIsuh0gsGu7WO3QsdKC8hx5lYVLECUlr5ESQeUdqKb9NhkLC0ilPq0Ga851OZdT33oKoyyCaQTgzhpaq91KKG3lqb/4+B; 25:DBbAGVIn8tT01hVdEvfa2Qqlvsb2goWoVqSKIH4CPS4CHE5yr4bjjY6UcwqCClPzgV5xK/JPQ99B+dHyIxU1L54WeginuJl9FMjLQmpTErce/DrrTqltYenVVaS/NAuvmd8ZPRPmNQ4muNL+E0R8UFjOXZKLyHF4lGR/OlEj8z/bkZ34w3KsPBej6+8gUn5ZiF5mLjetJfotFwCO8NuyoBJORfnpUiJMcP49ihDFGrMWsNksSVbUvxRrKK2LzIWSFvYwWcf7SZ+GsvPTGboPpUpJ9jx8FWQVij2p7jrxjx0JReA0VZqn5tEFhs9zrJkxSNHG1YMmLz0Izp/4QPgKPQ==; 31:WmVo4NgQRUk8EKXs4VvwKQSTCXhXpAlz4cQvwnkBRSb3FICeb7djI0qhJc9L1RLFwEoGuxRCji1/s42Jzrzix3uXANhuwr7/IufQ8DTqtF6obLnF0ouPW+wbGu1NMEgEc65JrMMQISBS8BYYCOuK1/KcEWKZFrQr98WPYr+tIhyeBw1c7z7N4HZuuDSiNufU0W4U+y1VAJf72ppy6uYQI/b7OwhQ6MCJwfGOY3kbvkk= X-MS-TrafficTypeDiagnostic: AM0PR05MB4435: X-Microsoft-Exchange-Diagnostics: 1; AM0PR05MB4435; 20:qbdyteWnF8C7RIX+MQ1Cim4BJRhxJlWJmRahRGa3a3xmx8be4KZGRSAvCppXinggP7MeafyeIEmopHt1TjkW6b8TIr1ouMCD+oXpYoy7nirBu2P4z+8aiTEKEzEHRLYVeetJvO94qE4CSBdwFS5UKX5JSOsWtpA1vsVI9qWTaj+DDsJwHYkFdkSe5aymhRebj9qOns/iXUGBWL3QO1az7Eng1zxhEtBzvdeSkeWoKDbFjYTm4MVljz3wiHmSXuN/Fitx2DMyuwcQo4YUU7KYRReQJsVjVSVkkQmr8r87OfS6qlsXQXozK4Fp5AibCmq5sEU+4C8qEjK9ddF5GbQ+m4X+bk/L3clQQs/bkHzMpNESwTkfOTTplUHiuAzokJIu0jsY2bvzvBaggQK+ggZRgg+dPFbeka4hYIm97EVzHBBhbHWkmCjwKdmChVFMvELlIkebNc4ZZo2KU+7L/lMJg/z91s7QR3modG9wMOSL0hWjoCzYxeZyWPgebyApLZhM; 4:G8GMdmRiBjOTrxHCXpWQIQDs8RwKJ3aZht5upzNuHSAux5bAzR2Lkh+ZmfEqvZCUZYh49pCyX56oDVnlqWnik7TV0MQVwa7/S5ENvMS2AIzSrnS51e59RXIXzWkoaGBTbHDW8PSqvJ+wmer8u+lQA6SzzCb3V0rSkP8XVGlOn5zgrk4BWhEDYF/9Ymgf1CddU/uwlNDw8WFZYf6iSg+4cCaRBtTyMMn6z8ivlSJVA2vGRxVw/4ARa6QkyaZ7jI08ADVpNLPd55k1AChLlABU0aJv+Slpr/4XoGWKZaxkWk4pTsBmyq15pfCogX5hph1M X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(211171220733660); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231355)(944501410)(52105095)(3002001)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:AM0PR05MB4435; BCL:0; PCL:0; RULEID:; SRVR:AM0PR05MB4435; X-Forefront-PRVS: 08296C9B35 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(39860400002)(136003)(396003)(376002)(346002)(366004)(199004)(189003)(3846002)(51416003)(37006003)(2906002)(6636002)(11346002)(76176011)(446003)(2351001)(5660300001)(53936002)(48376002)(6116002)(50466002)(47776003)(478600001)(6512007)(186003)(2616005)(6506007)(105586002)(26005)(14444005)(386003)(50226002)(106356001)(486006)(956004)(16526019)(2361001)(6666004)(97736004)(81166006)(36756003)(81156014)(8936002)(4744004)(6486002)(4326008)(52116002)(107886003)(66066001)(68736007)(25786009)(69590400006)(16586007)(8676002)(305945005)(316002)(34206002)(86362001)(7736002)(476003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR05MB4435; H:localhost.localdomain; 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-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR05MB4435; 23:DonhNsweRXrQ8DPAaW3U7qEtSHVTZ/ShGBhUcy86w?= ZC3NQra9XXqgYexDP2TCYC7KJNvhfFcj0RgjD+Cg31/cspE50GqNOHRlSv5FitSbvyZyLX5el/vTAUzrRetrl9H+jIuuhVZyI/I6RJ3jHR/41a0tgvchrBMCIuXjiMLQHz0NC8dKWspAk1W6PzS2MDamamoHsK/fYidMOoIPMsguxR5RCeyJpBDKnsSmYr8cB7iXt1IxJmhfPvvVfkGuQMODLVcCnBWSH35AtwZSYw/Qwo8sv5FhEaBf4xJqZUVtzIv4JfLw83G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qhfXwwkgmz9tq/iPXXYLVMdIw9YwlnWQv6ickDLZGdIHGkE08MTo4odLNth/1oajSIqHzb2wLTl2+WJb9Jv91+/lir0MMbopaAocbqp9154bwBDfufvJ7VDBN0gmEPHu+23Axc9ixeMCCdBzPnEv4yeIkg9gL42FipAgVqb3HkcOcxu9PU0OrdNIAdJVvu0UH1mlxJXFkLy+ElYeLoUEYHOuw SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2018 18:30:01.6340 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88e6ee0b-e8e6-4c0b-1f9f-08d63527b7a7 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4435 Subject: [dpdk-dev] [PATCH v5 4/4] net/mlx5: support e-switch flow count action 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" This commit adds support for configuring flows destined to the mlx5 eswitch with 'count' action and for querying these counts at runtime. Each flow rule configured by the mlx5 driver is implicitly assigned with flow counters. These counters can be retrieved when querying the flow rule via Netlink, they can be found in each flow action section of the reply. Hence, supporting the 'count' action in the flow configuration command is straight-forward. When transposing the command to a tc Netlink message we just ignore it instead of rejecting it. In the 'flow query count' side, the command now uses tc Netlink query command in order to retrieve the values of the flow counters. Signed-off-by: Moti Haimovsky --- v5: * Limited tc-flower message parsing to only the range of values requested. * Removed "problematic" define. v4: * Split the patch in two. This patch now contains only the tcf implementation of count action and query. * Fixed compilation error found on "old" kernels. * Modifications according to inputs from Shahaf S. v3: * Rebase on top of d80c8167c4fe ("net/mlx5: fix compilation issue on ARM SOC") * Code modifications accordig to review by Shahaf S. see message ID: 1539263057-16678-3-git-send-email-motih@mellanox.com v2: * Rebase on top of 3f4722ee01e7 ("net/mlx5: refactor TC-flow infrastructure" --- drivers/net/mlx5/mlx5_flow_tcf.c | 517 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 510 insertions(+), 7 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c index 6b19b2a..2dc2811 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include #include "mlx5.h" #include "mlx5_flow.h" @@ -248,6 +250,14 @@ struct mlx5_flow_tcf_context { uint8_t *buf; /* Message buffer. */ }; +/** Structure used when extracting the values of a flow counters + * from a netlink message. + */ +struct flow_tcf_stats_basic { + bool valid; + struct gnet_stats_basic counters; +}; + /** Empty masks for known item types. */ static const union { struct rte_flow_item_port_id port_id; @@ -363,6 +373,43 @@ struct pedit_parser { struct pedit_key_ex keys_ex[MAX_PEDIT_KEYS]; }; +/** + * Create space for using the implicitly created TC flow counter. + * + * @param[in] dev + * Pointer to the Ethernet device structure. + * + * @return + * A pointer to the counter data structure, NULL otherwise and + * rte_errno is set. + */ +static struct mlx5_flow_counter * +flow_tcf_counter_new(void) +{ + struct mlx5_flow_counter *cnt; + + /* + * eswitch counter cannot be shared and its id is unknown. + * currently returning all with id 0. + * in the future maybe better to switch to unique numbers. + */ + struct mlx5_flow_counter tmpl = { + .ref_cnt = 1, + .shared = 0, + .id = 0, + .cs = NULL, + .hits = 0, + .bytes = 0, + }; + cnt = rte_calloc(__func__, 1, sizeof(*cnt), 0); + if (!cnt) { + rte_errno = ENOMEM; + return NULL; + } + *cnt = tmpl; + /* Implicit counter, do not add to list. */ + return cnt; +} /** * Set pedit key of MAC address @@ -1175,6 +1222,8 @@ struct pedit_parser { case RTE_FLOW_ACTION_TYPE_DROP: current_action_flag = MLX5_FLOW_ACTION_DROP; break; + case RTE_FLOW_ACTION_TYPE_COUNT: + break; case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN: current_action_flag = MLX5_FLOW_ACTION_OF_POP_VLAN; break; @@ -1481,6 +1530,8 @@ struct pedit_parser { SZ_NLATTR_TYPE_OF(struct tc_gact); flags |= MLX5_FLOW_ACTION_DROP; break; + case RTE_FLOW_ACTION_TYPE_COUNT: + break; case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN: flags |= MLX5_FLOW_ACTION_OF_POP_VLAN; goto action_of_vlan; @@ -1620,6 +1671,38 @@ struct pedit_parser { } /** + * Make adjustments for supporting count actions. + * + * @param[in] dev + * Pointer to the Ethernet device structure. + * @param[in] dev_flow + * Pointer to mlx5_flow. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 On success else a negative errno value is returned and rte_errno is set. + */ +static int +flow_tcf_translate_action_count(struct rte_eth_dev *dev __rte_unused, + struct mlx5_flow *dev_flow, + struct rte_flow_error *error) +{ + struct rte_flow *flow = dev_flow->flow; + + if (!flow->counter) { + flow->counter = flow_tcf_counter_new(); + if (!flow->counter) + return rte_flow_error_set(error, rte_errno, + RTE_FLOW_ERROR_TYPE_ACTION, + NULL, + "cannot get counter" + " context."); + } + return 0; +} + +/** * Translate flow for Linux TC flower and construct Netlink message. * * @param[in] priv @@ -1676,6 +1759,7 @@ struct pedit_parser { struct nlattr *na_vlan_id = NULL; struct nlattr *na_vlan_priority = NULL; uint64_t item_flags = 0; + int ret; claim_nonzero(flow_tcf_build_ptoi_table(dev, ptoi, PTOI_TABLE_SZ_MAX(dev))); @@ -2018,6 +2102,16 @@ struct pedit_parser { mnl_attr_nest_end(nlh, na_act); mnl_attr_nest_end(nlh, na_act_index); break; + case RTE_FLOW_ACTION_TYPE_COUNT: + /* + * Driver adds the count action implicitly for + * each rule it creates. + */ + ret = flow_tcf_translate_action_count(dev, + dev_flow, error); + if (ret < 0) + return ret; + break; case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN: conf.of_push_vlan = NULL; vlan_act = TCA_VLAN_ACT_POP; @@ -2202,6 +2296,12 @@ struct pedit_parser { if (!flow) return; + if (flow->counter) { + if (--flow->counter->ref_cnt == 0) { + rte_free(flow->counter); + flow->counter = NULL; + } + } dev_flow = LIST_FIRST(&flow->dev_flows); if (!dev_flow) return; @@ -2239,20 +2339,423 @@ struct pedit_parser { } /** + * Helper routine for figuring the space size required for a parse buffer. + * + * @param array + * array of values to use. + * @param idx + * Current location in array. + * @param value + * Value to compare with. + * + * @return + * MAX(array[idx], value) if idx is valid. value otherwise. + */ +static uint16_t +arval_max(uint16_t array[], int idx, uint16_t value) +{ + return idx < 0 ? (value) : RTE_MAX((array)[idx], value); +} + +/** + * Parse rtnetlink message attributes filling the attribute table with the info + * retrieved. + * + * @param tb + * Attribute table to be filled. + * @param[out] max + * Maxinum entry in the attribute table. + * @param rte + * The attributes section in the message to be parsed. + * @param len + * The length of the attributes section in the message. + */ +static void +flow_tcf_nl_parse_rtattr(struct rtattr *tb[], int max, + struct rtattr *rta, int len) +{ + unsigned short type; + memset(tb, 0, sizeof(struct rtattr *) * (max + 1)); + while (RTA_OK(rta, len)) { + type = rta->rta_type; + if (type <= max && !tb[type]) + tb[type] = rta; + rta = RTA_NEXT(rta, len); + } +} + +/** + * Extract flow counters from flower action. + * + * @param rta + * flower action stats properties in the Netlink message received. + * @param rta_type + * The backward sequence of rta_types, as written in the attribute table, + * we need to traverse in order to get to the requested object. + * @param idx + * Current location in rta_type table. + * @param[out] data + * data holding the count statistics of the rte_flow retrieved from + * the message. + * + * @return + * 0 if data was found and retrieved, -1 otherwise. + */ +static int +flow_tcf_nl_action_stats_parse_and_get(struct rtattr *rta, + uint16_t rta_type[], int idx, + struct gnet_stats_basic *data) +{ + int tca_stats_max = arval_max(rta_type, idx, 0); + struct rtattr *tbs[tca_stats_max + 1]; + + if (rta == NULL || idx < 0) + return -1; + flow_tcf_nl_parse_rtattr(tbs, tca_stats_max, + RTA_DATA(rta), RTA_PAYLOAD(rta)); + switch (rta_type[idx]) { + case TCA_STATS_BASIC: + if (tbs[TCA_STATS_BASIC]) { + memcpy(data, RTA_DATA(tbs[TCA_STATS_BASIC]), + RTE_MIN(RTA_PAYLOAD(tbs[TCA_STATS_BASIC]), + sizeof(*data))); + return 0; + } + break; + default: + break; + } + return -1; +} + +/** + * Parse flower single action retrieving the requested action attribute, + * if found. + * + * @param arg + * flower action properties in the Netlink message received. + * @param rta_type + * The backward sequence of rta_types, as written in the attribute table, + * we need to traverse in order to get to the requested object. + * @param idx + * Current location in rta_type table. + * @param[out] data + * Count statistics retrieved from the message query. + * + * @return + * 0 if data was found and retrieved, -1 otherwise. + */ +static int +flow_tcf_nl_parse_one_action_and_get(struct rtattr *arg, + uint16_t rta_type[], int idx, void *data) +{ + int tca_act_max = arval_max(rta_type, idx, TCA_ACT_KIND); + struct rtattr *tb[tca_act_max + 1]; + + if (arg == NULL || idx < 0) + return -1; + flow_tcf_nl_parse_rtattr(tb, tca_act_max, + RTA_DATA(arg), RTA_PAYLOAD(arg)); + if (tb[TCA_ACT_KIND] == NULL) + return -1; + switch (rta_type[idx]) { + case TCA_ACT_STATS: + if (tb[TCA_ACT_STATS]) + return flow_tcf_nl_action_stats_parse_and_get + (tb[TCA_ACT_STATS], + rta_type, --idx, + (struct gnet_stats_basic *)data); + break; + default: + break; + } + return -1; +} + +/** + * Parse flower action section in the message retrieving the requested + * attribute from the first action that provides it. + * + * @param opt + * flower section in the Netlink message received. + * @param rta_type + * The backward sequence of rta_types, as written in the attribute table, + * we need to traverse in order to get to the requested object. + * @param idx + * Current location in rta_type table. + * @param[out] data + * data retrieved from the message query. + * + * @return + * 0 if data was found and retrieved, -1 otherwise. + */ +static int +flow_tcf_nl_action_parse_and_get(const struct rtattr *arg, + uint16_t rta_type[], int idx, void *data) +{ + struct rtattr *tb[TCA_ACT_MAX_PRIO + 1]; + int i; + + if (arg == NULL || idx < 0) + return -1; + flow_tcf_nl_parse_rtattr(tb, TCA_ACT_MAX_PRIO, + RTA_DATA(arg), RTA_PAYLOAD(arg)); + switch (rta_type[idx]) { + /* + * flow counters are stored in the actions defined by the flow + * and not in the flow itself, therefore we need to traverse the + * flower chain of actions in search for them. + * + * Note that the index is not decremented here. + */ + case TCA_ACT_STATS: + for (i = 0; i <= TCA_ACT_MAX_PRIO; i++) { + if (tb[i] && + !flow_tcf_nl_parse_one_action_and_get(tb[i], + rta_type, + idx, data)) + return 0; + } + break; + default: + break; + } + return -1; +} + +/** + * Parse flower classifier options in the message, retrieving the requested + * attribute if found. + * + * @param opt + * flower section in the Netlink message received. + * @param rta_type + * The backward sequence of rta_types, as written in the attribute table, + * we need to traverse in order to get to the requested object. + * @param idx + * Current location in rta_type table. + * @param[out] data + * data retrieved from the message query. + * + * @return + * 0 if data was found and retrieved, -1 otherwise. + */ +static int +flow_tcf_nl_opts_parse_and_get(struct rtattr *opt, + uint16_t rta_type[], int idx, void *data) +{ + int tca_flower_max = arval_max(rta_type, idx, 0); + struct rtattr *tb[tca_flower_max + 1]; + + if (!opt || idx < 0) + return -1; + flow_tcf_nl_parse_rtattr(tb, tca_flower_max, + RTA_DATA(opt), RTA_PAYLOAD(opt)); + switch (rta_type[idx]) { + case TCA_FLOWER_ACT: + if (tb[TCA_FLOWER_ACT]) + return flow_tcf_nl_action_parse_and_get + (tb[TCA_FLOWER_ACT], + rta_type, --idx, data); + break; + default: + break; + } + return -1; +} + +/** + * Parse Netlink reply on filter query, retrieving the flow counters. + * + * @param nlh + * Message received from Netlink. + * @param rta_type + * The backward sequence of rta_types, as written in the attribute table, + * we need to traverse in order to get to the requested object. + * @param idx + * Current location in rta_type table. + * @param[out] data + * data retrieved from the message query. + * + * @return + * 0 if data was found and retrieved, -1 otherwise. + */ +static int +flow_tcf_nl_filter_parse_and_get(const struct nlmsghdr *nlh, + uint16_t rta_type[], int idx, void *data) +{ + struct tcmsg *t = NLMSG_DATA(nlh); + int len = nlh->nlmsg_len; + int tca_max = arval_max(rta_type, idx, TCA_KIND); + struct rtattr *tb[tca_max + 1]; + + if (idx < 0) + return -1; + if (nlh->nlmsg_type != RTM_NEWTFILTER && + nlh->nlmsg_type != RTM_GETTFILTER && + nlh->nlmsg_type != RTM_DELTFILTER) + return -1; + len -= NLMSG_LENGTH(sizeof(*t)); + if (len < 0) + return -1; + flow_tcf_nl_parse_rtattr(tb, tca_max, TCA_RTA(t), len); + /* Not a TC flower flow - bail out */ + if (!tb[TCA_KIND] || + strcmp(RTA_DATA(tb[TCA_KIND]), "flower")) + return -1; + switch (rta_type[idx]) { + case TCA_OPTIONS: + if (tb[TCA_OPTIONS]) + return flow_tcf_nl_opts_parse_and_get(tb[TCA_OPTIONS], + rta_type, + --idx, data); + break; + default: + break; + } + return -1; +} + +/** + * A callback to parse Netlink reply on TC flower query. + * + * @param nlh + * Message received from Netlink. + * @param[out] data + * Pointer to data area to be filled by the parsing routine. + * assumed to be a pinter to struct flow_tcf_stats_basic. + * + * @return + * MNL_CB_OK value. + */ +static int +flow_tcf_nl_message_get_stats_basic(const struct nlmsghdr *nlh, void *data) +{ + /* + * The backward sequence of rta_types to pass in order to get + * to the counters. + */ + uint16_t rta_type[] = { TCA_STATS_BASIC, TCA_ACT_STATS, + TCA_FLOWER_ACT, TCA_OPTIONS }; + struct flow_tcf_stats_basic *sb_data = data; + + if (!flow_tcf_nl_filter_parse_and_get(nlh, rta_type, + RTE_DIM(rta_type) - 1, + (void *)&sb_data->counters)) + sb_data->valid = true; + return MNL_CB_OK; +} + +/** + * Query a TC flower rule for its statistics via netlink. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[in] flow + * Pointer to the sub flow. + * @param[out] data + * data retrieved by the query. + * @param[out] error + * Perform verbose error reporting if not NULL. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +flow_tcf_query_count(struct rte_eth_dev *dev, + struct rte_flow *flow, + void *data, + struct rte_flow_error *error) +{ + struct flow_tcf_stats_basic sb_data = { 0 }; + struct rte_flow_query_count *qc = data; + struct priv *priv = dev->data->dev_private; + struct mlx5_flow_tcf_context *ctx = priv->tcf_context; + struct mnl_socket *nl = ctx->nl; + struct mlx5_flow *dev_flow; + struct nlmsghdr *nlh; + uint32_t seq = priv->tcf_context->seq++; + ssize_t ret; + assert(qc); + + dev_flow = LIST_FIRST(&flow->dev_flows); + /* E-Switch flow can't be expanded. */ + assert(!LIST_NEXT(dev_flow, next)); + if (!dev_flow->flow->counter) + goto notsup_exit; + nlh = dev_flow->tcf.nlh; + nlh->nlmsg_type = RTM_GETTFILTER; + nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ECHO; + nlh->nlmsg_seq = seq; + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) == -1) + goto error_exit; + do { + ret = mnl_socket_recvfrom(nl, ctx->buf, ctx->buf_size); + if (ret <= 0) + break; + ret = mnl_cb_run(ctx->buf, ret, seq, + mnl_socket_get_portid(nl), + flow_tcf_nl_message_get_stats_basic, + (void *)&sb_data); + } while (ret > 0); + /* Return the delta from last reset. */ + if (sb_data.valid) { + /* Return the delta from last reset. */ + qc->hits_set = 1; + qc->bytes_set = 1; + qc->hits = sb_data.counters.packets; + qc->hits -= flow->counter->hits; + qc->bytes = sb_data.counters.bytes - flow->counter->bytes; + if (qc->reset) { + flow->counter->hits = sb_data.counters.packets; + flow->counter->bytes = sb_data.counters.bytes; + } + return 0; + } + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "flow does not have counter"); +error_exit: + return rte_flow_error_set + (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "netlink: failed to read flow rule counters"); +notsup_exit: + return rte_flow_error_set + (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "counters are not available."); +} + +/** * Query a flow. * * @see rte_flow_query() * @see rte_flow_ops */ static int -flow_tcf_query(struct rte_eth_dev *dev __rte_unused, - struct rte_flow *flow __rte_unused, - const struct rte_flow_action *actions __rte_unused, - void *data __rte_unused, - struct rte_flow_error *error __rte_unused) +flow_tcf_query(struct rte_eth_dev *dev, + struct rte_flow *flow, + const struct rte_flow_action *actions, + void *data, + struct rte_flow_error *error) { - rte_errno = ENOTSUP; - return -rte_errno; + int ret = -EINVAL; + + for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) { + switch (actions->type) { + case RTE_FLOW_ACTION_TYPE_VOID: + break; + case RTE_FLOW_ACTION_TYPE_COUNT: + ret = flow_tcf_query_count(dev, flow, data, error); + break; + default: + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "action not supported"); + } + } + return ret; } const struct mlx5_flow_driver_ops mlx5_flow_tcf_drv_ops = {