Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Sep 2024 00:20:34 GMT
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 7728586800bd - main - mt76: add mt7615 to the pile of buildable drivers
Message-ID:  <202409130020.48D0KYJc048364@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=7728586800bd5bb4655cff6d661133ed10cc2ff7

commit 7728586800bd5bb4655cff6d661133ed10cc2ff7
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-09-04 18:38:05 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2024-09-13 00:18:02 +0000

    mt76: add mt7615 to the pile of buildable drivers
    
    Ignoring page_pools with the few needed adjustments and ignoring 7622
    mt7615 seems to build as well.  Add it so once we can connect it to
    the build people can start testing and debugging.
    (The actual work was done on a newer version of the mt76 drivers but
    it seems the to-build-changes equally apply here already).
    
    Requested by:   Radu-Cristian Fotescu (freebsd-wireless, 2024-07-31)
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
---
 sys/contrib/dev/mediatek/mt76/mt7615/eeprom.c   | 15 ++++++++++++++
 sys/contrib/dev/mediatek/mt76/mt7615/init.c     |  6 ++++++
 sys/contrib/dev/mediatek/mt76/mt7615/mac.c      | 11 +++++++++++
 sys/contrib/dev/mediatek/mt76/mt7615/mcu.c      |  4 ++++
 sys/contrib/dev/mediatek/mt76/mt7615/pci_init.c |  5 +++++
 sys/contrib/dev/mediatek/mt76/mt7615/pci_mac.c  |  3 +++
 sys/modules/mt76/Makefile                       |  1 +
 sys/modules/mt76/mt7615/Makefile                | 26 +++++++++++++++++++++++++
 8 files changed, 71 insertions(+)

diff --git a/sys/contrib/dev/mediatek/mt76/mt7615/eeprom.c b/sys/contrib/dev/mediatek/mt76/mt7615/eeprom.c
index ccedea7e8a50..d5ec498aa9ef 100644
--- a/sys/contrib/dev/mediatek/mt76/mt7615/eeprom.c
+++ b/sys/contrib/dev/mediatek/mt76/mt7615/eeprom.c
@@ -6,6 +6,9 @@
  */
 
 #include <linux/of.h>
+#if defined(__FreeBSD__)
+#include <linux/delay.h>
+#endif
 #include "mt7615.h"
 #include "eeprom.h"
 
@@ -63,7 +66,11 @@ static int mt7615_efuse_init(struct mt7615_dev *dev, u32 base)
 	for (i = 0; i + 16 <= len; i += 16) {
 		int ret;
 
+#if defined(__linux__)
 		ret = mt7615_efuse_read(dev, base, i, buf + i);
+#elif defined(__FreeBSD__)
+		ret = mt7615_efuse_read(dev, base, i, (u8 *)buf + i);
+#endif
 		if (ret)
 			return ret;
 	}
@@ -256,6 +263,7 @@ int mt7615_eeprom_get_power_delta_index(struct mt7615_dev *dev,
 		return MT_EE_5G_RATE_POWER;
 }
 
+#if defined(__linux__)
 static void mt7615_apply_cal_free_data(struct mt7615_dev *dev)
 {
 	static const u16 ical[] = {
@@ -311,9 +319,11 @@ static void mt7622_apply_cal_free_data(struct mt7615_dev *dev)
 		eeprom[ical[i]] = otp[ical[i]];
 	}
 }
+#endif
 
 static void mt7615_cal_free_data(struct mt7615_dev *dev)
 {
+#if defined(__linux__)
 	struct device_node *np = dev->mt76.dev->of_node;
 
 	if (!np || !of_property_read_bool(np, "mediatek,eeprom-merge-otp"))
@@ -328,6 +338,7 @@ static void mt7615_cal_free_data(struct mt7615_dev *dev)
 		mt7615_apply_cal_free_data(dev);
 		break;
 	}
+#endif
 }
 
 int mt7615_eeprom_init(struct mt7615_dev *dev, u32 addr)
@@ -348,7 +359,11 @@ int mt7615_eeprom_init(struct mt7615_dev *dev, u32 addr)
 	}
 
 	mt7615_eeprom_parse_hw_cap(dev);
