1 /* $OpenBSD: if_urtwn.c,v 1.16 2011/02/10 17:26:40 jakemsr Exp $ */
4 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
5 * Copyright (c) 2014 Kevin Lo <kevlo@FreeBSD.org>
6 * Copyright (c) 2015-2016 Andriy Voskoboinyk <avos@FreeBSD.org>
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
26 #include <sys/param.h>
28 #include <sys/mutex.h>
30 #include <sys/kernel.h>
31 #include <sys/socket.h>
32 #include <sys/systm.h>
33 #include <sys/malloc.h>
34 #include <sys/queue.h>
35 #include <sys/taskqueue.h>
37 #include <sys/endian.h>
38 #include <sys/linker.h>
41 #include <net/ethernet.h>
42 #include <net/if_media.h>
44 #include <net80211/ieee80211_var.h>
45 #include <net80211/ieee80211_radiotap.h>
47 #include <dev/rtwn/if_rtwnreg.h>
48 #include <dev/rtwn/if_rtwnvar.h>
50 #include <dev/rtwn/if_rtwn_debug.h>
51 #include <dev/rtwn/if_rtwn_efuse.h>
53 #include <dev/rtwn/rtl8192c/r92c.h>
54 #include <dev/rtwn/rtl8192c/r92c_priv.h>
55 #include <dev/rtwn/rtl8192c/r92c_var.h>
56 #include <dev/rtwn/rtl8192c/r92c_rom_image.h>
59 r92c_set_chains(struct rtwn_softc *sc)
61 struct r92c_softc *rs = sc->sc_priv;
63 if (rs->chip & R92C_CHIP_92C) {
64 sc->ntxchains = (rs->chip & R92C_CHIP_92C_1T2R) ? 1 : 2;
73 r92c_efuse_postread(struct rtwn_softc *sc)
75 struct r92c_softc *rs = sc->sc_priv;
77 /* XXX Weird but this is what the vendor driver does. */
78 sc->next_rom_addr = 0x1fa;
79 (void) rtwn_efuse_read_next(sc, &rs->pa_setting);
80 RTWN_DPRINTF(sc, RTWN_DEBUG_ROM, "%s: PA setting=0x%x\n", __func__,
85 r92c_parse_rom(struct rtwn_softc *sc, uint8_t *buf)
87 struct r92c_softc *rs = sc->sc_priv;
88 struct rtwn_r92c_txpwr *rt = rs->rs_txpwr;
89 struct r92c_rom *rom = (struct r92c_rom *)buf;
92 rs->board_type = MS(rom->rf_opt1, R92C_ROM_RF1_BOARD_TYPE);
93 rs->regulatory = MS(rom->rf_opt1, R92C_ROM_RF1_REGULATORY);
94 RTWN_DPRINTF(sc, RTWN_DEBUG_ROM, "%s: regulatory type=%d\n",
95 __func__, rs->regulatory);
97 /* Need to be set before postinit() (but after preinit()). */
98 rtwn_r92c_set_rom_opts(sc, buf);
101 for (j = 0; j < R92C_GROUP_2G; j++) {
102 for (i = 0; i < sc->ntxchains; i++) {
103 rt->cck_tx_pwr[i][j] = rom->cck_tx_pwr[i][j];
104 rt->ht40_1s_tx_pwr[i][j] = rom->ht40_1s_tx_pwr[i][j];
107 rt->ht40_2s_tx_pwr_diff[0][j] =
108 MS(rom->ht40_2s_tx_pwr_diff[j], LOW_PART);
109 rt->ht20_tx_pwr_diff[0][j] =
110 RTWN_SIGN4TO8(MS(rom->ht20_tx_pwr_diff[j],
112 rt->ofdm_tx_pwr_diff[0][j] =
113 MS(rom->ofdm_tx_pwr_diff[j], LOW_PART);
114 rt->ht40_max_pwr[0][j] =
115 MS(rom->ht40_max_pwr[j], LOW_PART);
116 rt->ht20_max_pwr[0][j] =
117 MS(rom->ht20_max_pwr[j], LOW_PART);
119 if (sc->ntxchains > 1) {
120 rt->ht40_2s_tx_pwr_diff[1][j] =
121 MS(rom->ht40_2s_tx_pwr_diff[j], HIGH_PART);
122 rt->ht20_tx_pwr_diff[1][j] =
123 RTWN_SIGN4TO8(MS(rom->ht20_tx_pwr_diff[j],
125 rt->ofdm_tx_pwr_diff[1][j] =
126 MS(rom->ofdm_tx_pwr_diff[j], HIGH_PART);
127 rt->ht40_max_pwr[1][j] =
128 MS(rom->ht40_max_pwr[j], HIGH_PART);
129 rt->ht20_max_pwr[1][j] =
130 MS(rom->ht20_max_pwr[j], HIGH_PART);
134 sc->thermal_meter = MS(rom->thermal_meter, R92C_ROM_THERMAL_METER);
135 if (sc->thermal_meter == R92C_ROM_THERMAL_METER_M)
136 sc->thermal_meter = 0xff;
137 IEEE80211_ADDR_COPY(sc->sc_ic.ic_macaddr, rom->macaddr);