Home | History | Annotate | Line # | Download | only in ic
ath_netbsd.h revision 1.13.2.2
      1 /*	$NetBSD: ath_netbsd.h,v 1.13.2.2 2013/02/25 00:29:14 tls Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2003, 2004 David Young
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 #ifndef _ATH_NETBSD_H
     28 #define _ATH_NETBSD_H
     29 
     30 #include <sys/sysctl.h>
     31 
     32 typedef struct ath_task {
     33 	void	(*t_func)(void*, int);
     34 	void	*t_context;
     35 } ath_task_t;
     36 
     37 #define ATH_CALLOUT_INIT(__ch, __mpsafe) callout_init((__ch), 0)
     38 
     39 #define TASK_INIT(__task, __zero, __func, __context)	\
     40 	do {						\
     41 		(__task)->t_func = (__func);		\
     42 		(__task)->t_context = (__context);	\
     43 	} while (0)
     44 
     45 #define TASK_RUN_OR_ENQUEUE(__task)	\
     46 	((*(__task)->t_func)((__task)->t_context, 1))
     47 
     48 typedef kmutex_t ath_txq_lock_t;
     49 #define	ATH_TXQ_LOCK_INIT(_sc, _tq)	mutex_init(&(_tq)->axq_lock, MUTEX_DEFAULT, IPL_NET)
     50 #define	ATH_TXQ_LOCK_DESTROY(_tq)	mutex_destroy(&(_tq)->axq_lock)
     51 #define	ATH_TXQ_LOCK(_tq)		mutex_enter(&(_tq)->axq_lock)
     52 #define	ATH_TXQ_UNLOCK(_tq)		mutex_exit(&(_tq)->axq_lock)
     53 #define	ATH_TXQ_LOCK_ASSERT(_tq)	do { KASSERTMSG(mutex_owned(&(_tq)->axq_lock), "txq lock unheld"); } while (/*CONSTCOND*/true)
     54 
     55 typedef kmutex_t ath_txbuf_lock_t;
     56 #define	ATH_TXBUF_LOCK_INIT(_sc)	mutex_init(&(_sc)->sc_txbuflock, MUTEX_DEFAULT, IPL_NET)
     57 #define	ATH_TXBUF_LOCK_DESTROY(_sc)	mutex_destroy(&(_sc)->sc_txbuflock)
     58 #define	ATH_TXBUF_LOCK(_sc)		mutex_enter(&(_sc)->sc_txbuflock)
     59 #define	ATH_TXBUF_UNLOCK(_sc)		mutex_exit(&(_sc)->sc_txbuflock)
     60 #define	ATH_TXBUF_LOCK_ASSERT(_sc)	do { KASSERTMSG(mutex_owned(&(_sc)->sc_txbuflock), "txbuf lock unheld"); } while (/*CONSTCOND*/true)
     61 
     62 #define	NET_LOCK_GIANT()
     63 #define	NET_UNLOCK_GIANT()
     64 
     65 #define	SYSCTL_INT_SUBR(__rw, __name, __descr)				     \
     66 	sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_PERMANENT|(__rw),     \
     67 	    CTLTYPE_INT, #__name, SYSCTL_DESCR(__descr), ath_sysctl_##__name,\
     68 	    0, (void *)sc, 0, CTL_CREATE, CTL_EOL)
     69 
     70 #define	__PFX(__pfx, __name)	__pfx##__name
     71 
     72 #define	SYSCTL_PFX_INT(__pfx, __rw, __name, __descr)			\
     73 	sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_PERMANENT|(__rw),\
     74 	    CTLTYPE_INT, #__name, SYSCTL_DESCR(__descr), NULL, 0,	\
     75 	    __PFX(&__pfx, __name), 0, CTL_CREATE, CTL_EOL)
     76 
     77 #define	SYSCTL_INT(__rw, __name, __descr)				\
     78 	SYSCTL_PFX_INT(sc->sc_, __rw, __name, __descr)
     79 
     80 #define	SYSCTL_GLOBAL_INT(__rw, __name, __descr, __var)			\
     81 	sysctl_createv(clog, 0, &rnode, &cnode,				\
     82 	    CTLFLAG_PERMANENT|(__rw), CTLTYPE_INT, __name,		\
     83 	    SYSCTL_DESCR(__descr), NULL, 0, &ath_##__var, 0, CTL_CREATE,\
     84 	    CTL_EOL)
     85 
     86 const struct sysctlnode *ath_sysctl_treetop(struct sysctllog **);
     87 const struct sysctlnode *ath_sysctl_instance(const char *, struct sysctllog **);
     88 
     89 #endif /* _ATH_NETBSD_H */
     90