Module Name:    src
Committed By:   skrll
Date:           Sun Aug 25 07:25:00 UTC 2024

Modified Files:
        src/sys/arch/arm/xilinx: zynq_cemac.c
        src/sys/dev/cadence: if_cemac.c if_cemacvar.h

Log Message:
Re-organise to enable other attachments.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/xilinx/zynq_cemac.c
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/cadence/if_cemac.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/cadence/if_cemacvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/xilinx/zynq_cemac.c
diff -u src/sys/arch/arm/xilinx/zynq_cemac.c:1.8 src/sys/arch/arm/xilinx/zynq_cemac.c:1.9
--- src/sys/arch/arm/xilinx/zynq_cemac.c:1.8	Sun Aug 25 07:19:57 2024
+++ src/sys/arch/arm/xilinx/zynq_cemac.c	Sun Aug 25 07:25:00 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: zynq_cemac.c,v 1.8 2024/08/25 07:19:57 skrll Exp $	*/
+/*	$NetBSD: zynq_cemac.c,v 1.9 2024/08/25 07:25:00 skrll Exp $	*/
 /*-
  * Copyright (c) 2015  Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi for Genetec Corporation.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: zynq_cemac.c,v 1.8 2024/08/25 07:19:57 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: zynq_cemac.c,v 1.9 2024/08/25 07:25:00 skrll Exp $");
 
 #include <sys/param.h>
 
@@ -47,7 +47,7 @@ static const struct device_compatible_en
 	DEVICE_COMPAT_EOL
 };
 
-int
+static int
 cemac_match(device_t parent, cfdata_t cfdata, void *aux)
 {
 	struct fdt_attach_args * const faa = aux;
@@ -55,13 +55,13 @@ cemac_match(device_t parent, cfdata_t cf
 	return of_compatible_match(faa->faa_phandle, compat_data);
 }
 
-void
+static void
 cemac_attach(device_t parent, device_t self, void *aux)
 {
 	struct fdt_attach_args * const faa = aux;
+	struct cemac_softc *sc = device_private(self);
 	const int phandle = faa->faa_phandle;
 	prop_dictionary_t prop = device_properties(self);
-	bus_space_handle_t ioh;
 	char intrstr[128];
 	const char *macaddr;
 	bus_addr_t addr;
@@ -73,7 +73,7 @@ cemac_attach(device_t parent, device_t s
 		return;
 	}
 
-	error = bus_space_map(faa->faa_bst, addr, size, 0, &ioh);
+	error = bus_space_map(faa->faa_bst, addr, size, 0, &sc->sc_ioh);
 	if (error) {
 		aprint_error(": failed to map register %#lx@%#lx: %d\n",
 		    size, addr, error);
@@ -97,8 +97,15 @@ cemac_attach(device_t parent, device_t s
 		prop_dictionary_set_data(prop, "mac-address", macaddr, len);
 	}
 
-	cemac_attach_common(self, faa->faa_bst, ioh, faa->faa_dmat,
-	    CEMAC_FLAG_GEM);
+	sc->sc_dev = self;
+	sc->sc_iot = faa->faa_bst;
+	sc->sc_dmat = faa->faa_dmat;
+	sc->cemac_flags = CEMAC_FLAG_GEM;
+
+	cemac_attach_common(sc);
 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 }
 
+
+CFATTACH_DECL_NEW(cemac, sizeof(struct cemac_softc),
+    cemac_match, cemac_attach, NULL, NULL);

Index: src/sys/dev/cadence/if_cemac.c
diff -u src/sys/dev/cadence/if_cemac.c:1.32 src/sys/dev/cadence/if_cemac.c:1.33
--- src/sys/dev/cadence/if_cemac.c:1.32	Sat Aug 24 11:55:45 2024
+++ src/sys/dev/cadence/if_cemac.c	Sun Aug 25 07:25:00 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_cemac.c,v 1.32 2024/08/24 11:55:45 skrll Exp $	*/
+/*	$NetBSD: if_cemac.c,v 1.33 2024/08/25 07:25:00 skrll Exp $	*/
 
 /*
  * Copyright (c) 2015  Genetec Corporation.  All rights reserved.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cemac.c,v 1.32 2024/08/24 11:55:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cemac.c,v 1.33 2024/08/25 07:25:00 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -87,44 +87,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_cemac.c,v
 			bus_space_write_4(sc->sc_iot, sc->sc_ioh, (ETH_##x), (y)); \
 	} while(0)
 
-#define RX_QLEN 64
-#define	TX_QLEN	2		/* I'm very sorry but that's where we can get */
-
-struct cemac_qmeta {
-	struct mbuf	*m;
-	bus_dmamap_t	m_dmamap;
-};
-
-struct cemac_softc {
-	device_t		sc_dev;
-	bus_space_tag_t		sc_iot;
-	bus_space_handle_t	sc_ioh;
-	bus_dma_tag_t		sc_dmat;
-	uint8_t			sc_enaddr[ETHER_ADDR_LEN];
-	struct ethercom		sc_ethercom;
-	mii_data_t		sc_mii;
-
-	void			*rbqpage;
-	unsigned		rbqlen;
-	bus_addr_t		rbqpage_dsaddr;
-	bus_dmamap_t		rbqpage_dmamap;
-	void			*tbqpage;
-	unsigned		tbqlen;
-	bus_addr_t		tbqpage_dsaddr;
-	bus_dmamap_t		tbqpage_dmamap;
-
-	volatile struct eth_dsc *RDSC;
-	int			rxqi;
-	struct cemac_qmeta	rxq[RX_QLEN];
-	volatile struct eth_dsc *TDSC;
-	int			txqi, txqc;
-	struct cemac_qmeta	txq[TX_QLEN];
-	callout_t		cemac_tick_ch;
-	bool			tx_busy;
-
-	int			cemac_flags;
-};
-
 static void	cemac_init(struct cemac_softc *);
 static int	cemac_gctx(struct cemac_softc *);
 static int	cemac_mediachange(struct ifnet *);
