2006-09-18 16:49:15 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2008-04-20 20:35:46 +00:00
|
|
|
* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
|
2006-09-18 16:49:15 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* without modification.
|
|
|
|
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
|
|
|
|
* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
|
|
|
|
* redistribution must be conditioned upon including a substantially
|
|
|
|
* similar Disclaimer requirement for further binary redistribution.
|
|
|
|
*
|
|
|
|
* NO WARRANTY
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
|
|
|
|
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
|
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGES.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
#include "opt_ah.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/proc.h>
|
2012-04-04 20:46:20 +00:00
|
|
|
#include <sys/pcpu.h>
|
2011-11-09 22:39:44 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
[ath] [ath_hal] (etc, etc) - begin the task of re-modularising the HAL.
In the deep past, when this code compiled as a binary module, ath_hal
built as a module. This allowed custom, smaller HAL modules to be built.
This was especially beneficial for small embedded platforms where you
didn't require /everything/ just to run.
However, sometime around the HAL opening fanfare, the HAL landed here
as one big driver+HAL thing, and a lot of the (dirty) infrastructure
(ie, #ifdef AH_SUPPORT_XXX) to build specific subsets of the HAL went away.
This was retained in sys/conf/files as "ath_hal_XXX" but it wasn't
really floated up to the modules themselves.
I'm now in a position where for the reaaaaaly embedded boards (both the
really old and the last couple generation of QCA MIPS boards) having a
cut down HAL module and driver loaded at runtime is /actually/ beneficial.
This reduces the kernel size down by quite a bit. The MIPS modules look
like this:
adrian@gertrude:~/work/freebsd/head-embedded/src % ls -l ../root/mips_ap/boot/kernel.CARAMBOLA2/ath*ko
-r-xr-xr-x 1 adrian adrian 5076 May 23 23:45 ../root/mips_ap/boot/kernel.CARAMBOLA2/ath_dfs.ko
-r-xr-xr-x 1 adrian adrian 100588 May 23 23:45 ../root/mips_ap/boot/kernel.CARAMBOLA2/ath_hal.ko
-r-xr-xr-x 1 adrian adrian 627324 May 23 23:45 ../root/mips_ap/boot/kernel.CARAMBOLA2/ath_hal_ar9300.ko
-r-xr-xr-x 1 adrian adrian 314588 May 23 23:45 ../root/mips_ap/boot/kernel.CARAMBOLA2/ath_main.ko
-r-xr-xr-x 1 adrian adrian 23472 May 23 23:45 ../root/mips_ap/boot/kernel.CARAMBOLA2/ath_rate.ko
And the x86 versions, like this:
root@gertrude:/home/adrian # ls -l /boot/kernel/ath*ko
-r-xr-xr-x 1 root wheel 36632 May 24 18:32 /boot/kernel/ath_dfs.ko
-r-xr-xr-x 1 root wheel 134440 May 24 18:32 /boot/kernel/ath_hal.ko
-r-xr-xr-x 1 root wheel 82320 May 24 18:32 /boot/kernel/ath_hal_ar5210.ko
-r-xr-xr-x 1 root wheel 104976 May 24 18:32 /boot/kernel/ath_hal_ar5211.ko
-r-xr-xr-x 1 root wheel 236144 May 24 18:32 /boot/kernel/ath_hal_ar5212.ko
-r-xr-xr-x 1 root wheel 336104 May 24 18:32 /boot/kernel/ath_hal_ar5416.ko
-r-xr-xr-x 1 root wheel 598336 May 24 18:32 /boot/kernel/ath_hal_ar9300.ko
-r-xr-xr-x 1 root wheel 406144 May 24 18:32 /boot/kernel/ath_main.ko
-r-xr-xr-x 1 root wheel 55352 May 24 18:32 /boot/kernel/ath_rate.ko
.. so you can see, not building the whole HAL can save quite a bit.
For example, if you don't need AR9300 support, you can actually avoid
wasting half a megabyte of RAM. On embedded routers this is quite a
big deal.
The AR9300 HAL can be later further shrunk because, hilariously,
it indeed supports AH_SUPPORT_<xxx> for optionally adding chipset support.
(I'll chase that down later as it's quite a big savings if you're only
building for a single embedded target.)
So:
* Create a very hackish way to load/unload HAL modules
* Create module metadata for each HAL subtype - ah_osdep_arXXXX.c
* Create module metadata for ath_rate and ath_dfs (bluetooth is
currently just built as part of it)
* .. yes, this means we could actually build multiple rate control
modules and pick one at load time, but I'd rather just glue this
into net80211's rate control code. Oh well, baby steps.
* Main driver is now "ath_main"
* Create an "if_ath" module that does what the ye olde one did -
load PCI glue, main driver, HAL and all child modules.
In this way, if you have "if_ath_load=YES" in /boot/modules.conf
it will load everything the old way and stuff should still work.
* For module autoloading purposes, I actually /did/ fix up
the name of the modules in if_ath_pci and if_ath_ahb.
If you want to selectively load things (eg on ye cheape ARM/MIPS platforms
where RAM is at a premium) you should:
* load ath_hal
* load the chip modules in question
* load ath_rate, ath_dfs
* load ath_main
* load if_ath_pci and/or if_ath_ahb depending upon your particular
bus bind type - this is where probe/attach is done.
TODO:
* AR5312 module and associated pieces - yes, we have the SoC side support
now so the wifi support would be good to "round things out";
* Just nuke AH_SUPPORT_AR5416 for now and always bloat the packet
structures; this'll simplify other things.
* Should add a simple refcnt thing to the HAL RF/chip modules so you
can't unload them whilst you're using them.
* Manpage updates, UPDATING if appropriate, etc.
2017-05-25 04:18:46 +00:00
|
|
|
#include <sys/conf.h>
|
2006-09-18 16:49:15 +00:00
|
|
|
|
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
|
|
|
#include <net/ethernet.h> /* XXX for ether_sprintf */
|
|
|
|
|
2008-12-01 16:53:01 +00:00
|
|
|
#include <dev/ath/ath_hal/ah.h>
|
2012-07-01 02:34:32 +00:00
|
|
|
#include <dev/ath/ath_hal/ah_debug.h>
|
2006-09-18 16:49:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* WiSoC boards overload the bus tag with information about the
|
|
|
|
* board layout. We must extract the bus space tag from that
|
|
|
|
* indirect structure. For everyone else the tag is passed in
|
|
|
|
* directly.
|
|
|
|
* XXX cache indirect ref privately
|
|
|
|
*/
|
|
|
|
#ifdef AH_SUPPORT_AR5312
|
|
|
|
#define BUSTAG(ah) \
|
|
|
|
((bus_space_tag_t) ((struct ar531x_config *)((ah)->ah_st))->tag)
|
|
|
|
#else
|
2008-12-01 16:53:01 +00:00
|
|
|
#define BUSTAG(ah) ((ah)->ah_st)
|
2006-09-18 16:49:15 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-09 22:39:44 +00:00
|
|
|
/*
|
|
|
|
* This lock is used to seralise register access for chips which have
|
|
|
|
* problems w/ SMP CPUs issuing concurrent PCI transactions.
|
|
|
|
*
|
|
|
|
* XXX This is a global lock for now; it should be pushed to
|
|
|
|
* a per-device lock in some platform-independent fashion.
|
|
|
|
*/
|
|
|
|
struct mtx ah_regser_mtx;
|
|
|
|
MTX_SYSINIT(ah_regser, &ah_regser_mtx, "Atheros register access mutex",
|
|
|
|
MTX_SPIN);
|
|
|
|
|
2006-09-18 16:49:15 +00:00
|
|
|
extern void ath_hal_printf(struct ath_hal *, const char*, ...)
|
|
|
|
__printflike(2,3);
|
|
|
|
extern void ath_hal_vprintf(struct ath_hal *, const char*, __va_list)
|
|
|
|
__printflike(2, 0);
|
|
|
|
extern const char* ath_hal_ether_sprintf(const u_int8_t *mac);
|
|
|
|
extern void *ath_hal_malloc(size_t);
|
|
|
|
extern void ath_hal_free(void *);
|
|
|
|
#ifdef AH_ASSERT
|
|
|
|
extern void ath_hal_assert_failed(const char* filename,
|
|
|
|
int lineno, const char* msg);
|
|
|
|
#endif
|
|
|
|
#ifdef AH_DEBUG
|
2011-03-05 21:20:18 +00:00
|
|
|
extern void DO_HALDEBUG(struct ath_hal *ah, u_int mask, const char* fmt, ...);
|
2006-09-18 16:49:15 +00:00
|
|
|
#endif /* AH_DEBUG */
|
|
|
|
|
|
|
|
/* NB: put this here instead of the driver to avoid circular references */
|
|
|
|
SYSCTL_NODE(_hw, OID_AUTO, ath, CTLFLAG_RD, 0, "Atheros driver parameters");
|
2011-11-07 15:43:11 +00:00
|
|
|
static SYSCTL_NODE(_hw_ath, OID_AUTO, hal, CTLFLAG_RD, 0,
|
|
|
|
"Atheros HAL parameters");
|
2011-06-25 00:34:40 +00:00
|
|
|
|
|
|
|
#ifdef AH_DEBUG
|
|
|
|
int ath_hal_debug = 0;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_INT(_hw_ath_hal, OID_AUTO, debug, CTLFLAG_RWTUN, &ath_hal_debug,
|
2011-06-25 00:34:40 +00:00
|
|
|
0, "Atheros HAL debugging printfs");
|
|
|
|
#endif /* AH_DEBUG */
|
2006-09-18 16:49:15 +00:00
|
|
|
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_ATH_HAL, "ath_hal", "ath hal data");
|
2006-09-18 16:49:15 +00:00
|
|
|
|
|
|
|
void*
|
|
|
|
ath_hal_malloc(size_t size)
|
|
|
|
{
|
|
|
|
return malloc(size, M_ATH_HAL, M_NOWAIT | M_ZERO);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ath_hal_free(void* p)
|
|
|
|
{
|
2009-09-07 16:18:16 +00:00
|
|
|
free(p, M_ATH_HAL);
|
2006-09-18 16:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ath_hal_vprintf(struct ath_hal *ah, const char* fmt, va_list ap)
|
|
|
|
{
|
|
|
|
vprintf(fmt, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ath_hal_printf(struct ath_hal *ah, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
ath_hal_vprintf(ah, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
ath_hal_ether_sprintf(const u_int8_t *mac)
|
|
|
|
{
|
|
|
|
return ether_sprintf(mac);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef AH_DEBUG
|
2011-05-17 16:30:34 +00:00
|
|
|
|
2014-04-09 03:51:05 +00:00
|
|
|
/*
|
|
|
|
* XXX This is highly relevant only for the AR5416 and later
|
|
|
|
* PCI/PCIe NICs. It'll need adjustment for other hardware
|
|
|
|
* variations.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ath_hal_reg_whilst_asleep(struct ath_hal *ah, uint32_t reg)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (reg >= 0x4000 && reg < 0x5000)
|
|
|
|
return (1);
|
|
|
|
if (reg >= 0x6000 && reg < 0x7000)
|
|
|
|
return (1);
|
|
|
|
if (reg >= 0x7000 && reg < 0x8000)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-10-27 18:30:33 +00:00
|
|
|
void
|
2011-03-05 21:20:18 +00:00
|
|
|
DO_HALDEBUG(struct ath_hal *ah, u_int mask, const char* fmt, ...)
|
2008-10-27 18:30:33 +00:00
|
|
|
{
|
2011-07-14 23:30:30 +00:00
|
|
|
if ((mask == HAL_DEBUG_UNMASKABLE) ||
|
2011-09-30 05:17:57 +00:00
|
|
|
(ah != NULL && ah->ah_config.ah_debug & mask) ||
|
2011-07-14 23:30:30 +00:00
|
|
|
(ath_hal_debug & mask)) {
|
2008-10-27 18:30:33 +00:00
|
|
|
__va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
ath_hal_vprintf(ah, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
2011-05-17 16:30:34 +00:00
|
|
|
#undef HAL_DEBUG_UNMASKABLE
|
2006-09-18 16:49:15 +00:00
|
|
|
#endif /* AH_DEBUG */
|
|
|
|
|
|
|
|
#ifdef AH_DEBUG_ALQ
|
|
|
|
/*
|
|
|
|
* ALQ register tracing support.
|
|
|
|
*
|
|
|
|
* Setting hw.ath.hal.alq=1 enables tracing of all register reads and
|
|
|
|
* writes to the file /tmp/ath_hal.log. The file format is a simple
|
|
|
|
* fixed-size array of records. When done logging set hw.ath.hal.alq=0
|
|
|
|
* and then decode the file with the arcode program (that is part of the
|
|
|
|
* HAL). If you start+stop tracing the data will be appended to an
|
|
|
|
* existing file.
|
|
|
|
*
|
|
|
|
* NB: doesn't handle multiple devices properly; only one DEVICE record
|
|
|
|
* is emitted and the different devices are not identified.
|
|
|
|
*/
|
|
|
|
#include <sys/alq.h>
|
|
|
|
#include <sys/pcpu.h>
|
2008-12-01 16:53:01 +00:00
|
|
|
#include <dev/ath/ath_hal/ah_decode.h>
|
2006-09-18 16:49:15 +00:00
|
|
|
|
|
|
|
static struct alq *ath_hal_alq;
|
|
|
|
static int ath_hal_alq_emitdev; /* need to emit DEVICE record */
|
|
|
|
static u_int ath_hal_alq_lost; /* count of lost records */
|
2011-04-05 16:14:54 +00:00
|
|
|
static char ath_hal_logfile[MAXPATHLEN] = "/tmp/ath_hal.log";
|
|
|
|
|
|
|
|
SYSCTL_STRING(_hw_ath_hal, OID_AUTO, alq_logfile, CTLFLAG_RW,
|
|
|
|
&ath_hal_logfile, sizeof(kernelname), "Name of ALQ logfile");
|
|
|
|
|
2006-09-18 16:49:15 +00:00
|
|
|
static u_int ath_hal_alq_qsize = 64*1024;
|
|
|
|
|
|
|
|
static int
|
|
|
|
ath_hal_setlogging(int enable)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (enable) {
|
2007-04-10 15:48:45 +00:00
|
|
|
error = alq_open(&ath_hal_alq, ath_hal_logfile,
|
|
|
|
curthread->td_ucred, ALQ_DEFAULT_CMODE,
|
|
|
|
sizeof (struct athregrec), ath_hal_alq_qsize);
|
|
|
|
ath_hal_alq_lost = 0;
|
|
|
|
ath_hal_alq_emitdev = 1;
|
|
|
|
printf("ath_hal: logging to %s enabled\n",
|
|
|
|
ath_hal_logfile);
|
2006-09-18 16:49:15 +00:00
|
|
|
} else {
|
|
|
|
if (ath_hal_alq)
|
|
|
|
alq_close(ath_hal_alq);
|
|
|
|
ath_hal_alq = NULL;
|
|
|
|
printf("ath_hal: logging disabled\n");
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_hw_ath_hal_log(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error, enable;
|
|
|
|
|
|
|
|
enable = (ath_hal_alq != NULL);
|
|
|
|
error = sysctl_handle_int(oidp, &enable, 0, req);
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
else
|
|
|
|
return (ath_hal_setlogging(enable));
|
|
|
|
}
|
|
|
|
SYSCTL_PROC(_hw_ath_hal, OID_AUTO, alq, CTLTYPE_INT|CTLFLAG_RW,
|
|
|
|
0, 0, sysctl_hw_ath_hal_log, "I", "Enable HAL register logging");
|
|
|
|
SYSCTL_INT(_hw_ath_hal, OID_AUTO, alq_size, CTLFLAG_RW,
|
|
|
|
&ath_hal_alq_qsize, 0, "In-memory log size (#records)");
|
|
|
|
SYSCTL_INT(_hw_ath_hal, OID_AUTO, alq_lost, CTLFLAG_RW,
|
|
|
|
&ath_hal_alq_lost, 0, "Register operations not logged");
|
|
|
|
|
|
|
|
static struct ale *
|
|
|
|
ath_hal_alq_get(struct ath_hal *ah)
|
|
|
|
{
|
|
|
|
struct ale *ale;
|
|
|
|
|
|
|
|
if (ath_hal_alq_emitdev) {
|
|
|
|
ale = alq_get(ath_hal_alq, ALQ_NOWAIT);
|
|
|
|
if (ale) {
|
|
|
|
struct athregrec *r =
|
|
|
|
(struct athregrec *) ale->ae_data;
|
|
|
|
r->op = OP_DEVICE;
|
|
|
|
r->reg = 0;
|
|
|
|
r->val = ah->ah_devid;
|
|
|
|
alq_post(ath_hal_alq, ale);
|
|
|
|
ath_hal_alq_emitdev = 0;
|
|
|
|
} else
|
|
|
|
ath_hal_alq_lost++;
|
|
|
|
}
|
|
|
|
ale = alq_get(ath_hal_alq, ALQ_NOWAIT);
|
|
|
|
if (!ale)
|
|
|
|
ath_hal_alq_lost++;
|
|
|
|
return ale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val)
|
|
|
|
{
|
|
|
|
bus_space_tag_t tag = BUSTAG(ah);
|
2008-12-01 16:53:01 +00:00
|
|
|
bus_space_handle_t h = ah->ah_sh;
|
2006-09-18 16:49:15 +00:00
|
|
|
|
2016-01-03 17:58:11 +00:00
|
|
|
#ifdef AH_DEBUG
|
2014-03-20 05:10:17 +00:00
|
|
|
/* Debug - complain if we haven't fully waken things up */
|
2014-04-09 03:51:05 +00:00
|
|
|
if (! ath_hal_reg_whilst_asleep(ah, reg) &&
|
|
|
|
ah->ah_powerMode != HAL_PM_AWAKE) {
|
2014-03-20 05:10:17 +00:00
|
|
|
ath_hal_printf(ah, "%s: reg=0x%08x, val=0x%08x, pm=%d\n",
|
|
|
|
__func__, reg, val, ah->ah_powerMode);
|
|
|
|
}
|
2016-01-03 17:58:11 +00:00
|
|
|
#endif
|
2014-03-20 05:10:17 +00:00
|
|
|
|
2006-09-18 16:49:15 +00:00
|
|
|
if (ath_hal_alq) {
|
|
|
|
struct ale *ale = ath_hal_alq_get(ah);
|
|
|
|
if (ale) {
|
|
|
|
struct athregrec *r = (struct athregrec *) ale->ae_data;
|
2012-04-04 20:46:20 +00:00
|
|
|
r->threadid = curthread->td_tid;
|
2006-09-18 16:49:15 +00:00
|
|
|
r->op = OP_WRITE;
|
|
|
|
r->reg = reg;
|
|
|
|
r->val = val;
|
|
|
|
alq_post(ath_hal_alq, ale);
|
|
|
|
}
|
|
|
|
}
|
2011-11-09 22:39:44 +00:00
|
|
|
if (ah->ah_config.ah_serialise_reg_war)
|
|
|
|
mtx_lock_spin(&ah_regser_mtx);
|
2012-04-19 03:26:21 +00:00
|
|
|
bus_space_write_4(tag, h, reg, val);
|
2016-01-02 17:14:22 +00:00
|
|
|
OS_BUS_BARRIER_REG(ah, reg, OS_BUS_BARRIER_WRITE);
|
2011-11-09 22:39:44 +00:00
|
|
|
if (ah->ah_config.ah_serialise_reg_war)
|
|
|
|
mtx_unlock_spin(&ah_regser_mtx);
|
2006-09-18 16:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int32_t
|
|
|
|
ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg)
|
|
|
|
{
|
|
|
|
bus_space_tag_t tag = BUSTAG(ah);
|
2008-12-01 16:53:01 +00:00
|
|
|
bus_space_handle_t h = ah->ah_sh;
|
2006-09-18 16:49:15 +00:00
|
|
|
u_int32_t val;
|
|
|
|
|
2016-01-03 17:58:11 +00:00
|
|
|
#ifdef AH_DEBUG
|
2014-03-20 05:10:17 +00:00
|
|
|
/* Debug - complain if we haven't fully waken things up */
|
2014-04-09 03:51:05 +00:00
|
|
|
if (! ath_hal_reg_whilst_asleep(ah, reg) &&
|
|
|
|
ah->ah_powerMode != HAL_PM_AWAKE) {
|
2014-03-20 05:10:17 +00:00
|
|
|
ath_hal_printf(ah, "%s: reg=0x%08x, pm=%d\n",
|
|
|
|
__func__, reg, ah->ah_powerMode);
|
|
|
|
}
|
2016-01-03 17:58:11 +00:00
|
|
|
#endif
|
2014-03-20 05:10:17 +00:00
|
|
|
|
2011-11-09 22:39:44 +00:00
|
|
|
if (ah->ah_config.ah_serialise_reg_war)
|
|
|
|
mtx_lock_spin(&ah_regser_mtx);
|
2016-01-02 17:14:22 +00:00
|
|
|
OS_BUS_BARRIER_REG(ah, reg, OS_BUS_BARRIER_READ);
|
2012-04-19 03:26:21 +00:00
|
|
|
val = bus_space_read_4(tag, h, reg);
|
2011-11-09 22:39:44 +00:00
|
|
|
if (ah->ah_config.ah_serialise_reg_war)
|
|
|
|
mtx_unlock_spin(&ah_regser_mtx);
|
2006-09-18 16:49:15 +00:00
|
|
|
if (ath_hal_alq) {
|
|
|
|
struct ale *ale = ath_hal_alq_get(ah);
|
|
|
|
if (ale) {
|
|
|
|
struct athregrec *r = (struct athregrec *) ale->ae_data;
|
2012-04-04 20:46:20 +00:00
|
|
|
r->threadid = curthread->td_tid;
|
2006-09-18 16:49:15 +00:00
|
|
|
r->op = OP_READ;
|
|
|
|
r->reg = reg;
|
|
|
|
r->val = val;
|
|
|
|
alq_post(ath_hal_alq, ale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OS_MARK(struct ath_hal *ah, u_int id, u_int32_t v)
|
|
|
|
{
|
|
|
|
if (ath_hal_alq) {
|
|
|
|
struct ale *ale = ath_hal_alq_get(ah);
|
|
|
|
if (ale) {
|
|
|
|
struct athregrec *r = (struct athregrec *) ale->ae_data;
|
2012-04-04 20:46:20 +00:00
|
|
|
r->threadid = curthread->td_tid;
|
2006-09-18 16:49:15 +00:00
|
|
|
r->op = OP_MARK;
|
|
|
|
r->reg = id;
|
|
|
|
r->val = v;
|
|
|
|
alq_post(ath_hal_alq, ale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-03 17:58:11 +00:00
|
|
|
#else /* AH_DEBUG_ALQ */
|
|
|
|
|
2006-09-18 16:49:15 +00:00
|
|
|
/*
|
|
|
|
* Memory-mapped device register read/write. These are here
|
|
|
|
* as routines when debugging support is enabled and/or when
|
|
|
|
* explicitly configured to use function calls. The latter is
|
|
|
|
* for architectures that might need to do something before
|
|
|
|
* referencing memory (e.g. remap an i/o window).
|
|
|
|
*
|
|
|
|
* NB: see the comments in ah_osdep.h about byte-swapping register
|
|
|
|
* reads and writes to understand what's going on below.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val)
|
|
|
|
{
|
|
|
|
bus_space_tag_t tag = BUSTAG(ah);
|
2008-12-01 16:53:01 +00:00
|
|
|
bus_space_handle_t h = ah->ah_sh;
|
2006-09-18 16:49:15 +00:00
|
|
|
|
2016-01-03 17:58:11 +00:00
|
|
|
#ifdef AH_DEBUG
|
2014-03-20 05:10:17 +00:00
|
|
|
/* Debug - complain if we haven't fully waken things up */
|
2014-04-09 03:51:05 +00:00
|
|
|
if (! ath_hal_reg_whilst_asleep(ah, reg) &&
|
|
|
|
ah->ah_powerMode != HAL_PM_AWAKE) {
|
2014-03-20 05:10:17 +00:00
|
|
|
ath_hal_printf(ah, "%s: reg=0x%08x, val=0x%08x, pm=%d\n",
|
|
|
|
__func__, reg, val, ah->ah_powerMode);
|
|
|
|
}
|
2016-01-03 17:58:11 +00:00
|
|
|
#endif
|
2014-03-20 05:10:17 +00:00
|
|
|
|
2011-11-09 22:39:44 +00:00
|
|
|
if (ah->ah_config.ah_serialise_reg_war)
|
|
|
|
mtx_lock_spin(&ah_regser_mtx);
|
2012-04-19 03:26:21 +00:00
|
|
|
bus_space_write_4(tag, h, reg, val);
|
2016-01-02 17:14:22 +00:00
|
|
|
OS_BUS_BARRIER_REG(ah, reg, OS_BUS_BARRIER_WRITE);
|
2011-11-09 22:39:44 +00:00
|
|
|
if (ah->ah_config.ah_serialise_reg_war)
|
|
|
|
mtx_unlock_spin(&ah_regser_mtx);
|
2006-09-18 16:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int32_t
|
|
|
|
ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg)
|
|
|
|
{
|
|
|
|
bus_space_tag_t tag = BUSTAG(ah);
|
2008-12-01 16:53:01 +00:00
|
|
|
bus_space_handle_t h = ah->ah_sh;
|
2006-09-18 16:49:15 +00:00
|
|
|
u_int32_t val;
|
|
|
|
|
2016-01-03 17:58:11 +00:00
|
|
|
#ifdef AH_DEBUG
|
2014-03-20 05:10:17 +00:00
|
|
|
/* Debug - complain if we haven't fully waken things up */
|
2014-04-09 03:51:05 +00:00
|
|
|
if (! ath_hal_reg_whilst_asleep(ah, reg) &&
|
|
|
|
ah->ah_powerMode != HAL_PM_AWAKE) {
|
2014-03-20 05:10:17 +00:00
|
|
|
ath_hal_printf(ah, "%s: reg=0x%08x, pm=%d\n",
|
|
|
|
__func__, reg, ah->ah_powerMode);
|
|
|
|
}
|
2016-01-03 17:58:11 +00:00
|
|
|
#endif
|
2014-03-20 05:10:17 +00:00
|
|
|
|
2011-11-09 22:39:44 +00:00
|
|
|
if (ah->ah_config.ah_serialise_reg_war)
|
|
|
|
mtx_lock_spin(&ah_regser_mtx);
|
2016-01-02 17:14:22 +00:00
|
|
|
OS_BUS_BARRIER_REG(ah, reg, OS_BUS_BARRIER_READ);
|
2012-04-19 03:26:21 +00:00
|
|
|
val = bus_space_read_4(tag, h, reg);
|
2011-11-09 22:39:44 +00:00
|
|
|
if (ah->ah_config.ah_serialise_reg_war)
|
|
|
|
mtx_unlock_spin(&ah_regser_mtx);
|
2006-09-18 16:49:15 +00:00
|
|
|
return val;
|
|
|
|
}
|
2016-01-03 17:58:11 +00:00
|
|
|
#endif /* AH_DEBUG_ALQ */
|
2006-09-18 16:49:15 +00:00
|
|
|
|
|
|
|
#ifdef AH_ASSERT
|
|
|
|
void
|
|
|
|
ath_hal_assert_failed(const char* filename, int lineno, const char *msg)
|
|
|
|
{
|
|
|
|
printf("Atheros HAL assertion failure: %s: line %u: %s\n",
|
|
|
|
filename, lineno, msg);
|
|
|
|
panic("ath_hal_assert");
|
|
|
|
}
|
|
|
|
#endif /* AH_ASSERT */
|
[ath] [ath_hal] (etc, etc) - begin the task of re-modularising the HAL.
In the deep past, when this code compiled as a binary module, ath_hal
built as a module. This allowed custom, smaller HAL modules to be built.
This was especially beneficial for small embedded platforms where you
didn't require /everything/ just to run.
However, sometime around the HAL opening fanfare, the HAL landed here
as one big driver+HAL thing, and a lot of the (dirty) infrastructure
(ie, #ifdef AH_SUPPORT_XXX) to build specific subsets of the HAL went away.
This was retained in sys/conf/files as "ath_hal_XXX" but it wasn't
really floated up to the modules themselves.
I'm now in a position where for the reaaaaaly embedded boards (both the
really old and the last couple generation of QCA MIPS boards) having a
cut down HAL module and driver loaded at runtime is /actually/ beneficial.
This reduces the kernel size down by quite a bit. The MIPS modules look
like this:
adrian@gertrude:~/work/freebsd/head-embedded/src % ls -l ../root/mips_ap/boot/kernel.CARAMBOLA2/ath*ko
-r-xr-xr-x 1 adrian adrian 5076 May 23 23:45 ../root/mips_ap/boot/kernel.CARAMBOLA2/ath_dfs.ko
-r-xr-xr-x 1 adrian adrian 100588 May 23 23:45 ../root/mips_ap/boot/kernel.CARAMBOLA2/ath_hal.ko
-r-xr-xr-x 1 adrian adrian 627324 May 23 23:45 ../root/mips_ap/boot/kernel.CARAMBOLA2/ath_hal_ar9300.ko
-r-xr-xr-x 1 adrian adrian 314588 May 23 23:45 ../root/mips_ap/boot/kernel.CARAMBOLA2/ath_main.ko
-r-xr-xr-x 1 adrian adrian 23472 May 23 23:45 ../root/mips_ap/boot/kernel.CARAMBOLA2/ath_rate.ko
And the x86 versions, like this:
root@gertrude:/home/adrian # ls -l /boot/kernel/ath*ko
-r-xr-xr-x 1 root wheel 36632 May 24 18:32 /boot/kernel/ath_dfs.ko
-r-xr-xr-x 1 root wheel 134440 May 24 18:32 /boot/kernel/ath_hal.ko
-r-xr-xr-x 1 root wheel 82320 May 24 18:32 /boot/kernel/ath_hal_ar5210.ko
-r-xr-xr-x 1 root wheel 104976 May 24 18:32 /boot/kernel/ath_hal_ar5211.ko
-r-xr-xr-x 1 root wheel 236144 May 24 18:32 /boot/kernel/ath_hal_ar5212.ko
-r-xr-xr-x 1 root wheel 336104 May 24 18:32 /boot/kernel/ath_hal_ar5416.ko
-r-xr-xr-x 1 root wheel 598336 May 24 18:32 /boot/kernel/ath_hal_ar9300.ko
-r-xr-xr-x 1 root wheel 406144 May 24 18:32 /boot/kernel/ath_main.ko
-r-xr-xr-x 1 root wheel 55352 May 24 18:32 /boot/kernel/ath_rate.ko
.. so you can see, not building the whole HAL can save quite a bit.
For example, if you don't need AR9300 support, you can actually avoid
wasting half a megabyte of RAM. On embedded routers this is quite a
big deal.
The AR9300 HAL can be later further shrunk because, hilariously,
it indeed supports AH_SUPPORT_<xxx> for optionally adding chipset support.
(I'll chase that down later as it's quite a big savings if you're only
building for a single embedded target.)
So:
* Create a very hackish way to load/unload HAL modules
* Create module metadata for each HAL subtype - ah_osdep_arXXXX.c
* Create module metadata for ath_rate and ath_dfs (bluetooth is
currently just built as part of it)
* .. yes, this means we could actually build multiple rate control
modules and pick one at load time, but I'd rather just glue this
into net80211's rate control code. Oh well, baby steps.
* Main driver is now "ath_main"
* Create an "if_ath" module that does what the ye olde one did -
load PCI glue, main driver, HAL and all child modules.
In this way, if you have "if_ath_load=YES" in /boot/modules.conf
it will load everything the old way and stuff should still work.
* For module autoloading purposes, I actually /did/ fix up
the name of the modules in if_ath_pci and if_ath_ahb.
If you want to selectively load things (eg on ye cheape ARM/MIPS platforms
where RAM is at a premium) you should:
* load ath_hal
* load the chip modules in question
* load ath_rate, ath_dfs
* load ath_main
* load if_ath_pci and/or if_ath_ahb depending upon your particular
bus bind type - this is where probe/attach is done.
TODO:
* AR5312 module and associated pieces - yes, we have the SoC side support
now so the wifi support would be good to "round things out";
* Just nuke AH_SUPPORT_AR5416 for now and always bloat the packet
structures; this'll simplify other things.
* Should add a simple refcnt thing to the HAL RF/chip modules so you
can't unload them whilst you're using them.
* Manpage updates, UPDATING if appropriate, etc.
2017-05-25 04:18:46 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
ath_hal_modevent(module_t mod __unused, int type, void *data __unused)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
printf("[ath_hal] loaded\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
printf("[ath_hal] unloaded\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOD_SHUTDOWN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEV_MODULE(ath_hal, ath_hal_modevent, NULL);
|
|
|
|
MODULE_VERSION(ath_hal, 1);
|
2017-06-29 03:59:02 +00:00
|
|
|
#if defined(AH_DEBUG_ALQ)
|
|
|
|
MODULE_DEPEND(ath_hal, alq, 1, 1, 1);
|
|
|
|
#endif
|