1 /* $NetBSD: ath_netbsd.h,v 1.12 2011/10/07 16:58:11 dyoung 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 #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 ATH_CALLOUT_INIT(__ch, __mpsafe) callout_init((__ch), 0) 41 42 #define TASK_INIT(__task, __zero, __func, __context) \ 43 do { \ 44 (__task)->t_func = (__func); \ 45 (__task)->t_context = (__context); \ 46 } while (0) 47 48 #define TASK_RUN_OR_ENQUEUE(__task) \ 49 ((*(__task)->t_func)((__task)->t_context, 1)) 50 51 typedef kmutex_t ath_txq_lock_t; 52 #define ATH_TXQ_LOCK_INIT(_sc, _tq) mutex_init(&(_tq)->axq_lock, MUTEX_DEFAULT, IPL_NET) 53 #define ATH_TXQ_LOCK_DESTROY(_tq) mutex_destroy(&(_tq)->axq_lock) 54 #define ATH_TXQ_LOCK(_tq) mutex_enter(&(_tq)->axq_lock) 55 #define ATH_TXQ_UNLOCK(_tq) mutex_exit(&(_tq)->axq_lock) 56 #define ATH_TXQ_LOCK_ASSERT(_tq) do { KASSERT(mutex_owned(&(_tq)->axq_lock), ("txq lock unheld")); } while (/*CONSTCOND*/true) 57 58 typedef kmutex_t ath_txbuf_lock_t; 59 #define ATH_TXBUF_LOCK_INIT(_sc) mutex_init(&(_sc)->sc_txbuflock, MUTEX_DEFAULT, IPL_NET) 60 #define ATH_TXBUF_LOCK_DESTROY(_sc) mutex_destroy(&(_sc)->sc_txbuflock) 61 #define ATH_TXBUF_LOCK(_sc) mutex_enter(&(_sc)->sc_txbuflock) 62 #define ATH_TXBUF_UNLOCK(_sc) mutex_exit(&(_sc)->sc_txbuflock) 63 #define ATH_TXBUF_LOCK_ASSERT(_sc) do { KASSERT(mutex_owned(&(_sc)->sc_txbuflock), ("txbuf lock unheld")); } while (/*CONSTCOND*/true) 64 65 #define NET_LOCK_GIANT() 66 #define NET_UNLOCK_GIANT() 67 68 #define IF_LOCK(__q) 69 #define IF_UNLOCK(__q) 70 71 #define SYSCTL_INT_SUBR(__rw, __name, __descr) \ 72 sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_PERMANENT|(__rw), \ 73 CTLTYPE_INT, #__name, SYSCTL_DESCR(__descr), ath_sysctl_##__name,\ 74 0, sc, 0, CTL_CREATE, CTL_EOL) 75 76 #define __PFX(__pfx, __name) __pfx##__name 77 78 #define SYSCTL_PFX_INT(__pfx, __rw, __name, __descr) \ 79 sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_PERMANENT|(__rw),\ 80 CTLTYPE_INT, #__name, SYSCTL_DESCR(__descr), NULL, 0, \ 81 __PFX(&__pfx, __name), 0, CTL_CREATE, CTL_EOL) 82 83 #define SYSCTL_INT(__rw, __name, __descr) \ 84 SYSCTL_PFX_INT(sc->sc_, __rw, __name, __descr) 85 86 #define SYSCTL_GLOBAL_INT(__rw, __name, __descr, __var) \ 87 sysctl_createv(clog, 0, &rnode, &cnode, \ 88 CTLFLAG_PERMANENT|(__rw), CTLTYPE_INT, __name, \ 89 SYSCTL_DESCR(__descr), NULL, 0, &ath_##__var, 0, CTL_CREATE,\ 90 CTL_EOL) 91 92 const struct sysctlnode *ath_sysctl_treetop(struct sysctllog **); 93 const struct sysctlnode *ath_sysctl_instance(const char *, struct sysctllog **); 94 95 #endif /* _ATH_NETBSD_H */ 96