DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tomasz Duszynski <tduszynski@marvell.com>
To: <dev@dpdk.org>, Jakub Palider <jpalider@marvell.com>,
	Tomasz Duszynski <tduszynski@marvell.com>
Cc: <thomas@monjalon.net>, <jerinj@marvell.com>
Subject: [PATCH] raw/cnxk_gpio: allow controlling existing GPIO
Date: Sat, 4 Jun 2022 16:03:23 +0200	[thread overview]
Message-ID: <20220604140323.3380810-1-tduszynski@marvell.com> (raw)

Controlling existing GPIO should be normally frowned upon because
we want to avoid situation where multiple contenders modify GPIO
state simultaneously.

Still there might be situations where this is actually needed.
Restarting killed application being an example here.

So relax current restrictions and respect user needs.

Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
---
 drivers/raw/cnxk_gpio/cnxk_gpio.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c
index 9577753851..d759ed82d4 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
@@ -4,6 +4,7 @@
 
 #include <dirent.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #include <rte_bus_vdev.h>
 #include <rte_eal.h>
@@ -277,6 +278,17 @@ cnxk_gpio_lookup(struct cnxk_gpiochip *gpiochip, uint16_t queue)
 	return gpiochip->gpios[gpio];
 }
 
+static bool
+cnxk_gpio_exists(int num)
+{
+	char buf[CNXK_GPIO_BUFSZ];
+	struct stat st;
+
+	snprintf(buf, sizeof(buf), "%s/gpio%d", CNXK_GPIO_CLASS_PATH, num);
+
+	return !stat(buf, &st);
+}
+
 static int
 cnxk_gpio_queue_setup(struct rte_rawdev *dev, uint16_t queue_id,
 		      rte_rawdev_obj_t queue_conf, size_t queue_conf_size)
@@ -304,11 +316,15 @@ cnxk_gpio_queue_setup(struct rte_rawdev *dev, uint16_t queue_id,
 	gpio->num = num + gpiochip->base;
 	gpio->gpiochip = gpiochip;
 
-	snprintf(buf, sizeof(buf), "%s/export", CNXK_GPIO_CLASS_PATH);
-	ret = cnxk_gpio_write_attr_int(buf, gpio->num);
-	if (ret) {
-		rte_free(gpio);
-		return ret;
+	if (!cnxk_gpio_exists(gpio->num)) {
+		snprintf(buf, sizeof(buf), "%s/export", CNXK_GPIO_CLASS_PATH);
+		ret = cnxk_gpio_write_attr_int(buf, gpio->num);
+		if (ret) {
+			rte_free(gpio);
+			return ret;
+		}
+	} else {
+		RTE_LOG(WARNING, PMD, "using existing gpio%d\n", gpio->num);
 	}
 
 	gpiochip->gpios[num] = gpio;
-- 
2.25.1


             reply	other threads:[~2022-06-04 14:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-04 14:03 Tomasz Duszynski [this message]
2022-06-08  9:03 ` Thomas Monjalon

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=20220604140323.3380810-1-tduszynski@marvell.com \
    --to=tduszynski@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=jpalider@marvell.com \
    --cc=thomas@monjalon.net \
    /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).