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

Improve detection of Flashstor (FS67xx) devices, implement force_device to override detection #27

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

DanielGibson
Copy link
Contributor

@DanielGibson DanielGibson commented Oct 19, 2024

This is done by checking if the "ASMedia Technology Inc. ASM2806 4-Port PCIe x2 Gen3 Packet Switch" PCIe device exists.
This should work with FS6712X (though my code hasn't been tested by @mgc8 or @romracer yet it has been tested); unfortunately I couldn't find anyone with an FS6706T in the issues or PRs of this project.
Testing an AS6706T would also be interesting, in case it also uses such a switch (my AS5402T which is mostly identical to the AS6702T does not have it - Update: AS6706T has a PCIe switch, but a different one, AS6704T doesn't have a PCIe switch).

I also implemented a force_device kernel module argument which lets users override the device detection.

See also the discussion in #21 (comment) (and following)

@DanielGibson
Copy link
Contributor Author

DanielGibson commented Oct 19, 2024

Turned it into a draft because it hasn't been tested yet (except with my AS5402T Nimbustor Gen2)

@DanielGibson DanielGibson force-pushed the detect-flashtor branch 2 times, most recently from a1a25be to 4b0d9a9 Compare October 19, 2024 02:56
@DanielGibson
Copy link
Contributor Author

DanielGibson commented Oct 20, 2024

I just added a commit which improves detecting ASUSTOR systems a lot (IMHO :-p), but unfortunately makes this even less ready to merge as I removed MODULE_DEVICE_TABLE(...) without realizing what it's good for.
This can still be tested, but the module probably won't load automatically on boot until I fix this.

(already fixed)

@DanielGibson
Copy link
Contributor Author

I just fixed the aforementioned issue with MODULE_DEVICE_TABLE(), was easier/quicker than I expected.

@mgc8
Copy link

mgc8 commented Oct 20, 2024

Hi, following up here on the conversation from #21 . I tested the new detect-flashtor branch (slight typo there, took me a while to get right :) ). This is posted in dmesg after loading the module (similar to my local patched version), and the detection appears to have worked as expected:

[1050680.185118] asustor_it87: Found IT8625E chip at 0xa30, revision 13
[1050680.185198] asustor_it87: Beeping is supported
[1050680.187216] asustor_gpio_it87: Found Chip IT8625 rev d. 64 GPIO lines starting at 0a00h
[1050680.189747] asustor: Found FS67xx or similar (Intel Corporation/Jasper Lake Client Platform)
[1050680.190069] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (power:lcd)
[1050680.211508] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (blue:usb)
[1050680.211514] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (green:usb)
[1050680.211742] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata1:green:disk)
[1050680.211745] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata1:red:disk)
[1050680.211746] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata2:green:disk)
[1050680.211748] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata2:red:disk)
[1050680.211749] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata3:green:disk)
[1050680.211751] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata3:red:disk)
[1050680.211752] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata4:green:disk)
[1050680.211753] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata4:red:disk)
[1050680.211755] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata5:green:disk)
[1050680.211756] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata5:red:disk)
[1050680.211757] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata6:green:disk)
[1050680.211759] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata6:red:disk)
[1050680.244488] input: asustor-keys as /devices/platform/gpio-keys-polled/input/input25

Compared to main (wrong detection):

[1049364.124796] asustor_it87: Found IT8625E chip at 0xa30, revision 13
[1049364.124876] asustor_it87: Beeping is supported
[1049364.126611] asustor_gpio_it87: Found Chip IT8625 rev d. 64 GPIO lines starting at 0a00h
[1049364.129303] asustor: Found Intel Corporation/Jasper Lake Client Platform
[1049364.143637] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (blue:usb)
[1049364.267864] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (nvme1:green:disk)
[1049364.267871] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (nvme1:red:disk)
[1049364.268060] input: asustor-keys as /devices/platform/gpio-keys-polled/input/input21

I also tried loading with the force_device parameter and it looks the same, working correctly to force even a "wrong" type if specified.

The LEDs are still a bit confused, but at least I can control most of them properly now! We can open perhaps a new issue to look into tweaking them.

In any case, at least when it comes to the FS6712X, I can confirm that the detection based on PCIe switches works fine.

@DanielGibson
Copy link
Contributor Author

Great, thanks for testing! Good to hear my detection logic works :)

