2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
34 #include "ah_internal.h"
35 #include "ah_decode.h"
47 #define MAXREGS 5*1024
48 struct dumpreg *regs[MAXREGS];
51 static dumpregs_t state;
53 static void opdevice(const struct athregrec *r);
54 static const char* opmark(FILE *, int, const struct athregrec *);
55 static void oprw(FILE *fd, int recnum, struct athregrec *r);
58 main(int argc, char *argv[])
60 int fd, i, nrecs, same;
63 const char *filename = "/tmp/ath_hal.log";
64 struct athregrec *rprev;
68 fd = open(filename, O_RDONLY);
71 if (fstat(fd, &sb) < 0)
73 addr = mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE|MAP_NOCORE, fd, 0);
74 if (addr == MAP_FAILED)
76 nrecs = sb.st_size / sizeof (struct athregrec);
77 printf("%u records", nrecs);
81 for (i = 0; i < nrecs; i++) {
82 struct athregrec *r = &((struct athregrec *) addr)[i];
83 if (rprev && bcmp(r, rprev, sizeof (*r)) == 0) {
88 printf("\t\t+%u time%s", same, same == 1 ? "" : "s");
109 opmark(FILE *fd, int i, const struct athregrec *r)
111 fprintf(fd, "\n%05d: ", i);
114 fprintf(fd, "ar%uReset %s", state.chipnum,
115 r->val ? "change channel" : "no channel change");
117 case AH_MARK_RESET_LINE:
118 fprintf(fd, "ar%u_reset.c; line %u", state.chipnum, r->val);
120 case AH_MARK_RESET_DONE:
122 fprintf(fd, "ar%uReset (done), FAIL, error %u",
123 state.chipnum, r->val);
125 fprintf(fd, "ar%uReset (done), OK", state.chipnum);
127 case AH_MARK_CHIPRESET:
128 fprintf(fd, "ar%uChipReset, channel %u MHz", state.chipnum, r->val);
131 fprintf(fd, "ar%uPerCalibration, channel %u MHz", state.chipnum, r->val);
133 case AH_MARK_SETCHANNEL:
134 fprintf(fd, "ar%uSetChannel, channel %u MHz", state.chipnum, r->val);
136 case AH_MARK_ANI_RESET:
139 fprintf(fd, "ar%uAniReset, HAL_M_STA", state.chipnum);
142 fprintf(fd, "ar%uAniReset, HAL_M_IBSS", state.chipnum);
145 fprintf(fd, "ar%uAniReset, HAL_M_HOSTAP", state.chipnum);
148 fprintf(fd, "ar%uAniReset, HAL_M_MONITOR", state.chipnum);
151 fprintf(fd, "ar%uAniReset, opmode %u", state.chipnum, r->val);
155 case AH_MARK_ANI_POLL:
156 fprintf(fd, "ar%uAniPoll, listenTime %u", state.chipnum, r->val);
158 case AH_MARK_ANI_CONTROL:
160 case HAL_ANI_PRESENT:
161 fprintf(fd, "ar%uAniControl, PRESENT", state.chipnum);
163 case HAL_ANI_NOISE_IMMUNITY_LEVEL:
164 fprintf(fd, "ar%uAniControl, NOISE_IMMUNITY", state.chipnum);
166 case HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION:
167 fprintf(fd, "ar%uAniControl, OFDM_WEAK_SIGNAL", state.chipnum);
169 case HAL_ANI_CCK_WEAK_SIGNAL_THR:
170 fprintf(fd, "ar%uAniControl, CCK_WEAK_SIGNAL", state.chipnum);
172 case HAL_ANI_FIRSTEP_LEVEL:
173 fprintf(fd, "ar%uAniControl, FIRSTEP_LEVEL", state.chipnum);
175 case HAL_ANI_SPUR_IMMUNITY_LEVEL:
176 fprintf(fd, "ar%uAniControl, SPUR_IMMUNITY", state.chipnum);
179 fprintf(fd, "ar%uAniControl, MODE", state.chipnum);
181 case HAL_ANI_PHYERR_RESET:
182 fprintf(fd, "ar%uAniControl, PHYERR_RESET", state.chipnum);
185 fprintf(fd, "ar%uAniControl, cmd %u", state.chipnum, r->val);
190 fprintf(fd, "mark #%u value %u/0x%x", r->reg, r->val, r->val);
195 #include "ah_devid.h"
198 opdevice(const struct athregrec *r)
203 state.chipnum = 5210;
204 state.revs.ah_macVersion = 1;
205 state.revs.ah_macRev = 0;
211 state.chipnum = 5211;
212 state.revs.ah_macVersion = 2;
213 state.revs.ah_macRev = 0;
219 case AR5212_DEVID_IBM:
220 case AR5212_AR5312_REV2:
221 case AR5212_AR5312_REV7:
222 case AR5212_AR2313_REV8:
223 case AR5212_AR2315_REV6:
224 case AR5212_AR2315_REV7:
225 case AR5212_AR2317_REV1:
226 case AR5212_AR2317_REV2:
228 /* AR5212 compatible devid's also attach to 5212 */
229 case AR5212_DEVID_0014:
230 case AR5212_DEVID_0015:
231 case AR5212_DEVID_0016:
232 case AR5212_DEVID_0017:
233 case AR5212_DEVID_0018:
234 case AR5212_DEVID_0019:
239 case AR5212_DEVID_FF19:
240 state.chipnum = 5212;
241 state.revs.ah_macVersion = 4;
242 state.revs.ah_macRev = 5;
246 case AR5213_SREV_1_0:
247 case AR5213_SREV_REG:
248 state.chipnum = 5213;
249 state.revs.ah_macVersion = 5;
250 state.revs.ah_macRev = 9;
253 /* AR5416 compatible devid's */
254 case AR5416_DEVID_PCI:
255 case AR5416_DEVID_PCIE:
256 case AR9160_DEVID_PCI:
257 case AR9280_DEVID_PCI:
258 case AR9280_DEVID_PCIE:
259 case AR9285_DEVID_PCIE:
260 state.chipnum = 5416;
261 state.revs.ah_macVersion = 13;
262 state.revs.ah_macRev = 8;
265 printf("Unknown device id 0x%x\n", r->val);
271 regcompar(const void *a, const void *b)
273 const struct dumpreg *ra = *(const struct dumpreg **)a;
274 const struct dumpreg *rb = *(const struct dumpreg **)b;
275 return ra->addr - rb->addr;
279 register_regs(struct dumpreg *chipregs, u_int nchipregs,
280 int def_srev_min, int def_srev_max, int def_phy_min, int def_phy_max)
282 const int existing_regs = state.nregs;
285 for (i = 0; i < nchipregs; i++) {
286 struct dumpreg *nr = &chipregs[i];
287 if (nr->srevMin == 0)
288 nr->srevMin = def_srev_min;
289 if (nr->srevMax == 0)
290 nr->srevMax = def_srev_max;
292 nr->phyMin = def_phy_min;
294 nr->phyMax = def_phy_max;
295 for (j = 0; j < existing_regs; j++) {
296 struct dumpreg *r = state.regs[j];
298 * Check if we can just expand the mac+phy
299 * coverage for the existing entry.
301 if (nr->addr == r->addr &&
302 (nr->name == r->name ||
303 nr->name != NULL && r->name != NULL &&
304 strcmp(nr->name, r->name) == 0)) {
305 if (nr->srevMin < r->srevMin &&
306 (r->srevMin <= nr->srevMax &&
307 nr->srevMax+1 <= r->srevMax)) {
308 r->srevMin = nr->srevMin;
311 if (nr->srevMax > r->srevMax &&
312 (r->srevMin <= nr->srevMin &&
313 nr->srevMin <= r->srevMax)) {
314 r->srevMax = nr->srevMax;
318 if (r->addr > nr->addr)
322 * New item, add to the end, it'll be sorted below.
324 if (state.nregs == MAXREGS)
325 errx(-1, "too many registers; bump MAXREGS");
326 state.regs[state.nregs++] = nr;
330 qsort(state.regs, state.nregs, sizeof(struct dumpreg *), regcompar);
334 register_keycache(u_int nslots,
335 int def_srev_min, int def_srev_max, int def_phy_min, int def_phy_max)
337 /* discard, no use */
341 register_range(u_int brange, u_int erange, int type,
342 int def_srev_min, int def_srev_max, int def_phy_min, int def_phy_max)
344 /* discard, no use */
347 static const struct dumpreg *
350 const HAL_REVS *revs = &state.revs;
353 for (i = 0; i < state.nregs; i++) {
354 const struct dumpreg *dr = state.regs[i];
355 if (dr->addr == reg &&
356 MAC_MATCH(dr, revs->ah_macVersion, revs->ah_macRev))
362 /* XXX cheat, 5212 has a superset of the key table defs */
363 #include "ar5212/ar5212reg.h"
364 #include "ar5212/ar5212phy.h"
366 #define PWR_TABLE_SIZE 64
369 oprw(FILE *fd, int recnum, struct athregrec *r)
371 const struct dumpreg *dr;
376 fprintf(fd, "\n%05d: ", recnum);
377 dr = findreg(r->reg);
378 if (dr != NULL && dr->name != NULL) {
379 snprintf(buf, sizeof (buf), "AR_%s (0x%x)", dr->name, r->reg);
381 } else if (AR_KEYTABLE(0) <= r->reg && r->reg < AR_KEYTABLE(128)) {
382 snprintf(buf, sizeof (buf), "AR_KEYTABLE%u(%u) (0x%x)",
383 ((r->reg - AR_KEYTABLE_0) >> 2) & 7,
384 (r->reg - AR_KEYTABLE_0) >> 5, r->reg);
387 } else if (AR_PHY_PCDAC_TX_POWER(0) <= r->reg && r->reg < AR_PHY_PCDAC_TX_POWER(PWR_TABLE_SIZE/2)) {
388 snprintf(buf, sizeof (buf), "AR_PHY_PCDAC_TX_POWER(%u) (0x%x)",
389 (r->reg - AR_PHY_PCDAC_TX_POWER_0) >> 2, r->reg);
392 } else if (AR_RATE_DURATION(0) <= r->reg && r->reg < AR_RATE_DURATION(32)) {
393 snprintf(buf, sizeof (buf), "AR_RATE_DURATION(0x%x) (0x%x)",
394 (r->reg - AR_RATE_DURATION_0) >> 2, r->reg);
396 } else if (AR_PHY_BASE <= r->reg) {
397 snprintf(buf, sizeof (buf), "AR_PHY(%u) (0x%x)",
398 (r->reg - AR_PHY_BASE) >> 2, r->reg);
401 snprintf(buf, sizeof (buf), "0x%x", r->reg);
404 fprintf(fd, "%-30s %s 0x%x", buf, r->op ? "<=" : "=>", r->val);
406 const char *p = bits;
409 for (tmp = 0, p++; *p;) {
411 if (r->val & (1 << (n - 1))) {
412 putc(tmp ? ',' : '<', fd);
413 for (; (n = *p) > ' '; ++p)
417 for (; *p > ' '; ++p)