summaryrefslogtreecommitdiffstats
path: root/sys/compat/linuxkpi/common/include/linux
diff options
context:
space:
mode:
Diffstat (limited to 'sys/compat/linuxkpi/common/include/linux')
-rw-r--r--sys/compat/linuxkpi/common/include/linux/compiler.h16
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kobject.h24
-rw-r--r--sys/compat/linuxkpi/common/include/linux/srcu.h72
-rw-r--r--sys/compat/linuxkpi/common/include/linux/workqueue.h117
4 files changed, 139 insertions, 90 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/compiler.h b/sys/compat/linuxkpi/common/include/linux/compiler.h
index 6381358..b6ea98f 100644
--- a/sys/compat/linuxkpi/common/include/linux/compiler.h
+++ b/sys/compat/linuxkpi/common/include/linux/compiler.h
@@ -72,4 +72,20 @@
#define barrier() __asm__ __volatile__("": : :"memory")
+#define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x))
+
+#define WRITE_ONCE(x,v) do { \
+ barrier(); \
+ ACCESS_ONCE(x) = (v); \
+ barrier(); \
+} while (0)
+
+#define READ_ONCE(x) ({ \
+ __typeof(x) __var; \
+ barrier(); \
+ __var = ACCESS_ONCE(x); \
+ barrier(); \
+ __var; \
+})
+
#endif /* _LINUX_COMPILER_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kobject.h b/sys/compat/linuxkpi/common/include/linux/kobject.h
index 0e94809..475095e 100644
--- a/sys/compat/linuxkpi/common/include/linux/kobject.h
+++ b/sys/compat/linuxkpi/common/include/linux/kobject.h
@@ -103,29 +103,7 @@ kobject_get(struct kobject *kobj)
return kobj;
}
-static inline int
-kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list args)
-{
- char *old;
- char *name;
-
- old = kobj->name;
-
- if (old && !fmt)
- return 0;
-
- name = kzalloc(MAXPATHLEN, GFP_KERNEL);
- if (!name)
- return -ENOMEM;
- vsnprintf(name, MAXPATHLEN, fmt, args);
- kobj->name = name;
- kfree(old);
- for (; *name != '\0'; name++)
- if (*name == '/')
- *name = '!';
- return (0);
-}
-
+int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list);
int kobject_add(struct kobject *kobj, struct kobject *parent,
const char *fmt, ...);
diff --git a/sys/compat/linuxkpi/common/include/linux/srcu.h b/sys/compat/linuxkpi/common/include/linux/srcu.h
new file mode 100644
index 0000000..c20215b
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/srcu.h
@@ -0,0 +1,72 @@
+/*-
+ * Copyright (c) 2015 Mellanox Technologies, Ltd.
+ * All rights reserved.
+ *
+ * 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 unmodified, 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 AUTHOR ``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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+#ifndef _LINUX_SRCU_H_
+#define _LINUX_SRCU_H_
+
+#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/sx.h>
+
+struct srcu_struct {
+ struct sx sx;
+};
+
+static inline int
+init_srcu_struct(struct srcu_struct *srcu)
+{
+ sx_init(&srcu->sx, "SleepableRCU");
+ return (0);
+}
+
+static inline void
+cleanup_srcu_struct(struct srcu_struct *srcu)
+{
+ sx_destroy(&srcu->sx);
+}
+
+static inline int
+srcu_read_lock(struct srcu_struct *srcu)
+{
+ sx_slock(&srcu->sx);
+ return (0);
+}
+
+static inline void
+srcu_read_unlock(struct srcu_struct *srcu, int key)
+{
+ sx_sunlock(&srcu->sx);
+}
+
+static inline void
+synchronize_srcu(struct srcu_struct *srcu)
+{
+ sx_xlock(&srcu->sx);
+ sx_xunlock(&srcu->sx);
+}
+
+#endif /* _LINUX_SRCU_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/workqueue.h b/sys/compat/linuxkpi/common/include/linux/workqueue.h
index 58ef463..7eb2301 100644
--- a/sys/compat/linuxkpi/common/include/linux/workqueue.h
+++ b/sys/compat/linuxkpi/common/include/linux/workqueue.h
@@ -36,10 +36,13 @@
#include <linux/timer.h>
#include <linux/slab.h>
+#include <asm/atomic.h>
+
#include <sys/taskqueue.h>
struct workqueue_struct {
struct taskqueue *taskqueue;
+ atomic_t draining;
};
struct work_struct {
@@ -55,6 +58,12 @@ struct delayed_work {
struct callout timer;
};
+extern void linux_work_fn(void *, int);
+extern void linux_flush_fn(void *, int);
+extern void linux_delayed_work_fn(void *);
+extern struct workqueue_struct *linux_create_workqueue_common(const char *, int);
+extern void destroy_workqueue(struct workqueue_struct *);
+
static inline struct delayed_work *
to_delayed_work(struct work_struct *work)
{
@@ -62,21 +71,11 @@ to_delayed_work(struct work_struct *work)
return container_of(work, struct delayed_work, work);
}
-
-static inline void
-_work_fn(void *context, int pending)
-{
- struct work_struct *work;
-
- work = context;
- work->fn(work);
-}
-
#define INIT_WORK(work, func) \
do { \
(work)->fn = (func); \
(work)->taskqueue = NULL; \
- TASK_INIT(&(work)->work_task, 0, _work_fn, (work)); \
+ TASK_INIT(&(work)->work_task, 0, linux_work_fn, (work)); \
} while (0)
#define INIT_DELAYED_WORK(_work, func) \
@@ -85,7 +84,7 @@ do { \
callout_init(&(_work)->timer, 1); \
} while (0)
-#define INIT_DEFERRABLE_WORK INIT_DELAYED_WORK
+#define INIT_DEFERRABLE_WORK(...) INIT_DELAYED_WORK(__VA_ARGS__)
#define schedule_work(work) \
do { \
@@ -95,20 +94,15 @@ do { \
#define flush_scheduled_work() flush_taskqueue(taskqueue_thread)
-static inline int queue_work(struct workqueue_struct *q, struct work_struct *work)
-{
- (work)->taskqueue = (q)->taskqueue;
- /* Return opposite val to align with Linux logic */
- return !taskqueue_enqueue((q)->taskqueue, &(work)->work_task);
-}
-
-static inline void
-_delayed_work_fn(void *arg)
+static inline int
+queue_work(struct workqueue_struct *wq, struct work_struct *work)
{
- struct delayed_work *work;
-
- work = arg;
- taskqueue_enqueue(work->work.taskqueue, &work->work.work_task);
+ work->taskqueue = wq->taskqueue;
+ /* Check for draining */
+ if (atomic_read(&wq->draining) != 0)
+ return (!work->work_task.ta_pending);
+ /* Return opposite value to align with Linux logic */
+ return (!taskqueue_enqueue(wq->taskqueue, &work->work_task));
}
static inline int
@@ -117,76 +111,65 @@ queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work,
{
int pending;
- pending = work->work.work_task.ta_pending;
work->work.taskqueue = wq->taskqueue;
- if (delay != 0)
- callout_reset(&work->timer, delay, _delayed_work_fn, work);
- else
- _delayed_work_fn((void *)work);
-
+ if (atomic_read(&wq->draining) != 0) {
+ pending = work->work.work_task.ta_pending;
+ } else if (delay != 0) {
+ pending = work->work.work_task.ta_pending;
+ callout_reset(&work->timer, delay, linux_delayed_work_fn, work);
+ } else {
+ callout_stop(&work->timer);
+ pending = taskqueue_enqueue(work->work.taskqueue,
+ &work->work.work_task);
+ }
return (!pending);
}
-static inline bool schedule_delayed_work(struct delayed_work *dwork,
- unsigned long delay)
-{
- struct workqueue_struct wq;
- wq.taskqueue = taskqueue_thread;
- return queue_delayed_work(&wq, dwork, delay);
-}
-
-static inline struct workqueue_struct *
-_create_workqueue_common(char *name, int cpus)
+static inline bool
+schedule_delayed_work(struct delayed_work *dwork,
+ unsigned long delay)
{
- struct workqueue_struct *wq;
-
- wq = kmalloc(sizeof(*wq), M_WAITOK);
- wq->taskqueue = taskqueue_create((name), M_WAITOK,
- taskqueue_thread_enqueue, &wq->taskqueue);
- taskqueue_start_threads(&wq->taskqueue, cpus, PWAIT, "%s", name);
+ struct workqueue_struct wq;
- return (wq);
+ wq.taskqueue = taskqueue_thread;
+ atomic_set(&wq.draining, 0);
+ return (queue_delayed_work(&wq, dwork, delay));
}
-
#define create_singlethread_workqueue(name) \
- _create_workqueue_common(name, 1)
+ linux_create_workqueue_common(name, 1)
#define create_workqueue(name) \
- _create_workqueue_common(name, MAXCPU)
+ linux_create_workqueue_common(name, MAXCPU)
#define alloc_ordered_workqueue(name, flags) \
- _create_workqueue_common(name, 1)
+ linux_create_workqueue_common(name, 1)
#define alloc_workqueue(name, flags, max_active) \
- _create_workqueue_common(name, max_active)
-
-static inline void
-destroy_workqueue(struct workqueue_struct *wq)
-{
- taskqueue_free(wq->taskqueue);
- kfree(wq);
-}
+ linux_create_workqueue_common(name, max_active)
#define flush_workqueue(wq) flush_taskqueue((wq)->taskqueue)
static inline void
-_flush_fn(void *context, int pending)
-{
-}
-
-static inline void
flush_taskqueue(struct taskqueue *tq)
{
struct task flushtask;
PHOLD(curproc);
- TASK_INIT(&flushtask, 0, _flush_fn, NULL);
+ TASK_INIT(&flushtask, 0, linux_flush_fn, NULL);
taskqueue_enqueue(tq, &flushtask);
taskqueue_drain(tq, &flushtask);
PRELE(curproc);
}
+static inline void
+drain_workqueue(struct workqueue_struct *wq)
+{
+ atomic_inc(&wq->draining);
+ flush_taskqueue(wq->taskqueue);
+ atomic_dec(&wq->draining);
+}
+
static inline int
cancel_work_sync(struct work_struct *work)
{
@@ -223,7 +206,7 @@ cancel_delayed_work_sync(struct delayed_work *work)
static inline bool
mod_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork,
- unsigned long delay)
+ unsigned long delay)
{
cancel_delayed_work(dwork);
queue_delayed_work(wq, dwork, delay);
OpenPOWER on IntegriCloud