Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 May 2015 20:59:44 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r282514 - in stable/9/sys/ofed/include: linux net
Message-ID:  <201505052059.t45KxieA008224@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Tue May  5 20:59:43 2015
New Revision: 282514
URL: https://svnweb.freebsd.org/changeset/base/282514

Log:
  MFC r277396, r278681, r278865, r278924, r279205, r280208,
    r280210, r280764 and r280768:
  
  Update the Linux compatibility layer:
  - Add more functions.
  - Add some missing includes which are needed when the header files
    are not included in a particular order.
  - The kasprintf() function cannot be inlined due to using a variable
    number of arguments. Move it to a C-file.
  - Fix problems about 32-bit ticks wraparound and unsigned long
    conversion. Jiffies or ticks in FreeBSD have integer type and are
    not long.
  - Add missing "order_base_2()" macro.
  - Fix BUILD_BUG_ON() macro.
  - Declare a missing symbol which is needed when compiling without -O2
  - Clean up header file inclusions in the linux/completion.h, linux/in.h
    and linux/fs.h header files.
  
  Sponsored by:	Mellanox Technologies

Modified:
  stable/9/sys/ofed/include/linux/bitops.h
  stable/9/sys/ofed/include/linux/cache.h
  stable/9/sys/ofed/include/linux/completion.h
  stable/9/sys/ofed/include/linux/device.h
  stable/9/sys/ofed/include/linux/dma-mapping.h
  stable/9/sys/ofed/include/linux/etherdevice.h
  stable/9/sys/ofed/include/linux/fs.h
  stable/9/sys/ofed/include/linux/gfp.h
  stable/9/sys/ofed/include/linux/in.h
  stable/9/sys/ofed/include/linux/io.h
  stable/9/sys/ofed/include/linux/jiffies.h
  stable/9/sys/ofed/include/linux/kernel.h
  stable/9/sys/ofed/include/linux/kref.h
  stable/9/sys/ofed/include/linux/ktime.h
  stable/9/sys/ofed/include/linux/linux_compat.c
  stable/9/sys/ofed/include/linux/log2.h
  stable/9/sys/ofed/include/linux/pci.h
  stable/9/sys/ofed/include/linux/slab.h
  stable/9/sys/ofed/include/linux/timer.h
  stable/9/sys/ofed/include/net/ip.h
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/ofed/include/linux/bitops.h
==============================================================================
--- stable/9/sys/ofed/include/linux/bitops.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/bitops.h	Tue May  5 20:59:43 2015	(r282514)
@@ -288,9 +288,15 @@ bitmap_empty(unsigned long *addr, int si
 
 #define	NBLONG	(NBBY * sizeof(long))
 
+#define	__set_bit(i, a)							\
+    atomic_set_long(&((volatile long *)(a))[(i)/NBLONG], 1UL << ((i) % NBLONG))
+
 #define	set_bit(i, a)							\
     atomic_set_long(&((volatile long *)(a))[(i)/NBLONG], 1UL << ((i) % NBLONG))
 
+#define	__clear_bit(i, a)						\
+    atomic_clear_long(&((volatile long *)(a))[(i)/NBLONG], 1UL << ((i) % NBLONG))
+
 #define	clear_bit(i, a)							\
     atomic_clear_long(&((volatile long *)(a))[(i)/NBLONG], 1UL << ((i) % NBLONG))
 

Modified: stable/9/sys/ofed/include/linux/cache.h
==============================================================================
--- stable/9/sys/ofed/include/linux/cache.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/cache.h	Tue May  5 20:59:43 2015	(r282514)
@@ -30,8 +30,7 @@
 #ifndef	_LINUX_CACHE_H_
 #define _LINUX_CACHE_H_
 
-
 #define	cache_line_size()	CACHE_LINE_SIZE
-
+#define	L1_CACHE_BYTES		CACHE_LINE_SIZE
 
 #endif	/* _LINUX_CACHE_H_ */

Modified: stable/9/sys/ofed/include/linux/completion.h
==============================================================================
--- stable/9/sys/ofed/include/linux/completion.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/completion.h	Tue May  5 20:59:43 2015	(r282514)
@@ -32,124 +32,35 @@
 
 #include <linux/errno.h>
 
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sleepqueue.h>
-#include <sys/kernel.h>
-#include <sys/proc.h>
-
 struct completion {
 	unsigned int done;
 };
 
-#define	INIT_COMPLETION(c)	((c).done = 0)
-#define	init_completion(c)	((c)->done = 0)
-
-static inline void
-_complete_common(struct completion *c, int all)
-{
-	int wakeup_swapper;
-
-	sleepq_lock(c);
-	c->done++;
-	if (all)
-		wakeup_swapper = sleepq_broadcast(c, SLEEPQ_SLEEP, 0, 0);
-	else
-		wakeup_swapper = sleepq_signal(c, SLEEPQ_SLEEP, 0, 0);
-	sleepq_release(c);
-	if (wakeup_swapper)
-		kick_proc0();
-}
-
-#define	complete(c)	_complete_common(c, 0)
-#define	complete_all(c)	_complete_common(c, 1)
-
-/*
- * Indefinite wait for done != 0 with or without signals.
- */
-static inline long
-_wait_for_common(struct completion *c, int flags)
-{
-
-	flags |= SLEEPQ_SLEEP;
-	for (;;) {
-		sleepq_lock(c);
-		if (c->done)
-			break;
-		sleepq_add(c, NULL, "completion", flags, 0);
-		if (flags & SLEEPQ_INTERRUPTIBLE) {
-			if (sleepq_wait_sig(c, 0) != 0)
-				return (-ERESTARTSYS);
-		} else
-			sleepq_wait(c, 0);
-	}
-	c->done--;
-	sleepq_release(c);
-
-	return (0);
-}
-
-#define	wait_for_completion(c)	_wait_for_common(c, 0)
-#define	wait_for_completion_interuptible(c)				\
-	_wait_for_common(c, SLEEPQ_INTERRUPTIBLE)
-
-static inline long
-_wait_for_timeout_common(struct completion *c, long timeout, int flags)
-{
-	long end;
-
-	end = ticks + timeout;
-	flags |= SLEEPQ_SLEEP;
-	for (;;) {
-		sleepq_lock(c);
-		if (c->done)
-			break;
-		sleepq_add(c, NULL, "completion", flags, 0);
-		sleepq_set_timeout(c, end - ticks);
-		if (flags & SLEEPQ_INTERRUPTIBLE) {
-			if (sleepq_timedwait_sig(c, 0) != 0)
-				return (-ERESTARTSYS);
-		} else
-			sleepq_timedwait(c, 0);
-	}
-	c->done--;
-	sleepq_release(c);
-	timeout = end - ticks;
-
-	return (timeout > 0 ? timeout : 1);
-}
-
-#define	wait_for_completion_timeout(c, timeout)				\
-	_wait_for_timeout_common(c, timeout, 0)
-#define	wait_for_completion_interruptible_timeout(c, timeout)		\
-	_wait_for_timeout_common(c, timeout, SLEEPQ_INTERRUPTIBLE)
-
-static inline int
-try_wait_for_completion(struct completion *c)
-{
-	int isdone;
-
-	isdone = 1;
-	sleepq_lock(c);
-	if (c->done)
-		c->done--;
-	else
-		isdone = 0;
-	sleepq_release(c);
-	return (isdone);
-}
-
-static inline int
-completion_done(struct completion *c)
-{
-	int isdone;
-
-	isdone = 1;
-	sleepq_lock(c);
-	if (c->done == 0)
-		isdone = 0;
-	sleepq_release(c);
-	return (isdone);
-}
+#define	INIT_COMPLETION(c) \
+	((c).done = 0)
+#define	init_completion(c) \
+	((c)->done = 0)
+#define	complete(c)				\
+	linux_complete_common((c), 0)
+#define	complete_all(c)				\
+	linux_complete_common((c), 1)
+#define	wait_for_completion(c)			\
+	linux_wait_for_common((c), 0)
+#define	wait_for_completion_interuptible(c)	\
+	linux_wait_for_common((c), 1)
+#define	wait_for_completion_timeout(c, timeout)	\
+	linux_wait_for_timeout_common((c), (timeout), 0)
+#define	wait_for_completion_interruptible_timeout(c, timeout)	\
+	linux_wait_for_timeout_common((c), (timeout), 1)
+#define	try_wait_for_completion(c) \
+	linux_try_wait_for_completion(c)
+#define	completion_done(c) \
+	linux_completion_done(c)
+
+extern void linux_complete_common(struct completion *, int);
+extern long linux_wait_for_common(struct completion *, int);
+extern long linux_wait_for_timeout_common(struct completion *, long, int);
+extern int linux_try_wait_for_completion(struct completion *);
+extern int linux_completion_done(struct completion *);
 
-#endif	/* _LINUX_COMPLETION_H_ */
+#endif					/* _LINUX_COMPLETION_H_ */

Modified: stable/9/sys/ofed/include/linux/device.h
==============================================================================
--- stable/9/sys/ofed/include/linux/device.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/device.h	Tue May  5 20:59:43 2015	(r282514)
@@ -431,17 +431,6 @@ static inline char *kvasprintf(gfp_t gfp
 	return p;
 }
 
-static inline char *kasprintf(gfp_t gfp, const char *fmt, ...)
-{
-	va_list ap;
-	char *p;
-
-	va_start(ap, fmt);
-	p = kvasprintf(gfp, fmt, ap);
-	va_end(ap);
-
-	return p;
-}
-
+char *kasprintf(gfp_t, const char *, ...);
 
 #endif	/* _LINUX_DEVICE_H_ */

Modified: stable/9/sys/ofed/include/linux/dma-mapping.h
==============================================================================
--- stable/9/sys/ofed/include/linux/dma-mapping.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/dma-mapping.h	Tue May  5 20:59:43 2015	(r282514)
@@ -139,6 +139,14 @@ dma_alloc_coherent(struct device *dev, s
 		*dma_handle = 0;
 	return (mem);
 }
+
+static inline void *
+dma_zalloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
+    gfp_t flag)
+{
+
+	return (dma_alloc_coherent(dev, size, dma_handle, flag | __GFP_ZERO));
+}
                        
 static inline void
 dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,

