xref: /titanic_41/usr/src/uts/common/io/ath/ath_osdep.c (revision a90d965d832a5578dbfc2eadd1617e8cccf25264)
1 /*
2  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
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.
20  *
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.
33  *
34  */
35 
36 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37 
38 #include <sys/param.h>
39 #include <sys/types.h>
40 #include <sys/cmn_err.h>
41 #include <sys/kmem.h>
42 #include <sys/ddi.h>
43 #include <sys/sunddi.h>
44 #include <sys/varargs.h>
45 #include "ath_hal.h"
46 #include "ath_impl.h"
47 
48 struct ath_halfix {
49 	void *p;
50 	size_t size;
51 };
52 
53 #define	ATH_MAX_HALMEM	1024
54 static struct ath_halfix ath_halfix[ATH_MAX_HALMEM];
55 
56 /* HAL layer needs these definitions */
57 int ath_hal_dma_beacon_response_time = 2;	/* in TU's */
58 int ath_hal_sw_beacon_response_time = 10;	/* in TU's */
59 int ath_hal_additional_swba_backoff = 0;	/* in TU's */
60 
61 /*
62  * Print/log message support.
63  */
64 
65 void
66 ath_hal_printf(struct ath_hal *ah, const char *fmt, ...)
67 {
68 	va_list ap;
69 
70 	_NOTE(ARGUNUSED(ah))
71 	va_start(ap, fmt);
72 	vcmn_err(CE_CONT, fmt, ap);
73 	va_end(ap);
74 }
75 
76 /*
77  * Delay n microseconds.
78  */
79 void
80 ath_hal_delay(int n)
81 {
82 	drv_usecwait(n);
83 }
84 
85 /*
86  * ath_hal_malloc() and ath_hal_free() are called
87  * within ath_hal.o. We must record the size of
88  * the memory alloced, so ath_hal_free() can get
89  * the size and then calls kmem_free().
90  */
91 void *
92 ath_hal_malloc(size_t size)
93 {
94 	void *p;
95 	int i;
96 
97 	for (i = 0; i < ATH_MAX_HALMEM; i++) {
98 		if (ath_halfix[i].p == NULL)
99 			break;
100 	}
101 	if (i >= ATH_MAX_HALMEM) {
102 		ath_problem("ath: ath_hal_malloc(): too many malloc\n");
103 		return (NULL);
104 	}
105 	p = kmem_zalloc(size, KM_SLEEP);
106 	ath_halfix[i].p = p;
107 	ath_halfix[i].size = size;
108 	ATH_DEBUG((ATH_DBG_OSDEP, "ath: ath_hal_malloc(): "
109 	    "%d: p=%p, size=%d\n", i, p, size));
110 	return (p);
111 }
112 
113 void
114 ath_hal_free(void* p)
115 {
116 	int i;
117 	for (i = 0; i < ATH_MAX_HALMEM; i++) {
118 		if (ath_halfix[i].p == p)
119 			break;
120 	}
121 	if (i >= ATH_MAX_HALMEM) {
122 		ath_problem("ath: ath_hal_free(): no record for %p\n", p);
123 		return;
124 	}
125 	kmem_free(p, ath_halfix[i].size);
126 	ath_halfix[i].p = NULL;
127 	ATH_DEBUG((ATH_DBG_OSDEP, "ath: ath_hal_free(): %d: p=%p, size=%d\n",
128 	    i, p, ath_halfix[i].size));
129 }
130 
131 void *
132 ath_hal_memcpy(void *dst, const void *src, size_t n)
133 {
134 	bcopy(src, dst, n);
135 	return (dst);
136 }
137 
138 void
139 ath_hal_memzero(void *dst, size_t n)
140 {
141 	bzero(dst, n);
142 }
143 
144 void
145 ath_halfix_init(void)
146 {
147 	int i;
148 
149 	for (i = 0; i < ATH_MAX_HALMEM; i++)
150 		ath_halfix[i].p = NULL;
151 }
152 
153 void
154 ath_halfix_finit(void)
155 {
156 	int i;
157 
158 	for (i = 0; i < ATH_MAX_HALMEM; i++)
159 		if (ath_halfix[i].p != NULL) {
160 			kmem_free(ath_halfix[i].p, ath_halfix[i].size);
161 			ATH_DEBUG((ATH_DBG_OSDEP, "ath_halfix: "
162 			    "Free %d: p=%x size=%d\n",
163 			    i, ath_halfix[i].p, ath_halfix[i].size));
164 		}
165 }
166