xref: /onnv-gate/usr/src/uts/common/io/ath/ath_osdep.c (revision 8033:142c11860489)
11000Sxc151355 /*
2*8033SWang.Lin@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
31000Sxc151355  * Use is subject to license terms.
41000Sxc151355  */
51000Sxc151355 
61000Sxc151355 /*
71000Sxc151355  * Redistribution and use in source and binary forms, with or without
81000Sxc151355  * modification, are permitted provided that the following conditions
91000Sxc151355  * are met:
101000Sxc151355  * 1. Redistributions of source code must retain the above copyright
111000Sxc151355  * notice, this list of conditions and the following disclaimer,
121000Sxc151355  * without modification.
131000Sxc151355  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
141000Sxc151355  * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
151000Sxc151355  * redistribution must be conditioned upon including a substantially
161000Sxc151355  * similar Disclaimer requirement for further binary redistribution.
171000Sxc151355  * 3. Neither the names of the above-listed copyright holders nor the names
181000Sxc151355  * of any contributors may be used to endorse or promote products derived
191000Sxc151355  * from this software without specific prior written permission.
201000Sxc151355  *
211000Sxc151355  * NO WARRANTY
221000Sxc151355  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
231000Sxc151355  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
241000Sxc151355  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
251000Sxc151355  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
261000Sxc151355  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
271000Sxc151355  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
281000Sxc151355  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
291000Sxc151355  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
301000Sxc151355  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
311000Sxc151355  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
321000Sxc151355  * THE POSSIBILITY OF SUCH DAMAGES.
331000Sxc151355  *
341000Sxc151355  */
351000Sxc151355 
361000Sxc151355 #include <sys/param.h>
371000Sxc151355 #include <sys/types.h>
381000Sxc151355 #include <sys/cmn_err.h>
391000Sxc151355 #include <sys/kmem.h>
401000Sxc151355 #include <sys/ddi.h>
411000Sxc151355 #include <sys/sunddi.h>
421000Sxc151355 #include <sys/varargs.h>
431000Sxc151355 #include "ath_hal.h"
441000Sxc151355 #include "ath_impl.h"
451000Sxc151355 
461000Sxc151355 struct ath_halfix {
471000Sxc151355 	void *p;
481000Sxc151355 	size_t size;
491000Sxc151355 };
501000Sxc151355 
513147Sxc151355 #define	ATH_MAX_HALMEM	1024
523147Sxc151355 static struct ath_halfix ath_halfix[ATH_MAX_HALMEM];
531000Sxc151355 
541000Sxc151355 /* HAL layer needs these definitions */
551000Sxc151355 int ath_hal_dma_beacon_response_time = 2;	/* in TU's */
561000Sxc151355 int ath_hal_sw_beacon_response_time = 10;	/* in TU's */
571000Sxc151355 int ath_hal_additional_swba_backoff = 0;	/* in TU's */
581000Sxc151355 
591000Sxc151355 /*
601000Sxc151355  * Print/log message support.
611000Sxc151355  */
621000Sxc151355 
631000Sxc151355 void
ath_hal_printf(struct ath_hal * ah,const char * fmt,...)641000Sxc151355 ath_hal_printf(struct ath_hal *ah, const char *fmt, ...)
651000Sxc151355 {
661000Sxc151355 	va_list ap;
671000Sxc151355 
681000Sxc151355 	_NOTE(ARGUNUSED(ah))
691000Sxc151355 	va_start(ap, fmt);
701000Sxc151355 	vcmn_err(CE_CONT, fmt, ap);
711000Sxc151355 	va_end(ap);
721000Sxc151355 }
731000Sxc151355 
741000Sxc151355 /*
751000Sxc151355  * Delay n microseconds.
761000Sxc151355  */
771000Sxc151355 void
ath_hal_delay(int n)781000Sxc151355 ath_hal_delay(int n)
791000Sxc151355 {
801000Sxc151355 	drv_usecwait(n);
811000Sxc151355 }
821000Sxc151355 
831000Sxc151355 /*
841000Sxc151355  * ath_hal_malloc() and ath_hal_free() are called
851000Sxc151355  * within ath_hal.o. We must record the size of
861000Sxc151355  * the memory alloced, so ath_hal_free() can get
871000Sxc151355  * the size and then calls kmem_free().
881000Sxc151355  */
891000Sxc151355 void *
ath_hal_malloc(size_t size)901000Sxc151355 ath_hal_malloc(size_t size)
911000Sxc151355 {
921000Sxc151355 	void *p;
931000Sxc151355 	int i;
941000Sxc151355 
953147Sxc151355 	for (i = 0; i < ATH_MAX_HALMEM; i++) {
963147Sxc151355 		if (ath_halfix[i].p == NULL)
971000Sxc151355 			break;
981000Sxc151355 	}
993147Sxc151355 	if (i >= ATH_MAX_HALMEM) {
1001000Sxc151355 		ath_problem("ath: ath_hal_malloc(): too many malloc\n");
1011000Sxc151355 		return (NULL);
1021000Sxc151355 	}
1031000Sxc151355 	p = kmem_zalloc(size, KM_SLEEP);
1041000Sxc151355 	ath_halfix[i].p = p;
1051000Sxc151355 	ath_halfix[i].size = size;
1061000Sxc151355 	ATH_DEBUG((ATH_DBG_OSDEP, "ath: ath_hal_malloc(): "
1071000Sxc151355 	    "%d: p=%p, size=%d\n", i, p, size));
1081000Sxc151355 	return (p);
1091000Sxc151355 }
1101000Sxc151355 
1111000Sxc151355 void
ath_hal_free(void * p)1121000Sxc151355 ath_hal_free(void* p)
1131000Sxc151355 {
1141000Sxc151355 	int i;
1153147Sxc151355 	for (i = 0; i < ATH_MAX_HALMEM; i++) {
1161000Sxc151355 		if (ath_halfix[i].p == p)
1171000Sxc151355 			break;
1181000Sxc151355 	}
1193147Sxc151355 	if (i >= ATH_MAX_HALMEM) {
1201000Sxc151355 		ath_problem("ath: ath_hal_free(): no record for %p\n", p);
1211000Sxc151355 		return;
1221000Sxc151355 	}
1231000Sxc151355 	kmem_free(p, ath_halfix[i].size);
1243147Sxc151355 	ath_halfix[i].p = NULL;
1251000Sxc151355 	ATH_DEBUG((ATH_DBG_OSDEP, "ath: ath_hal_free(): %d: p=%p, size=%d\n",
1261000Sxc151355 	    i, p, ath_halfix[i].size));
1271000Sxc151355 }
1281000Sxc151355 
1291000Sxc151355 void *
ath_hal_memcpy(void * dst,const void * src,size_t n)1301000Sxc151355 ath_hal_memcpy(void *dst, const void *src, size_t n)
1311000Sxc151355 {
1321000Sxc151355 	bcopy(src, dst, n);
1331000Sxc151355 	return (dst);
1341000Sxc151355 }
1351000Sxc151355 
1361000Sxc151355 void
ath_hal_memzero(void * dst,size_t n)1371000Sxc151355 ath_hal_memzero(void *dst, size_t n)
1381000Sxc151355 {
1391000Sxc151355 	bzero(dst, n);
1401000Sxc151355 }
1411000Sxc151355 
1421000Sxc151355 void
ath_halfix_init(void)1431000Sxc151355 ath_halfix_init(void)
1441000Sxc151355 {
1451000Sxc151355 	int i;
1461000Sxc151355 
1473147Sxc151355 	for (i = 0; i < ATH_MAX_HALMEM; i++)
1483147Sxc151355 		ath_halfix[i].p = NULL;
1491000Sxc151355 }
1501000Sxc151355 
1511000Sxc151355 void
ath_halfix_finit(void)1521000Sxc151355 ath_halfix_finit(void)
1531000Sxc151355 {
1541000Sxc151355 	int i;
1551000Sxc151355 
1563147Sxc151355 	for (i = 0; i < ATH_MAX_HALMEM; i++)
1573147Sxc151355 		if (ath_halfix[i].p != NULL) {
1581000Sxc151355 			kmem_free(ath_halfix[i].p, ath_halfix[i].size);
1593147Sxc151355 			ATH_DEBUG((ATH_DBG_OSDEP, "ath_halfix: "
1603147Sxc151355 			    "Free %d: p=%x size=%d\n",
1613147Sxc151355 			    i, ath_halfix[i].p, ath_halfix[i].size));
1621000Sxc151355 		}
1631000Sxc151355 }
164