2 * Copyright (c) 2016 Adrian Chadd <adrian@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
34 * This is the top-level N-PHY support for the Broadcom softmac driver.
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/malloc.h>
44 #include <sys/module.h>
45 #include <sys/endian.h>
46 #include <sys/errno.h>
47 #include <sys/firmware.h>
49 #include <sys/mutex.h>
50 #include <machine/bus.h>
51 #include <machine/resource.h>
54 #include <sys/socket.h>
55 #include <sys/sockio.h>
57 #include <net/ethernet.h>
59 #include <net/if_var.h>
60 #include <net/if_arp.h>
61 #include <net/if_dl.h>
62 #include <net/if_llc.h>
63 #include <net/if_media.h>
64 #include <net/if_types.h>
66 #include <dev/pci/pcivar.h>
67 #include <dev/pci/pcireg.h>
68 #include <dev/siba/siba_ids.h>
69 #include <dev/siba/sibareg.h>
70 #include <dev/siba/sibavar.h>
72 #include <net80211/ieee80211_var.h>
73 #include <net80211/ieee80211_radiotap.h>
74 #include <net80211/ieee80211_regdomain.h>
75 #include <net80211/ieee80211_phy.h>
76 #include <net80211/ieee80211_ratectl.h>
78 #include <dev/bwn/if_bwnreg.h>
79 #include <dev/bwn/if_bwnvar.h>
81 #include <dev/bwn/if_bwn_debug.h>
82 #include <dev/bwn/if_bwn_misc.h>
83 #include <dev/bwn/if_bwn_phy_n.h>
86 #include <gnu/dev/bwn/phy_n/if_bwn_phy_n_tables.h>
87 #include <gnu/dev/bwn/phy_n/if_bwn_phy_n_ppr.h>
88 #include <gnu/dev/bwn/phy_n/if_bwn_phy_n_core.h>
92 * This module is always compiled into the kernel, regardless of
93 * whether the GPL PHY is enabled. If the GPL PHY isn't enabled
94 * then it'll just be stubs that will fail to attach.
98 bwn_phy_n_attach(struct bwn_mac *mac)
102 return bwn_nphy_op_allocate(mac);
104 device_printf(mac->mac_sc->sc_dev,
105 "%s: BWN_GPL_PHY not in kernel config; "
106 "no PHY-N support\n", __func__);
112 bwn_phy_n_detach(struct bwn_mac *mac)
116 return bwn_nphy_op_free(mac);
121 bwn_phy_n_prepare_hw(struct bwn_mac *mac)
125 bwn_nphy_op_prepare_structs(mac);
133 bwn_phy_n_init_pre(struct bwn_mac *mac)
140 bwn_phy_n_init(struct bwn_mac *mac)
143 return bwn_nphy_op_init(mac);
150 bwn_phy_n_exit(struct bwn_mac *mac)
157 bwn_phy_n_read(struct bwn_mac *mac, uint16_t reg)
160 BWN_WRITE_2(mac, BWN_PHYCTL, reg);
161 return BWN_READ_2(mac, BWN_PHYDATA);
165 bwn_phy_n_write(struct bwn_mac *mac, uint16_t reg, uint16_t value)
168 BWN_WRITE_2(mac, BWN_PHYCTL, reg);
169 BWN_WRITE_2(mac, BWN_PHYDATA, value);
173 bwn_phy_n_rf_read(struct bwn_mac *mac, uint16_t reg)
176 /* Register 1 is a 32-bit register. */
177 if (mac->mac_phy.rev < 7 && reg == 1) {
178 BWN_ERRPRINTF(mac->mac_sc, "%s: bad reg access\n", __func__);
181 if (mac->mac_phy.rev >= 7)
182 reg |= 0x200; /* radio 0x2057 */
186 BWN_WRITE_2(mac, BWN_RFCTL, reg);
187 return BWN_READ_2(mac, BWN_RFDATALO);
191 bwn_phy_n_rf_write(struct bwn_mac *mac, uint16_t reg, uint16_t value)
194 /* Register 1 is a 32-bit register. */
195 if (mac->mac_phy.rev < 7 && reg == 1) {
196 BWN_ERRPRINTF(mac->mac_sc, "%s: bad reg access\n", __func__);
199 BWN_WRITE_2(mac, BWN_RFCTL, reg);
200 BWN_WRITE_2(mac, BWN_RFDATALO, value);
204 bwn_phy_n_hwpctl(struct bwn_mac *mac)
211 bwn_phy_n_rf_onoff(struct bwn_mac *mac, int on)
214 bwn_nphy_op_software_rfkill(mac, on);
219 bwn_phy_n_switch_analog(struct bwn_mac *mac, int on)
222 bwn_nphy_op_switch_analog(mac, on);
227 bwn_phy_n_switch_channel(struct bwn_mac *mac, uint32_t newchan)
230 return bwn_nphy_op_switch_channel(mac, newchan);
237 bwn_phy_n_get_default_chan(struct bwn_mac *mac)
240 if (bwn_current_band(mac) == BWN_BAND_2G)
246 bwn_phy_n_set_antenna(struct bwn_mac *mac, int antenna)
252 bwn_phy_n_im(struct bwn_mac *mac, int mode)
259 bwn_phy_n_recalc_txpwr(struct bwn_mac *mac, int ignore_tssi)
262 return bwn_nphy_op_recalc_txpower(mac, ignore_tssi);
264 return (BWN_TXPWR_RES_DONE);
269 bwn_phy_n_set_txpwr(struct bwn_mac *mac)
275 bwn_phy_n_task_15s(struct bwn_mac *mac)
281 bwn_phy_n_task_60s(struct bwn_mac *mac)