+#if defined(__linux__)
 	memcpy(dev->mphy.macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
+#elif defined(__FreeBSD__)
+	memcpy(dev->mphy.macaddr, (u8 *)dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
+#endif
 	       ETH_ALEN);
 
 	mt76_eeprom_override(&dev->mphy);
diff --git a/sys/contrib/dev/mediatek/mt76/mt7615/init.c b/sys/contrib/dev/mediatek/mt76/mt7615/init.c
index 18a50ccff106..517a9ec9e07f 100644
--- a/sys/contrib/dev/mediatek/mt76/mt7615/init.c
+++ b/sys/contrib/dev/mediatek/mt76/mt7615/init.c
@@ -15,6 +15,7 @@
 #include "mcu.h"
 #include "eeprom.h"
 
+#if defined(__linux__)
 static ssize_t mt7615_thermal_show_temp(struct device *dev,
 					struct device_attribute *attr,
 					char *buf)
@@ -64,6 +65,7 @@ int mt7615_thermal_init(struct mt7615_dev *dev)
 	return 0;
 }
 EXPORT_SYMBOL_GPL(mt7615_thermal_init);
+#endif
 
 static void
 mt7615_phy_init(struct mt7615_dev *dev)
@@ -566,7 +568,11 @@ int mt7615_register_ext_phy(struct mt7615_dev *dev)
 	 * Make the secondary PHY MAC address local without overlapping with
 	 * the usual MAC address allocation scheme on multiple virtual interfaces
 	 */
+#if defined(__linux__)
 	memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
+#elif defined(__FreeBSD__)
+	memcpy(mphy->macaddr, (u8 *)dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
+#endif
 	       ETH_ALEN);
 	mphy->macaddr[0] |= 2;
 	mphy->macaddr[0] ^= BIT(7);
diff --git a/sys/contrib/dev/mediatek/mt76/mt7615/mac.c b/sys/contrib/dev/mediatek/mt76/mt7615/mac.c
index 7ba789834e8d..5037104ed1a4 100644
--- a/sys/contrib/dev/mediatek/mt76/mt7615/mac.c
+++ b/sys/contrib/dev/mediatek/mt76/mt7615/mac.c
@@ -10,6 +10,9 @@
 #include <linux/devcoredump.h>
 #include <linux/etherdevice.h>
 #include <linux/timekeeping.h>
+#if defined(__FreeBSD__)
+#include <linux/delay.h>
+#endif
 #include "mt7615.h"
 #include "../trace.h"
 #include "../dma.h"
@@ -1575,9 +1578,17 @@ mt7615_mac_tx_free_token(struct mt7615_dev *dev, u16 token)
 	mt7615_txwi_free(dev, txwi);
 }
 
+#if defined(__linux__)
 static void mt7615_mac_tx_free(struct mt7615_dev *dev, void *data, int len)
+#elif defined(__FreeBSD__)
+static void mt7615_mac_tx_free(struct mt7615_dev *dev, u8 *data, int len)
+#endif
 {
+#if defined(__linux__)
 	struct mt76_connac_tx_free *free = data;
+#elif defined(__FreeBSD__)
+	struct mt76_connac_tx_free *free = (void *)data;
+#endif
 	void *tx_token = data + sizeof(*free);
 	void *end = data + len;
 	u8 i, count;
diff --git a/sys/contrib/dev/mediatek/mt76/mt7615/mcu.c b/sys/contrib/dev/mediatek/mt76/mt7615/mcu.c
index 8d745c9730c7..704faf50f4f9 100644
--- a/sys/contrib/dev/mediatek/mt76/mt7615/mcu.c
+++ b/sys/contrib/dev/mediatek/mt76/mt7615/mcu.c
@@ -232,9 +232,13 @@ void mt7622_trigger_hif_int(struct mt7615_dev *dev, bool en)
 	if (!is_mt7622(&dev->mt76))
 		return;
 
+#if defined(__linux__)
 	regmap_update_bits(dev->infracfg, MT_INFRACFG_MISC,
 			   MT_INFRACFG_MISC_AP2CONN_WAKE,
 			   !en * MT_INFRACFG_MISC_AP2CONN_WAKE);
+#elif defined(__FreeBSD__)
+	panic("%s: LinuxKPI needs regmap\n", __func__);
+#endif
 }
 EXPORT_SYMBOL_GPL(mt7622_trigger_hif_int);
 
