Home | History | Annotate | Line # | Download | only in ic
ath_netbsd.h revision 1.1
      1 /*-
      2  * Copyright (c) 2003, 2004 David Young
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. The name of the author may not be used to endorse or promote products
     14  *    derived from this software without specific prior written permission.
     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 #undef KASSERT
     31 #define KASSERT(__cond, __complaint) if (!(__cond)) panic __complaint
     32 
     33 typedef struct ath_task {
     34 	void	(*t_func)(void*, int);
     35 	void	*t_context;
     36 } ath_task_t;
     37 
     38 #define	M_RDONLY	M_EXT	/* XXX check different/additional flags? */
     39 
     40 #define	CALLOUT_MPSAFE	0
     41 #define ATH_CALLOUT_INIT(__ch, __mpsafe) callout_init((__ch))
     42 
     43 #define TASK_INIT(__task, __zero, __func, __context)	\
     44 	do {						\
     45 		(__task)->t_func = (__func);		\
     46 		(__task)->t_context = (__context);	\
     47 	} while (0)
     48 
     49 #define TASK_RUN_OR_ENQUEUE(__task)	\
     50 	((*(__task)->t_func)((__task)->t_context, 1))
     51 
     52 typedef int ath_txq_lock_t;
     53 #define	ATH_TXQ_LOCK_INIT(_sc, _tq)
     54 #define	ATH_TXQ_LOCK_DESTROY(_tq)
     55 #define	ATH_TXQ_LOCK(_tq)		\
     56 	do { (_tq)->axq_lock = splnet(); } while (0)
     57 #define	ATH_TXQ_UNLOCK(_tq)		\
     58 	do { splx((_tq)->axq_lock); } while (0)
     59 #define	ATH_TXQ_LOCK_ASSERT(_tq)
     60 
     61 struct ath_lock {
     62 	int count;
     63 	int ipl;
     64 };
     65 
     66 #define	ATH_LOCK_INIT_IMPL(_sc, _member)		\
     67 	do { (_sc)->_member.count = 0; } while (0)
     68 #define	ATH_LOCK_IMPL(_sc, _member)			\
     69 	do {						\
     70 		int __s = splnet();			\
     71 		if ((_sc)->_member.count++ == 0)	\
     72 			(_sc)->_member.ipl = __s;	\
     73 	} while (0)
     74 #define	ATH_UNLOCK_IMPL(_sc, _member)					\
     75 	do {								\
     76 		if (--(_sc)->_member.count == 0)			\
     77 			splx((_sc)->_member.ipl);			\
     78 		else {							\
     79 			KASSERT((_sc)->_member.count >= 0,		\
     80 			    ("%s: no ATH_LOCK holders", __func__));	\
     81 		}							\
     82 	} while (0)
     83 typedef struct ath_lock ath_lock_t;
     84 #define	ATH_LOCK_INIT(_sc)	ATH_LOCK_INIT_IMPL(_sc, sc_mtx)
     85 #define	ATH_LOCK_DESTROY(_sc)
     86 #define	ATH_LOCK(_sc)	ATH_LOCK_IMPL(_sc, sc_mtx)
     87 #define	ATH_UNLOCK(_sc)	ATH_UNLOCK_IMPL(_sc, sc_mtx)
     88 #define	ATH_LOCK_ASSERT(_sc)
     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	SYSCTL_INT(__rw, __name, __descr)				\
    109 	sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_PERMANENT|(__rw),\
    110 	    CTLTYPE_INT, #__name, SYSCTL_DESCR(__descr), NULL, 0,	\
    111 	    &sc->sc_##__name, 0, CTL_CREATE, CTL_EOL)
    112 
    113 #define	SYSCTL_GLOBAL_INT(__rw, __name, __descr, __var)			\
    114 	sysctl_createv(clog, 0, &rnode, &cnode,				\
    115 	    CTLFLAG_PERMANENT|(__rw), CTLTYPE_INT, __name,		\
    116 	    SYSCTL_DESCR(__descr), NULL, 0, &ath_##__var, 0, CTL_CREATE,\
    117 	    CTL_EOL)
    118 
    119 extern void device_printf(struct device, const char *fmt, ...);
    120 struct mbuf *m_defrag(struct mbuf *, int);
    121 struct mbuf *m_getcl(int, int, int);
    122 const struct sysctlnode *ath_sysctl_treetop(struct sysctllog **);
    123 
    124 #endif /* _ATH_NETBSD_H */
    125