Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Documentation/PCI/controller/apple-t8140.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ The J700 path trains port 0, validates a bounded PIODMA bootstrap request,
and enables native ECAM for the MediaTek Wi-Fi and Bluetooth functions.
The root bridge forwards their BARs and DART translates endpoint DMA.

This is an opt-in bring-up implementation, not general T8140 PCIe support.
Build ``CONFIG_PCIE_APPLE_PIODMA_DIAG=y`` and pass
``pcie_apple_piodma_diag.enumerate=1`` to the kernel. Without the opt-in, the
root-only diagnostic path continues to reject downstream configuration access.
This is a bring-up implementation, not general T8140 PCIe support.
Build ``CONFIG_PCIE_APPLE_PIODMA_DIAG=y``. The board device tree selects the
bootstrap by pointing the host's ``apple,piodma`` property at the engine, and
the kernel then runs it during the host probe. Passing
``pcie_apple_piodma_diag.enumerate=0`` keeps the root-only diagnostic path,
which rejects downstream configuration access. A kernel built without the
option always uses that root-only path.
Build the host and its DART in as well: the supplier retains published DMA
and has no removal contract. Keeping the supplier and host built in avoids
a module dependency on a provider whose lifetime cannot end at unload.
Expand Down
51 changes: 37 additions & 14 deletions Documentation/networking/device_drivers/wifi/mt7932-neo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ MT7932 radio bring-up on the MacBook Neo
======================================

J700 MT7932 Wi-Fi uses cfg80211 and NetworkManager with firmware-managed
WPA2-CCMP authentication. Bluetooth uses an opt-in PCIe transport.
WPA2-CCMP authentication. Bluetooth uses a transport on the radio's second
PCIe function.

The Wi-Fi import is pinned to
``aurora-silicon/linux-neo-cleanroom-eryk-with-wifi``, commit
Expand All @@ -16,28 +17,50 @@ Platform and configuration
--------------------------

Use the separately reviewed T8140 PCIe bootstrap described in
``Documentation/PCI/controller/apple-t8140.rst``. Its explicit kernel opt-in is
``pcie_apple_piodma_diag.enumerate=1``. Public m1n1 must populate the J700
``Documentation/PCI/controller/apple-t8140.rst``. It runs during boot when
``CONFIG_PCIE_APPLE_PIODMA_DIAG=y``. Public m1n1 must populate the J700
``wifi0`` endpoint's own ``local-mac-address``; a zero placeholder is rejected.

The tested configuration includes ``CONFIG_MT7932_FULLMAC=m``,
``CONFIG_CFG80211=y``, ``CONFIG_BT_MTK7932_PCIE=m``, ``CONFIG_BT_BREDR=y``,
``CONFIG_CFG80211=m``, ``CONFIG_BT_MTK7932_PCIE=m``, ``CONFIG_BT_BREDR=y``,
``CONFIG_BT_LE=y``, ``CONFIG_CRYPTO_AES=y`` and ``CONFIG_CRYPTO_CMAC=y``.
The Bluetooth transport can be built with modular Bluetooth and system
sleep. The separately selected bootstrap provider has its own lifecycle
restrictions. Kexec is excluded while either retained experiment is enabled.
The station uses 2.4 GHz channels 1-13 and the 5 GHz channels 36-64,
100-144 and 149-165 that the cfg80211 regulatory domain permits. Radar (DFS)
channels stay passive: the firmware listens on them while the station is not
associated, but never probes or joins an access point there, and scans made
while associated skip them. A channel whose restrictions the driver cannot
apply (reduced power, no OFDM, PSD limits) is disabled rather than used, and
so is a channel the country package does not permit: every power limit of
that channel in ``policy/<CC>.bin`` is left undefined.

Use the ordinary cfg80211 regulatory database and applicable country policy.
The validated first-admission fallback is kernel country 00 with firmware XZ.

After the root filesystem and the local firmware packages are available,
select PCIe ASPM performance policy before loading ``mt7932-fullmac``. This
matches the tested admission sequence. Bluetooth's gate defaults closed;
validate the cold, unbound ``14c3:793b`` function, then load
``mt7932_bt_pcie`` with ``enable=1`` after its local inputs are installed.
A built-in transport can instead open its enable parameter before requesting
the PCI probe.
Do not reprobe after a failed or uncertain Bluetooth admission. The tested
Wi-Fi driver owns function 0 and Bluetooth owns function 1.
A modular cfg80211 loads ``regulatory.db`` from the root filesystem; a
built-in one tries before the root filesystem is mounted and then needs
``iw reg reload``.

