2016-05-14 20:11:48 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2009-2010 Weongyo Jeong <weongyo@freebsd.org>
|
|
|
|
* Copyright (c) 2016 Adrian Chadd <adrian@freebsd.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* without modification.
|
|
|
|
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
|
|
|
|
* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
|
|
|
|
* redistribution must be conditioned upon including a substantially
|
|
|
|
* similar Disclaimer requirement for further binary redistribution.
|
|
|
|
*
|
|
|
|
* NO WARRANTY
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
|
|
|
|
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
|
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGES.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2016-05-16 22:56:45 +00:00
|
|
|
#include "opt_bwn.h"
|
|
|
|
#include "opt_wlan.h"
|
|
|
|
|
2016-05-14 20:11:48 +00:00
|
|
|
/*
|
|
|
|
* The Broadcom Wireless LAN controller driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/firmware.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_var.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_llc.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
|
|
|
|
#include <net80211/ieee80211_var.h>
|
|
|
|
#include <net80211/ieee80211_radiotap.h>
|
|
|
|
#include <net80211/ieee80211_regdomain.h>
|
|
|
|
#include <net80211/ieee80211_phy.h>
|
|
|
|
#include <net80211/ieee80211_ratectl.h>
|
|
|
|
|
2018-02-05 23:38:15 +00:00
|
|
|
#include <dev/bhnd/bhnd.h>
|
|
|
|
#include <dev/bhnd/bhnd_ids.h>
|
|
|
|
|
|
|
|
#include <dev/bhnd/cores/chipc/chipc.h>
|
|
|
|
#include <dev/bhnd/cores/pmu/bhnd_pmu.h>
|
Introduce bwn(4) support for the bhnd(4) bus.
Currently, bwn(4) relies on the siba_bwn(4) bus driver to provide support
for the on-chip SSB interconnect found in Broadcom's older PCI(e) Wi-Fi
adapters. Non-PCI Wi-Fi adapters, as well as the newer BCMA interconnect
found in post-2009 Broadcom Wi-Fi hardware, are not supported by
siba_bwn(4).
The bhnd(4) bus driver (also used by the FreeBSD/MIPS Broadcom port)
provides a unified kernel interface to a superset of the hardware supported
by siba_bwn; by attaching bwn(4) via bhnd(4), we can support both modern
PCI(e) Wi-Fi devices based on the BCMA backplane interconnect, as well as
Broadcom MIPS WiSoCs that include a D11 MAC core directly attached to their
SSB or BCMA backplane.
This diff introduces opt-in bwn(4) support for bhnd(4) by providing:
- A small bwn(4) driver subclass, if_bwn_bhnd, that attaches via
bhnd(4) instead of siba_bwn(4).
- A bhndb(4)-based PCI host bridge driver, if_bwn_pci, that optionally
probes at a higher priority than the siba_bwn(4) PCI driver.
- A set of compatibility shims that perform translation of bwn(4)'s
siba_bwn function calls into their bhnd(9) API equivalents when bwn(4)
is attached via a bhnd(4) bus parent. When bwn(4) is attached via
siba_bwn(4), all siba_bwn function calls are simply passed through to
their original implementations.
To test bwn(4) with bhnd(4), place the following lines in loader.conf(5):
hw.bwn_pci.preferred="1"
if_bwn_pci_load="YES
bwn_v4_ucode_load="YES"
bwn_v4_lp_ucode_load="YES"
To verify that bwn(4) is using bhnd(4), you can check dmesg:
bwn0: <Broadcom 802.11 MAC/PHY/Radio, rev 15> ... on bhnd0
... or devinfo(8):
pcib2
pci2
bwn_pci0
bhndb0
bhnd0
bwn0
...
bwn(4)/bhnd(4) has been tested for regressions with most chipsets currently
supported by bwn(4), including:
- BCM4312
- BCM4318
- BCM4321
With minimal changes to the DMA code (not included in this commit), I was
also able to test support for newer BCMA devices by bringing up basic
working Wi-Fi on two previously unsupported, BCMA-based N-PHY chipsets:
- BCM43224
- BCM43225
Approved by: adrian (mentor, implicit)
Sponsored by: The FreeBSD Foundation & Plausible Labs
Differential Revision: https://reviews.freebsd.org/D13041
2017-12-02 02:21:27 +00:00
|
|
|
|
2016-05-14 20:11:48 +00:00
|
|
|
#include <dev/bwn/if_bwnreg.h>
|
|
|
|
#include <dev/bwn/if_bwnvar.h>
|
|
|
|
|
|
|
|
#include <dev/bwn/if_bwn_debug.h>
|
|
|
|
#include <dev/bwn/if_bwn_misc.h>
|
|
|
|
#include <dev/bwn/if_bwn_phy_common.h>
|
|
|
|
|
|
|
|
void
|
2018-02-05 23:38:15 +00:00
|
|
|
bwn_mac_switch_freq(struct bwn_mac *mac, bhnd_pmu_spuravoid spurmode)
|
2016-05-14 20:11:48 +00:00
|
|
|
{
|
|
|
|
struct bwn_softc *sc = mac->mac_sc;
|
2018-02-05 23:38:15 +00:00
|
|
|
uint16_t chip_id = sc->sc_cid.chip_id;
|
2016-05-14 20:11:48 +00:00
|
|
|
|
2018-02-05 23:38:15 +00:00
|
|
|
if (chip_id == BHND_CHIPID_BCM4331) {
|
2016-05-14 20:11:48 +00:00
|
|
|
switch (spurmode) {
|
2018-02-05 23:38:15 +00:00
|
|
|
case BHND_PMU_SPURAVOID_M2: /* 168 Mhz: 2^26/168 = 0x61862 */
|
2016-05-14 20:11:48 +00:00
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x1862);
|
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x6);
|
|
|
|
break;
|
2018-02-05 23:38:15 +00:00
|
|
|
case BHND_PMU_SPURAVOID_M1: /* 164 Mhz: 2^26/164 = 0x63e70 */
|
2016-05-14 20:11:48 +00:00
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x3e70);
|
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x6);
|
|
|
|
break;
|
2018-02-05 23:38:15 +00:00
|
|
|
case BHND_PMU_SPURAVOID_NONE: /* 160 Mhz: 2^26/160 = 0x66666 */
|
2016-05-14 20:11:48 +00:00
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x6666);
|
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x6);
|
|
|
|
break;
|
|
|
|
}
|
2018-02-05 23:38:15 +00:00
|
|
|
} else if (chip_id == BHND_CHIPID_BCM43131 ||
|
|
|
|
chip_id == BHND_CHIPID_BCM43217 ||
|
|
|
|
chip_id == BHND_CHIPID_BCM43222 ||
|
|
|
|
chip_id == BHND_CHIPID_BCM43224 ||
|
|
|
|
chip_id == BHND_CHIPID_BCM43225 ||
|
|
|
|
chip_id == BHND_CHIPID_BCM43227 ||
|
|
|
|
chip_id == BHND_CHIPID_BCM43228) {
|
2016-05-14 20:11:48 +00:00
|
|
|
switch (spurmode) {
|
2018-02-05 23:38:15 +00:00
|
|
|
case BHND_PMU_SPURAVOID_M2: /* 126 Mhz */
|
2016-05-14 20:11:48 +00:00
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x2082);
|
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x8);
|
|
|
|
break;
|
2018-02-05 23:38:15 +00:00
|
|
|
case BHND_PMU_SPURAVOID_M1: /* 123 Mhz */
|
2016-05-14 20:11:48 +00:00
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x5341);
|
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x8);
|
|
|
|
break;
|
2018-02-05 23:38:15 +00:00
|
|
|
case BHND_PMU_SPURAVOID_NONE: /* 120 Mhz */
|
2016-05-14 20:11:48 +00:00
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x8889);
|
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0x8);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (mac->mac_phy.type == BWN_PHYTYPE_LCN) {
|
|
|
|
switch (spurmode) {
|
2018-02-05 23:38:15 +00:00
|
|
|
case BHND_PMU_SPURAVOID_M2:
|
|
|
|
device_printf(sc->sc_dev, "invalid spuravoid mode: "
|
|
|
|
"%d\n", spurmode);
|
|
|
|
break;
|
|
|
|
case BHND_PMU_SPURAVOID_M1: /* 82 Mhz */
|
2016-05-14 20:11:48 +00:00
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0x7CE0);
|
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0xC);
|
|
|
|
break;
|
2018-02-05 23:38:15 +00:00
|
|
|
case BHND_PMU_SPURAVOID_NONE: /* 80 Mhz */
|
2016-05-14 20:11:48 +00:00
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_LOW, 0xCCCD);
|
|
|
|
BWN_WRITE_2(mac, BWN_TSF_CLK_FRAC_HIGH, 0xC);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* http://bcm-v4.sipsolutions.net/802.11/PHY/N/BmacPhyClkFgc */
|
2018-02-05 23:38:15 +00:00
|
|
|
int
|
2016-05-14 20:11:48 +00:00
|
|
|
bwn_phy_force_clock(struct bwn_mac *mac, int force)
|
|
|
|
{
|
2018-02-05 23:38:15 +00:00
|
|
|
struct bwn_softc *sc;
|
|
|
|
uint32_t val, mask;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sc = mac->mac_sc;
|
2016-05-14 20:11:48 +00:00
|
|
|
|
|
|
|
/* XXX Only for N, HT and AC PHYs */
|
2018-02-05 23:38:15 +00:00
|
|
|
mask = BHND_IOCTL_CLK_FORCE;
|
|
|
|
if (force) {
|
|
|
|
val = BHND_IOCTL_CLK_FORCE;
|
|
|
|
} else {
|
|
|
|
val = 0;
|
|
|
|
}
|
2016-05-14 20:11:48 +00:00
|
|
|
|
2018-02-05 23:38:15 +00:00
|
|
|
if ((error = bhnd_write_ioctl(sc->sc_dev, val, mask))) {
|
|
|
|
device_printf(sc->sc_dev, "failed to set CLK_FORCE ioctl flag: "
|
|
|
|
"%d\n", error);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
2016-05-14 20:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bwn_radio_wait_value(struct bwn_mac *mac, uint16_t offset, uint16_t mask,
|
|
|
|
uint16_t value, int delay, int timeout)
|
|
|
|
{
|
|
|
|
uint16_t val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < timeout; i += delay) {
|
|
|
|
val = BWN_RF_READ(mac, offset);
|
|
|
|
if ((val & mask) == value)
|
|
|
|
return (1);
|
|
|
|
DELAY(delay);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2018-02-05 23:38:15 +00:00
|
|
|
int
|
2016-05-14 20:11:48 +00:00
|
|
|
bwn_mac_phy_clock_set(struct bwn_mac *mac, int enabled)
|
|
|
|
{
|
2018-02-05 23:38:15 +00:00
|
|
|
struct bwn_softc *sc;
|
|
|
|
uint32_t val, mask;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sc = mac->mac_sc;
|
|
|
|
|
|
|
|
mask = BWN_IOCTL_MACPHYCLKEN;
|
|
|
|
if (enabled) {
|
|
|
|
val = BWN_IOCTL_MACPHYCLKEN;
|
|
|
|
} else {
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bhnd_write_ioctl(sc->sc_dev, val, mask))) {
|
|
|
|
device_printf(sc->sc_dev, "failed to set MACPHYCLKEN ioctl "
|
|
|
|
"flag: %d\n", error);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
2016-05-14 20:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* http://bcm-v4.sipsolutions.net/802.11/PHY/BmacCorePllReset */
|
2018-02-05 23:38:15 +00:00
|
|
|
int
|
2016-05-14 20:11:48 +00:00
|
|
|
bwn_wireless_core_phy_pll_reset(struct bwn_mac *mac)
|
|
|
|
{
|
2018-02-05 23:38:15 +00:00
|
|
|
struct bwn_softc *sc;
|
|
|
|
uint32_t pll_flag;
|
2016-05-14 20:11:48 +00:00
|
|
|
|
2018-02-05 23:38:15 +00:00
|
|
|
sc = mac->mac_sc;
|
|
|
|
|
|
|
|
if (sc->sc_pmu == NULL) {
|
|
|
|
device_printf(sc->sc_dev, "PMU device not found\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
pll_flag = 0x4;
|
|
|
|
bhnd_pmu_write_chipctrl(sc->sc_pmu, 0x0, 0x0, pll_flag);
|
|
|
|
bhnd_pmu_write_chipctrl(sc->sc_pmu, 0x0, pll_flag, pll_flag);
|
|
|
|
bhnd_pmu_write_chipctrl(sc->sc_pmu, 0x0, 0x0, pll_flag);
|
|
|
|
|
|
|
|
return (0);
|
2016-05-14 20:11:48 +00:00
|
|
|
}
|