git: 66cc0c61b023 - main - cgem: rework hardware quirk detection

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Tue, 12 Apr 2022 22:52:10 UTC
The branch main has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=66cc0c61b023a5d8ae1c05897bfaf7726be40934

commit 66cc0c61b023a5d8ae1c05897bfaf7726be40934
Author:     Milan Obuch <bsd@dino.sk>
AuthorDate: 2022-04-07 12:57:25 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-04-12 22:51:17 +0000

    cgem: rework hardware quirk detection
    
    Rather than doing these checks based on the detected hardware variant, allow
    quirks to be specified as a set of flags for each compatible string.
    This simplifies adding support for new compatible hardware.
    
    Reviewed by:    mhorne
    MFC after:      1 week
    Sponsored by:   Conclusive Engineering
    Differential Revision:  https://reviews.freebsd.org/D34764
---
 sys/dev/cadence/if_cgem.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/sys/dev/cadence/if_cgem.c b/sys/dev/cadence/if_cgem.c
index 6b9d5a090aff..979ca524c624 100644
--- a/sys/dev/cadence/if_cgem.c
+++ b/sys/dev/cadence/if_cgem.c
@@ -100,18 +100,19 @@ __FBSDID("$FreeBSD$");
 #define CGEM_CKSUM_ASSIST	(CSUM_IP | CSUM_TCP | CSUM_UDP | \
 				 CSUM_TCP_IPV6 | CSUM_UDP_IPV6)
 
-#define HWTYPE_GENERIC_GEM	1
-#define HWTYPE_ZYNQ		2
-#define HWTYPE_ZYNQMP		3
-#define HWTYPE_SIFIVE		4
+#define HWQUIRK_NONE		0
+#define HWQUIRK_NEEDNULLQS	1
+#define HWQUIRK_RXHANGWAR	2
+#define HWQUIRK_TXCLK		4
+#define HWQUIRK_PCLK		8
 
 static struct ofw_compat_data compat_data[] = {
-	{ "cdns,zynq-gem",		HWTYPE_ZYNQ },
-	{ "cdns,zynqmp-gem",		HWTYPE_ZYNQMP },
-	{ "sifive,fu540-c000-gem",	HWTYPE_SIFIVE },
-	{ "sifive,fu740-c000-gem",	HWTYPE_SIFIVE },
-	{ "cdns,gem",			HWTYPE_GENERIC_GEM },
-	{ "cadence,gem",		HWTYPE_GENERIC_GEM },
+	{ "cdns,zynq-gem",		HWQUIRK_RXHANGWAR | HWQUIRK_TXCLK },
+	{ "cdns,zynqmp-gem",		HWQUIRK_NEEDNULLQS | HWQUIRK_TXCLK },
+	{ "sifive,fu540-c000-gem",	HWQUIRK_PCLK },
+	{ "sifive,fu740-c000-gem",	HWQUIRK_PCLK },
+	{ "cdns,gem",			HWQUIRK_NONE },
+	{ "cadence,gem",		HWQUIRK_NONE },
 	{ NULL,				0 }
 };
 
@@ -1712,7 +1713,7 @@ cgem_probe(device_t dev)
 	if (!ofw_bus_status_okay(dev))
 		return (ENXIO);
 
-	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
+	if (ofw_bus_search_compatible(dev, compat_data)->ocd_str == NULL)
 		return (ENXIO);
 
 	device_set_desc(dev, "Cadence CGEM Gigabit Ethernet Interface");
@@ -1726,25 +1727,25 @@ cgem_attach(device_t dev)
 	if_t ifp = NULL;
 	int rid, err;
 	u_char eaddr[ETHER_ADDR_LEN];
-	int hwtype;
+	int hwquirks;
 
 	sc->dev = dev;
 	CGEM_LOCK_INIT(sc);
 
 	/* Key off of compatible string and set hardware-specific options. */
-	hwtype = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
-	if (hwtype == HWTYPE_ZYNQMP)
+	hwquirks = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
+	if ((hwquirks & HWQUIRK_NEEDNULLQS) != 0)
 		sc->neednullqs = 1;
-	if (hwtype == HWTYPE_ZYNQ)
+	if ((hwquirks & HWQUIRK_RXHANGWAR) != 0)
 		sc->rxhangwar = 1;
-
-	if (hwtype == HWTYPE_ZYNQ || hwtype == HWTYPE_ZYNQMP) {
+	if ((hwquirks & HWQUIRK_TXCLK) != 0) {
 		if (clk_get_by_ofw_name(dev, 0, "tx_clk", &sc->ref_clk) != 0)
 			device_printf(dev,
 			    "could not retrieve reference clock.\n");
 		else if (clk_enable(sc->ref_clk) != 0)
 			device_printf(dev, "could not enable clock.\n");
-	} else if (hwtype == HWTYPE_SIFIVE) {
+	}
+	if ((hwquirks & HWQUIRK_PCLK) != 0) {
 		if (clk_get_by_ofw_name(dev, 0, "pclk", &sc->ref_clk) != 0)
 			device_printf(dev,
 			    "could not retrieve reference clock.\n");