FreeBSD kernel ATH device code
ah_eeprom_9287.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: ISC
3 *
4 * Copyright (c) 2008 Sam Leffler, Errno Consulting
5 * Copyright (c) 2010 Atheros Communications, Inc.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 *
19 * $FreeBSD$
20 */
21#include "opt_ah.h"
22
23#include "ah.h"
24#include "ah_internal.h"
25#include "ah_eeprom_v14.h"
26#include "ah_eeprom_9287.h"
27
28static HAL_STATUS
29v9287EepromGet(struct ath_hal *ah, int param, void *val)
30{
31#define CHAN_A_IDX 0
32#define CHAN_B_IDX 1
33#define IS_VERS(op, v) ((pBase->version & AR5416_EEP_VER_MINOR_MASK) op (v))
34 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
35 const MODAL_EEP_9287_HEADER *pModal = &ee->ee_base.modalHeader;
36 const BASE_EEP_9287_HEADER *pBase = &ee->ee_base.baseEepHeader;
37 uint32_t sum;
38 uint8_t *macaddr;
39 int i;
40
41 switch (param) {
43 *(int16_t *)val = pModal->noiseFloorThreshCh[0];
44 return HAL_OK;
45 case AR_EEP_MACADDR: /* Get MAC Address */
46 sum = 0;
47 macaddr = val;
48 for (i = 0; i < 6; i++) {
49 macaddr[i] = pBase->macAddr[i];
50 sum += pBase->macAddr[i];
51 }
52 if (sum == 0 || sum == 0xffff*3) {
53 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad mac address %s\n",
54 __func__, ath_hal_ether_sprintf(macaddr));
55 return HAL_EEBADMAC;
56 }
57 return HAL_OK;
58 case AR_EEP_REGDMN_0:
59 return pBase->regDmn[0];
60 case AR_EEP_REGDMN_1:
61 return pBase->regDmn[1];
62 case AR_EEP_OPCAP:
63 return pBase->deviceCap;
64 case AR_EEP_OPMODE:
65 return pBase->opCapFlags;
66 case AR_EEP_RFSILENT:
67 return pBase->rfSilent;
68 case AR_EEP_TXMASK:
69 return pBase->txMask;
70 case AR_EEP_RXMASK:
71 return pBase->rxMask;
73 HALASSERT(val == AH_NULL);
74 return pBase->openLoopPwrCntl ? HAL_OK : HAL_EIO;
75 case AR_EEP_AMODE:
76 return HAL_EIO; /* no 5GHz for Kiwi */
77 case AR_EEP_BMODE:
78 case AR_EEP_GMODE:
79 HALASSERT(val == AH_NULL);
80 return pBase->opCapFlags & AR5416_OPFLAGS_11G ?
83 case AR_EEP_COMPRESS:
84 case AR_EEP_FASTFRAME: /* XXX policy decision, h/w can do it */
85 case AR_EEP_WRITEPROTECT: /* NB: no write protect bit */
86 HALASSERT(val == AH_NULL);
87 /* fall thru... */
88 case AR_EEP_MAXQCU: /* NB: not in opCapFlags */
89 case AR_EEP_KCENTRIES: /* NB: not in opCapFlags */
90 return HAL_EIO;
91 case AR_EEP_AES:
92 case AR_EEP_BURST:
93 case AR_EEP_RFKILL:
96 HALASSERT(val == AH_NULL);
97 return HAL_OK;
99 *(int8_t *) val = ee->ee_antennaGainMax[1];
100 return HAL_OK;
102 *(int8_t *) val = pBase->pwrTableOffset;
103 return HAL_OK;
106 *(int8_t *)val = pBase->tempSensSlope;
107 else
108 *(int8_t *)val = 0;
109 return HAL_OK;
112 *(int8_t *)val = pBase->tempSensSlopePalOn;
113 else
114 *(int8_t *)val = 0;
115 return HAL_OK;
116 default:
117 HALASSERT(0);
118 return HAL_EINVAL;
119 }
120#undef IS_VERS
121#undef CHAN_A_IDX
122#undef CHAN_B_IDX
123}
124
125static HAL_STATUS
126v9287EepromSet(struct ath_hal *ah, int param, int v)
127{
128 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
129
130 switch (param) {
132 ee->ee_antennaGainMax[1] = (int8_t) v;
133 return HAL_OK;
134 default:
135 return HAL_EINVAL;
136 }
137}
138
139static HAL_BOOL
140v9287EepromDiag(struct ath_hal *ah, int request,
141 const void *args, uint32_t argsize, void **result, uint32_t *resultsize)
142{
143 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
144
145 switch (request) {
146 case HAL_DIAG_EEPROM:
147 *result = ee;
148 *resultsize = sizeof(HAL_EEPROM_9287);
149 return AH_TRUE;
150 }
151 return AH_FALSE;
152}
153
154/* Do structure specific swaps if Eeprom format is non native to host */
155static void
157{
158 uint32_t integer, i;
159 uint16_t word;
160 MODAL_EEP_9287_HEADER *pModal;
161
162 /* convert Base Eep header */
163 word = __bswap16(ee->ee_base.baseEepHeader.length);
164 ee->ee_base.baseEepHeader.length = word;
165
166 word = __bswap16(ee->ee_base.baseEepHeader.checksum);
167 ee->ee_base.baseEepHeader.checksum = word;
168
169 word = __bswap16(ee->ee_base.baseEepHeader.version);
170 ee->ee_base.baseEepHeader.version = word;
171
172 word = __bswap16(ee->ee_base.baseEepHeader.regDmn[0]);
173 ee->ee_base.baseEepHeader.regDmn[0] = word;
174
175 word = __bswap16(ee->ee_base.baseEepHeader.regDmn[1]);
176 ee->ee_base.baseEepHeader.regDmn[1] = word;
177
178 word = __bswap16(ee->ee_base.baseEepHeader.rfSilent);
179 ee->ee_base.baseEepHeader.rfSilent = word;
180
181 word = __bswap16(ee->ee_base.baseEepHeader.blueToothOptions);
183
184 word = __bswap16(ee->ee_base.baseEepHeader.deviceCap);
186
187 /* convert Modal Eep header */
188
189 /* only 2.4ghz here; so only one modal header entry */
190 pModal = &ee->ee_base.modalHeader;
191
192 /* XXX linux/ah_osdep.h only defines __bswap32 for BE */
193 integer = __bswap32(pModal->antCtrlCommon);
194 pModal->antCtrlCommon = integer;
195
196 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
197 integer = __bswap32(pModal->antCtrlChain[i]);
198 pModal->antCtrlChain[i] = integer;
199 }
200 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
201 word = __bswap16(pModal->spurChans[i].spurChan);
202 pModal->spurChans[i].spurChan = word;
203 }
204}
205
206static uint16_t
207v9287EepromGetSpurChan(struct ath_hal *ah, int ix, HAL_BOOL is2GHz)
208{
209 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
210
211 HALASSERT(is2GHz == AH_TRUE);
212 if (is2GHz != AH_TRUE)
213 return 0; /* XXX ? */
214
215 HALASSERT(0 <= ix && ix < AR5416_EEPROM_MODAL_SPURS);
216 return ee->ee_base.modalHeader.spurChans[ix].spurChan;
217}
218
219/**************************************************************************
220 * fbin2freq
221 *
222 * Get channel value from binary representation held in eeprom
223 * RETURNS: the frequency in MHz
224 */
225static uint16_t
226fbin2freq(uint8_t fbin, HAL_BOOL is2GHz)
227{
228 /*
229 * Reserved value 0xFF provides an empty definition both as
230 * an fbin and as a frequency - do not convert
231 */
232 if (fbin == AR5416_BCHAN_UNUSED)
233 return fbin;
234 return (uint16_t)((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
235}
236
237/*
238 * Copy EEPROM Conformance Testing Limits contents
239 * into the allocated space
240 */
241/* USE CTLS from chain zero */
242#define CTL_CHAIN 0
243
244static void
246{
248 int i, j;
249
251
252 for (i = 0; ee->ee_base.ctlIndex[i] != 0 && i < AR9287_NUM_CTLS; i++) {
253 for (j = 0; j < NUM_EDGES; j ++) {
254 /* XXX Confirm this is the right thing to do when an invalid channel is stored */
256 rep[j].rdEdge = 0;
257 rep[j].twice_rdEdgePower = 0;
258 rep[j].flag = 0;
259 } else {
260 rep[j].rdEdge = fbin2freq(
262 (ee->ee_base.ctlIndex[i] & CTL_MODE_M) != CTL_11A);
265 }
266 }
267 rep += NUM_EDGES;
268 }
269 ee->ee_numCtls = i;
271 "%s Numctls = %u\n",__func__,i);
272}
273
274/*
275 * Reclaim any EEPROM-related storage.
276 */
277static void
279{
280 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
281
282 ath_hal_free(ee);
283 AH_PRIVATE(ah)->ah_eeprom = AH_NULL;
284}
285
286#define owl_get_eep_ver(_ee) \
287 (((_ee)->ee_base.baseEepHeader.version >> 12) & 0xF)
288#define owl_get_eep_rev(_ee) \
289 (((_ee)->ee_base.baseEepHeader.version) & 0xFFF)
290
293{
294#define NW(a) (sizeof(a) / sizeof(uint16_t))
295 HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
296 uint16_t *eep_data, magic;
297 HAL_BOOL need_swap;
298 u_int w, off, len;
299 uint32_t sum;
300
301 HALASSERT(ee == AH_NULL);
302
303 /*
304 * Don't check magic if we're supplied with an EEPROM block,
305 * typically this is from Howl but it may also be from later
306 * boards w/ an embedded WMAC.
307 */
308 if (ah->ah_eepromdata == NULL) {
311 "%s Error reading Eeprom MAGIC\n", __func__);
312 return HAL_EEREAD;
313 }
314 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s Eeprom Magic = 0x%x\n",
315 __func__, magic);
316 if (magic != AR5416_EEPROM_MAGIC) {
317 HALDEBUG(ah, HAL_DEBUG_ANY, "Bad magic number\n");
318 return HAL_EEMAGIC;
319 }
320 }
321
322 ee = ath_hal_malloc(sizeof(HAL_EEPROM_9287));
323 if (ee == AH_NULL) {
324 /* XXX message */
325 return HAL_ENOMEM;
326 }
327
328 eep_data = (uint16_t *) ee;
329 for (w = 0; w < NW(struct ar9287_eeprom); w++) {
330 off = AR9287_EEP_START_LOC + w;
331 if (!ath_hal_eepromRead(ah, off, &eep_data[w])) {
333 "%s eeprom read error at offset 0x%x\n",
334 __func__, off);
335 return HAL_EEREAD;
336 }
337 }
338 /* Convert to eeprom native eeprom endian format */
339 /*
340 * XXX this is likely incorrect but will do for now
341 * XXX to get embedded boards working.
342 */
343 if (ah->ah_eepromdata == NULL && isBigEndian()) {
344 for (w = 0; w < NW(HAL_EEPROM_9287); w++)
345 eep_data[w] = __bswap16(eep_data[w]);
346 }
347
348 /*
349 * At this point, we're in the native eeprom endian format
350 * Now, determine the eeprom endian by looking at byte 26??
351 */
353 if (need_swap) {
355 "Byte swap EEPROM contents.\n");
356 len = __bswap16(ee->ee_base.baseEepHeader.length);
357 } else {
358 len = ee->ee_base.baseEepHeader.length;
359 }
360 len = AH_MIN(len, sizeof(HAL_EEPROM_9287)) / sizeof(uint16_t);
361
362 /* Apply the checksum, done in native eeprom format */
363 /* XXX - Need to check to make sure checksum calculation is done
364 * in the correct endian format. Right now, it seems it would
365 * cast the raw data to host format and do the calculation, which may
366 * not be correct as the calculation may need to be done in the native
367 * eeprom format
368 */
369 sum = 0;
370 for (w = 0; w < len; w++)
371 sum ^= eep_data[w];
372 /* Check CRC - Attach should fail on a bad checksum */
373 if (sum != 0xffff) {
375 "Bad EEPROM checksum 0x%x (Len=%u)\n", sum, len);
376 return HAL_EEBADSUM;
377 }
378
379 if (need_swap)
380 eepromSwap(ee); /* byte swap multi-byte data */
381
382 /* swap words 0+2 so version is at the front */
383 magic = eep_data[0];
384 eep_data[0] = eep_data[2];
385 eep_data[2] = magic;
386
388 "%s Eeprom Version %u.%u\n", __func__,
390
391 /* NB: must be after all byte swapping */
392 if (owl_get_eep_ver(ee) != AR5416_EEP_VER) {
394 "Bad EEPROM version 0x%x\n", owl_get_eep_ver(ee));
395 return HAL_EEBADSUM;
396 }
397
398 v9287EepromReadCTLInfo(ah, ee); /* Get CTLs */
399
400 AH_PRIVATE(ah)->ah_eeprom = ee;
401 AH_PRIVATE(ah)->ah_eeversion = ee->ee_base.baseEepHeader.version;
402 AH_PRIVATE(ah)->ah_eepromDetach = v9287EepromDetach;
403 AH_PRIVATE(ah)->ah_eepromGet = v9287EepromGet;
404 AH_PRIVATE(ah)->ah_eepromSet = v9287EepromSet;
405 AH_PRIVATE(ah)->ah_getSpurChan = v9287EepromGetSpurChan;
406 AH_PRIVATE(ah)->ah_eepromDiag = v9287EepromDiag;
407 return HAL_OK;
408#undef NW
409}
HAL_STATUS
Definition: ah.h:71
@ HAL_EIO
Definition: ah.h:75
@ HAL_EEREAD
Definition: ah.h:80
@ HAL_OK
Definition: ah.h:72
@ HAL_EINVAL
Definition: ah.h:84
@ HAL_EEMAGIC
Definition: ah.h:76
@ HAL_EEBADMAC
Definition: ah.h:81
@ HAL_ENOMEM
Definition: ah.h:74
@ HAL_EEBADSUM
Definition: ah.h:79
HAL_BOOL
Definition: ah.h:93
@ AH_FALSE
Definition: ah.h:94
@ AH_TRUE
Definition: ah.h:95
@ HAL_DEBUG_ANY
Definition: ah_debug.h:62
@ HAL_DEBUG_EEPROM
Definition: ah_debug.h:44
@ HAL_DEBUG_ATTACH
Definition: ah_debug.h:30
@ HAL_DIAG_EEPROM
Definition: ah_diagcodes.h:41
#define CTL_MODE_M
Definition: ah_eeprom.h:125
#define CTL_11A
Definition: ah_eeprom.h:126
@ AR_EEP_GMODE
Definition: ah_eeprom.h:72
@ AR_EEP_COMPRESS
Definition: ah_eeprom.h:78
@ AR_EEP_MACADDR
Definition: ah_eeprom.h:77
@ AR_EEP_BMODE
Definition: ah_eeprom.h:71
@ AR_EEP_PWR_TABLE_OFFSET
Definition: ah_eeprom.h:105
@ AR_EEP_TURBO2DISABLE
Definition: ah_eeprom.h:74
@ AR_EEP_ANTGAINMAX_2
Definition: ah_eeprom.h:103
@ AR_EEP_AES
Definition: ah_eeprom.h:80
@ AR_EEP_TEMPSENSE_SLOPE_PAL_ON
Definition: ah_eeprom.h:108
@ AR_EEP_REGDMN_0
Definition: ah_eeprom.h:86
@ AR_EEP_OPMODE
Definition: ah_eeprom.h:89
@ AR_EEP_RXMASK
Definition: ah_eeprom.h:96
@ AR_EEP_TXMASK
Definition: ah_eeprom.h:95
@ AR_EEP_MAXQCU
Definition: ah_eeprom.h:82
@ AR_EEP_KCENTRIES
Definition: ah_eeprom.h:83
@ AR_EEP_BURST
Definition: ah_eeprom.h:81
@ AR_EEP_NFTHRESH_2
Definition: ah_eeprom.h:85
@ AR_EEP_OPCAP
Definition: ah_eeprom.h:88
@ AR_EEP_WRITEPROTECT
Definition: ah_eeprom.h:104
@ AR_EEP_RFKILL
Definition: ah_eeprom.h:69
@ AR_EEP_FASTFRAME
Definition: ah_eeprom.h:79
@ AR_EEP_32KHZCRYSTAL
Definition: ah_eeprom.h:76
@ AR_EEP_RFSILENT
Definition: ah_eeprom.h:90
@ AR_EEP_TEMPSENSE_SLOPE
Definition: ah_eeprom.h:107
@ AR_EEP_TURBO5DISABLE
Definition: ah_eeprom.h:73
@ AR_EEP_REGDMN_1
Definition: ah_eeprom.h:87
@ AR_EEP_AMODE
Definition: ah_eeprom.h:70
@ AR_EEP_OL_PWRCTRL
Definition: ah_eeprom.h:100
HAL_STATUS ath_hal_9287EepromAttach(struct ath_hal *ah)
static uint16_t v9287EepromGetSpurChan(struct ath_hal *ah, int ix, HAL_BOOL is2GHz)
static HAL_STATUS v9287EepromSet(struct ath_hal *ah, int param, int v)
static void v9287EepromDetach(struct ath_hal *ah)
static void v9287EepromReadCTLInfo(struct ath_hal *ah, HAL_EEPROM_9287 *ee)
#define owl_get_eep_rev(_ee)
#define CTL_CHAIN
static HAL_STATUS v9287EepromGet(struct ath_hal *ah, int param, void *val)
#define NW(a)
#define owl_get_eep_ver(_ee)
static uint16_t fbin2freq(uint8_t fbin, HAL_BOOL is2GHz)
#define IS_VERS(op, v)
static void eepromSwap(HAL_EEPROM_9287 *ee)
static HAL_BOOL v9287EepromDiag(struct ath_hal *ah, int request, const void *args, uint32_t argsize, void **result, uint32_t *resultsize)
#define AR9287_NUM_CTLS
#define AR9287_MAX_CHAINS
#define AR9287_EEP_MINOR_VER_3
#define AR9287_EEP_START_LOC
#define AR9287_EEP_MINOR_VER_2
#define NUM_EDGES
#define AR5416_EEPMISC_BIG_ENDIAN
Definition: ah_eeprom_v14.h:82
#define AR5416_EEP_VER
Definition: ah_eeprom_v14.h:46
#define AR5416_EEPROM_MAGIC
Definition: ah_eeprom_v14.h:31
#define AR5416_OPFLAGS_11G
Definition: ah_eeprom_v14.h:99
#define AR5416_EEPROM_MAGIC_OFFSET
Definition: ah_eeprom_v14.h:32
#define CAL_CTL_EDGES_POWER
#define AR5416_EEPROM_MODAL_SPURS
Definition: ah_eeprom_v14.h:76
#define CAL_CTL_EDGES_FLAG
#define AR5416_BCHAN_UNUSED
Definition: ah_eeprom_v14.h:80
#define MS(_v, _f)
Definition: ah_internal.h:588
#define AH_PRIVATE(_ah)
Definition: ah_internal.h:442
void * ath_hal_malloc(size_t)
static __inline__ int isBigEndian(void)
Definition: ah_internal.h:563
#define AH_NULL
Definition: ah_internal.h:28
#define HALASSERT(_x)
Definition: ah_internal.h:683
#define HALDEBUG(_ah, __m,...)
Definition: ah_internal.h:658
#define AH_MIN(a, b)
Definition: ah_internal.h:29
#define ath_hal_eepromRead(_ah, _off, _data)
Definition: ah_internal.h:448
void ath_hal_free(void *p)
Definition: ah_osdep.c:116
const char * ath_hal_ether_sprintf(const u_int8_t *mac)
Definition: ah_osdep.c:137
uint8_t tPowerFlag
uint8_t bChannel
struct ar9287_eeprom ee_base
int8_t ee_antennaGainMax[2]
RD_EDGES_POWER ee_rdEdgesPower[NUM_EDGES *AR9287_NUM_CTLS]
uint16_t twice_rdEdgePower
Definition: ah_eeprom.h:118
uint16_t rdEdge
Definition: ah_eeprom.h:117
HAL_BOOL flag
Definition: ah_eeprom.h:119
struct base_eep_ar9287_header baseEepHeader
struct modal_eep_ar9287_header modalHeader
struct cal_ctl_data_ar9287 ctlData[AR9287_NUM_CTLS]
uint8_t ctlIndex[AR9287_NUM_CTLS]
Definition: ah.h:1219
uint16_t * ah_eepromdata
Definition: ah.h:1235
CAL_CTL_EDGES ctlEdges[AR9287_MAX_CHAINS][AR9287_NUM_BAND_EDGES]
uint32_t antCtrlChain[AR9287_MAX_CHAINS]
int8_t noiseFloorThreshCh[AR9287_MAX_CHAINS]
SPUR_CHAN spurChans[AR5416_EEPROM_MODAL_SPURS]
uint16_t spurChan