The radio functions appear while the kernel boots, before the root
filesystem is mounted, and ``mt7932-fullmac`` reads its firmware while
probing. Build it as a module so that udev loads it from the root
filesystem, or provide its firmware in the initramfs. The driver disables
ASPM and clock power management on its link before starting the device,
matching the tested admission sequence, which used the PCIe ASPM
performance policy.

``mt7932_bt_pcie`` defers its probe until ``mt7932-fullmac`` is bound to
function 0, so the Bluetooth firmware always starts after the Wi-Fi firmware,
as in the tested sequence, however the drivers are loaded. Bluetooth therefore
stays unbound while the Wi-Fi driver is missing or has failed. A device link
makes the driver core unbind Bluetooth before Wi-Fi; unloading
``mt7932_bt_pcie`` does not affect Wi-Fi. The probe rejects a function that is
not cold, which is what now prevents a reprobe after a failed or uncertain
admission; ``enable=0`` leaves the function unbound. The transport also
disables ASPM on the shared link. Like the Wi-Fi driver, it reads its firmware
while probing, so build it as a module. The tested Wi-Fi driver owns function
0 and Bluetooth owns function 1.

Use a saved NetworkManager WPA2 profile matching the current interface.
KDE audio requires BlueZ, PipeWire, its PulseAudio compatibility service,
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/configs/j700-radio.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CONFIG_PCI=y
CONFIG_PCIE_APPLE=y
CONFIG_APPLE_DART=y
CONFIG_PCIE_APPLE_PIODMA_DIAG=y
CONFIG_CFG80211=m
CONFIG_WLAN=y
CONFIG_WLAN_VENDOR_MEDIATEK=y
CONFIG_MT7932_FULLMAC=m
Expand Down
5 changes: 4 additions & 1 deletion drivers/bluetooth/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ config BT_MTK7932_PCIE
select FW_LOADER
help
Support the J700 Bluetooth PCIe function with locally installed firmware
and calibration. The late-probe enable parameter defaults off.
and calibration. The function is probed once the Wi-Fi function is
bound to the mt7932-fullmac driver; the enable=0 parameter leaves it
unbound. Both functions appear before the root filesystem is mounted
and read their firmware when probed, so say M, like the Wi-Fi driver.
System suspend uses the firmware sleep handshake and preserves DMA
storage. Hibernation and automatic firmware recovery are unsupported.
Removal drains the PCI function before releasing device-visible memory;
Expand Down
35 changes: 32 additions & 3 deletions drivers/bluetooth/mt7932_bt_pcie.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
#define BT7932_CAL "mediatek/j700-mt7932-btcal.bin"
#define BT7932_ADDR "mediatek/j700-mt7932-bdaddr.bin"

static bool enable;
static bool enable = true;
module_param(enable, bool, 0600);
MODULE_PARM_DESC(enable, "Diagnostic late-probe gate; default closed, no effect on an already bound device");
MODULE_PARM_DESC(enable, "Probe the transport (default: on); no effect on an already bound device");

struct bt7932_geometry {
u16 stride;
Expand Down Expand Up @@ -1034,20 +1034,49 @@ static void bt7932_cleanup(struct bt7932 *bt, bool release_dma)
kfree_sensitive(bt);
}

/*
* Admission was only qualified with the Wi-Fi function already running its
* firmware. Wait until mt7932-fullmac is bound to function 0, then link the
* two functions so that the driver core unbinds this one first.
*/
static int bt7932_wait_for_wifi(struct pci_dev *pdev)
{
struct pci_dev *wifi = pci_get_slot(pdev->bus, PCI_DEVFN(0, 0));
int ret = 0;

if (!wifi)
return -ENODEV;
if (!device_is_bound(&wifi->dev) ||
strcmp(dev_driver_string(&wifi->dev), "mt7932-fullmac"))
ret = dev_err_probe(&pdev->dev, -EPROBE_DEFER,
"waiting for the Wi-Fi function\n");
else if (!device_link_add(&pdev->dev, &wifi->dev, DL_FLAG_AUTOREMOVE_CONSUMER))
ret = -EINVAL;
pci_dev_put(wifi);
return ret;
}