@@ -147,24 +109,10 @@ int cemac_debug = CEMAC_DEBUG;
 #define	DPRINTFN(n, fmt)
 #endif
 
-CFATTACH_DECL_NEW(cemac, sizeof(struct cemac_softc),
-    cemac_match, cemac_attach, NULL, NULL);
-
-
 void
-cemac_attach_common(device_t self, bus_space_tag_t iot,
-    bus_space_handle_t ioh, bus_dma_tag_t dmat, int flags)
+cemac_attach_common(struct cemac_softc *sc)
 {
-	struct cemac_softc	*sc = device_private(self);
-	prop_data_t		enaddr;
-	uint32_t		u;
-
-
-	sc->sc_dev = self;
-	sc->sc_ioh = ioh;
-	sc->sc_iot = iot;
-	sc->sc_dmat = dmat;
-	sc->cemac_flags = flags;
+	uint32_t u;
 
 	aprint_naive("\n");
 	if (ISSET(sc->cemac_flags, CEMAC_FLAG_GEM))
@@ -193,7 +141,8 @@ cemac_attach_common(device_t self, bus_s
 	CEMAC_WRITE(ETH_RSR, (u & (ETH_RSR_OVR | ETH_RSR_REC | ETH_RSR_BNA)));
 
 	/* Fetch the Ethernet address from property if set. */
-	enaddr = prop_dictionary_get(device_properties(self), "mac-address");
+	prop_dictionary_t prop = device_properties(sc->sc_dev);
+	prop_data_t enaddr = prop_dictionary_get(prop, "mac-address");
 
 	if (enaddr != NULL) {
 		KASSERT(prop_object_type(enaddr) == PROP_TYPE_DATA);

Index: src/sys/dev/cadence/if_cemacvar.h
diff -u src/sys/dev/cadence/if_cemacvar.h:1.3 src/sys/dev/cadence/if_cemacvar.h:1.4
--- src/sys/dev/cadence/if_cemacvar.h:1.3	Sat Aug 24 10:13:19 2024
+++ src/sys/dev/cadence/if_cemacvar.h	Sun Aug 25 07:25:00 2024
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_cemacvar.h,v 1.3 2024/08/24 10:13:19 skrll Exp $	*/
+/*      $NetBSD: if_cemacvar.h,v 1.4 2024/08/25 07:25:00 skrll Exp $	*/
 /*-
  * Copyright (c) 2015  Genetec Corporation.  All rights reserved.
  * Written by Hashimoto Kenichi for Genetec Corporation.
@@ -28,13 +28,55 @@
 #ifndef _IF_CEMACVAR_H_
 #define _IF_CEMACVAR_H_
 
-int cemac_match(device_t, cfdata_t, void *);
-void cemac_attach(device_t, device_t, void *);
+#include <net/if.h>
+#include <net/if_media.h>
+#include <net/if_ether.h>
+#include <net/if_media.h>
+
+#include <dev/mii/miivar.h>
+
+#define	RX_QLEN 64
+#define	TX_QLEN	2		/* I'm very sorry but that's where we can get */
+
+struct cemac_qmeta {
+	struct mbuf	*m;
+	bus_dmamap_t	m_dmamap;
+};
+
+struct cemac_softc {
+	device_t		sc_dev;
+	bus_space_tag_t		sc_iot;
+	bus_space_handle_t	sc_ioh;
+	bus_dma_tag_t		sc_dmat;
+	uint8_t			sc_enaddr[ETHER_ADDR_LEN];
+	struct ethercom		sc_ethercom;
+	mii_data_t		sc_mii;
+
+	void			*rbqpage;
+	unsigned		rbqlen;
+	bus_addr_t		rbqpage_dsaddr;
+	bus_dmamap_t		rbqpage_dmamap;
+	void			*tbqpage;
+	unsigned		tbqlen;
+	bus_addr_t		tbqpage_dsaddr;
+	bus_dmamap_t		tbqpage_dmamap;
+
+	volatile struct eth_dsc *RDSC;
+	int			rxqi;
+	struct cemac_qmeta	rxq[RX_QLEN];
+	volatile struct eth_dsc *TDSC;
+	int			txqi, txqc;
+	struct cemac_qmeta	txq[TX_QLEN];
+	callout_t		cemac_tick_ch;
+	bool			tx_busy;
+
+	unsigned		cemac_flags;
+#define CEMAC_FLAG_GEM	__BIT(0)
+};
+
 int cemac_intr(void *);
 
-void cemac_attach_common(device_t, bus_space_tag_t, bus_space_handle_t,
-    bus_dma_tag_t, int);
+void cemac_attach_common(struct cemac_softc *);
 
-#define CEMAC_FLAG_GEM	0x0001
 
 #endif /* _IF_CEMACVAR_H_ */

Reply via email to