xref: /illumos-gate/usr/src/uts/common/io/ath/ath_osdep.c (revision 129d67ac)
1 /*
2  * Copyright 2008 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 #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"
45 
46 struct ath_halfix {
47 	void *p;
48 	size_t size;
49 };
50 
51 #define	ATH_MAX_HALMEM	1024
52 static struct ath_halfix ath_halfix[ATH_MAX_HALMEM];
53 
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 */
58 
59 /*
60  * Print/log message support.
61  */
62 
63 void
ath_hal_printf(struct ath_hal * ah,const char * fmt,...)64 ath_hal_printf(struct ath_hal *ah, const char *fmt, ...)
65 {
66 	va_list ap;
67 
68 	_NOTE(ARGUNUSED(ah))
69 	va_start(ap, fmt);
70 	vcmn_err(CE_CONT, fmt, ap);
71 	va_end(ap);
72 }
73 
74 /*
75  * Delay n microseconds.
76  */
77 void
ath_hal_delay(int n)78 ath_hal_delay(int n)
79 {
80 	drv_usecwait(n);
81 }
82 
83 /*
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().
88  */
89 void *
ath_hal_malloc(size_t size)90 ath_hal_malloc(size_t size)
91 {
92 	void *p;
93 	int i;
94 
95 	for (i = 0; i < ATH_MAX_HALMEM; i++) {
96 		if (ath_halfix[i].p == NULL)
97 			break;
98 	}
99 	if (i >= ATH_MAX_HALMEM) {
100 		ath_problem("ath: ath_hal_malloc(): too many malloc\n");
101 		return (NULL);
102 	}
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);
109 }
110 
111 void
ath_hal_free(void * p)112 ath_hal_free(void* p)
113 {
114 	int i;
115 	for (i = 0; i < ATH_MAX_HALMEM; i++) {
116 		if (ath_halfix[i].p == p)
117 			break;
118 	}
119 	if (i >= ATH_MAX_HALMEM) {
120 		ath_problem("ath: ath_hal_free(): no record for %p\n", p);
121 		return;
122 	}
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));
127 }
128 
129 void *
ath_hal_memcpy(void * dst,const void * src,size_t n)130 ath_hal_memcpy(void *dst, const void *src, size_t n)
131 {
132 	bcopy(src, dst, n);
133 	return (dst);
134 }
135 
136 void
ath_hal_memzero(void * dst,size_t n)137 ath_hal_memzero(void *dst, size_t n)
138 {
139 	bzero(dst, n);
140 }
141 
142 void
ath_halfix_init(void)143 ath_halfix_init(void)
144 {
145 	int i;
146 
147 	for (i = 0; i < ATH_MAX_HALMEM; i++)
148 		ath_halfix[i].p = NULL;
149 }
150 
151 void
ath_halfix_finit(void)152 ath_halfix_finit(void)
153 {
154 	int i;
155 
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));
162 		}
163 }
164