FreeBSD/Linux Kernel Cross Reference
sys/dev/ic/athcompat.h
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_COMPAT_H
28 #define _ATH_COMPAT_H
29
30 #ifdef __FreeBSD__
31 #define ATH_TICKS() (ticks)
32
33 typedef struct task ath_task_t;
34
35 #define ATH_CALLOUT_INIT(chp) callout_init((chp), CALLOUT_MPSAFE)
36
37 #define ATH_TASK_INIT(task, func, context) TASK_INIT(task, 0, func, context)
38 #define ATH_TASK_RUN_OR_ENQUEUE(_task) taskqueue_enqueue(taskqueue_swi, _task)
39
40 #define ath_softc_critsect_decl(_x) /* empty */
41 #define ath_softc_critsect_begin(sc, _x) mtx_lock(&(sc)->sc_mtx)
42 #define ath_softc_critsect_end(sc, _x) mtx_unlock(&(sc)->sc_mtx)
43 #define ath_txbuf_critsect_decl(_x) /* empty */
44 #define ath_txbuf_critsect_begin(sc, _x) mtx_lock(&(sc)->sc_txbuflock)
45 #define ath_txbuf_critsect_end(sc, _x) mtx_unlock(&(sc)->sc_txbuflock)
46 #define ath_txq_critsect_decl(_x) /* empty */
47 #define ath_txq_critsect_begin(sc, _x) mtx_lock(&(sc)->sc_txqlock)
48 #define ath_txq_critsect_end(sc, _x) mtx_unlock(&(sc)->sc_txqlock)
49
50 static __inline int
51 ath_buf_dmamap_load_mbuf(bus_dma_tag_t tag, struct ath_buf *bf,
52 struct mbuf *m, int flags)
53 {
54 int error;
55 error = bus_dmamap_load_mbuf(tag, bf->bf_dmamap, m, ath_mbuf_load_cb,
56 bf, flags);
57 if (error == 0 && bf->bf_nseg > ATH_TXDESC)
58 return EFBIG;
59 return error;
60 }
61
62 #define ath_buf_dmamap_sync(tag, bf, ops) \
63 bus_dmamap_sync((tag), (bf)->bf_dmamap, (ops))
64
65 #else
66 #define ATH_TICKS() (hardclock_ticks)
67
68 #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
69 #undef KASSERT
70 #define KASSERT(cond, complaint) if (!(cond)) panic complaint
71
72 typedef struct ath_task {
73 void (*t_func)(void*, int);
74 void *t_context;
75 } ath_task_t;
76
77 #define ATH_CALLOUT_INIT(chp) callout_init((chp))
78
79 #define ATH_TASK_INIT(task, func, context) \
80 do { \
81 (task)->t_func = (func); \
82 (task)->t_context = (context); \
83 } while (0)
84
85 #define ATH_TASK_RUN_OR_ENQUEUE(task) ((*(task)->t_func)((task)->t_context, 1))
86
87 #define ath_critsect_decl(_x) int _x
88 #define ath_critsect_begin(sc, _x) do { _x = splnet(); } while (0)
89 #define ath_critsect_end(sc, _x) splx(_x)
90 #define ath_softc_critsect_decl(_x) ath_critsect_decl(_x)
91 #define ath_softc_critsect_begin(sc, _x) ath_critsect_begin(sc, _x)
92 #define ath_softc_critsect_end(sc, _x) ath_critsect_end(sc, _x)
93 #define ath_txbuf_critsect_decl(_x) ath_critsect_decl(_x)
94 #define ath_txbuf_critsect_begin(sc, _x) ath_critsect_begin(sc, _x)
95 #define ath_txbuf_critsect_end(sc, _x) ath_critsect_end(sc, _x)
96 #define ath_txq_critsect_decl(_x) ath_critsect_decl(_x)
97 #define ath_txq_critsect_begin(sc, _x) ath_critsect_begin(sc, _x)
98 #define ath_txq_critsect_end(sc, _x) ath_critsect_end(sc, _x)
99
100 #define ath_buf_dmamap_load_mbuf(tag, bf, m, flags) \
101 bus_dmamap_load_mbuf((tag), (bf)->bf_dmamap, (m), (flags))
102
103 #define ath_buf_dmamap_sync(tag, bf, ops) \
104 bus_dmamap_sync((tag), (bf)->bf_dmamap, 0, \
105 (bf)->bf_dmamap->dm_mapsize, (ops))
106
107 extern void device_printf(struct device, const char *fmt, ...);
108
109 #endif
110
111 #endif /* _ATH_COMPAT_H */
Cache object: ba87a0467c81413cacdcacbe0c0529a9
|