Convert RSSI into signal strength (relative to noise floor)
[dragonfly/port-amd64.git] / sys / dev / netif / bwi / bwirf.h
blobbbf8c5512a8ead54062e860472b4848592e4f7da
1 /*
2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Sepherosa Ziehau <sepherosa@gmail.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * $DragonFly: src/sys/dev/netif/bwi/bwirf.h,v 1.2 2007/09/15 09:59:29 sephe Exp $
37 #ifndef _BWI_RF_H
38 #define _BWI_RF_H
40 int bwi_rf_attach(struct bwi_mac *);
41 void bwi_rf_clear_state(struct bwi_rf *);
43 int bwi_rf_map_txpower(struct bwi_mac *);
44 void bwi_rf_lo_adjust(struct bwi_mac *, const struct bwi_tpctl *);
45 void bwi_rf_set_chan(struct bwi_mac *, u_int, int);
46 void bwi_rf_get_gains(struct bwi_mac *);
47 void bwi_rf_init(struct bwi_mac *);
48 void bwi_rf_init_bcm2050(struct bwi_mac *);
49 void bwi_rf_lo_update(struct bwi_mac *);
50 void bwi_rf_init_hw_nrssi_table(struct bwi_mac *, uint16_t);
51 void bwi_rf_set_ant_mode(struct bwi_mac *, int);
53 void bwi_rf_clear_tssi(struct bwi_mac *);
54 int bwi_rf_get_latest_tssi(struct bwi_mac *, int8_t[], uint16_t);
55 int bwi_rf_tssi2dbm(struct bwi_mac *, int8_t, int8_t *);
57 void bwi_rf_write(struct bwi_mac *, uint16_t, uint16_t);
58 uint16_t bwi_rf_read(struct bwi_mac *, uint16_t);
60 static __inline void
61 bwi_rf_off(struct bwi_mac *_mac)
63 _mac->mac_rf.rf_off(_mac);
64 /* TODO:LED */
66 _mac->mac_rf.rf_flags &= ~BWI_RF_F_ON;
69 static __inline void
70 bwi_rf_on(struct bwi_mac *_mac)
72 if (_mac->mac_rf.rf_flags & BWI_RF_F_ON)
73 return;
75 _mac->mac_rf.rf_on(_mac);
76 /* TODO: LED */
78 _mac->mac_rf.rf_flags |= BWI_RF_F_ON;
81 static __inline void
82 bwi_rf_calc_nrssi_slope(struct bwi_mac *_mac)
84 _mac->mac_rf.rf_calc_nrssi_slope(_mac);
87 static __inline void
88 bwi_rf_set_nrssi_thr(struct bwi_mac *_mac)
90 _mac->mac_rf.rf_set_nrssi_thr(_mac);
93 static __inline int
94 bwi_rf_calc_rssi(struct bwi_mac *_mac, const struct bwi_rxbuf_hdr *_hdr)
96 return _mac->mac_rf.rf_calc_rssi(_mac, _hdr);
99 #define RF_WRITE(mac, ofs, val) bwi_rf_write((mac), (ofs), (val))
100 #define RF_READ(mac, ofs) bwi_rf_read((mac), (ofs))
102 #define RF_SETBITS(mac, ofs, bits) \
103 RF_WRITE((mac), (ofs), RF_READ((mac), (ofs)) | (bits))
104 #define RF_CLRBITS(mac, ofs, bits) \
105 RF_WRITE((mac), (ofs), RF_READ((mac), (ofs)) & ~(bits))
106 #define RF_FILT_SETBITS(mac, ofs, filt, bits) \
107 RF_WRITE((mac), (ofs), (RF_READ((mac), (ofs)) & (filt)) | (bits))
109 #define BWI_RFR_ATTEN 0x43
111 #define BWI_RFR_TXPWR 0x52
112 #define BWI_RFR_TXPWR1_MASK __BITS(6, 4)
114 #define BWI_RFR_BBP_ATTEN 0x60
115 #define BWI_RFR_BBP_ATTEN_CALIB_BIT __BIT(0)
116 #define BWI_RFR_BBP_ATTEN_CALIB_IDX __BITS(4, 1)
119 * TSSI -- TX power maps
122 * http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table
123 * B PHY
125 #define BWI_TXPOWER_MAP_11B \
126 0x4d, 0x4c, 0x4b, 0x4a, 0x4a, 0x49, 0x48, 0x47, \
127 0x47, 0x46, 0x45, 0x45, 0x44, 0x43, 0x42, 0x42, \
128 0x41, 0x40, 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, \
129 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x32, 0x31, \
130 0x30, 0x2f, 0x2d, 0x2c, 0x2b, 0x29, 0x28, 0x26, \
131 0x25, 0x23, 0x21, 0x1f, 0x1d, 0x1a, 0x17, 0x14, \
132 0x10, 0x0c, 0x06, 0x00, -7, -7, -7, -7, \
133 -7, -7, -7, -7, -7, -7, -7, -7
135 * http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table
136 * G PHY
138 #define BWI_TXPOWER_MAP_11G \
139 77, 77, 77, 76, 76, 76, 75, 75, \
140 74, 74, 73, 73, 73, 72, 72, 71, \
141 71, 70, 70, 69, 68, 68, 67, 67, \
142 66, 65, 65, 64, 63, 63, 62, 61, \
143 60, 59, 58, 57, 56, 55, 54, 53, \
144 52, 50, 49, 47, 45, 43, 40, 37, \
145 33, 28, 22, 14, 5, -7, -20, -20, \
146 -20, -20, -20, -20, -20, -20, -20, -20
148 #endif /* !_BWI_RF_H */