Modified: stable/9/sys/ofed/include/linux/etherdevice.h
==============================================================================
--- stable/9/sys/ofed/include/linux/etherdevice.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/etherdevice.h	Tue May  5 20:59:43 2015	(r282514)
@@ -89,6 +89,9 @@ static inline bool is_valid_ether_addr(c
         return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
 }
 
-
+static inline void ether_addr_copy(u8 *dst, const u8 *src)
+{
+	memcpy(dst, src, 6);
+}
 
 #endif /* _LINUX_ETHERDEVICE */

Modified: stable/9/sys/ofed/include/linux/fs.h
==============================================================================
--- stable/9/sys/ofed/include/linux/fs.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/fs.h	Tue May  5 20:59:43 2015	(r282514)
@@ -29,6 +29,8 @@
 #ifndef	_LINUX_FS_H_
 #define	_LINUX_FS_H_
 
+#include <sys/cdefs.h>
+#include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/conf.h>
 #include <sys/vnode.h>

Modified: stable/9/sys/ofed/include/linux/gfp.h
==============================================================================
--- stable/9/sys/ofed/include/linux/gfp.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/gfp.h	Tue May  5 20:59:43 2015	(r282514)
@@ -30,6 +30,8 @@
 #ifndef	_LINUX_GFP_H_
 #define	_LINUX_GFP_H_
 
