diff mbox series

[v3,2/3] libsbefifo: Add long read timeout API

Message ID 20220303014616.757411-3-joel@jms.id.au
State New
Headers show
Series sbefifo long running chip-op ioctl support | expand

Commit Message

Joel Stanley March 3, 2022, 1:46 a.m. UTC
From: Amitay Isaacs <amitay@ozlabs.org>

Add a function to set the long read timeout on a sbefifo context, and to
reset it afterwards.

This will be used by chip-ops that require a long timeout.

Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 libsbefifo/sbefifo_private.h |  2 ++
 libsbefifo/connect.c         | 41 ++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
diff mbox series

Patch

diff --git a/libsbefifo/sbefifo_private.h b/libsbefifo/sbefifo_private.h
index 3c5ebcefb288..373f7f3c90ed 100644
--- a/libsbefifo/sbefifo_private.h
+++ b/libsbefifo/sbefifo_private.h
@@ -83,6 +83,8 @@  struct sbefifo_context {
 	uint32_t ffdc_len;
 };
 
+int sbefifo_set_long_timeout(struct sbefifo_context *sctx);
+int sbefifo_reset_timeout(struct sbefifo_context *sctx);
 void sbefifo_debug(const char *fmt, ...);
 
 void sbefifo_ffdc_clear(struct sbefifo_context *sctx);
diff --git a/libsbefifo/connect.c b/libsbefifo/connect.c
index 1d23af5ec896..27e8976cb2dc 100644
--- a/libsbefifo/connect.c
+++ b/libsbefifo/connect.c
@@ -21,6 +21,17 @@ 
 #include <errno.h>
 #include <stdarg.h>
 #include <stdbool.h>
+#include <sys/ioctl.h>
+
+#ifdef HAVE_LINUX_FSI_H
+#include <linux/fsi.h>
+#else
+#include <linux/ioctl.h>
+#endif /* HAVE_LINUX_FSI_H */
+
+#ifndef FSI_SBEFIFO_READ_TIMEOUT
+#define FSI_SBEFIFO_READ_TIMEOUT        _IOW('s', 0x00, unsigned int)
+#endif
 
 #include "libsbefifo.h"
 #include "sbefifo_private.h"
@@ -106,6 +117,36 @@  int sbefifo_proc(struct sbefifo_context *sctx)
 	return sctx->proc;
 }
 
+int sbefifo_set_long_timeout(struct sbefifo_context *sctx)
+{
+	unsigned int long_timeout = 30;
+	int rc;
+
+	LOG("long_timeout: %u sec\n", long_timeout);
+	rc = ioctl(sctx->fd, FSI_SBEFIFO_READ_TIMEOUT, &long_timeout);
+	if (rc == -1 && errno == ENOTTY) {
+		/* Do not fail if kernel does not implement ioctl */
+		rc = 0;
+	}
+
+	return rc;
+}
+
+int sbefifo_reset_timeout(struct sbefifo_context *sctx)
+{
+	unsigned int timeout = 0;
+	int rc;
+
+	LOG("reset_timeout\n");
+	rc = ioctl(sctx->fd, FSI_SBEFIFO_READ_TIMEOUT, &timeout);
+	if (rc == -1 && errno == ENOTTY) {
+		/* Do not fail if kernel does not implement ioctl */
+		rc = 0;
+	}
+
+	return rc;
+}
+
 void sbefifo_debug(const char *fmt, ...)
 {
 	va_list ap;