Bug 2091399 - Bluetooth does not work on Mediatek MT7922
Summary: Bluetooth does not work on Mediatek MT7922
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: linux-firmware
Version: 36
Hardware: x86_64
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: David Woodhouse
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-05-29 13:47 UTC by undercover_black_hat
Modified: 2022-06-17 10:02 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-06-07 14:56:37 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description undercover_black_hat 2022-05-29 13:47:09 UTC
Description of problem:
Bluetooth on Mediatek MT7922 just does not work.

Version-Release number of selected component (if applicable):
[razvan@fedora ~]$ uname -a
Linux fedora 5.17.11-300.fc36.x86_64 #1 SMP PREEMPT Wed May 25 15:04:05 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

[razvan@fedora ~]$ rpm -qa | grep -i blue
bluez-libs-5.64-1.fc36.x86_64
bluez-5.64-1.fc36.x86_64
gnome-bluetooth-libs-42.0-1.fc36.x86_64
gnome-bluetooth-42.0-1.fc36.x86_64
bluez-cups-5.64-1.fc36.x86_64
NetworkManager-bluetooth-1.38.0-1.fc36.x86_64

[razvan@fedora ~]$ rpm -qa | grep -i firmware
linux-firmware-whence-20220509-132.fc36.noarch
linux-firmware-20220509-132.fc36.noarch

lspci -k 
03:00.0 Network controller: MEDIATEK Corp. Device 7922
	Subsystem: AzureWave Device 5300
	Kernel driver in use: mt7921e
	Kernel modules: mt7921e


How reproducible:
Everytime

Steps to Reproduce:
1. Boot
2. Try to turn on bluetooth
3. Fail

Actual results:
Bluetooth does not work.

Expected results:
Bluetooth should work.

Additional info:
[razvan@fedora ~]$ dmesg | grep -i blue
[    4.732817] Bluetooth: Core ver 2.22
[    4.732836] NET: Registered PF_BLUETOOTH protocol family
[    4.732837] Bluetooth: HCI device and connection manager initialized
[    4.732840] Bluetooth: HCI socket layer initialized
[    4.732841] Bluetooth: L2CAP socket layer initialized
[    4.732845] Bluetooth: SCO socket layer initialized
[    5.730162] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    5.730166] Bluetooth: BNEP filters: protocol multicast
[    5.730170] Bluetooth: BNEP socket layer initialized
[    6.892206] Bluetooth: hci0: Opcode 0x c03 failed: -110

Comment 1 Peter Robinson 2022-05-30 08:00:29 UTC
> lspci -k 
> 03:00.0 Network controller: MEDIATEK Corp. Device 7922
> 	Subsystem: AzureWave Device 5300
> 	Kernel driver in use: mt7921e
> 	Kernel modules: mt7921e

That's for the WiFi component, can you see if there's a mediatek entry on lsusb? The module for mediatke BT is one of btmtk*. Even though it's a single module the WiFi is attached via PCIe, the BT is usually via USB. We have firmware for the BT MT7922 module, maybe this variant isn't detected in the kernel as yet.