+#include <sys/cdefs.h>
+#include <sys/types.h>
 #include <sys/systm.h>
 #include <sys/malloc.h>
 
@@ -103,6 +105,13 @@ __free_pages(void *p, unsigned int order
 	kmem_free(kmem_map, (vm_offset_t)p, size);
 }
 
+static inline void free_pages(uintptr_t addr, unsigned int order)
+{
+	if (addr == 0)
+		return;
+	__free_pages(virt_to_page((void *)addr), order);
+}
+
 /*
  * Alloc pages allocates directly from the buddy allocator on linux so
  * order specifies a power of two bucket of pages and the results
@@ -122,6 +131,16 @@ alloc_pages(gfp_t gfp_mask, unsigned int
         return (virt_to_page(page));
 }
 
+static inline uintptr_t __get_free_pages(gfp_t gfp_mask, unsigned int order)
+{
+	struct page *page;
+
+	page = alloc_pages(gfp_mask, order);
+	if (page == NULL)
+		return (0);
+	return ((uintptr_t)page_address(page));
+}
+
 #define alloc_pages_node(node, mask, order)     alloc_pages(mask, order)
 
 #define kmalloc_node(chunk, mask, node)         kmalloc(chunk, mask)

Modified: stable/9/sys/ofed/include/linux/in.h
==============================================================================
--- stable/9/sys/ofed/include/linux/in.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/in.h	Tue May  5 20:59:43 2015	(r282514)
@@ -31,6 +31,9 @@
 
 #include "opt_inet.h"
 
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/systm.h>
 #include <netinet/in.h>
 #include <asm/byteorder.h>
 

Modified: stable/9/sys/ofed/include/linux/io.h
==============================================================================
--- stable/9/sys/ofed/include/linux/io.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/io.h	Tue May  5 20:59:43 2015	(r282514)
@@ -31,6 +31,7 @@
 #define	_LINUX_IO_H_
 
 #include <machine/vm.h>
+#include <sys/endian.h>
 
 static inline uint32_t
 __raw_readl(const volatile void *addr)
@@ -89,6 +90,20 @@ writew(uint16_t b, void *addr)
         *(volatile uint16_t *)addr = b;
 }
 
+#undef ioread32be
+static inline uint32_t
+ioread32be(const volatile void *addr)
+{
+	return be32toh(*(const volatile uint32_t *)addr);
+}
+
+#undef iowrite32be
+static inline void
+iowrite32be(uint32_t v, volatile void *addr)
+{
+	*(volatile uint32_t *)addr = htobe32(v);
+}
+
 void *_ioremap_attr(vm_paddr_t phys_addr, unsigned long size, int attr);
 #define	ioremap_nocache(addr, size)					\
     _ioremap_attr((addr), (size), VM_MEMATTR_UNCACHEABLE)

Modified: stable/9/sys/ofed/include/linux/jiffies.h
==============================================================================
--- stable/9/sys/ofed/include/linux/jiffies.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/jiffies.h	Tue May  5 20:59:43 2015	(r282514)
@@ -45,14 +45,12 @@ msecs_to_jiffies(int msec)
 	return (tvtohz(&tv));
 }
 
-
 #define jiffies                 ticks
 #define jiffies_to_msecs(x)     (((int64_t)(x)) * 1000 / hz)
 
-
-#define	time_after(a, b)	((long)(b) - (long)(a) < 0)
+#define	time_after(a, b)	((int)((b) - (a)) < 0)
 #define	time_before(a, b)	time_after(b,a)
-#define	time_after_eq(a, b)	((long)(a) - (long)(b) >= 0)
+#define	time_after_eq(a, b)	((int)((a) - (b)) >= 0)
 #define	time_before_eq(a, b)	time_after_eq(b, a)
 
 #define	HZ	hz

Modified: stable/9/sys/ofed/include/linux/kernel.h
==============================================================================
--- stable/9/sys/ofed/include/linux/kernel.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/kernel.h	Tue May  5 20:59:43 2015	(r282514)
@@ -29,6 +29,8 @@
 #ifndef	_LINUX_KERNEL_H_
 #define	_LINUX_KERNEL_H_
 
+#include <sys/cdefs.h>
+#include <sys/types.h>
 #include <sys/systm.h>
 #include <sys/param.h>
 #include <sys/libkern.h>
@@ -57,6 +59,8 @@
 #define	KERN_INFO	"<6>"
 #define	KERN_DEBUG	"<7>"
 
+#define	BUILD_BUG_ON(x)		CTASSERT(!(x))
+
 #define BUG()			panic("BUG")
 #define BUG_ON(condition)	do { if (condition) BUG(); } while(0)
 #define	WARN_ON			BUG_ON
@@ -66,6 +70,7 @@
 #undef PTR_ALIGN
 #define	PTR_ALIGN(p, a)		((__typeof(p))ALIGN((uintptr_t)(p), (a)))
 #define	DIV_ROUND_UP		howmany
+#define	FIELD_SIZEOF(t, f)	sizeof(((t *)0)->f)
 
 #define	printk(X...)		printf(X)
 
@@ -86,6 +91,7 @@
 #endif
 
 #define udelay(t)       	DELAY(t)
+#define usleep_range(min,max)	DELAY(min)
 
 #ifndef pr_fmt
 #define pr_fmt(fmt) fmt
@@ -172,6 +178,7 @@
 #define round_down(x, y) ((x) & ~__round_mask(x, y))
 
 #define	num_possible_cpus()	mp_ncpus
+#define	num_online_cpus()	mp_ncpus
 
 typedef struct pm_message {
         int event;

Modified: stable/9/sys/ofed/include/linux/kref.h
==============================================================================
--- stable/9/sys/ofed/include/linux/kref.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/kref.h	Tue May  5 20:59:43 2015	(r282514)
@@ -29,6 +29,7 @@
 #ifndef _LINUX_KREF_H_
 #define _LINUX_KREF_H_
 
+#include <sys/types.h>
 #include <sys/refcount.h>
 
 struct kref {

Modified: stable/9/sys/ofed/include/linux/ktime.h
==============================================================================
--- stable/9/sys/ofed/include/linux/ktime.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/ktime.h	Tue May  5 20:59:43 2015	(r282514)
@@ -288,4 +288,13 @@ static inline s64 ktime_to_ns(const ktim
 
 #endif	/* !((BITS_PER_LONG == 64) || defined(CONFIG_KTIME_SCALAR)) */
 
