Module Name:    src
Committed By:   jdolecek
Date:           Sat May 19 08:59:38 UTC 2018

Modified Files:
        src/sys/external/bsd/ena-com: ena_plat.h

Log Message:
adapt for NetBSD


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 src/sys/external/bsd/ena-com/ena_plat.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/ena-com/ena_plat.h
diff -u src/sys/external/bsd/ena-com/ena_plat.h:1.1.1.1 src/sys/external/bsd/ena-com/ena_plat.h:1.2
--- src/sys/external/bsd/ena-com/ena_plat.h:1.1.1.1	Sat May 19 08:56:06 2018
+++ src/sys/external/bsd/ena-com/ena_plat.h	Sat May 19 08:59:38 2018
@@ -35,7 +35,10 @@
 #define ENA_PLAT_H_
 
 #include <sys/cdefs.h>
+#if 0
 __FBSDID("$FreeBSD: head/sys/contrib/ena-com/ena_plat.h 333453 2018-05-10 09:25:51Z mw $");
+#endif
+__KERNEL_RCSID(0, "$NetBSD: ena_plat.h,v 1.2 2018/05/19 08:59:38 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -48,45 +51,29 @@ __FBSDID("$FreeBSD: head/sys/contrib/ena
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
 #include <sys/module.h>
-#include <sys/rman.h>
 #include <sys/proc.h>
-#include <sys/smp.h>
 #include <sys/socket.h>
 #include <sys/sockio.h>
 #include <sys/sysctl.h>
-#include <sys/taskqueue.h>
-#include <sys/eventhandler.h>
 #include <sys/types.h>
-#include <sys/timetc.h>
-#include <sys/cdefs.h>
-
-#include <machine/atomic.h>
-#include <machine/bus.h>
-#include <machine/in_cksum.h>
-#include <machine/pcpu.h>
-#include <machine/resource.h>
+#include <sys/bus.h>
+#include <sys/atomic.h>
 
-#include <net/bpf.h>
-#include <net/ethernet.h>
 #include <net/if.h>
-#include <net/if_var.h>
-#include <net/if_arp.h>
 #include <net/if_dl.h>
 #include <net/if_media.h>
+#include <net/if_ether.h>
 
-#include <net/if_types.h>
-#include <net/if_vlan_var.h>
+#include <net/bpf.h>
+
+#include <net/rss_config.h>
 
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-#include <netinet/ip.h>
-#include <netinet/ip6.h>
-#include <netinet/tcp.h>
-#include <netinet/tcp_lro.h>
-#include <netinet/udp.h>
+#include <netinet/in.h>			/* XXX for struct ip */
+#include <netinet/in_systm.h>		/* XXX for struct ip */
+#include <netinet/ip.h>			/* XXX for struct ip */
+#include <netinet/ip6.h>		/* XXX for struct ip6_hdr */
+#include <netinet/tcp.h>		/* XXX for struct tcphdr */
 
-#include <dev/led/led.h>
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>
 
@@ -114,8 +101,8 @@ extern int ena_log_level;
 	} while (0)
 
 #define ena_trace(level, fmt, args...)				\