Comment 2 undercover_black_hat 2022-05-30 09:37:58 UTC
Weirdly enough it now works without any update. I just fiddled with the power settings, removed all paired devices from Windows and did a disable/enable bluetooth device from Windows (it's a dual boot system). I've suspected it could be some weird state leftover from Windows as I've found anecdotal evidence about this online but everything I tried until now failed (hard power cycle of device, uninstall device from windows, disable device from windows).

This is how it looks when it is working:

[root@fedora razvan]# uname -a
Linux fedora 5.17.11-300.fc36.x86_64 #1 SMP PREEMPT Wed May 25 15:04:05 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

[root@fedora razvan]# rpm -qa | grep -i blue
bluez-libs-5.64-1.fc36.x86_64
bluez-5.64-1.fc36.x86_64
gnome-bluetooth-libs-42.0-1.fc36.x86_64
gnome-bluetooth-42.0-1.fc36.x86_64
bluez-cups-5.64-1.fc36.x86_64
NetworkManager-bluetooth-1.38.0-1.fc36.x86_64

[root@fedora razvan]# rpm -qa | grep -i firmware
zd1211-firmware-1.5-10.fc36.noarch
atmel-firmware-1.3-26.fc36.noarch
alsa-sof-firmware-2.0-3.fc36.noarch
linux-firmware-whence-20220509-132.fc36.noarch
linux-firmware-20220509-132.fc36.noarch
libertas-usb8388-firmware-20220509-132.fc36.noarch

[root@fedora razvan]# lspci -k | grep -C 3 mt79
pcilib: Error reading /sys/bus/pci/devices/0000:00:08.3/label: Operation not permitted
	Kernel modules: r8169
03:00.0 Network controller: MEDIATEK Corp. Device 7922
	Subsystem: AzureWave Device 5300
	Kernel driver in use: mt7921e
	Kernel modules: mt7921e
04:00.0 SD Host controller: O2 Micro, Inc. SD/MMC Card Reader Controller (rev 01)
	Subsystem: ASUSTeK Computer Inc. Device 202f
	Kernel driver in use: sdhci-pci

[root@fedora razvan]# dmesg | grep -i blue
[    4.680336] Bluetooth: Core ver 2.22
[    4.680361] NET: Registered PF_BLUETOOTH protocol family
[    4.680362] Bluetooth: HCI device and connection manager initialized
[    4.680417] Bluetooth: HCI socket layer initialized
[    4.680420] Bluetooth: L2CAP socket layer initialized
[    4.680426] Bluetooth: SCO socket layer initialized
[    5.670817] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    5.670821] Bluetooth: BNEP filters: protocol multicast
[    5.670824] Bluetooth: BNEP socket layer initialized
[   16.075319] Bluetooth: RFCOMM TTY layer initialized
[   16.075326] Bluetooth: RFCOMM socket layer initialized
[   16.075353] Bluetooth: RFCOMM ver 1.11
[ 2165.380469] Bluetooth: hci0: SCO packet for unknown connection handle 3584
[ 2165.380476] Bluetooth: hci0: SCO packet for unknown connection handle 3584
[ 2165.380481] Bluetooth: hci0: SCO packet for unknown connection handle 3584
[ 2165.380484] Bluetooth: hci0: SCO packet for unknown connection handle 3584
[ 2165.380487] Bluetooth: hci0: SCO packet for unknown connection handle 3584
[ 2165.380488] Bluetooth: hci0: SCO packet for unknown connection handle 3584
[ 2165.380490] Bluetooth: hci0: SCO packet for unknown connection handle 3584

[root@fedora razvan]# lsusb
Bus 009 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 010 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 002: ID 13d3:56eb IMC Networks USB2.0 HD UVC WebCam
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 13d3:3568 IMC Networks Wireless_Device
Bus 003 Device 002: ID 09da:1242 A4Tech Co., Ltd. USB Device
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 0b05:19b6 ASUSTek Computer, Inc. ITE Device(8910)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

[root@fedora razvan]# dmesg | grep -i mt79
[    4.873012] mt7921e 0000:03:00.0: enabling device (0000 -> 0002)
[    4.899077] mt7921e 0000:03:00.0: ASIC revision: 79220010
[    4.976148] mt7921e 0000:03:00.0: HW/SW Version: 0x8a108a10, Build Time: 20220322163923a
[    4.991499] mt7921e 0000:03:00.0: WM Firmware Version: ____000000, Build Time: 20220322164011
[    6.069734] mt7921e 0000:03:00.0 wlp3s0: renamed from wlan0


As soon as it starts not working again I will post a lsusb from a non working state.

Comment 3 undercover_black_hat 2022-06-02 10:18:22 UTC
It is back to non working after one reboot. There is definitely something wrong with the drivers.

Here is the output os lsusb from the non working state:
[root@fedora ~]# lsusb
Bus 009 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 010 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 002: ID 13d3:56eb IMC Networks USB2.0 HD UVC WebCam
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 13d3:3568 IMC Networks Wireless_Device
Bus 003 Device 003: ID 09da:1242 A4Tech Co., Ltd. USB Device
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 0b05:19b6 ASUSTek Computer, Inc. ITE Device(8910)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I really think this should not be closed as it is clear it is a bug. It went from working to not working without booting into windows.