+static inline s64 ktime_get_ns(void)
+{
+	struct timespec ts;
+	ktime_t kt;
+	ktime_get_ts(&ts);
+	kt = timespec_to_ktime(ts);
+	return (ktime_to_ns(kt));
+}
+
 #endif	/* _LINUX_KTIME_H */

Modified: stable/9/sys/ofed/include/linux/linux_compat.c
==============================================================================
--- stable/9/sys/ofed/include/linux/linux_compat.c	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/linux_compat.c	Tue May  5 20:59:43 2015	(r282514)
@@ -32,6 +32,8 @@
 #include <sys/malloc.h>
 #include <sys/kernel.h>
 #include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/sleepqueue.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
 #include <sys/bus.h>
@@ -55,6 +57,8 @@
 #include <linux/mm.h>
 #include <linux/io.h>
 #include <linux/vmalloc.h>
+#include <linux/timer.h>
+#include <linux/netdevice.h>
 
 #include <vm/vm_pager.h>
 
@@ -66,20 +70,17 @@ MALLOC_DEFINE(M_KMALLOC, "linux", "Linux
 #undef file
 #undef cdev
 #define	RB_ROOT(head)	(head)->rbh_root
-#undef LIST_HEAD
-/* From sys/queue.h */
-#define LIST_HEAD(name, type)						\
-struct name {								\
-	struct type *lh_first;	/* first element */			\
-}
 
 struct kobject class_root;
 struct device linux_rootdev;
 struct class miscclass;
 struct list_head pci_drivers;
 struct list_head pci_devices;
+struct net init_net;
 spinlock_t pci_lock;
 
+unsigned long linux_timer_hz_mask;
+
 int
 panic_cmp(struct rb_node *one, struct rb_node *two)
 {
@@ -595,7 +596,9 @@ struct vmmap {
 	unsigned long		vm_size;
 };
 
-LIST_HEAD(vmmaphd, vmmap);
+struct vmmaphd {
+	struct vmmap *lh_first;
+};
 #define	VMMAP_HASH_SIZE	64
 #define	VMMAP_HASH_MASK	(VMMAP_HASH_SIZE - 1)
 #define	VM_HASH(addr)	((uintptr_t)(addr) >> PAGE_SHIFT) & VMMAP_HASH_MASK
@@ -686,6 +689,185 @@ vunmap(void *addr)
 	kfree(vmmap);
 }
 
+
+char *
+kasprintf(gfp_t gfp, const char *fmt, ...)
+{
+	va_list ap;
+	char *p;
+
+	va_start(ap, fmt);
+	p = kvasprintf(gfp, fmt, ap);
+	va_end(ap);
+
+	return p;
+}
+
+static int
+linux_timer_jiffies_until(unsigned long expires)
+{
+	int delta = expires - jiffies;
+	/* guard against already expired values */
+	if (delta < 1)
+		delta = 1;
+	return (delta);
+}
+
+static void
+linux_timer_callback_wrapper(void *context)
+{
+	struct timer_list *timer;
+
+	timer = context;
+	timer->function(timer->data);
+}
+
+void
+mod_timer(struct timer_list *timer, unsigned long expires)
+{
+
+	timer->expires = expires;
+	callout_reset(&timer->timer_callout,		      
+	    linux_timer_jiffies_until(expires),
+	    &linux_timer_callback_wrapper, timer);
+}
+
+void
+add_timer(struct timer_list *timer)
+{
+
+	callout_reset(&timer->timer_callout,
+	    linux_timer_jiffies_until(timer->expires),
+	    &linux_timer_callback_wrapper, timer);
+}
+
+static void
+linux_timer_init(void *arg)
+{
+
+	/*
+	 * Compute an internal HZ value which can divide 2**32 to
+	 * avoid timer rounding problems when the tick value wraps
+	 * around 2**32:
+	 */
+	linux_timer_hz_mask = 1;
+	while (linux_timer_hz_mask < (unsigned long)hz)
+		linux_timer_hz_mask *= 2;
+	linux_timer_hz_mask--;
+}
+SYSINIT(linux_timer, SI_SUB_DRIVERS, SI_ORDER_FIRST, linux_timer_init, NULL);
+
+void
+linux_complete_common(struct completion *c, int all)
+{
+	int wakeup_swapper;
+
+	sleepq_lock(c);
+	c->done++;
+	if (all)
+		wakeup_swapper = sleepq_broadcast(c, SLEEPQ_SLEEP, 0, 0);
+	else
+		wakeup_swapper = sleepq_signal(c, SLEEPQ_SLEEP, 0, 0);
+	sleepq_release(c);
+	if (wakeup_swapper)
+		kick_proc0();
+}
+
+/*
+ * Indefinite wait for done != 0 with or without signals.
+ */
+long
+linux_wait_for_common(struct completion *c, int flags)
+{
+
+	if (flags != 0)
+		flags = SLEEPQ_INTERRUPTIBLE | SLEEPQ_SLEEP;
+	else
+		flags = SLEEPQ_SLEEP;
+	for (;;) {
+		sleepq_lock(c);
+		if (c->done)
+			break;
+		sleepq_add(c, NULL, "completion", flags, 0);
+		if (flags & SLEEPQ_INTERRUPTIBLE) {
+			if (sleepq_wait_sig(c, 0) != 0)
+				return (-ERESTARTSYS);
+		} else
+			sleepq_wait(c, 0);
+	}
+	c->done--;
+	sleepq_release(c);
+
+	return (0);
+}
+
+/*
+ * Time limited wait for done != 0 with or without signals.
+ */
+long
+linux_wait_for_timeout_common(struct completion *c, long timeout, int flags)
+{
+	long end = jiffies + timeout;
+
+	if (flags != 0)
+		flags = SLEEPQ_INTERRUPTIBLE | SLEEPQ_SLEEP;
+	else
+		flags = SLEEPQ_SLEEP;
+	for (;;) {
+		int ret;
+
+		sleepq_lock(c);
+		if (c->done)
+			break;
+		sleepq_add(c, NULL, "completion", flags, 0);
+		sleepq_set_timeout(c, linux_timer_jiffies_until(end));
+		if (flags & SLEEPQ_INTERRUPTIBLE)
+			ret = sleepq_timedwait_sig(c, 0);
+		else
+			ret = sleepq_timedwait(c, 0);
+		if (ret != 0) {
+			/* check for timeout or signal */
+			if (ret == EWOULDBLOCK)
+				return (0);
+			else
+				return (-ERESTARTSYS);
+		}
+	}
+	c->done--;
+	sleepq_release(c);
+
+	/* return how many jiffies are left */
+	return (linux_timer_jiffies_until(end));
+}
+
+int
+linux_try_wait_for_completion(struct completion *c)
+{
+	int isdone;
+
+	isdone = 1;
+	sleepq_lock(c);
+	if (c->done)
+		c->done--;
+	else
+		isdone = 0;
+	sleepq_release(c);
+	return (isdone);
+}
+
+int
+linux_completion_done(struct completion *c)
+{
+	int isdone;
+
+	isdone = 1;
+	sleepq_lock(c);
+	if (c->done == 0)
+		isdone = 0;
+	sleepq_release(c);
+	return (isdone);
+}
+
 static void
 linux_compat_init(void *arg)
 {

Modified: stable/9/sys/ofed/include/linux/log2.h
==============================================================================
--- stable/9/sys/ofed/include/linux/log2.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/log2.h	Tue May  5 20:59:43 2015	(r282514)
@@ -167,4 +167,6 @@ int __ilog2_u64(u64 n)
 	__ilog2_u64(n)				\
  )
 
+#define	order_base_2(x) ilog2(roundup_pow_of_two(x))
+
 #endif	/* _LINUX_LOG2_H_ */

Modified: stable/9/sys/ofed/include/linux/pci.h
==============================================================================
--- stable/9/sys/ofed/include/linux/pci.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/pci.h	Tue May  5 20:59:43 2015	(r282514)
@@ -270,6 +270,14 @@ pci_set_master(struct pci_dev *pdev)
 }
 
 static inline int
