diff --git a/configure.ac b/configure.ac index 76cf33e..82f3ad8 100644 --- a/configure.ac +++ b/configure.ac @@ -315,6 +315,11 @@ AC_ARG_ENABLE(qat_hw_kpt, [Enable QAT HW Key Protection technology(KPT) support])) AC_SUBST(enable_qat_hw_kpt) +AC_ARG_WITH(fstack_dir, + AS_HELP_STRING([--with-fstack_dir], + [Path to where the F-stack libraries are installed to.])) +AC_SUBST(with_fstack_dir) + #Default library name is qatengine AC_SUBST([LIBQATNAME], "qatengine") @@ -650,6 +655,10 @@ then fi #Enable additional QAT_HW & QAT_SW flags + +AS_IF([test "x$with_fstack_dir" != "x"], + [cflags_common="${cflags_common} -DFSTACK -I\$(with_fstack_dir)/lib"; AC_MSG_NOTICE([FSTACK enabled])]) + AS_IF([test "x$enable_qat_debug" = "xyes"], [cflags_common="${cflags_common} -DQAT_DEBUG"; AC_MSG_NOTICE([Debug messages enabled])]) diff --git a/qat_events.c b/qat_events.c index 717db0a..8183a55 100644 --- a/qat_events.c +++ b/qat_events.c @@ -57,7 +57,9 @@ #include #include #include -#ifndef __FreeBSD__ +#if defined(FSTACK) +# include +#elif defined(__FreeBSD__) # include # include #else @@ -99,10 +101,17 @@ static void qat_fd_cleanup(ASYNC_WAIT_CTX *ctx, const void *key, return; } #endif +#ifndef FSTACK if (close(readfd) != 0) { WARN("Failed to close readfd: %d - error: %d\n", readfd, errno); QATerr(QAT_F_QAT_FD_CLEANUP, QAT_R_CLOSE_READFD_FAILURE); } +#else + if (ff_close(readfd) != 0) { + WARN("Failed to close readfd: %d - error: %d\n", readfd, errno); + QATerr(QAT_F_QAT_FD_CLEANUP, QAT_R_CLOSE_READFD_FAILURE); + } +#endif } int qat_setup_async_event_notification(volatile ASYNC_JOB *job) @@ -115,7 +124,7 @@ int qat_setup_async_event_notification(volatile ASYNC_JOB *job) OSSL_ASYNC_FD efd; void *custom = NULL; -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(FSTACK) struct kevent event; #endif @@ -146,7 +155,20 @@ int qat_setup_async_event_notification(volatile ASYNC_JOB *job) close(efd); return 0; } - +#elif defined(FSTACK) + efd = ff_kqueue(); + if (efd == -1) { + WARN("Failed to get kqueue fd = %d\n", errno); + return 0; + } + /* Initialize the event */ + EV_SET(&event, QAT_EVENT_NUM, EVFILT_USER, EV_ADD | EV_CLEAR, NOTE_WRITE, + 0, NULL); + if (ff_kevent(efd, &event, QAT_EVENT_NUM, NULL, 0, NULL) == -1) { + WARN("Failed to register event for the fd = %d\n", efd); + ff_close(efd); + return 0; + } #else efd = eventfd(0, EFD_NONBLOCK); if (efd == -1) { @@ -231,7 +253,7 @@ int qat_pause_job(volatile ASYNC_JOB *job, int jobStatus) #endif OSSL_ASYNC_FD readfd; void *custom = NULL; -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(FSTACK) struct kevent event; #else uint64_t buf = 0; @@ -261,20 +283,26 @@ int qat_pause_job(volatile ASYNC_JOB *job, int jobStatus) #endif if ((ret = ASYNC_WAIT_CTX_get_fd(waitctx, engine_qat_id, &readfd, &custom)) > 0) { -#ifndef __FreeBSD__ - if (read(readfd, &buf, sizeof(uint64_t)) == -1) { - if (errno != EAGAIN) { - WARN("Failed to read from fd: %d - error: %d\n", readfd, errno); - } +#if defined(FSTACK) + if (ff_kevent(readfd, NULL, 0, &event, QAT_EVENT_NUM, NULL) == -1) { + WARN("Failed to get event from fd: %d - error: %d\n", readfd, errno); /* Not resumed by the expected qat_wake_job() */ return QAT_JOB_RESUMED_UNEXPECTEDLY; } -#else +#elif defined(__FreeBSD__) if (kevent(readfd, NULL, 0, &event, QAT_EVENT_NUM, NULL) == -1) { WARN("Failed to get event from fd: %d - error: %d\n", readfd, errno); /* Not resumed by the expected qat_wake_job() */ return QAT_JOB_RESUMED_UNEXPECTEDLY; } +#else + if (read(readfd, &buf, sizeof(uint64_t)) == -1) { + if (errno != EAGAIN) { + WARN("Failed to read from fd: %d - error: %d\n", readfd, errno); + } + /* Not resumed by the expected qat_wake_job() */ + return QAT_JOB_RESUMED_UNEXPECTEDLY; + } #endif } return ret; @@ -290,7 +318,7 @@ int qat_wake_job(volatile ASYNC_JOB *job, int jobStatus) #endif OSSL_ASYNC_FD efd; void *custom = NULL; -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(FSTACK) struct kevent event; #else /* Arbitrary value '1' to write down the pipe to trigger event */ @@ -319,15 +347,20 @@ int qat_wake_job(volatile ASYNC_JOB *job, int jobStatus) if ((ret = ASYNC_WAIT_CTX_get_fd(waitctx, engine_qat_id, &efd, &custom)) > 0) { -#ifndef __FreeBSD__ - if (write(efd, &buf, sizeof(uint64_t)) == -1) { - WARN("Failed to write to fd: %d - error: %d\n", efd, errno); +#if defined(FSTACK) + EV_SET(&event, QAT_EVENT_NUM, EVFILT_USER, EV_ADD, NOTE_TRIGGER, 0, NULL); + if (ff_kevent(efd, &event, QAT_EVENT_NUM, NULL, 0, NULL) == -1) { + WARN("Failed to trigger event to fd: %d - error: %d\n", efd, errno); } -#else +#elif defined(__FreeBSD__) EV_SET(&event, QAT_EVENT_NUM, EVFILT_USER, EV_ADD, NOTE_TRIGGER, 0, NULL); if (kevent(efd, &event, QAT_EVENT_NUM, NULL, 0, NULL) == -1) { WARN("Failed to trigger event to fd: %d - error: %d\n", efd, errno); } +#else + if (write(efd, &buf, sizeof(uint64_t)) == -1) { + WARN("Failed to write to fd: %d - error: %d\n", efd, errno); + } #endif } return ret; diff --git a/qat_events.h b/qat_events.h index fd4c1fc..e1e9f38 100644 --- a/qat_events.h +++ b/qat_events.h @@ -73,7 +73,7 @@ # define ASYNC_STATUS_EAGAIN 3 #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(FSTACK) # define QAT_EVENT_NUM 1 #endif