Home | History | Annotate | Line # | Download | only in ic
      1  1.8       mrg /*	$NetBSD: athnvar.h,v 1.8 2019/10/05 23:27:20 mrg Exp $	*/
      2  1.5  jmcneill /*	$OpenBSD: athnvar.h,v 1.34 2013/10/21 16:13:49 stsp Exp $	*/
      3  1.1  christos 
      4  1.1  christos /*-
      5  1.1  christos  * Copyright (c) 2009 Damien Bergamini <damien.bergamini (at) free.fr>
      6  1.1  christos  *
      7  1.1  christos  * Permission to use, copy, modify, and distribute this software for any
      8  1.1  christos  * purpose with or without fee is hereby granted, provided that the above
      9  1.1  christos  * copyright notice and this permission notice appear in all copies.
     10  1.1  christos  *
     11  1.1  christos  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  1.1  christos  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  1.1  christos  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  1.1  christos  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  1.1  christos  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16  1.1  christos  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17  1.1  christos  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18  1.1  christos  */
     19  1.1  christos 
     20  1.1  christos #ifndef _ATHNVAR_H_
     21  1.1  christos #define _ATHNVAR_H_
     22  1.1  christos 
     23  1.1  christos #ifdef	_KERNEL_OPT
     24  1.1  christos #include "opt_athn.h"
     25  1.1  christos #endif
     26  1.1  christos 
     27  1.1  christos #define PUBLIC
     28  1.1  christos 
     29  1.1  christos #define IEEE80211_NO_HT		/* XXX: porting artifact */
     30  1.1  christos 
     31  1.1  christos #ifdef notyet
     32  1.1  christos #define ATHN_BT_COEXISTENCE	1
     33  1.1  christos #endif
     34  1.1  christos 
     35  1.1  christos #define ATHN_SOFTC(sc)		((struct athn_softc *)(sc))
     36  1.1  christos #define ATHN_NODE(ni)		((struct athn_node *)(ni))
     37  1.1  christos 
     38  1.1  christos #ifdef ATHN_DEBUG
     39  1.1  christos #define	DBG_INIT	__BIT(0)
     40  1.1  christos #define	DBG_FN		__BIT(1)
     41  1.1  christos #define	DBG_TX		__BIT(2)
     42  1.1  christos #define	DBG_RX		__BIT(3)
     43  1.1  christos #define	DBG_STM		__BIT(4)
     44  1.1  christos #define	DBG_RF		__BIT(5)
     45  1.1  christos #define	DBG_NODES	__BIT(6)
     46  1.1  christos #define	DBG_INTR	__BIT(7)
     47  1.1  christos #define	DBG_ALL		0xffffffffU
     48  1.1  christos #define DPRINTFN(n, s, ...) do { \
     49  1.1  christos 	if (athn_debug & (n)) { \
     50  1.1  christos 		printf("%s: %s: ", \
     51  1.1  christos 			device_xname(ATHN_SOFTC(s)->sc_dev), __func__); \
     52  1.1  christos 		printf(__VA_ARGS__); \
     53  1.1  christos 	} \
     54  1.1  christos } while (0)
     55  1.1  christos extern int athn_debug;
     56  1.1  christos #else /* ATHN_DEBUG */
     57  1.1  christos #define DPRINTFN(n, s, ...)
     58  1.1  christos #endif /* ATHN_DEBUG */
     59  1.1  christos 
     60  1.1  christos #define LE_READ_4(p)	((p)[0] | (p)[1] << 8 | (p)[2] << 16 | (p)[3] << 24)
     61  1.1  christos #define LE_READ_2(p)	((p)[0] | (p)[1] << 8)
     62  1.1  christos 
     63  1.1  christos #define ATHN_RXBUFSZ	3872
     64  1.1  christos #define ATHN_TXBUFSZ	4096
     65  1.1  christos 
     66  1.1  christos #define ATHN_NRXBUFS	64
     67  1.1  christos #define ATHN_NTXBUFS	64	/* Shared between all Tx queues. */
     68  1.1  christos 
     69  1.1  christos struct athn_rx_radiotap_header {
     70  1.1  christos 	struct ieee80211_radiotap_header wr_ihdr;
     71  1.1  christos 	uint64_t	wr_tsft;
     72  1.1  christos 	uint8_t		wr_flags;
     73  1.1  christos 	uint8_t		wr_rate;
     74  1.1  christos 	uint16_t	wr_chan_freq;
     75  1.1  christos 	uint16_t	wr_chan_flags;
     76  1.1  christos 	int8_t		wr_dbm_antsignal;
     77  1.1  christos 	uint8_t		wr_antenna;
     78  1.8       mrg };
     79  1.1  christos 
     80  1.1  christos #define ATHN_RX_RADIOTAP_PRESENT					\
     81  1.1  christos 	(1 << IEEE80211_RADIOTAP_TSFT |					\
     82  1.1  christos 	 1 << IEEE80211_RADIOTAP_FLAGS |				\
     83  1.1  christos 	 1 << IEEE80211_RADIOTAP_RATE |					\
     84  1.1  christos 	 1 << IEEE80211_RADIOTAP_CHANNEL |				\
     85  1.1  christos 	 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL |			\
     86  1.1  christos 	 1 << IEEE80211_RADIOTAP_ANTENNA)
     87  1.1  christos 
     88  1.1  christos struct athn_tx_radiotap_header {
     89  1.1  christos 	struct ieee80211_radiotap_header wt_ihdr;
     90  1.1  christos 	uint8_t		wt_flags;
     91  1.1  christos 	uint8_t		wt_rate;
     92  1.1  christos 	uint16_t	wt_chan_freq;
     93  1.1  christos 	uint16_t	wt_chan_flags;
     94  1.8       mrg };
     95  1.1  christos 
     96  1.1  christos #define ATHN_TX_RADIOTAP_PRESENT					\
     97  1.1  christos 	(1 << IEEE80211_RADIOTAP_FLAGS |				\
     98  1.1  christos 	 1 << IEEE80211_RADIOTAP_RATE |					\
     99  1.1  christos 	 1 << IEEE80211_RADIOTAP_CHANNEL)
    100  1.1  christos 
    101  1.1  christos struct athn_tx_buf {
    102  1.1  christos 	SIMPLEQ_ENTRY(athn_tx_buf)	bf_list;
    103  1.1  christos 
    104  1.1  christos 	void				*bf_descs;
    105  1.1  christos 	bus_dmamap_t			bf_map;
    106  1.1  christos 	bus_addr_t			bf_daddr;
    107  1.1  christos 
    108  1.1  christos 	struct mbuf			*bf_m;
    109  1.1  christos 	struct ieee80211_node		*bf_ni;
    110  1.1  christos 	int				bf_txflags;
    111  1.1  christos #define ATHN_TXFLAG_PAPRD	(1 << 0)
    112  1.1  christos #define ATHN_TXFLAG_CAB		(1 << 1)
    113  1.1  christos };
    114  1.1  christos 
    115  1.1  christos struct athn_txq {
    116  1.1  christos 	SIMPLEQ_HEAD(, athn_tx_buf)	head;
    117  1.1  christos 	void				*lastds;
    118  1.1  christos 	struct athn_tx_buf		*wait;
    119  1.1  christos 	int				queued;
    120  1.1  christos };
    121  1.1  christos 
    122  1.1  christos struct athn_rx_buf {
    123  1.1  christos 	SIMPLEQ_ENTRY(athn_rx_buf)	bf_list;
    124  1.1  christos 
    125  1.1  christos 	void				*bf_desc;
    126  1.1  christos 	bus_dmamap_t			bf_map;
    127  1.1  christos 
    128  1.1  christos 	struct mbuf			*bf_m;
    129  1.1  christos 	bus_addr_t			bf_daddr;
    130  1.1  christos };
    131  1.1  christos 
    132  1.1  christos struct athn_rxq {
    133  1.1  christos 	struct athn_rx_buf		*bf;
    134  1.1  christos 
    135  1.1  christos 	void				*descs;
    136  1.1  christos 	void				*lastds;
    137  1.1  christos 	bus_dmamap_t			map;
    138  1.1  christos 	bus_dma_segment_t		seg;
    139  1.1  christos 	int				count;
    140  1.1  christos 
    141  1.1  christos 	SIMPLEQ_HEAD(, athn_rx_buf)	head;
    142  1.1  christos };
    143  1.1  christos 
    144  1.1  christos /* Software rate indexes. */
    145  1.1  christos #define ATHN_RIDX_CCK1	0
    146  1.1  christos #define ATHN_RIDX_CCK2	1
    147  1.1  christos #define ATHN_RIDX_OFDM6	4
    148  1.1  christos #define ATHN_RIDX_MCS0	12
    149  1.1  christos #define ATHN_RIDX_MCS15	27
    150  1.1  christos #define ATHN_RIDX_MAX	27
    151  1.1  christos #define ATHN_IS_HT_RIDX(ridx)	((ridx) >= ATHN_RIDX_MCS0)
    152  1.1  christos 
    153  1.1  christos static const struct athn_rate {
    154  1.1  christos 	uint8_t	rate;		/* Rate in 500Kbps unit or MCS if 0x80. */
    155  1.1  christos 	uint8_t	hwrate;		/* HW representation. */
    156  1.1  christos 	uint8_t	rspridx;	/* Control Response Frame rate index. */
    157  1.1  christos 	enum	ieee80211_phytype phy;
    158  1.1  christos } athn_rates[] = {
    159  1.1  christos 	{    2, 0x1b, 0, IEEE80211_T_DS },
    160  1.1  christos 	{    4, 0x1a, 1, IEEE80211_T_DS },
    161  1.1  christos 	{   11, 0x19, 1, IEEE80211_T_DS },
    162  1.1  christos 	{   22, 0x18, 1, IEEE80211_T_DS },
    163  1.1  christos 	{   12, 0x0b, 4, IEEE80211_T_OFDM },
    164  1.1  christos 	{   18, 0x0f, 4, IEEE80211_T_OFDM },
    165  1.1  christos 	{   24, 0x0a, 6, IEEE80211_T_OFDM },
    166  1.1  christos 	{   36, 0x0e, 6, IEEE80211_T_OFDM },
    167  1.1  christos 	{   48, 0x09, 8, IEEE80211_T_OFDM },
    168  1.1  christos 	{   72, 0x0d, 8, IEEE80211_T_OFDM },
    169  1.1  christos 	{   96, 0x08, 8, IEEE80211_T_OFDM },
    170  1.1  christos 	{  108, 0x0c, 8, IEEE80211_T_OFDM },
    171  1.1  christos 	{ 0x80, 0x80, 8, IEEE80211_T_OFDM },
    172  1.1  christos 	{ 0x81, 0x81, 8, IEEE80211_T_OFDM },
    173  1.1  christos 	{ 0x82, 0x82, 8, IEEE80211_T_OFDM },
    174  1.1  christos 	{ 0x83, 0x83, 8, IEEE80211_T_OFDM },
    175  1.1  christos 	{ 0x84, 0x84, 8, IEEE80211_T_OFDM },
    176  1.1  christos 	{ 0x85, 0x85, 8, IEEE80211_T_OFDM },
    177  1.1  christos 	{ 0x86, 0x86, 8, IEEE80211_T_OFDM },
    178  1.1  christos 	{ 0x87, 0x87, 8, IEEE80211_T_OFDM },
    179  1.1  christos 	{ 0x88, 0x88, 8, IEEE80211_T_OFDM },
    180  1.1  christos 	{ 0x89, 0x89, 8, IEEE80211_T_OFDM },
    181  1.1  christos 	{ 0x8a, 0x8a, 8, IEEE80211_T_OFDM },
    182  1.1  christos 	{ 0x8b, 0x8b, 8, IEEE80211_T_OFDM },
    183  1.1  christos 	{ 0x8c, 0x8c, 8, IEEE80211_T_OFDM },
    184  1.1  christos 	{ 0x8d, 0x8d, 8, IEEE80211_T_OFDM },
    185  1.1  christos 	{ 0x8e, 0x8e, 8, IEEE80211_T_OFDM },
    186  1.1  christos 	{ 0x8f, 0x8f, 8, IEEE80211_T_OFDM }
    187  1.1  christos };
    188  1.1  christos 
    189  1.1  christos struct athn_series {
    190  1.1  christos 	uint16_t	dur;
    191  1.1  christos 	uint8_t		hwrate;
    192  1.1  christos };
    193  1.1  christos 
    194  1.1  christos struct athn_pier {
    195  1.1  christos 	uint8_t		fbin;
    196  1.1  christos 	const uint8_t	*pwr[AR_PD_GAINS_IN_MASK];
    197  1.1  christos 	const uint8_t	*vpd[AR_PD_GAINS_IN_MASK];
    198  1.1  christos };
    199  1.1  christos 
    200  1.1  christos /*
    201  1.1  christos  * Structures used to store initialization values.
    202  1.1  christos  */
    203  1.1  christos struct athn_ini {
    204  1.1  christos 	int		nregs;
    205  1.1  christos 	const uint16_t	*regs;
    206  1.1  christos 	const uint32_t	*vals_5g20;
    207  1.1  christos #ifndef IEEE80211_NO_HT
    208  1.1  christos 	const uint32_t	*vals_5g40;
    209  1.1  christos 	const uint32_t	*vals_2g40;
    210  1.1  christos #endif
    211  1.1  christos 	const uint32_t	*vals_2g20;
    212  1.1  christos 	int		ncmregs;
    213  1.1  christos 	const uint16_t	*cmregs;
    214  1.1  christos 	const uint32_t	*cmvals;
    215  1.1  christos 	int		nfastregs;
    216  1.1  christos 	const uint16_t	*fastregs;
    217  1.1  christos 	const uint32_t	*fastvals_5g20;
    218  1.1  christos #ifndef IEEE80211_NO_HT
    219  1.1  christos 	const uint32_t	*fastvals_5g40;
    220  1.1  christos #endif
    221  1.1  christos };
    222  1.1  christos 
    223  1.1  christos struct athn_gain {
    224  1.1  christos 	int		nregs;
    225  1.1  christos 	const uint16_t	*regs;
    226  1.1  christos 	const uint32_t	*vals_5g;
    227  1.1  christos 	const uint32_t	*vals_2g;
    228  1.1  christos };
    229  1.1  christos 
    230  1.1  christos struct athn_addac {
    231  1.1  christos 	int		nvals;
    232  1.1  christos 	const uint32_t	*vals;
    233  1.1  christos };
    234  1.1  christos 
    235  1.1  christos struct athn_serdes {
    236  1.1  christos 	int		nvals;
    237  1.1  christos 	const uint32_t	*regs;
    238  1.1  christos 	const uint32_t	*vals;
    239  1.1  christos };
    240  1.1  christos 
    241  1.1  christos /* Rx queue software indexes. */
    242  1.1  christos #define ATHN_QID_LP		0
    243  1.5  jmcneill #define ATHN_QID_HP		1
    244  1.1  christos 
    245  1.1  christos /* Tx queue software indexes. */
    246  1.1  christos #define ATHN_QID_AC_BE		0
    247  1.1  christos #define ATHN_QID_PSPOLL		1
    248  1.1  christos #define ATHN_QID_AC_BK		2
    249  1.1  christos #define ATHN_QID_AC_VI		3
    250  1.1  christos #define ATHN_QID_AC_VO		4
    251  1.1  christos #define ATHN_QID_UAPSD		5
    252  1.1  christos #define ATHN_QID_CAB		6
    253  1.1  christos #define ATHN_QID_BEACON		7
    254  1.1  christos #define ATHN_QID_COUNT		8
    255  1.1  christos 
    256  1.1  christos /* Map Access Category to Tx queue Id. */
    257  1.2  christos static const uint8_t athn_ac2qid[WME_NUM_AC] = {
    258  1.2  christos 	ATHN_QID_AC_BE,	/* WME_AC_BE */
    259  1.2  christos 	ATHN_QID_AC_BK,	/* WME_AC_BK */
    260  1.2  christos 	ATHN_QID_AC_VI,	/* WME_AC_VI */
    261  1.2  christos 	ATHN_QID_AC_VO	/* WME_AC_VO */
    262  1.1  christos };
    263  1.1  christos 
    264  1.1  christos static const uint8_t athn_5ghz_chans[] = {
    265  1.1  christos 	/* UNII 1. */
    266  1.1  christos 	36, 40, 44, 48,
    267  1.1  christos 	/* UNII 2. */
    268  1.1  christos 	52, 56, 60, 64,
    269  1.1  christos 	/* Middle band. */
    270  1.1  christos 	100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140,
    271  1.1  christos 	/* UNII 3. */
    272  1.1  christos 	149, 153, 157, 161, 165
    273  1.1  christos };
    274  1.1  christos 
    275  1.1  christos /* Number of data bits per OFDM symbol for MCS[0-15]. */
    276  1.1  christos /* See tables 20-29, 20-30, 20-33, 20-34. */
    277  1.1  christos static const uint16_t ar_mcs_ndbps[][2] = {
    278  1.1  christos 	/* 20MHz  40MHz */
    279  1.1  christos 	{     26,    54 },	/* MCS0 */
    280  1.1  christos 	{     52,   108 },	/* MCS1 */
    281  1.1  christos 	{     78,   162 },	/* MCS2 */
    282  1.1  christos 	{    104,   216 },	/* MCS3 */
    283  1.1  christos 	{    156,   324 },	/* MCS4 */
    284  1.1  christos 	{    208,   432 },	/* MCS5 */
    285  1.1  christos 	{    234,   486 },	/* MCS6 */
    286  1.1  christos 	{    260,   540 },	/* MCS7 */
    287  1.1  christos 	{     26,   108 },	/* MCS8 */
    288  1.1  christos 	{     52,   216 },	/* MCS9 */
    289  1.1  christos 	{     78,   324 },	/* MCS10 */
    290  1.1  christos 	{    104,   432 },	/* MCS11 */
    291  1.1  christos 	{    156,   648 },	/* MCS12 */
    292  1.1  christos 	{    208,   864 },	/* MCS13 */
    293  1.1  christos 	{    234,   972 },	/* MCS14 */
    294  1.1  christos 	{    260,  1080 }	/* MCS15 */
    295  1.1  christos };
    296  1.1  christos 
    297  1.1  christos #define ATHN_POWER_OFDM6	0
    298  1.1  christos #define ATHN_POWER_OFDM9	1
    299  1.1  christos #define ATHN_POWER_OFDM12	2
    300  1.1  christos #define ATHN_POWER_OFDM18	3
    301  1.1  christos #define ATHN_POWER_OFDM24	4
    302  1.1  christos #define ATHN_POWER_OFDM36	5
    303  1.1  christos #define ATHN_POWER_OFDM48	6
    304  1.1  christos #define ATHN_POWER_OFDM54	7
    305  1.1  christos #define ATHN_POWER_CCK1_LP	8
    306  1.1  christos #define ATHN_POWER_CCK2_LP	9
    307  1.1  christos #define ATHN_POWER_CCK2_SP	10
    308  1.1  christos #define ATHN_POWER_CCK55_LP	11
    309  1.1  christos #define ATHN_POWER_CCK55_SP	12
    310  1.1  christos #define ATHN_POWER_CCK11_LP	13
    311  1.1  christos #define ATHN_POWER_CCK11_SP	14
    312  1.1  christos #define ATHN_POWER_XR		15
    313  1.1  christos #define ATHN_POWER_HT20(mcs)	(16 + (mcs))
    314  1.1  christos #define ATHN_POWER_HT40(mcs)	(40 + (mcs))
    315  1.1  christos #define ATHN_POWER_CCK_DUP	64
    316  1.1  christos #define ATHN_POWER_OFDM_DUP	65
    317  1.1  christos #define ATHN_POWER_CCK_EXT	66
    318  1.1  christos #define ATHN_POWER_OFDM_EXT	67
    319  1.1  christos #define ATHN_POWER_COUNT	68
    320  1.1  christos 
    321  1.1  christos struct athn_node {
    322  1.1  christos 	struct ieee80211_node		ni;
    323  1.1  christos 	struct ieee80211_amrr_node	amn;
    324  1.1  christos 	uint8_t				ridx[IEEE80211_RATE_MAXSIZE];
    325  1.1  christos 	uint8_t				fallback[IEEE80211_RATE_MAXSIZE];
    326  1.1  christos 	uint8_t				sta_index;
    327  1.1  christos };
    328  1.1  christos 
    329  1.1  christos /*
    330  1.1  christos  * Adaptive noise immunity state.
    331  1.1  christos  */
    332  1.1  christos #define ATHN_ANI_PERIOD		100
    333  1.1  christos #define ATHN_ANI_RSSI_THR_HIGH	40
    334  1.1  christos #define ATHN_ANI_RSSI_THR_LOW	7
    335  1.1  christos struct athn_ani {
    336  1.1  christos 	uint8_t		noise_immunity_level;
    337  1.1  christos 	uint8_t		spur_immunity_level;
    338  1.1  christos 	uint8_t		firstep_level;
    339  1.1  christos 	uint8_t		ofdm_weak_signal;
    340  1.1  christos 	uint8_t		cck_weak_signal;
    341  1.1  christos 
    342  1.1  christos 	uint32_t	listen_time;
    343  1.1  christos 
    344  1.1  christos 	uint32_t	ofdm_trig_high;
    345  1.1  christos 	uint32_t	ofdm_trig_low;
    346  1.1  christos 
    347  1.1  christos 	int32_t		cck_trig_high;
    348  1.1  christos 	int32_t		cck_trig_low;
    349  1.1  christos 
    350  1.1  christos 	uint32_t	ofdm_phy_err_base;
    351  1.1  christos 	uint32_t	cck_phy_err_base;
    352  1.1  christos 	uint32_t	ofdm_phy_err_count;
    353  1.1  christos 	uint32_t	cck_phy_err_count;
    354  1.1  christos 
    355  1.1  christos 	uint32_t	cyccnt;
    356  1.1  christos 	uint32_t	txfcnt;
    357  1.1  christos 	uint32_t	rxfcnt;
    358  1.1  christos };
    359  1.1  christos 
    360  1.1  christos struct athn_iq_cal {
    361  1.1  christos 	uint32_t	pwr_meas_i;
    362  1.1  christos 	uint32_t	pwr_meas_q;
    363  1.1  christos 	int32_t		iq_corr_meas;
    364  1.1  christos };
    365  1.1  christos 
    366  1.1  christos struct athn_adc_cal {
    367  1.1  christos 	uint32_t	pwr_meas_odd_i;
    368  1.1  christos 	uint32_t	pwr_meas_even_i;
    369  1.1  christos 	uint32_t	pwr_meas_odd_q;
    370  1.1  christos 	uint32_t	pwr_meas_even_q;
    371  1.1  christos };
    372  1.1  christos 
    373  1.1  christos struct athn_calib {
    374  1.1  christos 	int			nsamples;
    375  1.1  christos 	struct athn_iq_cal	iq[AR_MAX_CHAINS];
    376  1.1  christos 	struct athn_adc_cal	adc_gain[AR_MAX_CHAINS];
    377  1.1  christos 	struct athn_adc_cal	adc_dc_offset[AR_MAX_CHAINS];
    378  1.1  christos };
    379  1.1  christos 
    380  1.1  christos #define ATHN_NF_CAL_HIST_MAX	5
    381  1.1  christos 
    382  1.1  christos struct athn_softc;
    383  1.1  christos 
    384  1.1  christos struct athn_ops {
    385  1.1  christos 	/* Bus callbacks. */
    386  1.1  christos 	uint32_t	(*read)(struct athn_softc *, uint32_t);
    387  1.1  christos 	void		(*write)(struct athn_softc *, uint32_t, uint32_t);
    388  1.1  christos 	void		(*write_barrier)(struct athn_softc *);
    389  1.1  christos 
    390  1.1  christos 	void	(*setup)(struct athn_softc *);
    391  1.1  christos 	void	(*set_txpower)(struct athn_softc *, struct ieee80211_channel *,
    392  1.1  christos 		    struct ieee80211_channel *);
    393  1.1  christos 	void	(*spur_mitigate)(struct athn_softc *,
    394  1.1  christos 		    struct ieee80211_channel *, struct ieee80211_channel *);
    395  1.1  christos 	const struct ar_spur_chan *
    396  1.1  christos 		(*get_spur_chans)(struct athn_softc *, int);
    397  1.1  christos 	void	(*init_from_rom)(struct athn_softc *,
    398  1.1  christos 		    struct ieee80211_channel *, struct ieee80211_channel *);
    399  1.1  christos 	int	(*set_synth)(struct athn_softc *, struct ieee80211_channel *,
    400  1.1  christos 		    struct ieee80211_channel *);
    401  1.1  christos 	int	(*read_rom_data)(struct athn_softc *, uint32_t, void *, int);
    402  1.1  christos 	const uint8_t *
    403  1.1  christos 		(*get_rom_template)(struct athn_softc *, uint8_t);
    404  1.1  christos 	void	(*swap_rom)(struct athn_softc *);
    405  1.1  christos 	void	(*olpc_init)(struct athn_softc *);
    406  1.1  christos 	void	(*olpc_temp_compensation)(struct athn_softc *);
    407  1.1  christos 
    408  1.1  christos 	/* GPIO callbacks. */
    409  1.1  christos 	int	(*gpio_read)(struct athn_softc *, int);
    410  1.1  christos 	void	(*gpio_write)(struct athn_softc *, int, int);
    411  1.1  christos 	void	(*gpio_config_input)(struct athn_softc *, int);
    412  1.1  christos 	void	(*gpio_config_output)(struct athn_softc *, int, int);
    413  1.1  christos 	void	(*rfsilent_init)(struct athn_softc *);
    414  1.1  christos 
    415  1.1  christos 	/* DMA callbacks. */
    416  1.1  christos 	int	(*dma_alloc)(struct athn_softc *);
    417  1.1  christos 	void	(*dma_free)(struct athn_softc *);
    418  1.1  christos 	void	(*rx_enable)(struct athn_softc *);
    419  1.6    nonaka 	int	(*intr_status)(struct athn_softc *);
    420  1.1  christos 	int	(*intr)(struct athn_softc *);
    421  1.1  christos 	int	(*tx)(struct athn_softc *, struct mbuf *,
    422  1.1  christos 		    struct ieee80211_node *, int);
    423  1.1  christos 
    424  1.1  christos 	/* PHY callbacks. */
    425  1.1  christos 	void	(*set_rf_mode)(struct athn_softc *,
    426  1.1  christos 		    struct ieee80211_channel *);
    427  1.1  christos 	int	(*rf_bus_request)(struct athn_softc *);
    428  1.1  christos 	void	(*rf_bus_release)(struct athn_softc *);
    429  1.1  christos 	void	(*set_phy)(struct athn_softc *, struct ieee80211_channel *,
    430  1.1  christos 		    struct ieee80211_channel *);
    431  1.1  christos 	void	(*set_delta_slope)(struct athn_softc *,
    432  1.1  christos 		    struct ieee80211_channel *, struct ieee80211_channel *);
    433  1.1  christos 	void	(*enable_antenna_diversity)(struct athn_softc *);
    434  1.1  christos 	void	(*init_baseband)(struct athn_softc *);
    435  1.1  christos 	void	(*disable_phy)(struct athn_softc *);
    436  1.1  christos 	void	(*set_rxchains)(struct athn_softc *);
    437  1.1  christos 	void	(*noisefloor_calib)(struct athn_softc *);
    438  1.1  christos 	void	(*do_calib)(struct athn_softc *);
    439  1.1  christos 	void	(*next_calib)(struct athn_softc *);
    440  1.1  christos 	void	(*hw_init)(struct athn_softc *, struct ieee80211_channel *,
    441  1.1  christos 		    struct ieee80211_channel *);
    442  1.1  christos 	void	(*get_paprd_masks)(struct athn_softc *sc,
    443  1.1  christos 		    struct ieee80211_channel *, uint32_t *, uint32_t *);
    444  1.1  christos 
    445  1.1  christos 	/* ANI callbacks. */
    446  1.1  christos 	void	(*set_noise_immunity_level)(struct athn_softc *, int);
    447  1.1  christos 	void	(*enable_ofdm_weak_signal)(struct athn_softc *);
    448  1.1  christos 	void	(*disable_ofdm_weak_signal)(struct athn_softc *);
    449  1.1  christos 	void	(*set_cck_weak_signal)(struct athn_softc *, int);
    450  1.1  christos 	void	(*set_firstep_level)(struct athn_softc *, int);
    451  1.1  christos 	void	(*set_spur_immunity_level)(struct athn_softc *, int);
    452  1.1  christos };
    453  1.1  christos 
    454  1.1  christos struct athn_softc {
    455  1.1  christos 	device_t			sc_dev;
    456  1.1  christos 	device_suspensor_t		sc_suspensor;
    457  1.1  christos 	pmf_qual_t			sc_qual;
    458  1.1  christos 	struct ieee80211com		sc_ic;
    459  1.3  christos 	struct ethercom			sc_ec;
    460  1.3  christos #define sc_if	sc_ec.ec_if
    461  1.6    nonaka 	void				*sc_soft_ih;
    462  1.1  christos 
    463  1.1  christos #if 0
    464  1.1  christos 	int				(*sc_enable)(struct athn_softc *);
    465  1.1  christos 	void				(*sc_disable)(struct athn_softc *);
    466  1.1  christos 	void				(*sc_power)(struct athn_softc *, int);
    467  1.1  christos #endif
    468  1.1  christos 	void				(*sc_disable_aspm)(struct athn_softc *);
    469  1.1  christos 	void				(*sc_enable_extsynch)(
    470  1.1  christos 					    struct athn_softc *);
    471  1.1  christos 
    472  1.1  christos 	int				(*sc_newstate)(struct ieee80211com *,
    473  1.1  christos 					    enum ieee80211_state, int);
    474  1.1  christos 
    475  1.1  christos 	bus_dma_tag_t			sc_dmat;
    476  1.1  christos 
    477  1.1  christos 	callout_t			sc_scan_to;
    478  1.1  christos 	callout_t			sc_calib_to;
    479  1.1  christos 	struct ieee80211_amrr		sc_amrr;
    480  1.1  christos 
    481  1.1  christos 	u_int				sc_flags;
    482  1.1  christos #define ATHN_FLAG_PCIE			(1 << 0)
    483  1.1  christos #define ATHN_FLAG_USB			(1 << 1)
    484  1.1  christos #define ATHN_FLAG_OLPC			(1 << 2)
    485  1.1  christos #define ATHN_FLAG_PAPRD			(1 << 3)
    486  1.1  christos #define ATHN_FLAG_FAST_PLL_CLOCK	(1 << 4)
    487  1.1  christos #define ATHN_FLAG_RFSILENT		(1 << 5)
    488  1.1  christos #define ATHN_FLAG_RFSILENT_REVERSED	(1 << 6)
    489  1.1  christos #define ATHN_FLAG_BTCOEX2WIRE		(1 << 7)
    490  1.1  christos #define ATHN_FLAG_BTCOEX3WIRE		(1 << 8)
    491  1.1  christos /* Shortcut. */
    492  1.1  christos #define ATHN_FLAG_BTCOEX	(ATHN_FLAG_BTCOEX2WIRE | ATHN_FLAG_BTCOEX3WIRE)
    493  1.1  christos #define ATHN_FLAG_11A			(1 << 9)
    494  1.1  christos #define ATHN_FLAG_11G			(1 << 10)
    495  1.1  christos #define ATHN_FLAG_11N			(1 << 11)
    496  1.1  christos #define ATHN_FLAG_AN_TOP2_FIXUP		(1 << 12)
    497  1.1  christos #define ATHN_FLAG_NON_ENTERPRISE	(1 << 13)
    498  1.1  christos #define ATHN_FLAG_3TREDUCE_CHAIN	(1 << 14)
    499  1.1  christos 
    500  1.1  christos 	uint8_t				sc_ngpiopins;
    501  1.1  christos 	int				sc_led_pin;
    502  1.1  christos 	int				sc_rfsilent_pin;
    503  1.1  christos 	int				sc_led_state;
    504  1.1  christos 	uint32_t			sc_isync;
    505  1.1  christos 	uint32_t			sc_imask;
    506  1.1  christos 
    507  1.1  christos 	uint16_t			sc_mac_ver;
    508  1.1  christos 	uint8_t				sc_mac_rev;
    509  1.1  christos 	uint8_t				sc_rf_rev;
    510  1.1  christos 	uint16_t			sc_eep_rev;
    511  1.1  christos 
    512  1.1  christos 	uint8_t				sc_txchainmask;
    513  1.1  christos 	uint8_t				sc_rxchainmask;
    514  1.1  christos 	uint8_t				sc_ntxchains;
    515  1.1  christos 	uint8_t				sc_nrxchains;
    516  1.1  christos 
    517  1.1  christos 	uint8_t				sc_sup_calib_mask;
    518  1.1  christos 	uint8_t				sc_cur_calib_mask;
    519  1.1  christos #define ATHN_CAL_IQ		(1 << 0)
    520  1.1  christos #define ATHN_CAL_ADC_GAIN	(1 << 1)
    521  1.1  christos #define ATHN_CAL_ADC_DC		(1 << 2)
    522  1.1  christos #define ATHN_CAL_TEMP		(1 << 3)
    523  1.1  christos 
    524  1.1  christos 	struct ieee80211_channel	*sc_curchan;
    525  1.1  christos 	struct ieee80211_channel	*sc_curchanext;
    526  1.1  christos 
    527  1.1  christos 	/* Open Loop Power Control. */
    528  1.1  christos 	int8_t				sc_tx_gain_tbl[AR9280_TX_GAIN_TABLE_SIZE];
    529  1.1  christos 	int8_t				sc_pdadc;
    530  1.1  christos 	int8_t				sc_tcomp;
    531  1.1  christos 	int				sc_olpc_ticks;
    532  1.1  christos 
    533  1.1  christos 	/* PA predistortion. */
    534  1.1  christos 	uint16_t			sc_gain1[AR_MAX_CHAINS];
    535  1.1  christos 	uint32_t			sc_txgain[AR9003_TX_GAIN_TABLE_SIZE];
    536  1.1  christos 	int16_t				sc_pa_in[AR_MAX_CHAINS]
    537  1.1  christos 					     [AR9003_PAPRD_MEM_TAB_SIZE];
    538  1.1  christos 	int16_t				sc_angle[AR_MAX_CHAINS]
    539  1.1  christos 					     [AR9003_PAPRD_MEM_TAB_SIZE];
    540  1.1  christos 	int32_t				sc_trainpow;
    541  1.1  christos 	uint8_t				sc_paprd_curchain;
    542  1.1  christos 
    543  1.1  christos 	uint32_t			sc_rwbuf[64];
    544  1.1  christos 
    545  1.1  christos 	size_t				sc_kc_entries;
    546  1.1  christos 
    547  1.1  christos 	void				*sc_eep;
    548  1.1  christos 	const void			*sc_eep_def;
    549  1.1  christos 	uint32_t			sc_eep_base;
    550  1.1  christos 	uint32_t			sc_eep_size;
    551  1.1  christos 
    552  1.1  christos 	struct athn_rxq			sc_rxq[2];
    553  1.1  christos 	struct athn_txq			sc_txq[31];
    554  1.1  christos 
    555  1.1  christos 	void				*sc_descs;
    556  1.1  christos 	bus_dmamap_t			sc_map;
    557  1.1  christos 	bus_dma_segment_t		sc_seg;
    558  1.1  christos 	SIMPLEQ_HEAD(, athn_tx_buf)	sc_txbufs;
    559  1.1  christos 	struct athn_tx_buf		*sc_bcnbuf;
    560  1.1  christos 	struct athn_tx_buf		sc_txpool[ATHN_NTXBUFS];
    561  1.1  christos 
    562  1.1  christos 	bus_dmamap_t			sc_txsmap;
    563  1.1  christos 	bus_dma_segment_t		sc_txsseg;
    564  1.1  christos 	void				*sc_txsring;
    565  1.1  christos 	int				sc_txscur;
    566  1.1  christos 
    567  1.7   msaitoh 	u_short				sc_if_flags;
    568  1.1  christos 	int				sc_tx_timer;
    569  1.1  christos 
    570  1.1  christos 	const struct athn_ini		*sc_ini;
    571  1.1  christos 	const struct athn_gain		*sc_rx_gain;
    572  1.1  christos 	const struct athn_gain		*sc_tx_gain;
    573  1.1  christos 	const struct athn_addac		*sc_addac;
    574  1.1  christos 	const struct athn_serdes	*sc_serdes;
    575  1.1  christos 	uint32_t			sc_workaround;
    576  1.1  christos 	uint32_t			sc_obs_off;
    577  1.1  christos 	uint32_t			sc_gpio_input_en_off;
    578  1.1  christos 
    579  1.1  christos 	struct athn_ops			sc_ops;
    580  1.1  christos 
    581  1.1  christos 	int				sc_fixed_ridx;
    582  1.1  christos 
    583  1.1  christos 	int16_t				sc_cca_min_2g;
    584  1.1  christos 	int16_t				sc_cca_max_2g;
    585  1.1  christos 	int16_t				sc_cca_min_5g;
    586  1.1  christos 	int16_t				sc_cca_max_5g;
    587  1.1  christos 	int16_t				sc_def_nf;
    588  1.1  christos 	struct {
    589  1.1  christos 		int16_t	nf[AR_MAX_CHAINS];
    590  1.1  christos 		int16_t	nf_ext[AR_MAX_CHAINS];
    591  1.1  christos 	}				sc_nf_hist[ATHN_NF_CAL_HIST_MAX];
    592  1.1  christos 	int				sc_nf_hist_cur;
    593  1.1  christos 	int16_t				sc_nf_priv[AR_MAX_CHAINS];
    594  1.1  christos 	int16_t				sc_nf_ext_priv[AR_MAX_CHAINS];
    595  1.1  christos 	int				sc_pa_calib_ticks;
    596  1.1  christos 
    597  1.1  christos 	struct athn_calib		sc_calib;
    598  1.1  christos 	struct athn_ani			sc_ani;
    599  1.1  christos 
    600  1.1  christos 	struct bpf_if *			sc_drvbpf;
    601  1.1  christos 
    602  1.1  christos 	union {
    603  1.1  christos 		struct athn_rx_radiotap_header th;
    604  1.1  christos 		uint8_t pad[IEEE80211_RADIOTAP_HDRLEN];
    605  1.1  christos 	} sc_rxtapu;
    606  1.1  christos #define sc_rxtap			sc_rxtapu.th
    607  1.1  christos 	int				sc_rxtap_len;
    608  1.1  christos 
    609  1.1  christos 	union {
    610  1.1  christos 		struct athn_tx_radiotap_header th;
    611  1.1  christos 		uint8_t pad[IEEE80211_RADIOTAP_HDRLEN];
    612  1.1  christos 	} sc_txtapu;
    613  1.1  christos #define sc_txtap			sc_txtapu.th
    614  1.1  christos 	int				sc_txtap_len;
    615  1.1  christos 
    616  1.1  christos 	/*
    617  1.1  christos 	 * Attach overrides.  Set before calling athn_attach().
    618  1.1  christos 	 */
    619  1.1  christos 	int				sc_max_aid;
    620  1.1  christos 	int				(*sc_media_change)(struct ifnet *);
    621  1.1  christos };
    622  1.1  christos 
    623  1.1  christos int	athn_attach(struct athn_softc *);
    624  1.1  christos void	athn_detach(struct athn_softc *);
    625  1.1  christos void	athn_suspend(struct athn_softc *);
    626  1.4    martin bool	athn_resume(struct athn_softc *);
    627  1.1  christos int	athn_intr(void *);
    628  1.1  christos 
    629  1.1  christos /* used by if_athn_usb.c */
    630  1.1  christos void	athn_btcoex_init(struct athn_softc *);
    631  1.1  christos int	athn_hw_reset(struct athn_softc *, struct ieee80211_channel *,
    632  1.1  christos 	    struct ieee80211_channel *, int);
    633  1.1  christos void	athn_init_pll(struct athn_softc *, const struct ieee80211_channel *);
    634  1.1  christos void	athn_led_init(struct athn_softc *);
    635  1.1  christos int	athn_reset(struct athn_softc *, int);
    636  1.1  christos void	athn_reset_key(struct athn_softc *, int);
    637  1.1  christos void	athn_rx_start(struct athn_softc *);
    638  1.1  christos void	athn_set_bss(struct athn_softc *, struct ieee80211_node *);
    639  1.1  christos int	athn_set_chan(struct athn_softc *, struct ieee80211_channel *,
    640  1.1  christos 	    struct ieee80211_channel *);
    641  1.1  christos void	athn_set_hostap_timers(struct athn_softc *);
    642  1.1  christos void	athn_set_led(struct athn_softc *, int);
    643  1.1  christos void	athn_set_opmode(struct athn_softc *);
    644  1.1  christos int	athn_set_power_awake(struct athn_softc *);
    645  1.1  christos void	athn_set_power_sleep(struct athn_softc *);
    646  1.1  christos void	athn_set_rxfilter(struct athn_softc *, uint32_t);
    647  1.1  christos void	athn_set_sta_timers(struct athn_softc *);
    648  1.1  christos void	athn_updateslot(struct ifnet *);
    649  1.1  christos 
    650  1.1  christos #ifdef notyet_edca
    651  1.1  christos void	athn_updateedca(struct ieee80211com *);
    652  1.1  christos #endif
    653  1.1  christos #ifdef notyet
    654  1.1  christos void	athn_delete_key(struct ieee80211com *, struct ieee80211_node *,
    655  1.1  christos 	    struct ieee80211_key *);
    656  1.1  christos int	athn_set_key(struct ieee80211com *, struct ieee80211_node *,
    657  1.1  christos 	    struct ieee80211_key *);
    658  1.1  christos #endif /* notyet */
    659  1.1  christos 
    660  1.1  christos /* used by ar9285.c */
    661  1.1  christos uint8_t	athn_chan2fbin(struct ieee80211_channel *);
    662  1.1  christos void	athn_get_pier_ival(uint8_t, const uint8_t *, int, int *, int *);
    663  1.1  christos 
    664  1.1  christos /* used by arn5008.c and arn9003.c */
    665  1.1  christos void	athn_config_nonpcie(struct athn_softc *);
    666  1.1  christos void	athn_config_pcie(struct athn_softc *);
    667  1.1  christos void	athn_get_delta_slope(uint32_t, uint32_t *, uint32_t *);
    668  1.1  christos void	athn_inc_tx_trigger_level(struct athn_softc *);
    669  1.1  christos void	athn_stop(struct ifnet *, int);
    670  1.1  christos void	athn_stop_tx_dma(struct athn_softc *, int);
    671  1.1  christos int	athn_tx_pending(struct athn_softc *, int);
    672  1.1  christos int	athn_txtime(struct athn_softc *, int, int, u_int);
    673  1.1  christos 
    674  1.1  christos /* used by arn5008.c, arn9003.c, arn9287.c, and arn9380.c */
    675  1.1  christos int	athn_interpolate(int, int, int, int, int);
    676  1.1  christos 
    677  1.1  christos #endif /* _ATHNVAR_H_ */
    678