From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80078.outbound.protection.outlook.com [40.107.8.78]) by dpdk.org (Postfix) with ESMTP id 0788D54AE for ; Wed, 17 Oct 2018 15:54:22 +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=xd3MjyLlzpPQR964pf7La3/UTAdfPLnb6AI7jGX978w=; b=lZJUZFNzXD8J/e87ptZ8T9gCzSb7KdsqdppqI0qeJFAd2uK8rIT/zkH3B3N0+hxoew9XWz6whDa9zc9ehrt/8w/dInysX7hwXOhjvXEzlfz7gUGdsR+1iDsDDT389o9QqKDZQ5h6iCRNr9ClnjWGOyD5j+5gkRtJKWpOjxVHy2k= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=viacheslavo@mellanox.com; Received: from mellanox.com (37.142.13.130) by DB6PR05MB3272.eurprd05.prod.outlook.com (2603:10a6:6:25::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.23; Wed, 17 Oct 2018 13:54:19 +0000 From: Viacheslav Ovsiienko To: shahafs@mellanox.com, yskoh@mellanox.com Cc: dev@dpdk.org, Viacheslav Ovsiienko Date: Wed, 17 Oct 2018 13:53:58 +0000 Message-Id: <1539784438-29242-1-git-send-email-viacheslavo@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1538580540-2224-1-git-send-email-viacheslavo@mellanox.com> References: <1538580540-2224-1-git-send-email-viacheslavo@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: LO2P265CA0087.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::27) To DB6PR05MB3272.eurprd05.prod.outlook.com (2603:10a6:6:25::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8e46a6c2-dc9b-4ec7-55c5-08d6343809a0 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DB6PR05MB3272; X-Microsoft-Exchange-Diagnostics: 1; DB6PR05MB3272; 3:rlVjW7GnDI1R/xP5AsOhg6CQ+ooxyEw3OWQlFCjtg1QxIqtFafqnq2h1wXQT8vNyR3VNGoP5q9Ro1hpN4SbifeNl68Y65GuPBANOHsSkMfPSuPuR0I1pbvbvqQ7usfJd/mQ+h2bj6VOUFTge9gph7Z8lOMFoMHWAcLIf8/gQBASMa7FbuezeTy4pKipxuDTXldnaCV2IJN7jS+DkNyS1+0fQ6YcYaJOWSADFJ3FAy86STMu/ZdFaz+NCk7pk8pWa; 25:CMBsHSB1xwiRN/B0FRYsZ0hP4v9gxwSWkfe9BXAHi3Xt9Y6s6VaR23yd+CZjmu7FT5inymcxO6ekqv3jyu1bK37wGI1JvJB7bn+63tstdcVZpmXCV0k/RneTT1MqbLdmnnoug2aaza7GX6WXHNExYwqeliwMS1XpYzJJLpCjGr39qHfmrYx4yn5H5piUoWQl4qbD/a8ERIaNg2hZZcOKuPwcNmJbMayK3fuQS570JDUdHQnkJ1WHVNcjs5h8tV8Mg8zLuM5bh2ZsBPvUaK3COtfOn9NvW3EjytWYR+ay7uqq14CiWuO2WbhbGSdNtK/X4Ha782+RLtL+cynzWSiYng==; 31:qqH/MOBnOGVNxcnxeCsRgs/081ZohKhh03ybWLBRuhnwFfx5dxYw1sdrFiIXDRh1se/Ht+xywnnhSvwlXHHVnxjlCWi4WoTSGblLC1Fcsr+6aZtG/cgDkT4faVsuDa7odahc/dmUxoTZldZKjKHJcQs70Rm+N4L0Hvm/7lQotSRWxrV+W6GQFQyewbCXGUt6NOGRDrNvKr2ddiZCd8/jPVV536MBHPyuOEUbC69G4k0= X-MS-TrafficTypeDiagnostic: DB6PR05MB3272: X-Microsoft-Exchange-Diagnostics: 1; DB6PR05MB3272; 20:sjHNUWYFTfn7l92cIajyJfNyX/gfQ2rFu4ugQ0LwD7/lgHq+WtZAY52uX7+jh9GMnF3z2i39hBMH4hjXVHRMzUwKyVXu8W56X6ZlbFPxGFAu1WpiRDlsPxrVG5ewkCnQK+pHONWXh1gQz5XnRwjAKNq1F+NDNNPVXUwV5xaPB8vyqHlfXV+i4HwRY0X0JFDLDGPify69bRtML7g7PxRr/ZM8AX6VR+wBqft0Jm/ixB7s6RXFw1f7NIs7Z/G4mL0CRtZRKN2OTOcFys2g6VLl9A+DVOaTjAp41/JV3BMNGcKjCogPa/F9vrw/ecR5le8BEOlawSe/ig1EBld1c4YcrYltj9f6hyfF9zZ3zwLnPjeces1DrWmevS0VBdbJLIRWaSH6OWPrm/TKifZ4ZyRuT6x2cJurmMEL7dxk65yZbVhL8dqZw28qM541pBKZFQHAETU4Lkw4mhaq3Akt+BLBBbFVap69xI4m67SzteKCJU0iw8zt0Tw7qDk3qnkTZU8Z; 4:hlqXJ6tSEBzplaTHIErUDbGb+1D4W35/wH07f9vach0EMr77kzVHFnaiBH3hSQbb+Cd0CWBGcWTb6BLEXmLJ7cNiRj6QEpT//KJkSPBuUCWU9ygOsMgu02Denr4iFNvOAzIIMkXbYnT/pGcOgNr/wRILnR1BnWFqrVdkJHV8L+Me+Ii9QZf3Sx6zsKN5VteiP6MXyAHl72Bg1O40MFwYhULvqVlq1+cTBEP/meF99qCGVXDI9BNlZOwL88KSem8cpWBs6VTqhSK9yQBJ1Q4LKQ== 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)(10201501046)(3231355)(944501410)(4982022)(52105095)(3002001)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(201708071742011)(7699051)(76991095); SRVR:DB6PR05MB3272; BCL:0; PCL:0; RULEID:; SRVR:DB6PR05MB3272; X-Forefront-PRVS: 08286A0BE2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(136003)(39860400002)(366004)(346002)(376002)(199004)(189003)(386003)(6636002)(4720700003)(33026002)(69596002)(4744004)(5660300001)(486006)(476003)(11346002)(2616005)(956004)(305945005)(5024004)(50466002)(446003)(16586007)(48376002)(19627235002)(8886007)(316002)(7736002)(50226002)(3846002)(6116002)(14444005)(21086003)(76176011)(7696005)(52116002)(51416003)(8936002)(25786009)(53936002)(4326008)(97736004)(107886003)(68736007)(55016002)(6306002)(2906002)(6666004)(186003)(47776003)(16526019)(85306007)(26005)(575784001)(966005)(36756003)(8676002)(81166006)(81156014)(86362001)(105586002)(478600001)(106356001)(66066001)(309714004); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR05MB3272; H:mellanox.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-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR05MB3272; 23:Npa84acjaEMOI0QyCtKs3kyFVtLDCUZxdD8N7xZne?= =?us-ascii?Q?oAoxEiZXLg66dw4JZfKvODqz3gIuULhNwMXqonnIbWsr61belZ/1tgnYangb?= =?us-ascii?Q?v1ADbsGAwEGvFzQIvolLLFiKoeWp/2DkY4n0n6NdZ9820ad0z52pl2YGse0f?= =?us-ascii?Q?LP2uL/PqEdOO0Zr3/lHUNL82XELTmyEPQncpR+7+Woy3hLXAhIYGQZcZjRsX?= =?us-ascii?Q?hAn1kdap8TlShvrKr+eVcN3kDTTNF2ARh/Ig+Oam8S/If1XVBJWBtPKJIHUZ?= =?us-ascii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e8cIUeMWY1rxxNfdS6FO+7ESOQ7yS4kyi+2DlAKgD09+Mu6C+0nBFJf8/940UbzbEQcTxuKJllW6sKIT5RFuRR2Q/+g3ROy27QPpQz2cI4YhO5iYJnFKYtKHmRJPc+4IRI4vXcRqAQeBqb21M5opwwPVdehyJ84uxIVht6bzsqFEpneyDMbhLDuRTF5UZotg==; 5:/vTJQu+GQLXUgNLZsawRWBX8QcMbCKoFyhzHijjsi4V6GX5KkzHSYoukIRxh+WKZZTSa3odtakyyrSD1Ds/muiNmsAcoTP2rbwDI1rqjYospQv8xex4riquM1XjXRpkHsd0m2SJAca5k1Q+W8v4TJ1hjR3ot8gLZktzkhwYHxiw=; 7:y9VNaT7KYQoYT2MsSNSCqQoC2FftmKJwFz+Dm8zd3Soc7ZOBhicpHIKlobEAlw2no16mi9axKJnSE79vyiYJLaxHaN8DXOost2AKkjUI+tp0HpgeCr3jySW4rRhJalo7LGIg8zQ2N3Ufwyy0BiIpMjf/pXFIYfn+m3fSG5TSQU1uihT4Bl47iMHDnt0cgrwXiQD9Bh0lyeCR5rabrSoKcRWsOaeaFmr8bECeCuEpsT36+N8myigkaKb5bvQmot8S SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2018 13:54:19.8595 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e46a6c2-dc9b-4ec7-55c5-08d6343809a0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR05MB3272 Subject: [dpdk-dev] [PATCH v2] net/mlx5: flow counters support on the Linux-rdma v19 base 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: Wed, 17 Oct 2018 13:54:22 -0000 Mellanox mlx5 PMD supports Flow Counters via Verbs library. The current implementation is based on the Mellanox proprietary Verbs library included in MLNX OFED packages. The Flow Counter support is recently added into linux-rdma release (v19), so the mlx5 PMD update is needed to provide Counter feature on the base of linux-rdma. mlx5 PMD can be compiled with MLNX OFED or linux-rdma v19+ and provide flow counters for both. Signed-off-by: Viacheslav Ovsiienko --- v2: - rebased on top of master-net-mlx branch - new compilation flags are introduced: - HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V42, kernel/verbs library provides the flow counter support in style of MLNX_OFED_4.2 to MLNX_OFED_4.4 - HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45, kernel/verbs library provides the flow counter support in style of MLNX_OFED_4.5 or higher v1: - http://patches.dpdk.org/patch/45972/ --- drivers/net/mlx5/Makefile | 7 ++- drivers/net/mlx5/meson.build | 4 +- drivers/net/mlx5/mlx5.c | 13 +++++- drivers/net/mlx5/mlx5_flow.c | 27 +++++++++--- drivers/net/mlx5/mlx5_flow.h | 5 +++ drivers/net/mlx5/mlx5_flow_verbs.c | 81 +++++++++++++++++++++++++++-------- drivers/net/mlx5/mlx5_glue.c | 88 +++++++++++++++++++++++++++++++------- drivers/net/mlx5/mlx5_glue.h | 22 +++++++++- 8 files changed, 202 insertions(+), 45 deletions(-) diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile index 1e9c0b4..fecb57c 100644 --- a/drivers/net/mlx5/Makefile +++ b/drivers/net/mlx5/Makefile @@ -157,11 +157,16 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config-h.sh enum ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT \ $(AUTOCONF_OUTPUT) $Q sh -- '$<' '$@' \ - HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT \ + HAVE_IBV_DEVICE_COUNTERS_SET_V42 \ infiniband/verbs.h \ type 'struct ibv_counter_set_init_attr' \ $(AUTOCONF_OUTPUT) $Q sh -- '$<' '$@' \ + HAVE_IBV_DEVICE_COUNTERS_SET_V45 \ + infiniband/verbs.h \ + type 'struct ibv_counters_init_attr' \ + $(AUTOCONF_OUTPUT) + $Q sh -- '$<' '$@' \ HAVE_RDMA_NL_NLDEV \ rdma/rdma_netlink.h \ enum RDMA_NL_NLDEV \ diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build index c192d44..e8cbe3e 100644 --- a/drivers/net/mlx5/meson.build +++ b/drivers/net/mlx5/meson.build @@ -79,8 +79,10 @@ if build has_member_args = [ [ 'HAVE_IBV_MLX5_MOD_SWP', 'infiniband/mlx5dv.h', 'struct mlx5dv_sw_parsing_caps', 'sw_parsing_offloads' ], - [ 'HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT', 'infiniband/verbs.h', + [ 'HAVE_IBV_DEVICE_COUNTERS_SET_V42', 'infiniband/verbs.h', 'struct ibv_counter_set_init_attr', 'counter_set_id' ], + [ 'HAVE_IBV_DEVICE_COUNTERS_SET_V45', 'infiniband/verbs.h', + 'struct ibv_counters_init_attr', 'comp_mask' ], ] # input array for meson symbol search: # [ "MACRO to define if found", "header for the search", diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 795a219..7dbe4bc 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -739,7 +739,7 @@ unsigned int mprq_max_stride_size_n = 0; unsigned int mprq_min_stride_num_n = 0; unsigned int mprq_max_stride_num_n = 0; -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42 struct ibv_counter_set_description cs_desc = { .counter_type = 0 }; #endif struct ether_addr mac; @@ -1009,13 +1009,22 @@ config.hw_csum = !!(attr.device_cap_flags_ex & IBV_DEVICE_RAW_IP_CSUM); DRV_LOG(DEBUG, "checksum offloading is %ssupported", (config.hw_csum ? "" : "not ")); -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT +#if !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) && \ + !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) + DRV_LOG(DEBUG, "no flow counters support found, OFED 4.2+ " + "is required for counters support"); +#endif +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42 config.flow_counter_en = !!attr.max_counter_sets; mlx5_glue->describe_counter_set(ctx, 0, &cs_desc); DRV_LOG(DEBUG, "counter type = %d, num of cs = %ld, attributes = %d", cs_desc.counter_type, cs_desc.num_of_cs, cs_desc.attributes); #endif +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V45 + DRV_LOG(DEBUG, "Flow counters support OFED 4.5+/upstream assumed"); + config.flow_counter_en = 1; +#endif config.ind_table_max_size = attr.rss_caps.max_rwq_indirection_table_size; /* diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index bd70fce..4df114d 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -2352,15 +2352,17 @@ struct rte_flow * * @return * 0 on success, a negative errno value otherwise and rte_errno is set. */ +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) static int -mlx5_flow_query_count(struct rte_flow *flow __rte_unused, - void *data __rte_unused, +mlx5_flow_query_count(struct rte_flow *flow, + 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}; +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42 struct ibv_query_counter_set_attr query_cs_attr = { .cs = flow->counter->cs, .query_flags = IBV_COUNTER_SET_FORCE_UPDATE, @@ -2371,7 +2373,14 @@ struct rte_flow * }; int err = mlx5_glue->query_counter_set(&query_cs_attr, &query_out); - +#endif +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V45 + int err = mlx5_glue->query_counter_set( + flow->counter->cs, + counters, + RTE_DIM(counters), + IBV_READ_COUNTERS_ATTR_PREFER_CACHED); +#endif if (err) return rte_flow_error_set (error, err, @@ -2392,12 +2401,20 @@ struct rte_flow * RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "flow does not have counter"); -#endif +} +#else +static int +mlx5_flow_query_count(struct rte_flow *flow __rte_unused, + void *data __rte_unused, + struct rte_flow_error *error) +{ return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "counters are not available"); } +#endif /* HAVE_IBV_DEVICE_COUNTERS_SET_Vxx */ + /** * Query a flows. diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 094f666..d2856c3 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -224,7 +224,12 @@ struct mlx5_flow_counter { uint32_t shared:1; /**< Share counter ID with other flow rules. */ uint32_t ref_cnt:31; /**< Reference counter. */ uint32_t id; /**< Counter ID. */ +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42 struct ibv_counter_set *cs; /**< Holds the counters for the rule. */ +#endif +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V45 + struct ibv_counters *cs; /**< Holds the counters for the rule. */ +#endif uint64_t hits; /**< Number of packets matched by the rule. */ uint64_t bytes; /**< Number of bytes matched by the rule. */ }; diff --git a/drivers/net/mlx5/mlx5_flow_verbs.c b/drivers/net/mlx5/mlx5_flow_verbs.c index 65c849c..6d5f900 100644 --- a/drivers/net/mlx5/mlx5_flow_verbs.c +++ b/drivers/net/mlx5/mlx5_flow_verbs.c @@ -46,30 +46,37 @@ * @return * A pointer to the counter, NULL otherwise and rte_errno is set. */ +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) static struct mlx5_flow_counter * flow_verbs_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id) { struct priv *priv = dev->data->dev_private; struct mlx5_flow_counter *cnt; - LIST_FOREACH(cnt, &priv->flow_counters, next) { - if (!cnt->shared || cnt->shared != shared) - continue; - if (cnt->id != id) - continue; - cnt->ref_cnt++; - return cnt; + if (shared) { + LIST_FOREACH(cnt, &priv->flow_counters, next) + if (cnt->shared && cnt->id == id) { + cnt->ref_cnt++; + return cnt; + } } -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT struct mlx5_flow_counter tmpl = { .shared = shared, .id = id, +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42 .cs = mlx5_glue->create_counter_set (priv->ctx, &(struct ibv_counter_set_init_attr){ .counter_set_id = id, }), +#endif +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V45 + .cs = mlx5_glue->create_counter_set + (priv->ctx, + &(struct ibv_counters_init_attr){0}), +#endif .hits = 0, .bytes = 0, }; @@ -78,17 +85,36 @@ rte_errno = errno; return NULL; } + +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V45 + struct ibv_counter_attach_attr attach_attr = {0}; + int ret; + + attach_attr.counter_desc = IBV_COUNTER_PACKETS; + attach_attr.index = 0; + ret = ibv_attach_counters_point_flow(tmpl.cs, &attach_attr, NULL); + if (!ret) { + attach_attr.counter_desc = IBV_COUNTER_BYTES; + attach_attr.index = 1; + ret = ibv_attach_counters_point_flow(tmpl.cs, + &attach_attr, + NULL); + } + if (ret) { + claim_zero(mlx5_glue->destroy_counter_set(tmpl.cs)); + rte_errno = ret; + return NULL; + } +#endif cnt = rte_calloc(__func__, 1, sizeof(*cnt), 0); if (!cnt) { + claim_zero(mlx5_glue->destroy_counter_set(tmpl.cs)); rte_errno = ENOMEM; return NULL; } *cnt = tmpl; LIST_INSERT_HEAD(&priv->flow_counters, cnt, next); return cnt; -#endif - rte_errno = ENOTSUP; - return NULL; } /** @@ -106,6 +132,7 @@ rte_free(counter); } } +#endif /* HAVE_IBV_DEVICE_COUNTERS_SET_Vxx */ /** * Add a verbs item specification into @p flow. @@ -927,6 +954,8 @@ * @return * 0 On success else a negative errno value is returned and rte_errno is set. */ +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) static int flow_verbs_translate_action_count(struct rte_eth_dev *dev, const struct rte_flow_action *action, @@ -936,13 +965,11 @@ { const struct rte_flow_action_count *count = action->conf; struct rte_flow *flow = dev_flow->flow; -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT unsigned int size = sizeof(struct ibv_flow_spec_counter_action); struct ibv_flow_spec_counter_action counter = { .type = IBV_FLOW_SPEC_ACTION_COUNT, .size = size, }; -#endif if (!flow->counter) { flow->counter = flow_verbs_counter_new(dev, count->shared, @@ -955,12 +982,16 @@ " context."); } *action_flags |= MLX5_FLOW_ACTION_COUNT; -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42 counter.counter_set_handle = flow->counter->cs->handle; - flow_verbs_spec_add(dev_flow, &counter, size); #endif +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V45 + counter.counters = flow->counter->cs; +#endif + flow_verbs_spec_add(dev_flow, &counter, size); return 0; } +#endif /* HAVE_IBV_DEVICE_COUNTERS_SET_Vxx */ /** * Internal validation function. For validating both actions and items. @@ -1157,12 +1188,15 @@ return ret; action_flags |= MLX5_FLOW_ACTION_RSS; break; +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) case RTE_FLOW_ACTION_TYPE_COUNT: ret = mlx5_flow_validate_action_count(dev, attr, error); if (ret < 0) return ret; action_flags |= MLX5_FLOW_ACTION_COUNT; break; +#endif default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, @@ -1219,11 +1253,12 @@ case RTE_FLOW_ACTION_TYPE_RSS: detected_actions |= MLX5_FLOW_ACTION_RSS; break; +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) case RTE_FLOW_ACTION_TYPE_COUNT: -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT size += sizeof(struct ibv_flow_spec_counter_action); -#endif detected_actions |= MLX5_FLOW_ACTION_COUNT; +#endif break; default: break; @@ -1406,7 +1441,6 @@ if (priority == MLX5_FLOW_PRIO_RSVD) priority = priv->config.flow_prio - 1; for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) { - int ret; switch (actions->type) { case RTE_FLOW_ACTION_TYPE_VOID: break; @@ -1434,7 +1468,11 @@ &action_flags, dev_flow); break; - case RTE_FLOW_ACTION_TYPE_COUNT: +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) + case RTE_FLOW_ACTION_TYPE_COUNT: { + int ret; + ret = flow_verbs_translate_action_count(dev, actions, &action_flags, @@ -1443,6 +1481,8 @@ if (ret < 0) return ret; break; + } +#endif default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, @@ -1538,10 +1578,13 @@ verbs->hrxq = NULL; } } +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) if (flow->counter) { flow_verbs_counter_release(flow->counter); flow->counter = NULL; } +#endif } /** diff --git a/drivers/net/mlx5/mlx5_glue.c b/drivers/net/mlx5/mlx5_glue.c index 48590df..d77adb8 100644 --- a/drivers/net/mlx5/mlx5_glue.c +++ b/drivers/net/mlx5/mlx5_glue.c @@ -211,28 +211,84 @@ return ibv_dereg_mr(mr); } +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V45 +static struct ibv_counters * +mlx5_glue_create_counters(struct ibv_context *context, + struct ibv_counters_init_attr *init_attr) +{ + return ibv_create_counters(context, init_attr); +} + +static int +mlx5_glue_destroy_counters(struct ibv_counters *counters) +{ + return ibv_destroy_counters(counters); +} + +static int +mlx5_glue_attach_counters(struct ibv_counters *counters, + struct ibv_counter_attach_attr *attr, + struct ibv_flow *flow) +{ + return ibv_attach_counters_point_flow(counters, attr, flow); +} + +static int +mlx5_glue_query_counters(struct ibv_counters *counters, + uint64_t *counters_value, + uint32_t ncounters, + uint32_t flags) +{ + return ibv_read_counters(counters, counters_value, ncounters, flags); +} +#endif /* HAVE_IBV_DEVICE_COUNTERS_SET_V45 */ + +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42 +static struct ibv_counter_set * +mlx5_glue_create_counter_set(struct ibv_context *context, + struct ibv_counter_set_init_attr *init_attr) +{ + return ibv_create_counter_set(context, init_attr); +} + +static int +mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs) +{ + return ibv_destroy_counter_set(cs); +} + +static int +mlx5_glue_describe_counter_set(struct ibv_context *context, + uint16_t counter_set_id, + struct ibv_counter_set_description *cs_desc) +{ + return ibv_describe_counter_set(context, counter_set_id, cs_desc); +} + +static int +mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr, + struct ibv_counter_set_data *cs_data) +{ + return ibv_query_counter_set(query_attr, cs_data); +} +#endif /* HAVE_IBV_DEVICE_COUNTERS_SET_V42 */ + +#if !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) && \ + !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) static struct ibv_counter_set * mlx5_glue_create_counter_set(struct ibv_context *context, struct ibv_counter_set_init_attr *init_attr) { -#ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT (void)context; (void)init_attr; return NULL; -#else - return ibv_create_counter_set(context, init_attr); -#endif } static int mlx5_glue_destroy_counter_set(struct ibv_counter_set *cs) { -#ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT (void)cs; return ENOTSUP; -#else - return ibv_destroy_counter_set(cs); -#endif } static int @@ -240,28 +296,21 @@ uint16_t counter_set_id, struct ibv_counter_set_description *cs_desc) { -#ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT (void)context; (void)counter_set_id; (void)cs_desc; return ENOTSUP; -#else - return ibv_describe_counter_set(context, counter_set_id, cs_desc); -#endif } static int mlx5_glue_query_counter_set(struct ibv_query_counter_set_attr *query_attr, struct ibv_counter_set_data *cs_data) { -#ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT (void)query_attr; (void)cs_data; return ENOTSUP; -#else - return ibv_query_counter_set(query_attr, cs_data); -#endif } +#endif /* HAVE_IBV_DEVICE_COUNTERS_SET_Vxx */ static void mlx5_glue_ack_async_event(struct ibv_async_event *event) @@ -420,10 +469,17 @@ .modify_qp = mlx5_glue_modify_qp, .reg_mr = mlx5_glue_reg_mr, .dereg_mr = mlx5_glue_dereg_mr, +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V45 + .create_counter_set = mlx5_glue_create_counters, + .destroy_counter_set = mlx5_glue_destroy_counters, + .attach_counter_set = mlx5_glue_attach_counters, + .query_counter_set = mlx5_glue_query_counters, +#else .create_counter_set = mlx5_glue_create_counter_set, .destroy_counter_set = mlx5_glue_destroy_counter_set, .describe_counter_set = mlx5_glue_describe_counter_set, .query_counter_set = mlx5_glue_query_counter_set, +#endif .ack_async_event = mlx5_glue_ack_async_event, .get_async_event = mlx5_glue_get_async_event, .port_state_str = mlx5_glue_port_state_str, diff --git a/drivers/net/mlx5/mlx5_glue.h b/drivers/net/mlx5/mlx5_glue.h index f6e4e38..b9033de 100644 --- a/drivers/net/mlx5/mlx5_glue.h +++ b/drivers/net/mlx5/mlx5_glue.h @@ -23,7 +23,11 @@ #define MLX5_GLUE_VERSION "" #endif -#ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V45 +struct ibv_counters; +struct ibv_counters_attach_data; +struct ibv_counters_init_attr; +#else struct ibv_counter_set; struct ibv_counter_set_data; struct ibv_counter_set_description; @@ -96,6 +100,21 @@ struct mlx5_glue { struct ibv_mr *(*reg_mr)(struct ibv_pd *pd, void *addr, size_t length, int access); int (*dereg_mr)(struct ibv_mr *mr); +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V45 + struct ibv_counters *(*create_counter_set) + (struct ibv_context *context, + struct ibv_counters_init_attr *init_attr); + int (*destroy_counter_set)(struct ibv_counters *cs); + int (*attach_counter_set) + (struct ibv_counters *cs, + struct ibv_counter_attach_attr *attr, + struct ibv_flow *flow); + int (*query_counter_set) + (struct ibv_counters *cs, + uint64_t *counters_value, + uint32_t ncounters, + uint32_t flags); +#else struct ibv_counter_set *(*create_counter_set) (struct ibv_context *context, struct ibv_counter_set_init_attr *init_attr); @@ -106,6 +125,7 @@ struct mlx5_glue { struct ibv_counter_set_description *cs_desc); int (*query_counter_set)(struct ibv_query_counter_set_attr *query_attr, struct ibv_counter_set_data *cs_data); +#endif void (*ack_async_event)(struct ibv_async_event *event); int (*get_async_event)(struct ibv_context *context, struct ibv_async_event *event); -- 1.8.3.1