Home | History | Annotate | Line # | Download | only in ic
ath_netbsd.h revision 1.2.2.2
      1 /*	$NetBSD: ath_netbsd.h,v 1.2.2.2 2007/09/03 14:34:20 yamt 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  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 #ifndef _ATH_NETBSD_H
     30 #define _ATH_NETBSD_H
     31 
     32 #undef KASSERT
     33 #define KASSERT(__cond, __complaint) if (!(__cond)) panic __complaint
     34 
     35 typedef struct ath_task {
     36 	void	(*t_func)(void*, int);
     37 	void	*t_context;
     38 } ath_task_t;
     39 
     40 #define	M_RDONLY	M_EXT	/* XXX check different/additional flags? */
     41 
     42 #define ATH_CALLOUT_INIT(__ch, __mpsafe) callout_init((__ch), 0)
     43 
     44 #define TASK_INIT(__task, __zero, __func, __context)	\
     45 	do {						\
     46 		(__task)->t_func = (__func);		\
     47 		(__task)->t_context = (__context);	\
     48 	} while (0)
     49 
     50 #define TASK_RUN_OR_ENQUEUE(__task)	\
     51 	((*(__task)->t_func)((__task)->t_context, 1))
     52 
     53 struct ath_lock {
     54 	int count;
     55 	int ipl;
     56 };
     57 
     58 #define	ATH_LOCK_INIT_IMPL(_obj, _member)		\
     59 	do { (_obj)->_member.count = 0; } while (0)
     60 #define	ATH_LOCK_IMPL(_obj, _member)			\
     61 	do {						\
     62 		int __s = splnet();			\
     63 		if ((_obj)->_member.count++ == 0)	\
     64 			(_obj)->_member.ipl = __s;	\
     65 	} while (0)
     66 #define	ATH_UNLOCK_IMPL(_obj, _member)					\
     67 	do {								\
     68 		if (--(_obj)->_member.count == 0)			\
     69 			splx((_obj)->_member.ipl);			\
     70 		else {							\
     71 			KASSERT((_obj)->_member.count >= 0,		\
     72 			    ("%s: no ATH_LOCK holders", __func__));	\
     73 		}							\
     74 	} while (0)
     75 
     76 typedef struct ath_lock ath_lock_t;
     77 #define	ATH_LOCK_INIT(_sc)	ATH_LOCK_INIT_IMPL(_sc, sc_mtx)
     78 #define	ATH_LOCK_DESTROY(_sc)
     79 #define	ATH_LOCK(_sc)	ATH_LOCK_IMPL(_sc, sc_mtx)
     80 #define	ATH_UNLOCK(_sc)	ATH_UNLOCK_IMPL(_sc, sc_mtx)
     81 #define	ATH_LOCK_ASSERT(_sc)
     82 
     83 typedef struct ath_lock ath_txq_lock_t;
     84 #define	ATH_TXQ_LOCK_INIT(_sc, _tq)	ATH_LOCK_INIT_IMPL(_tq, axq_lock)
     85 #define	ATH_TXQ_LOCK_DESTROY(_tq)
     86 #define	ATH_TXQ_LOCK(_tq)		ATH_LOCK_IMPL(_tq, axq_lock)
     87 #define	ATH_TXQ_UNLOCK(_tq)		ATH_UNLOCK_IMPL(_tq, axq_lock)
     88 #define	ATH_TXQ_LOCK_ASSERT(_tq)
     89 
     90 typedef struct ath_lock ath_txbuf_lock_t;
     91 #define	ATH_TXBUF_LOCK_INIT(_sc)	ATH_LOCK_INIT_IMPL(_sc, sc_txbuflock)
     92 #define	ATH_TXBUF_LOCK_DESTROY(_sc)
     93 #define	ATH_TXBUF_LOCK(_sc)		ATH_LOCK_IMPL(_sc, sc_txbuflock)
     94 #define	ATH_TXBUF_UNLOCK(_sc)		ATH_UNLOCK_IMPL(_sc, sc_txbuflock)
     95 #define	ATH_TXBUF_LOCK_ASSERT(_sc)
     96 
     97 #define	NET_LOCK_GIANT()
     98 #define	NET_UNLOCK_GIANT()
     99 
    100 #define	IF_LOCK(__q)
    101 #define	IF_UNLOCK(__q)
    102 
    103 #define	SYSCTL_INT_SUBR(__rw, __name, __descr)				     \
    104 	sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_PERMANENT|(__rw),     \
    105 	    CTLTYPE_INT, #__name, SYSCTL_DESCR(__descr), ath_sysctl_##__name,\
    106 	    0, sc, 0, CTL_CREATE, CTL_EOL)
    107 
    108 #define	__PFX(__pfx, __name)	__pfx##__name
    109 
    110 #define	SYSCTL_PFX_INT(__pfx, __rw, __name, __descr)			\
    111 	sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_PERMANENT|(__rw),\
    112 	    CTLTYPE_INT, #__name, SYSCTL_DESCR(__descr), NULL, 0,	\
    113 	    __PFX(&__pfx, __name), 0, CTL_CREATE, CTL_EOL)
    114 
    115 #define	SYSCTL_INT(__rw, __name, __descr)				\
    116 	SYSCTL_PFX_INT(sc->sc_, __rw, __name, __descr)
    117 
    118 #define	SYSCTL_GLOBAL_INT(__rw, __name, __descr, __var)			\
    119 	sysctl_createv(clog, 0, &rnode, &cnode,				\
    120 	    CTLFLAG_PERMANENT|(__rw), CTLTYPE_INT, __name,		\
    121 	    SYSCTL_DESCR(__descr), NULL, 0, &ath_##__var, 0, CTL_CREATE,\
    122 	    CTL_EOL)
    123 
    124 extern void device_printf(struct device, const char *fmt, ...);
    125 struct mbuf *m_defrag(struct mbuf *, int);
    126 struct mbuf *m_getcl(int, int, int);
    127 const struct sysctlnode *ath_sysctl_treetop(struct sysctllog **);
    128 const struct sysctlnode *ath_sysctl_instance(const char *, struct sysctllog **);
    129 
    130 #endif /* _ATH_NETBSD_H */
    131