DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH 04/11] net/sfc: provide a way to check if filter is supported
Date: Thu, 2 Mar 2017 16:03:04 +0000	[thread overview]
Message-ID: <1488470591-5853-5-git-send-email-arybchenko@solarflare.com> (raw)
In-Reply-To: <1488470591-5853-1-git-send-email-arybchenko@solarflare.com>

The information is obtained from firmware on attach. It may
change after MC reboot (firmware version or variant change).
Cache should be refreshed after MC reboot when it is handled
properly (not yet).

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andrew Lee <alee@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@solarflare.com>
Reviewed-by: Robert Stonehouse <rstonehouse@solarflare.com>
---
 drivers/net/sfc/Makefile     |   1 +
 drivers/net/sfc/sfc.c        |   7 +++
 drivers/net/sfc/sfc.h        |   3 +
 drivers/net/sfc/sfc_filter.c | 135 +++++++++++++++++++++++++++++++++++++++++++
 drivers/net/sfc/sfc_filter.h |  56 ++++++++++++++++++
 5 files changed, 202 insertions(+)
 create mode 100644 drivers/net/sfc/sfc_filter.c
 create mode 100644 drivers/net/sfc/sfc_filter.h

diff --git a/drivers/net/sfc/Makefile b/drivers/net/sfc/Makefile
index 619a0ed..2b7ede8 100644
--- a/drivers/net/sfc/Makefile
+++ b/drivers/net/sfc/Makefile
@@ -90,6 +90,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_SFC_EFX_PMD) += sfc_port.c
 SRCS-$(CONFIG_RTE_LIBRTE_SFC_EFX_PMD) += sfc_rx.c
 SRCS-$(CONFIG_RTE_LIBRTE_SFC_EFX_PMD) += sfc_tx.c
 SRCS-$(CONFIG_RTE_LIBRTE_SFC_EFX_PMD) += sfc_tso.c
+SRCS-$(CONFIG_RTE_LIBRTE_SFC_EFX_PMD) += sfc_filter.c
 
 VPATH += $(SRCDIR)/base
 
diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c
index 03ecec2..6fd8bf1 100644
--- a/drivers/net/sfc/sfc.c
+++ b/drivers/net/sfc/sfc.c
@@ -633,6 +633,10 @@ sfc_attach(struct sfc_adapter *sa)
 	if (rc != 0)
 		goto fail_set_rss_defaults;
 
+	rc = sfc_filter_attach(sa);
+	if (rc != 0)
+		goto fail_filter_attach;
+
 	sfc_log_init(sa, "fini nic");
 	efx_nic_fini(enp);
 
@@ -641,6 +645,7 @@ sfc_attach(struct sfc_adapter *sa)
 	sfc_log_init(sa, "done");
 	return 0;
 
+fail_filter_attach:
 fail_set_rss_defaults:
 	sfc_intr_detach(sa);
 
@@ -678,6 +683,8 @@ sfc_detach(struct sfc_adapter *sa)
 
 	SFC_ASSERT(sfc_adapter_is_locked(sa));
 
+	sfc_filter_detach(sa);
+
 	sfc_intr_detach(sa);
 
 	sfc_log_init(sa, "unprobe nic");
diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h
index 8c6c02f..2b105aa 100644
--- a/drivers/net/sfc/sfc.h
+++ b/drivers/net/sfc/sfc.h
@@ -38,6 +38,8 @@
 
 #include "efx.h"
 
+#include "sfc_filter.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -179,6 +181,7 @@ struct sfc_adapter {
 	struct sfc_mcdi			mcdi;
 	struct sfc_intr			intr;
 	struct sfc_port			port;
+	struct sfc_filter		filter;
 
 	unsigned int			rxq_max;
 	unsigned int			txq_max;