diff --git a/sys/contrib/dev/mediatek/mt76/mt7615/pci_init.c b/sys/contrib/dev/mediatek/mt76/mt7615/pci_init.c
index f607eee3fb47..68f628c6f24e 100644
--- a/sys/contrib/dev/mediatek/mt76/mt7615/pci_init.c
+++ b/sys/contrib/dev/mediatek/mt76/mt7615/pci_init.c
@@ -8,6 +8,9 @@
  */
 
 #include <linux/etherdevice.h>
+#if defined(__FreeBSD__)
+#include <linux/delay.h>
+#endif
 #include "mt7615.h"
 #include "mac.h"
 #include "eeprom.h"
@@ -92,9 +95,11 @@ int mt7615_register_device(struct mt7615_dev *dev)
 	if (ret)
 		return ret;
 
+#if defined(__linux__)
 	ret = mt7615_thermal_init(dev);
 	if (ret)
 		return ret;
+#endif
 
 	ieee80211_queue_work(mt76_hw(dev), &dev->mcu_work);
 	mt7615_init_txpower(dev, &dev->mphy.sband_2g.sband);
diff --git a/sys/contrib/dev/mediatek/mt76/mt7615/pci_mac.c b/sys/contrib/dev/mediatek/mt76/mt7615/pci_mac.c
index 0019890fdb78..fe6bd71c7d97 100644
--- a/sys/contrib/dev/mediatek/mt76/mt7615/pci_mac.c
+++ b/sys/contrib/dev/mediatek/mt76/mt7615/pci_mac.c
@@ -9,6 +9,9 @@
 
 #include <linux/etherdevice.h>
 #include <linux/timekeeping.h>
+#if defined(__FreeBSD__)
+#include <linux/delay.h>
+#endif
 
 #include "mt7615.h"
 #include "../dma.h"
diff --git a/sys/modules/mt76/Makefile b/sys/modules/mt76/Makefile
index fbc9265c9127..f75427acf4f5 100644
--- a/sys/modules/mt76/Makefile
+++ b/sys/modules/mt76/Makefile
@@ -1,4 +1,5 @@
 SUBDIR=		core
+SUBDIR+=	mt7615
 SUBDIR+=	mt7915
 SUBDIR+=	mt7921
 SUBDIR+=	mt7996
diff --git a/sys/modules/mt76/mt7615/Makefile b/sys/modules/mt76/mt7615/Makefile
new file mode 100644
index 000000000000..6d7cb945a32d
--- /dev/null
+++ b/sys/modules/mt76/mt7615/Makefile
@@ -0,0 +1,26 @@
+DEVDIR=	${SRCTOP}/sys/contrib/dev/mediatek/mt76/mt7615
+
+.PATH: ${DEVDIR}
+
+WITH_DEBUGFS=		0
+WITH_DEV_COREDUMP=	0
+
+KMOD=	if_mt7615
+
+# Common stuff.
+SRCS=	init.c main.c mac.c mcu.c eeprom.c
+
+# PCIe  (7622_WMAC ignored)
+SRCS+=	dma.c mmio.c pci.c pci_init.c pci_mac.c
+
+# USB + SDIO ignored currently.
+
+.if defined(WITH_DEBUGFS) && ${WITH_DEBUGFS} > 0
+SRCS+=	debugfs.c
+CFLAGS+=	-DCONFIG_MT7915_DEBUGFS=${WITH_DEBUGFS}
+.endif
+
+CFLAGS+=	-DKBUILD_MODNAME='"mt7615"'
+CFLAGS+=	-I${DEVDIR}
+
+.include <bsd.kmod.mk>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202409130020.48D0KYJc048364>