detect-flashtor branch (slight typo there

oops, you're right!

We can as well try to tweak the LEDs here if they're wrong. What specifically is wrong/confused about them?
Did you try modifying the asustor_fs6700_gpio_leds_lookup table to fix them?

@DanielGibson DanielGibson changed the title Improve detection of Flashtor (FS67xx) devices, implement force_device to override detection Improve detection of Flashstor (FS67xx) devices, implement force_device to override detection Oct 20, 2024
@DanielGibson DanielGibson marked this pull request as ready for review October 21, 2024 12:24
@DanielGibson
Copy link
Contributor Author

I think this is ready for review.

I think potential tweaks for the LEDs don't impair that - they should only affect a few lines in the asustor_fs6700_gpio_leds_lookup table, which is quick to review. Depending on when @mafredri gets around to reviewing and on how long it takes to make the LEDs behave like they should, either it gets merged as part of this PR or we'll just create a new one.

@romracer
Copy link
Contributor

I'm confused why you removed NVME_ACT_LED and NVME_ERR_LED. I suppose NVME_ERR_LED is the same as DISK_ERR_LED, but NVME_ACT_LED is most definitely not the same as DISK_ACT_LED. And using NVME for one and SATA for the other is even more confusing, hence duplicating DISK_ERR_LED as NVME_ERR_LED.

See the original PR if you're confused as to why I didn't use the DISK LED structs for NVMe drives.

@DanielGibson
Copy link
Contributor Author

Damn, you're right, sorry!
I must've been tired when I did those changes..
Will undo them.

@DanielGibson
Copy link
Contributor Author

Fixed (force-pushed the commits without that change)
@romracer: Does this code, esp. the detection, work for you as well? Just to make sure the different BIOS version doesn't break it..

@mgc8 Was your issue with the LEDs with the NVME LED (and thus either due to my change, or due to Linux not being able to flash LEDs based on NVME activity), or are there other issues?

the AS67xx devices shouldn't have those packet switches

from `lspci` on a FS6712X:
02:00.0 PCI bridge: ASMedia Technology Inc. ASM2806 4-Port PCIe x2 Gen3 Packet Switch (rev 01)
03:00.0 PCI bridge: ASMedia Technology Inc. ASM2806 4-Port PCIe x2 Gen3 Packet Switch (rev 01)
(... and several more ...)

`lspci -v -nn` then revealed that their PCI vendor ID and product ID
are 1b21:2806 (vendor 0xb21 product 0x2806)
can be used like `modprobe asustor force_device=AS66xx`
or by adding /etc/modprobe.d/asustor.conf with a line like
  options asustor force_device=FS67xx

(Also ran clang-format)
Instead of using dmi_first_match(asustor_systems) to figure out what
kind of ASUSTOR system we're on, I added custom pci_matches[] to
asustor_driver_data and wrote custom logic to find the matching system
based on both DMI data *and* PCI devices.

It's a bit ugly that I had to copy the dmi_matches() code from
drivers/firmware/dmi_scan.c, but as that function (or equivalent ones)
aren't exported by dmi_scan.c (it's static), it was unavoidable.

On the upside, this helped getting rid of the special-casing of FS67xx
in asustor_init() and is potentially useful for matching other systems
in the future. It should even be a good base for implementing matching
of other kinds of devices (than PCI/PCIe), if that becomes necessary.

NOTE: While the asustor_systems array isn't fed into dmi_first_match()
anymore, it still needs to use the dmi_system_id type so it can be
used with MODULE_DEVICE_TABLE(), which creates the alias entries that
can be seen in `modinfo asustor`, like
  alias:          dmi*:svn*Insyde*:pn*AS61xx*:
and is also used to automatically load the asustor kernel module
on boot if the DMI entries in those aliases match the current system
@mgc8
Copy link

mgc8 commented Oct 21, 2024

I can confirm that the latest version with the generalised detection still works fine on my FS6712X.

@mgc8 Was your issue with the LEDs with the NVME LED (and thus either due to my change, or due to Linux not being able to flash LEDs based on NVME activity), or are there other issues?

No, in my case it's not the NVMe LED. Let me try to explain the LED status in more detail.

In /sys, with the new detection we have 8 LEDs detected and addressable (with the old version, it was full of "sataNN:green:disk"/etc. entries which did nothing):

$ ls /sys/class/leds/
blue:lan  blue:power  green:status  nvme1:green:disk  nvme1:red:disk  power:front_panel  red:power  red:status

Taking them one-by-one:

  • blue:lan - is actually purple/magenta, but otherwise works fine
  • blue/red:power - works fine, as per documentation -- it's actually one 'LED' with three different "colours" -- depending on which of the blue/red is on/off, it can either be blue, red or a combination purple
  • green/red:status - can be made to blink or not, but not turned off (brightness = 0 does nothing), likely a hardware restriction to force it always on? The red combines with green for a sort of orange, as per below
  • nvme1:green/red:status - works fine, as per documentation -- it's actually one 'LED' with three different "colours" -- depending on which of the green/red is on/off, it can either be green, red or a combination orange
  • power:front_panel - this actually controls a part of the large red side LED (the exterior part); it turns that bit on and off, but the interior/centre part remains unaffected

When the machine boots, the green status led comes on blinking, this can be turned off with the (...)hwmon/gpled1_blink_freq value as documented, or turned back on the same way. The triggers seem to only work partially -- i.e. I can get the usb-host to blink on activity on either of the LEDs, but not any other of the listed triggers such as disk-activity, disk-read, nand-disk, etc. -- this appears to be in contrast to what the documentation says about it blinking all LEDs with any disk activity, in my case it's blinking none of them. If I try those triggers, the affected LED turns off and that's it, I can then bring it back on with an echo 1 > (...)/brightness but it's never blinking.

