1*49e18393Smrg /* $NetBSD: athnvar.h,v 1.8 2019/10/05 23:27:20 mrg Exp $ */ 26e138cfdSjmcneill /* $OpenBSD: athnvar.h,v 1.34 2013/10/21 16:13:49 stsp Exp $ */ 364f89611Schristos 464f89611Schristos /*- 564f89611Schristos * Copyright (c) 2009 Damien Bergamini <damien.bergamini@free.fr> 664f89611Schristos * 764f89611Schristos * Permission to use, copy, modify, and distribute this software for any 864f89611Schristos * purpose with or without fee is hereby granted, provided that the above 964f89611Schristos * copyright notice and this permission notice appear in all copies. 1064f89611Schristos * 1164f89611Schristos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1264f89611Schristos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1364f89611Schristos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1464f89611Schristos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1564f89611Schristos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1664f89611Schristos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1764f89611Schristos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1864f89611Schristos */ 1964f89611Schristos 2064f89611Schristos #ifndef _ATHNVAR_H_ 2164f89611Schristos #define _ATHNVAR_H_ 2264f89611Schristos 2364f89611Schristos #ifdef _KERNEL_OPT 2464f89611Schristos #include "opt_athn.h" 2564f89611Schristos #endif 2664f89611Schristos 2764f89611Schristos #define PUBLIC 2864f89611Schristos 2964f89611Schristos #define IEEE80211_NO_HT /* XXX: porting artifact */ 3064f89611Schristos 3164f89611Schristos #ifdef notyet 3264f89611Schristos #define ATHN_BT_COEXISTENCE 1 3364f89611Schristos #endif 3464f89611Schristos 3564f89611Schristos #define ATHN_SOFTC(sc) ((struct athn_softc *)(sc)) 3664f89611Schristos #define ATHN_NODE(ni) ((struct athn_node *)(ni)) 3764f89611Schristos 3864f89611Schristos #ifdef ATHN_DEBUG 3964f89611Schristos #define DBG_INIT __BIT(0) 4064f89611Schristos #define DBG_FN __BIT(1) 4164f89611Schristos #define DBG_TX __BIT(2) 4264f89611Schristos #define DBG_RX __BIT(3) 4364f89611Schristos #define DBG_STM __BIT(4) 4464f89611Schristos #define DBG_RF __BIT(5) 4564f89611Schristos #define DBG_NODES __BIT(6) 4664f89611Schristos #define DBG_INTR __BIT(7) 4764f89611Schristos #define DBG_ALL 0xffffffffU 4864f89611Schristos #define DPRINTFN(n, s, ...) do { \ 4964f89611Schristos if (athn_debug & (n)) { \ 5064f89611Schristos printf("%s: %s: ", \ 5164f89611Schristos device_xname(ATHN_SOFTC(s)->sc_dev), __func__); \ 5264f89611Schristos printf(__VA_ARGS__); \ 5364f89611Schristos } \ 5464f89611Schristos } while (0) 5564f89611Schristos extern int athn_debug; 5664f89611Schristos #else /* ATHN_DEBUG */ 5764f89611Schristos #define DPRINTFN(n, s, ...) 5864f89611Schristos #endif /* ATHN_DEBUG */ 5964f89611Schristos 6064f89611Schristos #define LE_READ_4(p) ((p)[0] | (p)[1] << 8 | (p)[2] << 16 | (p)[3] << 24) 6164f89611Schristos #define LE_READ_2(p) ((p)[0] | (p)[1] << 8) 6264f89611Schristos 6364f89611Schristos #define ATHN_RXBUFSZ 3872 6464f89611Schristos #define ATHN_TXBUFSZ 4096 6564f89611Schristos 6664f89611Schristos #define ATHN_NRXBUFS 64 6764f89611Schristos #define ATHN_NTXBUFS 64 /* Shared between all Tx queues. */ 6864f89611Schristos 6964f89611Schristos struct athn_rx_radiotap_header { 7064f89611Schristos struct ieee80211_radiotap_header wr_ihdr; 7164f89611Schristos uint64_t wr_tsft; 7264f89611Schristos uint8_t wr_flags; 7364f89611Schristos uint8_t wr_rate; 7464f89611Schristos uint16_t wr_chan_freq; 7564f89611Schristos uint16_t wr_chan_flags; 7664f89611Schristos int8_t wr_dbm_antsignal; 7764f89611Schristos uint8_t wr_antenna; 78*49e18393Smrg }; 7964f89611Schristos 8064f89611Schristos #define ATHN_RX_RADIOTAP_PRESENT \ 8164f89611Schristos (1 << IEEE80211_RADIOTAP_TSFT | \ 8264f89611Schristos 1 << IEEE80211_RADIOTAP_FLAGS | \ 8364f89611Schristos 1 << IEEE80211_RADIOTAP_RATE | \ 8464f89611Schristos 1 << IEEE80211_RADIOTAP_CHANNEL | \ 8564f89611Schristos 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL | \ 8664f89611Schristos 1 << IEEE80211_RADIOTAP_ANTENNA) 8764f89611Schristos 8864f89611Schristos struct athn_tx_radiotap_header { 8964f89611Schristos struct ieee80211_radiotap_header wt_ihdr; 9064f89611Schristos uint8_t wt_flags; 9164f89611Schristos uint8_t wt_rate; 9264f89611Schristos uint16_t wt_chan_freq; 9364f89611Schristos uint16_t wt_chan_flags; 94*49e18393Smrg }; 9564f89611Schristos 9664f89611Schristos #define ATHN_TX_RADIOTAP_PRESENT \ 9764f89611Schristos (1 << IEEE80211_RADIOTAP_FLAGS | \ 9864f89611Schristos 1 << IEEE80211_RADIOTAP_RATE | \ 9964f89611Schristos 1 << IEEE80211_RADIOTAP_CHANNEL) 10064f89611Schristos 10164f89611Schristos struct athn_tx_buf { 10264f89611Schristos SIMPLEQ_ENTRY(athn_tx_buf) bf_list; 10364f89611Schristos 10464f89611Schristos void *bf_descs; 10564f89611Schristos bus_dmamap_t bf_map; 10664f89611Schristos bus_addr_t bf_daddr; 10764f89611Schristos 10864f89611Schristos struct mbuf *bf_m; 10964f89611Schristos struct ieee80211_node *bf_ni; 11064f89611Schristos int bf_txflags; 11164f89611Schristos #define ATHN_TXFLAG_PAPRD (1 << 0) 11264f89611Schristos #define ATHN_TXFLAG_CAB (1 << 1) 11364f89611Schristos }; 11464f89611Schristos 11564f89611Schristos struct athn_txq { 11664f89611Schristos SIMPLEQ_HEAD(, athn_tx_buf) head; 11764f89611Schristos void *lastds; 11864f89611Schristos struct athn_tx_buf *wait; 11964f89611Schristos int queued; 12064f89611Schristos }; 12164f89611Schristos 12264f89611Schristos struct athn_rx_buf { 12364f89611Schristos SIMPLEQ_ENTRY(athn_rx_buf) bf_list; 12464f89611Schristos 12564f89611Schristos void *bf_desc; 12664f89611Schristos bus_dmamap_t bf_map; 12764f89611Schristos 12864f89611Schristos struct mbuf *bf_m; 12964f89611Schristos bus_addr_t bf_daddr; 13064f89611Schristos }; 13164f89611Schristos 13264f89611Schristos struct athn_rxq { 13364f89611Schristos struct athn_rx_buf *bf; 13464f89611Schristos 13564f89611Schristos void *descs; 13664f89611Schristos void *lastds; 13764f89611Schristos bus_dmamap_t map; 13864f89611Schristos bus_dma_segment_t seg; 13964f89611Schristos int count; 14064f89611Schristos 14164f89611Schristos SIMPLEQ_HEAD(, athn_rx_buf) head; 14264f89611Schristos }; 14364f89611Schristos 14464f89611Schristos /* Software rate indexes. */ 14564f89611Schristos #define ATHN_RIDX_CCK1 0 14664f89611Schristos #define ATHN_RIDX_CCK2 1 14764f89611Schristos #define ATHN_RIDX_OFDM6 4 14864f89611Schristos #define ATHN_RIDX_MCS0 12 14964f89611Schristos #define ATHN_RIDX_MCS15 27 15064f89611Schristos #define ATHN_RIDX_MAX 27 15164f89611Schristos #define ATHN_IS_HT_RIDX(ridx) ((ridx) >= ATHN_RIDX_MCS0) 15264f89611Schristos 15364f89611Schristos static const struct athn_rate { 15464f89611Schristos uint8_t rate; /* Rate in 500Kbps unit or MCS if 0x80. */ 15564f89611Schristos uint8_t hwrate; /* HW representation. */ 15664f89611Schristos uint8_t rspridx; /* Control Response Frame rate index. */ 15764f89611Schristos enum ieee80211_phytype phy; 15864f89611Schristos } athn_rates[] = { 15964f89611Schristos { 2, 0x1b, 0, IEEE80211_T_DS }, 16064f89611Schristos { 4, 0x1a, 1, IEEE80211_T_DS }, 16164f89611Schristos { 11, 0x19, 1, IEEE80211_T_DS }, 16264f89611Schristos { 22, 0x18, 1, IEEE80211_T_DS }, 16364f89611Schristos { 12, 0x0b, 4, IEEE80211_T_OFDM }, 16464f89611Schristos { 18, 0x0f, 4, IEEE80211_T_OFDM }, 16564f89611Schristos { 24, 0x0a, 6, IEEE80211_T_OFDM }, 16664f89611Schristos { 36, 0x0e, 6, IEEE80211_T_OFDM }, 16764f89611Schristos { 48, 0x09, 8, IEEE80211_T_OFDM }, 16864f89611Schristos { 72, 0x0d, 8, IEEE80211_T_OFDM }, 16964f89611Schristos { 96, 0x08, 8, IEEE80211_T_OFDM }, 17064f89611Schristos { 108, 0x0c, 8, IEEE80211_T_OFDM }, 17164f89611Schristos { 0x80, 0x80, 8, IEEE80211_T_OFDM }, 17264f89611Schristos { 0x81, 0x81, 8, IEEE80211_T_OFDM }, 17364f89611Schristos { 0x82, 0x82, 8, IEEE80211_T_OFDM }, 17464f89611Schristos { 0x83, 0x83, 8, IEEE80211_T_OFDM }, 17564f89611Schristos { 0x84, 0x84, 8, IEEE80211_T_OFDM }, 17664f89611Schristos { 0x85, 0x85, 8, IEEE80211_T_OFDM }, 17764f89611Schristos { 0x86, 0x86, 8, IEEE80211_T_OFDM }, 17864f89611Schristos { 0x87, 0x87, 8, IEEE80211_T_OFDM }, 17964f89611Schristos { 0x88, 0x88, 8, IEEE80211_T_OFDM }, 18064f89611Schristos { 0x89, 0x89, 8, IEEE80211_T_OFDM }, 18164f89611Schristos { 0x8a, 0x8a, 8, IEEE80211_T_OFDM }, 18264f89611Schristos { 0x8b, 0x8b, 8, IEEE80211_T_OFDM }, 18364f89611Schristos { 0x8c, 0x8c, 8, IEEE80211_T_OFDM }, 18464f89611Schristos { 0x8d, 0x8d, 8, IEEE80211_T_OFDM }, 18564f89611Schristos { 0x8e, 0x8e, 8, IEEE80211_T_OFDM }, 18664f89611Schristos { 0x8f, 0x8f, 8, IEEE80211_T_OFDM } 18764f89611Schristos }; 18864f89611Schristos 18964f89611Schristos struct athn_series { 19064f89611Schristos uint16_t dur; 19164f89611Schristos uint8_t hwrate; 19264f89611Schristos }; 19364f89611Schristos 19464f89611Schristos struct athn_pier { 19564f89611Schristos uint8_t fbin; 19664f89611Schristos const uint8_t *pwr[AR_PD_GAINS_IN_MASK]; 19764f89611Schristos const uint8_t *vpd[AR_PD_GAINS_IN_MASK]; 19864f89611Schristos }; 19964f89611Schristos 20064f89611Schristos /* 20164f89611Schristos * Structures used to store initialization values. 20264f89611Schristos */ 20364f89611Schristos struct athn_ini { 20464f89611Schristos int nregs; 20564f89611Schristos const uint16_t *regs; 20664f89611Schristos const uint32_t *vals_5g20; 20764f89611Schristos #ifndef IEEE80211_NO_HT 20864f89611Schristos const uint32_t *vals_5g40; 20964f89611Schristos const uint32_t *vals_2g40; 21064f89611Schristos #endif 21164f89611Schristos const uint32_t *vals_2g20; 21264f89611Schristos int ncmregs; 21364f89611Schristos const uint16_t *cmregs; 21464f89611Schristos const uint32_t *cmvals; 21564f89611Schristos int nfastregs; 21664f89611Schristos const uint16_t *fastregs; 21764f89611Schristos const uint32_t *fastvals_5g20; 21864f89611Schristos #ifndef IEEE80211_NO_HT 21964f89611Schristos const uint32_t *fastvals_5g40; 22064f89611Schristos #endif 22164f89611Schristos }; 22264f89611Schristos 22364f89611Schristos struct athn_gain { 22464f89611Schristos int nregs; 22564f89611Schristos const uint16_t *regs; 22664f89611Schristos const uint32_t *vals_5g; 22764f89611Schristos const uint32_t *vals_2g; 22864f89611Schristos }; 22964f89611Schristos 23064f89611Schristos struct athn_addac { 23164f89611Schristos int nvals; 23264f89611Schristos const uint32_t *vals; 23364f89611Schristos }; 23464f89611Schristos 23564f89611Schristos struct athn_serdes { 23664f89611Schristos int nvals; 23764f89611Schristos const uint32_t *regs; 23864f89611Schristos const uint32_t *vals; 23964f89611Schristos }; 24064f89611Schristos 24164f89611Schristos /* Rx queue software indexes. */ 24264f89611Schristos #define ATHN_QID_LP 0 2436e138cfdSjmcneill #define ATHN_QID_HP 1 24464f89611Schristos 24564f89611Schristos /* Tx queue software indexes. */ 24664f89611Schristos #define ATHN_QID_AC_BE 0 24764f89611Schristos #define ATHN_QID_PSPOLL 1 24864f89611Schristos #define ATHN_QID_AC_BK 2 24964f89611Schristos #define ATHN_QID_AC_VI 3 25064f89611Schristos #define ATHN_QID_AC_VO 4 25164f89611Schristos #define ATHN_QID_UAPSD 5 25264f89611Schristos #define ATHN_QID_CAB 6 25364f89611Schristos #define ATHN_QID_BEACON 7 25464f89611Schristos #define ATHN_QID_COUNT 8 25564f89611Schristos 25664f89611Schristos /* Map Access Category to Tx queue Id. */ 257f3de05fdSchristos static const uint8_t athn_ac2qid[WME_NUM_AC] = { 258f3de05fdSchristos ATHN_QID_AC_BE, /* WME_AC_BE */ 259f3de05fdSchristos ATHN_QID_AC_BK, /* WME_AC_BK */ 260f3de05fdSchristos ATHN_QID_AC_VI, /* WME_AC_VI */ 261f3de05fdSchristos ATHN_QID_AC_VO /* WME_AC_VO */ 26264f89611Schristos }; 26364f89611Schristos 26464f89611Schristos static const uint8_t athn_5ghz_chans[] = { 26564f89611Schristos /* UNII 1. */ 26664f89611Schristos 36, 40, 44, 48, 26764f89611Schristos /* UNII 2. */ 26864f89611Schristos 52, 56, 60, 64, 26964f89611Schristos /* Middle band. */ 27064f89611Schristos 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 27164f89611Schristos /* UNII 3. */ 27264f89611Schristos 149, 153, 157, 161, 165 27364f89611Schristos }; 27464f89611Schristos 27564f89611Schristos /* Number of data bits per OFDM symbol for MCS[0-15]. */ 27664f89611Schristos /* See tables 20-29, 20-30, 20-33, 20-34. */ 27764f89611Schristos static const uint16_t ar_mcs_ndbps[][2] = { 27864f89611Schristos /* 20MHz 40MHz */ 27964f89611Schristos { 26, 54 }, /* MCS0 */ 28064f89611Schristos { 52, 108 }, /* MCS1 */ 28164f89611Schristos { 78, 162 }, /* MCS2 */ 28264f89611Schristos { 104, 216 }, /* MCS3 */ 28364f89611Schristos { 156, 324 }, /* MCS4 */ 28464f89611Schristos { 208, 432 }, /* MCS5 */ 28564f89611Schristos { 234, 486 }, /* MCS6 */ 28664f89611Schristos { 260, 540 }, /* MCS7 */ 28764f89611Schristos { 26, 108 }, /* MCS8 */ 28864f89611Schristos { 52, 216 }, /* MCS9 */ 28964f89611Schristos { 78, 324 }, /* MCS10 */ 29064f89611Schristos { 104, 432 }, /* MCS11 */ 29164f89611Schristos { 156, 648 }, /* MCS12 */ 29264f89611Schristos { 208, 864 }, /* MCS13 */ 29364f89611Schristos { 234, 972 }, /* MCS14 */ 29464f89611Schristos { 260, 1080 } /* MCS15 */ 29564f89611Schristos }; 29664f89611Schristos 29764f89611Schristos #define ATHN_POWER_OFDM6 0 29864f89611Schristos #define ATHN_POWER_OFDM9 1 29964f89611Schristos #define ATHN_POWER_OFDM12 2 30064f89611Schristos #define ATHN_POWER_OFDM18 3 30164f89611Schristos #define ATHN_POWER_OFDM24 4 30264f89611Schristos #define ATHN_POWER_OFDM36 5 30364f89611Schristos #define ATHN_POWER_OFDM48 6 30464f89611Schristos #define ATHN_POWER_OFDM54 7 30564f89611Schristos #define ATHN_POWER_CCK1_LP 8 30664f89611Schristos #define ATHN_POWER_CCK2_LP 9 30764f89611Schristos #define ATHN_POWER_CCK2_SP 10 30864f89611Schristos #define ATHN_POWER_CCK55_LP 11 30964f89611Schristos #define ATHN_POWER_CCK55_SP 12 31064f89611Schristos #define ATHN_POWER_CCK11_LP 13 31164f89611Schristos #define ATHN_POWER_CCK11_SP 14 31264f89611Schristos #define ATHN_POWER_XR 15 31364f89611Schristos #define ATHN_POWER_HT20(mcs) (16 + (mcs)) 31464f89611Schristos #define ATHN_POWER_HT40(mcs) (40 + (mcs)) 31564f89611Schristos #define ATHN_POWER_CCK_DUP 64 31664f89611Schristos #define ATHN_POWER_OFDM_DUP 65 31764f89611Schristos #define ATHN_POWER_CCK_EXT 66 31864f89611Schristos #define ATHN_POWER_OFDM_EXT 67 31964f89611Schristos #define ATHN_POWER_COUNT 68 32064f89611Schristos 32164f89611Schristos struct athn_node { 32264f89611Schristos struct ieee80211_node ni; 32364f89611Schristos struct ieee80211_amrr_node amn; 32464f89611Schristos uint8_t ridx[IEEE80211_RATE_MAXSIZE]; 32564f89611Schristos uint8_t fallback[IEEE80211_RATE_MAXSIZE]; 32664f89611Schristos uint8_t sta_index; 32764f89611Schristos }; 32864f89611Schristos 32964f89611Schristos /* 33064f89611Schristos * Adaptive noise immunity state. 33164f89611Schristos */ 33264f89611Schristos #define ATHN_ANI_PERIOD 100 33364f89611Schristos #define ATHN_ANI_RSSI_THR_HIGH 40 33464f89611Schristos #define ATHN_ANI_RSSI_THR_LOW 7 33564f89611Schristos struct athn_ani { 33664f89611Schristos uint8_t noise_immunity_level; 33764f89611Schristos uint8_t spur_immunity_level; 33864f89611Schristos uint8_t firstep_level; 33964f89611Schristos uint8_t ofdm_weak_signal; 34064f89611Schristos uint8_t cck_weak_signal; 34164f89611Schristos 34264f89611Schristos uint32_t listen_time; 34364f89611Schristos 34464f89611Schristos uint32_t ofdm_trig_high; 34564f89611Schristos uint32_t ofdm_trig_low; 34664f89611Schristos 34764f89611Schristos int32_t cck_trig_high; 34864f89611Schristos int32_t cck_trig_low; 34964f89611Schristos 35064f89611Schristos uint32_t ofdm_phy_err_base; 35164f89611Schristos uint32_t cck_phy_err_base; 35264f89611Schristos uint32_t ofdm_phy_err_count; 35364f89611Schristos uint32_t cck_phy_err_count; 35464f89611Schristos 35564f89611Schristos uint32_t cyccnt; 35664f89611Schristos uint32_t txfcnt; 35764f89611Schristos uint32_t rxfcnt; 35864f89611Schristos }; 35964f89611Schristos 36064f89611Schristos struct athn_iq_cal { 36164f89611Schristos uint32_t pwr_meas_i; 36264f89611Schristos uint32_t pwr_meas_q; 36364f89611Schristos int32_t iq_corr_meas; 36464f89611Schristos }; 36564f89611Schristos 36664f89611Schristos struct athn_adc_cal { 36764f89611Schristos uint32_t pwr_meas_odd_i; 36864f89611Schristos uint32_t pwr_meas_even_i; 36964f89611Schristos uint32_t pwr_meas_odd_q; 37064f89611Schristos uint32_t pwr_meas_even_q; 37164f89611Schristos }; 37264f89611Schristos 37364f89611Schristos struct athn_calib { 37464f89611Schristos int nsamples; 37564f89611Schristos struct athn_iq_cal iq[AR_MAX_CHAINS]; 37664f89611Schristos struct athn_adc_cal adc_gain[AR_MAX_CHAINS]; 37764f89611Schristos struct athn_adc_cal adc_dc_offset[AR_MAX_CHAINS]; 37864f89611Schristos }; 37964f89611Schristos 38064f89611Schristos #define ATHN_NF_CAL_HIST_MAX 5 38164f89611Schristos 38264f89611Schristos struct athn_softc; 38364f89611Schristos 38464f89611Schristos struct athn_ops { 38564f89611Schristos /* Bus callbacks. */ 38664f89611Schristos uint32_t (*read)(struct athn_softc *, uint32_t); 38764f89611Schristos void (*write)(struct athn_softc *, uint32_t, uint32_t); 38864f89611Schristos void (*write_barrier)(struct athn_softc *); 38964f89611Schristos 39064f89611Schristos void (*setup)(struct athn_softc *); 39164f89611Schristos void (*set_txpower)(struct athn_softc *, struct ieee80211_channel *, 39264f89611Schristos struct ieee80211_channel *); 39364f89611Schristos void (*spur_mitigate)(struct athn_softc *, 39464f89611Schristos struct ieee80211_channel *, struct ieee80211_channel *); 39564f89611Schristos const struct ar_spur_chan * 39664f89611Schristos (*get_spur_chans)(struct athn_softc *, int); 39764f89611Schristos void (*init_from_rom)(struct athn_softc *, 39864f89611Schristos struct ieee80211_channel *, struct ieee80211_channel *); 39964f89611Schristos int (*set_synth)(struct athn_softc *, struct ieee80211_channel *, 40064f89611Schristos struct ieee80211_channel *); 40164f89611Schristos int (*read_rom_data)(struct athn_softc *, uint32_t, void *, int); 40264f89611Schristos const uint8_t * 40364f89611Schristos (*get_rom_template)(struct athn_softc *, uint8_t); 40464f89611Schristos void (*swap_rom)(struct athn_softc *); 40564f89611Schristos void (*olpc_init)(struct athn_softc *); 40664f89611Schristos void (*olpc_temp_compensation)(struct athn_softc *); 40764f89611Schristos 40864f89611Schristos /* GPIO callbacks. */ 40964f89611Schristos int (*gpio_read)(struct athn_softc *, int); 41064f89611Schristos void (*gpio_write)(struct athn_softc *, int, int); 41164f89611Schristos void (*gpio_config_input)(struct athn_softc *, int); 41264f89611Schristos void (*gpio_config_output)(struct athn_softc *, int, int); 41364f89611Schristos void (*rfsilent_init)(struct athn_softc *); 41464f89611Schristos 41564f89611Schristos /* DMA callbacks. */ 41664f89611Schristos int (*dma_alloc)(struct athn_softc *); 41764f89611Schristos void (*dma_free)(struct athn_softc *); 41864f89611Schristos void (*rx_enable)(struct athn_softc *); 4195ffb0503Snonaka int (*intr_status)(struct athn_softc *); 42064f89611Schristos int (*intr)(struct athn_softc *); 42164f89611Schristos int (*tx)(struct athn_softc *, struct mbuf *, 42264f89611Schristos struct ieee80211_node *, int); 42364f89611Schristos 42464f89611Schristos /* PHY callbacks. */ 42564f89611Schristos void (*set_rf_mode)(struct athn_softc *, 42664f89611Schristos struct ieee80211_channel *); 42764f89611Schristos int (*rf_bus_request)(struct athn_softc *); 42864f89611Schristos void (*rf_bus_release)(struct athn_softc *); 42964f89611Schristos void (*set_phy)(struct athn_softc *, struct ieee80211_channel *, 43064f89611Schristos struct ieee80211_channel *); 43164f89611Schristos void (*set_delta_slope)(struct athn_softc *, 43264f89611Schristos struct ieee80211_channel *, struct ieee80211_channel *); 43364f89611Schristos void (*enable_antenna_diversity)(struct athn_softc *); 43464f89611Schristos void (*init_baseband)(struct athn_softc *); 43564f89611Schristos void (*disable_phy)(struct athn_softc *); 43664f89611Schristos void (*set_rxchains)(struct athn_softc *); 43764f89611Schristos void (*noisefloor_calib)(struct athn_softc *); 43864f89611Schristos void (*do_calib)(struct athn_softc *); 43964f89611Schristos void (*next_calib)(struct athn_softc *); 44064f89611Schristos void (*hw_init)(struct athn_softc *, struct ieee80211_channel *, 44164f89611Schristos struct ieee80211_channel *); 44264f89611Schristos void (*get_paprd_masks)(struct athn_softc *sc, 44364f89611Schristos struct ieee80211_channel *, uint32_t *, uint32_t *); 44464f89611Schristos 44564f89611Schristos /* ANI callbacks. */ 44664f89611Schristos void (*set_noise_immunity_level)(struct athn_softc *, int); 44764f89611Schristos void (*enable_ofdm_weak_signal)(struct athn_softc *); 44864f89611Schristos void (*disable_ofdm_weak_signal)(struct athn_softc *); 44964f89611Schristos void (*set_cck_weak_signal)(struct athn_softc *, int); 45064f89611Schristos void (*set_firstep_level)(struct athn_softc *, int); 45164f89611Schristos void (*set_spur_immunity_level)(struct athn_softc *, int); 45264f89611Schristos }; 45364f89611Schristos 45464f89611Schristos struct athn_softc { 45564f89611Schristos device_t sc_dev; 45664f89611Schristos device_suspensor_t sc_suspensor; 45764f89611Schristos pmf_qual_t sc_qual; 45864f89611Schristos struct ieee80211com sc_ic; 45902421171Schristos struct ethercom sc_ec; 46002421171Schristos #define sc_if sc_ec.ec_if 4615ffb0503Snonaka void *sc_soft_ih; 46264f89611Schristos 46364f89611Schristos #if 0 46464f89611Schristos int (*sc_enable)(struct athn_softc *); 46564f89611Schristos void (*sc_disable)(struct athn_softc *); 46664f89611Schristos void (*sc_power)(struct athn_softc *, int); 46764f89611Schristos #endif 46864f89611Schristos void (*sc_disable_aspm)(struct athn_softc *); 46964f89611Schristos void (*sc_enable_extsynch)( 47064f89611Schristos struct athn_softc *); 47164f89611Schristos 47264f89611Schristos int (*sc_newstate)(struct ieee80211com *, 47364f89611Schristos enum ieee80211_state, int); 47464f89611Schristos 47564f89611Schristos bus_dma_tag_t sc_dmat; 47664f89611Schristos 47764f89611Schristos callout_t sc_scan_to; 47864f89611Schristos callout_t sc_calib_to; 47964f89611Schristos struct ieee80211_amrr sc_amrr; 48064f89611Schristos 48164f89611Schristos u_int sc_flags; 48264f89611Schristos #define ATHN_FLAG_PCIE (1 << 0) 48364f89611Schristos #define ATHN_FLAG_USB (1 << 1) 48464f89611Schristos #define ATHN_FLAG_OLPC (1 << 2) 48564f89611Schristos #define ATHN_FLAG_PAPRD (1 << 3) 48664f89611Schristos #define ATHN_FLAG_FAST_PLL_CLOCK (1 << 4) 48764f89611Schristos #define ATHN_FLAG_RFSILENT (1 << 5) 48864f89611Schristos #define ATHN_FLAG_RFSILENT_REVERSED (1 << 6) 48964f89611Schristos #define ATHN_FLAG_BTCOEX2WIRE (1 << 7) 49064f89611Schristos #define ATHN_FLAG_BTCOEX3WIRE (1 << 8) 49164f89611Schristos /* Shortcut. */ 49264f89611Schristos #define ATHN_FLAG_BTCOEX (ATHN_FLAG_BTCOEX2WIRE | ATHN_FLAG_BTCOEX3WIRE) 49364f89611Schristos #define ATHN_FLAG_11A (1 << 9) 49464f89611Schristos #define ATHN_FLAG_11G (1 << 10) 49564f89611Schristos #define ATHN_FLAG_11N (1 << 11) 49664f89611Schristos #define ATHN_FLAG_AN_TOP2_FIXUP (1 << 12) 49764f89611Schristos #define ATHN_FLAG_NON_ENTERPRISE (1 << 13) 49864f89611Schristos #define ATHN_FLAG_3TREDUCE_CHAIN (1 << 14) 49964f89611Schristos 50064f89611Schristos uint8_t sc_ngpiopins; 50164f89611Schristos int sc_led_pin; 50264f89611Schristos int sc_rfsilent_pin; 50364f89611Schristos int sc_led_state; 50464f89611Schristos uint32_t sc_isync; 50564f89611Schristos uint32_t sc_imask; 50664f89611Schristos 50764f89611Schristos uint16_t sc_mac_ver; 50864f89611Schristos uint8_t sc_mac_rev; 50964f89611Schristos uint8_t sc_rf_rev; 51064f89611Schristos uint16_t sc_eep_rev; 51164f89611Schristos 51264f89611Schristos uint8_t sc_txchainmask; 51364f89611Schristos uint8_t sc_rxchainmask; 51464f89611Schristos uint8_t sc_ntxchains; 51564f89611Schristos uint8_t sc_nrxchains; 51664f89611Schristos 51764f89611Schristos uint8_t sc_sup_calib_mask; 51864f89611Schristos uint8_t sc_cur_calib_mask; 51964f89611Schristos #define ATHN_CAL_IQ (1 << 0) 52064f89611Schristos #define ATHN_CAL_ADC_GAIN (1 << 1) 52164f89611Schristos #define ATHN_CAL_ADC_DC (1 << 2) 52264f89611Schristos #define ATHN_CAL_TEMP (1 << 3) 52364f89611Schristos 52464f89611Schristos struct ieee80211_channel *sc_curchan; 52564f89611Schristos struct ieee80211_channel *sc_curchanext; 52664f89611Schristos 52764f89611Schristos /* Open Loop Power Control. */ 52864f89611Schristos int8_t sc_tx_gain_tbl[AR9280_TX_GAIN_TABLE_SIZE]; 52964f89611Schristos int8_t sc_pdadc; 53064f89611Schristos int8_t sc_tcomp; 53164f89611Schristos int sc_olpc_ticks; 53264f89611Schristos 53364f89611Schristos /* PA predistortion. */ 53464f89611Schristos uint16_t sc_gain1[AR_MAX_CHAINS]; 53564f89611Schristos uint32_t sc_txgain[AR9003_TX_GAIN_TABLE_SIZE]; 53664f89611Schristos int16_t sc_pa_in[AR_MAX_CHAINS] 53764f89611Schristos [AR9003_PAPRD_MEM_TAB_SIZE]; 53864f89611Schristos int16_t sc_angle[AR_MAX_CHAINS] 53964f89611Schristos [AR9003_PAPRD_MEM_TAB_SIZE]; 54064f89611Schristos int32_t sc_trainpow; 54164f89611Schristos uint8_t sc_paprd_curchain; 54264f89611Schristos 54364f89611Schristos uint32_t sc_rwbuf[64]; 54464f89611Schristos 54564f89611Schristos size_t sc_kc_entries; 54664f89611Schristos 54764f89611Schristos void *sc_eep; 54864f89611Schristos const void *sc_eep_def; 54964f89611Schristos uint32_t sc_eep_base; 55064f89611Schristos uint32_t sc_eep_size; 55164f89611Schristos 55264f89611Schristos struct athn_rxq sc_rxq[2]; 55364f89611Schristos struct athn_txq sc_txq[31]; 55464f89611Schristos 55564f89611Schristos void *sc_descs; 55664f89611Schristos bus_dmamap_t sc_map; 55764f89611Schristos bus_dma_segment_t sc_seg; 55864f89611Schristos SIMPLEQ_HEAD(, athn_tx_buf) sc_txbufs; 55964f89611Schristos struct athn_tx_buf *sc_bcnbuf; 56064f89611Schristos struct athn_tx_buf sc_txpool[ATHN_NTXBUFS]; 56164f89611Schristos 56264f89611Schristos bus_dmamap_t sc_txsmap; 56364f89611Schristos bus_dma_segment_t sc_txsseg; 56464f89611Schristos void *sc_txsring; 56564f89611Schristos int sc_txscur; 56664f89611Schristos 56770b25bc9Smsaitoh u_short sc_if_flags; 56864f89611Schristos int sc_tx_timer; 56964f89611Schristos 57064f89611Schristos const struct athn_ini *sc_ini; 57164f89611Schristos const struct athn_gain *sc_rx_gain; 57264f89611Schristos const struct athn_gain *sc_tx_gain; 57364f89611Schristos const struct athn_addac *sc_addac; 57464f89611Schristos const struct athn_serdes *sc_serdes; 57564f89611Schristos uint32_t sc_workaround; 57664f89611Schristos uint32_t sc_obs_off; 57764f89611Schristos uint32_t sc_gpio_input_en_off; 57864f89611Schristos 57964f89611Schristos struct athn_ops sc_ops; 58064f89611Schristos 58164f89611Schristos int sc_fixed_ridx; 58264f89611Schristos 58364f89611Schristos int16_t sc_cca_min_2g; 58464f89611Schristos int16_t sc_cca_max_2g; 58564f89611Schristos int16_t sc_cca_min_5g; 58664f89611Schristos int16_t sc_cca_max_5g; 58764f89611Schristos int16_t sc_def_nf; 58864f89611Schristos struct { 58964f89611Schristos int16_t nf[AR_MAX_CHAINS]; 59064f89611Schristos int16_t nf_ext[AR_MAX_CHAINS]; 59164f89611Schristos } sc_nf_hist[ATHN_NF_CAL_HIST_MAX]; 59264f89611Schristos int sc_nf_hist_cur; 59364f89611Schristos int16_t sc_nf_priv[AR_MAX_CHAINS]; 59464f89611Schristos int16_t sc_nf_ext_priv[AR_MAX_CHAINS]; 59564f89611Schristos int sc_pa_calib_ticks; 59664f89611Schristos 59764f89611Schristos struct athn_calib sc_calib; 59864f89611Schristos struct athn_ani sc_ani; 59964f89611Schristos 60064f89611Schristos struct bpf_if * sc_drvbpf; 60164f89611Schristos 60264f89611Schristos union { 60364f89611Schristos struct athn_rx_radiotap_header th; 60464f89611Schristos uint8_t pad[IEEE80211_RADIOTAP_HDRLEN]; 60564f89611Schristos } sc_rxtapu; 60664f89611Schristos #define sc_rxtap sc_rxtapu.th 60764f89611Schristos int sc_rxtap_len; 60864f89611Schristos 60964f89611Schristos union { 61064f89611Schristos struct athn_tx_radiotap_header th; 61164f89611Schristos uint8_t pad[IEEE80211_RADIOTAP_HDRLEN]; 61264f89611Schristos } sc_txtapu; 61364f89611Schristos #define sc_txtap sc_txtapu.th 61464f89611Schristos int sc_txtap_len; 61564f89611Schristos 61664f89611Schristos /* 61764f89611Schristos * Attach overrides. Set before calling athn_attach(). 61864f89611Schristos */ 61964f89611Schristos int sc_max_aid; 62064f89611Schristos int (*sc_media_change)(struct ifnet *); 62164f89611Schristos }; 62264f89611Schristos 62364f89611Schristos int athn_attach(struct athn_softc *); 62464f89611Schristos void athn_detach(struct athn_softc *); 62564f89611Schristos void athn_suspend(struct athn_softc *); 626c381a4f1Smartin bool athn_resume(struct athn_softc *); 62764f89611Schristos int athn_intr(void *); 62864f89611Schristos 62964f89611Schristos /* used by if_athn_usb.c */ 63064f89611Schristos void athn_btcoex_init(struct athn_softc *); 63164f89611Schristos int athn_hw_reset(struct athn_softc *, struct ieee80211_channel *, 63264f89611Schristos struct ieee80211_channel *, int); 63364f89611Schristos void athn_init_pll(struct athn_softc *, const struct ieee80211_channel *); 63464f89611Schristos void athn_led_init(struct athn_softc *); 63564f89611Schristos int athn_reset(struct athn_softc *, int); 63664f89611Schristos void athn_reset_key(struct athn_softc *, int); 63764f89611Schristos void athn_rx_start(struct athn_softc *); 63864f89611Schristos void athn_set_bss(struct athn_softc *, struct ieee80211_node *); 63964f89611Schristos int athn_set_chan(struct athn_softc *, struct ieee80211_channel *, 64064f89611Schristos struct ieee80211_channel *); 64164f89611Schristos void athn_set_hostap_timers(struct athn_softc *); 64264f89611Schristos void athn_set_led(struct athn_softc *, int); 64364f89611Schristos void athn_set_opmode(struct athn_softc *); 64464f89611Schristos int athn_set_power_awake(struct athn_softc *); 64564f89611Schristos void athn_set_power_sleep(struct athn_softc *); 64664f89611Schristos void athn_set_rxfilter(struct athn_softc *, uint32_t); 64764f89611Schristos void athn_set_sta_timers(struct athn_softc *); 64864f89611Schristos void athn_updateslot(struct ifnet *); 64964f89611Schristos 65064f89611Schristos #ifdef notyet_edca 65164f89611Schristos void athn_updateedca(struct ieee80211com *); 65264f89611Schristos #endif 65364f89611Schristos #ifdef notyet 65464f89611Schristos void athn_delete_key(struct ieee80211com *, struct ieee80211_node *, 65564f89611Schristos struct ieee80211_key *); 65664f89611Schristos int athn_set_key(struct ieee80211com *, struct ieee80211_node *, 65764f89611Schristos struct ieee80211_key *); 65864f89611Schristos #endif /* notyet */ 65964f89611Schristos 66064f89611Schristos /* used by ar9285.c */ 66164f89611Schristos uint8_t athn_chan2fbin(struct ieee80211_channel *); 66264f89611Schristos void athn_get_pier_ival(uint8_t, const uint8_t *, int, int *, int *); 66364f89611Schristos 66464f89611Schristos /* used by arn5008.c and arn9003.c */ 66564f89611Schristos void athn_config_nonpcie(struct athn_softc *); 66664f89611Schristos void athn_config_pcie(struct athn_softc *); 66764f89611Schristos void athn_get_delta_slope(uint32_t, uint32_t *, uint32_t *); 66864f89611Schristos void athn_inc_tx_trigger_level(struct athn_softc *); 66964f89611Schristos void athn_stop(struct ifnet *, int); 67064f89611Schristos void athn_stop_tx_dma(struct athn_softc *, int); 67164f89611Schristos int athn_tx_pending(struct athn_softc *, int); 67264f89611Schristos int athn_txtime(struct athn_softc *, int, int, u_int); 67364f89611Schristos 67464f89611Schristos /* used by arn5008.c, arn9003.c, arn9287.c, and arn9380.c */ 67564f89611Schristos int athn_interpolate(int, int, int, int, int); 67664f89611Schristos 67764f89611Schristos #endif /* _ATHNVAR_H_ */ 678