Comment 4 Peter Robinson 2022-06-06 10:50:26 UTC
(In reply to undercover_black_hat from comment #2)
> Weirdly enough it now works without any update. I just fiddled with the
> power settings, removed all paired devices from Windows and did a
> disable/enable bluetooth device from Windows (it's a dual boot system). I've
> suspected it could be some weird state leftover from Windows as I've found
> anecdotal evidence about this online but everything I tried until now failed
> (hard power cycle of device, uninstall device from windows, disable device
> from windows).

So does it work if you boot from Linux to Linux? Windows to Linux? You need to provide a LOT more information. But TBH I don't believe I'm going to be able to resolve this issue, I don't have the HW or windows licenses to even begin to test.

Comment 5 undercover_black_hat 2022-06-06 12:19:46 UTC
So it only works if Windows loads the firmware on the card and then I do a restart (not shutdown). I think the problem was in btusb.c and this commit might fix it: https://patchwork.kernel.org/project/linux-mediatek/patch/20220602092822.953521-1-aaron.ma@canonical.com/

I have not tested this patch yet but it lines up with the card ID I see on lsusb (13d3:3568) so you can go ahead and close the bug again.

Thank you!

Comment 6 undercover_black_hat 2022-06-07 12:47:31 UTC
I am having issues compiling the patch (it is based on kernel 5.18 while I'm running 5.17). I have installed the kernel-devel package but it seems to be missing the drivers, all I get in the folder are a Makefile and a Kconfig:

[root@fedora]$ ls /usr/src/kernels/5.17.12-300.fc36.x86_64/drivers/bluetooth/
Kconfig  Makefile


Do you know what package I should install in order to get the source for bluetooth for my running kernel? If I build the module from bluetooth-next branch I get an error when inserting it with modprobe:
[root@fedora 5.17.12-300.fc36.x86_64]# modprobe btusb
modprobe: ERROR: could not insert 'btusb': Exec format error

Comment 7 Peter Robinson 2022-06-07 14:56:37 UTC
You'll probably need to build a new kernel, else an out of tree driver from the upstream source with the patch applied. Details on that is here:
https://fedoraproject.org/wiki/Building_a_custom_kernel

Unfortunately I don't have the time to walk you through this process, and a bug report against linux-firmware isn't the place to get help building bits if the kernel.

Comment 8 undercover_black_hat 2022-06-07 18:27:57 UTC
Fortunately you don't need to. I fixed it and it ALL WORKS no matter how many times I reboot or shutdown!

[razvan@fedora ~]$ dmesg | grep -i blue
[    4.803356] Bluetooth: Core ver 2.22
[    4.803384] NET: Registered PF_BLUETOOTH protocol family
[    4.803385] Bluetooth: HCI device and connection manager initialized
[    4.803389] Bluetooth: HCI socket layer initialized
[    4.803391] Bluetooth: L2CAP socket layer initialized
[    4.803394] Bluetooth: SCO socket layer initialized
[    5.039361] Bluetooth: hci0: Device setup in 140689 usecs
[    5.815196] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    5.815200] Bluetooth: BNEP filters: protocol multicast
[    5.815205] Bluetooth: BNEP socket layer initialized
[   15.180344] Bluetooth: RFCOMM TTY layer initialized
[   15.180350] Bluetooth: RFCOMM socket layer initialized
[   15.180374] Bluetooth: RFCOMM ver 1.11

In case anyone else had this problem and google leads them here I will note down the steps taken to apply the patch from Aaron Ma until this gets mainlined in the Fedora Kernel.

First install the kernel-devel package:
  dnf install kernel-devel

Install build tools (I've put the whole dnf group because I don't know the exact packages used):
  dnf install @'Development Tools'

Download your version of the kernel from kernel.org:
  wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$(uname -r | awk '{split($0,a,"-"); print a[1]}').tar.xz

Unarchive the kernel:
  tar -xf linux-$(uname -r | awk '{split($0,a,"-"); print a[1]}').tar.xz

Change to the bluetooth directory of your newly extracted kernel:
  cd linux-$(uname -r | awk '{split($0,a,"-"); print a[1]}')/drivers/bluetooth/

Now you have to edit the Makefile so it has the following text (note that the space beneath default: is a tab key, not spaces):
obj-m := btusb.o

KDIR  := /lib/modules/$(shell uname -r)/build
PWD   := $(shell pwd)

default:
        $(MAKE) -C $(KDIR) M=$(PWD) modules

Now you have to edit btusb.c to apply the patch, just insert the following after
 	{ USB_DEVICE(0x0489, 0xe0d9), .driver_info = BTUSB_MEDIATEK |
						     BTUSB_WIDEBAND_SPEECH |
						     BTUSB_VALID_LE_STATES }, <--- after this
	{ USB_DEVICE(0x13d3, 0x3568), .driver_info = BTUSB_MEDIATEK |
						     BTUSB_WIDEBAND_SPEECH |
						     BTUSB_VALID_LE_STATES },
Save, and use make to build the module.

After it's build zip it up with:
  xz -z btusb.ko

And move it to it's final resting place>
  cp btusb.ko.xz /lib/modules/$(uname -r)/kernel/drivers/bluetooth/

This will give you a tainted kernel, but at least you have bluetooth. Reboot and enjoy!

Comment 9 undercover_black_hat 2022-06-17 10:02:49 UTC
If you, like me, don't feel like compiling an out of tree module every time you update your kernel, I made this python script that binary patches btusb.ko and strips it's keys: https://github.com/mpsOxygen/kernel_btusb


Note You need to log in before you can comment on or make changes to this bug.