static int bt7932_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
struct bt7932 *bt;
u32 chip, boot = U32_MAX, selector;
u16 command;
int ret;

/* The coordinator opens this only after the real root has its inputs. */
/* enable=0 leaves the function unbound for diagnosis. */
if (!READ_ONCE(enable))
return -ENODEV;
if (!of_machine_is_compatible("apple,j700") ||
!of_machine_is_compatible("apple,t8140") ||
pci_domain_nr(pdev->bus) || pdev->bus->number != 1 || pdev->devfn != PCI_DEVFN(0, 1))
return -ENODEV;
ret = bt7932_wait_for_wifi(pdev);
if (ret)
return ret;
/* Admission was qualified with ASPM and clock PM off on this link. */
ret = pci_disable_link_state(pdev, PCIE_LINK_STATE_ALL);
if (ret)
dev_warn(&pdev->dev, "link power management left as found: %d\n", ret);
bt = kzalloc_obj(*bt);
if (!bt)
return -ENOMEM;
Expand Down
8 changes: 6 additions & 2 deletions drivers/net/wireless/mediatek/mt7932/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
config MT7932_FULLMAC
tristate "Experimental J700 MT7932 fullmac wireless support"
depends on PCI && OF && ARM64 && IOMMU_DMA
depends on CFG80211
select FW_LOADER
select CFG80211
help
Native support for the built-in J700 Wi-Fi endpoint: managed
WPA2-CCMP station operation on 2.4 GHz and channels 36..48 at 20 MHz.
WPA2-CCMP station operation on 2.4 GHz and on the 5 GHz UNII-1, -2,
-2e and -3 channels that the regulatory domain permits. Radar (DFS)
channels are scanned passively but not joined.
Requires original firmware, own calibration and original-derived
country policy packages in addition to the cfg80211 regulatory database.
The device is probed before the root filesystem is mounted, so say M
unless those files are in the initramfs.
Requires a trained retained PCI link and a translated SID1 DMA domain.
Firmware, runtime DMA and calibration negotiation start automatically;
cfg80211 and userspace select the country and network. No test boot
Expand Down
9 changes: 5 additions & 4 deletions drivers/net/wireless/mediatek/mt7932/bandwidth.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ static inline u8 mt7932_domain_5g_bw(void)
}

/* EE4d width 0 combines 20/40; primary and extension select the center.
* Keep all operational primaries inside 36..48, and 2 GHz at 20 MHz.
* Extension 1 places the secondary above the primary, 3 below it. Keep 2 GHz
* at 20 MHz, and 165, which has no 40 MHz pair, at 20 MHz too.
*/
static inline bool mt7932_channel_layout(u8 primary, u8 width, u8 extension,
u8 maximum, u8 *center, u8 *bw)
{
u8 band = mt7932_channel_band(primary);
u8 expected = primary == 36 || primary == 44 ? 1 : 3;
u8 pair = mt7932_channel_ht40_centre(primary);

if (!band || maximum > 2 || width > 1)
return false;
Expand All @@ -28,12 +29,12 @@ static inline bool mt7932_channel_layout(u8 primary, u8 width, u8 extension,
*bw = 0;
return true;
}
if (band != 2 || extension != expected)
if (band != 2 || !pair || extension != (pair > primary ? 1 : 3))
return false;
*bw = width ? 2 : 1;
if (*bw > maximum)
return false;
*center = width ? 42 : extension == 1 ? primary + 2 : primary - 2;
*center = width ? mt7932_channel_vht80_centre(primary) : pair;
return true;
}

Expand Down
7 changes: 4 additions & 3 deletions drivers/net/wireless/mediatek/mt7932/calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef MT7932_CALIBRATION_H
#define MT7932_CALIBRATION_H

#include "channels.h"
#include "protocol.h"

