Home | History | Annotate | Line # | Download | only in ic
ah_osdep.c revision 1.4
      1  1.1       alc /*-
      2  1.1       alc  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
      3  1.1       alc  * All rights reserved.
      4  1.1       alc  *
      5  1.1       alc  * Redistribution and use in source and binary forms, with or without
      6  1.1       alc  * modification, are permitted provided that the following conditions
      7  1.1       alc  * are met:
      8  1.1       alc  * 1. Redistributions of source code must retain the above copyright
      9  1.1       alc  *    notice, this list of conditions and the following disclaimer,
     10  1.1       alc  *    without modification.
     11  1.1       alc  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     12  1.1       alc  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
     13  1.1       alc  *    redistribution must be conditioned upon including a substantially
     14  1.1       alc  *    similar Disclaimer requirement for further binary redistribution.
     15  1.1       alc  *
     16  1.1       alc  * NO WARRANTY
     17  1.1       alc  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     18  1.1       alc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     19  1.1       alc  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
     20  1.1       alc  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
     21  1.1       alc  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
     22  1.1       alc  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  1.1       alc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  1.1       alc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
     25  1.1       alc  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  1.1       alc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     27  1.1       alc  * THE POSSIBILITY OF SUCH DAMAGES.
     28  1.1       alc  *
     29  1.4  jmcneill  * $Id: ah_osdep.c,v 1.4 2011/02/20 03:55:18 jmcneill Exp $
     30  1.1       alc  */
     31  1.1       alc 
     32  1.1       alc #include <sys/cdefs.h>
     33  1.4  jmcneill __KERNEL_RCSID(0, "$NetBSD: ah_osdep.c,v 1.4 2011/02/20 03:55:18 jmcneill Exp $");
     34  1.1       alc 
     35  1.4  jmcneill #ifdef _KERNEL_OPT
     36  1.1       alc #include "opt_athhal.h"
     37  1.4  jmcneill #endif
     38  1.1       alc 
     39  1.1       alc #include <sys/param.h>
     40  1.1       alc #include <sys/systm.h>
     41  1.1       alc #include <sys/kernel.h>
     42  1.1       alc #include <sys/sysctl.h>
     43  1.1       alc #include <sys/malloc.h>
     44  1.1       alc #include <sys/proc.h>
     45  1.1       alc #include <sys/kauth.h>
     46  1.4  jmcneill #include <sys/module.h>
     47  1.1       alc 
     48  1.1       alc #include <machine/stdarg.h>
     49  1.1       alc 
     50  1.1       alc #include <net/if.h>
     51  1.1       alc #include <net/if_dl.h>
     52  1.1       alc #include <net/if_media.h>
     53  1.1       alc #include <net/if_arp.h>
     54  1.1       alc #include <net/if_ether.h>
     55  1.1       alc 
     56  1.1       alc #include <external/isc/atheros_hal/dist/ah.h>
     57  1.1       alc 
     58  1.1       alc extern	void ath_hal_printf(struct ath_hal *, const char*, ...)
     59  1.1       alc 		__printflike(2,3);
     60  1.1       alc extern	void ath_hal_vprintf(struct ath_hal *, const char*, va_list)
     61  1.1       alc 		__printflike(2, 0);
     62  1.1       alc extern	const char* ath_hal_ether_sprintf(const u_int8_t *mac);
     63  1.1       alc extern	void *ath_hal_malloc(size_t);
     64  1.1       alc extern	void ath_hal_free(void *);
     65  1.1       alc #ifdef ATHHAL_ASSERT
     66  1.1       alc extern	void ath_hal_assert_failed(const char* filename,
     67  1.1       alc 		int lineno, const char* msg);
     68  1.1       alc #endif
     69  1.1       alc #ifdef ATHHAL_DEBUG
     70  1.1       alc extern	void HALDEBUG(struct ath_hal *ah, const char* fmt, ...);
     71  1.1       alc extern	void HALDEBUGn(struct ath_hal *ah, u_int level, const char* fmt, ...);
     72  1.1       alc #endif /* ATHHAL_DEBUG */
     73  1.1       alc 
     74  1.1       alc #ifdef ATHHAL_DEBUG
     75  1.1       alc static	int ath_hal_debug = 0;
     76  1.1       alc #endif /* ATHHAL_DEBUG */
     77  1.1       alc 
     78  1.1       alc int	ath_hal_dma_beacon_response_time = 2;	/* in TU's */
     79  1.1       alc int	ath_hal_sw_beacon_response_time = 10;	/* in TU's */
     80  1.1       alc int	ath_hal_additional_swba_backoff = 0;	/* in TU's */
     81  1.1       alc 
     82  1.1       alc SYSCTL_SETUP(sysctl_ath_hal, "sysctl ath.hal subtree setup")
     83  1.1       alc {
     84  1.1       alc 	int rc;
     85  1.1       alc 	const struct sysctlnode *cnode, *rnode;
     86  1.1       alc 
     87  1.1       alc 	if ((rc = sysctl_createv(clog, 0, NULL, &rnode, CTLFLAG_PERMANENT,
     88  1.1       alc 	    CTLTYPE_NODE, "hw", NULL, NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0)
     89  1.1       alc 		goto err;
     90  1.1       alc 
     91  1.1       alc 	if ((rc = sysctl_createv(clog, 0, &rnode, &rnode, CTLFLAG_PERMANENT,
     92  1.1       alc 	    CTLTYPE_NODE, "ath", SYSCTL_DESCR("Atheros driver parameters"),
     93  1.1       alc 	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
     94  1.1       alc 		goto err;
     95  1.1       alc 
     96  1.1       alc 	if ((rc = sysctl_createv(clog, 0, &rnode, &rnode, CTLFLAG_PERMANENT,
     97  1.1       alc 	    CTLTYPE_NODE, "hal", SYSCTL_DESCR("Atheros HAL parameters"),
     98  1.1       alc 	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
     99  1.1       alc 		goto err;
    100  1.1       alc 
    101  1.1       alc #if 0
    102  1.1       alc 	if ((rc = sysctl_createv(clog, 0, &rnode, &cnode,
    103  1.1       alc 	    CTLFLAG_PERMANENT|CTLFLAG_READONLY, CTLTYPE_STRING, "version",
    104  1.1       alc 	    SYSCTL_DESCR("Atheros HAL version"), NULL, 0, &ath_hal_version, 0,
    105  1.1       alc 	    CTL_CREATE, CTL_EOL)) != 0)
    106  1.1       alc 		goto err;
    107  1.1       alc #endif
    108  1.1       alc 
    109  1.1       alc 	if ((rc = sysctl_createv(clog, 0, &rnode, &cnode,
    110  1.1       alc 	    CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "dma_brt",
    111  1.1       alc 	    SYSCTL_DESCR("Atheros HAL DMA beacon response time"), NULL, 0,
    112  1.1       alc 	    &ath_hal_dma_beacon_response_time, 0, CTL_CREATE, CTL_EOL)) != 0)
    113  1.1       alc 		goto err;
    114  1.1       alc 
    115  1.1       alc 	if ((rc = sysctl_createv(clog, 0, &rnode, &cnode,
    116  1.1       alc 	    CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "sw_brt",
    117  1.1       alc 	    SYSCTL_DESCR("Atheros HAL software beacon response time"), NULL, 0,
    118  1.1       alc 	    &ath_hal_sw_beacon_response_time, 0, CTL_CREATE, CTL_EOL)) != 0)
    119  1.1       alc 		goto err;
    120  1.1       alc 
    121  1.1       alc 	if ((rc = sysctl_createv(clog, 0, &rnode, &cnode,
    122  1.1       alc 	    CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "swba_backoff",
    123  1.1       alc 	    SYSCTL_DESCR("Atheros HAL additional SWBA backoff time"), NULL, 0,
    124  1.1       alc 	    &ath_hal_additional_swba_backoff, 0, CTL_CREATE, CTL_EOL)) != 0)
    125  1.1       alc 		goto err;
    126  1.1       alc 
    127  1.1       alc #ifdef ATHHAL_DEBUG
    128  1.1       alc 	if ((rc = sysctl_createv(clog, 0, &rnode, &cnode,
    129  1.1       alc 	    CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "debug",
    130  1.1       alc 	    SYSCTL_DESCR("Atheros HAL debugging printfs"), NULL, 0,
    131  1.1       alc 	    &ath_hal_debug, 0, CTL_CREATE, CTL_EOL)) != 0)
    132  1.1       alc 		goto err;
    133  1.1       alc #endif /* ATHHAL_DEBUG */
    134  1.1       alc 	return;
    135  1.1       alc err:
    136  1.1       alc 	printf("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
    137  1.1       alc }
    138  1.1       alc 
    139  1.1       alc MALLOC_DEFINE(M_ATH_HAL, "ath_hal", "ath hal data");
    140  1.1       alc 
    141  1.1       alc void*
    142  1.1       alc ath_hal_malloc(size_t size)
    143  1.1       alc {
    144  1.2    martin 	return malloc(size, M_ATH_HAL, M_NOWAIT | M_ZERO);
    145  1.1       alc }
    146  1.1       alc 
    147  1.1       alc void
    148  1.1       alc ath_hal_free(void* p)
    149  1.1       alc {
    150  1.1       alc 	free(p, M_ATH_HAL);
    151  1.1       alc }
    152  1.1       alc 
    153  1.1       alc void
    154  1.1       alc ath_hal_vprintf(struct ath_hal *ah, const char* fmt, va_list ap)
    155  1.1       alc {
    156  1.1       alc 	vprintf(fmt, ap);
    157  1.1       alc }
    158  1.1       alc 
    159  1.1       alc void
    160  1.1       alc ath_hal_printf(struct ath_hal *ah, const char* fmt, ...)
    161  1.1       alc {
    162  1.1       alc 	va_list ap;
    163  1.1       alc 	va_start(ap, fmt);
    164  1.1       alc 	ath_hal_vprintf(ah, fmt, ap);
    165  1.1       alc 	va_end(ap);
    166  1.1       alc }
    167  1.1       alc 
    168  1.1       alc const char*
    169  1.1       alc ath_hal_ether_sprintf(const u_int8_t *mac)
    170  1.1       alc {
    171  1.2    martin 	return ether_sprintf(mac);
    172  1.1       alc }
    173  1.1       alc 
    174  1.1       alc #ifdef ATHHAL_DEBUG
    175  1.1       alc void
    176  1.1       alc HALDEBUG(struct ath_hal *ah, const char* fmt, ...)
    177  1.1       alc {
    178  1.1       alc 	if (ath_hal_debug) {
    179  1.1       alc 		va_list ap;
    180  1.1       alc 		va_start(ap, fmt);
    181  1.1       alc 		ath_hal_vprintf(ah, fmt, ap);
    182  1.1       alc 		va_end(ap);
    183  1.1       alc 	}
    184  1.1       alc }
    185  1.1       alc 
    186  1.1       alc void
    187  1.1       alc HALDEBUGn(struct ath_hal *ah, u_int level, const char* fmt, ...)
    188  1.1       alc {
    189  1.1       alc 	if (ath_hal_debug >= level) {
    190  1.1       alc 		va_list ap;
    191  1.1       alc 		va_start(ap, fmt);
    192  1.1       alc 		ath_hal_vprintf(ah, fmt, ap);
    193  1.1       alc 		va_end(ap);
    194  1.1       alc 	}
    195  1.1       alc }
    196  1.1       alc #endif /* ATHHAL_DEBUG */
    197  1.1       alc 
    198  1.1       alc #ifdef ATHHAL_DEBUG_ALQ
    199  1.1       alc /*
    200  1.1       alc  * ALQ register tracing support.
    201  1.1       alc  *
    202  1.1       alc  * Setting hw.ath.hal.alq=1 enables tracing of all register reads and
    203  1.1       alc  * writes to the file /tmp/ath_hal.log.  The file format is a simple
    204  1.1       alc  * fixed-size array of records.  When done logging set hw.ath.hal.alq=0
    205  1.1       alc  * and then decode the file with the arcode program (that is part of the
    206  1.1       alc  * HAL).  If you start+stop tracing the data will be appended to an
    207  1.1       alc  * existing file.
    208  1.1       alc  *
    209  1.1       alc  * NB: doesn't handle multiple devices properly; only one DEVICE record
    210  1.1       alc  *     is emitted and the different devices are not identified.
    211  1.1       alc  */
    212  1.1       alc #include <sys/alq.h>
    213  1.1       alc #include <sys/pcpu.h>
    214  1.1       alc 
    215  1.1       alc static	struct alq *ath_hal_alq;
    216  1.1       alc static	int ath_hal_alq_emitdev;	/* need to emit DEVICE record */
    217  1.1       alc static	u_int ath_hal_alq_lost;		/* count of lost records */
    218  1.1       alc static	const char *ath_hal_logfile = "/tmp/ath_hal.log";
    219  1.1       alc static	u_int ath_hal_alq_qsize = 64*1024;
    220  1.1       alc 
    221  1.1       alc static int
    222  1.1       alc ath_hal_setlogging(int enable)
    223  1.1       alc {
    224  1.1       alc 	int error;
    225  1.1       alc 
    226  1.1       alc 	if (enable) {
    227  1.1       alc 		error = kauth_authorize_network(curlwp->l_cred,
    228  1.1       alc 		    KAUTH_NETWORK_INTERFACE,
    229  1.1       alc 		    KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, NULL, NULL, NULL);
    230  1.1       alc 		if (error == 0) {
    231  1.1       alc 			error = alq_open(&ath_hal_alq, ath_hal_logfile,
    232  1.1       alc 				curproc->p_ucred,
    233  1.1       alc 				sizeof (struct athregrec), ath_hal_alq_qsize);
    234  1.1       alc 			ath_hal_alq_lost = 0;
    235  1.1       alc 			ath_hal_alq_emitdev = 1;
    236  1.1       alc 			printf("ath_hal: logging to %s enabled\n",
    237  1.1       alc 				ath_hal_logfile);
    238  1.1       alc 		}
    239  1.1       alc 	} else {
    240  1.1       alc 		if (ath_hal_alq)
    241  1.1       alc 			alq_close(ath_hal_alq);
    242  1.1       alc 		ath_hal_alq = NULL;
    243  1.1       alc 		printf("ath_hal: logging disabled\n");
    244  1.1       alc 		error = 0;
    245  1.1       alc 	}
    246  1.1       alc 	return (error);
    247  1.1       alc }
    248  1.1       alc 
    249  1.1       alc static int
    250  1.1       alc sysctl_hw_ath_hal_log(SYSCTL_HANDLER_ARGS)
    251  1.1       alc {
    252  1.1       alc 	int error, enable;
    253  1.1       alc 
    254  1.1       alc 	enable = (ath_hal_alq != NULL);
    255  1.1       alc         error = sysctl_handle_int(oidp, &enable, 0, req);
    256  1.1       alc         if (error || !req->newptr)
    257  1.1       alc                 return (error);
    258  1.1       alc 	else
    259  1.1       alc 		return (ath_hal_setlogging(enable));
    260  1.1       alc }
    261  1.1       alc SYSCTL_PROC(_hw_ath_hal, OID_AUTO, alq, CTLTYPE_INT|CTLFLAG_RW,
    262  1.1       alc 	0, 0, sysctl_hw_ath_hal_log, "I", "Enable HAL register logging");
    263  1.1       alc SYSCTL_INT(_hw_ath_hal, OID_AUTO, alq_size, CTLFLAG_RW,
    264  1.1       alc 	&ath_hal_alq_qsize, 0, "In-memory log size (#records)");
    265  1.1       alc SYSCTL_INT(_hw_ath_hal, OID_AUTO, alq_lost, CTLFLAG_RW,
    266  1.1       alc 	&ath_hal_alq_lost, 0, "Register operations not logged");
    267  1.1       alc 
    268  1.1       alc static struct ale *
    269  1.1       alc ath_hal_alq_get(struct ath_hal *ah)
    270  1.1       alc {
    271  1.1       alc 	struct ale *ale;
    272  1.1       alc 
    273  1.1       alc 	if (ath_hal_alq_emitdev) {
    274  1.1       alc 		ale = alq_get(ath_hal_alq, ALQ_NOWAIT);
    275  1.1       alc 		if (ale) {
    276  1.1       alc 			struct athregrec *r =
    277  1.1       alc 				(struct athregrec *) ale->ae_data;
    278  1.1       alc 			r->op = OP_DEVICE;
    279  1.1       alc 			r->reg = 0;
    280  1.1       alc 			r->val = ah->ah_devid;
    281  1.1       alc 			alq_post(ath_hal_alq, ale);
    282  1.1       alc 			ath_hal_alq_emitdev = 0;
    283  1.1       alc 		} else
    284  1.1       alc 			ath_hal_alq_lost++;
    285  1.1       alc 	}
    286  1.1       alc 	ale = alq_get(ath_hal_alq, ALQ_NOWAIT);
    287  1.1       alc 	if (!ale)
    288  1.1       alc 		ath_hal_alq_lost++;
    289  1.1       alc 	return ale;
    290  1.1       alc }
    291  1.1       alc 
    292  1.1       alc void
    293  1.1       alc ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val)
    294  1.1       alc {
    295  1.1       alc 	bus_space_tag_t t = BUSTAG(ah);
    296  1.1       alc 
    297  1.1       alc 	if (ath_hal_alq) {
    298  1.1       alc 		struct ale *ale = ath_hal_alq_get(ah);
    299  1.1       alc 		if (ale) {
    300  1.1       alc 			struct athregrec *r = (struct athregrec *) ale->ae_data;
    301  1.1       alc 			r->op = OP_WRITE;
    302  1.1       alc 			r->reg = reg;
    303  1.1       alc 			r->val = val;
    304  1.1       alc 			alq_post(ath_hal_alq, ale);
    305  1.1       alc 		}
    306  1.1       alc 	}
    307  1.1       alc #if _BYTE_ORDER == _BIG_ENDIAN
    308  1.1       alc 	if (reg >= 0x4000 && reg < 0x5000)
    309  1.1       alc 		bus_space_write_4(t, h, reg, val);
    310  1.1       alc 	else
    311  1.1       alc #endif
    312  1.1       alc 		bus_space_write_stream_4(t, h, reg, val);
    313  1.1       alc }
    314  1.1       alc 
    315  1.1       alc u_int32_t
    316  1.1       alc ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg)
    317  1.1       alc {
    318  1.1       alc 	u_int32_t val;
    319  1.1       alc 	bus_space_handle_t h = BUSHANDLE(ah);
    320  1.1       alc 	bus_space_tag_t t = BUSTAG(ah);
    321  1.1       alc 
    322  1.1       alc #if _BYTE_ORDER == _BIG_ENDIAN
    323  1.1       alc 	if (reg >= 0x4000 && reg < 0x5000)
    324  1.1       alc 		val = bus_space_read_4(t, h, reg);
    325  1.1       alc 	else
    326  1.1       alc #endif
    327  1.1       alc 		val = bus_space_read_stream_4(t, h, reg);
    328  1.1       alc 
    329  1.1       alc 	if (ath_hal_alq) {
    330  1.1       alc 		struct ale *ale = ath_hal_alq_get(ah);
    331  1.1       alc 		if (ale) {
    332  1.1       alc 			struct athregrec *r = (struct athregrec *) ale->ae_data;
    333  1.1       alc 			r->op = OP_READ;
    334  1.1       alc 			r->reg = reg;
    335  1.1       alc 			r->val = val;
    336  1.1       alc 			alq_post(ath_hal_alq, ale);
    337  1.1       alc 		}
    338  1.1       alc 	}
    339  1.1       alc 
    340  1.1       alc 	return val;
    341  1.1       alc }
    342  1.1       alc 
    343  1.1       alc void
    344  1.1       alc OS_MARK(struct ath_hal *ah, u_int id, u_int32_t v)
    345  1.1       alc {
    346  1.1       alc 	if (ath_hal_alq) {
    347  1.1       alc 		struct ale *ale = ath_hal_alq_get(ah);
    348  1.2    martin 
    349  1.1       alc 		if (ale) {
    350  1.1       alc 			struct athregrec *r = (struct athregrec *) ale->ae_data;
    351  1.1       alc 			r->op = OP_MARK;
    352  1.1       alc 			r->reg = id;
    353  1.1       alc 			r->val = v;
    354  1.1       alc 			alq_post(ath_hal_alq, ale);
    355  1.1       alc 		}
    356  1.1       alc 	}
    357  1.1       alc }
    358  1.1       alc #elif defined(ATHHAL_DEBUG) || defined(AH_REGOPS_FUNC)
    359  1.1       alc /*
    360  1.1       alc  * Memory-mapped device register read/write.  These are here
    361  1.1       alc  * as routines when debugging support is enabled and/or when
    362  1.1       alc  * explicitly configured to use function calls.  The latter is
    363  1.1       alc  * for architectures that might need to do something before
    364  1.1       alc  * referencing memory (e.g. remap an i/o window).
    365  1.1       alc  *
    366  1.1       alc  * NB: see the comments in ah_osdep.h about byte-swapping register
    367  1.1       alc  *     reads and writes to understand what's going on below.
    368  1.1       alc  */
    369  1.1       alc 
    370  1.1       alc void
    371  1.1       alc ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val)
    372  1.1       alc {
    373  1.1       alc 	bus_space_handle_t h = BUSHANDLE(ah);
    374  1.1       alc 	bus_space_tag_t t = BUSTAG(ah);
    375  1.1       alc 
    376  1.1       alc #if _BYTE_ORDER == _BIG_ENDIAN
    377  1.1       alc 	if (reg >= 0x4000 && reg < 0x5000)
    378  1.1       alc 		bus_space_write_4(t, h, reg, val);
    379  1.1       alc 	else
    380  1.1       alc #endif
    381  1.1       alc 		bus_space_write_stream_4(t, h, reg, val);
    382  1.1       alc }
    383  1.1       alc 
    384  1.1       alc u_int32_t
    385  1.1       alc ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg)
    386  1.1       alc {
    387  1.1       alc 	bus_space_handle_t h = BUSHANDLE(ah);
    388  1.1       alc 	bus_space_tag_t t = BUSTAG(ah);
    389  1.1       alc 	uint32_t ret;
    390  1.1       alc 
    391  1.1       alc #if _BYTE_ORDER == _BIG_ENDIAN
    392  1.1       alc 	if (reg >= 0x4000 && reg < 0x5000)
    393  1.1       alc 		ret = bus_space_read_4(t, h, reg);
    394  1.1       alc 	else
    395  1.1       alc #endif
    396  1.1       alc 		ret = bus_space_read_stream_4(t, h, reg);
    397  1.1       alc 
    398  1.1       alc 	return ret;
    399  1.1       alc }
    400  1.1       alc #endif /* ATHHAL_DEBUG || AH_REGOPS_FUNC */
    401  1.1       alc 
    402  1.1       alc #ifdef ATHHAL_ASSERT
    403  1.1       alc void
    404  1.1       alc ath_hal_assert_failed(const char* filename, int lineno, const char *msg)
    405  1.1       alc {
    406  1.1       alc 	printf("Atheros HAL assertion failure: %s: line %u: %s\n",
    407  1.1       alc 		filename, lineno, msg);
    408  1.1       alc 	panic("ath_hal_assert");
    409  1.1       alc }
    410  1.1       alc #endif /* ATHHAL_ASSERT */
    411  1.1       alc 
    412  1.1       alc /*
    413  1.1       alc  * Delay n microseconds.
    414  1.1       alc  */
    415  1.1       alc void
    416  1.1       alc ath_hal_delay(int n)
    417  1.1       alc {
    418  1.1       alc 	DELAY(n);
    419  1.1       alc }
    420  1.1       alc 
    421  1.1       alc u_int32_t
    422  1.1       alc ath_hal_getuptime(struct ath_hal *ah)
    423  1.1       alc {
    424  1.1       alc 	struct bintime bt;
    425  1.1       alc 	uint32_t ret;
    426  1.1       alc 	getbinuptime(&bt);
    427  1.1       alc 	ret = (bt.sec * 1000) +
    428  1.1       alc 		(((uint64_t)1000 * (uint32_t)(bt.frac >> 32)) >> 32);
    429  1.1       alc 	return ret;
    430  1.1       alc }
    431  1.1       alc 
    432  1.1       alc void
    433  1.1       alc ath_hal_memzero(void *dst, size_t n)
    434  1.1       alc {
    435  1.1       alc 	(void)memset(dst, 0, n);
    436  1.1       alc }
    437  1.1       alc 
    438  1.1       alc void *
    439  1.1       alc ath_hal_memcpy(void *dst, const void *src, size_t n)
    440  1.1       alc {
    441  1.2    martin 	return memcpy(dst, src, n);
    442  1.1       alc }
    443  1.4  jmcneill 
    444  1.4  jmcneill MODULE(MODULE_CLASS_MISC, ath_hal, NULL);
    445  1.4  jmcneill 
    446  1.4  jmcneill static int
    447  1.4  jmcneill ath_hal_modcmd(modcmd_t cmd, void *opaque)
    448  1.4  jmcneill {
    449  1.4  jmcneill 	switch (cmd) {
    450  1.4  jmcneill 	case MODULE_CMD_INIT:
    451  1.4  jmcneill 	case MODULE_CMD_FINI:
    452  1.4  jmcneill 		return 0;
    453  1.4  jmcneill 	default:
    454  1.4  jmcneill 		return ENOTTY;
    455  1.4  jmcneill 	}
    456  1.4  jmcneill }
    457