Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

power: supply: macsmc_power: Report available charge_behaviours #277

Open
wants to merge 906 commits into
base: asahi
Choose a base branch
from

Conversation

t-8ch
Copy link

@t-8ch t-8ch commented Mar 6, 2024

The generic handling if charge_behaviours in the power_supply core requires power_supply_desc.charge_behaviours to be set.

Note:

This is entirely untested, not even compiled.
This patch requires changes to upstream linux that should land in mainline 6.9-rc1.

See commit "power: supply: core: fix charge_behaviour formatting"

marcan and others added 30 commits November 20, 2023 11:25
This is the counterpart to b50255c. In MSI mode we can still get MSIs
even with IRQs disabled, so add an explicit gate for it.

Signed-off-by: Hector Martin <marcan@marcan.st>
SYSMEM corerev 12+ uses different coreinfo masks for the ROM/RAM sizes.
The masks for cores <12 also look like they were wrong all along, since
the register layout is not the same as for SOCRAM (even though it was
sharing the defines). Plus we need to skip the ROM banks, which we
weren't doing.

So it looks like this was always wrong for SYSMEM chips. Fix it and add
support for the new revisions.

Signed-off-by: Hector Martin <marcan@marcan.st>
Beginning with BCM4388, Apple machines are using firmware signing. This
requires a new firmware blob (as the signature is provided out-of-band)
as well as an extension of the existing random seed upload mechanism to
populate the data structures required for signature verification by the
bootloader.

To implement this, refactor the existing random seed code to be more
generic, and use it to implement the signature upload.

Drive-by changes: Remove two unused members of brcmf_pciedev_info (which
are confusing as they are never initialized), and also zero out the
unused portion of TCM to make TCM dumps less noisy. With this, the TCM
contents are 1:1 identical to what the macOS driver ends up doing,
except for the NVRAM which has the injected macaddr property at the end
instead of at the start.

Signed-off-by: Hector Martin <marcan@marcan.st>
New chips, bigger rings again. BCM4388 Apple firmware posts more than
1024 RX buffers, so we need to bump this up again.

This also requires increasing the number of RX PKTIDs.

Signed-off-by: Hector Martin <marcan@marcan.st>
BCM4388 supports more bands, so make space for them.

Signed-off-by: Hector Martin <marcan@marcan.st>
…y number