What used to be possible but doesn't seem to be any more with the current setup was to turn off the entire large red side LED, which is quite distracting. The power:front_panel control seems to affect part of it as noted above, but I am not sure how to enable control for the rest.

If I can provide more information or videos/photos, please let me know.

@DanielGibson
Copy link
Contributor Author

The disk triggers won't work with the FS67xx, because they don't work with NVME drives at all, see #21 (comment)

Lastly, these units are all NVMe devices, and the default Linux kernel doesn't have a LED trigger for NVMe activity. disk-activity doesn't work for PCIe devices and the Linux kernel maintainers can't decide on the right approach. Again, we have to hope for ledtrig-blk or something here, but the disk activity LED could be used for other purposes in the meantime.

(I assume that disk-read etc have the same issues as disk-activity)

green/red:status - can be made to blink or not, but not turned off (brightness = 0 does nothing), likely a hardware restriction to force it always on?

Weird that brightness=0 doesn't work. Does it work for one of the colors (red or green) at least?
Does it help to set both gpled1_blink and gpled2_blink to 0?

@romracer: Is it the same with your device?

@mgc8
Copy link

mgc8 commented Oct 21, 2024

The disk triggers won't work with the FS67xx, because they don't work with NVME drives at all, see #21 (comment)

Okay, so that's the known NVMe LED issue then, all clear. But it's the same with pretty much every other trigger (cpuX, bluetooth-power, etc.). They either turn the LED completely on or off, none of them flickers at all -- except usb-host, that's the only one that seems to reflect some actual activity.

green/red:status - can be made to blink or not, but not turned off (brightness = 0 does nothing), likely a hardware restriction to force it always on?
Weird that brightness=0 doesn't work. Does it work for one of the colors (red or green) at least? Does it help to set both gpled1_blink and gpled2_blink to 0?

Ah, yes, the red part works fine, sorry for not being more clear. I can turn the red bit on, and then it gets that combined orange colour, and if I make the green status bit blink, then it basically flicks between deep red and orange.

The green won't turn fully off though, no matter what I set gpled1_blink to. gpled2_blink appears to not have any discernible effect on any of the existing LEDs (or at least not with any of the values I've tried, including 0 and 47).

@DanielGibson
Copy link
Contributor Author

If the usb-host trigger works but others don't then that sounds more like an issue with the triggers than with "our" kernel modules.

I just tested the green status LED blinking with my AS5402T.
echo 0 | sudo tee /sys/devices/platform/asustor_it87.*/hwmon/hwmon*/gpled1_blink
turns it off, but then I can't turn it on with setting brightness to 1, so it's kinda the opposite problem of yours?
However, after changing line 61 in asustor.c from
{ .name = "green:status", .default_state = LEDS_GPIO_DEFSTATE_ON }, // 4
to
{ .name = "green:status", .default_state = LEDS_GPIO_DEFSTATE_OFF }, // 4
setting brightness seems to work - can you try if it also works for you?

@romracer
Copy link
Contributor

but then I can't turn it on with setting brightness to 1

Does setting to 0 turn it on? I seem to remember if the default state is backwards, the brightness is backwards, or something like that. I'll have to digest some of these comments and check this module later this evening or this week. But I use the following in a startup script on TrueNAS SCALE and it works as expected (with my changes):

# Disable blinking status LED
echo 11 | sudo tee /sys/devices/platform/asustor_it87.*/hwmon/hwmon*/gpled1_blink_freq > /dev/null

# Turn off power LEDs
echo 0 | sudo tee /sys/class/leds/blue\:power/brightness > /dev/null
echo 0 | sudo tee /sys/class/leds/power\:front_panel/brightness > /dev/null

# Configure red disk LED as heartbeat
sudo /sbin/modprobe ledtrig-heartbeat
echo heartbeat | sudo tee /sys/class/leds/nvme1\:red\:disk/trigger > /dev/null

blue:lan - is actually purple/magenta, but otherwise works fine

I noticed this too, but only when connected to 10GbE. Is yours also connected to 10GbE? I swear it was blue on 1GbE, but I couldn't do my probing to find red while connected at 10GbE.

@DanielGibson
Copy link
Contributor Author

I did most requested changes, but I still have to do something about that dmi_matches() license issue

@DanielGibson
Copy link
Contributor Author

Ok I figured out how to build asustor.ko from two source files.
Unfortunately that required renaming asustor.c to something else; I chose asustor_main.c.
The second source file is asustor_gpl2.c which currently only contains the dmi_matches() implementation (renamed to asustor_dmi_matches to avoid conflicts)

@DanielGibson DanielGibson force-pushed the detect-flashtor branch 3 times, most recently from 2f7c0f6 to e61ad9d Compare November 24, 2024 20:51
@DanielGibson
Copy link
Contributor Author

Turns out that similar to how the struct pci_dev* must bee "freed" with pci_dev_put(), the struct gpio_device* from gpio_device_find_by_label() must be fed into gpio_device_put(). I made that change.

@mgc8 @romracer can you test the current version of the code? I think now it's really done :-)

@brunomatic
Copy link

brunomatic commented Dec 13, 2024

