xref: /freebsd/sys/dev/bwi/bwirf.h (revision 2ff63af9b88c7413b7d71715b5532625752a248e)
1*7282444bSPedro F. Giffuni /*-
2*7282444bSPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*7282444bSPedro F. Giffuni  *
412e36acbSWarner Losh  * Copyright (c) 2007 The DragonFly Project.  All rights reserved.
512e36acbSWarner Losh  *
612e36acbSWarner Losh  * This code is derived from software contributed to The DragonFly Project
712e36acbSWarner Losh  * by Sepherosa Ziehau <sepherosa@gmail.com>
812e36acbSWarner Losh  *
912e36acbSWarner Losh  * Redistribution and use in source and binary forms, with or without
1012e36acbSWarner Losh  * modification, are permitted provided that the following conditions
1112e36acbSWarner Losh  * are met:
1212e36acbSWarner Losh  *
1312e36acbSWarner Losh  * 1. Redistributions of source code must retain the above copyright
1412e36acbSWarner Losh  *    notice, this list of conditions and the following disclaimer.
1512e36acbSWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
1612e36acbSWarner Losh  *    notice, this list of conditions and the following disclaimer in
1712e36acbSWarner Losh  *    the documentation and/or other materials provided with the
1812e36acbSWarner Losh  *    distribution.
1912e36acbSWarner Losh  * 3. Neither the name of The DragonFly Project nor the names of its
2012e36acbSWarner Losh  *    contributors may be used to endorse or promote products derived
2112e36acbSWarner Losh  *    from this software without specific, prior written permission.
2212e36acbSWarner Losh  *
2312e36acbSWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2412e36acbSWarner Losh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2512e36acbSWarner Losh  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2612e36acbSWarner Losh  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
2712e36acbSWarner Losh  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2812e36acbSWarner Losh  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
2912e36acbSWarner Losh  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
3012e36acbSWarner Losh  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
3112e36acbSWarner Losh  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3212e36acbSWarner Losh  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3312e36acbSWarner Losh  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3412e36acbSWarner Losh  * SUCH DAMAGE.
3512e36acbSWarner Losh  *
3612e36acbSWarner Losh  * $DragonFly: src/sys/dev/netif/bwi/bwirf.h,v 1.3 2007/10/03 04:53:19 sephe Exp $
3712e36acbSWarner Losh  */
3812e36acbSWarner Losh 
3912e36acbSWarner Losh #ifndef _BWI_RF_H
4012e36acbSWarner Losh #define _BWI_RF_H
4112e36acbSWarner Losh 
4212e36acbSWarner Losh int		bwi_rf_attach(struct bwi_mac *);
4312e36acbSWarner Losh void		bwi_rf_clear_state(struct bwi_rf *);
4412e36acbSWarner Losh 
4512e36acbSWarner Losh int		bwi_rf_map_txpower(struct bwi_mac *);
4612e36acbSWarner Losh void		bwi_rf_lo_adjust(struct bwi_mac *, const struct bwi_tpctl *);
4712e36acbSWarner Losh void		bwi_rf_set_chan(struct bwi_mac *, u_int, int);
4812e36acbSWarner Losh void		bwi_rf_get_gains(struct bwi_mac *);
4912e36acbSWarner Losh void		bwi_rf_init(struct bwi_mac *);
5012e36acbSWarner Losh void		bwi_rf_init_bcm2050(struct bwi_mac *);
5112e36acbSWarner Losh void		bwi_rf_init_hw_nrssi_table(struct bwi_mac *, uint16_t);
5212e36acbSWarner Losh void		bwi_rf_set_ant_mode(struct bwi_mac *, int);
5312e36acbSWarner Losh 
5412e36acbSWarner Losh void		bwi_rf_clear_tssi(struct bwi_mac *);
5512e36acbSWarner Losh int		bwi_rf_get_latest_tssi(struct bwi_mac *, int8_t[], uint16_t);
5612e36acbSWarner Losh int		bwi_rf_tssi2dbm(struct bwi_mac *, int8_t, int8_t *);
5712e36acbSWarner Losh 
5812e36acbSWarner Losh void		bwi_rf_write(struct bwi_mac *, uint16_t, uint16_t);
5912e36acbSWarner Losh uint16_t	bwi_rf_read(struct bwi_mac *, uint16_t);
6012e36acbSWarner Losh 
6112e36acbSWarner Losh static __inline void
bwi_rf_off(struct bwi_mac * _mac)6212e36acbSWarner Losh bwi_rf_off(struct bwi_mac *_mac)
6312e36acbSWarner Losh {
6412e36acbSWarner Losh 	_mac->mac_rf.rf_off(_mac);
6512e36acbSWarner Losh 	/* TODO:LED */
6612e36acbSWarner Losh 
6712e36acbSWarner Losh 	_mac->mac_rf.rf_flags &= ~BWI_RF_F_ON;
6812e36acbSWarner Losh }
6912e36acbSWarner Losh 
7012e36acbSWarner Losh static __inline void
bwi_rf_on(struct bwi_mac * _mac)7112e36acbSWarner Losh bwi_rf_on(struct bwi_mac *_mac)
7212e36acbSWarner Losh {
7312e36acbSWarner Losh 	if (_mac->mac_rf.rf_flags & BWI_RF_F_ON)
7412e36acbSWarner Losh 		return;
7512e36acbSWarner Losh 
7612e36acbSWarner Losh 	_mac->mac_rf.rf_on(_mac);
7712e36acbSWarner Losh 	/* TODO: LED */
7812e36acbSWarner Losh 
7912e36acbSWarner Losh 	_mac->mac_rf.rf_flags |= BWI_RF_F_ON;
8012e36acbSWarner Losh }
8112e36acbSWarner Losh 
8212e36acbSWarner Losh static __inline void
bwi_rf_calc_nrssi_slope(struct bwi_mac * _mac)8312e36acbSWarner Losh bwi_rf_calc_nrssi_slope(struct bwi_mac *_mac)
8412e36acbSWarner Losh {
8512e36acbSWarner Losh 	_mac->mac_rf.rf_calc_nrssi_slope(_mac);
8612e36acbSWarner Losh }
8712e36acbSWarner Losh 
8812e36acbSWarner Losh static __inline void
bwi_rf_set_nrssi_thr(struct bwi_mac * _mac)8912e36acbSWarner Losh bwi_rf_set_nrssi_thr(struct bwi_mac *_mac)
9012e36acbSWarner Losh {
9112e36acbSWarner Losh 	_mac->mac_rf.rf_set_nrssi_thr(_mac);
9212e36acbSWarner Losh }
9312e36acbSWarner Losh 
9412e36acbSWarner Losh static __inline int
bwi_rf_calc_rssi(struct bwi_mac * _mac,const struct bwi_rxbuf_hdr * _hdr)9512e36acbSWarner Losh bwi_rf_calc_rssi(struct bwi_mac *_mac, const struct bwi_rxbuf_hdr *_hdr)
9612e36acbSWarner Losh {
9712e36acbSWarner Losh 	return _mac->mac_rf.rf_calc_rssi(_mac, _hdr);
9812e36acbSWarner Losh }
9912e36acbSWarner Losh 
10012e36acbSWarner Losh static __inline int
bwi_rf_calc_noise(struct bwi_mac * _mac)10112e36acbSWarner Losh bwi_rf_calc_noise(struct bwi_mac *_mac)
10212e36acbSWarner Losh {
10312e36acbSWarner Losh 	return _mac->mac_rf.rf_calc_noise(_mac);
10412e36acbSWarner Losh }
10512e36acbSWarner Losh 
10612e36acbSWarner Losh static __inline void
bwi_rf_lo_update(struct bwi_mac * _mac)10712e36acbSWarner Losh bwi_rf_lo_update(struct bwi_mac *_mac)
10812e36acbSWarner Losh {
10912e36acbSWarner Losh 	return _mac->mac_rf.rf_lo_update(_mac);
11012e36acbSWarner Losh }
11112e36acbSWarner Losh 
11212e36acbSWarner Losh #define RF_WRITE(mac, ofs, val)		bwi_rf_write((mac), (ofs), (val))
11312e36acbSWarner Losh #define RF_READ(mac, ofs)		bwi_rf_read((mac), (ofs))
11412e36acbSWarner Losh 
11512e36acbSWarner Losh #define RF_SETBITS(mac, ofs, bits)		\
11612e36acbSWarner Losh 	RF_WRITE((mac), (ofs), RF_READ((mac), (ofs)) | (bits))
11712e36acbSWarner Losh #define RF_CLRBITS(mac, ofs, bits)		\
11812e36acbSWarner Losh 	RF_WRITE((mac), (ofs), RF_READ((mac), (ofs)) & ~(bits))
11912e36acbSWarner Losh #define RF_FILT_SETBITS(mac, ofs, filt, bits)	\
12012e36acbSWarner Losh 	RF_WRITE((mac), (ofs), (RF_READ((mac), (ofs)) & (filt)) | (bits))
12112e36acbSWarner Losh 
12212e36acbSWarner Losh #define BWI_RFR_ATTEN			0x43
12312e36acbSWarner Losh 
12412e36acbSWarner Losh #define BWI_RFR_TXPWR			0x52
12512e36acbSWarner Losh #define BWI_RFR_TXPWR1_MASK		__BITS(6, 4)
12612e36acbSWarner Losh 
12712e36acbSWarner Losh #define BWI_RFR_BBP_ATTEN		0x60
12812e36acbSWarner Losh #define BWI_RFR_BBP_ATTEN_CALIB_BIT	__BIT(0)
12912e36acbSWarner Losh #define BWI_RFR_BBP_ATTEN_CALIB_IDX	__BITS(4, 1)
13012e36acbSWarner Losh 
13112e36acbSWarner Losh /*
13212e36acbSWarner Losh  * TSSI -- TX power maps
13312e36acbSWarner Losh  */
13412e36acbSWarner Losh /*
13512e36acbSWarner Losh  * http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table
13612e36acbSWarner Losh  * B PHY
13712e36acbSWarner Losh  */
13812e36acbSWarner Losh #define BWI_TXPOWER_MAP_11B \
13912e36acbSWarner Losh 	0x4d,	0x4c,	0x4b,	0x4a,	0x4a,	0x49,	0x48,	0x47,	\
14012e36acbSWarner Losh 	0x47,	0x46,	0x45,	0x45,	0x44,	0x43,	0x42,	0x42,	\
14112e36acbSWarner Losh 	0x41,	0x40,	0x3f,	0x3e,	0x3d,	0x3c,	0x3b,	0x3a,	\
14212e36acbSWarner Losh 	0x39,	0x38,	0x37,	0x36,	0x35,	0x34,	0x32,	0x31,	\
14312e36acbSWarner Losh 	0x30,	0x2f,	0x2d,	0x2c,	0x2b,	0x29,	0x28,	0x26,	\
14412e36acbSWarner Losh 	0x25,	0x23,	0x21,	0x1f,	0x1d,	0x1a,	0x17,	0x14,	\
14512e36acbSWarner Losh 	0x10,	0x0c,	0x06,	0x00,	-7,	-7,	-7,	-7, 	\
14612e36acbSWarner Losh 	-7,	-7,	-7,	-7,	-7,	-7,	-7,	-7
14712e36acbSWarner Losh /*
14812e36acbSWarner Losh  * http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table
14912e36acbSWarner Losh  * G PHY
15012e36acbSWarner Losh  */
15112e36acbSWarner Losh #define BWI_TXPOWER_MAP_11G \
15212e36acbSWarner Losh 	77,	77,	77,	76,	76,	76,	75,	75,	\
15312e36acbSWarner Losh 	74,	74,	73,	73,	73,	72,	72,	71,	\
15412e36acbSWarner Losh 	71,	70,	70,	69,	68,	68,	67,	67,	\
15512e36acbSWarner Losh 	66,	65,	65,	64,	63,	63,	62,	61,	\
15612e36acbSWarner Losh 	60,	59,	58,	57,	56,	55,	54,	53,	\
15712e36acbSWarner Losh 	52,	50,	49,	47,	45,	43,	40,	37,	\
15812e36acbSWarner Losh 	33,	28,	22,	14,	5,	-7,	-20,	-20,	\
15912e36acbSWarner Losh 	-20,	-20,	-20,	-20,	-20,	-20,	-20,	-20
16012e36acbSWarner Losh 
16112e36acbSWarner Losh #endif	/* !_BWI_RF_H */
162