-	ena_trace_raw(level, "%s() [TID:%d]: "			\
-	    fmt " \n", __func__, curthread->td_tid, ##args)
+	ena_trace_raw(level, "%s() [LID:%d]: "			\
+	    fmt " \n", __func__, curlwp->l_lid, ##args)
 
 
 #define ena_trc_dbg(format, arg...) 	ena_trace(ENA_DBG, format, ##arg)
@@ -184,11 +171,11 @@ static inline long PTR_ERR(const void *p
 #define	ENA_COM_PERMISSION	EPERM
 #define ENA_COM_TIMER_EXPIRED	ETIMEDOUT
 
-#define ENA_MSLEEP(x) 		pause_sbt("ena", SBT_1MS * (x), SBT_1MS, 0)
+#define ENA_MSLEEP(x) 		kpause("enaw", false, mstohz(x), NULL)
 #define ENA_UDELAY(x) 		DELAY(x)
 #define ENA_GET_SYSTEM_TIMEOUT(timeout_us) \
-    ((long)cputick2usec(cpu_ticks()) + (timeout_us))
-#define ENA_TIME_EXPIRE(timeout)  ((timeout) < (long)cputick2usec(cpu_ticks()))
+	mstohz(timeout_us * (1000 / 100))	/* XXX assumes 100 ms sleep */
+#define ENA_TIME_EXPIRE(timeout)  ((timeout)-- <= 0)
 #define ENA_MIGHT_SLEEP()
 
 #define min_t(type, _x, _y) ((type)(_x) < (type)(_y) ? (type)(_x) : (type)(_y))
@@ -203,52 +190,51 @@ static inline long PTR_ERR(const void *p
 #define ENA_MAX8(x,y) 	MAX(x, y)
 
 /* Spinlock related methods */
-#define ena_spinlock_t 	struct mtx
+#define ena_spinlock_t 	kmutex_t
 #define ENA_SPINLOCK_INIT(spinlock)				\
-	mtx_init(&(spinlock), "ena_spin", NULL, MTX_SPIN)
+	mutex_init(&(spinlock), MUTEX_DEFAULT, IPL_NET)
 #define ENA_SPINLOCK_DESTROY(spinlock)				\
 	do {							\
-		if (mtx_initialized(&(spinlock)))		\
-		    mtx_destroy(&(spinlock));			\
+		mutex_destroy(&(spinlock));			\
 	} while (0)
 #define ENA_SPINLOCK_LOCK(spinlock, flags)			\
 	do {							\
 		(void)(flags);					\
-		mtx_lock_spin(&(spinlock));			\
+		mutex_enter(&(spinlock));			\
 	} while (0)
 #define ENA_SPINLOCK_UNLOCK(spinlock, flags)			\
 	do {							\
 		(void)(flags);					\
-		mtx_unlock_spin(&(spinlock));			\
+		mutex_exit(&(spinlock));			\
 	} while (0)
 
 
 /* Wait queue related methods */
-#define ena_wait_event_t struct { struct cv wq; struct mtx mtx; }
+#define ena_wait_event_t struct { kcondvar_t wq; kmutex_t mtx; }
 #define ENA_WAIT_EVENT_INIT(waitqueue)					\
 	do {								\
-		cv_init(&((waitqueue).wq), "cv");			\
-		mtx_init(&((waitqueue).mtx), "wq", NULL, MTX_DEF);	\
+		cv_init(&((waitqueue).wq), "enacv");			\
+		mutex_init(&((waitqueue).mtx), MUTEX_DEFAULT, IPL_NET);	\
 	} while (0)
 #define ENA_WAIT_EVENT_DESTROY(waitqueue)				\
 	do {								\
 		cv_destroy(&((waitqueue).wq));				\
-		mtx_destroy(&((waitqueue).mtx));			\
+		mutex_destroy(&((waitqueue).mtx));			\
 	} while (0)
 #define ENA_WAIT_EVENT_CLEAR(waitqueue)					\
-	cv_init(&((waitqueue).wq), (waitqueue).wq.cv_description)
+	cv_init(&((waitqueue).wq), "enacv")
 #define ENA_WAIT_EVENT_WAIT(waitqueue, timeout_us)			\
 	do {								\
-		mtx_lock(&((waitqueue).mtx));				\
+		mutex_enter(&((waitqueue).mtx));			\
 		cv_timedwait(&((waitqueue).wq), &((waitqueue).mtx),	\
 		    timeout_us * hz / 1000 / 1000 );			\
-		mtx_unlock(&((waitqueue).mtx));				\
+		mutex_exit(&((waitqueue).mtx));				\
 	} while (0)
 #define ENA_WAIT_EVENT_SIGNAL(waitqueue)		\
 	do {						\
-		mtx_lock(&((waitqueue).mtx));		\
+		mutex_enter(&((waitqueue).mtx));	\
 		cv_broadcast(&((waitqueue).wq));	\
-		mtx_unlock(&((waitqueue).mtx));		\
+		mutex_exit(&((waitqueue).mtx));		\
 	} while (0)
 
 #define dma_addr_t 	bus_addr_t
@@ -258,8 +244,8 @@ static inline long PTR_ERR(const void *p
 #define u64 		uint64_t
 
 typedef struct {
-	bus_addr_t              paddr;
-	caddr_t                 vaddr;
+	paddr_t                 paddr;
+	void                    *vaddr;
         bus_dma_tag_t           tag;
 	bus_dmamap_t            map;
         bus_dma_segment_t       seg;
@@ -312,8 +298,8 @@ int	ena_dma_alloc(device_t dmadev, bus_s
 	do {								\
 		(void)size;						\
 		bus_dmamap_unload((dma).tag, (dma).map);		\
-		bus_dmamem_free((dma).tag, (virt), (dma).map);		\
-		bus_dma_tag_destroy((dma).tag);				\
+		bus_dmamem_free((dma).tag, &(dma).seg, (dma).nseg);	\
+		bus_dma_tag_destroy((dma).tag);	/* XXX remove */	\
 		(dma).tag = NULL;					\
 		(virt) = NULL;						\
 	} while (0)
@@ -332,7 +318,8 @@ int	ena_dma_alloc(device_t dmadev, bus_s
 			 (bus_size_t)(offset))
 
 #define ENA_DB_SYNC(mem_handle)	bus_dmamap_sync((mem_handle)->tag,	\
-	(mem_handle)->map, BUS_DMASYNC_PREREAD)
+	(mem_handle)->map, 0, (mem_handle)->map->dm_mapsize,		\
+	BUS_DMASYNC_PREREAD)
 
 #define time_after(a,b)	((long)((unsigned long)(b) - (unsigned long)(a)) < 0)
 
@@ -357,10 +344,10 @@ void prefetch(void *x)
 
 #define memcpy_toio memcpy
 
-#define ATOMIC32_INC(I32_PTR)		atomic_add_int(I32_PTR, 1)
-#define ATOMIC32_DEC(I32_PTR) 		atomic_add_int(I32_PTR, -1)
-#define ATOMIC32_READ(I32_PTR) 		atomic_load_acq_int(I32_PTR)
-#define ATOMIC32_SET(I32_PTR, VAL) 	atomic_store_rel_int(I32_PTR, VAL)
+#define ATOMIC32_INC(I32_PTR)		atomic_inc_32(I32_PTR)
+#define ATOMIC32_DEC(I32_PTR) 		atomic_dec_32(I32_PTR)
+#define ATOMIC32_READ(I32_PTR) 		atomic_cas_32(I32_PTR, 0, 0)
+#define ATOMIC32_SET(I32_PTR, VAL) 	atomic_swap_32(I32_PTR, VAL)
 
 #define	barrier() __asm__ __volatile__("": : :"memory")
 #define	ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x))
@@ -374,4 +361,8 @@ void prefetch(void *x)
 
 #include "ena_defs/ena_includes.h"
 
+#define	rmb()		membar_enter()
+#define	wmb()		membar_exit()
+#define	mb()		membar_sync()
+
 #endif /* ENA_PLAT_H_ */

Reply via email to