Patching mt76 eeprom.c for MT7615 on x86/64

I am currently trying to get a MT7615 mini pcie card (https://docs.banana-pi.org/en/BPI-MT7615/BananaPi_MT7615) to run in a x86/64 device. Since the card does not seem to have its own eeprom, this data has (afaik) to be loaded during initialization. I tried to use a patch from Frank Wunderlich when compiling the kernel module, which allows the eeprom data to be loaded from the file system:

diff -Naur a/eeprom.c b/eeprom.c
From: Frank Wunderlich <frank-w@public-files.de>

Updated to kernel 5.14

--- a/eeprom.c
+++ b/eeprom.c
@@ -9,6 +9,48 @@
 #include <linux/etherdevice.h>
 #include "mt76.h"
 
+static int
+mt76_get_eeprom_file(struct mt76_dev *dev, void *eep, int offset, int len)
+{
+	char path[64]="";
+	struct file *fp;
+	loff_t pos=0;
+	int ret;
+	struct inode *inode = NULL;
+	loff_t size;
+
+	ret = snprintf(path,sizeof(path),"/lib/firmware/mediatek/%s_rf.bin",dev->dev->driver->name);
+	if(ret<0)
+		return -EINVAL;
+	dev_info(dev->dev,"Load eeprom: %s\n",path);
+	fp = filp_open(path, O_RDONLY, 0);
+	if (IS_ERR(fp)) {
+		dev_info(dev->dev,"Open eeprom file failed: %s\n",path);
+		return -ENOENT;
+	}
+
+	inode = file_inode(fp);
+	if ((!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) {
+		printk(KERN_ALERT "invalid file type: %s\n", path);
+		return -ENOENT;
+	}
+	size = i_size_read(inode->i_mapping->host);
+	if (size < 0)
+	{
+		printk(KERN_ALERT "failed getting size of %s size:%lld \n",path,size);
+		return -ENOENT;
+	}
+	ret = kernel_read(fp, eep, len, &pos);
+	if(ret < size){
+		dev_info(dev->dev,"Load eeprom ERR, count %d byte (len:%d)\n",ret,len);
+		return -ENOENT;
+	}
+	filp_close(fp, 0);
+	dev_info(dev->dev,"Load eeprom OK, count %d byte\n",ret);
+
+	return 0;
+}
+
 int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
 {
 #if defined(CONFIG_OF) && defined(CONFIG_MTD)
@@ -331,6 +373,7 @@
 	if (!dev->eeprom.data)
 		return -ENOMEM;
 
-	return !mt76_get_of_eeprom(dev, dev->eeprom.data, 0, len);
+	return (!mt76_get_of_eeprom(dev, dev->eeprom.data, 0, len)) || 
+	     (!mt76_get_eeprom_file(dev, dev->eeprom.data, 0, len));
 }
 EXPORT_SYMBOL_GPL(mt76_eeprom_init);

I put the patch file to package/kernel/mt76/patches/. Unfortunately there is an error when compiling:

Applying /home/mike/openwrt/package/kernel/mt76/patches/0009-mt76-mt7603-fix-mixed-declarations-and-code.patch using plaintext: 
patching file mt7603/dma.c

Applying /home/mike/openwrt/package/kernel/mt76/patches/0010_mt76_eeprom_file.patch using plaintext: 
patching file eeprom.c
Hunk #1 FAILED at 9.
patch unexpectedly ends in middle of line
Hunk #2 FAILED at 331.
2 out of 2 hunks FAILED -- saving rejects to file eeprom.c.rej
Patch failed!  Please fix /home/mike/openwrt/package/kernel/mt76/patches/0010_mt76_eeprom_file.patch!
make[2]: *** [Makefile:642: /home/mike/openwrt/build_dir/target-x86_64_musl/linux-x86_64/mt76-2024-04-03-1e336a85/.prepared_c8b77d4779ffbe0ee25e41db1281e8f7_18f1e190c5d53547fed41a3eaa76e9e9] Error 1
make[2]: Leaving directory '/home/mike/openwrt/package/kernel/mt76'
time: package/kernel/mt76/compile#0.69#0.16#0.77
    ERROR: package/kernel/mt76 failed to build.
make[1]: *** [package/Makefile:129: package/kernel/mt76/compile] Error 1
make[1]: Leaving directory '/home/mike/openwrt'
make: *** [/home/mike/openwrt/include/toplevel.mk:233: package/kernel/mt76/compile] Fehler 2

Can anyone help here?

No, there's an error when you're patching ...

1 Like

My fault: The patch fails during the build process. :wink:

Ok, it seems to me that the patch no longer matches the current version of eeprom.c. I'll try to modify it.

Seems to work after fixing the patch fille:

[    8.868027] mt7615e 0000:02:00.0: enabling device (0000 -> 0002)
[    8.876774] mt7615e 0000:02:00.0: Load eeprom: /lib/firmware/mediatek/mt7615e_rf.bin
[    8.887660] mt7615e 0000:02:00.0: Load eeprom OK, count 19880 byte
[    8.899235] mt7615e 0000:02:00.0: registering led 'mt76-phy0'
[    9.040768] mt7615e 0000:02:00.0: N9 Firmware Version: _reserved_, Build Time: 20200814163649
[    9.057834] mt7615e 0000:02:00.0: CR4 Firmware Version: _reserved_, Build Time: 20190415154149
[   16.702064] mt7615e 0000:02:00.0: registering led 'mt76-phy1'

post/link the fixed patch file, TIA ...

diff -Naur a/eeprom.c b/eeprom.c
From: Frank Wunderlich <frank-w@public-files.de>

--- a/eeprom.c
+++ b/eeprom.c
@@ -10,6 +10,48 @@
 #include <linux/etherdevice.h>
 #include "mt76.h"
 
+static int
+mt76_get_eeprom_file(struct mt76_dev *dev, void *eep, int len)
+{
+	char path[64]="";
+	struct file *fp;
+	loff_t pos=0;
+	int ret;
+	struct inode *inode = NULL;
+	loff_t size;
+
+	ret = snprintf(path,sizeof(path),"/lib/firmware/mediatek/%s_rf.bin",dev->dev->driver->name);
+	if(ret<0)
+		return -EINVAL;
+	dev_info(dev->dev,"Load eeprom: %s\n",path);
+	fp = filp_open(path, O_RDONLY, 0);
+	if (IS_ERR(fp)) {
+		dev_info(dev->dev,"Open eeprom file failed: %s\n",path);
+		return -ENOENT;
+	}
+
+	inode = file_inode(fp);
+	if ((!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) {
+		printk(KERN_ALERT "invalid file type: %s\n", path);
+		return -ENOENT;
+	}
+	size = i_size_read(inode->i_mapping->host);
+	if (size < 0)
+	{
+		printk(KERN_ALERT "failed getting size of %s size:%lld \n",path,size);
+		return -ENOENT;
+	}
+	ret = kernel_read(fp, eep, len, &pos);
+	if(ret < size){
+		dev_info(dev->dev,"Load eeprom ERR, count %d byte (len:%d)\n",ret,len);
+		return -ENOENT;
+	}
+	filp_close(fp, 0);
+	dev_info(dev->dev,"Load eeprom OK, count %d byte\n",ret);
+
+	return 0;
+}
+
 static int mt76_get_of_eeprom_data(struct mt76_dev *dev, void *eep, int len)
 {
 #if defined(CONFIG_OF) && defined(CONFIG_MTD)
@@ -414,6 +414,7 @@
 	if (!dev->eeprom.data)
 		return -ENOMEM;
 
-	return !mt76_get_of_eeprom(dev, dev->eeprom.data, len);
+	return (!mt76_get_of_eeprom(dev, dev->eeprom.data, len)) || 
+	     (!mt76_get_eeprom_file(dev, dev->eeprom.data, len));
 }
 EXPORT_SYMBOL_GPL(mt76_eeprom_init);
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.