16e778a7eSPedro F. Giffuni /*-
26e778a7eSPedro F. Giffuni * SPDX-License-Identifier: ISC
36e778a7eSPedro F. Giffuni *
459efa8b5SSam Leffler * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
514779705SSam Leffler * Copyright (c) 2002-2004 Atheros Communications, Inc.
614779705SSam Leffler *
714779705SSam Leffler * Permission to use, copy, modify, and/or distribute this software for any
814779705SSam Leffler * purpose with or without fee is hereby granted, provided that the above
914779705SSam Leffler * copyright notice and this permission notice appear in all copies.
1014779705SSam Leffler *
1114779705SSam Leffler * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1214779705SSam Leffler * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1314779705SSam Leffler * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1414779705SSam Leffler * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1514779705SSam Leffler * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1614779705SSam Leffler * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1714779705SSam Leffler * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1814779705SSam Leffler */
1914779705SSam Leffler #include "opt_ah.h"
2014779705SSam Leffler
2114779705SSam Leffler #include "ah.h"
2214779705SSam Leffler #include "ah_internal.h"
2314779705SSam Leffler
2414779705SSam Leffler #include "ar5210/ar5210.h"
2514779705SSam Leffler #include "ar5210/ar5210reg.h"
2614779705SSam Leffler #include "ar5210/ar5210phy.h"
2714779705SSam Leffler
2814779705SSam Leffler #include "ah_eeprom_v1.h"
2914779705SSam Leffler
3014779705SSam Leffler #define AR_NUM_GPIO 6 /* 6 GPIO bits */
3114779705SSam Leffler #define AR_GPIOD_MASK 0x2f /* 6-bit mask */
3214779705SSam Leffler
3314779705SSam Leffler void
ar5210GetMacAddress(struct ath_hal * ah,uint8_t * mac)3414779705SSam Leffler ar5210GetMacAddress(struct ath_hal *ah, uint8_t *mac)
3514779705SSam Leffler {
3614779705SSam Leffler struct ath_hal_5210 *ahp = AH5210(ah);
3714779705SSam Leffler
3814779705SSam Leffler OS_MEMCPY(mac, ahp->ah_macaddr, IEEE80211_ADDR_LEN);
3914779705SSam Leffler }
4014779705SSam Leffler
4114779705SSam Leffler HAL_BOOL
ar5210SetMacAddress(struct ath_hal * ah,const uint8_t * mac)4214779705SSam Leffler ar5210SetMacAddress(struct ath_hal *ah, const uint8_t *mac)
4314779705SSam Leffler {
4414779705SSam Leffler struct ath_hal_5210 *ahp = AH5210(ah);
4514779705SSam Leffler
4614779705SSam Leffler OS_MEMCPY(ahp->ah_macaddr, mac, IEEE80211_ADDR_LEN);
4714779705SSam Leffler return AH_TRUE;
4814779705SSam Leffler }
4914779705SSam Leffler
5014779705SSam Leffler void
ar5210GetBssIdMask(struct ath_hal * ah,uint8_t * mask)5114779705SSam Leffler ar5210GetBssIdMask(struct ath_hal *ah, uint8_t *mask)
5214779705SSam Leffler {
5314779705SSam Leffler static const uint8_t ones[IEEE80211_ADDR_LEN] =
5414779705SSam Leffler { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
5514779705SSam Leffler OS_MEMCPY(mask, ones, IEEE80211_ADDR_LEN);
5614779705SSam Leffler }
5714779705SSam Leffler
5814779705SSam Leffler HAL_BOOL
ar5210SetBssIdMask(struct ath_hal * ah,const uint8_t * mask)5914779705SSam Leffler ar5210SetBssIdMask(struct ath_hal *ah, const uint8_t *mask)
6014779705SSam Leffler {
6114779705SSam Leffler return AH_FALSE;
6214779705SSam Leffler }
6314779705SSam Leffler
6414779705SSam Leffler /*
6514779705SSam Leffler * Read 16 bits of data from the specified EEPROM offset.
6614779705SSam Leffler */
6714779705SSam Leffler HAL_BOOL
ar5210EepromRead(struct ath_hal * ah,u_int off,uint16_t * data)6814779705SSam Leffler ar5210EepromRead(struct ath_hal *ah, u_int off, uint16_t *data)
6914779705SSam Leffler {
7014779705SSam Leffler (void) OS_REG_READ(ah, AR_EP_AIR(off)); /* activate read op */
7114779705SSam Leffler if (!ath_hal_wait(ah, AR_EP_STA,
7214779705SSam Leffler AR_EP_STA_RDCMPLT | AR_EP_STA_RDERR, AR_EP_STA_RDCMPLT)) {
7314779705SSam Leffler HALDEBUG(ah, HAL_DEBUG_ANY, "%s: read failed for entry 0x%x\n",
7414779705SSam Leffler __func__, AR_EP_AIR(off));
7514779705SSam Leffler return AH_FALSE;
7614779705SSam Leffler }
7714779705SSam Leffler *data = OS_REG_READ(ah, AR_EP_RDATA) & 0xffff;
7814779705SSam Leffler return AH_TRUE;
7914779705SSam Leffler }
8014779705SSam Leffler
8114779705SSam Leffler #ifdef AH_SUPPORT_WRITE_EEPROM
8214779705SSam Leffler /*
8314779705SSam Leffler * Write 16 bits of data to the specified EEPROM offset.
8414779705SSam Leffler */
8514779705SSam Leffler HAL_BOOL
ar5210EepromWrite(struct ath_hal * ah,u_int off,uint16_t data)8614779705SSam Leffler ar5210EepromWrite(struct ath_hal *ah, u_int off, uint16_t data)
8714779705SSam Leffler {
8814779705SSam Leffler return AH_FALSE;
8914779705SSam Leffler }
9014779705SSam Leffler #endif /* AH_SUPPORT_WRITE_EEPROM */
9114779705SSam Leffler
9214779705SSam Leffler /*
9314779705SSam Leffler * Attempt to change the cards operating regulatory domain to the given value
9414779705SSam Leffler */
9514779705SSam Leffler HAL_BOOL
ar5210SetRegulatoryDomain(struct ath_hal * ah,uint16_t regDomain,HAL_STATUS * status)9614779705SSam Leffler ar5210SetRegulatoryDomain(struct ath_hal *ah,
9714779705SSam Leffler uint16_t regDomain, HAL_STATUS *status)
9814779705SSam Leffler {
9914779705SSam Leffler HAL_STATUS ecode;
10014779705SSam Leffler
10114779705SSam Leffler if (AH_PRIVATE(ah)->ah_currentRD == regDomain) {
10214779705SSam Leffler ecode = HAL_EINVAL;
10314779705SSam Leffler goto bad;
10414779705SSam Leffler }
10514779705SSam Leffler /*
10614779705SSam Leffler * Check if EEPROM is configured to allow this; must
10714779705SSam Leffler * be a proper version and the protection bits must
10814779705SSam Leffler * permit re-writing that segment of the EEPROM.
10914779705SSam Leffler */
11014779705SSam Leffler if (ath_hal_eepromGetFlag(ah, AR_EEP_WRITEPROTECT)) {
11114779705SSam Leffler ecode = HAL_EEWRITE;
11214779705SSam Leffler goto bad;
11314779705SSam Leffler }
11414779705SSam Leffler ecode = HAL_EIO; /* disallow all writes */
11514779705SSam Leffler bad:
11614779705SSam Leffler if (status)
11714779705SSam Leffler *status = ecode;
11814779705SSam Leffler return AH_FALSE;
11914779705SSam Leffler }
12014779705SSam Leffler
12114779705SSam Leffler /*
12214779705SSam Leffler * Return the wireless modes (a,b,g,t) supported by hardware.
12314779705SSam Leffler *
12414779705SSam Leffler * This value is what is actually supported by the hardware
12514779705SSam Leffler * and is unaffected by regulatory/country code settings.
12614779705SSam Leffler *
12714779705SSam Leffler */
12814779705SSam Leffler u_int
ar5210GetWirelessModes(struct ath_hal * ah)12914779705SSam Leffler ar5210GetWirelessModes(struct ath_hal *ah)
13014779705SSam Leffler {
13114779705SSam Leffler /* XXX could enable turbo mode but can't do all rates */
13214779705SSam Leffler return HAL_MODE_11A;
13314779705SSam Leffler }
13414779705SSam Leffler
13514779705SSam Leffler /*
13614779705SSam Leffler * Called if RfKill is supported (according to EEPROM). Set the interrupt and
13714779705SSam Leffler * GPIO values so the ISR and can disable RF on a switch signal
13814779705SSam Leffler */
13914779705SSam Leffler void
ar5210EnableRfKill(struct ath_hal * ah)14014779705SSam Leffler ar5210EnableRfKill(struct ath_hal *ah)
14114779705SSam Leffler {
14214779705SSam Leffler uint16_t rfsilent = AH_PRIVATE(ah)->ah_rfsilent;
14314779705SSam Leffler int select = MS(rfsilent, AR_EEPROM_RFSILENT_GPIO_SEL);
14414779705SSam Leffler int polarity = MS(rfsilent, AR_EEPROM_RFSILENT_POLARITY);
14514779705SSam Leffler
14614779705SSam Leffler /*
14714779705SSam Leffler * If radio disable switch connection to GPIO bit 0 is enabled
14814779705SSam Leffler * program GPIO interrupt.
14914779705SSam Leffler * If rfkill bit on eeprom is 1, setupeeprommap routine has already
15014779705SSam Leffler * verified that it is a later version of eeprom, it has a place for
15114779705SSam Leffler * rfkill bit and it is set to 1, indicating that GPIO bit 0 hardware
15214779705SSam Leffler * connection is present.
15314779705SSam Leffler */
15414779705SSam Leffler ar5210Gpio0SetIntr(ah, select, (ar5210GpioGet(ah, select) == polarity));
15514779705SSam Leffler }
15614779705SSam Leffler
15714779705SSam Leffler /*
15814779705SSam Leffler * Configure GPIO Output lines
15914779705SSam Leffler */
16014779705SSam Leffler HAL_BOOL
ar5210GpioCfgOutput(struct ath_hal * ah,uint32_t gpio,HAL_GPIO_MUX_TYPE type)161869ff02eSSam Leffler ar5210GpioCfgOutput(struct ath_hal *ah, uint32_t gpio, HAL_GPIO_MUX_TYPE type)
16214779705SSam Leffler {
16314779705SSam Leffler HALASSERT(gpio < AR_NUM_GPIO);
16414779705SSam Leffler
16514779705SSam Leffler OS_REG_WRITE(ah, AR_GPIOCR,
16614779705SSam Leffler (OS_REG_READ(ah, AR_GPIOCR) &~ AR_GPIOCR_ALL(gpio))
16714779705SSam Leffler | AR_GPIOCR_OUT1(gpio));
16814779705SSam Leffler
16914779705SSam Leffler return AH_TRUE;
17014779705SSam Leffler }
17114779705SSam Leffler
17214779705SSam Leffler /*
17314779705SSam Leffler * Configure GPIO Input lines
17414779705SSam Leffler */
17514779705SSam Leffler HAL_BOOL
ar5210GpioCfgInput(struct ath_hal * ah,uint32_t gpio)17614779705SSam Leffler ar5210GpioCfgInput(struct ath_hal *ah, uint32_t gpio)
17714779705SSam Leffler {
17814779705SSam Leffler HALASSERT(gpio < AR_NUM_GPIO);
17914779705SSam Leffler
18014779705SSam Leffler OS_REG_WRITE(ah, AR_GPIOCR,
18114779705SSam Leffler (OS_REG_READ(ah, AR_GPIOCR) &~ AR_GPIOCR_ALL(gpio))
18214779705SSam Leffler | AR_GPIOCR_IN(gpio));
18314779705SSam Leffler
18414779705SSam Leffler return AH_TRUE;
18514779705SSam Leffler }
18614779705SSam Leffler
18714779705SSam Leffler /*
18814779705SSam Leffler * Once configured for I/O - set output lines
18914779705SSam Leffler */
19014779705SSam Leffler HAL_BOOL
ar5210GpioSet(struct ath_hal * ah,uint32_t gpio,uint32_t val)19114779705SSam Leffler ar5210GpioSet(struct ath_hal *ah, uint32_t gpio, uint32_t val)
19214779705SSam Leffler {
19314779705SSam Leffler uint32_t reg;
19414779705SSam Leffler
19514779705SSam Leffler HALASSERT(gpio < AR_NUM_GPIO);
19614779705SSam Leffler
19714779705SSam Leffler reg = OS_REG_READ(ah, AR_GPIODO);
19814779705SSam Leffler reg &= ~(1 << gpio);
19914779705SSam Leffler reg |= (val&1) << gpio;
20014779705SSam Leffler
20114779705SSam Leffler OS_REG_WRITE(ah, AR_GPIODO, reg);
20214779705SSam Leffler return AH_TRUE;
20314779705SSam Leffler }
20414779705SSam Leffler
20514779705SSam Leffler /*
20614779705SSam Leffler * Once configured for I/O - get input lines
20714779705SSam Leffler */
20814779705SSam Leffler uint32_t
ar5210GpioGet(struct ath_hal * ah,uint32_t gpio)20914779705SSam Leffler ar5210GpioGet(struct ath_hal *ah, uint32_t gpio)
21014779705SSam Leffler {
21114779705SSam Leffler if (gpio < AR_NUM_GPIO) {
21214779705SSam Leffler uint32_t val = OS_REG_READ(ah, AR_GPIODI);
21314779705SSam Leffler val = ((val & AR_GPIOD_MASK) >> gpio) & 0x1;
21414779705SSam Leffler return val;
21514779705SSam Leffler } else {
21614779705SSam Leffler return 0xffffffff;
21714779705SSam Leffler }
21814779705SSam Leffler }
21914779705SSam Leffler
22014779705SSam Leffler /*
22114779705SSam Leffler * Set the GPIO 0 Interrupt
22214779705SSam Leffler */
22314779705SSam Leffler void
ar5210Gpio0SetIntr(struct ath_hal * ah,u_int gpio,uint32_t ilevel)22414779705SSam Leffler ar5210Gpio0SetIntr(struct ath_hal *ah, u_int gpio, uint32_t ilevel)
22514779705SSam Leffler {
22614779705SSam Leffler uint32_t val = OS_REG_READ(ah, AR_GPIOCR);
22714779705SSam Leffler
22814779705SSam Leffler /* Clear the bits that we will modify. */
22914779705SSam Leffler val &= ~(AR_GPIOCR_INT_SEL(gpio) | AR_GPIOCR_INT_SELH | AR_GPIOCR_INT_ENA |
23014779705SSam Leffler AR_GPIOCR_ALL(gpio));
23114779705SSam Leffler
23214779705SSam Leffler val |= AR_GPIOCR_INT_SEL(gpio) | AR_GPIOCR_INT_ENA;
23314779705SSam Leffler if (ilevel)
23414779705SSam Leffler val |= AR_GPIOCR_INT_SELH;
23514779705SSam Leffler
23614779705SSam Leffler /* Don't need to change anything for low level interrupt. */
23714779705SSam Leffler OS_REG_WRITE(ah, AR_GPIOCR, val);
23814779705SSam Leffler
23914779705SSam Leffler /* Change the interrupt mask. */
24014779705SSam Leffler ar5210SetInterrupts(ah, AH5210(ah)->ah_maskReg | HAL_INT_GPIO);
24114779705SSam Leffler }
24214779705SSam Leffler
24314779705SSam Leffler /*
24414779705SSam Leffler * Change the LED blinking pattern to correspond to the connectivity
24514779705SSam Leffler */
24614779705SSam Leffler void
ar5210SetLedState(struct ath_hal * ah,HAL_LED_STATE state)24714779705SSam Leffler ar5210SetLedState(struct ath_hal *ah, HAL_LED_STATE state)
24814779705SSam Leffler {
24914779705SSam Leffler uint32_t val;
25014779705SSam Leffler
25114779705SSam Leffler val = OS_REG_READ(ah, AR_PCICFG);
25214779705SSam Leffler switch (state) {
25314779705SSam Leffler case HAL_LED_INIT:
25414779705SSam Leffler val &= ~(AR_PCICFG_LED_PEND | AR_PCICFG_LED_ACT);
25514779705SSam Leffler break;
25614779705SSam Leffler case HAL_LED_RUN:
25714779705SSam Leffler /* normal blink when connected */
25814779705SSam Leffler val &= ~AR_PCICFG_LED_PEND;
25914779705SSam Leffler val |= AR_PCICFG_LED_ACT;
26014779705SSam Leffler break;
26114779705SSam Leffler default:
26214779705SSam Leffler val |= AR_PCICFG_LED_PEND;
26314779705SSam Leffler val &= ~AR_PCICFG_LED_ACT;
26414779705SSam Leffler break;
26514779705SSam Leffler }
26614779705SSam Leffler OS_REG_WRITE(ah, AR_PCICFG, val);
26714779705SSam Leffler }
26814779705SSam Leffler
26914779705SSam Leffler /*
27014779705SSam Leffler * Return 1 or 2 for the corresponding antenna that is in use
27114779705SSam Leffler */
27214779705SSam Leffler u_int
ar5210GetDefAntenna(struct ath_hal * ah)27314779705SSam Leffler ar5210GetDefAntenna(struct ath_hal *ah)
27414779705SSam Leffler {
27514779705SSam Leffler uint32_t val = OS_REG_READ(ah, AR_STA_ID1);
27614779705SSam Leffler return (val & AR_STA_ID1_DEFAULT_ANTENNA ? 2 : 1);
27714779705SSam Leffler }
27814779705SSam Leffler
27914779705SSam Leffler void
ar5210SetDefAntenna(struct ath_hal * ah,u_int antenna)28014779705SSam Leffler ar5210SetDefAntenna(struct ath_hal *ah, u_int antenna)
28114779705SSam Leffler {
28214779705SSam Leffler uint32_t val = OS_REG_READ(ah, AR_STA_ID1);
28314779705SSam Leffler
28414779705SSam Leffler if (antenna != (val & AR_STA_ID1_DEFAULT_ANTENNA ? 2 : 1)) {
28514779705SSam Leffler /*
28614779705SSam Leffler * Antenna change requested, force a toggle of the default.
28714779705SSam Leffler */
28814779705SSam Leffler OS_REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_DEFAULT_ANTENNA);
28914779705SSam Leffler }
29014779705SSam Leffler }
29114779705SSam Leffler
29214779705SSam Leffler HAL_ANT_SETTING
ar5210GetAntennaSwitch(struct ath_hal * ah)29314779705SSam Leffler ar5210GetAntennaSwitch(struct ath_hal *ah)
29414779705SSam Leffler {
29514779705SSam Leffler return HAL_ANT_VARIABLE;
29614779705SSam Leffler }
29714779705SSam Leffler
29814779705SSam Leffler HAL_BOOL
ar5210SetAntennaSwitch(struct ath_hal * ah,HAL_ANT_SETTING settings)29914779705SSam Leffler ar5210SetAntennaSwitch(struct ath_hal *ah, HAL_ANT_SETTING settings)
30014779705SSam Leffler {
30114779705SSam Leffler /* XXX not sure how to fix antenna */
30214779705SSam Leffler return (settings == HAL_ANT_VARIABLE);
30314779705SSam Leffler }
30414779705SSam Leffler
30514779705SSam Leffler /*
30614779705SSam Leffler * Change association related fields programmed into the hardware.
30714779705SSam Leffler * Writing a valid BSSID to the hardware effectively enables the hardware
30814779705SSam Leffler * to synchronize its TSF to the correct beacons and receive frames coming
30914779705SSam Leffler * from that BSSID. It is called by the SME JOIN operation.
31014779705SSam Leffler */
31114779705SSam Leffler void
ar5210WriteAssocid(struct ath_hal * ah,const uint8_t * bssid,uint16_t assocId)31214779705SSam Leffler ar5210WriteAssocid(struct ath_hal *ah, const uint8_t *bssid, uint16_t assocId)
31314779705SSam Leffler {
31414779705SSam Leffler struct ath_hal_5210 *ahp = AH5210(ah);
31514779705SSam Leffler
31614779705SSam Leffler /* XXX save bssid for possible re-use on reset */
31714779705SSam Leffler OS_MEMCPY(ahp->ah_bssid, bssid, IEEE80211_ADDR_LEN);
3189b34359bSAdrian Chadd ahp->ah_associd = assocId;
31914779705SSam Leffler OS_REG_WRITE(ah, AR_BSS_ID0, LE_READ_4(ahp->ah_bssid));
32014779705SSam Leffler OS_REG_WRITE(ah, AR_BSS_ID1, LE_READ_2(ahp->ah_bssid+4) |
32114779705SSam Leffler ((assocId & 0x3fff)<<AR_BSS_ID1_AID_S));
32214779705SSam Leffler if (assocId == 0)
32314779705SSam Leffler OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_NO_PSPOLL);
32414779705SSam Leffler else
32514779705SSam Leffler OS_REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_NO_PSPOLL);
32614779705SSam Leffler }
32714779705SSam Leffler
32814779705SSam Leffler /*
32914779705SSam Leffler * Get the current hardware tsf for stamlme.
33014779705SSam Leffler */
33114779705SSam Leffler uint64_t
ar5210GetTsf64(struct ath_hal * ah)33214779705SSam Leffler ar5210GetTsf64(struct ath_hal *ah)
33314779705SSam Leffler {
33414779705SSam Leffler uint32_t low1, low2, u32;
33514779705SSam Leffler
33614779705SSam Leffler /* sync multi-word read */
33714779705SSam Leffler low1 = OS_REG_READ(ah, AR_TSF_L32);
33814779705SSam Leffler u32 = OS_REG_READ(ah, AR_TSF_U32);
33914779705SSam Leffler low2 = OS_REG_READ(ah, AR_TSF_L32);
34014779705SSam Leffler if (low2 < low1) { /* roll over */
34114779705SSam Leffler /*
34214779705SSam Leffler * If we are not preempted this will work. If we are
34314779705SSam Leffler * then we re-reading AR_TSF_U32 does no good as the
34414779705SSam Leffler * low bits will be meaningless. Likewise reading
34514779705SSam Leffler * L32, U32, U32, then comparing the last two reads
34614779705SSam Leffler * to check for rollover doesn't help if preempted--so
34714779705SSam Leffler * we take this approach as it costs one less PCI
34814779705SSam Leffler * read which can be noticeable when doing things
34914779705SSam Leffler * like timestamping packets in monitor mode.
35014779705SSam Leffler */
35114779705SSam Leffler u32++;
35214779705SSam Leffler }
35314779705SSam Leffler return (((uint64_t) u32) << 32) | ((uint64_t) low2);
35414779705SSam Leffler }
35514779705SSam Leffler
35614779705SSam Leffler /*
35714779705SSam Leffler * Get the current hardware tsf for stamlme.
35814779705SSam Leffler */
35914779705SSam Leffler uint32_t
ar5210GetTsf32(struct ath_hal * ah)36014779705SSam Leffler ar5210GetTsf32(struct ath_hal *ah)
36114779705SSam Leffler {
36214779705SSam Leffler return OS_REG_READ(ah, AR_TSF_L32);
36314779705SSam Leffler }
36414779705SSam Leffler
36514779705SSam Leffler /*
36614779705SSam Leffler * Reset the current hardware tsf for stamlme
36714779705SSam Leffler */
36814779705SSam Leffler void
ar5210ResetTsf(struct ath_hal * ah)36914779705SSam Leffler ar5210ResetTsf(struct ath_hal *ah)
37014779705SSam Leffler {
37114779705SSam Leffler uint32_t val = OS_REG_READ(ah, AR_BEACON);
37214779705SSam Leffler
37314779705SSam Leffler OS_REG_WRITE(ah, AR_BEACON, val | AR_BEACON_RESET_TSF);
37414779705SSam Leffler }
37514779705SSam Leffler
37614779705SSam Leffler /*
37714779705SSam Leffler * Grab a semi-random value from hardware registers - may not
37814779705SSam Leffler * change often
37914779705SSam Leffler */
38014779705SSam Leffler uint32_t
ar5210GetRandomSeed(struct ath_hal * ah)38114779705SSam Leffler ar5210GetRandomSeed(struct ath_hal *ah)
38214779705SSam Leffler {
38314779705SSam Leffler uint32_t nf;
38414779705SSam Leffler
38514779705SSam Leffler nf = (OS_REG_READ(ah, AR_PHY_BASE + (25 << 2)) >> 19) & 0x1ff;
38614779705SSam Leffler if (nf & 0x100)
38714779705SSam Leffler nf = 0 - ((nf ^ 0x1ff) + 1);
38814779705SSam Leffler return (OS_REG_READ(ah, AR_TSF_U32) ^
38914779705SSam Leffler OS_REG_READ(ah, AR_TSF_L32) ^ nf);
39014779705SSam Leffler }
39114779705SSam Leffler
39214779705SSam Leffler /*
39314779705SSam Leffler * Detect if our card is present
39414779705SSam Leffler */
39514779705SSam Leffler HAL_BOOL
ar5210DetectCardPresent(struct ath_hal * ah)39614779705SSam Leffler ar5210DetectCardPresent(struct ath_hal *ah)
39714779705SSam Leffler {
39814779705SSam Leffler /*
39914779705SSam Leffler * Read the Silicon Revision register and compare that
40014779705SSam Leffler * to what we read at attach time. If the same, we say
40114779705SSam Leffler * a card/device is present.
40214779705SSam Leffler */
40314779705SSam Leffler return (AH_PRIVATE(ah)->ah_macRev == (OS_REG_READ(ah, AR_SREV) & 0xff));
40414779705SSam Leffler }
40514779705SSam Leffler
40614779705SSam Leffler /*
40714779705SSam Leffler * Update MIB Counters
40814779705SSam Leffler */
40914779705SSam Leffler void
ar5210UpdateMibCounters(struct ath_hal * ah,HAL_MIB_STATS * stats)41014779705SSam Leffler ar5210UpdateMibCounters(struct ath_hal *ah, HAL_MIB_STATS *stats)
41114779705SSam Leffler {
41214779705SSam Leffler stats->ackrcv_bad += OS_REG_READ(ah, AR_ACK_FAIL);
41314779705SSam Leffler stats->rts_bad += OS_REG_READ(ah, AR_RTS_FAIL);
41414779705SSam Leffler stats->fcs_bad += OS_REG_READ(ah, AR_FCS_FAIL);
41514779705SSam Leffler stats->rts_good += OS_REG_READ(ah, AR_RTS_OK);
41614779705SSam Leffler stats->beacons += OS_REG_READ(ah, AR_BEACON_CNT);
41714779705SSam Leffler }
41814779705SSam Leffler
41914779705SSam Leffler HAL_BOOL
ar5210SetSifsTime(struct ath_hal * ah,u_int us)42014779705SSam Leffler ar5210SetSifsTime(struct ath_hal *ah, u_int us)
42114779705SSam Leffler {
42214779705SSam Leffler struct ath_hal_5210 *ahp = AH5210(ah);
42314779705SSam Leffler
42414779705SSam Leffler if (us > ath_hal_mac_usec(ah, 0x7ff)) {
42514779705SSam Leffler HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad SIFS time %u\n",
42614779705SSam Leffler __func__, us);
42714779705SSam Leffler ahp->ah_sifstime = (u_int) -1; /* restore default handling */
42814779705SSam Leffler return AH_FALSE;
42914779705SSam Leffler } else {
43014779705SSam Leffler /* convert to system clocks */
43114779705SSam Leffler OS_REG_RMW_FIELD(ah, AR_IFS0, AR_IFS0_SIFS,
43214779705SSam Leffler ath_hal_mac_clks(ah, us));
43314779705SSam Leffler ahp->ah_sifstime = us;
43414779705SSam Leffler return AH_TRUE;
43514779705SSam Leffler }
43614779705SSam Leffler }
43714779705SSam Leffler
43814779705SSam Leffler u_int
ar5210GetSifsTime(struct ath_hal * ah)43914779705SSam Leffler ar5210GetSifsTime(struct ath_hal *ah)
44014779705SSam Leffler {
44114779705SSam Leffler u_int clks = OS_REG_READ(ah, AR_IFS0) & 0x7ff;
44214779705SSam Leffler return ath_hal_mac_usec(ah, clks); /* convert from system clocks */
44314779705SSam Leffler }
44414779705SSam Leffler
44514779705SSam Leffler HAL_BOOL
ar5210SetSlotTime(struct ath_hal * ah,u_int us)44614779705SSam Leffler ar5210SetSlotTime(struct ath_hal *ah, u_int us)
44714779705SSam Leffler {
44814779705SSam Leffler struct ath_hal_5210 *ahp = AH5210(ah);
44914779705SSam Leffler
45014779705SSam Leffler if (us < HAL_SLOT_TIME_9 || us > ath_hal_mac_usec(ah, 0xffff)) {
45114779705SSam Leffler HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad slot time %u\n",
45214779705SSam Leffler __func__, us);
45314779705SSam Leffler ahp->ah_slottime = (u_int) -1; /* restore default handling */
45414779705SSam Leffler return AH_FALSE;
45514779705SSam Leffler } else {
45614779705SSam Leffler /* convert to system clocks */
45714779705SSam Leffler OS_REG_WRITE(ah, AR_SLOT_TIME, ath_hal_mac_clks(ah, us));
45814779705SSam Leffler ahp->ah_slottime = us;
45914779705SSam Leffler return AH_TRUE;
46014779705SSam Leffler }
46114779705SSam Leffler }
46214779705SSam Leffler
46314779705SSam Leffler u_int
ar5210GetSlotTime(struct ath_hal * ah)46414779705SSam Leffler ar5210GetSlotTime(struct ath_hal *ah)
46514779705SSam Leffler {
46614779705SSam Leffler u_int clks = OS_REG_READ(ah, AR_SLOT_TIME) & 0xffff;
46714779705SSam Leffler return ath_hal_mac_usec(ah, clks); /* convert from system clocks */
46814779705SSam Leffler }
46914779705SSam Leffler
47014779705SSam Leffler HAL_BOOL
ar5210SetAckTimeout(struct ath_hal * ah,u_int us)47114779705SSam Leffler ar5210SetAckTimeout(struct ath_hal *ah, u_int us)
47214779705SSam Leffler {
47314779705SSam Leffler struct ath_hal_5210 *ahp = AH5210(ah);
47414779705SSam Leffler
47514779705SSam Leffler if (us > ath_hal_mac_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
47614779705SSam Leffler HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad ack timeout %u\n",
47714779705SSam Leffler __func__, us);
47814779705SSam Leffler ahp->ah_acktimeout = (u_int) -1; /* restore default handling */
47914779705SSam Leffler return AH_FALSE;
48014779705SSam Leffler } else {
48114779705SSam Leffler /* convert to system clocks */
48214779705SSam Leffler OS_REG_RMW_FIELD(ah, AR_TIME_OUT,
48314779705SSam Leffler AR_TIME_OUT_ACK, ath_hal_mac_clks(ah, us));
48414779705SSam Leffler ahp->ah_acktimeout = us;
48514779705SSam Leffler return AH_TRUE;
48614779705SSam Leffler }
48714779705SSam Leffler }
48814779705SSam Leffler
48914779705SSam Leffler u_int
ar5210GetAckTimeout(struct ath_hal * ah)49014779705SSam Leffler ar5210GetAckTimeout(struct ath_hal *ah)
49114779705SSam Leffler {
49214779705SSam Leffler u_int clks = MS(OS_REG_READ(ah, AR_TIME_OUT), AR_TIME_OUT_ACK);
49314779705SSam Leffler return ath_hal_mac_usec(ah, clks); /* convert from system clocks */
49414779705SSam Leffler }
49514779705SSam Leffler
49614779705SSam Leffler u_int
ar5210GetAckCTSRate(struct ath_hal * ah)49714779705SSam Leffler ar5210GetAckCTSRate(struct ath_hal *ah)
49814779705SSam Leffler {
49914779705SSam Leffler return ((AH5210(ah)->ah_staId1Defaults & AR_STA_ID1_ACKCTS_6MB) == 0);
50014779705SSam Leffler }
50114779705SSam Leffler
50214779705SSam Leffler HAL_BOOL
ar5210SetAckCTSRate(struct ath_hal * ah,u_int high)50314779705SSam Leffler ar5210SetAckCTSRate(struct ath_hal *ah, u_int high)
50414779705SSam Leffler {
50514779705SSam Leffler struct ath_hal_5210 *ahp = AH5210(ah);
50614779705SSam Leffler
50714779705SSam Leffler if (high) {
50814779705SSam Leffler OS_REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_ACKCTS_6MB);
50914779705SSam Leffler ahp->ah_staId1Defaults &= ~AR_STA_ID1_ACKCTS_6MB;
51014779705SSam Leffler } else {
51114779705SSam Leffler OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_ACKCTS_6MB);
51214779705SSam Leffler ahp->ah_staId1Defaults |= AR_STA_ID1_ACKCTS_6MB;
51314779705SSam Leffler }
51414779705SSam Leffler return AH_TRUE;
51514779705SSam Leffler }
51614779705SSam Leffler
51714779705SSam Leffler HAL_BOOL
ar5210SetCTSTimeout(struct ath_hal * ah,u_int us)51814779705SSam Leffler ar5210SetCTSTimeout(struct ath_hal *ah, u_int us)
51914779705SSam Leffler {
52014779705SSam Leffler struct ath_hal_5210 *ahp = AH5210(ah);
52114779705SSam Leffler
52214779705SSam Leffler if (us > ath_hal_mac_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
52314779705SSam Leffler HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad cts timeout %u\n",
52414779705SSam Leffler __func__, us);
52514779705SSam Leffler ahp->ah_ctstimeout = (u_int) -1; /* restore default handling */
52614779705SSam Leffler return AH_FALSE;
52714779705SSam Leffler } else {
52814779705SSam Leffler /* convert to system clocks */
52914779705SSam Leffler OS_REG_RMW_FIELD(ah, AR_TIME_OUT,
53014779705SSam Leffler AR_TIME_OUT_CTS, ath_hal_mac_clks(ah, us));
53114779705SSam Leffler ahp->ah_ctstimeout = us;
53214779705SSam Leffler return AH_TRUE;
53314779705SSam Leffler }
53414779705SSam Leffler }
53514779705SSam Leffler
53614779705SSam Leffler u_int
ar5210GetCTSTimeout(struct ath_hal * ah)53714779705SSam Leffler ar5210GetCTSTimeout(struct ath_hal *ah)
53814779705SSam Leffler {
53914779705SSam Leffler u_int clks = MS(OS_REG_READ(ah, AR_TIME_OUT), AR_TIME_OUT_CTS);
54014779705SSam Leffler return ath_hal_mac_usec(ah, clks); /* convert from system clocks */
54114779705SSam Leffler }
54214779705SSam Leffler
54314779705SSam Leffler HAL_BOOL
ar5210SetDecompMask(struct ath_hal * ah,uint16_t keyidx,int en)54414779705SSam Leffler ar5210SetDecompMask(struct ath_hal *ah, uint16_t keyidx, int en)
54514779705SSam Leffler {
54614779705SSam Leffler /* nothing to do */
54714779705SSam Leffler return AH_TRUE;
54814779705SSam Leffler }
54914779705SSam Leffler
55014779705SSam Leffler void
ar5210SetCoverageClass(struct ath_hal * ah,uint8_t coverageclass,int now)55114779705SSam Leffler ar5210SetCoverageClass(struct ath_hal *ah, uint8_t coverageclass, int now)
55214779705SSam Leffler {
55314779705SSam Leffler }
55414779705SSam Leffler
555aa36f34dSAdrian Chadd HAL_STATUS
ar5210SetQuiet(struct ath_hal * ah,uint32_t period,uint32_t duration,uint32_t next_start,HAL_QUIET_FLAG flags)556aa36f34dSAdrian Chadd ar5210SetQuiet(struct ath_hal *ah, uint32_t period, uint32_t duration,
557aa36f34dSAdrian Chadd uint32_t next_start, HAL_QUIET_FLAG flags)
558aa36f34dSAdrian Chadd {
559aa36f34dSAdrian Chadd return HAL_OK;
560aa36f34dSAdrian Chadd }
561aa36f34dSAdrian Chadd
56214779705SSam Leffler /*
56314779705SSam Leffler * Control Adaptive Noise Immunity Parameters
56414779705SSam Leffler */
56514779705SSam Leffler HAL_BOOL
ar5210AniControl(struct ath_hal * ah,HAL_ANI_CMD cmd,int param)56614779705SSam Leffler ar5210AniControl(struct ath_hal *ah, HAL_ANI_CMD cmd, int param)
56714779705SSam Leffler {
56814779705SSam Leffler return AH_FALSE;
56914779705SSam Leffler }
57014779705SSam Leffler
57114779705SSam Leffler void
ar5210RxMonitor(struct ath_hal * ah,const HAL_NODE_STATS * stats,const struct ieee80211_channel * chan)572a108ab63SAdrian Chadd ar5210RxMonitor(struct ath_hal *ah, const HAL_NODE_STATS *stats,
57359efa8b5SSam Leffler const struct ieee80211_channel *chan)
57414779705SSam Leffler {
57514779705SSam Leffler }
57614779705SSam Leffler
57714779705SSam Leffler void
ar5210AniPoll(struct ath_hal * ah,const struct ieee80211_channel * chan)578a108ab63SAdrian Chadd ar5210AniPoll(struct ath_hal *ah, const struct ieee80211_channel *chan)
579a108ab63SAdrian Chadd {
580a108ab63SAdrian Chadd }
581a108ab63SAdrian Chadd
582a108ab63SAdrian Chadd void
ar5210MibEvent(struct ath_hal * ah,const HAL_NODE_STATS * stats)58314779705SSam Leffler ar5210MibEvent(struct ath_hal *ah, const HAL_NODE_STATS *stats)
58414779705SSam Leffler {
58514779705SSam Leffler }
58614779705SSam Leffler
58714779705SSam Leffler HAL_STATUS
ar5210GetCapability(struct ath_hal * ah,HAL_CAPABILITY_TYPE type,uint32_t capability,uint32_t * result)58814779705SSam Leffler ar5210GetCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
58914779705SSam Leffler uint32_t capability, uint32_t *result)
59014779705SSam Leffler {
59114779705SSam Leffler
59214779705SSam Leffler switch (type) {
59314779705SSam Leffler case HAL_CAP_CIPHER: /* cipher handled in hardware */
594143cfad7SAdrian Chadd #if 0
59514779705SSam Leffler return (capability == HAL_CIPHER_WEP ? HAL_OK : HAL_ENOTSUPP);
596143cfad7SAdrian Chadd #else
597143cfad7SAdrian Chadd return HAL_ENOTSUPP;
598143cfad7SAdrian Chadd #endif
59914779705SSam Leffler default:
60014779705SSam Leffler return ath_hal_getcapability(ah, type, capability, result);
60114779705SSam Leffler }
60214779705SSam Leffler }
60314779705SSam Leffler
60414779705SSam Leffler HAL_BOOL
ar5210SetCapability(struct ath_hal * ah,HAL_CAPABILITY_TYPE type,uint32_t capability,uint32_t setting,HAL_STATUS * status)60514779705SSam Leffler ar5210SetCapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
60614779705SSam Leffler uint32_t capability, uint32_t setting, HAL_STATUS *status)
60714779705SSam Leffler {
60814779705SSam Leffler
60914779705SSam Leffler switch (type) {
61014779705SSam Leffler case HAL_CAP_DIAG: /* hardware diagnostic support */
61114779705SSam Leffler /*
61214779705SSam Leffler * NB: could split this up into virtual capabilities,
61314779705SSam Leffler * (e.g. 1 => ACK, 2 => CTS, etc.) but it hardly
61414779705SSam Leffler * seems worth the additional complexity.
61514779705SSam Leffler */
61614779705SSam Leffler #ifdef AH_DEBUG
61714779705SSam Leffler AH_PRIVATE(ah)->ah_diagreg = setting;
61814779705SSam Leffler #else
61914779705SSam Leffler AH_PRIVATE(ah)->ah_diagreg = setting & 0x6; /* ACK+CTS */
62014779705SSam Leffler #endif
621143cfad7SAdrian Chadd ar5210UpdateDiagReg(ah, AH_PRIVATE(ah)->ah_diagreg);
62214779705SSam Leffler return AH_TRUE;
62314779705SSam Leffler case HAL_CAP_RXORN_FATAL: /* HAL_INT_RXORN treated as fatal */
62414779705SSam Leffler return AH_FALSE; /* NB: disallow */
62514779705SSam Leffler default:
62614779705SSam Leffler return ath_hal_setcapability(ah, type, capability,
62714779705SSam Leffler setting, status);
62814779705SSam Leffler }
62914779705SSam Leffler }
63014779705SSam Leffler
63114779705SSam Leffler HAL_BOOL
ar5210GetDiagState(struct ath_hal * ah,int request,const void * args,uint32_t argsize,void ** result,uint32_t * resultsize)63214779705SSam Leffler ar5210GetDiagState(struct ath_hal *ah, int request,
63314779705SSam Leffler const void *args, uint32_t argsize,
63414779705SSam Leffler void **result, uint32_t *resultsize)
63514779705SSam Leffler {
63614779705SSam Leffler #ifdef AH_PRIVATE_DIAG
63714779705SSam Leffler uint32_t pcicfg;
63814779705SSam Leffler HAL_BOOL ok;
63914779705SSam Leffler
64014779705SSam Leffler switch (request) {
64114779705SSam Leffler case HAL_DIAG_EEPROM:
64214779705SSam Leffler /* XXX */
64314779705SSam Leffler break;
64414779705SSam Leffler case HAL_DIAG_EEREAD:
64514779705SSam Leffler if (argsize != sizeof(uint16_t))
64614779705SSam Leffler return AH_FALSE;
64714779705SSam Leffler pcicfg = OS_REG_READ(ah, AR_PCICFG);
64814779705SSam Leffler OS_REG_WRITE(ah, AR_PCICFG, pcicfg | AR_PCICFG_EEPROMSEL);
64914779705SSam Leffler ok = ath_hal_eepromRead(ah, *(const uint16_t *)args, *result);
65014779705SSam Leffler OS_REG_WRITE(ah, AR_PCICFG, pcicfg);
65114779705SSam Leffler if (ok)
65214779705SSam Leffler *resultsize = sizeof(uint16_t);
65314779705SSam Leffler return ok;
65414779705SSam Leffler }
65514779705SSam Leffler #endif
65614779705SSam Leffler return ath_hal_getdiagstate(ah, request,
65714779705SSam Leffler args, argsize, result, resultsize);
65814779705SSam Leffler }
659352f07f6SAdrian Chadd
660352f07f6SAdrian Chadd /*
661352f07f6SAdrian Chadd * Return what percentage of the extension channel is busy.
662352f07f6SAdrian Chadd * This is always disabled for AR5210 series NICs.
663352f07f6SAdrian Chadd */
664352f07f6SAdrian Chadd uint32_t
ar5210Get11nExtBusy(struct ath_hal * ah)665352f07f6SAdrian Chadd ar5210Get11nExtBusy(struct ath_hal *ah)
666352f07f6SAdrian Chadd {
667352f07f6SAdrian Chadd
668352f07f6SAdrian Chadd return (0);
669352f07f6SAdrian Chadd }
670352f07f6SAdrian Chadd
671352f07f6SAdrian Chadd /*
672352f07f6SAdrian Chadd * There's no channel survey support for the AR5210.
673352f07f6SAdrian Chadd */
674352f07f6SAdrian Chadd HAL_BOOL
ar5210GetMibCycleCounts(struct ath_hal * ah,HAL_SURVEY_SAMPLE * hsample)675352f07f6SAdrian Chadd ar5210GetMibCycleCounts(struct ath_hal *ah, HAL_SURVEY_SAMPLE *hsample)
676352f07f6SAdrian Chadd {
677352f07f6SAdrian Chadd
678352f07f6SAdrian Chadd return (AH_FALSE);
679352f07f6SAdrian Chadd }
680a41607fcSAdrian Chadd
681a41607fcSAdrian Chadd void
ar5210SetChainMasks(struct ath_hal * ah,uint32_t txchainmask,uint32_t rxchainmask)682d2a72d67SAdrian Chadd ar5210SetChainMasks(struct ath_hal *ah, uint32_t txchainmask,
683d2a72d67SAdrian Chadd uint32_t rxchainmask)
684d2a72d67SAdrian Chadd {
685d2a72d67SAdrian Chadd }
686d2a72d67SAdrian Chadd
687d2a72d67SAdrian Chadd void
ar5210EnableDfs(struct ath_hal * ah,HAL_PHYERR_PARAM * pe)688a41607fcSAdrian Chadd ar5210EnableDfs(struct ath_hal *ah, HAL_PHYERR_PARAM *pe)
689a41607fcSAdrian Chadd {
690a41607fcSAdrian Chadd }
691a41607fcSAdrian Chadd
692a41607fcSAdrian Chadd void
ar5210GetDfsThresh(struct ath_hal * ah,HAL_PHYERR_PARAM * pe)693a41607fcSAdrian Chadd ar5210GetDfsThresh(struct ath_hal *ah, HAL_PHYERR_PARAM *pe)
694a41607fcSAdrian Chadd {
695a41607fcSAdrian Chadd }
696143cfad7SAdrian Chadd
697143cfad7SAdrian Chadd /*
698143cfad7SAdrian Chadd * Update the diagnostic register.
699143cfad7SAdrian Chadd *
700143cfad7SAdrian Chadd * This merges in the diagnostic register setting with the default
701143cfad7SAdrian Chadd * value, which may or may not involve disabling hardware encryption.
702143cfad7SAdrian Chadd */
703143cfad7SAdrian Chadd void
ar5210UpdateDiagReg(struct ath_hal * ah,uint32_t val)704143cfad7SAdrian Chadd ar5210UpdateDiagReg(struct ath_hal *ah, uint32_t val)
705143cfad7SAdrian Chadd {
706143cfad7SAdrian Chadd
707143cfad7SAdrian Chadd /* Disable all hardware encryption */
708143cfad7SAdrian Chadd val |= AR_DIAG_SW_DIS_CRYPTO;
709143cfad7SAdrian Chadd OS_REG_WRITE(ah, AR_DIAG_SW, val);
710143cfad7SAdrian Chadd }
711*bed90bf8SAdrian Chadd
712*bed90bf8SAdrian Chadd /*
713*bed90bf8SAdrian Chadd * Get the current NAV value from the hardware.
714*bed90bf8SAdrian Chadd */
715*bed90bf8SAdrian Chadd u_int
ar5210GetNav(struct ath_hal * ah)716*bed90bf8SAdrian Chadd ar5210GetNav(struct ath_hal *ah)
717*bed90bf8SAdrian Chadd {
718*bed90bf8SAdrian Chadd uint32_t reg;
719*bed90bf8SAdrian Chadd
720*bed90bf8SAdrian Chadd reg = OS_REG_READ(ah, AR_NAV);
721*bed90bf8SAdrian Chadd return (reg);
722*bed90bf8SAdrian Chadd }
723*bed90bf8SAdrian Chadd
724*bed90bf8SAdrian Chadd /*
725*bed90bf8SAdrian Chadd * Set the current NAV value to the hardware.
726*bed90bf8SAdrian Chadd */
727*bed90bf8SAdrian Chadd void
ar5210SetNav(struct ath_hal * ah,u_int val)728*bed90bf8SAdrian Chadd ar5210SetNav(struct ath_hal *ah, u_int val)
729*bed90bf8SAdrian Chadd {
730*bed90bf8SAdrian Chadd
731*bed90bf8SAdrian Chadd OS_REG_WRITE(ah, AR_NAV, val);
732*bed90bf8SAdrian Chadd }
733*bed90bf8SAdrian Chadd
734