17a1306a7Sxc151355 /* 2*129d67acSlin wang - Sun Microsystems - Beijing China * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 37a1306a7Sxc151355 * Use is subject to license terms. 47a1306a7Sxc151355 */ 57a1306a7Sxc151355 67a1306a7Sxc151355 /* 77a1306a7Sxc151355 * Redistribution and use in source and binary forms, with or without 87a1306a7Sxc151355 * modification, are permitted provided that the following conditions 97a1306a7Sxc151355 * are met: 107a1306a7Sxc151355 * 1. Redistributions of source code must retain the above copyright 117a1306a7Sxc151355 * notice, this list of conditions and the following disclaimer, 127a1306a7Sxc151355 * without modification. 137a1306a7Sxc151355 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 147a1306a7Sxc151355 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 157a1306a7Sxc151355 * redistribution must be conditioned upon including a substantially 167a1306a7Sxc151355 * similar Disclaimer requirement for further binary redistribution. 177a1306a7Sxc151355 * 3. Neither the names of the above-listed copyright holders nor the names 187a1306a7Sxc151355 * of any contributors may be used to endorse or promote products derived 197a1306a7Sxc151355 * from this software without specific prior written permission. 207a1306a7Sxc151355 * 217a1306a7Sxc151355 * NO WARRANTY 227a1306a7Sxc151355 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 237a1306a7Sxc151355 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 247a1306a7Sxc151355 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 257a1306a7Sxc151355 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 267a1306a7Sxc151355 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 277a1306a7Sxc151355 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 287a1306a7Sxc151355 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 297a1306a7Sxc151355 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 307a1306a7Sxc151355 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 317a1306a7Sxc151355 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 327a1306a7Sxc151355 * THE POSSIBILITY OF SUCH DAMAGES. 337a1306a7Sxc151355 * 347a1306a7Sxc151355 */ 357a1306a7Sxc151355 367a1306a7Sxc151355 #include <sys/param.h> 377a1306a7Sxc151355 #include <sys/types.h> 387a1306a7Sxc151355 #include <sys/cmn_err.h> 397a1306a7Sxc151355 #include <sys/kmem.h> 407a1306a7Sxc151355 #include <sys/ddi.h> 417a1306a7Sxc151355 #include <sys/sunddi.h> 427a1306a7Sxc151355 #include <sys/varargs.h> 437a1306a7Sxc151355 #include "ath_hal.h" 447a1306a7Sxc151355 #include "ath_impl.h" 457a1306a7Sxc151355 467a1306a7Sxc151355 struct ath_halfix { 477a1306a7Sxc151355 void *p; 487a1306a7Sxc151355 size_t size; 497a1306a7Sxc151355 }; 507a1306a7Sxc151355 510ba2cbe9Sxc151355 #define ATH_MAX_HALMEM 1024 520ba2cbe9Sxc151355 static struct ath_halfix ath_halfix[ATH_MAX_HALMEM]; 537a1306a7Sxc151355 547a1306a7Sxc151355 /* HAL layer needs these definitions */ 557a1306a7Sxc151355 int ath_hal_dma_beacon_response_time = 2; /* in TU's */ 567a1306a7Sxc151355 int ath_hal_sw_beacon_response_time = 10; /* in TU's */ 577a1306a7Sxc151355 int ath_hal_additional_swba_backoff = 0; /* in TU's */ 587a1306a7Sxc151355 597a1306a7Sxc151355 /* 607a1306a7Sxc151355 * Print/log message support. 617a1306a7Sxc151355 */ 627a1306a7Sxc151355 637a1306a7Sxc151355 void 647a1306a7Sxc151355 ath_hal_printf(struct ath_hal *ah, const char *fmt, ...) 657a1306a7Sxc151355 { 667a1306a7Sxc151355 va_list ap; 677a1306a7Sxc151355 687a1306a7Sxc151355 _NOTE(ARGUNUSED(ah)) 697a1306a7Sxc151355 va_start(ap, fmt); 707a1306a7Sxc151355 vcmn_err(CE_CONT, fmt, ap); 717a1306a7Sxc151355 va_end(ap); 727a1306a7Sxc151355 } 737a1306a7Sxc151355 747a1306a7Sxc151355 /* 757a1306a7Sxc151355 * Delay n microseconds. 767a1306a7Sxc151355 */ 777a1306a7Sxc151355 void 787a1306a7Sxc151355 ath_hal_delay(int n) 797a1306a7Sxc151355 { 807a1306a7Sxc151355 drv_usecwait(n); 817a1306a7Sxc151355 } 827a1306a7Sxc151355 837a1306a7Sxc151355 /* 847a1306a7Sxc151355 * ath_hal_malloc() and ath_hal_free() are called 857a1306a7Sxc151355 * within ath_hal.o. We must record the size of 867a1306a7Sxc151355 * the memory alloced, so ath_hal_free() can get 877a1306a7Sxc151355 * the size and then calls kmem_free(). 887a1306a7Sxc151355 */ 897a1306a7Sxc151355 void * 907a1306a7Sxc151355 ath_hal_malloc(size_t size) 917a1306a7Sxc151355 { 927a1306a7Sxc151355 void *p; 937a1306a7Sxc151355 int i; 947a1306a7Sxc151355 950ba2cbe9Sxc151355 for (i = 0; i < ATH_MAX_HALMEM; i++) { 960ba2cbe9Sxc151355 if (ath_halfix[i].p == NULL) 977a1306a7Sxc151355 break; 987a1306a7Sxc151355 } 990ba2cbe9Sxc151355 if (i >= ATH_MAX_HALMEM) { 1007a1306a7Sxc151355 ath_problem("ath: ath_hal_malloc(): too many malloc\n"); 1017a1306a7Sxc151355 return (NULL); 1027a1306a7Sxc151355 } 1037a1306a7Sxc151355 p = kmem_zalloc(size, KM_SLEEP); 1047a1306a7Sxc151355 ath_halfix[i].p = p; 1057a1306a7Sxc151355 ath_halfix[i].size = size; 1067a1306a7Sxc151355 ATH_DEBUG((ATH_DBG_OSDEP, "ath: ath_hal_malloc(): " 1077a1306a7Sxc151355 "%d: p=%p, size=%d\n", i, p, size)); 1087a1306a7Sxc151355 return (p); 1097a1306a7Sxc151355 } 1107a1306a7Sxc151355 1117a1306a7Sxc151355 void 1127a1306a7Sxc151355 ath_hal_free(void* p) 1137a1306a7Sxc151355 { 1147a1306a7Sxc151355 int i; 1150ba2cbe9Sxc151355 for (i = 0; i < ATH_MAX_HALMEM; i++) { 1167a1306a7Sxc151355 if (ath_halfix[i].p == p) 1177a1306a7Sxc151355 break; 1187a1306a7Sxc151355 } 1190ba2cbe9Sxc151355 if (i >= ATH_MAX_HALMEM) { 1207a1306a7Sxc151355 ath_problem("ath: ath_hal_free(): no record for %p\n", p); 1217a1306a7Sxc151355 return; 1227a1306a7Sxc151355 } 1237a1306a7Sxc151355 kmem_free(p, ath_halfix[i].size); 1240ba2cbe9Sxc151355 ath_halfix[i].p = NULL; 1257a1306a7Sxc151355 ATH_DEBUG((ATH_DBG_OSDEP, "ath: ath_hal_free(): %d: p=%p, size=%d\n", 1267a1306a7Sxc151355 i, p, ath_halfix[i].size)); 1277a1306a7Sxc151355 } 1287a1306a7Sxc151355 1297a1306a7Sxc151355 void * 1307a1306a7Sxc151355 ath_hal_memcpy(void *dst, const void *src, size_t n) 1317a1306a7Sxc151355 { 1327a1306a7Sxc151355 bcopy(src, dst, n); 1337a1306a7Sxc151355 return (dst); 1347a1306a7Sxc151355 } 1357a1306a7Sxc151355 1367a1306a7Sxc151355 void 1377a1306a7Sxc151355 ath_hal_memzero(void *dst, size_t n) 1387a1306a7Sxc151355 { 1397a1306a7Sxc151355 bzero(dst, n); 1407a1306a7Sxc151355 } 1417a1306a7Sxc151355 1427a1306a7Sxc151355 void 1437a1306a7Sxc151355 ath_halfix_init(void) 1447a1306a7Sxc151355 { 1457a1306a7Sxc151355 int i; 1467a1306a7Sxc151355 1470ba2cbe9Sxc151355 for (i = 0; i < ATH_MAX_HALMEM; i++) 1480ba2cbe9Sxc151355 ath_halfix[i].p = NULL; 1497a1306a7Sxc151355 } 1507a1306a7Sxc151355 1517a1306a7Sxc151355 void 1527a1306a7Sxc151355 ath_halfix_finit(void) 1537a1306a7Sxc151355 { 1547a1306a7Sxc151355 int i; 1557a1306a7Sxc151355 1560ba2cbe9Sxc151355 for (i = 0; i < ATH_MAX_HALMEM; i++) 1570ba2cbe9Sxc151355 if (ath_halfix[i].p != NULL) { 1587a1306a7Sxc151355 kmem_free(ath_halfix[i].p, ath_halfix[i].size); 1590ba2cbe9Sxc151355 ATH_DEBUG((ATH_DBG_OSDEP, "ath_halfix: " 1600ba2cbe9Sxc151355 "Free %d: p=%x size=%d\n", 1610ba2cbe9Sxc151355 i, ath_halfix[i].p, ath_halfix[i].size)); 1627a1306a7Sxc151355 } 1637a1306a7Sxc151355 } 164