Since i just found this now, maybe the following can help for FS6706T - it has no PCIe bridges at all from what I see in the output of lspci:

admin@Oracle[~]$ sudo lspci -tv -nn
-[0000:00]-+-00.0  Intel Corporation Device [8086:4e24]
           +-02.0  Intel Corporation JasperLake [UHD Graphics] [8086:4e61]
           +-04.0  Intel Corporation Dynamic Tuning service [8086:4e03]
           +-05.0  Intel Corporation JasperLake IPU [8086:4e19]
           +-08.0  Intel Corporation Device [8086:4e11]
           +-14.0  Intel Corporation Device [8086:4ded]
           +-14.2  Intel Corporation Device [8086:4def]
           +-15.0  Intel Corporation Serial IO I2C Host Controller [8086:4de8]
           +-15.2  Intel Corporation Device [8086:4dea]
           +-16.0  Intel Corporation Management Engine Interface [8086:4de0]
           +-19.0  Intel Corporation Device [8086:4dc5]
           +-19.1  Intel Corporation Device [8086:4dc6]
           +-1c.0-[01]----00.0  Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller [10ec:8125]
           +-1c.1-[02]----00.0  Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller [10ec:8125]
           +-1c.2-[03]----00.0  Micron/Crucial Technology P2 NVMe PCIe SSD [c0a9:540a]
           +-1c.3-[04]----00.0  Kingston Technology Company, Inc. Device [2646:5017]
           +-1c.4-[05]----00.0  Micron/Crucial Technology P2 NVMe PCIe SSD [c0a9:540a]
           +-1c.5-[06]----00.0  Kingston Technology Company, Inc. Device [2646:5017]
           +-1c.6-[07]----00.0  Micron/Crucial Technology P2 NVMe PCIe SSD [c0a9:540a]
           +-1c.7-[08]----00.0  Kingston Technology Company, Inc. Device [2646:5017]
           +-1e.0  Intel Corporation Device [8086:4da8]
           +-1e.3  Intel Corporation Device [8086:4dab]
           +-1f.0  Intel Corporation Device [8086:4d87]
           +-1f.3  Intel Corporation Jasper Lake HD Audio [8086:4dc8]
           +-1f.4  Intel Corporation Jasper Lake SMBus [8086:4da3]
           \-1f.5  Intel Corporation Jasper Lake SPI Controller [8086:4da4]
admin@Oracle[~]$ sudo lspci -nn
00:00.0 Host bridge [0600]: Intel Corporation Device [8086:4e24]
00:02.0 VGA compatible controller [0300]: Intel Corporation JasperLake [UHD Graphics] [8086:4e61] (rev 01)
00:04.0 Signal processing controller [1180]: Intel Corporation Dynamic Tuning service [8086:4e03]
00:05.0 Multimedia controller [0480]: Intel Corporation JasperLake IPU [8086:4e19]
00:08.0 System peripheral [0880]: Intel Corporation Device [8086:4e11]
00:14.0 USB controller [0c03]: Intel Corporation Device [8086:4ded] (rev 01)
00:14.2 RAM memory [0500]: Intel Corporation Device [8086:4def] (rev 01)
00:15.0 Serial bus controller [0c80]: Intel Corporation Serial IO I2C Host Controller [8086:4de8] (rev 01)
00:15.2 Serial bus controller [0c80]: Intel Corporation Device [8086:4dea] (rev 01)
00:16.0 Communication controller [0780]: Intel Corporation Management Engine Interface [8086:4de0] (rev 01)
00:19.0 Serial bus controller [0c80]: Intel Corporation Device [8086:4dc5] (rev 01)
00:19.1 Serial bus controller [0c80]: Intel Corporation Device [8086:4dc6] (rev 01)
00:1c.0 PCI bridge [0604]: Intel Corporation Device [8086:4db8] (rev 01)
00:1c.1 PCI bridge [0604]: Intel Corporation Device [8086:4db9] (rev 01)
00:1c.2 PCI bridge [0604]: Intel Corporation Device [8086:4dba] (rev 01)
00:1c.3 PCI bridge [0604]: Intel Corporation Device [8086:4dbb] (rev 01)
00:1c.4 PCI bridge [0604]: Intel Corporation Device [8086:4dbc] (rev 01)
00:1c.5 PCI bridge [0604]: Intel Corporation Device [8086:4dbd] (rev 01)
00:1c.6 PCI bridge [0604]: Intel Corporation Device [8086:4dbe] (rev 01)
00:1c.7 PCI bridge [0604]: Intel Corporation Device [8086:4dbf] (rev 01)
00:1e.0 Communication controller [0780]: Intel Corporation Device [8086:4da8] (rev 01)
00:1e.3 Serial bus controller [0c80]: Intel Corporation Device [8086:4dab] (rev 01)
00:1f.0 ISA bridge [0601]: Intel Corporation Device [8086:4d87] (rev 01)
00:1f.3 Audio device [0403]: Intel Corporation Jasper Lake HD Audio [8086:4dc8] (rev 01)
00:1f.4 SMBus [0c05]: Intel Corporation Jasper Lake SMBus [8086:4da3] (rev 01)
00:1f.5 Serial bus controller [0c80]: Intel Corporation Jasper Lake SPI Controller [8086:4da4] (rev 01)
01:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller [10ec:8125] (rev 05)
02:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller [10ec:8125] (rev 05)
03:00.0 Non-Volatile memory controller [0108]: Micron/Crucial Technology P2 NVMe PCIe SSD [c0a9:540a] (rev 01)
04:00.0 Non-Volatile memory controller [0108]: Kingston Technology Company, Inc. Device [2646:5017] (rev 03)
05:00.0 Non-Volatile memory controller [0108]: Micron/Crucial Technology P2 NVMe PCIe SSD [c0a9:540a] (rev 01)
06:00.0 Non-Volatile memory controller [0108]: Kingston Technology Company, Inc. Device [2646:5017] (rev 03)
07:00.0 Non-Volatile memory controller [0108]: Micron/Crucial Technology P2 NVMe PCIe SSD [c0a9:540a] (rev 01)
08:00.0 Non-Volatile memory controller [0108]: Kingston Technology Company, Inc. Device [2646:5017] (rev 03)

