ath_ee_v14_print.c revision 217682
1 2/* 3 * Copyright (c) 2010-2011 Adrian Chadd, Xenion Pty Ltd. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: head/tools/tools/ath/ath_ee_v14_print/ath_ee_v14_print.c 217682 2011-01-21 03:14:08Z adrian $ 27 */ 28 29#include <stdio.h> 30#include <stdlib.h> 31#include <unistd.h> 32#include <string.h> 33#include <sys/types.h> 34#include <err.h> 35 36typedef enum { 37 AH_FALSE = 0, /* NB: lots of code assumes false is zero */ 38 AH_TRUE = 1, 39} HAL_BOOL; 40 41typedef enum { 42 HAL_OK = 0, /* No error */ 43} HAL_STATUS; 44 45struct ath_hal; 46 47#include "ah_eeprom_v14.h" 48 49void 50load_eeprom_dump(const char *file, uint16_t *buf) 51{ 52 unsigned int r[8]; 53 FILE *fp; 54 char b[1024]; 55 int i; 56 57 fp = fopen(file, "r"); 58 if (!fp) 59 err(1, "fopen"); 60 61 while (!feof(fp)) { 62 if (fgets(b, 1024, fp) == NULL) 63 break; 64 if (feof(fp)) 65 break; 66 if (strlen(b) > 0) 67 b[strlen(b)-1] = '\0'; 68 if (strlen(b) == 0) 69 break; 70 sscanf(b, "%x: %x %x %x %x %x %x %x %x\n", 71 &i, &r[0], &r[1], &r[2], &r[3], &r[4], 72 &r[5], &r[6], &r[7]); 73 buf[i++] = r[0]; 74 buf[i++] = r[1]; 75 buf[i++] = r[2]; 76 buf[i++] = r[3]; 77 buf[i++] = r[4]; 78 buf[i++] = r[5]; 79 buf[i++] = r[6]; 80 buf[i++] = r[7]; 81 } 82 fclose(fp); 83} 84 85static void 86eeprom_v14_base_print(uint16_t *buf) 87{ 88 HAL_EEPROM_v14 *eep = (HAL_EEPROM_v14 *) buf; 89 BASE_EEP_HEADER *eh = &eep->ee_base.baseEepHeader; 90 91 printf("| Version: 0x%.4x | Length: 0x%.4x | Checksum: 0x%.4x ", 92 eh->version, eh->length, eh->checksum); 93 printf("| CapFlags: 0x%.2x | eepMisc: 0x%.2x | RegDomain: 0x%.2x 0x%.2x | \n", 94 eh->opCapFlags, eh->eepMisc, eh->regDmn[0], eh->regDmn[1]); 95 printf("| MAC: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x ", 96 eh->macAddr[0], eh->macAddr[1], eh->macAddr[2], 97 eh->macAddr[3], eh->macAddr[4], eh->macAddr[5]); 98 printf("| RxMask: 0x%.2x | TxMask: 0x%.2x | RfSilent: 0x%.4x | btOptions: 0x%.4x |\n", 99 eh->rxMask, eh->txMask, eh->rfSilent, eh->blueToothOptions); 100 printf("| DeviceCap: 0x%.4x | binBuildNumber: %.8x | deviceType: 0x%.2x |\n", 101 eh->deviceCap, eh->binBuildNumber, eh->deviceType); 102 103 printf("| pwdclkind: 0x%.2x | fastClk5g: 0x%.2x | divChain: 0x%.2x | rxGainType: 0x%.2x |\n", 104 (int) eh->pwdclkind, (int) eh->fastClk5g, (int) eh->divChain, 105 (int) eh->rxGainType); 106 107 printf("| dacHiPwrMode: 0x%.2x | openLoopPwrCntl: 0x%.2x | dacLpMode: 0x%.2x ", 108 (int) eh->dacHiPwrMode, (int) eh->openLoopPwrCntl, (int) eh->dacLpMode); 109 printf("| txGainType: 0x%.2x | rcChainMask: 0x%.2x |\n", 110 (int) eh->txGainType, (int) eh->rcChainMask); 111 112 /* because it's convienent */ 113 printf("| antennaGainMax[0]: 0x%.2x antennaGainMax[1]: 0x%.2x |\n", 114 eep->ee_antennaGainMax[0], eep->ee_antennaGainMax[1]); 115} 116 117static void 118eeprom_v14_custdata_print(uint16_t *buf) 119{ 120 HAL_EEPROM_v14 *eep = (HAL_EEPROM_v14 *) buf; 121 uint8_t *custdata = (uint8_t *) &eep->ee_base.custData; 122 int i; 123 124 printf("\n| Custdata: |\n"); 125 for (i = 0; i < 64; i++) { 126 printf("%s0x%.2x %s", 127 i % 16 == 0 ? "| " : "", 128 custdata[i], 129 i % 16 == 15 ? "|\n" : ""); 130 } 131} 132 133static void 134eeprom_v14_modal_print(uint16_t *buf, int m) 135{ 136 HAL_EEPROM_v14 *eep = (HAL_EEPROM_v14 *) buf; 137 MODAL_EEP_HEADER *mh = &eep->ee_base.modalHeader[m]; 138 int i; 139 140 printf("| antCtrlCommon: 0x%.4x |\n", mh->antCtrlCommon); 141 printf("| switchSettling: 0x%.2x |\n", mh->switchSettling); 142 printf("| adcDesiredSize: %d |\n| pgaDesiredSize: %.2f dBm |\n", 143 mh->adcDesiredSize, (float) mh->pgaDesiredSize / 2.0); 144 145 printf("| antCtrlChain: 0:0x%.4x 1:0x%.4x 2:0x%.4x |\n", 146 mh->antCtrlChain[0], mh->antCtrlChain[1], mh->antCtrlChain[2]); 147 printf("| antennaGainCh: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n", 148 mh->antennaGainCh[0], mh->antennaGainCh[1], mh->antennaGainCh[2]); 149 printf("| txRxAttenCh: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n", 150 mh->txRxAttenCh[0], mh->txRxAttenCh[1], mh->txRxAttenCh[2]); 151 printf("| rxTxMarginCh: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n", 152 mh->rxTxMarginCh[0], mh->rxTxMarginCh[1], mh->rxTxMarginCh[2]); 153 printf("| noiseFloorThresCh: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n", 154 mh->noiseFloorThreshCh[0], mh->noiseFloorThreshCh[1], mh->noiseFloorThreshCh[2]); 155 printf("| xlnaGainCh: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n", 156 mh->xlnaGainCh[0], mh->xlnaGainCh[1], mh->xlnaGainCh[2]); 157 printf("| iqCalICh: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n| iqCalQCh: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n", 158 mh->iqCalICh[0], mh->iqCalICh[1], mh->iqCalICh[2], 159 mh->iqCalQCh[0], mh->iqCalQCh[1], mh->iqCalQCh[2]); 160 printf("| bswAtten: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n", 161 mh->bswAtten[0], mh->bswAtten[1], mh->bswAtten[2]); 162 printf("| bswMargin: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n", 163 mh->bswMargin[0], mh->bswMargin[1], mh->bswMargin[2]); 164 printf("| xatten2Db: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n", 165 mh->xatten2Db[0], mh->xatten2Db[1], mh->xatten2Db[2]); 166 printf("| xatten2Margin: 0:0x%.2x 1:0x%.2x 2:0x%.2x |\n", 167 mh->xatten2Margin[0], mh->xatten2Margin[1], mh->xatten2Margin[2]); 168 169 printf("| txEndToXpaOff: 0x%.2x | txEndToRxOn: 0x%.2x | txFrameToXpaOn: 0x%.2x |\n", 170 mh->txEndToXpaOff, mh->txEndToRxOn, mh->txFrameToXpaOn); 171 172 printf("| thres62: 0x%.2x\n", mh->thresh62); 173 174 printf("| xpdGain: 0x%.2x | xpd: 0x%.2x |\n", mh->xpdGain, mh->xpd); 175 printf("| xpaBiasLvlFreq: 0:0x%.4x 1:0x%.4x 2:0x%.4x |\n", 176 mh->xpaBiasLvlFreq[0], mh->xpaBiasLvlFreq[1], mh->xpaBiasLvlFreq[2]); 177 178 printf("| pdGainOverlap: 0x%.2x | ob: 0x%.2x | db: 0x%.2x | xpaBiasLvl: 0x%.2x |\n", 179 mh->pdGainOverlap, mh->ob, mh->db, mh->xpaBiasLvl); 180 181 printf("| pwrDecreaseFor2Chain: 0x%.2x | pwrDecreaseFor3Chain: 0x%.2x | txFrameToDataStart: 0x%.2x | txFrameToPaOn: 0x%.2x |\n", 182 mh->pwrDecreaseFor2Chain, mh->pwrDecreaseFor3Chain, mh->txFrameToDataStart, 183 mh->txFrameToPaOn); 184 185 printf("| ht40PowerIncForPdadc: 0x%.2x |\n", mh->ht40PowerIncForPdadc); 186 187 printf("| swSettleHt40: 0x%.2x |\n", mh->swSettleHt40); 188 189 printf("| ob_ch1: 0x%.2x | db_ch1: 0x%.2x |\n", mh->ob_ch1, mh->db_ch1); 190 191 printf("| flagBits: 0x%.2x | miscBits: 0x%.2x |\n", mh->flagBits, mh->miscBits); 192 193 194 printf("| futureModal: 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x |\n", 195 mh->futureModal[0], 196 mh->futureModal[1], 197 mh->futureModal[2], 198 mh->futureModal[3], 199 mh->futureModal[4], 200 mh->futureModal[5]); 201 202 /* and now, spur channels */ 203 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) { 204 printf("| Spur %d: spurChan: 0x%.4x spurRangeLow: 0x%.2x spurRangeHigh: 0x%.2x |\n", 205 i, mh->spurChans[i].spurChan, 206 (int) mh->spurChans[i].spurRangeLow, 207 (int) mh->spurChans[i].spurRangeHigh); 208 } 209} 210 211static void 212eeprom_v14_print_caldata_perfreq(CAL_DATA_PER_FREQ *f) 213{ 214 int i, j; 215 216 for (i = 0; i < AR5416_NUM_PD_GAINS; i++) { 217 printf(" Gain %d: pwr dBm/vpd: ", i); 218 for (j = 0; j < AR5416_PD_GAIN_ICEPTS; j++) { 219 /* These are stored in 0.25dBm increments */ 220 printf("%d:(%.2f/%d) ", j, (float) f->pwrPdg[i][j] / 4.00, 221 f->vpdPdg[i][j]); 222 } 223 printf("\n"); 224 } 225} 226 227static void 228eeprom_v14_calfreqpiers_print(uint16_t *buf) 229{ 230 HAL_EEPROM_v14 *eep = (HAL_EEPROM_v14 *) buf; 231 int i, n; 232 233 /* 2ghz cal piers */ 234 printf("calFreqPier2G: "); 235 for (i = 0; i < AR5416_NUM_2G_CAL_PIERS; i++) { 236 printf(" 0x%.2x ", eep->ee_base.calFreqPier2G[i]); 237 } 238 printf("|\n"); 239 240 for (i = 0; i < AR5416_NUM_2G_CAL_PIERS; i++) { 241 if (eep->ee_base.calFreqPier2G[i] == 0xff) 242 continue; 243 printf("2Ghz Cal Pier %d\n", i); 244 for (n = 0; n < AR5416_MAX_CHAINS; n++) { 245 printf(" Chain %d:\n", n); 246 eeprom_v14_print_caldata_perfreq(&eep->ee_base.calPierData2G[n][i]); 247 } 248 } 249 250 printf("\n"); 251 252 /* 5ghz cal piers */ 253 printf("calFreqPier5G: "); 254 for (i = 0; i < AR5416_NUM_5G_CAL_PIERS; i++) { 255 printf(" 0x%.2x ", eep->ee_base.calFreqPier5G[i]); 256 } 257 printf("|\n"); 258 for (i = 0; i < AR5416_NUM_5G_CAL_PIERS; i++) { 259 if (eep->ee_base.calFreqPier5G[i] == 0xff) 260 continue; 261 printf("5Ghz Cal Pier %d\n", i); 262 for (n = 0; n < AR5416_MAX_CHAINS; n++) { 263 printf(" Chain %d:\n", n); 264 eeprom_v14_print_caldata_perfreq(&eep->ee_base.calPierData5G[n][i]); 265 } 266 } 267} 268 269static void 270eeprom_v14_target_legacy_print(CAL_TARGET_POWER_LEG *l) 271{ 272 int i; 273 if (l->bChannel == 0xff) 274 return; 275 printf(" bChannel: %d;", l->bChannel); 276 for (i = 0; i < 4; i++) { 277 printf(" %.2f", (float) l->tPow2x[i] / 2.0); 278 } 279 printf(" (dBm)\n"); 280} 281 282static void 283eeprom_v14_target_ht_print(CAL_TARGET_POWER_HT *l) 284{ 285 int i; 286 if (l->bChannel == 0xff) 287 return; 288 printf(" bChannel: %d;", l->bChannel); 289 for (i = 0; i < 8; i++) { 290 printf(" %.2f", (float) l->tPow2x[i] / 2.0); 291 } 292 printf(" (dBm)\n"); 293} 294 295static void 296eeprom_v14_print_targets(uint16_t *buf) 297{ 298 HAL_EEPROM_v14 *eep = (HAL_EEPROM_v14 *) buf; 299 int i; 300 301 /* 2ghz rates */ 302 printf("2Ghz CCK:\n"); 303 for (i = 0; i < AR5416_NUM_2G_CCK_TARGET_POWERS; i++) { 304 eeprom_v14_target_legacy_print(&eep->ee_base.calTargetPowerCck[i]); 305 } 306 printf("2Ghz 11g:\n"); 307 for (i = 0; i < AR5416_NUM_2G_20_TARGET_POWERS; i++) { 308 eeprom_v14_target_legacy_print(&eep->ee_base.calTargetPower2G[i]); 309 } 310 printf("2Ghz HT20:\n"); 311 for (i = 0; i < AR5416_NUM_2G_20_TARGET_POWERS; i++) { 312 eeprom_v14_target_ht_print(&eep->ee_base.calTargetPower2GHT20[i]); 313 } 314 printf("2Ghz HT40:\n"); 315 for (i = 0; i < AR5416_NUM_2G_40_TARGET_POWERS; i++) { 316 eeprom_v14_target_ht_print(&eep->ee_base.calTargetPower2GHT40[i]); 317 } 318 319 /* 5ghz rates */ 320 printf("5Ghz 11a:\n"); 321 for (i = 0; i < AR5416_NUM_5G_20_TARGET_POWERS; i++) { 322 eeprom_v14_target_legacy_print(&eep->ee_base.calTargetPower5G[i]); 323 } 324 printf("5Ghz HT20:\n"); 325 for (i = 0; i < AR5416_NUM_5G_20_TARGET_POWERS; i++) { 326 eeprom_v14_target_ht_print(&eep->ee_base.calTargetPower5GHT20[i]); 327 } 328 printf("5Ghz HT40:\n"); 329 for (i = 0; i < AR5416_NUM_5G_40_TARGET_POWERS; i++) { 330 eeprom_v14_target_ht_print(&eep->ee_base.calTargetPower5GHT40[i]); 331 } 332 333} 334 335static void 336eeprom_v14_ctl_edge_print(CAL_CTL_DATA *ctl) 337{ 338 int i, j; 339 uint8_t pow, flag; 340 341 for (i = 0; i < AR5416_MAX_CHAINS; i++) { 342 printf(" chain %d: ", i); 343 for (j = 0; j < AR5416_NUM_BAND_EDGES; j++) { 344 pow = ctl->ctlEdges[i][j].tPowerFlag & 0x3f; 345 flag = (ctl->ctlEdges[i][j].tPowerFlag & 0xc0) >> 6; 346 printf(" %d:pow=%d,flag=%.2x", j, pow, flag); 347 } 348 printf("\n"); 349 } 350} 351 352static void 353eeprom_v14_ctl_print(uint16_t *buf) 354{ 355 HAL_EEPROM_v14 *eep = (HAL_EEPROM_v14 *) buf; 356 int i; 357 358 for (i = 0; i < AR5416_NUM_CTLS; i++) { 359 if (eep->ee_base.ctlIndex[i] == 0) 360 continue; 361 printf("| ctlIndex: offset %d, value %d\n", i, eep->ee_base.ctlIndex[i]); 362 eeprom_v14_ctl_edge_print(&eep->ee_base.ctlData[i]); 363 } 364} 365 366static void 367eeprom_v14_print_edges(uint16_t *buf) 368{ 369 HAL_EEPROM_v14 *eep = (HAL_EEPROM_v14 *) buf; 370 int i; 371 372 printf("| eeNumCtls: %d\n", eep->ee_numCtls); 373 for (i = 0; i < NUM_EDGES*eep->ee_numCtls; i++) { 374 /* XXX is flag 8 or 32 bits? */ 375 printf("| edge %2d/%2d: rdEdge: %5d EdgePower: %.2f dBm Flag: 0x%.8x\n", 376 i / NUM_EDGES, i % NUM_EDGES, 377 eep->ee_rdEdgesPower[i].rdEdge, 378 (float) eep->ee_rdEdgesPower[i].twice_rdEdgePower / 2.0, 379 eep->ee_rdEdgesPower[i].flag); 380 381 if (i % NUM_EDGES == (NUM_EDGES -1)) 382 printf("|\n"); 383 } 384#if 0 385typedef struct { 386 uint16_t rdEdge; 387 uint16_t twice_rdEdgePower; 388 HAL_BOOL flag; 389 } RD_EDGES_POWER; 390 391#endif 392} 393 394void 395usage(char *argv[]) 396{ 397 printf("Usage: %s <eeprom dump file>\n", argv[0]); 398 printf("\n"); 399 printf(" The eeprom dump file is a text hexdump of an EEPROM.\n"); 400 printf(" The lines must be formatted as follows:\n"); 401 printf(" 0xAAAA: 0xDD 0xDD 0xDD 0xDD 0xDD 0xDD 0xDD 0xDD\n"); 402 printf(" where each line must have exactly eight data bytes.\n"); 403 exit(127); 404} 405 406int 407main(int argc, char *argv[]) 408{ 409 uint16_t *eep = NULL; 410 eep = calloc(4096, sizeof(int16_t)); 411 412 if (argc < 2) 413 usage(argv); 414 415 load_eeprom_dump(argv[1], eep); 416 417 eeprom_v14_base_print(eep); 418 eeprom_v14_custdata_print(eep); 419 420 /* 2.4ghz */ 421 printf("\n2.4ghz:\n"); 422 eeprom_v14_modal_print(eep, 1); 423 /* 5ghz */ 424 printf("\n5ghz:\n"); 425 eeprom_v14_modal_print(eep, 0); 426 printf("\n"); 427 428 eeprom_v14_calfreqpiers_print(eep); 429 printf("\n"); 430 431 eeprom_v14_print_targets(eep); 432 printf("\n"); 433 434 eeprom_v14_ctl_print(eep); 435 printf("\n"); 436 437 eeprom_v14_print_edges(eep); 438 printf("\n"); 439 440 free(eep); 441 exit(0); 442} 443