diff --git a/drivers/net/sfc/sfc_filter.c b/drivers/net/sfc/sfc_filter.c
new file mode 100644
index 0000000..98435e9
--- /dev/null
+++ b/drivers/net/sfc/sfc_filter.c
@@ -0,0 +1,135 @@
+/*-
+ * Copyright (c) 2017 Solarflare Communications Inc.
+ * All rights reserved.
+ *
+ * This software was jointly developed between OKTET Labs (under contract
+ * for Solarflare) and Solarflare Communications, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_common.h>
+
+#include "efx.h"
+
+#include "sfc.h"
+#include "sfc_log.h"
+
+boolean_t
+sfc_filter_is_match_supported(struct sfc_adapter *sa, uint32_t match)
+{
+	struct sfc_filter *filter = &sa->filter;
+	size_t i;
+
+	for (i = 0; i < filter->supported_match_num; ++i) {
+		if (match == filter->supported_match[i])
+			return B_TRUE;
+	}
+
+	return B_FALSE;
+}
+
+static int
+sfc_filter_cache_match_supported(struct sfc_adapter *sa)
+{
+	struct sfc_filter *filter = &sa->filter;
+	size_t num = filter->supported_match_num;
+	uint32_t *buf = filter->supported_match;
+	unsigned int retry;
+	int rc;
+
+	/* Just a guess of possibly sufficient entries */
+	if (num == 0)
+		num = 16;
+
+	for (retry = 0; retry < 2; ++retry) {
+		if (num != filter->supported_match_num) {
+			rc = ENOMEM;
+			buf = rte_realloc(buf, num * sizeof(*buf), 0);
+			if (buf == NULL)
+				goto fail_realloc;
+		}
+
+		rc = efx_filter_supported_filters(sa->nic, buf, num, &num);
+		if (rc == 0) {
+			filter->supported_match_num = num;
+			filter->supported_match = buf;
+
+			return 0;
+		} else if (rc != ENOSPC) {
+			goto fail_efx_filter_supported_filters;
+		}
+	}
+
+	SFC_ASSERT(rc == ENOSPC);
+
+fail_efx_filter_supported_filters:
+fail_realloc:
+	/* Original pointer is not freed by rte_realloc() on failure */
+	rte_free(buf);
+	filter->supported_match = NULL;
+	filter->supported_match_num = 0;
+	return rc;
+}
+
+int
+sfc_filter_attach(struct sfc_adapter *sa)
+{
+	int rc;
+
+	sfc_log_init(sa, "entry");
+
+	rc = efx_filter_init(sa->nic);
+	if (rc != 0)
+		goto fail_filter_init;
+
+	rc = sfc_filter_cache_match_supported(sa);
+	if (rc != 0)
+		goto fail_cache_match_supported;
+
+	efx_filter_fini(sa->nic);
+
+	sfc_log_init(sa, "done");
+
+	return 0;
+
+fail_cache_match_supported:
+	efx_filter_fini(sa->nic);
+
+fail_filter_init:
+	sfc_log_init(sa, "failed %d", rc);
+	return rc;
+}
+
+void
+sfc_filter_detach(struct sfc_adapter *sa)
+{
+	struct sfc_filter *filter = &sa->filter;
+
+	sfc_log_init(sa, "entry");
+
+	rte_free(filter->supported_match);
+	filter->supported_match = NULL;
+	filter->supported_match_num = 0;
+
+	sfc_log_init(sa, "done");
+}
diff --git a/drivers/net/sfc/sfc_filter.h b/drivers/net/sfc/sfc_filter.h
new file mode 100644
index 0000000..5ba1617
--- /dev/null
+++ b/drivers/net/sfc/sfc_filter.h
@@ -0,0 +1,56 @@
+/*-
+ * Copyright (c) 2017 Solarflare Communications Inc.
+ * All rights reserved.
+ *
+ * This software was jointly developed between OKTET Labs (under contract
+ * for Solarflare) and Solarflare Communications, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SFC_FILTER_H
+#define _SFC_FILTER_H
+
+#include "efx.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct sfc_filter {
+	/** Number of elements in match_supported array */
+	size_t				supported_match_num;
+	/** Driver cache of supported filter match masks */
+	uint32_t			*supported_match;
+};
+
+struct sfc_adapter;
+
+int sfc_filter_attach(struct sfc_adapter *sa);
+void sfc_filter_detach(struct sfc_adapter *sa);
+
+boolean_t sfc_filter_is_match_supported(struct sfc_adapter *sa, uint32_t match);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _SFC_FILTER_H */
-- 
2.9.3

  parent reply	other threads:[~2017-03-02 16:03 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-02 16:03 [dpdk-dev] [PATCH 00/11] Support flow API in Solarflare PMD Andrew Rybchenko
2017-03-02 16:03 ` [dpdk-dev] [PATCH 01/11] net/sfc/base: split local MAC I/G back into separate flags Andrew Rybchenko
2017-03-02 16:03 ` [dpdk-dev] [PATCH 02/11] net/sfc/base: improve API to get supported filter matches Andrew Rybchenko
2017-03-07 13:25   ` Ferruh Yigit
2017-03-07 14:47     ` Andrew Rybchenko
2017-03-07 14:56       ` Ferruh Yigit
2017-03-02 16:03 ` [dpdk-dev] [PATCH 03/11] net/sfc: implement dummy filter control callback Andrew Rybchenko
2017-03-02 16:03 ` Andrew Rybchenko [this message]
2017-03-02 16:03 ` [dpdk-dev] [PATCH 05/11] net/sfc: add flow API filters support Andrew Rybchenko
2017-03-07 13:21   ` Ferruh Yigit
2017-03-09 15:29     ` Andrew Rybchenko
2017-03-02 16:03 ` [dpdk-dev] [PATCH 06/11] net/sfc: add VLAN in " Andrew Rybchenko
2017-03-02 16:03 ` [dpdk-dev] [PATCH 07/11] net/sfc: add IPV4 " Andrew Rybchenko
2017-03-07 13:21   ` Ferruh Yigit
2017-03-02 16:03 ` [dpdk-dev] [PATCH 08/11] net/sfc: add IPV6 " Andrew Rybchenko
2017-03-02 16:03 ` [dpdk-dev] [PATCH 09/11] net/sfc: add TCP " Andrew Rybchenko
2017-03-02 16:03 ` [dpdk-dev] [PATCH 10/11] net/sfc: add UDP " Andrew Rybchenko
2017-03-02 16:03 ` [dpdk-dev] [PATCH 11/11] net/sfc: add unknown unicast/multicast match in flow API Andrew Rybchenko
2017-03-07 13:27 ` [dpdk-dev] [PATCH 00/11] Support flow API in Solarflare PMD Ferruh Yigit
2017-03-07 14:56   ` Andrew Rybchenko
2017-03-09 15:26 ` [dpdk-dev] [PATCH v2 " Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 01/11] net/sfc/base: split local MAC I/G back into separate flags Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 02/11] net/sfc/base: improve API to get supported filter matches Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 03/11] net/sfc: implement dummy filter control callback Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 04/11] net/sfc: provide a way to check if filter is supported Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 05/11] net/sfc: add flow API filters support Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 06/11] net/sfc: add VLAN in " Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 07/11] net/sfc: add IPV4 " Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 08/11] net/sfc: add IPV6 " Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 09/11] net/sfc: add TCP " Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 10/11] net/sfc: add UDP " Andrew Rybchenko
2017-03-09 15:26   ` [dpdk-dev] [PATCH v2 11/11] net/sfc: add unknown unicast/multicast match in flow API Andrew Rybchenko
2017-03-09 17:28   ` [dpdk-dev] [PATCH v2 00/11] Support flow API in Solarflare PMD Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1488470591-5853-5-git-send-email-arybchenko@solarflare.com \
    --to=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).