37#include <sys/kernel.h>
38#include <sys/module.h>
39#include <sys/sysctl.h>
41#include <sys/malloc.h>
48#include <machine/stdarg.h>
50#include <net/ethernet.h>
62#ifdef AH_SUPPORT_AR5312
64 ((bus_space_tag_t) ((struct ar531x_config *)((ah)->ah_st))->tag)
66#define BUSTAG(ah) ((ah)->ah_st)
88extern void ath_hal_assert_failed(
const char* filename,
89 int lineno,
const char* msg);
92extern void DO_HALDEBUG(
struct ath_hal *ah, u_int mask,
const char* fmt, ...);
96SYSCTL_NODE(_hw, OID_AUTO, ath, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
97 "Atheros driver parameters");
98static SYSCTL_NODE(_hw_ath, OID_AUTO, hal, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
99 "Atheros HAL parameters");
102int ath_hal_debug = 0;
103SYSCTL_INT(_hw_ath_hal, OID_AUTO, debug, CTLFLAG_RWTUN, &ath_hal_debug,
104 0,
"Atheros HAL debugging printfs");
112 return malloc(size, M_ATH_HAL, M_NOWAIT | M_ZERO);
139 return ether_sprintf(mac);
150ath_hal_reg_whilst_asleep(
struct ath_hal *ah, uint32_t reg)
153 if (reg >= 0x4000 && reg < 0x5000)
155 if (reg >= 0x6000 && reg < 0x7000)
157 if (reg >= 0x7000 && reg < 0x8000)
163DO_HALDEBUG(
struct ath_hal *ah, u_int mask,
const char* fmt, ...)
167 (ath_hal_debug & mask)) {
174#undef HAL_DEBUG_UNMASKABLE
195static struct alq *ath_hal_alq;
196static int ath_hal_alq_emitdev;
197static u_int ath_hal_alq_lost;
198static char ath_hal_logfile[MAXPATHLEN] =
"/tmp/ath_hal.log";
200SYSCTL_STRING(_hw_ath_hal, OID_AUTO, alq_logfile, CTLFLAG_RW,
201 &ath_hal_logfile,
sizeof(kernelname),
"Name of ALQ logfile");
203static u_int ath_hal_alq_qsize = 64*1024;
206ath_hal_setlogging(
int enable)
211 error = alq_open(&ath_hal_alq, ath_hal_logfile,
212 curthread->td_ucred, ALQ_DEFAULT_CMODE,
213 sizeof (
struct athregrec), ath_hal_alq_qsize);
214 ath_hal_alq_lost = 0;
215 ath_hal_alq_emitdev = 1;
216 printf(
"ath_hal: logging to %s enabled\n",
220 alq_close(ath_hal_alq);
222 printf(
"ath_hal: logging disabled\n");
229sysctl_hw_ath_hal_log(SYSCTL_HANDLER_ARGS)
233 enable = (ath_hal_alq != NULL);
234 error = sysctl_handle_int(oidp, &enable, 0, req);
235 if (error || !req->newptr)
238 return (ath_hal_setlogging(enable));
240SYSCTL_PROC(_hw_ath_hal, OID_AUTO, alq,
241 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
242 0, 0, sysctl_hw_ath_hal_log,
"I",
243 "Enable HAL register logging");
244SYSCTL_INT(_hw_ath_hal, OID_AUTO, alq_size, CTLFLAG_RW,
245 &ath_hal_alq_qsize, 0,
"In-memory log size (#records)");
246SYSCTL_INT(_hw_ath_hal, OID_AUTO, alq_lost, CTLFLAG_RW,
247 &ath_hal_alq_lost, 0,
"Register operations not logged");
250ath_hal_alq_get(
struct ath_hal *ah)
254 if (ath_hal_alq_emitdev) {
255 ale = alq_get(ath_hal_alq, ALQ_NOWAIT);
262 alq_post(ath_hal_alq, ale);
263 ath_hal_alq_emitdev = 0;
267 ale = alq_get(ath_hal_alq, ALQ_NOWAIT);
276 bus_space_tag_t tag =
BUSTAG(ah);
277 bus_space_handle_t h = ah->
ah_sh;
281 if (! ath_hal_reg_whilst_asleep(ah,
reg) &&
289 struct ale *ale = ath_hal_alq_get(ah);
296 alq_post(ath_hal_alq, ale);
301 bus_space_write_4(tag, h,
reg,
val);
310 bus_space_tag_t tag =
BUSTAG(ah);
311 bus_space_handle_t h = ah->
ah_sh;
316 if (! ath_hal_reg_whilst_asleep(ah,
reg) &&
326 val = bus_space_read_4(tag, h,
reg);
330 struct ale *ale = ath_hal_alq_get(ah);
337 alq_post(ath_hal_alq, ale);
347 struct ale *ale = ath_hal_alq_get(ah);
354 alq_post(ath_hal_alq, ale);
374 bus_space_tag_t tag =
BUSTAG(ah);
375 bus_space_handle_t h = ah->
ah_sh;
379 if (! ath_hal_reg_whilst_asleep(ah,
reg) &&
388 bus_space_write_4(tag, h,
reg,
val);
397 bus_space_tag_t tag =
BUSTAG(ah);
398 bus_space_handle_t h = ah->
ah_sh;
403 if (! ath_hal_reg_whilst_asleep(ah,
reg) &&
413 val = bus_space_read_4(tag, h,
reg);
422ath_hal_assert_failed(
const char* filename,
int lineno,
const char *msg)
424 printf(
"Atheros HAL assertion failure: %s: line %u: %s\n",
425 filename, lineno, msg);
426 panic(
"ath_hal_assert");
438 printf(
"[ath_hal] loaded\n");
443 printf(
"[ath_hal] unloaded\n");
458#if defined(AH_DEBUG_ALQ)
void * ath_hal_malloc(size_t)
u_int32_t ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg)
void ath_hal_vprintf(struct ath_hal *ah, const char *fmt, va_list ap)
MTX_SYSINIT(ah_regser, &ah_regser_mtx, "Atheros register access mutex", MTX_SPIN)
static int ath_hal_modevent(module_t mod __unused, int type, void *data __unused)
void ath_hal_free(void *p)
void ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val)
void ath_hal_printf(struct ath_hal *, const char *,...)
MODULE_VERSION(ath_hal, 1)
const char * ath_hal_ether_sprintf(const u_int8_t *mac)
DEV_MODULE(ath_hal, ath_hal_modevent, NULL)
#define OS_BUS_BARRIER_READ
#define OS_BUS_BARRIER_WRITE
#define OS_BUS_BARRIER_REG(_ah, _reg, _t)
#define OS_MARK(_ah, _id, _v)
MODULE_DEPEND(ath_hal_ar5210, ath_hal, 1, 1, 1)
MALLOC_DEFINE(M_ATHDEV, "athdev", "ath driver dma buffers")
SYSCTL_INT(_hw_ath, OID_AUTO, longcal, CTLFLAG_RW, &ath_longcalinterval, 0, "long chip calibration interval (secs)")
HAL_POWER_MODE ah_powerMode