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