/* Protected by the RX/procedure lock. One active logical procedure only;
Expand Down Expand Up @@ -146,7 +147,7 @@ static inline int mt7932_cal_association(const u8 *data, size_t size, u8 channel

if (channel >= 1 && channel <= 13)
group = 0;
else if (channel >= 36 && channel <= 48 && !(channel % 2))
else if (mt7932_channel_5g_cal(channel))
group = 1;
else
return -EOPNOTSUPP;
Expand Down Expand Up @@ -228,7 +229,7 @@ static inline int mt7932_cal_requested_5g(const u8 *data, size_t size,
int ret;

if (upper != 0x1000 || version != 12 || module != 0x89 ||
channel < 36 || channel > 48 || channel % 2)
!mt7932_channel_5g_cal(channel))
return -EOPNOTSUPP;
ret = mt7932_cal_validate(data, size);
if (ret)
Expand All @@ -243,7 +244,7 @@ static inline int mt7932_cal_requested_5g(const u8 *data, size_t size,
if (segment.data[i])
return -EOPNOTSUPP;
/* Own row610f07 does not remap center selectors1/2; only primaries. */
selected = channel % 4 ? channel : channel <= 40 ? 38 : 46;
selected = mt7932_channel_band(channel) ? mt7932_channel_cal_centre(channel) : channel;
params[0] = 0x10000001;
params[1] = 0x10001000 | channel;
params[2] = 0x10001000 | (channel << 17) | selected;
Expand Down
66 changes: 65 additions & 1 deletion drivers/net/wireless/mediatek/mt7932/channels.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,78 @@

/* Bounded operational whitelist, not the full calibration channel namespace.
* Firmware RF bands1/2 are distinct from single-interface MAC index0.
* 5 GHz covers the 20 MHz primaries of UNII-1/2 (36..64), UNII-2e (100..144)
* and UNII-3 (149..165); regulatory flags decide which of them are usable.
*/
#define MT7932_CHANNELS_2G 13
#define MT7932_CHANNELS_5G 25
#define MT7932_CHANNELS (MT7932_CHANNELS_2G + MT7932_CHANNELS_5G)

static inline unsigned int mt7932_channel_band(unsigned int channel)
{
if (channel >= 1 && channel <= 13)
return 1;
if (channel >= 36 && channel <= 48 && !(channel % 4))
if (((channel >= 36 && channel <= 64) || (channel >= 100 && channel <= 144)) &&
!(channel % 4))
return 2;
if (channel >= 149 && channel <= 165 && !((channel - 149) % 4))
return 2;
return 0;
}

/* The nth 5 GHz primary, in the order the wiphy advertises them. */
static inline unsigned int mt7932_channel_5g(unsigned int index)
{
if (index < 8)
return 36 + 4 * index;
if (index < 20)
return 100 + 4 * (index - 8);
return 149 + 4 * (index - 20);
}

/* Offset of a 5 GHz primary within its 80 MHz block numbering. */
static inline unsigned int mt7932_channel_slot(unsigned int primary, unsigned int *base)
{
*base = primary >= 149 ? 149 : primary >= 100 ? 100 : 36;
return (primary - *base) / 4;
}

/* 40 MHz pair centre of a 5 GHz primary; 0 where no pair exists (165). */
static inline unsigned int mt7932_channel_ht40_centre(unsigned int primary)
{
unsigned int base, slot;

if (mt7932_channel_band(primary) != 2 || primary == 165)
return 0;
slot = mt7932_channel_slot(primary, &base);
return base + 4 * (slot & ~1U) + 2;
}

/* 80 MHz block centre of a 5 GHz primary; 0 where no block exists (165). */
static inline unsigned int mt7932_channel_vht80_centre(unsigned int primary)
{
unsigned int base, slot;

if (mt7932_channel_band(primary) != 2 || primary == 165)
return 0;
slot = mt7932_channel_slot(primary, &base);
return base + 4 * (slot & ~3U) + 6;
}

/* A 5 GHz primary or a 40/80 MHz centre that calibration can be asked for. */
static inline bool mt7932_channel_5g_cal(unsigned int channel)
{
if ((channel >= 36 && channel <= 64) || (channel >= 100 && channel <= 144))
return !(channel % 2);
return channel >= 149 && channel <= 167 && (channel % 2);
}

/* Calibration centre for a 5 GHz primary. 165 has no 40 MHz pair; its own
* calibration package carries the record for the 165/169 centre, 167.
*/
static inline unsigned int mt7932_channel_cal_centre(unsigned int primary)
{
return primary == 165 ? 167 : mt7932_channel_ht40_centre(primary);
}

#endif
Loading