Unfortunately I dont have the time right now to test the change but will do as soon as possible, but my guess is that just reducing the amount of these bridges to 0 will correct the detection mechanism for FS6706T as well.

{ 0x1b21, 0x2806, 1, DEVICE_COUNT_MAX }, -> { 0x1b21, 0x2806, 0, DEVICE_COUNT_MAX },

Maybe a proposal would be to differentiate between the two FS models based on their NICs but I dont know the ID used by 10G NIC:
FS6706T -> { 0x10ec, 0x8125, 1, 2},
FS6712X -> { 0xxxx, 0xxxx, 1, 1},

Also I'm willing to test something if needed as soon as I have some spare time.

@DanielGibson
Copy link
Contributor Author

DanielGibson commented Dec 13, 2024

Thanks a lot!
Just setting the min count to 0 wouldn't work, because 0 of these PCIe switches is how we detect the AS67xx which has the same DMI data as the FS67xx (usually the devices are detected by just the DMI data).

It seems like your device has more Intel PCI bridges than the FS6712X (or the AS67xx).
Some exist only in both FS67xx (but not AS67xx, I think, at least not in my AS5402 which I think is like AS6702):

00:1c.4 PCI bridge [0604]: Intel Corporation Device [8086:4dbc] (rev 01)
00:1c.6 PCI bridge [0604]: Intel Corporation Device [8086:4dbe] (rev 01)

UPDATE/TODO: I also only have one NVME SSD in my NAS, but it has 4 slots - I wonder if more of those intel PCI bridges would turn up if I used the other 3 NVME slots

Another candidate might be
00:1f.3 Audio device [0403]: Intel Corporation Jasper Lake HD Audio [8086:4dc8] (rev 01) (prog-if 80)
which also both FS67xx devices have, but my AS54xx doesn't.

Maybe one of those can be used, but I'll have to take a closer look at data from other AS67xx devices first.

ANOTHER UPDATE: Shit, at least the AS6706 has all the aforementioned PCI bridges and the audio device: #27 (comment)

@DanielGibson
Copy link
Contributor Author

Oh right, for the sake of completeness, can you also post the output of:

sudo dmidecode -s system-manufacturer
sudo dmidecode -s system-product-name
sudo dmidecode -s bios-vendor

@brunomatic
Copy link

Hi, yes, you are right i totally forgot the AS67xxx machine.
Here is the output:

root@Oracle[/home/admin]# sudo dmidecode -s system-manufacturer
sudo dmidecode -s system-product-name
sudo dmidecode -s bios-vendor
Intel Corporation
Jasper Lake Client Platform
Phoenix Technologies Ltd
root@Oracle[/home/admin]#

asustor_main.c is licensed under GPLv2 or later, while asustor_gpl2.c
is licensed under GPLv2 only.
dmi_matches() is moved from asustor(_main).c to asustor_gpl2.c, because
it's copied from drivers/firmware/dmi_scan.c which is released under
GPLv2 only.

asustor.c had to be renamed to asustor_main.c, because apparently the
kernel build system only supports a source file with the same name as
the module if that module is built only from that file.

I also bumped the DRIVER_VERSION (used for DKMS) from v0.1 to v0.2
to hopefully avoid conflicts due to all these changes
.. and update the link to the block device LED trigger to the (AFAIK)
latest (last?) attempt by Ian Pilcher (v13)

Though TBH it seems like neither is ever gonna happen, because the block
subsystem maintainers don't even want to provide an API that allows
accessing block device data based on the device name (like sda), and
generally seem to be unfriendly, so maybe the best solution would be to
implement this in the userland (periodically check disks read/write
stats and control blinking based on that)...
turns out that the gpio_device* returned by gpio_device_find_by_label()
must be "freed" (or the refcounter decremented) by calling
gpio_device_put(dev).