This is the ca7 version of 3c7c07c ("wifi: brcmfmac: chip: Only disable
D11 cores; handle an arbitrary number"). Instead of the hack in
resetcore to handle multiple 80211 cores, let's just iterate in
set_passive.

Signed-off-by: Hector Martin <marcan@marcan.st>
On newer cores, we need to explicitly set the subsystems to reset via
the watchdog. Logic adapted from bcmdhd.

Signed-off-by: Hector Martin <marcan@marcan.st>
Currently the pcie code multiplexes all register accesses through a
single window. This isn't very efficient, and it creates race conditions
when we access registers from multiple paths (e.g. in the interrupt
handler). Since the chip has a dedicated window for the PCIe core
registers, we can use that instead, avoid all the gratuitous window
switching, and fix the IRQ race issues.

Signed-off-by: Hector Martin <marcan@marcan.st>
Newer firmwares notify the host of boot completion via an MSI, so let's
make sure that is initialized before booting the firmware.

Signed-off-by: Hector Martin <marcan@marcan.st>
With secure boot, the vector is not accessible and trying to write it
triggers PCIe errors. Skip it in that case.

Signed-off-by: Hector Martin <marcan@marcan.st>
Make sure the firmware can't get any early notifications by masking all
IRQs explicitly before loading the firmware.

Signed-off-by: Hector Martin <marcan@marcan.st>
This is essentially identical to SCAN_V2 with an extra field where we
had a padding byte, so don't bother duplicating the entire structure.
Just add the field and the logic to set the version properly.

Signed-off-by: Hector Martin <marcan@marcan.st>
This extended command supports bit set/clear operations, but we just use
it like the old full mask set command.

Signed-off-by: Hector Martin <marcan@marcan.st>
The structures are compatible and just add fields, so we can just treat
it as always v112. If we start using new fields, that will have to be
gated on the version.

Signed-off-by: Hector Martin <marcan@marcan.st>
New firmware wants extra fields, hopefully old firmware ignores them.

Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
Fix access point mode by bringing firmware into appropriate state before setting up the device.

Signed-off-by: Patrick Blass <patrickblass.dev@gmail.com>
This patch fixes the firmware memory map structure to be complete.
Along the way, we fix a failure to align the heap memory start address,
which causes failures with the newest apple wifi firmware.

With this patch, we can load the latest (sonoma 14.0 as of right now) apple wifi firmware.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
This patch adds support for 6G chanspecs, as part of adding 6G and
802.11ax support.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
1. Correct VHT MCS settings to support as many tx/rx streams as chip
   does.

2. Correct VHT capabilities to support what all chips do.

3. Correct max AMPDU capabilities for VHT.

4. Support LDPC and STBC in VHT where available.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
…tructure.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
This patch adds support for using GCMP/etc during offload
where supported by the firmware.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
We may just have had to clone a packet, and not actually
have run out of headroom.  Only issue warning about headroom
when we actually ran out of headroom.
This removes useless spam about needing 0 more bytes of headroom.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
This patch adds support for handling the scan flags that come from the
802.11 stack.  This enables the stack to control whether we are doing
high/low power scans, as well as other options.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
This patch adds support for 6G bands, along with HE capabilities,
as they are required to register 6G bands with wiphy.
This in turn, enables 802.11ax support for the other bands.

Scanning is not updated in this patch, so the bands are unused
except to be able to process what the firmware tells us.

Existing code is updated to handle all the bands rather than just 2g and
5g channels.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
Currently, we ignore the default country in the reg notifier.
We also register a custom regulatory domain, which is set
as the default.
As a result, the chip is likely to be set to the correct country,
but the regulatory domain will not match it.

When the regulatory notifier is then called, we see the countries
are the same and do not change anything, even though the domain
is wrong.

This patch forces us to reset the bands on the first country change
even if the chip is already set to that country.

We also restore the original band info before reconstructing channel
info, as the new regdom power limits may be higher than what is
currently set.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
This patch structurizes PNF scan handling, adding support for
netinfo v3 and PNO v3 structures.

This in turn, enables the chip to tell us about 6G scan results,
as the results contain chanspecs and not just channels.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
marcan and others added 21 commits December 19, 2023 18:22
The generic handling if charge_behaviours in the power_supply core
requires power_supply_desc.charge_behaviours to be set.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
@mzyngier
Copy link

This fixes an issue I'm currently seeing on my M2 Air that screams:

[  234.839586] power_supply macsmc-battery: driver reporting unsupported charge behaviour
[  234.847377] power_supply macsmc-battery: driver reporting unsupported charge behaviour
[  234.855430] power_supply macsmc-battery: driver reporting unsupported charge behaviour
[  234.863108] power_supply macsmc-battery: driver reporting unsupported charge behaviour
[  234.871860] power_supply macsmc-battery: driver reporting unsupported charge behaviour
[  234.879245] power_supply macsmc-battery: driver reporting unsupported charge behaviour
[  234.887118] power_supply macsmc-battery: driver reporting unsupported charge behaviour
[  234.895056] power_supply macsmc-battery: driver reporting unsupported charge behaviour

FWIW:

Tested-by: Marc Zyngier <maz@kernel.org>

@t-8ch
Copy link
Author

t-8ch commented May 14, 2024

...that screams:

In hindsight that warning should have been ratelimited.
But well, only (this) out-of-tree code is affected.

@jannau
Copy link
Member

jannau commented May 14, 2024

thanks, merged into my rebase onto v6.9 (https://github.com/jannau/linux/tree/asahi-wip-6.9). I'll keep this open until the change is in this repository

@t-8ch
Copy link
Author

t-8ch commented May 15, 2024

@mzyngier Why is that file read 100 times per second?

@mzyngier
Copy link

@mzyngier Why is that file read 100 times per second?

systemd-journald is the one. for some reason, it thinks it needs that.

openat(AT_FDCWD, "/sys/devices/platform/soc/23e400000.smc/macsmc-power/power_supply/macsmc-battery/uevent", O_RDONLY|O_NOCTTY|O_CLOEXEC) = 18
newfstatat(18, "", {st_mode=S_IFREG|0644, st_size=16384, ...}, AT_EMPTY_PATH) = 0
read(18, "", 16392)                     = 0
close(18)                               = 0
readlinkat(AT_FDCWD, "/sys/devices/platform/soc/23e400000.smc/macsmc-power/power_supply/macsmc-battery/subsystem", "../../../../../../../class/power"..., 4096) = 39
openat(AT_FDCWD, "/run/udev/data/+power_supply:macsmc-battery", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
faccessat(AT_FDCWD, "/run/systemd/journal/flushed", F_OK) = 0
read(9, "4,62318,574228820,-;power_supply"..., 8192) = 156
faccessat(AT_FDCWD, "/sys/bus/power_supply/devices/macsmc-battery", F_OK) = -1 ENOENT (No such file or directory)
faccessat(AT_FDCWD, "/sys/class/power_supply/macsmc-battery", F_OK) = 0
openat(AT_FDCWD, "/", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY) = 18
openat(18, "sys", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 19
newfstatat(19, "", {st_mode=S_IFDIR|0555, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(18)                               = 0
openat(19, "class", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 18
newfstatat(18, "", {st_mode=S_IFDIR|0755, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(19)                               = 0
openat(18, "power_supply", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 19
newfstatat(19, "", {st_mode=S_IFDIR|0755, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(18)                               = 0
openat(19, "macsmc-battery", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 18
newfstatat(18, "", {st_mode=S_IFLNK|0777, st_size=0, ...}, AT_EMPTY_PATH) = 0
readlinkat(19, "macsmc-battery", "../../devices/platform/soc/23e40"..., 4096) = 81
close(18)                               = 0
openat(19, "..", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 18
close(19)                               = 0
openat(18, "..", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 19
close(18)                               = 0
openat(19, "devices", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 18
newfstatat(18, "", {st_mode=S_IFDIR|0755, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(19)                               = 0
openat(18, "platform", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 19
newfstatat(19, "", {st_mode=S_IFDIR|0755, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(18)                               = 0
openat(19, "soc", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 18
newfstatat(18, "", {st_mode=S_IFDIR|0755, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(19)                               = 0
openat(18, "23e400000.smc", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 19
newfstatat(19, "", {st_mode=S_IFDIR|0755, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(18)                               = 0
openat(19, "macsmc-power", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 18
newfstatat(18, "", {st_mode=S_IFDIR|0755, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(19)                               = 0
openat(18, "power_supply", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 19
newfstatat(19, "", {st_mode=S_IFDIR|0755, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(18)                               = 0
openat(19, "macsmc-battery", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 18
newfstatat(18, "", {st_mode=S_IFDIR|0755, st_size=0, ...}, AT_EMPTY_PATH) = 0
close(19)                               = 0
faccessat2(18, "uevent", F_OK, 0)       = 0
fstatfs(18, {f_type=SYSFS_MAGIC, f_bsize=16384, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={val=[0xf7892793, 0x326e46c9]}, f_namelen=255, f_frsize=16384, f_flags=ST_VALID|ST_NOSUID|ST_NODEV|ST_NOEXEC|ST_RELATIME}) = 0
close(18)                               = 0
openat(AT_FDCWD, "/sys/devices/platform/soc/23e400000.smc/macsmc-power/power_supply/macsmc-battery/uevent", O_RDONLY|O_NOCTTY|O_CLOEXEC) = 18

Ad nauseam.

@t-8ch
Copy link
Author

t-8ch commented May 15, 2024

systemd-journald is the one. for some reason, it thinks it needs that.

It doesn't do that for me. Seems like something worth investigating.

@mzyngier
Copy link

Investigating systemd? I have better ways to waste my time! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants