2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2008 Atheros Communications, Inc.
4 * Copyright (c) 2010 Neil Cafferkey
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 #include <exec/memory.h>
32 #include <proto/exec.h>
33 #include <proto/timer.h>
38 static int ath_hal_debug
= 0;
41 int ath_hal_dma_beacon_response_time
= 2; /* in TU's */
42 int ath_hal_sw_beacon_response_time
= 10; /* in TU's */
43 int ath_hal_additional_swba_backoff
= 0; /* in TU's */
47 _ath_hal_attach(uint16_t devid
, HAL_SOFTC sc
,
48 HAL_BUS_TAG t
, HAL_BUS_HANDLE h
, void* s
)
51 struct ath_hal
*ah
= ath_hal_attach(devid
, sc
, t
, h
, &status
);
53 *(HAL_STATUS
*)s
= status
;
58 ath_hal_detach(struct ath_hal
*ah
)
65 * Print/log message support.
69 ath_hal_vprintf(struct ath_hal
*ah
, const char* fmt
, va_list ap
)
71 char buf
[1024]; /* XXX */
72 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
77 ath_hal_printf(struct ath_hal
*ah
, const char* fmt
, ...)
81 ath_hal_vprintf(ah
, fmt
, ap
);
84 //EXPORT_SYMBOL(ath_hal_printf);
87 * Format an Ethernet MAC for printing.
90 ath_hal_ether_sprintf(const uint8_t *mac
)
92 static char etherbuf
[18];
93 snprintf(etherbuf
, sizeof(etherbuf
), "%02x:%02x:%02x:%02x:%02x:%02x",
94 mac
[0], mac
[1], mac
[2], mac
[3], mac
[4], mac
[5]);
100 ath_hal_assert_failed(const char* filename
, int lineno
, const char *msg
)
102 printk("Atheros HAL assertion failure: %s: line %u: %s\n",
103 filename
, lineno
, msg
);
104 panic("ath_hal_assert");
106 #endif /* AH_ASSERT */
110 * ALQ register tracing support.
112 * Setting hw.ath.hal.alq=1 enables tracing of all register reads and
113 * writes to the file /tmp/ath_hal.log. The file format is a simple
114 * fixed-size array of records. When done logging set hw.ath.hal.alq=0
115 * and then decode the file with the ardecode program (that is part of the
116 * HAL). If you start+stop tracing the data will be appended to an
119 * NB: doesn't handle multiple devices properly; only one DEVICE record
120 * is emitted and the different devices are not identified.
123 #include "ah_decode.h"
125 static struct alq
*ath_hal_alq
;
126 static int ath_hal_alq_emitdev
; /* need to emit DEVICE record */
127 static u_int ath_hal_alq_lost
; /* count of lost records */
128 static const char *ath_hal_logfile
= "/tmp/ath_hal.log";
129 static u_int ath_hal_alq_qsize
= 8*1024;
132 ath_hal_setlogging(int enable
)
137 if (!capable(CAP_NET_ADMIN
))
139 error
= alq_open(&ath_hal_alq
, ath_hal_logfile
,
140 sizeof (struct athregrec
), ath_hal_alq_qsize
);
141 ath_hal_alq_lost
= 0;
142 ath_hal_alq_emitdev
= 1;
143 printk("ath_hal: logging to %s %s\n", ath_hal_logfile
,
144 error
== 0 ? "enabled" : "could not be setup");
147 alq_close(ath_hal_alq
);
149 printk("ath_hal: logging disabled\n");
156 * Deal with the sysctl handler api changing.
158 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8)
159 #define AH_SYSCTL_ARGS_DECL \
160 ctl_table *ctl, int write, struct file *filp, void *buffer, \
162 #define AH_SYSCTL_ARGS ctl, write, filp, buffer, lenp
163 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,8) */
164 #define AH_SYSCTL_ARGS_DECL \
165 ctl_table *ctl, int write, struct file *filp, void *buffer,\
166 size_t *lenp, loff_t *ppos
167 #define AH_SYSCTL_ARGS ctl, write, filp, buffer, lenp, ppos
171 sysctl_hw_ath_hal_log(AH_SYSCTL_ARGS_DECL
)
176 ctl
->maxlen
= sizeof(enable
);
177 enable
= (ath_hal_alq
!= NULL
);
178 error
= proc_dointvec(AH_SYSCTL_ARGS
);
182 return ath_hal_setlogging(enable
);
186 ath_hal_alq_get(struct ath_hal
*ah
)
190 if (ath_hal_alq_emitdev
) {
191 ale
= alq_get(ath_hal_alq
, ALQ_NOWAIT
);
193 struct athregrec
*r
=
194 (struct athregrec
*) ale
->ae_data
;
197 r
->val
= ah
->ah_devid
;
198 alq_post(ath_hal_alq
, ale
);
199 ath_hal_alq_emitdev
= 0;
203 ale
= alq_get(ath_hal_alq
, ALQ_NOWAIT
);
210 ath_hal_reg_write(struct ath_hal
*ah
, uint32_t reg
, uint32_t val
)
216 local_irq_save(flags
);
217 ale
= ath_hal_alq_get(ah
);
219 struct athregrec
*r
= (struct athregrec
*) ale
->ae_data
;
223 alq_post(ath_hal_alq
, ale
);
225 local_irq_restore(flags
);
227 _OS_REG_WRITE(ah
, reg
, val
);
229 EXPORT_SYMBOL(ath_hal_reg_write
);
232 ath_hal_reg_read(struct ath_hal
*ah
, uint32_t reg
)
236 val
= _OS_REG_READ(ah
, reg
);
241 local_irq_save(flags
);
242 ale
= ath_hal_alq_get(ah
);
244 struct athregrec
*r
= (struct athregrec
*) ale
->ae_data
;
248 alq_post(ath_hal_alq
, ale
);
250 local_irq_restore(flags
);
254 EXPORT_SYMBOL(ath_hal_reg_read
);
257 OS_MARK(struct ath_hal
*ah
, u_int id
, uint32_t v
)
263 local_irq_save(flags
);
264 ale
= ath_hal_alq_get(ah
);
266 struct athregrec
*r
= (struct athregrec
*) ale
->ae_data
;
270 alq_post(ath_hal_alq
, ale
);
272 local_irq_restore(flags
);
275 EXPORT_SYMBOL(OS_MARK
);
276 #elif defined(AH_DEBUG) || defined(AH_REGOPS_FUNC)
278 * Memory-mapped device register read/write. These are here
279 * as routines when debugging support is enabled and/or when
280 * explicitly configured to use function calls. The latter is
281 * for architectures that might need to do something before
282 * referencing memory (e.g. remap an i/o window).
284 * NB: see the comments in ah_osdep.h about byte-swapping register
285 * reads and writes to understand what's going on below.
288 ath_hal_reg_write(struct ath_hal
*ah
, u_int reg
, uint32_t val
)
291 if (ath_hal_debug
> 1)
292 ath_hal_printf(ah
, "WRITE 0x%x <= 0x%x\n", reg
, val
);
294 _OS_REG_WRITE(ah
, reg
, val
);
296 EXPORT_SYMBOL(ath_hal_reg_write
);
299 ath_hal_reg_read(struct ath_hal
*ah
, u_int reg
)
303 val
= _OS_REG_READ(ah
, reg
);
305 if (ath_hal_debug
> 1)
306 ath_hal_printf(ah
, "READ 0x%x => 0x%x\n", reg
, val
);
310 EXPORT_SYMBOL(ath_hal_reg_read
);
311 #endif /* AH_DEBUG || AH_REGOPS_FUNC */
315 HALDEBUG(struct ath_hal
*ah
, const char* fmt
, ...)
320 ath_hal_vprintf(ah
, fmt
, ap
);
327 HALDEBUGn(struct ath_hal
*ah
, u_int level
, const char* fmt
, ...)
329 if (ath_hal_debug
>= level
) {
332 ath_hal_vprintf(ah
, fmt
, ap
);
336 #endif /* AH_DEBUG */
339 * Delay n microseconds.
348 ath_hal_getuptime(struct ath_hal
*ah
)
350 // return ((jiffies / HZ) * 1000) + (jiffies % HZ) * (1000 / HZ);
353 //EXPORT_SYMBOL(ath_hal_getuptime);
356 * Allocate/free memory.
360 ath_hal_malloc(size_t size
)
362 return AllocVec(size
, MEMF_PUBLIC
| MEMF_CLEAR
);
366 ath_hal_free(void* p
)
372 ath_hal_memzero(void *dst
, size_t n
)
376 //EXPORT_SYMBOL(ath_hal_memzero);
379 ath_hal_memcpy(void *dst
, const void *src
, size_t n
)
381 return memcpy(dst
, src
, n
);
383 //EXPORT_SYMBOL(ath_hal_memcpy);
386 ath_hal_memcmp(const void *a
, const void *b
, size_t n
)
388 return memcmp(a
, b
, n
);
390 //EXPORT_SYMBOL(ath_hal_memcmp);