+pci_clear_master(struct pci_dev *pdev)
+{
+
+	pci_disable_busmaster(pdev->dev.bsddev);
+	return (0);
+}
+
+static inline int
 pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
 {
 	int rid;
@@ -592,6 +600,30 @@ pci_enable_msix(struct pci_dev *pdev, st
 	return (0);
 }
 
+#define	pci_enable_msix_range	linux_pci_enable_msix_range
+static inline int
+pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
+    int minvec, int maxvec)
+{
+	int nvec = maxvec;
+	int rc;
+
+	if (maxvec < minvec)
+		return (-ERANGE);
+
+	do {
+		rc = pci_enable_msix(dev, entries, nvec);
+		if (rc < 0) {
+			return (rc);
+		} else if (rc > 0) {
+			if (rc < minvec)
+				return (-ENOSPC);
+			nvec = rc;
+		}
+	} while (rc);
+	return (nvec);
+}
+
 static inline int pci_channel_offline(struct pci_dev *pdev)
 {
         return false;

Modified: stable/9/sys/ofed/include/linux/slab.h
==============================================================================
--- stable/9/sys/ofed/include/linux/slab.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/slab.h	Tue May  5 20:59:43 2015	(r282514)
@@ -40,6 +40,7 @@
 MALLOC_DECLARE(M_KMALLOC);
 
 #define	kmalloc(size, flags)		malloc((size), M_KMALLOC, (flags))
+#define	kvmalloc(size)			kmalloc((size), 0)
 #define	kzalloc(size, flags)		kmalloc((size), (flags) | M_ZERO)
 #define	kzalloc_node(size, flags, node)	kzalloc(size, flags)
 #define	kfree(ptr)			free(__DECONST(void *, (ptr)), M_KMALLOC)
@@ -47,6 +48,7 @@ MALLOC_DECLARE(M_KMALLOC);
 #define	kcalloc(n, size, flags)	        kmalloc((n) * (size), flags | M_ZERO)
 #define	vzalloc(size)			kzalloc(size, GFP_KERNEL | __GFP_NOWARN)
 #define	vfree(arg)			kfree(arg)
+#define	kvfree(arg)			kfree(arg)
 #define	vmalloc(size)                   kmalloc(size, GFP_KERNEL)
 #define	vmalloc_node(size, node)        kmalloc(size, GFP_KERNEL)
 

Modified: stable/9/sys/ofed/include/linux/timer.h
==============================================================================
--- stable/9/sys/ofed/include/linux/timer.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/linux/timer.h	Tue May  5 20:59:43 2015	(r282514)
@@ -27,7 +27,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #ifndef _LINUX_TIMER_H_
-#define _LINUX_TIMER_H_
+#define	_LINUX_TIMER_H_
 
 #include <linux/types.h>
 
@@ -36,20 +36,13 @@
 #include <sys/callout.h>
 
 struct timer_list {
-	struct callout	timer_callout;
-	void		(*function)(unsigned long);
-	unsigned long	data;
-	unsigned long	expires;
+	struct callout timer_callout;
+	void    (*function) (unsigned long);
+	unsigned long data;
+	unsigned long expires;
 };
 
-static inline void
-_timer_fn(void *context)
-{
-	struct timer_list *timer;
-
-	timer = context;
-	timer->function(timer->data);
-}
+extern unsigned long linux_timer_hz_mask;
 
 #define	setup_timer(timer, func, dat)					\
 do {									\
@@ -65,28 +58,15 @@ do {									\
 	callout_init(&(timer)->timer_callout, CALLOUT_MPSAFE);		\
 } while (0)
 
-#define	mod_timer(timer, exp)						\
-do {									\
-	(timer)->expires = (exp);					\
-	callout_reset(&(timer)->timer_callout, (exp) - jiffies,		\
-	    _timer_fn, (timer));					\
-} while (0)
-
-#define	add_timer(timer)						\
-	callout_reset(&(timer)->timer_callout,				\
-	    (timer)->expires - jiffies, _timer_fn, (timer))
+extern void mod_timer(struct timer_list *, unsigned long);
+extern void add_timer(struct timer_list *);
 
 #define	del_timer(timer)	callout_stop(&(timer)->timer_callout)
 #define	del_timer_sync(timer)	callout_drain(&(timer)->timer_callout)
-
 #define	timer_pending(timer)	callout_pending(&(timer)->timer_callout)
+#define	round_jiffies(j) \
+	((unsigned long)(((j) + linux_timer_hz_mask) & ~linux_timer_hz_mask))
+#define	round_jiffies_relative(j) \
+	round_jiffies(j)
 
-static inline unsigned long
-round_jiffies(unsigned long j)
-{
-	return roundup(j, hz);
-}
-
-#define round_jiffies_relative(j) round_jiffies(j)
-
-#endif /* _LINUX_TIMER_H_ */
+#endif					/* _LINUX_TIMER_H_ */

Modified: stable/9/sys/ofed/include/net/ip.h
==============================================================================
--- stable/9/sys/ofed/include/net/ip.h	Tue May  5 20:58:12 2015	(r282513)
+++ stable/9/sys/ofed/include/net/ip.h	Tue May  5 20:59:43 2015	(r282514)
@@ -42,13 +42,17 @@
 #include <netinet/in.h>
 #include <netinet/in_pcb.h>
 
-#ifdef INET
 static inline void inet_get_local_port_range(int *low, int *high)
 {
+#ifdef INET
 	CURVNET_SET_QUIET(TD_TO_VNET(curthread));
 	*low = V_ipport_firstauto;
 	*high = V_ipport_lastauto;
 	CURVNET_RESTORE();
+#else
+	*low = IPPORT_EPHEMERALFIRST;     /* 10000 */
+	*high = IPPORT_EPHEMERALLAST;     /* 65535 */
+#endif
 }
 
 static inline void
@@ -79,6 +83,5 @@ ip_ib_mc_map(uint32_t addr, const unsign
 	buf[18] = (addr >> 8) & 0xff;
 	buf[19] = addr & 0xff;
 }
-#endif
 
 #endif	/* _LINUX_NET_IP_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201505052059.t45KxieA008224>