While fixing that, I refactored the code for getting the GPIO chip's
base number a bit so we don't have to use the (deprecated)
gpio_device_get_chip() anymore.
Looks like the Flashtor for 6 SSDs doesn't have any PCIe device that
the *A*S67xx devices don't have.
So now we painstakingly detect every AS67xx and FS67xx separately.
On the upside, this allows exposing only the SATA LEDs that actually
exist on each specific AS67xx device.

This also means that the overrides (force_device kernel module argument)
for those devices have changed and are now "AS6702", "AS6704", "AS6706"
instead of "AS67xx" and "FS6706", "FS6712" instead of "FS67xx"
@DanielGibson
Copy link
Contributor Author

I updated the code for this, now the AS67xx and FS67xx devices are detected separately as "AS6702" (also used for AS5402T), "AS6704" (also used for AS5404T), "AS6706", "FS6706" and "FS6712".

Of course this means that the code should be tested on all those devices.
So @brunomatic please test it on FS6706T, @mgc8 and @romracer please test on FS6712X, @phjz and @hkdd please test on AS6704T, @odeBuXTeR please test on AS6702T (I did those changes assuming that it is similar enough to my AS5402T), @LPJon please test on AS6706T :)

Testing means: Check out my branch (detect-flashtor at https://github.com/DanielGibson/asustor-platform-driver.git), build it (make) and either install it or, of you already have a version of this driver installed, you can just temporarily test it like:

# unload currently loaded asustor kernel module
sudo rmmod asustor
# load the new one you just built
sudo insmod ./asustor.ko

Afterwards check if dmesg has a line like [Dez14 14:15] asustor: Found AS6702 or similar (Intel Corporation/Jasper Lake Client Platform) (of course instead of "AS6702" it should name the device you're actually using).

Thanks in advance!

@brunomatic
Copy link

Hi @DanielGibson,

All seems to work well on my end, good idea on using negative check for SATA and all PCIe bridges!

Dec 14 15:55:42 Oracle kernel: asustor_it87: Found IT8625E chip at 0xa30, revision 13
Dec 14 15:55:42 Oracle kernel: asustor_it87: Beeping is supported
Dec 14 15:55:42 Oracle kernel: asustor_gpio_it87: Found Chip IT8625 rev d. 64 GPIO lines starting at 0a00h
Dec 14 15:55:42 Oracle kernel: asustor: Found FS6706 or similar (Intel Corporation/Jasper Lake Client Platform)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (power:lcd)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (blue:usb)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (green:usb)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata1:green:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata1:red:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata2:green:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata2:red:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata3:green:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata3:red:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata4:green:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata4:red:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata5:green:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata5:red:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata6:green:disk)
Dec 14 15:55:42 Oracle kernel: leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata6:red:disk)
Dec 14 15:55:42 Oracle kernel: input: asustor-keys as /devices/platform/gpio-keys-polled/input/input18

Some further information that i managed to dig out from my experiments some time ago is the LED to GPIO mapping using the gpio_it87 driver:

49 - activity red 
56 - red power button led + blue power led
8 - orange power led
12 - disk green
13 - disk red
55 - network blue

46 - front red decorative inner
47 - front red decorative mid
52 - front red decorative outer

Further more I noted also the inversion on the pwm control for the brightness, but i have no idea if this is still valid:

pwm3 -> power button brightness and leds, inverted - 255 off
pwm1 -> fan

What I really can't wrap my head around is that Asustor does this detection most likely on something stored in emmc boot partitions or maybe in the SPI eeprom where the BIOS is stored, but I could not find a single clue in their firmware update files or ACPI tables dissasembly. The furthest i could get is that they pull this info from /etc/nas.conf for their scripts.

@DanielGibson
Copy link
Contributor Author

DanielGibson commented Dec 14, 2024

Thanks a lot @brunomatic!
Most of those LEDs are already supported, see https://github.com/DanielGibson/asustor-platform-driver/blob/9c9cc669d8c6b22f12c203c97b05f5b294851118/asustor_main.c#L95-L111
But those decorative inner and mid ones (46 and 47) are currently missing, so it's great you figured them out :)
@mgc8 you were wondering about this, can you confirm that 46 and 47 also work on the FS6712X?
I'll add those later.

You're right about the inverted pwm control for brightness, it's the same on my AS5402T. Not sure if we can do anything about that though

@mgc8
Copy link

mgc8 commented Dec 14, 2024

Of course this means that the code should be tested on all those devices. So @brunomatic please test it on FS6706T, @mgc8 and @romracer please test on FS6712X, @phjz and @hkdd please test on AS6704T, @odeBuXTeR please test on AS6702T (I did those changes assuming that it is similar enough to my AS5402T), @LPJon please test on AS6706T :)

Hi @DanielGibson , sorry for the delay lately, the end of the year period tends to get a bit crazy...

I have checked out the latest version of your branch for a clean build, and I can confirm that it compiles and loads fine, yielding the expected result on the FS6712x:

[4414215.779223] asustor: Found FS6712 or similar (Intel Corporation/Jasper Lake Client Platform)
[4414215.779505] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (power:lcd)
[4414215.794119] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (blue:usb)
[4414215.794126] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (green:usb)
[4414215.794345] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata1:green:disk)
[4414215.794347] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata1:red:disk)
[4414215.794349] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata2:green:disk)
[4414215.794351] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata2:red:disk)
[4414215.794352] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata3:green:disk)
[4414215.794354] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata3:red:disk)
[4414215.794355] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata4:green:disk)
[4414215.794357] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata4:red:disk)
[4414215.794358] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata5:green:disk)
[4414215.794359] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata5:red:disk)
[4414215.794361] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata6:green:disk)
[4414215.794362] leds-gpio leds-gpio: Skipping unavailable LED gpio 0 (sata6:red:disk)
[4414215.794828] input: asustor-keys as /devices/platform/gpio-keys-polled/input/input22

@mgc8 you were wondering about this, can you confirm that 46 and 47 also work on the FS6712X?

I tried enabling those GPIOs as per your comments here, but I didn't see any change with the red side/middle LEDs:

$ echo 0 | sudo tee /sys/devices/platform/asustor_it87.*/hwmon/hwmon*/gpled1_blink_freq
$ echo 46 | sudo tee /sys/devices/platform/asustor_it87.*/hwmon/hwmon*/gpled1_blink
>>> does nothing
$ echo 47 | sudo tee /sys/devices/platform/asustor_it87.*/hwmon/hwmon*/gpled1_blink
>>> makes the green front led blink instead
$ echo 52 | sudo tee /sys/devices/platform/asustor_it87.*/hwmon/hwmon*/gpled1_blink
>>> does nothing
$ echo 66 | sudo tee /sys/devices/platform/asustor_it87.*/hwmon/hwmon*/gpled1_blink
>>> does nothing (assuming 46 as index in the GPIO list, pointing to GPIO 66)
$ echo 67 | sudo tee /sys/devices/platform/asustor_it87.*/hwmon/hwmon*/gpled1_blink
>>> does nothing (assuming 47 as index in the GPIO list, pointing to GPIO 67)

@brunomatic Can you please provide more details as to how you identified those GPIO numbers and process you use for testing them? On quick check they don't line up with what we already have here:
https://github.com/mafredri/asustor-platform-driver/blob/main/research/as6204_it87_gpio_firmware_configuration.md

@mgc8
Copy link

mgc8 commented Dec 14, 2024

Since i just found this now, maybe the following can help for FS6706T - it has no PCIe bridges at all from what I see in the output of lspci:

Be careful with lspci -tv, as it will hide the in-between switches and only shows the end devices (in this case, NICs and NVMe drives). As it happens, the FS6706 also contains quite a few PCIe bridges, as the processor would be incapable of supporting all the devices otherwise. You can see right in your full output -- but they're Intel, not ASMedia:

(...)
00:1c.0 PCI bridge [0604]: Intel Corporation Device [8086:4db8] (rev 01)
00:1c.1 PCI bridge [0604]: Intel Corporation Device [8086:4db9] (rev 01)
00:1c.2 PCI bridge [0604]: Intel Corporation Device [8086:4dba] (rev 01)
00:1c.3 PCI bridge [0604]: Intel Corporation Device [8086:4dbb] (rev 01)
00:1c.4 PCI bridge [0604]: Intel Corporation Device [8086:4dbc] (rev 01)
00:1c.5 PCI bridge [0604]: Intel Corporation Device [8086:4dbd] (rev 01)
00:1c.6 PCI bridge [0604]: Intel Corporation Device [8086:4dbe] (rev 01)
00:1c.7 PCI bridge [0604]: Intel Corporation Device [8086:4dbf] (rev 01)

Maybe a proposal would be to differentiate between the two FS models based on their NICs but I dont know the ID used by 10G NIC: FS6706T -> { 0x10ec, 0x8125, 1, 2}, FS6712X -> { 0xxxx, 0xxxx, 1, 1},

That would indeed be a good way to differentiate them. The FS6712x comes with the Aquantia AQC113 10GbE controller, ID [1d6a:04c0]:

01:00.0 Ethernet controller [0200]: Aquantia Corp. AQtion AQC113 NBase-T/IEEE 802.3an Ethernet Controller [Antigua 10G] [1d6a:04c0] (rev 03)

@DanielGibson
Copy link
Contributor Author

DanielGibson commented Dec 14, 2024

Thanks a lot, @mgc8 !
I just pushed a commit that should allow controlling the LEDs on the side through /sys/class/leds/red:side_inner, red:side_mid and red:side_outer - does that work for you (and/or for @brunomatic)?

That would indeed be a good way to differentiate them.

The problem wasn't telling FS6706 and FS6712 apart (only the latter has the specific PCIe Switch I'm matching - the Intel PCI bridges exist in all AS67xx and FS67xx devices), but telling FS6706 and AS67xx apart - but I found a solution that worked for anyone who tested so far (FS6712 is still the only device with that PCIe Bridge and FS6706 is the only device, apart from FS6712, that has no SATA controller) :)

@mgc8
Copy link

mgc8 commented Dec 14, 2024

