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