8572 ccompile.h: rename __GNU_UNUSED to __unused
[unleashed.git] / kernel / drivers / net / wifi / ath / ath_osdep.c
blobf22537bdad32ef07fe74dfd0cba3336e1eab27c4
1 /*
2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
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 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
15 * redistribution must be conditioned upon including a substantially
16 * similar Disclaimer requirement for further binary redistribution.
17 * 3. Neither the names of the above-listed copyright holders nor the names
18 * of any contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO WARRANTY
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
25 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
26 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
27 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGES.
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/cmn_err.h>
39 #include <sys/kmem.h>
40 #include <sys/ddi.h>
41 #include <sys/sunddi.h>
42 #include <sys/varargs.h>
43 #include "ath_hal.h"
44 #include "ath_impl.h"
46 struct ath_halfix {
47 void *p;
48 size_t size;
51 #define ATH_MAX_HALMEM 1024
52 static struct ath_halfix ath_halfix[ATH_MAX_HALMEM];
54 /* HAL layer needs these definitions */
55 int ath_hal_dma_beacon_response_time = 2; /* in TU's */
56 int ath_hal_sw_beacon_response_time = 10; /* in TU's */
57 int ath_hal_additional_swba_backoff = 0; /* in TU's */
60 * Print/log message support.
63 void
64 ath_hal_printf(struct ath_hal *ah, const char *fmt, ...)
66 va_list ap;
68 _NOTE(ARGUNUSED(ah))
69 va_start(ap, fmt);
70 vcmn_err(CE_CONT, fmt, ap);
71 va_end(ap);
75 * Delay n microseconds.
77 void
78 ath_hal_delay(int n)
80 drv_usecwait(n);
84 * ath_hal_malloc() and ath_hal_free() are called
85 * within ath_hal.o. We must record the size of
86 * the memory alloced, so ath_hal_free() can get
87 * the size and then calls kmem_free().
89 void *
90 ath_hal_malloc(size_t size)
92 void *p;
93 int i;
95 for (i = 0; i < ATH_MAX_HALMEM; i++) {
96 if (ath_halfix[i].p == NULL)
97 break;
99 if (i >= ATH_MAX_HALMEM) {
100 ath_problem("ath: ath_hal_malloc(): too many malloc\n");
101 return (NULL);
103 p = kmem_zalloc(size, KM_SLEEP);
104 ath_halfix[i].p = p;
105 ath_halfix[i].size = size;
106 ATH_DEBUG((ATH_DBG_OSDEP, "ath: ath_hal_malloc(): "
107 "%d: p=%p, size=%d\n", i, p, size));
108 return (p);
111 void
112 ath_hal_free(void* p)
114 int i;
115 for (i = 0; i < ATH_MAX_HALMEM; i++) {
116 if (ath_halfix[i].p == p)
117 break;
119 if (i >= ATH_MAX_HALMEM) {
120 ath_problem("ath: ath_hal_free(): no record for %p\n", p);
121 return;
123 kmem_free(p, ath_halfix[i].size);
124 ath_halfix[i].p = NULL;
125 ATH_DEBUG((ATH_DBG_OSDEP, "ath: ath_hal_free(): %d: p=%p, size=%d\n",
126 i, p, ath_halfix[i].size));
129 void *
130 ath_hal_memcpy(void *dst, const void *src, size_t n)
132 bcopy(src, dst, n);
133 return (dst);
136 void
137 ath_hal_memzero(void *dst, size_t n)
139 bzero(dst, n);
142 void
143 ath_halfix_init(void)
145 int i;
147 for (i = 0; i < ATH_MAX_HALMEM; i++)
148 ath_halfix[i].p = NULL;
151 void
152 ath_halfix_finit(void)
154 int i;
156 for (i = 0; i < ATH_MAX_HALMEM; i++)
157 if (ath_halfix[i].p != NULL) {
158 kmem_free(ath_halfix[i].p, ath_halfix[i].size);
159 ATH_DEBUG((ATH_DBG_OSDEP, "ath_halfix: "
160 "Free %d: p=%x size=%d\n",
161 i, ath_halfix[i].p, ath_halfix[i].size));