Thanks a lot, @mgc8 ! I just pushed a commit that should allow controlling the LEDs on the side through /sys/class/leds/red:side_inner, red:side_mid and red:side_outer - does that work for you (and/or for @brunomatic)?

Wow, awesome! Yes, they work perfectly with this patch, and each has the correct assignment. The mid ones are not very obvious if the inner/outer are lit, but they become quite visible if those are turned off. Then there's the centre one as well, controlled as earlier with blue:power. Interestingly, these LEDs don't appear to apply the "blink" state as the others can, thus probably why I didn't see them change with testing earlier.

You can make a veritable light show with a script like this 😅:

#!/bin/bash

LEDs=(/sys/class/leds/red:side*)

while : ; do
	state=$(($RANDOM % 2))
	led=$(($RANDOM % 3))
	echo ${state} > ${LEDs[$led]}/brightness
	sleep 0.2
done

The problem wasn't telling FS6706 and FS6712 apart (only the latter has the specific PCIe Switch I'm matching - the Intel PCI bridges exist in all AS67xx and FS67xx devices), but telling FS6706 and AS67xx apart - but I found a solution that worked for anyone who tested so far (FS6712 is still the only device with that PCIe Bridge and FS6706 is the only device, apart from FS6712, that has no SATA controller) :)

That's quite smart :) What a variety of configurations for these devices...

@DanielGibson
Copy link
Contributor Author

DanielGibson commented Dec 14, 2024

Yes, they work perfectly with this patch

Good to hear!

That's quite smart :)

thanks :)

What a variety of configurations for these devices...

It partly makes sense: the ones with SATA drives each have a different SATA controller that supports as many drives as needed (and it's possible that the SATA controller isn't even on the mainboard, but on a separate card that also holds the SATA connectors for the bays, connected via PCIe slot, so maybe all AS67xx devices use the same mainboard - but that's just speculation on my side).
What surprised me the most was that the AS5402T hardware is slightly different from the AS6702T hardware: Unlike the AS5402T, the AS6702T has an Intel HD Audio chip (and so do the other AS67xx devices, apparently) - even though those don't have any audio ports (FS67xx seems to have an SPDIF port, but the AS67xx devices don't).

BTW, nice idea with the script =)

It's those red strips on the left and right side of the power button.
They're controlled by three GPIOs that are exposed as the new LEDs
red:side_inner, red:side_mid and red:side_outer

One of them was previously controlled by power:front_panel, but I
changed it so it's more consistent with the other two LEDs (LED pairs?)
of the strips

Thanks to @brunomatic for figuring out the GPIOs of these LEDs!
@DanielGibson
Copy link
Contributor Author

DanielGibson commented Dec 15, 2024

@mgc8

I tried enabling those GPIOs as per your #27 (comment), but I didn't see any change with the red side/middle LEDs:
(...)

Sorry, didn't look at that closely earlier.
The numbers you must use with gpledX_blink are not the numbers used in the asustor_main.c gpiod_lookup_tables.
The gpiod_lookup_table use the line, but gpledX_blink needs to use the number from the name, see this table: https://github.com/mafredri/asustor-platform-driver/blob/main/research/as6204_it87_gpio_firmware_configuration.md
So for line 42 the name is it87_gp62 so you must write 62 into gpled1_blink.
Yes, this is a bit confusing, maybe it could be improved, but not in this PR or it will never get merged ;)
(you could open an issue about it so it's not forgotten)

@mgc8
Copy link

mgc8 commented Dec 15, 2024

Sorry, didn't look at that closely earlier. The numbers you must use with gpledX_blink are not the numbers used in the asustor_main.c gpiod_lookup_tables. The gpiod_lookup_table use the line, but gpledX_blink needs to use the number from the name, see this table: https://github.com/mafredri/asustor-platform-driver/blob/main/research/as6204_it87_gpio_firmware_configuration.md So for line 42 the name is it87_gp62 so you must write 62 into gpled1_blink. Yes, this is a bit confusing, maybe it could be improved, but not in this PR or it will never get merged ;) (you could open an issue about it so it's not forgotten)

It is indeed a bit confusing, but I had tried both 46 and 66 in that case, and neither caused the LED to blink; it could be that it was working but just not doing the "blink" action. In any case, it's all moot now as your added patch makes sure they all work nicely. I don't think it's worth a separate issue, let's just get this merged as I think it covers all the bases now!

@DanielGibson
Copy link
Contributor Author

@mafredri I think this is really ready for merging now ;)

Of course it would've been nice of someone with an AS67xx had tested the current code, but at least it has been tested with Flashtor FS6706T and FS6712X and my FS5402T (which is correctly detected as "AS6702 or similar") and I see no reason why detection of AS67xx should fail.

@odeBuXTeR
Copy link

@mafredri I think this is really ready for merging now ;)

Of course it would've been nice of someone with an AS67xx had tested the current code, but at least it has been tested with Flashtor FS6706T and FS6712X and my FS5402T (which is correctly detected as "AS6702 or similar") and I see no reason why detection of AS67xx should fail.

So sorry, I forgot to tell you that I've installed it last week, and all seems to work properly. Detection is OK (as AS6702 wich I have)

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.

7 participants