CVS commit: src/sys/arch/arm/sociox

2024-06-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 29 11:27:12 UTC 2024

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
scx(4): Fix if_statinc call.

We don't have a reference to the local statistics counters, so we
can't use if_statinc_ref.  But, because net_stat_ref_t is just an
alias for void *, the compiler doesn't detect this mistake.

PR kern/58380


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.43 src/sys/arch/arm/sociox/if_scx.c:1.44
--- src/sys/arch/arm/sociox/if_scx.c:1.43	Thu Jun 15 07:21:45 2023
+++ src/sys/arch/arm/sociox/if_scx.c	Sat Jun 29 11:27:12 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.43 2023/06/15 07:21:45 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.44 2024/06/29 11:27:12 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.43 2023/06/15 07:21:45 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.44 2024/06/29 11:27:12 riastradh Exp $");
 
 #include 
 #include 
@@ -1399,7 +1399,7 @@ scx_start(struct ifnet *ifp)
 "DMA segments, dropping...\n");
 IFQ_DEQUEUE(>if_snd, m0);
 m_freem(m0);
-if_statinc_ref(ifp, if_oerrors);
+if_statinc(ifp, if_oerrors);
 continue;
 			}
 			/* Short on resources, just stop for now. */



CVS commit: src/sys/arch/arm/sociox

2024-06-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 29 11:27:12 UTC 2024

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
scx(4): Fix if_statinc call.

We don't have a reference to the local statistics counters, so we
can't use if_statinc_ref.  But, because net_stat_ref_t is just an
alias for void *, the compiler doesn't detect this mistake.

PR kern/58380


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2023-06-15 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Jun 15 07:21:45 UTC 2023

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
if_scx.c


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.42 src/sys/arch/arm/sociox/if_scx.c:1.43
--- src/sys/arch/arm/sociox/if_scx.c:1.42	Wed Jun 14 00:07:22 2023
+++ src/sys/arch/arm/sociox/if_scx.c	Thu Jun 15 07:21:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.42 2023/06/14 00:07:22 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.43 2023/06/15 07:21:45 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.42 2023/06/14 00:07:22 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.43 2023/06/15 07:21:45 nisimura Exp $");
 
 #include 
 #include 
@@ -120,13 +120,6 @@ struct rdes {
 #define COMINIT		0x120
 #define  INIT_DB	(1U<<2)		/* ???; self clear when done */
 #define  INIT_CLS	(1U<<1)		/* ???; self clear when done */
-#define PKTCTRL		0x140		/* pkt engine control */
-#define  MODENRM	(1U<<28)	/* set operational mode to 'normal' */
-#define  ENJUMBO	(1U<<27)	/* allow jumbo frame */
-#define  RPTCSUMERR	(1U<<3)		/* log Rx checksum error */
-#define  RPTHDCOMP	(1U<<2)		/* log header incomplete condition */
-#define  RPTHDERR	(1U<<1)		/* log header error */
-#define  DROPNOMATCH	(1U<<0)		/* drop no match frames */
 #define xINTSR		0x200		/* aggregated interrupt status */
 #define  IRQ_UCODE	(1U<<20)	/* ucode load completed; W1C */
 #define  IRQ_MAC	(1U<<19)	/* ??? */
@@ -146,14 +139,14 @@ struct rdes {
 #define TXIE_SET	0x428		/* bit to set */
 #define TXIE_CLR	0x42c		/* bit to clr */
 #define  TXI_NTOWNR	(1U<<17)	/* ??? desc array got empty */
-#define  TXI_TR_ERR	(1U<<16)	/* xmit error */
+#define  TXI_TR_ERR	(1U<<16)	/* xmit error detected */
 #define  TXI_TXDONE	(1U<<15)	/* xmit completed */
 #define  TXI_TMREXP	(1U<<14)	/* coalesce guard timer expired */
 #define RXISR		0x440		/* receive status; W1C */
 #define RXIEN		0x444		/* rx interrupt enable */
 #define RXIE_SET	0x468		/* bit to set */
 #define RXIE_CLR	0x46c		/* bit to clr */
-#define  RXI_RC_ERR	(1U<<16)	/* recv error */
+#define  RXI_RC_ERR	(1U<<16)	/* recv error detected */
 #define  RXI_PKTCNT	(1U<<15)	/* recv counter has new value */
 #define  RXI_TMREXP	(1U<<14)	/* coalesce guard timer expired */
 #define TDBA_LO		0x408		/* tdes array base addr 31:0 */
@@ -164,16 +157,24 @@ struct rdes {
 #define RXCONF		0x470		/* rdes config */
 #define  DESCNF_UP	(1U<<31)	/* 'up-and-running' */
 #define  DESCNF_CHRST	(1U<<30)	/* channel reset */
-#define  DESCNF_TMR	(1U<<4)		/* coalesce timer mode select */
+#define  DESCNF_TMR	(1U<<4)		/* coalesce timer unit select */
 #define  DESCNF_LE	(1)		/* little endian desc format */
 #define TXSUBMIT	0x410		/* submit frame(s) to transmit */
 #define TXCOALESC	0x418		/* tx intr coalesce upper bound */
 #define RXCOALESC	0x458		/* rx intr coalesce upper bound */
-#define TCLSCTIME	0x420		/* tintr guard time usec, MSB to on */
-#define RCLSCTIME	0x460		/* rintr guard time usec, MSB to on */
+#define TCLSCTIME	0x420		/* tintr guard time usec */
+#define RCLSCTIME	0x460		/* rintr guard time usec */
 #define TXDONECNT	0x414		/* tx completed count, auto-zero */
 #define RXAVAILCNT	0x454		/* rx available count, auto-zero */
-#define DMACTL_TMR	0x20c		/* engine DMA timer value */
+#define DMACTL_TMR	0x20c		/* DMA cycle tick value */
+#define PKTCTRL		0x140		/* pkt engine control */
+#define  MODENRM	(1U<<28)	/* set operational mode to 'normal' */
+#define  ENJUMBO	(1U<<27)	/* allow jumbo frame */
+#define  RPTCSUMERR	(1U<<3)		/* log Rx checksum error */
+#define  RPTHDCOMP	(1U<<2)		/* log header incomplete condition */
+#define  RPTHDERR	(1U<<1)		/* log header error */
+#define  DROPNOMATCH	(1U<<0)		/* drop no match frames */
+#define UCODE_PKT	0x0d0		/* packet engine ucode port */
 #define UCODE_H2M	0x210		/* host2media engine ucode port */
 #define UCODE_M2H	0x21c		/* media2host engine ucode port */
 #define CORESTAT	0x218		/* engine run state */
@@ -184,11 +185,15 @@ struct rdes {
 #define DMACTL_M2H	0x220		/* media2host engine control */
 #define  DMACTL_STOP	(1U<<0)		/* instruct stop; self-clear */
 #define  M2H_MODE_TRANS	(1U<<20)	/* initiate M2H mode change */
-#define UCODE_PKT	0x0d0		/* packet engine ucode port */
+#define MODE_TRANS	0x500		/* mode change completion status */
+#define  N2T_DONE	(1U<<20)	/* normal->taiki change completed */
+#define  T2N_DONE	(1U<<19)	/* taiki->normal change completed */
 #define CLKEN		0x100		/* clock distribution enable */
 #define  CLK_G		(1U<<5)		/* feed clk domain G */
 #define  CLK_C		(1U<<1)		/* feed clk domain C */
 #define  CLK_D		(1U<<0)		/* 

CVS commit: src/sys/arch/arm/sociox

2023-06-15 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Jun 15 07:21:45 UTC 2023

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
if_scx.c


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2023-06-13 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Jun 14 00:07:22 UTC 2023

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
force PHY loopback while uengine reloading process as tianocore/EDK2 UEFI
mentions.  A piece of comment updates.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.41 src/sys/arch/arm/sociox/if_scx.c:1.42
--- src/sys/arch/arm/sociox/if_scx.c:1.41	Tue Jun 13 00:15:52 2023
+++ src/sys/arch/arm/sociox/if_scx.c	Wed Jun 14 00:07:22 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.41 2023/06/13 00:15:52 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.42 2023/06/14 00:07:22 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.41 2023/06/13 00:15:52 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.42 2023/06/14 00:07:22 nisimura Exp $");
 
 #include 
 #include 
@@ -156,14 +156,12 @@ struct rdes {
 #define  RXI_RC_ERR	(1U<<16)	/* recv error */
 #define  RXI_PKTCNT	(1U<<15)	/* recv counter has new value */
 #define  RXI_TMREXP	(1U<<14)	/* coalesce guard timer expired */
-/* 13 sets of special purpose desc interrupt handling register exist */
 #define TDBA_LO		0x408		/* tdes array base addr 31:0 */
 #define TDBA_HI		0x434		/* tdes array base addr 63:32 */
 #define RDBA_LO		0x448		/* rdes array base addr 31:0 */
 #define RDBA_HI		0x474		/* rdes array base addr 63:32 */
-/* 13 pairs of special purpose desc array base address register exist */
-#define TXCONF		0x430
-#define RXCONF		0x470
+#define TXCONF		0x430		/* tdes config */
+#define RXCONF		0x470		/* rdes config */
 #define  DESCNF_UP	(1U<<31)	/* 'up-and-running' */
 #define  DESCNF_CHRST	(1U<<30)	/* channel reset */
 #define  DESCNF_TMR	(1U<<4)		/* coalesce timer mode select */
@@ -197,8 +195,8 @@ struct rdes {
 #define MACCMD		0x11c4		/* gmac register operation */
 #define  CMD_IOWR	(1U<<28)	/* write op */
 #define  CMD_BUSY	(1U<<31)	/* busy bit */
-#define MACSTAT		0x1024		/* gmac status; ??? */
-#define MACINTE		0x1028		/* interrupt enable; ??? */
+#define MACSTAT		0x1024		/* mac interrupt status (unused) */
+#define MACINTE		0x1028		/* mac interrupt enable (unused) */
 
 #define FLOWTHR		0x11cc		/* flow control threshold */
 /* 31:16 pause threshold, 15:0 resume threshold */
@@ -212,8 +210,6 @@ struct rdes {
 #define MODE_TRANS	0x500		/* mode change completion status */
 #define  N2T_DONE	(1U<<20)	/* normal->taiki change completed */
 #define  T2N_DONE	(1U<<19)	/* taiki->normal change completed */
-#define MACADRH		0x10c		/* ??? */
-#define MACADRL		0x110		/* ??? */
 #define MCVER		0x22c		/* micro controller version */
 #define HWVER		0x230		/* hardware version */
 
@@ -247,7 +243,7 @@ struct rdes {
 #define  AFR_HPF	(1U<<10)	/* hash+perfect filter, or hash only */
 #define  AFR_SAF	(1U<<9)		/* source address filter */
 #define  AFR_SAIF	(1U<<8)		/* SA inverse filtering */
-#define  AFR_PCF	(2U<<6)		/* ??? */
+#define  AFR_PCF	(2U<<6)		/* 7:6 accept pause frame 0~3 */
 #define  AFR_DBF	(1U<<5)		/* reject broadcast frame */
 #define  AFR_PM		(1U<<4)		/* accept all multicast frame */
 #define  AFR_DAIF	(1U<<3)		/* DA inverse filtering */
@@ -585,6 +581,8 @@ static void dump_hwfeature(struct scx_so
 static void resetuengine(struct scx_softc *);
 static void loaducode(struct scx_softc *);
 static void injectucode(struct scx_softc *, int, bus_addr_t, bus_size_t);
+static void forcephyloopback(struct scx_softc *);
+static void resetphytonormal(struct scx_softc *);
 
 static int get_mdioclk(uint32_t);
 
@@ -997,7 +995,7 @@ aprint_normal_dev(sc->sc_dev, "descripto
 
 	/* 802.1Q VLAN-sized frames, and 9000 jumbo frame are supported */
 	sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
-	sc->sc_ethercom.ec_capabilities |= ETHERCAP_JUMBO_MTU;
+	/* sc->sc_ethercom.ec_capabilities |= ETHERCAP_JUMBO_MTU; not yet */
 
 	sc->sc_flowflags = 0; /* track PAUSE flow caps */
 
@@ -1025,12 +1023,24 @@ aprint_normal_dev(sc->sc_dev, "descripto
 	CSR_WRITE(sc, RXCONF, DESCNF_LE);	/* little endian */
 	CSR_WRITE(sc, DMACTL_TMR, sc->sc_freq / 100 - 1);
 
+	forcephyloopback(sc);/* make PHY loopback mode for uengine init */
+
+	CSR_WRITE(sc, xINTSR, IRQ_UCODE); /* pre-cautional W1C */
+	CSR_WRITE(sc, CORESTAT, 0);	  /* start uengine to reprogram */
+	error = WAIT_FOR_SET(sc, xINTSR, IRQ_UCODE);
+	if (error) {
+		aprint_error_dev(sc->sc_dev, "uengine start failed\n");
+	}
+	CSR_WRITE(sc, xINTSR, IRQ_UCODE); /* W1C load complete report */
+
+	resetphytonormal(sc); /* take back PHY to normal mode */
+
 	CSR_WRITE(sc, DMACTL_M2H, M2H_MODE_TRANS);
-	CSR_WRITE(sc, PKTCTRL, MODENRM);	/* change to use normal mode */
-	WAIT_FOR_SET(sc, MODE_TRANS, T2N_DONE);
-	/* do {

CVS commit: src/sys/arch/arm/sociox

2023-06-13 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Jun 14 00:07:22 UTC 2023

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
force PHY loopback while uengine reloading process as tianocore/EDK2 UEFI
mentions.  A piece of comment updates.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2023-06-12 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Jun 13 00:15:52 UTC 2023

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
major code quality improvements, descriptive comments, code density.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.40 src/sys/arch/arm/sociox/if_scx.c:1.41
--- src/sys/arch/arm/sociox/if_scx.c:1.40	Sun May 21 00:35:38 2023
+++ src/sys/arch/arm/sociox/if_scx.c	Tue Jun 13 00:15:52 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.40 2023/05/21 00:35:38 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.41 2023/06/13 00:15:52 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.40 2023/05/21 00:35:38 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.41 2023/06/13 00:15:52 nisimura Exp $");
 
 #include 
 #include 
@@ -75,7 +75,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #include 
 #include 
 
-/* SC2A11 GbE 64-bit paddr descriptor */
+/* SC2A11 GbE has 64-bit paddr descriptor */
 struct tdes {
 	uint32_t t0, t1, t2, t3;
 };
@@ -105,8 +105,9 @@ struct rdes {
 #define R0_TDRID	(12)		/* 15:12 target desc ring id */
 #define R0_FS		(1U<<9)		/* first segment of frame */
 #define R0_LS		(1U<<8)		/* last segment of frame */
-#define R0_CSUM		(3U<<6)		/* 7:6 checksum status */
-#define R0_CERR		(2U<<6)		/* 0: undone, 1: found ok, 2: bad */
+#define R0_CSUM		(3U<<6)		/* 7:6 checksum status, 0: undone */
+#define R0_CERR		(2U<<6)		/* 2: found bad */
+#define R0_COK		(1U<<6)		/* 1: found ok */
 /* R1 frame address 63:32 */
 /* R2 frame address 31:0 */
 /* R3 31:16 received frame length, 15:0 buffer length to receive */
@@ -120,11 +121,11 @@ struct rdes {
 #define  INIT_DB	(1U<<2)		/* ???; self clear when done */
 #define  INIT_CLS	(1U<<1)		/* ???; self clear when done */
 #define PKTCTRL		0x140		/* pkt engine control */
-#define  MODENRM	(1U<<28)	/* change mode to normal */
+#define  MODENRM	(1U<<28)	/* set operational mode to 'normal' */
 #define  ENJUMBO	(1U<<27)	/* allow jumbo frame */
 #define  RPTCSUMERR	(1U<<3)		/* log Rx checksum error */
-#define  RPTHDCOMP	(1U<<2)		/* log HD incomplete condition */
-#define  RPTHDERR	(1U<<1)		/* log HD error */
+#define  RPTHDCOMP	(1U<<2)		/* log header incomplete condition */
+#define  RPTHDERR	(1U<<1)		/* log header error */
 #define  DROPNOMATCH	(1U<<0)		/* drop no match frames */
 #define xINTSR		0x200		/* aggregated interrupt status */
 #define  IRQ_UCODE	(1U<<20)	/* ucode load completed; W1C */
@@ -145,16 +146,16 @@ struct rdes {
 #define TXIE_SET	0x428		/* bit to set */
 #define TXIE_CLR	0x42c		/* bit to clr */
 #define  TXI_NTOWNR	(1U<<17)	/* ??? desc array got empty */
-#define  TXI_TR_ERR	(1U<<16)	/* tx error */
-#define  TXI_TXDONE	(1U<<15)	/* tx completed */
-#define  TXI_TMREXP	(1U<<14)	/* coalesce timer expired */
+#define  TXI_TR_ERR	(1U<<16)	/* xmit error */
+#define  TXI_TXDONE	(1U<<15)	/* xmit completed */
+#define  TXI_TMREXP	(1U<<14)	/* coalesce guard timer expired */
 #define RXISR		0x440		/* receive status; W1C */
 #define RXIEN		0x444		/* rx interrupt enable */
 #define RXIE_SET	0x468		/* bit to set */
 #define RXIE_CLR	0x46c		/* bit to clr */
-#define  RXI_RC_ERR	(1U<<16)	/* rx error */
-#define  RXI_PKTCNT	(1U<<15)	/* rx counter has new value */
-#define  RXI_TMREXP	(1U<<14)	/* coalesce timer expired */
+#define  RXI_RC_ERR	(1U<<16)	/* recv error */
+#define  RXI_PKTCNT	(1U<<15)	/* recv counter has new value */
+#define  RXI_TMREXP	(1U<<14)	/* coalesce guard timer expired */
 /* 13 sets of special purpose desc interrupt handling register exist */
 #define TDBA_LO		0x408		/* tdes array base addr 31:0 */
 #define TDBA_HI		0x434		/* tdes array base addr 63:32 */
@@ -163,33 +164,33 @@ struct rdes {
 /* 13 pairs of special purpose desc array base address register exist */
 #define TXCONF		0x430
 #define RXCONF		0x470
-#define  DESCNF_UP	(1U<<31)	/* up-and-running */
+#define  DESCNF_UP	(1U<<31)	/* 'up-and-running' */
 #define  DESCNF_CHRST	(1U<<30)	/* channel reset */
 #define  DESCNF_TMR	(1U<<4)		/* coalesce timer mode select */
 #define  DESCNF_LE	(1)		/* little endian desc format */
 #define TXSUBMIT	0x410		/* submit frame(s) to transmit */
-#define TXCLSCMAX	0x418		/* tx intr coalesce upper bound */
-#define RXCLSCMAX	0x458		/* rx intr coalesce upper bound */
-#define TXITIMER	0x420		/* coalesce timer usec, MSB to use */
-#define RXITIMER	0x460		/* coalesce timer usec, MSB to use */
+#define TXCOALESC	0x418		/* tx intr coalesce upper bound */
+#define RXCOALESC	0x458		/* rx intr coalesce upper bound */
+#define TCLSCTIME	0x420		/* tintr guard time usec, MSB to on */
+#define RCLSCTIME	0x460		/* rintr guard time usec, MSB to on */
 

CVS commit: src/sys/arch/arm/sociox

2023-06-12 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Jun 13 00:15:52 UTC 2023

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
major code quality improvements, descriptive comments, code density.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2023-05-20 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Sun May 21 00:35:38 UTC 2023

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
small fixes, code shuffle for ease of understanding.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.39 src/sys/arch/arm/sociox/if_scx.c:1.40
--- src/sys/arch/arm/sociox/if_scx.c:1.39	Tue Sep 27 06:36:43 2022
+++ src/sys/arch/arm/sociox/if_scx.c	Sun May 21 00:35:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.39 2022/09/27 06:36:43 skrll Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.40 2023/05/21 00:35:38 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,6 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#define NOT_MP_SAFE	0
 
 /*
  * Socionext SC2A11 SynQuacer NetSec GbE driver
@@ -41,17 +42,14 @@
  * NetSec uses Synopsys DesignWare Core EMAC.  DWC implementation
  * register (0x20) is known to have 0x10.36 and feature register (0x1058)
  * reports 0x11056f37.
- *  <24> exdesc
+ *  <24> alternative/enhanced desc format
  *  <18> receive IP type 2 checksum offload
- *  <17> (no) receive IP type 1 checksum offload
  *  <16> transmit checksum offload
  *  <11> event counter (mac management counter, MMC) 
  */
 
-#define NOT_MP_SAFE	0
-
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.39 2022/09/27 06:36:43 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.40 2023/05/21 00:35:38 nisimura Exp $");
 
 #include 
 #include 
@@ -81,27 +79,25 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 struct tdes {
 	uint32_t t0, t1, t2, t3;
 };
-
 struct rdes {
 	uint32_t r0, r1, r2, r3;
 };
-
 #define T0_OWN		(1U<<31)	/* desc is ready to Tx */
-#define T0_EOD		(1U<<30)	/* end of descriptor array */
+#define T0_LD		(1U<<30)	/* last descriptor in array */
 #define T0_DRID		(24)		/* 29:24 desc ring id */
 #define T0_PT		(1U<<21)	/* 23:21 "pass-through" */
 #define T0_TDRID	(16)		/* 20:16 target desc ring id: GMAC=15 */
+#define T0_CC		(1U<<15)	/* ??? */
 #define T0_FS		(1U<<9)		/* first segment of frame */
 #define T0_LS		(1U<<8)		/* last segment of frame */
 #define T0_CSUM		(1U<<7)		/* enable check sum offload */
 #define T0_TSO		(1U<<6)		/* enable TCP segment offload */
-#define T0_TRS		(1U<<4)		/* 5:4 "TRS" */
+#define T0_TRS		(1U<<4)		/* 5:4 "TRS" ??? */
 /* T1 frame segment address 63:32 */
 /* T2 frame segment address 31:0 */
 /* T3 31:16 TCP segment length, 15:0 frame segment length to transmit */
-
 #define R0_OWN		(1U<<31)	/* desc is empty */
-#define R0_EOD		(1U<<30)	/* end of descriptor array */
+#define R0_LD		(1U<<30)	/* last descriptor in array */
 #define R0_SDRID	(24)		/* 29:24 source desc ring id */
 #define R0_FR		(1U<<23)	/* found fragmented */
 #define R0_ER		(1U<<21)	/* Rx error indication */
@@ -131,9 +127,13 @@ struct rdes {
 #define  RPTHDERR	(1U<<1)		/* log HD error */
 #define  DROPNOMATCH	(1U<<0)		/* drop no match frames */
 #define xINTSR		0x200		/* aggregated interrupt status */
-#define  IRQ_RX		(1U<<1)		/* top level Rx interrupt */
-#define  IRQ_TX		(1U<<0)		/* top level Rx interrupt */
 #define  IRQ_UCODE	(1U<<20)	/* ucode load completed; W1C */
+#define  IRQ_MAC	(1U<<19)	/* ??? */
+#define  IRQ_PKT	(1U<<18)	/* ??? */
+#define  IRQ_BOOTCODE	(1U<<5)		/* ??? */
+#define  IRQ_XDONE	(1U<<4)		/* ??? mode change completed */
+#define  IRQ_RX		(1U<<1)		/* top level Rx interrupt */
+#define  IRQ_TX		(1U<<0)		/* top level Tx interrupt */
 #define xINTAEN		0x204		/* INT_A enable */
 #define xINTAE_SET	0x234		/* bit to set */
 #define xINTAE_CLR	0x238		/* bit to clr */
@@ -174,6 +174,7 @@ struct rdes {
 #define RXITIMER	0x460		/* coalesce timer usec, MSB to use */
 #define TXDONECNT	0x414		/* tx completed count, auto-zero */
 #define RXDONECNT	0x454		/* rx available count, auto-zero */
+#define DMACTL_TMR	0x20c		/* engine DMA timer value */
 #define UCODE_H2M	0x210		/* host2media engine ucode port */
 #define UCODE_M2H	0x21c		/* media2host engine ucode port */
 #define CORESTAT	0x218		/* engine run state */
@@ -223,9 +224,9 @@ struct rdes {
 #define  MCR_WD		(1U<<23)	/* allow long >2048 tx frame */
 #define  MCR_JE		(1U<<20)	/* allow ~9018 tx jumbo frame */
 #define  MCR_IFG	(7U<<17)	/* 19:17 IFG value 0~7 */
-#define  MCR_DRCS	(1U<<16)	/* ignore (G)MII HDX Tx error */
-#define  MCR_USEMII	(1U<<15)	/* 1: RMII/MII, 0: RGMII (_PS) */
-#define  MCR_SPD100	(1U<<14)	/* force speed 100 (_FES) */
+#define  MCR_DCRS	(1U<<16)	/* ignore (G)MII HDX Tx error */
+#define  MCR_PS		(1U<<15)	/* 1: MII 10/100, 0: GMII 1000 */
+#define  MCR_FES	(1U<<14)	/* force speed 100 */
 #define  MCR_DO		(1U<<13)	/* don't receive my own HDX Tx frames */
 #define  MCR_LOOP	(1U<<12)	/* run loop back */
 #define  MCR_USEFDX	(1U<<11)	/* force full duplex */
@@ -233,11 +234,10 @@ struct 

CVS commit: src/sys/arch/arm/sociox

2023-05-20 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Sun May 21 00:35:38 UTC 2023

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
small fixes, code shuffle for ease of understanding.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2022-09-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Sep 18 15:22:43 UTC 2022

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
Eliminate use of IFF_OACTIVE.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.37 src/sys/arch/arm/sociox/if_scx.c:1.38
--- src/sys/arch/arm/sociox/if_scx.c:1.37	Sun Jun 12 16:22:37 2022
+++ src/sys/arch/arm/sociox/if_scx.c	Sun Sep 18 15:22:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.37 2022/06/12 16:22:37 andvar Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.38 2022/09/18 15:22:43 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -51,7 +51,7 @@
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.37 2022/06/12 16:22:37 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.38 2022/09/18 15:22:43 thorpej Exp $");
 
 #include 
 #include 
@@ -1133,7 +1133,6 @@ scx_init(struct ifnet *ifp)
 	mac_write(sc, GMACOMR, csr | OMR_SR | OMR_ST);
 
 	ifp->if_flags |= IFF_RUNNING;
-	ifp->if_flags &= ~IFF_OACTIVE;
 
 	/* start one second timer */
 	callout_schedule(>sc_callout, hz);
@@ -1153,7 +1152,7 @@ scx_stop(struct ifnet *ifp, int disable)
 	mii_down(>sc_mii);
 
 	/* Mark the interface down and cancel the watchdog timer. */
-	ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
+	ifp->if_flags &= ~IFF_RUNNING;
 	ifp->if_timer = 0;
 
 	CSR_WRITE(sc, xINTAE_CLR, ~0);
@@ -1318,7 +1317,7 @@ scx_start(struct ifnet *ifp)
 	int error, nexttx, lasttx, ofree, seg;
 	uint32_t tdes0;
 
-	if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
+	if ((ifp->if_flags & IFF_RUNNING) == 0)
 		return;
 
 	/* Remember the previous number of free descriptors. */
@@ -1362,10 +1361,8 @@ scx_start(struct ifnet *ifp)
 			 * Not enough free descriptors to transmit this
 			 * packet.  We haven't committed anything yet,
 			 * so just unload the DMA map, put the packet
-			 * back on the queue, and punt.	 Notify the upper
-			 * layer that there are not more slots left.
+			 * back on the queue, and punt.
 			 */
-			ifp->if_flags |= IFF_OACTIVE;
 			bus_dmamap_unload(sc->sc_dmat, dmamap);
 			break;
 		}
@@ -1427,10 +1424,6 @@ scx_start(struct ifnet *ifp)
 		bpf_mtap(ifp, m0, BPF_D_OUT);
 	}
 
-	if (sc->sc_txsfree == 0 || sc->sc_txfree == 0) {
-		/* No more slots left; notify upper layer. */
-		ifp->if_flags |= IFF_OACTIVE;
-	}
 	if (sc->sc_txfree != ofree) {
 		/* Set a watchdog timer in case the chip flakes out. */
 		ifp->if_timer = 5;
@@ -1505,8 +1498,6 @@ txreap(struct scx_softc *sc)
 	uint32_t txstat;
 	int i;
 
-	ifp->if_flags &= ~IFF_OACTIVE;
-
 	for (i = sc->sc_txsdirty; sc->sc_txsfree != MD_TXQUEUELEN;
 	 i = MD_NEXTTXS(i), sc->sc_txsfree++) {
 		txs = >sc_txsoft[i];



CVS commit: src/sys/arch/arm/sociox

2022-09-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Sep 18 15:22:43 UTC 2022

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
Eliminate use of IFF_OACTIVE.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2022-02-01 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Feb  1 09:08:33 UTC 2022

Modified Files:
src/sys/arch/arm/sociox: files.sociox

Log Message:
retire SocioNext AVE 32/64 GbE driver


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/sociox/files.sociox

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/sociox/files.sociox
diff -u src/sys/arch/arm/sociox/files.sociox:1.10 src/sys/arch/arm/sociox/files.sociox:1.11
--- src/sys/arch/arm/sociox/files.sociox:1.10	Fri Dec  3 05:21:52 2021
+++ src/sys/arch/arm/sociox/files.sociox	Tue Feb  1 09:08:33 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sociox,v 1.10 2021/12/03 05:21:52 nisimura Exp $
+#	$NetBSD: files.sociox,v 1.11 2022/02/01 09:08:33 nisimura Exp $
 #
 # Configuration info for Socionext SC2A11
 #
@@ -10,11 +10,6 @@ attach	scx at acpinodebus with scx_acpi
 attach	scx at fdt with scx_fdt
 file	arch/arm/sociox/if_scx.c		scx
 
-# Unifier AVE GbE
-device	ave: ether, ifnet, arp, mii, bus_dma_generic
-attach	ave at fdt with ave_fdt
-file	arch/arm/sociox/if_ave.c		ave
-
 # Socionext eMMC
 device	sniemmc: sdmmcbus
 attach	sniemmc at acpinodebus with sniemmc_acpi



CVS commit: src/sys/arch/arm/sociox

2022-02-01 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Feb  1 09:08:33 UTC 2022

Modified Files:
src/sys/arch/arm/sociox: files.sociox

Log Message:
retire SocioNext AVE 32/64 GbE driver


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/sociox/files.sociox

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



CVS commit: src/sys/arch/arm/sociox

2022-02-01 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Feb  1 08:58:25 UTC 2022

Removed Files:
src/sys/arch/arm/sociox: if_ave.c

Log Message:
retire SocioNext AVE 32/64 GbE driver


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r0 src/sys/arch/arm/sociox/if_ave.c

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



CVS commit: src/sys/arch/arm/sociox

2022-02-01 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Feb  1 08:58:25 UTC 2022

Removed Files:
src/sys/arch/arm/sociox: if_ave.c

Log Message:
retire SocioNext AVE 32/64 GbE driver


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r0 src/sys/arch/arm/sociox/if_ave.c

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



CVS commit: src/sys/arch/arm/sociox

2022-01-26 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Jan 27 02:34:23 UTC 2022

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
always use mac_write/read to handle DWC registers


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.35 src/sys/arch/arm/sociox/if_scx.c:1.36
--- src/sys/arch/arm/sociox/if_scx.c:1.35	Tue Jan 25 10:51:36 2022
+++ src/sys/arch/arm/sociox/if_scx.c	Thu Jan 27 02:34:23 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.35 2022/01/25 10:51:36 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.36 2022/01/27 02:34:23 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -40,13 +40,18 @@
  * have to be loaded by device driver.
  * NetSec uses Synopsys DesignWare Core EMAC.  DWC implementation
  * register (0x20) is known to have 0x10.36 and feature register (0x1058)
- * to report XX.XX.
+ * reports 0x11056f37.
+ *  <24> exdesc
+ *  <18> receive IP type 2 checksum offload
+ *  <17> (no) receive IP type 1 checksum offload
+ *  <16> transmit checksum offload
+ *  <11> event counter (mac management counter, MMC) 
  */
 
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.35 2022/01/25 10:51:36 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.36 2022/01/27 02:34:23 nisimura Exp $");
 
 #include 
 #include 
@@ -380,12 +385,12 @@ struct rdes {
 #define  FEA_2COE	(1U<<18)	/* Rx type 2 IP checksum offload */
 #define  FEA_1COE	(1U<<17)	/* Rx type 1 IP checksum offload */
 #define  FEA_TXOE	(1U<<16)	/* Tx checksum offload */
-#define  FEA_MMC	(1U<<11)	/* RMON management block */
+#define  FEA_MMC	(1U<<11)	/* RMON event counter */
 
 #define GMACEVCTL	0x0100		/* event counter control */
 #define  EVC_FHP	(1U<<5)		/* full-half preset */
-#define  EVC_CP		(1U<<4)		/* counters preset */
-#define  EVC_MCF	(1U<<3)		/* MMC counter freeze */
+#define  EVC_CP		(1U<<4)		/* counter preset */
+#define  EVC_MCF	(1U<<3)		/* counter freeze */
 #define  EVC_ROR	(1U<<2)		/* auto-zero on counter read */
 #define  EVC_CSR	(1U<<1)		/* counter stop rollover */
 #define  EVC_CR		(1U<<0)		/* reset counters */
@@ -1025,7 +1030,8 @@ scx_reset(struct scx_softc *sc)
 	CSR_WRITE(sc, TXISR, ~0);
 	CSR_WRITE(sc, xINTAE_CLR, ~0);
 
-	mac_write(sc, GMACEVCTL, 1);
+	/* clear event counters, auto-zero after every read */
+	mac_write(sc, GMACEVCTL, EVC_CR | EVC_ROR);
 }
 
 static int
@@ -1045,7 +1051,7 @@ scx_init(struct ifnet *ifp)
 
 	/* build sane Tx */
 	memset(sc->sc_txdescs, 0, sizeof(struct tdes) * MD_NTXDESC);
-	sc->sc_txdescs[MD_NTXDESC - 1].t0 |= T0_EOD; /* tie off the ring */
+	sc->sc_txdescs[MD_NTXDESC - 1].t0 = T0_EOD; /* tie off the ring */
 	SCX_CDTXSYNC(sc, 0, MD_NTXDESC,
 		BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
 	sc->sc_txfree = MD_NTXDESC;
@@ -1071,8 +1077,7 @@ scx_init(struct ifnet *ifp)
 		else
 			SCX_INIT_RXDESC(sc, i);
 	}
-	sc->sc_rxdescs[MD_NRXDESC - 1].r0 = R0_EOD;
-	sc->sc_rxptr = 0;
+	sc->sc_rxdescs[MD_NRXDESC - 1].r0 = R0_EOD; /* tie off the ring */
 	sc->sc_rxptr = 0;
 
 	paddr = SCX_CDTXADDR(sc, 0);		/* tdes array (ring#0) */
@@ -1104,8 +1109,8 @@ scx_init(struct ifnet *ifp)
 	CSR_WRITE(sc, DESC_INIT, 01);
 	WAIT_FOR_CLR(sc, DESC_INIT, 01, 0);
 
-	CSR_WRITE(sc, GMACRDLA, _RDLA);		/* GMAC rdes store */
-	CSR_WRITE(sc, GMACTDLA, _TDLA);		/* GMAC tdes store */
+	mac_write(sc, GMACRDLA, _RDLA);		/* GMAC rdes store */
+	mac_write(sc, GMACTDLA, _TDLA);		/* GMAC tdes store */
 
 	CSR_WRITE(sc, FLOWTHR, (48<<16) | 36);	/* pause|resume threshold */
 	mac_write(sc, GMACFCR, 256 << 16);	/* 31:16 pause value */



CVS commit: src/sys/arch/arm/sociox

2022-01-26 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Jan 27 02:34:23 UTC 2022

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
always use mac_write/read to handle DWC registers


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2022-01-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Jan 25 10:51:36 UTC 2022

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
- don't put const for CFATTACH_DECL_NEW()
- MDIO now senses PHY correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.34 src/sys/arch/arm/sociox/if_scx.c:1.35
--- src/sys/arch/arm/sociox/if_scx.c:1.34	Fri Dec 31 14:25:22 2021
+++ src/sys/arch/arm/sociox/if_scx.c	Tue Jan 25 10:51:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.34 2021/12/31 14:25:22 riastradh Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.35 2022/01/25 10:51:36 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.34 2021/12/31 14:25:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.35 2022/01/25 10:51:36 nisimura Exp $");
 
 #include 
 #include 
@@ -546,10 +546,10 @@ static void scx_fdt_attach(device_t, dev
 static int scx_acpi_match(device_t, cfdata_t, void *);
 static void scx_acpi_attach(device_t, device_t, void *);
 
-const CFATTACH_DECL_NEW(scx_fdt, sizeof(struct scx_softc),
+CFATTACH_DECL_NEW(scx_fdt, sizeof(struct scx_softc),
 scx_fdt_match, scx_fdt_attach, NULL, NULL);
 
-const CFATTACH_DECL_NEW(scx_acpi, sizeof(struct scx_softc),
+CFATTACH_DECL_NEW(scx_acpi, sizeof(struct scx_softc),
 scx_acpi_match, scx_acpi_attach, NULL, NULL);
 
 static void scx_attach_i(struct scx_softc *);
@@ -683,9 +683,6 @@ scx_fdt_attach(device_t parent, device_t
 	const char *phy_type;
 	long ref_clk;
 
-	aprint_naive("\n");
-	aprint_normal(": Socionext Gigabit Ethernet controller\n");
-
 	if (fdtbus_get_reg(phandle, 0, addr+0, size+0) != 0
 	|| bus_space_map(faa->faa_bst, addr[0], size[0], 0, ) != 0) {
 		aprint_error_dev(self, "unable to map device csr\n");
@@ -731,6 +728,7 @@ scx_fdt_attach(device_t parent, device_t
 	sc->sc_phy_id = phy_id;
 	sc->sc_freq = ref_clk;
 
+	aprint_normal("%s", device_xname(self));
 	scx_attach_i(sc);
 	return;
  fail:
@@ -762,15 +760,11 @@ scx_acpi_attach(device_t parent, device_
 	ACPI_INTEGER phy_type, phy_id, ref_freq;
 	ACPI_STATUS rv;
 
-	aprint_naive("\n");
-	aprint_normal(": Socionext Gigabit Ethernet controller\n");
-
 	rv = acpi_resource_parse(self, handle, "_CRS",
 	, _resource_parse_ops_default);
-	if (ACPI_FAILURE(rv)) {
-		aprint_error_dev(self, "missing crs resources\n");
+	if (ACPI_FAILURE(rv))
 		return;
-	}
+
 	mem = acpi_res_mem(, 0);
 	irq = acpi_res_irq(, 0);
 	if (mem == NULL || irq == NULL || mem->ar_length == 0) {
@@ -783,8 +777,8 @@ scx_acpi_attach(device_t parent, device_
 		return;
 	}
 	sc->sc_sz = mem->ar_length;
-	sc->sc_ih = acpi_intr_establish(self, (uint64_t)handle, IPL_NET,
-	NOT_MP_SAFE, scx_intr, sc, device_xname(self));
+	sc->sc_ih = acpi_intr_establish(self, (uint64_t)(uintptr_t)handle,
+	IPL_NET, NOT_MP_SAFE, scx_intr, sc, device_xname(self));
 	if (sc->sc_ih == NULL) {
 		aprint_error_dev(self, "couldn't establish interrupt\n");
 		goto fail;
@@ -808,7 +802,7 @@ scx_acpi_attach(device_t parent, device_
 	}
 	rv = acpi_dsd_integer(handle, "phy-channel", _id);
 	if (ACPI_FAILURE(rv))
-		phy_id = 7;
+		phy_id = MII_PHY_ANY;
 	rv = acpi_dsd_integer(handle, "socionext,phy-clock-frequency",
 			_freq);
 	if (ACPI_FAILURE(rv))
@@ -819,15 +813,14 @@ scx_acpi_attach(device_t parent, device_
 	sc->sc_sh = bsh;
 	sc->sc_eesh = eebsh;
 	sc->sc_dmat = aa->aa_dmat64;
-
-aprint_normal_dev(self,
-"phy type %d, phy id %d, freq %ld\n", (int)phy_type, (int)phy_id, ref_freq);
 	sc->sc_100mii = (phy_type != 1000);
 	sc->sc_phy_id = (int)phy_id;
 	sc->sc_freq = ref_freq;
+
 aprint_normal_dev(self,
-"GMACGAR %08x\n", mac_read(sc, GMACGAR));
+"phy type %d, phy id %d, freq %ld\n", (int)phy_type, (int)phy_id, ref_freq);
 
+	aprint_normal("%s", device_xname(self));
 	scx_attach_i(sc);
 
 	acpi_resource_cleanup();
@@ -847,22 +840,23 @@ scx_attach_i(struct scx_softc *sc)
 	struct ifnet * const ifp = >sc_ethercom.ec_if;
 	struct mii_data * const mii = >sc_mii;
 	struct ifmedia * const ifm = >mii_media;
-	uint32_t which, dwimp, dwfea;
+	uint32_t which, dwfea, dwimp;
 	uint8_t enaddr[ETHER_ADDR_LEN];
 	bus_dma_segment_t seg;
 	uint32_t csr;
 	int i, nseg, error = 0;
 
+	aprint_naive("\n");
+	aprint_normal(": Socionext Gigabit Ethernet controller\n");
+
 	which = CSR_READ(sc, HWVER);	/* Socionext version 5.00xx */
-	dwimp = mac_read(sc, GMACIMPL);	/* DWC EMAC XX.YY */
-	dwfea = mac_read(sc, HWFEA);	/* DWC feature */
+	dwfea = mac_read(sc, HWFEA);	/* DWC feature bits */
+	dwimp = mac_read(sc, GMACIMPL);	/* DWC implementation XX.YY */
 	aprint_normal_dev(sc->sc_dev,
-	"Socionext NetSec GbE %x.%x"
-	" (impl 0x%x, feature 0x%x)\n",
-	which >> 

CVS commit: src/sys/arch/arm/sociox

2022-01-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Jan 25 10:51:36 UTC 2022

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
- don't put const for CFATTACH_DECL_NEW()
- MDIO now senses PHY correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2022-01-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Jan 25 10:38:56 UTC 2022

Modified Files:
src/sys/arch/arm/sociox: sni_gpio.c

Log Message:
- rectify attach messages.
- abandon irq to use for now.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sociox/sni_gpio.c

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/sociox/sni_gpio.c
diff -u src/sys/arch/arm/sociox/sni_gpio.c:1.12 src/sys/arch/arm/sociox/sni_gpio.c:1.13
--- src/sys/arch/arm/sociox/sni_gpio.c:1.12	Tue Dec 21 06:00:45 2021
+++ src/sys/arch/arm/sociox/sni_gpio.c	Tue Jan 25 10:38:56 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_gpio.c,v 1.12 2021/12/21 06:00:45 nisimura Exp $	*/
+/*	$NetBSD: sni_gpio.c,v 1.13 2022/01/25 10:38:56 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.12 2021/12/21 06:00:45 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.13 2022/01/25 10:38:56 nisimura Exp $");
 
 #include 
 #include 
@@ -94,14 +94,13 @@ CFATTACH_DECL_NEW(snigpio_acpi, sizeof(s
  *PowerButton (PWROFF#) can be detectable.
  *
  *  DevelopmentBox has 96board mezzanine 2x 20 receptacle
- *gpio  "/gpio@5100" pinA-L (10-25) down edge sensitive
+ *gpio  "/gpio@5100" pinA-L (23-34) down edge sensitive
  *i2c   "/i2c1@51221000"
  *spi   "/spi1@5481"
- *uart0 "/uart@2a40" pin1-4 for real S2C11 console
- *uart1 SCP secure co-prorcessor uart console in pin5-6
+ *uart0 "/uart@2a40" pin3,5,7,9 for real S2CA11 console
+ *uart1 SCP secure co-prorcessor uart console in pin11,13
  */
 static void snigpio_attach_i(struct snigpio_softc *);
-static int snigpio_intr(void *);
 
 static const struct device_compatible_entry compat_data[] = {
 	{ .compat = "socionext,synquacer-gpio" },
@@ -130,32 +129,12 @@ snigpio_fdt_attach(device_t parent, devi
 	bus_space_handle_t ioh;
 	bus_addr_t addr;
 	bus_size_t size;
-	char intrstr[128];
-	const char *list;
-
-	aprint_naive("\n");
-	aprint_normal(": Socionext GPIO controller\n");
 
 	if (fdtbus_get_reg(phandle, 0, , ) != 0
 	|| bus_space_map(faa->faa_bst, addr, size, 0, ) != 0) {
 		aprint_error_dev(self, "unable to map device\n");
 		return;
 	}
-	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
-		aprint_error_dev(self, "failed to decode interrupt\n");
-		goto fail;
-	}
-	sc->sc_ih = fdtbus_intr_establish(phandle,
-			0, IPL_VM, 0, snigpio_intr, sc);
-	if (sc->sc_ih == NULL) {
-		aprint_error_dev(self, "couldn't establish interrupt\n");
-		goto fail;
-	}
-	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
-
-	list = fdtbus_get_string(phandle, "gpio-line-names");
-	if (list)
-		aprint_normal_dev(self, "%s\n", list);
 
 	sc->sc_dev = self;
 	sc->sc_iot = faa->faa_bst;
@@ -163,13 +142,11 @@ snigpio_fdt_attach(device_t parent, devi
 	sc->sc_iob = addr;
 	sc->sc_ios = size;
 	sc->sc_phandle = phandle;
+	/* could use FDI "gpio-line-names" array via device_set_handle() */
 
 	snigpio_attach_i(sc);
 
 	return;
- fail:
-	bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
-	return;	
 }
 
 static int
@@ -189,22 +166,16 @@ snigpio_acpi_attach(device_t parent, dev
 	bus_space_handle_t ioh;
 	struct acpi_resources res;
 	struct acpi_mem *mem;
-	struct acpi_irq *irq;
 	ACPI_STATUS rv;
 	char *list;
 
-	aprint_naive("\n");
-	aprint_normal(": Socionext GPIO controller\n");
-
 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
 	, _resource_parse_ops_default);
-	if (ACPI_FAILURE(rv)) {
-		aprint_error_dev(self, "missing crs resources\n");
+	if (ACPI_FAILURE(rv))
 		return;
-	}
+
 	mem = acpi_res_mem(, 0);
-	irq = acpi_res_irq(, 0);
-	if (mem == NULL || irq == NULL || mem->ar_length == 0) {
+	if (mem == NULL || mem->ar_length == 0) {
 		aprint_error_dev(self, "incomplete resources\n");
 		return;
 	}
@@ -213,30 +184,19 @@ snigpio_acpi_attach(device_t parent, dev
 		aprint_error_dev(self, "couldn't map registers\n");
 		return;
 	}
-	sc->sc_ih = acpi_intr_establish(self, (uint64_t)handle,
-	IPL_VM, false, snigpio_intr, sc, device_xname(self));
-	if (sc->sc_ih == NULL) {
-		aprint_error_dev(self, "couldn't establish interrupt\n");
-		goto fail;
-	}
-	rv = acpi_dsd_string(handle, "gpio-line-names", );
-	if (ACPI_SUCCESS(rv))
-		aprint_normal_dev(self, "%s\n", list);
 
 	sc->sc_dev = self;
 	sc->sc_iot = aa->aa_memt;
 	sc->sc_ioh = ioh;
 	sc->sc_ios = mem->ar_length;
 	sc->sc_phandle = 0;
+	/* UEFI provides "gpio-line-names" for us */
 
+	aprint_normal("%s", device_xname(self));
 	snigpio_attach_i(sc);
 
 	acpi_resource_cleanup();
 	return;
- fail:
-	acpi_resource_cleanup();
-	bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
-	return;	
 }
 
 static void
@@ -245,6 +205,9 @@ snigpio_attach_i(struct snigpio_softc *s
 	struct gpio_chipset_tag	*gc;
 	struct gpiobus_attach_args gba;
 
+	

CVS commit: src/sys/arch/arm/sociox

2022-01-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Jan 25 10:38:56 UTC 2022

Modified Files:
src/sys/arch/arm/sociox: sni_gpio.c

Log Message:
- rectify attach messages.
- abandon irq to use for now.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sociox/sni_gpio.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-21 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Dec 22 02:32:53 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: sni_i2c.c

Log Message:
add register definitions. the design is BCM2835 I2C look-a-like.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/sociox/sni_i2c.c

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/sociox/sni_i2c.c
diff -u src/sys/arch/arm/sociox/sni_i2c.c:1.13 src/sys/arch/arm/sociox/sni_i2c.c:1.14
--- src/sys/arch/arm/sociox/sni_i2c.c:1.13	Tue Dec 21 06:00:45 2021
+++ src/sys/arch/arm/sociox/sni_i2c.c	Wed Dec 22 02:32:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_i2c.c,v 1.13 2021/12/21 06:00:45 nisimura Exp $	*/
+/*	$NetBSD: sni_i2c.c,v 1.14 2021/12/22 02:32:53 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.13 2021/12/21 06:00:45 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.14 2021/12/22 02:32:53 nisimura Exp $");
 
 #include 
 #include 
@@ -53,23 +53,67 @@ __KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 
 #include 
 #include 
 
+#define BSR		0x00		/* status */
+#define  BSR_BB		(1U<<7)		/* busy */
+#define  BSR_RSC	(1U<<6)		/* repeated cycle condition */
+#define  BSR_AL		(1U<<5)		/* arbitration lost */
+#define  BSR_LRB	(1U<<4)		/* last bit received */
+#define  BSR_XFR	(1U<<3)		/* start transfer */
+#define  BSR_AAS	(1U<<2)		/* ??? address as slave */
+#define  BSR_GCA	(1U<<1)		/* ??? general call address */
+#define  BSR_FBT	(1U<<0)		/* first byte transfer detected */
+#define BCR		0x04		/* control */
+#define  BCR_BERR	(1U<<7)		/* bus error report; W0C */
+#define  BCR_BEIEN	(1U<<6)		/* enable bus error interrupt */
+#define  BCR_SCC	(1U<<5)		/* make start condition */
+#define  BCR_MSS	(1U<<4)		/* 1: xmit, 0: recv */ 
+#define  BCR_ACK	(1U<<3)		/* make acknowledge at last byte */
+#define  BCR_GCAA	(1U<<2)		/* ??? general call access ack */
+#define  BCR_IEN	(1U<<1)		/* enable interupt */
+#define  BCR_INT	(1U<<0)		/* interrupt report; W0C */
+#define CCR		0x08
+#define  CCR_FM		(1U<<6)		/* speed; 1: fast, 0: standard */
+#define  CCR_EN		(1U<<5)		/* enable clock feed */
+/* 4:0 clock rate select */
+#define ADR		0x0c		/* 6:0 my own address */
+#define DAR		0x10		/* 7:0 data port */
+#define CSR		0x14		/* 5:0 clock divisor */
+#define FSR		0x18		/* bus clock frequency */
+#define BC2R		0x1c		/* control 2 */
+#define  BC2R_SDA	(1U<<5)		/* detected SDA signal */
+#define  BC2R_SCL	(1U<<5)		/* detected SCL signal */
+#define  BC2R_SDA_L	(1U<<1)		/* make SDA signal low */
+#define  BC2R_SCL_L	(1U<<1)		/* make SCL signal low */
+
 static int sniiic_fdt_match(device_t, struct cfdata *, void *);
 static void sniiic_fdt_attach(device_t, device_t, void *);
 static int sniiic_acpi_match(device_t, struct cfdata *, void *);
 static void sniiic_acpi_attach(device_t, device_t, void *);
 
+typedef enum {
+	EXEC_IDLE	= 0,	/* sane and idle */
+	EXEC_ADDR	= 1,	/* send address bits */
+	EXEC_CMD	= 2,	/* send command bits */
+	EXEC_SEND	= 3,	/* data xmit */
+	EXEC_RECV	= 4,	/* data recv */
+	EXEC_DONE	= 5,	/* xter done */
+	EXEC_ERR	= 6,	/* recover error */
+} state_t;
+
 struct sniiic_softc {
 	device_t		sc_dev;
 	struct i2c_controller	sc_ic;
 	bus_space_tag_t		sc_iot;
 	bus_space_handle_t	sc_ioh;
-	bus_addr_t		sc_iob;
 	bus_size_t		sc_ios;
 	void			*sc_ih;
 	kmutex_t		sc_lock;
 	kmutex_t		sc_mtx;
 	kcondvar_t		sc_cv;
 	volatile bool		sc_busy;
+	state_t			sc_state;
+	u_int			sc_frequency;
+	u_int			sc_clkrate;
 	int			sc_phandle;
 };
 
@@ -90,9 +134,9 @@ static int sni_i2c_intr(void *);
 static void sni_i2c_reset(struct sniiic_softc *);
 static void sni_i2c_flush(struct sniiic_softc *);
 
-#define I2C_READ(sc, reg) \
+#define CSR_READ(sc, reg) \
 bus_space_read_4((sc)->sc_ioh,(sc)->sc_ioh,(reg))
-#define I2C_WRITE(sc, reg, val) \
+#define CSR_WRITE(sc, reg, val) \
 bus_space_write_4((sc)->sc_ioh,(sc)->sc_ioh,(reg),(val))
 
 static const struct device_compatible_entry compat_data[] = {
@@ -146,7 +190,6 @@ sniiic_fdt_attach(device_t parent, devic
 	sc->sc_dev = self;
 	sc->sc_iot = faa->faa_bst;
 	sc->sc_ioh = ioh;
-	sc->sc_iob = addr;
 	sc->sc_ios = size;
 	sc->sc_phandle = phandle;
 
@@ -213,7 +256,6 @@ sniiic_acpi_attach(device_t parent, devi
 	sc->sc_dev = self;
 	sc->sc_iot = aa->aa_memt;
 	sc->sc_ioh = ioh;
-	sc->sc_iob = mem->ar_base;
 	sc->sc_ios = mem->ar_length;
 	sc->sc_phandle = 0;
 



CVS commit: src/sys/arch/arm/sociox

2021-12-21 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Dec 22 02:32:53 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: sni_i2c.c

Log Message:
add register definitions. the design is BCM2835 I2C look-a-like.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/sociox/sni_i2c.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-21 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Dec 21 21:30:49 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
pursue better register description


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-21 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Dec 21 21:30:49 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
pursue better register description


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.32 src/sys/arch/arm/sociox/if_scx.c:1.33
--- src/sys/arch/arm/sociox/if_scx.c:1.32	Tue Dec 21 12:12:52 2021
+++ src/sys/arch/arm/sociox/if_scx.c	Tue Dec 21 21:30:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.32 2021/12/21 12:12:52 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.33 2021/12/21 21:30:49 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.32 2021/12/21 12:12:52 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.33 2021/12/21 21:30:49 nisimura Exp $");
 
 #include 
 #include 
@@ -163,7 +163,7 @@ struct rdes {
 #define  DESCNF_CHRST	(1U<<30)	/* channel reset */
 #define  DESCNF_TMR	(1U<<4)		/* coalesce timer mode select */
 #define  DESCNF_LE	(1)		/* little endian desc format */
-#define TXSUBMIT	0x410		/* submit loaded tx frame */
+#define TXSUBMIT	0x410		/* submit frame(s) to transmit */
 #define TXCLSCMAX	0x418		/* tx intr coalesce upper bound */
 #define RXCLSCMAX	0x458		/* rx intr coalesce upper bound */
 #define TXITIMER	0x420		/* coalesce timer usec, MSB to use */



CVS commit: src/sys/arch/arm/sociox

2021-12-21 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Dec 21 12:12:52 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
correct register definition error and improve naming


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.31 src/sys/arch/arm/sociox/if_scx.c:1.32
--- src/sys/arch/arm/sociox/if_scx.c:1.31	Tue Dec 21 11:07:51 2021
+++ src/sys/arch/arm/sociox/if_scx.c	Tue Dec 21 12:12:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.31 2021/12/21 11:07:51 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.32 2021/12/21 12:12:52 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.31 2021/12/21 11:07:51 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.32 2021/12/21 12:12:52 nisimura Exp $");
 
 #include 
 #include 
@@ -163,12 +163,13 @@ struct rdes {
 #define  DESCNF_CHRST	(1U<<30)	/* channel reset */
 #define  DESCNF_TMR	(1U<<4)		/* coalesce timer mode select */
 #define  DESCNF_LE	(1)		/* little endian desc format */
-#define TXCOLMAX	0x410		/* tx intr coalesce upper bound */
-#define RXCOLMAX	0x454		/* rx intr coalesce upper bound */
+#define TXSUBMIT	0x410		/* submit loaded tx frame */
+#define TXCLSCMAX	0x418		/* tx intr coalesce upper bound */
+#define RXCLSCMAX	0x458		/* rx intr coalesce upper bound */
 #define TXITIMER	0x420		/* coalesce timer usec, MSB to use */
 #define RXITIMER	0x460		/* coalesce timer usec, MSB to use */
-#define TXDONECNT	0x424		/* tx completed count, auto-zero */
-#define RXDONECNT	0x458		/* rx available count, auto-zero */
+#define TXDONECNT	0x414		/* tx completed count, auto-zero */
+#define RXDONECNT	0x454		/* rx available count, auto-zero */
 #define UCODE_H2M	0x210		/* host2media engine ucode port */
 #define UCODE_M2H	0x21c		/* media2host engine ucode port */
 #define CORESTAT	0x218		/* engine run state */
@@ -1117,8 +1118,8 @@ scx_init(struct ifnet *ifp)
 	CSR_WRITE(sc, RXIE_CLR, ~0);	/* clear Rx interrupt enable */
 	CSR_WRITE(sc, TXIE_CLR, ~0);	/* clear Tx interrupt enable */
 
-	CSR_WRITE(sc, RXCOLMAX, 8);	/* Rx coalesce upper bound */
-	CSR_WRITE(sc, TXCOLMAX, 8);	/* Tx coalesce upper bound */
+	CSR_WRITE(sc, RXCLSCMAX, 8);	/* Rx coalesce upper bound */
+	CSR_WRITE(sc, TXCLSCMAX, 8);	/* Tx coalesce upper bound */
 	CSR_WRITE(sc, RXITIMER, 500);	/* Rx co. timer usec */
 	CSR_WRITE(sc, TXITIMER, 500);	/* Tx co. timer usec */
 
@@ -1408,8 +1409,8 @@ scx_start(struct ifnet *ifp)
 		SCX_CDTXSYNC(sc, sc->sc_txnext, dmamap->dm_nsegs,
 		BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
 
-		/* Tell DMA start transmit */
-		mac_write(sc, GMACTPD, 1);
+		/* submit one frame to xmit */
+		CSR_WRITE(sc, TXSUBMIT, 1);
 
 		txs->txs_mbuf = m0;
 		txs->txs_firstdesc = sc->sc_txnext;



CVS commit: src/sys/arch/arm/sociox

2021-12-21 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Dec 21 12:12:52 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
correct register definition error and improve naming


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-21 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Dec 21 11:07:51 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
add interrupt logic stuff


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.30 src/sys/arch/arm/sociox/if_scx.c:1.31
--- src/sys/arch/arm/sociox/if_scx.c:1.30	Mon Dec 20 06:47:24 2021
+++ src/sys/arch/arm/sociox/if_scx.c	Tue Dec 21 11:07:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.30 2021/12/20 06:47:24 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.31 2021/12/21 11:07:51 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.30 2021/12/20 06:47:24 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.31 2021/12/21 11:07:51 nisimura Exp $");
 
 #include 
 #include 
@@ -129,28 +129,29 @@ struct rdes {
 #define xINTSR		0x200		/* aggregated interrupt status */
 #define  IRQ_RX		(1U<<1)		/* top level Rx interrupt */
 #define  IRQ_TX		(1U<<0)		/* top level Rx interrupt */
-#define  IRQ_UCODE	(1U<<20)	/* ucode load completed */
+#define  IRQ_UCODE	(1U<<20)	/* ucode load completed; W1C */
 #define xINTAEN		0x204		/* INT_A enable */
 #define xINTAE_SET	0x234		/* bit to set */
 #define xINTAE_CLR	0x238		/* bit to clr */
 #define xINTBEN		0x23c		/* INT_B enable */
 #define xINTBE_SET	0x240		/* bit to set */
 #define xINTBE_CLR	0x244		/* bit to clr */
-#define TXISR		0x400		/* transmit status */
+#define TXISR		0x400		/* transmit status; W1C */
 #define TXIEN		0x404		/* tx interrupt enable */
 #define TXIE_SET	0x428		/* bit to set */
 #define TXIE_CLR	0x42c		/* bit to clr */
-#define  TXI_NTOWNR	(1U<<17)	/* ready desc got empty */
+#define  TXI_NTOWNR	(1U<<17)	/* ??? desc array got empty */
 #define  TXI_TR_ERR	(1U<<16)	/* tx error */
 #define  TXI_TXDONE	(1U<<15)	/* tx completed */
 #define  TXI_TMREXP	(1U<<14)	/* coalesce timer expired */
-#define RXISR		0x440		/* receive status */
+#define RXISR		0x440		/* receive status; W1C */
 #define RXIEN		0x444		/* rx interrupt enable */
 #define RXIE_SET	0x468		/* bit to set */
 #define RXIE_CLR	0x46c		/* bit to clr */
 #define  RXI_RC_ERR	(1U<<16)	/* rx error */
 #define  RXI_PKTCNT	(1U<<15)	/* rx counter has new value */
 #define  RXI_TMREXP	(1U<<14)	/* coalesce timer expired */
+/* 13 sets of special purpose desc interrupt handling register exist */
 #define TDBA_LO		0x408		/* tdes array base addr 31:0 */
 #define TDBA_HI		0x434		/* tdes array base addr 63:32 */
 #define RDBA_LO		0x448		/* rdes array base addr 31:0 */
@@ -459,7 +460,6 @@ struct scx_softc {
 	int sc_flowflags;		/* 802.3x PAUSE flow control */
 	uint32_t sc_mdclk;		/* GAR 5:2 clock selection */
 	uint32_t sc_t0cotso;		/* T0_CSUM | T0_TSO to run */
-	int sc_ucodeloaded;		/* ucode for H2M/M2H/PKT */
 	int sc_100mii;			/* 1 for RMII/MII, 0 for RGMII */
 	int sc_phandle;			/* fdt phandle */
 	uint64_t sc_freq;
@@ -603,7 +603,7 @@ static int
 mac_read(struct scx_softc *sc, int reg)
 {
 
-	CSR_WRITE(sc, MACCMD, reg);
+	CSR_WRITE(sc, MACCMD, reg | CMD_BUSY);
 	(void)WAIT_FOR_CLR(sc, MACCMD, CMD_BUSY, 0);
 	return CSR_READ(sc, MACDATA);
 }
@@ -613,10 +613,11 @@ mac_write(struct scx_softc *sc, int reg,
 {
 
 	CSR_WRITE(sc, MACDATA, val);
-	CSR_WRITE(sc, MACCMD, reg | CMD_IOWR);
+	CSR_WRITE(sc, MACCMD, reg | CMD_IOWR | CMD_BUSY);
 	(void)WAIT_FOR_CLR(sc, MACCMD, CMD_BUSY, 0);
 }
 
+/* dig and decode "clock-frequency" value for a given clkname */
 static int
 get_clk_freq(int phandle, const char *clkname)
 {
@@ -671,7 +672,6 @@ scx_fdt_attach(device_t parent, device_t
 	struct scx_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
 	const int phandle = faa->faa_phandle;
-	bus_space_tag_t bst = faa->faa_bst;
 	bus_space_handle_t bsh;
 	bus_space_handle_t eebsh;
 	bus_addr_t addr[2];
@@ -683,7 +683,7 @@ scx_fdt_attach(device_t parent, device_t
 	long ref_clk;
 
 	aprint_naive("\n");
-	aprint_normal(": Gigabit Ethernet Controller\n");
+	aprint_normal(": Socionext Gigabit Ethernet controller\n");
 
 	if (fdtbus_get_reg(phandle, 0, addr+0, size+0) != 0
 	|| bus_space_map(faa->faa_bst, addr[0], size[0], 0, ) != 0) {
@@ -707,7 +707,7 @@ scx_fdt_attach(device_t parent, device_t
 	}
 
 	sc->sc_dev = self;
-	sc->sc_st = bst;
+	sc->sc_st = faa->faa_bst;
 	sc->sc_sh = bsh;
 	sc->sc_sz = size[0];
 	sc->sc_eesh = eebsh;
@@ -754,7 +754,6 @@ scx_acpi_attach(device_t parent, device_
 	struct scx_softc * const sc = device_private(self);
 	struct acpi_attach_args * const aa = aux;
 	ACPI_HANDLE handle = aa->aa_node->ad_handle;
-	bus_space_tag_t bst = aa->aa_memt;
 	bus_space_handle_t bsh, eebsh;
 	struct acpi_resources res;
 	struct acpi_mem *mem;
@@ -763,7 

CVS commit: src/sys/arch/arm/sociox

2021-12-21 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Dec 21 11:07:51 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
add interrupt logic stuff


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-20 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Dec 21 06:00:45 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c sni_gpio.c sni_i2c.c

Log Message:
improve consistency when attach error cases.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/sociox/sni_emmc.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/arm/sociox/sni_gpio.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sociox/sni_i2c.c

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/sociox/sni_emmc.c
diff -u src/sys/arch/arm/sociox/sni_emmc.c:1.9 src/sys/arch/arm/sociox/sni_emmc.c:1.10
--- src/sys/arch/arm/sociox/sni_emmc.c:1.9	Wed Nov 10 17:23:46 2021
+++ src/sys/arch/arm/sociox/sni_emmc.c	Tue Dec 21 06:00:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_emmc.c,v 1.9 2021/11/10 17:23:46 msaitoh Exp $	*/
+/*	$NetBSD: sni_emmc.c,v 1.10 2021/12/21 06:00:45 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.9 2021/11/10 17:23:46 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.10 2021/12/21 06:00:45 nisimura Exp $");
 
 #include 
 #include 
@@ -87,6 +87,10 @@ static const struct device_compatible_en
 	{ .compat = "fujitsu,mb86s70-sdhci-3.0" },
 	DEVICE_COMPAT_EOL
 };
+static const struct device_compatible_entry compatible[] = {
+	{ .compat = "SCX0002" },
+	DEVICE_COMPAT_EOL
+};
 
 static int
 sniemmc_fdt_match(device_t parent, struct cfdata *match, void *aux)
@@ -107,13 +111,16 @@ sniemmc_fdt_attach(device_t parent, devi
 	bus_size_t size;
 	char intrstr[128];
 
+	aprint_naive("\n");
+	aprint_normal_dev(self, "Socionext eMMC controller\n");
+
 	if (fdtbus_get_reg(phandle, 0, , ) != 0
 	|| bus_space_map(faa->faa_bst, addr, size, 0, ) != 0) {
-		aprint_error(": unable to map device\n");
+		aprint_error_dev(self, "unable to map device\n");
 		return;
 	}
 	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
-		aprint_error(": failed to decode interrupt\n");
+		aprint_error_dev(self, "failed to decode interrupt\n");
 		goto fail;
 	}
 	sc->sc_ih = fdtbus_intr_establish(phandle, 0, IPL_SDMMC, 0,
@@ -123,19 +130,16 @@ sniemmc_fdt_attach(device_t parent, devi
 		intrstr);
 		goto fail;
 	}
-
-	aprint_naive("\n");
-	aprint_normal_dev(self, "Socionext eMMC controller\n");
 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
 	sc->sc.sc_dev = self;
 	sc->sc.sc_dmat = faa->faa_dmat;
 	sc->sc.sc_host = sc->sc_hosts;
-	sc->sc_phandle = phandle;
 	sc->sc_iot = faa->faa_bst;
 	sc->sc_ioh = ioh;
 	sc->sc_iob = addr;
 	sc->sc_ios = size;
+	sc->sc_phandle = phandle;
 
 	config_defer(self, sniemmc_attach_i);
 	return;
@@ -147,15 +151,9 @@ sniemmc_fdt_attach(device_t parent, devi
 static int
 sniemmc_acpi_match(device_t parent, struct cfdata *match, void *aux)
 {
-	static const char * compatible[] = {
-		"SCX0002",
-		NULL
-	};
 	struct acpi_attach_args *aa = aux;
 
-	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
-		return 0;
-	return acpi_match_hid(aa->aa_node->ad_devinfo, compatible);
+	return acpi_compatible_match(aa, compatible);
 }
 
 static void
@@ -163,12 +161,16 @@ sniemmc_acpi_attach(device_t parent, dev
 {
 	struct sniemmc_softc * const sc = device_private(self);
 	struct acpi_attach_args *aa = aux;
+	ACPI_HANDLE handle = aa->aa_node->ad_handle;
 	bus_space_handle_t ioh;
 	struct acpi_resources res;
 	struct acpi_mem *mem;
 	struct acpi_irq *irq;
 	ACPI_STATUS rv;
 
+	aprint_naive("\n");
+	aprint_normal(": Socionext eMMC controller\n");
+
 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
 	, _resource_parse_ops_default);
 	if (ACPI_FAILURE(rv))
@@ -176,31 +178,28 @@ sniemmc_acpi_attach(device_t parent, dev
 	mem = acpi_res_mem(, 0);
 	irq = acpi_res_irq(, 0);
 	if (mem == NULL || irq == NULL || mem->ar_length == 0) {
-		aprint_error(": incomplete resources\n");
+		aprint_error_dev(self, "incomplete resources\n");
 		return;
 	}
 	if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0,
 	)) {
-		aprint_error(": couldn't map registers\n");
+		aprint_error_dev(self, "couldn't map registers\n");
 		return;
 	}
-	sc->sc_ih = acpi_intr_establish(self,
-	(uint64_t)(uintptr_t)aa->aa_node->ad_handle,
+	sc->sc_ih = acpi_intr_establish(self, (uint64_t)handle,
 	IPL_BIO, false, sdhc_intr, >sc, device_xname(self));
 	if (sc->sc_ih == NULL) {
 		aprint_error_dev(self, "couldn't establish interrupt\n");
 		goto fail;
 	}
 
-	aprint_naive("\n");
-	aprint_normal_dev(self, "Socionext eMMC controller\n");
-
 	sc->sc.sc_dev = self;
 	sc->sc.sc_dmat = aa->aa_dmat;
 	sc->sc.sc_host = sc->sc_hosts;
 	sc->sc_iot = aa->aa_memt;
 	sc->sc_ioh = ioh;
 	sc->sc_ios = mem->ar_length;
+	sc->sc_phandle = 0;
 
 	config_defer(self, sniemmc_attach_i);
 
@@ -228,7 +227,8 @@ sniemmc_attach_i(device_t self)
 #endif
 	error = 0;
 	if (error) {
-		aprint_error_dev(self, 

CVS commit: src/sys/arch/arm/sociox

2021-12-20 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Dec 21 06:00:45 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c sni_gpio.c sni_i2c.c

Log Message:
improve consistency when attach error cases.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/sociox/sni_emmc.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/arm/sociox/sni_gpio.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sociox/sni_i2c.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-19 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Mon Dec 20 06:47:25 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
- iron out attach error case messages
- use 64-bit paddr bus_dma_tag
- dig and decode FDT "clock-frequency" value


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.29 src/sys/arch/arm/sociox/if_scx.c:1.30
--- src/sys/arch/arm/sociox/if_scx.c:1.29	Mon Dec 20 02:24:33 2021
+++ src/sys/arch/arm/sociox/if_scx.c	Mon Dec 20 06:47:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.29 2021/12/20 02:24:33 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.30 2021/12/20 06:47:24 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.29 2021/12/20 02:24:33 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.30 2021/12/20 06:47:24 nisimura Exp $");
 
 #include 
 #include 
@@ -449,7 +449,6 @@ struct scx_softc {
 	bus_space_handle_t sc_eesh;	/* eeprom section handle */
 	bus_size_t sc_eesz;		/* eeprom map size */
 	bus_dma_tag_t sc_dmat;		/* bus DMA tag */
-	bus_dma_tag_t sc_dmat32;
 	struct ethercom sc_ethercom;	/* Ethernet common data */
 	struct mii_data sc_mii;		/* MII */
 	callout_t sc_callout;		/* PHY monitor callout */
@@ -618,6 +617,37 @@ mac_write(struct scx_softc *sc, int reg,
 	(void)WAIT_FOR_CLR(sc, MACCMD, CMD_BUSY, 0);
 }
 
+static int
+get_clk_freq(int phandle, const char *clkname)
+{
+	u_int index, n, cells;
+	const u_int *p;
+	int err, len, resid;
+	unsigned int freq = 0;
+
+	err = fdtbus_get_index(phandle, "clock-names", clkname, );
+	if (err == -1)
+		return -1;
+	p = fdtbus_get_prop(phandle, "clocks", );
+	if (p == NULL)
+		return -1;
+	for (n = 0, resid = len; resid > 0; n++) {
+		const int cc_phandle =
+		fdtbus_get_phandle_from_native(be32toh(p[0]));
+		if (of_getprop_uint32(cc_phandle, "#clock-cells", ))
+			return -1;
+		if (n == index) {
+			if (of_getprop_uint32(cc_phandle,
+			"clock-frequency", ))
+return -1;
+			return freq;
+		}
+		resid -= (cells + 1) * 4;
+		p += (cells + 1) * 4;
+	}
+	return -1;
+}
+
 static const struct device_compatible_entry compat_data[] = {
 	{ .compat = "socionext,synquacer-netsec" },
 	DEVICE_COMPAT_EOL
@@ -647,15 +677,21 @@ scx_fdt_attach(device_t parent, device_t
 	bus_addr_t addr[2];
 	bus_size_t size[2];
 	char intrstr[128];
-	const char *phy_mode;
+	int phy_phandle;
+	bus_addr_t phy_id;
+	const char *phy_type;
+	long ref_clk;
+
+	aprint_naive("\n");
+	aprint_normal(": Gigabit Ethernet Controller\n");
 
 	if (fdtbus_get_reg(phandle, 0, addr+0, size+0) != 0
 	|| bus_space_map(faa->faa_bst, addr[0], size[0], 0, ) != 0) {
-		aprint_error(": unable to map device csr\n");
+		aprint_error_dev(self, "unable to map device csr\n");
 		return;
 	}
 	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
-		aprint_error(": failed to decode interrupt\n");
+		aprint_error_dev(self, "failed to decode interrupt\n");
 		goto fail;
 	}
 	sc->sc_ih = fdtbus_intr_establish(phandle, 0, IPL_NET,
@@ -666,14 +702,10 @@ scx_fdt_attach(device_t parent, device_t
 	}
 	if (fdtbus_get_reg(phandle, 1, addr+1, size+1) != 0
 	|| bus_space_map(faa->faa_bst, addr[1], size[1], 0, ) != 0) {
-		aprint_error(": unable to map device eeprom\n");
+		aprint_error_dev(self, "unable to map device eeprom\n");
 		goto fail;
 	}
 
-	aprint_naive("\n");
-	/* aprint_normal(": Gigabit Ethernet Controller\n"); */
-	aprint_normal_dev(self, "interrupt on %s\n", intrstr);
-
 	sc->sc_dev = self;
 	sc->sc_st = bst;
 	sc->sc_sh = bsh;
@@ -681,13 +713,22 @@ scx_fdt_attach(device_t parent, device_t
 	sc->sc_eesh = eebsh;
 	sc->sc_eesz = size[1];
 	sc->sc_dmat = faa->faa_dmat;
-	sc->sc_dmat32 = faa->faa_dmat; /* XXX */
 	sc->sc_phandle = phandle;
 
-	phy_mode = fdtbus_get_string(phandle, "phy-mode");
-	if (phy_mode == NULL)
-		aprint_error(": missing 'phy-mode' property\n");
-	sc->sc_100mii = (phy_mode  && strcmp(phy_mode, "rgmii") != 0);
+	phy_type = fdtbus_get_string(phandle, "phy-mode");
+	if (phy_type == NULL)
+		aprint_error_dev(self, "missing 'phy-mode' property\n");
+	phy_phandle = fdtbus_get_phandle(phandle, "phy-handle");	
+	if (phy_phandle == -1
+	|| fdtbus_get_reg(phy_phandle, 0, _id, NULL) != 0)
+		phy_id = MII_PHY_ANY;
+	ref_clk = get_clk_freq(phandle, "phy_ref_clk");
+	if (ref_clk == -1)
+		ref_clk = 250 * 1000 * 1000;
+
+	sc->sc_100mii = (phy_type && strncmp(phy_type, "rgmii", 5) != 0);
+	sc->sc_phy_id = phy_id;
+	sc->sc_freq = ref_clk;
 
 	scx_attach_i(sc);
 	return;
@@ -718,23 +759,26 @@ scx_acpi_attach(device_t parent, device_
 	struct acpi_resources res;
 	struct acpi_mem *mem;
 	struct acpi_irq *irq;
-	char *phy_mode;
-	ACPI_INTEGER 

CVS commit: src/sys/arch/arm/sociox

2021-12-19 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Mon Dec 20 06:47:25 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
- iron out attach error case messages
- use 64-bit paddr bus_dma_tag
- dig and decode FDT "clock-frequency" value


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-19 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Mon Dec 20 02:24:33 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
development snapshot; endianness and others.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.28 src/sys/arch/arm/sociox/if_scx.c:1.29
--- src/sys/arch/arm/sociox/if_scx.c:1.28	Mon Dec 20 02:23:04 2021
+++ src/sys/arch/arm/sociox/if_scx.c	Mon Dec 20 02:24:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.28 2021/12/20 02:23:04 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.29 2021/12/20 02:24:33 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.28 2021/12/20 02:23:04 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.29 2021/12/20 02:24:33 nisimura Exp $");
 
 #include 
 #include 
@@ -482,8 +482,8 @@ struct scx_softc {
 	int sc_rxptr;			/* next ready Rx descriptor/descsoft */
 
 	krndsource_t rnd_source;	/* random source */
-#ifdef GMAC_EVENT_COUNTER
-	/* 80 event counter exist */
+#ifdef GMAC_EVENT_COUNTERS
+	/* 80 event counters exist */
 #endif
 };
 
@@ -524,11 +524,11 @@ do {	\
 	struct mbuf *__m = __rxs->rxs_mbuf;\
 	bus_addr_t __paddr =__rxs->rxs_dmamap->dm_segs[0].ds_addr;	\
 	__m->m_data = __m->m_ext.ext_buf;\
-	__rxd->r3 = __rxs->rxs_dmamap->dm_segs[0].ds_len;		\
+	__rxd->r3 = htole32(__rxs->rxs_dmamap->dm_segs[0].ds_len);	\
 	__rxd->r2 = htole32(BUS_ADDR_LO32(__paddr));			\
 	__rxd->r1 = htole32(BUS_ADDR_HI32(__paddr));			\
-	__rxd->r0 = R0_OWN | R0_FS | R0_LS;\
-	if ((x) == MD_NRXDESC - 1) __rxd->r0 |= R0_EOD;			\
+	__rxd->r0 = htole32(R0_OWN | R0_FS | R0_LS);			\
+	if ((x) == MD_NRXDESC - 1) __rxd->r0 |= htole32(R0_EOD);	\
 } while (/*CONSTCOND*/0)
 
 /* memory mapped CSR register access */
@@ -1334,20 +1334,20 @@ scx_start(struct ifnet *ifp)
 			 * yet.	 That could cause a race condition.
 			 * We'll do it below.
 			 */
-			tdes->t3 = dmamap->dm_segs[seg].ds_len;
+			tdes->t3 = htole32(dmamap->dm_segs[seg].ds_len);
 			tdes->t2 = htole32(BUS_ADDR_LO32(paddr));
 			tdes->t1 = htole32(BUS_ADDR_HI32(paddr));
-			tdes->t0 = tdes0 | (tdes->t0 & T0_EOD) |
+			tdes->t0 = htole32(tdes0 | (tdes->t0 & T0_EOD) |
 	(15 << T0_TDRID) | T0_PT |
-	sc->sc_t0cotso | T0_TRS;
+	sc->sc_t0cotso | T0_TRS);
 			tdes0 = T0_OWN; /* 2nd and other segments */
 			/* NB; t0 DRID field contains zero */
 			lasttx = nexttx;
 		}
 
 		/* Write deferred 1st segment T0_OWN at the final stage */
-		sc->sc_txdescs[lasttx].t0 |= T0_LS;
-		sc->sc_txdescs[sc->sc_txnext].t0 |= (T0_FS | T0_OWN);
+		sc->sc_txdescs[lasttx].t0 |= htole32(T0_LS);
+		sc->sc_txdescs[sc->sc_txnext].t0 |= htole32(T0_FS | T0_OWN);
 		SCX_CDTXSYNC(sc, sc->sc_txnext, dmamap->dm_nsegs,
 		BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
 
@@ -1468,7 +1468,7 @@ rxintr(struct scx_softc *sc)
 		SCX_CDRXSYNC(sc, i,
 		BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
 
-		rxstat = sc->sc_rxdescs[i].r0;
+		rxstat = le32toh(sc->sc_rxdescs[i].r0);
 		if (rxstat & R0_OWN) /* desc is left empty */
 			break;
 
@@ -1569,16 +1569,19 @@ mii_statchg(struct ifnet *ifp)
 
 	/* decode MIISR register value */
 	miisr = mac_read(sc, GMACMIISR);
-	spd = Mbps[(miisr >> 1) & 03];
+	spd = Mbps[(miisr & MIISR_SPD) >> 1];
 #if 1
-	printf("MII link status (0x%x) %s",
-	miisr, (miisr & 8) ? "up" : "down");
-	if (miisr & 8) {
-		printf(" spd%d", spd);
-		if (miisr & 01)
-			printf(",full-duplex");
+	static uint32_t oldmiisr = 0;
+	if (miisr != oldmiisr) {
+		printf("MII link status (0x%x) %s",
+		miisr, (miisr & MIISR_LUP) ? "up" : "down");
+		if (miisr & MIISR_LUP) {
+			printf(" spd%d", spd);
+			if (miisr & MIISR_FDX)
+printf(",full-duplex");
+		}
+		printf("\n");
 	}
-	printf("\n");
 #endif
 	/* Get flow control negotiation result. */
 	if (IFM_SUBTYPE(mii->mii_media.ifm_cur->ifm_media) == IFM_AUTO &&
@@ -1601,7 +1604,7 @@ mii_statchg(struct ifnet *ifp)
 	/* Adjust duplexity and PAUSE flow control. */
 	mcr &= ~MCR_USEFDX;
 	fcr = mac_read(sc, GMACFCR) & ~(FCR_TFE | FCR_RFE);
-	if (miisr & 01) {
+	if (miisr & MIISR_FDX) {
 		if (sc->sc_flowflags & IFM_ETH_TXPAUSE)
 			fcr |= FCR_TFE;
 		if (sc->sc_flowflags & IFM_ETH_RXPAUSE)
@@ -1611,8 +1614,14 @@ mii_statchg(struct ifnet *ifp)
 	mac_write(sc, GMACMCR, mcr);
 	mac_write(sc, GMACFCR, fcr);
 
-printf("%ctxfe, %crxfe\n",
- (fcr & FCR_TFE) ? '+' : '-', (fcr & FCR_RFE) ? '+' : '-');
+#if 1
+	if (miisr != oldmiisr) {
+		printf("%ctxfe, %crxfe\n",
+		(fcr & FCR_TFE) ? '+' : '-',
+		(fcr & FCR_RFE) ? '+' : '-');
+	}
+	oldmiisr = miisr;
+#endif
 }
 
 static void
@@ -1680,6 +1689,7 @@ phy_tick(void *arg)
 	mii_tick(mii);
 	splx(s);
 #ifdef 

CVS commit: src/sys/arch/arm/sociox

2021-12-19 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Mon Dec 20 02:24:33 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
development snapshot; endianness and others.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-19 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Mon Dec 20 02:23:04 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
fix and improve register definitions


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.27 src/sys/arch/arm/sociox/if_scx.c:1.28
--- src/sys/arch/arm/sociox/if_scx.c:1.27	Thu Dec 16 11:36:25 2021
+++ src/sys/arch/arm/sociox/if_scx.c	Mon Dec 20 02:23:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.27 2021/12/16 11:36:25 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.28 2021/12/20 02:23:04 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.27 2021/12/16 11:36:25 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.28 2021/12/20 02:23:04 nisimura Exp $");
 
 #include 
 #include 
@@ -126,7 +126,7 @@ struct rdes {
 #define  RPTHDCOMP	(1U<<2)		/* log HD imcomplete condition */
 #define  RPTHDERR	(1U<<1)		/* log HD error */
 #define  DROPNOMATCH	(1U<<0)		/* drop no match frames */
-#define xINTSR		0x200		/* aggregated interrupt status report */
+#define xINTSR		0x200		/* aggregated interrupt status */
 #define  IRQ_RX		(1U<<1)		/* top level Rx interrupt */
 #define  IRQ_TX		(1U<<0)		/* top level Rx interrupt */
 #define  IRQ_UCODE	(1U<<20)	/* ucode load completed */
@@ -144,18 +144,18 @@ struct rdes {
 #define  TXI_TR_ERR	(1U<<16)	/* tx error */
 #define  TXI_TXDONE	(1U<<15)	/* tx completed */
 #define  TXI_TMREXP	(1U<<14)	/* coalesce timer expired */
-#define RXISR		0x440		/* receipt status */
+#define RXISR		0x440		/* receive status */
 #define RXIEN		0x444		/* rx interrupt enable */
 #define RXIE_SET	0x468		/* bit to set */
 #define RXIE_CLR	0x46c		/* bit to clr */
 #define  RXI_RC_ERR	(1U<<16)	/* rx error */
-#define  RXI_PKTCNT	(1U<<15)	/* rx counter has new value report */
+#define  RXI_PKTCNT	(1U<<15)	/* rx counter has new value */
 #define  RXI_TMREXP	(1U<<14)	/* coalesce timer expired */
 #define TDBA_LO		0x408		/* tdes array base addr 31:0 */
 #define TDBA_HI		0x434		/* tdes array base addr 63:32 */
 #define RDBA_LO		0x448		/* rdes array base addr 31:0 */
 #define RDBA_HI		0x474		/* rdes array base addr 63:32 */
-/* 13 pairs of special purpose desc array address registers exit */
+/* 13 pairs of special purpose desc array base address register exist */
 #define TXCONF		0x430
 #define RXCONF		0x470
 #define  DESCNF_UP	(1U<<31)	/* up-and-running */
@@ -166,8 +166,8 @@ struct rdes {
 #define RXCOLMAX	0x454		/* rx intr coalesce upper bound */
 #define TXITIMER	0x420		/* coalesce timer usec, MSB to use */
 #define RXITIMER	0x460		/* coalesce timer usec, MSB to use */
-#define TXDONECNT	0x424		/* tx completion report, auto-clear */
-#define RXDONECNT	0x458		/* rx completion report, auto-clear */
+#define TXDONECNT	0x424		/* tx completed count, auto-zero */
+#define RXDONECNT	0x458		/* rx available count, auto-zero */
 #define UCODE_H2M	0x210		/* host2media engine ucode port */
 #define UCODE_M2H	0x21c		/* media2host engine ucode port */
 #define CORESTAT	0x218		/* engine run state */
@@ -214,15 +214,18 @@ struct rdes {
 #define  MCR_IBN	(1U<<30)	/* ??? */
 #define  MCR_CST	(1U<<25)	/* strip CRC */
 #define  MCR_TC		(1U<<24)	/* keep RGMII PHY notified */
-#define  MCR_JE		(1U<<20)	/* ignore oversized >9018 condition */
+#define  MCR_WD		(1U<<23)	/* allow long >2048 tx frame */
+#define  MCR_JE		(1U<<20)	/* allow ~9018 tx jumbo frame */
 #define  MCR_IFG	(7U<<17)	/* 19:17 IFG value 0~7 */
 #define  MCR_DRCS	(1U<<16)	/* ignore (G)MII HDX Tx error */
 #define  MCR_USEMII	(1U<<15)	/* 1: RMII/MII, 0: RGMII (_PS) */
 #define  MCR_SPD100	(1U<<14)	/* force speed 100 (_FES) */
-#define  MCR_DO		(1U<<13)	/* ??? don't receive my own Tx frames */
+#define  MCR_DO		(1U<<13)	/* don't receive my own HDX Tx frames */
 #define  MCR_LOOP	(1U<<12)	/* run loop back */
 #define  MCR_USEFDX	(1U<<11)	/* force full duplex */
 #define  MCR_IPCEN	(1U<<10)	/* handle checksum */
+#define  MCR_DR		(1U<<9)		/* attempt no tx retry, send once */
+#define  MCR_LUD	(1U<<8)		/* link condition report when RGMII */
 #define  MCR_ACS	(1U<<7)		/* auto pad strip CRC */
 #define  MCR_TE		(1U<<3)		/* run Tx MAC engine, 0 to stop */
 #define  MCR_RE		(1U<<2)		/* run Rx MAC engine, 0 to stop */
@@ -258,12 +261,9 @@ struct rdes {
 /* 31:16 pause timer value, 5:4 pause timer threshold */
 #define  FCR_RFE	(1U<<2)		/* accept PAUSE to throttle Tx */
 #define  FCR_TFE	(1U<<1)		/* generate PAUSE to moderate Rx lvl */
-#define GMACVTAG	0x001c		/* VLAN tag control */
-#define GMACIMPL	0x0020		/* implementation number XX.YY */
-#define GMACLPIS	0x0030		/* ??? AXI LPI control */
-#define GMACLPIC	0x0034		/* ??? AXI LPI 

CVS commit: src/sys/arch/arm/sociox

2021-12-19 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Mon Dec 20 02:23:04 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
fix and improve register definitions


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-16 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Dec 16 11:36:26 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
interlim commit to snapshot SC2A11 GbE progress.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.26 src/sys/arch/arm/sociox/if_scx.c:1.27
--- src/sys/arch/arm/sociox/if_scx.c:1.26	Thu Dec 16 11:32:22 2021
+++ src/sys/arch/arm/sociox/if_scx.c	Thu Dec 16 11:36:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.26 2021/12/16 11:32:22 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.27 2021/12/16 11:36:25 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.26 2021/12/16 11:32:22 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.27 2021/12/16 11:36:25 nisimura Exp $");
 
 #include 
 #include 
@@ -408,7 +408,7 @@ struct scx_softc {
 	int sc_phy_id;			/* PHY address */
 	int sc_flowflags;		/* 802.3x PAUSE flow control */
 	uint32_t sc_mdclk;		/* GAR 5:2 clock selection */
-	uint32_t sc_t0coso;		/* T0_CSUM | T0_SGOL to run */
+	uint32_t sc_t0cotso;		/* T0_CSUM | T0_TSO to run */
 	int sc_ucodeloaded;		/* ucode for H2M/M2H/PKT */
 	int sc_100mii;			/* 1 for RMII/MII, 0 for RGMII */
 	int sc_phandle;			/* fdt phandle */
@@ -431,6 +431,9 @@ struct scx_softc {
 	int sc_rxptr;			/* next ready Rx descriptor/descsoft */
 
 	krndsource_t rnd_source;	/* random source */
+#ifdef GMAC_EVENT_COUNTER
+	/* 80 event counter exist */
+#endif
 };
 
 #define SCX_CDTXADDR(sc, x)	((sc)->sc_cddma + SCX_CDTXOFF((x)))
@@ -477,6 +480,16 @@ do {	\
 	if ((x) == MD_NRXDESC - 1) __rxd->r0 |= R0_EOD;			\
 } while (/*CONSTCOND*/0)
 
+/* memory mapped CSR register access */
+#define CSR_READ(sc,off) \
+	bus_space_read_4((sc)->sc_st, (sc)->sc_sh, (off))
+#define CSR_WRITE(sc,off,val) \
+	bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (off), (val))
+
+/* flash memory access */
+#define EE_READ(sc,off) \
+	bus_space_read_4((sc)->sc_st, (sc)->sc_eesh, (off))
+
 static int scx_fdt_match(device_t, cfdata_t, void *);
 static void scx_fdt_attach(device_t, device_t, void *);
 static int scx_acpi_match(device_t, cfdata_t, void *);
@@ -558,6 +571,10 @@ static const struct device_compatible_en
 	{ .compat = "socionext,synquacer-netsec" },
 	DEVICE_COMPAT_EOL
 };
+static const struct device_compatible_entry compatible[] = {
+	{ .compat = "SCX0001" },
+	DEVICE_COMPAT_EOL
+};
 
 static int
 scx_fdt_match(device_t parent, cfdata_t cf, void *aux)
@@ -634,15 +651,9 @@ scx_fdt_attach(device_t parent, device_t
 static int
 scx_acpi_match(device_t parent, cfdata_t cf, void *aux)
 {
-	static const char * compatible[] = {
-		"SCX0001",
-		NULL
-	};
 	struct acpi_attach_args *aa = aux;
 
-	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
-		return 0;
-	return acpi_match_hid(aa->aa_node->ad_devinfo, compatible);
+	return acpi_compatible_match(aa, compatible);
 }
 
 static void
@@ -660,6 +671,7 @@ scx_acpi_attach(device_t parent, device_
 	ACPI_INTEGER acpi_phy, acpi_freq;
 	ACPI_STATUS rv;
 
+aprint_normal(": Gigabit Ethernet Controller\n");
 	rv = acpi_resource_parse(self, handle, "_CRS",
 	, _resource_parse_ops_default);
 	if (ACPI_FAILURE(rv))
@@ -713,7 +725,7 @@ scx_acpi_attach(device_t parent, device_
 	sc->sc_sh = bsh;
 	sc->sc_eesh = eebsh;
 	sc->sc_dmat = aa->aa_dmat64;
-	sc->sc_dmat32 = aa->aa_dmat;	/* descriptor needs dma32 */
+	sc->sc_dmat32 = aa->aa_dmat;
 
 aprint_normal_dev(self,
 "phy mode %s, phy id %d, freq %ld\n", phy_mode, (int)acpi_phy, acpi_freq);
@@ -742,18 +754,19 @@ scx_attach_i(struct scx_softc *sc)
 	struct ifnet * const ifp = >sc_ethercom.ec_if;
 	struct mii_data * const mii = >sc_mii;
 	struct ifmedia * const ifm = >mii_media;
-	uint32_t hwver, dwimp, dwfea;
+	uint32_t which, dwimp, dwfea;
 	uint8_t enaddr[ETHER_ADDR_LEN];
 	bus_dma_segment_t seg;
 	uint32_t csr;
 	int i, nseg, error = 0;
 
-	hwver = CSR_READ(sc, HWVER);	/* Socionext version */
-	dwimp = mac_read(sc, GMACIMPL);	/* DW EMAC XX.YY */
-	dwfea = mac_read(sc, HWFEA);	/* DW feature */
+	which = CSR_READ(sc, HWVER);	/* Socionext version 5.00xx */
+	dwimp = mac_read(sc, GMACIMPL);	/* DWC EMAC XX.YY */
+	dwfea = mac_read(sc, HWFEA);	/* DWC feature */
 	aprint_normal_dev(sc->sc_dev,
-	"Socionext NetSec GbE %d.%d (impl 0x%x, feature 0x%x)\n",
-	hwver >> 16, hwver & 0x,
+	"Socionext NetSec GbE %x.%x"
+	" (impl 0x%x, feature 0x%x)\n",
+	which >> 16, which & 0x,
 	dwimp, dwfea);
 
 	/* fetch MAC address in flash. stored in big endian order */
@@ -762,14 +775,13 @@ scx_attach_i(struct scx_softc *sc)
 	enaddr[1] = csr >> 16;
 	enaddr[2] = csr >> 8;
 	enaddr[3] = csr;
-	csr = bus_space_read_4(sc->sc_st, 

CVS commit: src/sys/arch/arm/sociox

2021-12-16 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Dec 16 11:36:26 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
interlim commit to snapshot SC2A11 GbE progress.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-16 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Dec 16 11:32:23 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
improve SC2A11 hardware register description.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.25 src/sys/arch/arm/sociox/if_scx.c:1.26
--- src/sys/arch/arm/sociox/if_scx.c:1.25	Mon Aug  2 12:56:22 2021
+++ src/sys/arch/arm/sociox/if_scx.c	Thu Dec 16 11:32:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.25 2021/08/02 12:56:22 andvar Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.26 2021/12/16 11:32:22 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
 #define NOT_MP_SAFE	0
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.25 2021/08/02 12:56:22 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.26 2021/12/16 11:32:22 nisimura Exp $");
 
 #include 
 #include 
@@ -73,7 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #include 
 #include 
 
-/* Socionext SC2A11 descriptor format */
+/* SC2A11 GbE 64-bit paddr descriptor */
 struct tdes {
 	uint32_t t0, t1, t2, t3;
 };
@@ -84,103 +84,131 @@ struct rdes {
 
 #define T0_OWN		(1U<<31)	/* desc is ready to Tx */
 #define T0_EOD		(1U<<30)	/* end of descriptor array */
-#define T0_DRID		(24)		/* 29:24 D-RID */
-#define T0_PT		(1U<<21)	/* 23:21 PT */
-#define T0_TRID		(16)		/* 20:16 T-RID */
+#define T0_DRID		(24)		/* 29:24 desc ring id */
+#define T0_PT		(1U<<21)	/* 23:21 "pass-through" */
+#define T0_TDRID	(16)		/* 20:16 target desc ring id: GMAC=15 */
 #define T0_FS		(1U<<9)		/* first segment of frame */
 #define T0_LS		(1U<<8)		/* last segment of frame */
 #define T0_CSUM		(1U<<7)		/* enable check sum offload */
-#define T0_SGOL		(1U<<6)		/* enable TCP segment offload */
-#define T0_TRS		(1U<<4)		/* 5:4 TRS */
-#define T0_IOC		(0)		/* XXX TBD interrupt when completed */
-/* T1 segment address 63:32 */
-/* T2 segment address 31:0 */
-/* T3 31:16 TCP segment length, 15:0 segment length to transmit */
+#define T0_TSO		(1U<<6)		/* enable TCP segment offload */
+#define T0_TRS		(1U<<4)		/* 5:4 "TRS" */
+/* T1 frame segment address 63:32 */
+/* T2 frame segment address 31:0 */
+/* T3 31:16 TCP segment length, 15:0 frame segment length to transmit */
 
 #define R0_OWN		(1U<<31)	/* desc is empty */
 #define R0_EOD		(1U<<30)	/* end of descriptor array */
-#define R0_SRID		(24)		/* 29:24 S-RID */
-#define R0_FR		(1U<<23)	/* FR */
+#define R0_SDRID	(24)		/* 29:24 source desc ring id */
+#define R0_FR		(1U<<23)	/* found fragmented */
 #define R0_ER		(1U<<21)	/* Rx error indication */
 #define R0_ERR		(3U<<16)	/* 18:16 receive error code */
-#define R0_TDRID	(14)		/* 15:14 TD-RID */
+#define R0_TDRID	(12)		/* 15:12 target desc ring id */
 #define R0_FS		(1U<<9)		/* first segment of frame */
 #define R0_LS		(1U<<8)		/* last segment of frame */
 #define R0_CSUM		(3U<<6)		/* 7:6 checksum status */
-#define R0_CERR		(2U<<6)		/* 0 (undone), 1 (found ok), 2 (bad) */
+#define R0_CERR		(2U<<6)		/* 0: undone, 1: found ok, 2: bad */
 /* R1 frame address 63:32 */
 /* R2 frame address 31:0 */
 /* R3 31:16 received frame length, 15:0 buffer length to receive */
 
 /*
- * SC2A11 NetSec registers. 0x100 - 1204
+ * SC2A11 registers. 0x100 - 1204
  */
 #define SWRESET		0x104
+#define  SRST_RUN	(1U<<31)	/* instruct start, 0 to stop */
 #define COMINIT		0x120
+#define  INIT_DB	(1U<<2)		/* ???; self clear when done */
+#define  INIT_CLS	(1U<<1)		/* ???; self clear when done */
+#define PKTCTRL		0x140		/* pkt engine control */
+#define  MODENRM	(1U<<28)	/* change mode to normal */
+#define  ENJUMBO	(1U<<27)	/* allow jumbo frame */
+#define  RPTCSUMERR	(1U<<3)		/* log Rx checksum error */
+#define  RPTHDCOMP	(1U<<2)		/* log HD imcomplete condition */
+#define  RPTHDERR	(1U<<1)		/* log HD error */
+#define  DROPNOMATCH	(1U<<0)		/* drop no match frames */
 #define xINTSR		0x200		/* aggregated interrupt status report */
 #define  IRQ_RX		(1U<<1)		/* top level Rx interrupt */
 #define  IRQ_TX		(1U<<0)		/* top level Rx interrupt */
+#define  IRQ_UCODE	(1U<<20)	/* ucode load completed */
 #define xINTAEN		0x204		/* INT_A enable */
-#define xINTA_SET	0x234		/* bit to set */
-#define xINTA_CLR	0x238		/* bit to clr */
+#define xINTAE_SET	0x234		/* bit to set */
+#define xINTAE_CLR	0x238		/* bit to clr */
 #define xINTBEN		0x23c		/* INT_B enable */
-#define xINTB_SET	0x240		/* bit to set */
-#define xINTB_CLR	0x244		/* bit to clr */
-/* 0x00c - 048 */			/* pkt,tls,s0,s1 SR/IE/SET/CLR */
-#define TXISR		0x400
-#define TXIEN		0x404
-#define TXI_SET		0x428
-#define TXI_CLR		0x42c
-#define  TXI_NTOWNR	(1U<<17)
-#define  TXI_TR_ERR	(1U<<16)
-#define  TXI_TXDONE	(1U<<15)
-#define  TXI_TMREXP	(1U<<14)
-#define RXISR		0x440
-#define RXIEN		0x444

CVS commit: src/sys/arch/arm/sociox

2021-12-16 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Dec 16 11:32:23 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
improve SC2A11 hardware register description.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-02 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Dec  3 05:28:33 UTC 2021

Removed Files:
src/sys/arch/arm/sociox: sni_exiu.c

Log Message:
retire sni_exiu.c in favour of ACPI0013 generic event divice to
respond power button press.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r0 src/sys/arch/arm/sociox/sni_exiu.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-02 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Dec  3 05:28:33 UTC 2021

Removed Files:
src/sys/arch/arm/sociox: sni_exiu.c

Log Message:
retire sni_exiu.c in favour of ACPI0013 generic event divice to
respond power button press.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r0 src/sys/arch/arm/sociox/sni_exiu.c

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



CVS commit: src/sys/arch/arm/sociox

2021-12-02 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Dec  3 05:21:52 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: files.sociox

Log Message:
retire sni_exiu.c in favour of ACPI0013 generic event device implemented
by dev/acpi/acpi_ged.c


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/sociox/files.sociox

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/sociox/files.sociox
diff -u src/sys/arch/arm/sociox/files.sociox:1.9 src/sys/arch/arm/sociox/files.sociox:1.10
--- src/sys/arch/arm/sociox/files.sociox:1.9	Thu Mar 19 22:17:45 2020
+++ src/sys/arch/arm/sociox/files.sociox	Fri Dec  3 05:21:52 2021
@@ -1,6 +1,6 @@
-#	$NetBSD: files.sociox,v 1.9 2020/03/19 22:17:45 nisimura Exp $
+#	$NetBSD: files.sociox,v 1.10 2021/12/03 05:21:52 nisimura Exp $
 #
-# Configuration info for Socionext Unifier/SC2A11
+# Configuration info for Socionext SC2A11
 #
 #
 
@@ -32,9 +32,3 @@ device	snigpio: gpiobus
 attach	snigpio at acpinodebus with snigpio_acpi
 attach	snigpio at fdt with snigpio_fdt
 file	arch/arm/sociox/sni_gpio.c		snigpio
-
-# Socionext EXIU external interrupt controller unit
-device	sniexiu
-attach	sniexiu at acpinodebus with sniexitu_acpi
-attach	sniexiu at fdt with sniexiu_fdt
-file	arch/arm/sociox/sni_exiu.c		sniexiu



CVS commit: src/sys/arch/arm/sociox

2021-12-02 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Dec  3 05:21:52 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: files.sociox

Log Message:
retire sni_exiu.c in favour of ACPI0013 generic event device implemented
by dev/acpi/acpi_ged.c


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/sociox/files.sociox

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



CVS commit: src/sys/arch/arm/sociox

2021-11-10 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Nov 10 17:23:46 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c

Log Message:
s/intialize/initialize/


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/sociox/sni_emmc.c

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/sociox/sni_emmc.c
diff -u src/sys/arch/arm/sociox/sni_emmc.c:1.8 src/sys/arch/arm/sociox/sni_emmc.c:1.9
--- src/sys/arch/arm/sociox/sni_emmc.c:1.8	Wed Jan 27 03:10:19 2021
+++ src/sys/arch/arm/sociox/sni_emmc.c	Wed Nov 10 17:23:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_emmc.c,v 1.8 2021/01/27 03:10:19 thorpej Exp $	*/
+/*	$NetBSD: sni_emmc.c,v 1.9 2021/11/10 17:23:46 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.8 2021/01/27 03:10:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.9 2021/11/10 17:23:46 msaitoh Exp $");
 
 #include 
 #include 
@@ -228,7 +228,7 @@ sniemmc_attach_i(device_t self)
 #endif
 	error = 0;
 	if (error) {
-		aprint_error_dev(self, "couldn't intialize host, error=%d\n",error);
+		aprint_error_dev(self, "couldn't initialize host, error=%d\n",error);
 		goto fail;
 	}
 	return;



CVS commit: src/sys/arch/arm/sociox

2021-11-10 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Nov 10 17:23:46 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c

Log Message:
s/intialize/initialize/


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/sociox/sni_emmc.c

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



CVS commit: src/sys/arch/arm/sociox

2021-01-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 27 02:03:10 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_ave.c

Log Message:
Use DEVICE_COMPAT_EOL.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/sociox/if_ave.c

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/sociox/if_ave.c
diff -u src/sys/arch/arm/sociox/if_ave.c:1.19 src/sys/arch/arm/sociox/if_ave.c:1.20
--- src/sys/arch/arm/sociox/if_ave.c:1.19	Mon Jan 25 14:20:38 2021
+++ src/sys/arch/arm/sociox/if_ave.c	Wed Jan 27 02:03:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ave.c,v 1.19 2021/01/25 14:20:38 thorpej Exp $	*/
+/*	$NetBSD: if_ave.c,v 1.20 2021/01/27 02:03:10 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1.19 2021/01/25 14:20:38 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1.20 2021/01/27 02:03:10 thorpej Exp $");
 
 #include 
 #include 
@@ -327,7 +327,7 @@ static const struct device_compatible_en
 	{ .compat = "socionext,unifier-pxs2-ave4", .value = 32 },
 	{ .compat = "socionext,unifier-ld11-ave4", .value = 32 },
 	{ .compat = "socionext,unifier-pxs3-ave4", .value = 32 },
-	{ }
+	DEVICE_COMPAT_EOL
 };
 
 static int



CVS commit: src/sys/arch/arm/sociox

2021-01-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 27 02:03:10 UTC 2021

Modified Files:
src/sys/arch/arm/sociox: if_ave.c

Log Message:
Use DEVICE_COMPAT_EOL.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/sociox/if_ave.c

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



CVS commit: src/sys/arch/arm/sociox

2020-10-09 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Sat Oct 10 03:29:48 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
reorder functions for better relevance


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.22 src/sys/arch/arm/sociox/if_scx.c:1.23
--- src/sys/arch/arm/sociox/if_scx.c:1.22	Sat Mar 28 13:15:24 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Sat Oct 10 03:29:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.22 2020/03/28 13:15:24 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.23 2020/10/10 03:29:48 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,35 +29,24 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#define NOT_MP_SAFE	0
 
 /*
  * Socionext SC2A11 SynQuacer NetSec GbE driver
  *
- *   (possibly incorrect notes to be removed eventually)
- * - 32 byte descriptor for 64 bit paddr design.
- * - multiple rings seems available. There are special descriptor fields
- *   to designify ring number from which to arrive or to which go.
- * - memory mapped EEPROM to hold MAC address. The rest of the area is
- *   occupied by a set of ucode for two DMA engines and one packet engine.
- * - The size of frame address filter is 16 plus 16.
- * - The first slot is my own station address. Always enabled to perform
- *   to identify oneself.
- * - 1~15 are for supplimental MAC addresses. Independently enabled for
- *   use. Good to catch multicast. Byte-wise selective match available.
- *   Use the mask to catch { 0x01, 0x00, 0x00 } and/or { 0x33, 0x33 }.
- * - 16~32 might be exact match without byte-mask.
- * - The size of multicast hash filter store is 64 bit.
- * - Socionext/Linaro "NetSec" code contains some constants left unexplained.
- *   Fortunately, Intel/Altera CycloneV PDFs describe every detail of
- *   "such the instance of" DW EMAC IP and most of them are likely applicable
- *   to SC2A11 GbE.
- * - not known "NetSec" instanciates DW timestamp or builds its own.
- * - DW EMAC implmentation (0x20) is known 0x10.36
+ * Multiple Tx and Rx queues exist inside and dedicated descriptor
+ * fields specifies which queue is to use. Three internal micro-processors
+ * to handle incoming frames, outgoing frames and packet data crypto
+ * processing. uP programs are stored in an external flash memory and
+ * have to be loaded by device driver.
+ * NetSec uses Synopsys DesignWare Core EMAC.  DWC implmentation
+ * regiter (0x20) is known to have 0x10.36 and feature register (0x1058)
+ * to report XX.XX.
  */
 
+#define NOT_MP_SAFE	0
+
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.22 2020/03/28 13:15:24 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.23 2020/10/10 03:29:48 nisimura Exp $");
 
 #include 
 #include 
@@ -84,8 +73,47 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #include 
 #include 
 
+/* Socionext SC2A11 descriptor format */
+struct tdes {
+	uint32_t t0, t1, t2, t3;
+};
+
+struct rdes {
+	uint32_t r0, r1, r2, r3;
+};
+
+#define T0_OWN		(1U<<31)	/* desc is ready to Tx */
+#define T0_EOD		(1U<<30)	/* end of descriptor array */
+#define T0_DRID		(24)		/* 29:24 D-RID */
+#define T0_PT		(1U<<21)	/* 23:21 PT */
+#define T0_TRID		(16)		/* 20:16 T-RID */
+#define T0_FS		(1U<<9)		/* first segment of frame */
+#define T0_LS		(1U<<8)		/* last segment of frame */
+#define T0_CSUM		(1U<<7)		/* enable check sum offload */
+#define T0_SGOL		(1U<<6)		/* enable TCP segment offload */
+#define T0_TRS		(1U<<4)		/* 5:4 TRS */
+#define T0_IOC		(0)		/* XXX TBD interrupt when completed */
+/* T1 segment address 63:32 */
+/* T2 segment address 31:0 */
+/* T3 31:16 TCP segment length, 15:0 segment length to transmit */
+
+#define R0_OWN		(1U<<31)	/* desc is empty */
+#define R0_EOD		(1U<<30)	/* end of descriptor array */
+#define R0_SRID		(24)		/* 29:24 S-RID */
+#define R0_FR		(1U<<23)	/* FR */
+#define R0_ER		(1U<<21)	/* Rx error indication */
+#define R0_ERR		(3U<<16)	/* 18:16 receive error code */
+#define R0_TDRID	(14)		/* 15:14 TD-RID */
+#define R0_FS		(1U<<9)		/* first segment of frame */
+#define R0_LS		(1U<<8)		/* last segment of frame */
+#define R0_CSUM		(3U<<6)		/* 7:6 checksum status */
+#define R0_CERR		(2U<<6)		/* 0 (undone), 1 (found ok), 2 (bad) */
+/* R1 frame address 63:32 */
+/* R2 frame address 31:0 */
+/* R3 31:16 received frame length, 15:0 buffer length to receive */
+
 /*
- * SC2A11 register block 0x100-0x1204?
+ * SC2A11 NetSec registers. 0x100 - 1204
  */
 #define SWRESET		0x104
 #define COMINIT		0x120
@@ -98,7 +126,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define xINTBEN		0x23c		/* INT_B enable */
 #define xINTB_SET	0x240		/* bit to set */
 #define xINTB_CLR	0x244		/* bit to clr */
-/* 0x00c-048 */		/* pkt,tls,s0,s1 SR/IE/SET/CLR */
+/* 0x00c - 048 

CVS commit: src/sys/arch/arm/sociox

2020-10-09 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Sat Oct 10 03:29:48 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
reorder functions for better relevance


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-09-23 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Sep 23 23:38:24 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_ave.c

Log Message:
note more about AVE EMAC design


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/sociox/if_ave.c

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/sociox/if_ave.c
diff -u src/sys/arch/arm/sociox/if_ave.c:1.16 src/sys/arch/arm/sociox/if_ave.c:1.17
--- src/sys/arch/arm/sociox/if_ave.c:1.16	Fri Mar 27 13:00:22 2020
+++ src/sys/arch/arm/sociox/if_ave.c	Wed Sep 23 23:38:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ave.c,v 1.16 2020/03/27 13:00:22 nisimura Exp $	*/
+/*	$NetBSD: if_ave.c,v 1.17 2020/09/23 23:38:24 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1.16 2020/03/27 13:00:22 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1.17 2020/09/23 23:38:24 nisimura Exp $");
 
 #include 
 #include 
@@ -63,6 +63,41 @@ __KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1
 
 #define NOT_MP_SAFE	(0)
 
+/*
+ * AVE has two different, rather obscure, descriptor formats. 32-bit
+ * paddr descriptor layout occupies 8 bytes while 64-bit paddr descriptor
+ * does 12 bytes. AVE is a derivative of Synopsys DesignWare Core
+ * EMAC.
+ */
+struct tdes {
+	uint32_t t0, t1, t2;
+};
+
+struct rdes {
+	uint32_t r0, r1, r2;
+};
+
+struct tdes32 { uint32_t t0, t1; };
+struct rdes32 { uint32_t r0, r1; };
+
+#define T0_OWN		(1U<<31)	/* desc is ready to Tx */
+#define T0_IOC		(1U<<29)	/* post interrupt on Tx completes */
+#define T0_NOCSUM	(1U<<28)	/* inhibit checksum operation */
+#define T0_DONEOK	(1U<<27)	/* status - Tx completed ok */
+#define T0_FS		(1U<<26)	/* first segment of frame */
+#define T0_LS		(1U<<25)	/* last segment of frame */
+#define T0_OWC		(1U<<21)	/* status - out of win. late coll. */
+#define T0_ECOL		(1U<<20)	/* status - excess collision */
+#define T0_TBS_MASK	0x		/* T0 segment length 15:0 */
+/* T1 segment address 31:0 */
+/* T2 segment address 63:32 */
+#define R0_OWN		(1U<<31)	/* desc is empty */
+#define R0_CSUM		(1U<<21)	/* receive checksum done */
+#define R0_CERR		(1U<<20)	/* csum found negative */
+#define R0_FL_MASK	0x07ff		/* R0 frame length 10:0 */
+/* R1 frame address 31:0 */
+/* R2 frame address 63:32 */
+
 #define AVEID		0x000		/* hardware ID */
 #define AVEHWVER	0x004		/* hardware version */
 #define AVEGR		0x008		/* chip global control */
@@ -107,17 +142,14 @@ __KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1
 #define  DESCC_RD0	(1U<<3)		/* activate Rx0 descriptor to run */
 #define DESCC_RSTP	(1U<<2)		/* pause Rx descriptor */
 #define  DESCC_TD	(1U<<0)		/* activate Tx descriptor to run */
-	/* 31:16 status report to read */
+/* 31:16 status report to read */
 #define AVETXDES	0x304		/* Tx descriptor control */
-	/* 27:16 Tx descriptor byte count
-	 * 11:0 start address offset */
+/* 27:16 Tx descriptor byte count, 11:0 start address offset */
 #define AVERXDES0	0x308		/* Rx0 descriptor control */
-	/* 30:16 Rx descriptor byte count
-	 * 14:0 start address offset */
+/* 30:16 Rx descriptor byte count, 14:0 start address offset */
 #define AVEITIRQC	0x34c		/* interval IRQ control */
 #define  ITIRQC_R0E	(1U<<27)	/* enable Rx0 interval timer */
-#define  INTMVAL	(20<<16)	/* INTM value */
-	/* 15:0 interval timer count */
+#define  INTMVAL	(20<<16)	/* 15:0 interval timer count */
 
 #define AVEAFB		0x0800		/* address filter base */
 #define AVEAFMSKB	0x0d00		/* byte mask base */
@@ -128,47 +160,21 @@ __KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1
 #define AVEAFRING	0x0f00		/* entry ring number selector */
 #define AVEAFEN		0x0ffc		/* entry enable bit vector */
 
-#define AVETDB		0x1000	/* 64bit Tx descriptor store, upto 256 */
-#define AVERDB		0x1c00	/* 64bit Rx descriptor store, upto 2048 */
-#define AVE32TDB	0x1000	/* 32bit Tx store base, upto 256 */
-#define AVE32RDB	0x1800	/* 32bit Rx store base, upto 2048 */
+/* AVE has internal cache coherent memory tol hold descriptor arrays. */
+#define AVETDB		0x1000		/* 64-bit Tx desc store, upto 256 */
+#define AVERDB		0x1c00		/* 64-bit Rx desc store, upto 2048 */
+#define AVE32TDB	0x1000		/* 32-bit Tx store base, upto 256 */
+#define AVE32RDB	0x1800		/* 32-bit Rx store base, upto 2048 */
 
 #define AVERMIIC	0x8028		/* RMII control */
 #define  RMIIC_RST	(1U<<16)	/* reset operation */
 #define AVELINKSEL	0x8034		/* RMII speed selection */
 #define  LINKSEL_SPD100	(1U<<0)		/* use 100Mbps */
 
-/*
- * descriptor size is 12 bytes when 64bit paddr design, 8 bytes otherwise.
- */
-struct tdes {
-	uint32_t t0, t1, t2;
-};
-
-struct rdes {
-	uint32_t r0, r1, r2;
-};
-
-struct tdes32 { uint32_t t0, t1; };
-struct rdes32 { uint32_t r0, r1; };
-
-#define T0_OWN		(1U<<31)	/* desc is ready to Tx */
-#define T0_IOC		(1U<<29)	/* post interrupt on Tx completes */

CVS commit: src/sys/arch/arm/sociox

2020-09-23 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Sep 23 23:38:24 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_ave.c

Log Message:
note more about AVE EMAC design


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/sociox/if_ave.c

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



CVS commit: src/sys/arch/arm/sociox

2020-05-31 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jun  1 00:00:37 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_i2c.c

Log Message:
Oops, missed a line in the last change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sociox/sni_i2c.c

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/sociox/sni_i2c.c
diff -u src/sys/arch/arm/sociox/sni_i2c.c:1.7 src/sys/arch/arm/sociox/sni_i2c.c:1.8
--- src/sys/arch/arm/sociox/sni_i2c.c:1.7	Sun May 31 23:55:18 2020
+++ src/sys/arch/arm/sociox/sni_i2c.c	Mon Jun  1 00:00:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_i2c.c,v 1.7 2020/05/31 23:55:18 thorpej Exp $	*/
+/*	$NetBSD: sni_i2c.c,v 1.8 2020/06/01 00:00:37 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.7 2020/05/31 23:55:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.8 2020/06/01 00:00:37 thorpej Exp $");
 
 #include 
 #include 
@@ -117,7 +117,6 @@ sniiic_fdt_attach(device_t parent, devic
 {
 	struct sniiic_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
-	prop_dictionary_t dict = device_properties(self);
 	const int phandle = faa->faa_phandle;
 	bus_space_handle_t ioh;
 	bus_addr_t addr;



CVS commit: src/sys/arch/arm/sociox

2020-05-31 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jun  1 00:00:37 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_i2c.c

Log Message:
Oops, missed a line in the last change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sociox/sni_i2c.c

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



CVS commit: src/sys/arch/arm/sociox

2020-05-31 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 31 23:55:18 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c sni_exiu.c sni_gpio.c sni_i2c.c

Log Message:
Remove superfluous checking for a "disable" property in the device_t
properties dictionary.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sociox/sni_emmc.c \
src/sys/arch/arm/sociox/sni_i2c.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sociox/sni_exiu.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sociox/sni_gpio.c

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



CVS commit: src/sys/arch/arm/sociox

2020-05-31 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 31 23:55:18 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c sni_exiu.c sni_gpio.c sni_i2c.c

Log Message:
Remove superfluous checking for a "disable" property in the device_t
properties dictionary.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sociox/sni_emmc.c \
src/sys/arch/arm/sociox/sni_i2c.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sociox/sni_exiu.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sociox/sni_gpio.c

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/sociox/sni_emmc.c
diff -u src/sys/arch/arm/sociox/sni_emmc.c:1.6 src/sys/arch/arm/sociox/sni_emmc.c:1.7
--- src/sys/arch/arm/sociox/sni_emmc.c:1.6	Wed Mar 25 23:20:38 2020
+++ src/sys/arch/arm/sociox/sni_emmc.c	Sun May 31 23:55:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_emmc.c,v 1.6 2020/03/25 23:20:38 nisimura Exp $	*/
+/*	$NetBSD: sni_emmc.c,v 1.7 2020/05/31 23:55:18 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.6 2020/03/25 23:20:38 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.7 2020/05/31 23:55:18 thorpej Exp $");
 
 #include 
 #include 
@@ -100,20 +100,12 @@ sniemmc_fdt_attach(device_t parent, devi
 {
 	struct sniemmc_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
-	prop_dictionary_t dict = device_properties(self);
 	const int phandle = faa->faa_phandle;
 	bus_space_handle_t ioh;
 	bus_addr_t addr;
 	bus_size_t size;
 	char intrstr[128];
-	_Bool disable;
 
-	prop_dictionary_get_bool(dict, "disable", );
-	if (disable) {
-		aprint_naive(": disabled\n");
-		aprint_normal(": disabled\n");
-		return;
-	}
 	if (fdtbus_get_reg(phandle, 0, , ) != 0
 	|| bus_space_map(faa->faa_bst, addr, size, 0, ) != 0) {
 		aprint_error(": unable to map device\n");
Index: src/sys/arch/arm/sociox/sni_i2c.c
diff -u src/sys/arch/arm/sociox/sni_i2c.c:1.6 src/sys/arch/arm/sociox/sni_i2c.c:1.7
--- src/sys/arch/arm/sociox/sni_i2c.c:1.6	Wed Mar 25 23:20:38 2020
+++ src/sys/arch/arm/sociox/sni_i2c.c	Sun May 31 23:55:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_i2c.c,v 1.6 2020/03/25 23:20:38 nisimura Exp $	*/
+/*	$NetBSD: sni_i2c.c,v 1.7 2020/05/31 23:55:18 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.6 2020/03/25 23:20:38 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.7 2020/05/31 23:55:18 thorpej Exp $");
 
 #include 
 #include 
@@ -123,14 +123,7 @@ sniiic_fdt_attach(device_t parent, devic
 	bus_addr_t addr;
 	bus_size_t size;
 	char intrstr[128];
-	_Bool disable;
 
-	prop_dictionary_get_bool(dict, "disable", );
-	if (disable) {
-		aprint_naive(": disabled\n");
-		aprint_normal(": disabled\n");
-		return;
-	}
 	if (fdtbus_get_reg(phandle, 0, , ) != 0
 	|| bus_space_map(faa->faa_bst, addr, size, 0, ) != 0) {
 		aprint_error(": unable to map device\n");

Index: src/sys/arch/arm/sociox/sni_exiu.c
diff -u src/sys/arch/arm/sociox/sni_exiu.c:1.3 src/sys/arch/arm/sociox/sni_exiu.c:1.4
--- src/sys/arch/arm/sociox/sni_exiu.c:1.3	Wed Mar 25 23:29:39 2020
+++ src/sys/arch/arm/sociox/sni_exiu.c	Sun May 31 23:55:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_exiu.c,v 1.3 2020/03/25 23:29:39 nisimura Exp $	*/
+/*	$NetBSD: sni_exiu.c,v 1.4 2020/05/31 23:55:18 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_exiu.c,v 1.3 2020/03/25 23:29:39 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_exiu.c,v 1.4 2020/05/31 23:55:18 thorpej Exp $");
 
 #include 
 #include 
@@ -91,20 +91,12 @@ sniexiu_fdt_attach(device_t parent, devi
 {
 	struct sniexiu_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
-	prop_dictionary_t dict = device_properties(self);
 	const int phandle = faa->faa_phandle;
 	bus_space_handle_t ioh;
 	bus_addr_t addr;
 	bus_size_t size;
 	char intrstr[128];
-	_Bool disable;
 
-	prop_dictionary_get_bool(dict, "disable", );
-	if (disable) {
-		aprint_naive(": disabled\n");
-		aprint_normal(": disabled\n");
-		return;
-	}
 	if (fdtbus_get_reg(phandle, 0, , ) != 0
 	|| bus_space_map(faa->faa_bst, addr, size, 0, ) != 0) {
 		aprint_error(": unable to map device\n");

Index: src/sys/arch/arm/sociox/sni_gpio.c
diff -u src/sys/arch/arm/sociox/sni_gpio.c:1.7 src/sys/arch/arm/sociox/sni_gpio.c:1.8
--- src/sys/arch/arm/sociox/sni_gpio.c:1.7	Wed Mar 25 23:31:19 2020
+++ src/sys/arch/arm/sociox/sni_gpio.c	Sun May 31 23:55:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_gpio.c,v 1.7 2020/03/25 23:31:19 nisimura Exp $	*/
+/*	$NetBSD: sni_gpio.c,v 1.8 2020/05/31 23:55:18 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */

CVS commit: src/sys/arch/arm/sociox

2020-03-28 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Sat Mar 28 13:15:24 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
- comb down rcvfilt() filter adjustment  logic.
- some mii_statchg() can be written in simpler form.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.21 src/sys/arch/arm/sociox/if_scx.c:1.22
--- src/sys/arch/arm/sociox/if_scx.c:1.21	Fri Mar 27 13:00:13 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Sat Mar 28 13:15:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.21 2020/03/27 13:00:13 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.22 2020/03/28 13:15:24 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.21 2020/03/27 13:00:13 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.22 2020/03/28 13:15:24 nisimura Exp $");
 
 #include 
 #include 
@@ -673,7 +673,12 @@ scx_attach_i(struct scx_softc *sc)
 	int i, nseg, error = 0;
 
 	hwver = CSR_READ(sc, HWVER);	/* Socionext HW */
-	/* stored in big endian order */
+	dwimp = mac_read(sc, GMACIMPL);	/* DW EMAC XX.YY */
+	aprint_normal_dev(sc->sc_dev,
+	"Socionext NetSec GbE hw %d.%d impl 0x%x\n",
+	hwver >> 16, hwver & 0x, dwimp);
+
+	/* fetch MAC address in flash. stored in big endian order */
 	csr = bus_space_read_4(sc->sc_st, sc->sc_eesh, 0);
 	enaddr[0] = csr >> 24;
 	enaddr[1] = csr >> 16;
@@ -682,11 +687,6 @@ scx_attach_i(struct scx_softc *sc)
 	csr = bus_space_read_4(sc->sc_st, sc->sc_eesh, 4);
 	enaddr[4] = csr >> 24;
 	enaddr[5] = csr >> 16;
-	dwimp = mac_read(sc, GMACIMPL);	/* DW EMAC XX.YY */
-
-	aprint_normal_dev(sc->sc_dev,
-	"Socionext NetSec GbE hw %d.%d impl 0x%x\n",
-	hwver >> 16, hwver & 0x, dwimp);
 	aprint_normal_dev(sc->sc_dev,
 	"Ethernet address %s\n", ether_sprintf(enaddr));
 
@@ -1024,20 +1024,21 @@ scx_set_rcvfilt(struct scx_softc *sc)
 	csr &= ~(AFR_PR | AFR_PM | AFR_MHTE | AFR_HPF);
 	mac_write(sc, GMACAFR, csr);
 
+	/* clear 15 entry supplimental perfect match filter */
+	for (i = 1; i < 16; i++)
+		 mac_write(sc, GMACMAH(i), 0);
+	/* build 64 bit multicast hash filter */
+	crc = mchash[1] = mchash[0] = 0;
+
 	ETHER_LOCK(ec);
 	if (ifp->if_flags & IFF_PROMISC) {
 		ec->ec_flags |= ETHER_F_ALLMULTI;
 		ETHER_UNLOCK(ec);
+		/* run promisc. mode */
+		csr |= AFR_PR;
 		goto update;
 	}
 	ec->ec_flags &= ~ETHER_F_ALLMULTI;
-
-	/* clear 15 entry supplimental perfect match filter */
-	for (i = 1; i < 16; i++)
-		 mac_write(sc, GMACMAH(i), 0);
-	/* build 64 bit multicast hash filter */
-	crc = mchash[1] = mchash[0] = 0;
-
 	ETHER_FIRST_MULTI(step, ec, enm);
 	i = 1; /* slot 0 is occupied */
 	while (enm != NULL) {
@@ -1052,6 +1053,8 @@ scx_set_rcvfilt(struct scx_softc *sc)
 			 */
 			ec->ec_flags |= ETHER_F_ALLMULTI;
 			ETHER_UNLOCK(ec);
+			/* accept all multi */
+			csr |= AFR_PM;
 			goto update;
 		}
 printf("[%d] %s\n", i, ether_sprintf(enm->enm_addrlo));
@@ -1080,15 +1083,8 @@ printf("[%d] %s\n", i, ether_sprintf(enm
 	csr |= AFR_HPF; /* use hash+perfect */
 	mac_write(sc, GMACMHTH, mchash[1]);
 	mac_write(sc, GMACMHTL, mchash[0]);
-	mac_write(sc, GMACAFR, csr);
-	return;
-
  update:
 	/* With PR or PM, MHTE/MHTL/MHTH are never consulted. really? */
-	if (ifp->if_flags & IFF_PROMISC)
-		csr |= AFR_PR;	/* run promisc. mode */
-	else
-		csr |= AFR_PM;	/* accept all multicast */
 	mac_write(sc, GMACAFR, csr);
 	return;
 }
@@ -1110,18 +1106,19 @@ mii_statchg(struct ifnet *ifp)
 {
 	struct scx_softc *sc = ifp->if_softc;
 	struct mii_data *mii = >sc_mii;
-	struct ifmedia * ifm = >mii_media;
-	uint32_t mcr, fcr;
+	const int Mbps[4] = { 10, 100, 1000, 0 };
+	uint32_t miisr, mcr, fcr;
+	int spd;
 
-#if 1
 	/* decode MIISR register value */
-	uint32_t miisr = mac_read(sc, GMACMIISR);
-	int spd = (miisr >> 1) & 03;
+	miisr = mac_read(sc, GMACMIISR);
+	spd = Mbps[(miisr >> 1) & 03];
+#if 1
 	printf("MII link status (0x%x) %s",
 	miisr, (miisr & 8) ? "up" : "down");
 	if (miisr & 8) {
-		printf(" spd%d", (spd == 2) ? 1000 : (spd == 1) ? 100 : 10);
-		if (miisr & 1)
+		printf(" spd%d", spd);
+		if (miisr & 01)
 			printf(",full-duplex");
 	}
 	printf("\n");
@@ -1133,11 +1130,10 @@ mii_statchg(struct ifnet *ifp)
 
 	/* Adjust speed 1000/100/10. */
 	mcr = mac_read(sc, GMACMCR);
-	if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_1000_T)
+	if (spd == 1000)
 		mcr &= ~MCR_USEMII; /* RGMII+SPD1000 */
 	else {
-		if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_100_TX
-		&& sc->sc_100mii)
+		if (spd == 100 && sc->sc_100mii)
 			mcr |= MCR_SPD100;
 		mcr |= MCR_USEMII;
 	}
@@ -1148,12 +1144,12 @@ mii_statchg(struct ifnet *ifp)
 	/* Adjust duplexity and PAUSE flow control. */
 	mcr &= ~MCR_USEFDX;
 	fcr 

CVS commit: src/sys/arch/arm/sociox

2020-03-28 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Sat Mar 28 13:15:24 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
- comb down rcvfilt() filter adjustment  logic.
- some mii_statchg() can be written in simpler form.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-27 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Mar 27 13:00:13 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
extend mii_statchg() to use ether_mediachange(). care about hash filter 
selection.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.20 src/sys/arch/arm/sociox/if_scx.c:1.21
--- src/sys/arch/arm/sociox/if_scx.c:1.20	Fri Mar 27 09:19:33 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Fri Mar 27 13:00:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.20 2020/03/27 09:19:33 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.21 2020/03/27 13:00:13 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.20 2020/03/27 09:19:33 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.21 2020/03/27 13:00:13 nisimura Exp $");
 
 #include 
 #include 
@@ -224,8 +224,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define GMACEVCTL	0x0100		/* event counter control */
 #define GMACEVCNT(i)	((i)*4+0x114)	/* event counter 0x114~284 */
 
-#define GMACMHT0	0x0500		/* 256bit multicast hash table 0 - 7 */
-#define GMACMHT(i)	((i)*4+0x500)
+#define GMACMHT(i)	((i)*4+0x500)	/* 256bit multicast hash table 0 - 7 */
 #define GMACVHT		0x0588		/* VLAN tag hash */
 
 /* 0x0700-0734 ??? */
@@ -452,7 +451,6 @@ static void scx_stop(struct ifnet *, int
 static void scx_watchdog(struct ifnet *);
 static int scx_ioctl(struct ifnet *, u_long, void *);
 static void scx_set_rcvfilt(struct scx_softc *);
-static int scx_ifmedia_upd(struct ifnet *);
 static void scx_ifmedia_sts(struct ifnet *, struct ifmediareq *);
 static void mii_statchg(struct ifnet *);
 static void phy_tick(void *);
@@ -709,7 +707,7 @@ sc->sc_mdclk <<= 2;
 	mii->mii_statchg = mii_statchg;
 
 	sc->sc_ethercom.ec_mii = mii;
-	ifmedia_init(ifm, 0, scx_ifmedia_upd, scx_ifmedia_sts);
+	ifmedia_init(ifm, 0, ether_mediachange, scx_ifmedia_sts);
 	mii_attach(sc->sc_dev, mii, 0x, sc->sc_phy_id,
 	MII_OFFSET_ANY, MIIF_DOPAUSE);
 	if (LIST_FIRST(>mii_phys) == NULL) {
@@ -881,7 +879,7 @@ scx_init(struct ifnet *ifp)
 	/* accept multicast frame or run promisc mode */
 	scx_set_rcvfilt(sc);
 
-	(void)scx_ifmedia_upd(ifp);
+	(void)ether_mediachange(ifp);
 
 	/* build sane Tx */
 	memset(sc->sc_txdescs, 0, sizeof(struct tdes) * MD_NTXDESC);
@@ -1077,16 +1075,16 @@ printf("[%d] %s\n", i, ether_sprintf(enm
 		i++;
 	}
 	ETHER_UNLOCK(ec);
-
 	if (crc)
-		csr |= AFR_MHTE | AFR_HPF; /* use hash+perfect */
+		csr |= AFR_MHTE;
+	csr |= AFR_HPF; /* use hash+perfect */
 	mac_write(sc, GMACMHTH, mchash[1]);
 	mac_write(sc, GMACMHTL, mchash[0]);
 	mac_write(sc, GMACAFR, csr);
 	return;
 
  update:
-	/* With PM or AM, MHTE/MHT0-7 are never consulted. really? */
+	/* With PR or PM, MHTE/MHTL/MHTH are never consulted. really? */
 	if (ifp->if_flags & IFF_PROMISC)
 		csr |= AFR_PR;	/* run promisc. mode */
 	else
@@ -1095,39 +1093,6 @@ printf("[%d] %s\n", i, ether_sprintf(enm
 	return;
 }
 
-static int
-scx_ifmedia_upd(struct ifnet *ifp)
-{
-	struct scx_softc *sc = ifp->if_softc;
-	struct ifmedia *ifm = >sc_mii.mii_media;
-
-	if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_AUTO) {
-		; /* restart AN */
-		; /* enable AN */
-		; /* advertise flow control pause */
-		; /* adv. 1000FDX,100FDX,100HDX,10FDX,10HDX */
-	} else {
-#if 1 /* XXX not sure to belong here XXX */
-		uint32_t mcr = mac_read(sc, GMACMCR);
-		if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_1000_T)
-			mcr &= ~MCR_USEMII; /* RGMII+SPD1000 */
-		else {
-			if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_100_TX
-			&& sc->sc_100mii)
-mcr |= MCR_SPD100;
-			mcr |= MCR_USEMII;
-		}
-		if (ifm->ifm_cur->ifm_media & IFM_FDX)
-			mcr |= MCR_USEFDX;
-		mcr |= MCR_CST | MCR_JE;
-		if (sc->sc_100mii == 0)
-			mcr |= MCR_IBN;
-		mac_write(sc, GMACMCR, mcr);
-#endif
-	}
-	return 0;
-}
-
 static void
 scx_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
 {
@@ -1145,7 +1110,8 @@ mii_statchg(struct ifnet *ifp)
 {
 	struct scx_softc *sc = ifp->if_softc;
 	struct mii_data *mii = >sc_mii;
-	uint32_t fcr;
+	struct ifmedia * ifm = >mii_media;
+	uint32_t mcr, fcr;
 
 #if 1
 	/* decode MIISR register value */
@@ -1165,14 +1131,31 @@ mii_statchg(struct ifnet *ifp)
 	(mii->mii_media_active & IFM_ETH_FMASK) != sc->sc_flowflags)
 		sc->sc_flowflags = mii->mii_media_active & IFM_ETH_FMASK;
 
-	/* Adjust PAUSE flow control. */
+	/* Adjust speed 1000/100/10. */
+	mcr = mac_read(sc, GMACMCR);
+	if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_1000_T)
+		mcr &= ~MCR_USEMII; /* RGMII+SPD1000 */
+	else {
+		if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_100_TX
+		&& sc->sc_100mii)
+			mcr |= MCR_SPD100;
+		mcr |= MCR_USEMII;
+	}
+	mcr 

CVS commit: src/sys/arch/arm/sociox

2020-03-27 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Mar 27 13:00:22 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_ave.c

Log Message:
extend mii_statchg() to use ether_mediachange(). care about hash filter 
selection.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/arm/sociox/if_ave.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-27 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Mar 27 13:00:22 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_ave.c

Log Message:
extend mii_statchg() to use ether_mediachange(). care about hash filter 
selection.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/arm/sociox/if_ave.c

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/sociox/if_ave.c
diff -u src/sys/arch/arm/sociox/if_ave.c:1.15 src/sys/arch/arm/sociox/if_ave.c:1.16
--- src/sys/arch/arm/sociox/if_ave.c:1.15	Tue Mar 24 03:08:02 2020
+++ src/sys/arch/arm/sociox/if_ave.c	Fri Mar 27 13:00:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ave.c,v 1.15 2020/03/24 03:08:02 nisimura Exp $	*/
+/*	$NetBSD: if_ave.c,v 1.16 2020/03/27 13:00:22 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -36,15 +36,16 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1.15 2020/03/24 03:08:02 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1.16 2020/03/27 13:00:22 nisimura Exp $");
 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -249,7 +250,6 @@ static void ave_watchdog(struct ifnet *)
 static int ave_ioctl(struct ifnet *, u_long, void *);
 static void ave_set_rcvfilt(struct ave_softc *);
 static void ave_write_filt(struct ave_softc *, int, const uint8_t *);
-static int ave_ifmedia_upd(struct ifnet *);
 static void ave_ifmedia_sts(struct ifnet *, struct ifmediareq *);
 static void mii_statchg(struct ifnet *);
 static void lnkchg(struct ave_softc *);
@@ -384,19 +384,17 @@ ave_fdt_attach(device_t parent, device_t
 	sc->sc_model = of_search_compatible(phandle, compat_data)->data;
 
 	phy_mode = fdtbus_get_string(phandle, "phy-mode");
-	if (phy_mode == NULL) {
+	if (phy_mode == NULL)
 		aprint_error(": missing 'phy-mode' property\n");
-		phy_mode = "rgmii";
-	}
 
 	aprint_naive("\n");
 	aprint_normal(": Gigabit Ethernet Controller\n");
-	aprint_normal_dev(self, "UniPhier %c%c%c%c AVE%d GbE (%d.%d) %s\n",
+	aprint_normal_dev(self, "UniPhier %c%c%c%c AVE%d GbE (%d.%d)\n",
 	hwimp >> 24, hwimp >> 16, hwimp >> 8, hwimp,
-	sc->sc_model, hwver >> 8, hwver & 0xff, phy_mode);
+	sc->sc_model, hwver >> 8, hwver & 0xff);
 	aprint_normal_dev(self, "interrupt on %s\n", intrstr);
 
-	sc->sc_100mii = (strcmp(phy_mode, "rgmii") != 0);
+	sc->sc_100mii = (phy_mode && strcmp(phy_mode, "rgmii") != 0);
 	sc->sc_desops = (sc->sc_model == 64) ?  : 
 
 	CSR_WRITE(sc, AVEGR, GR_GRST | GR_PHYRST);
@@ -429,7 +427,7 @@ ave_fdt_attach(device_t parent, device_t
 	sc->sc_phy_id = MII_PHY_ANY;
 
 	sc->sc_ethercom.ec_mii = mii;
-	ifmedia_init(ifm, 0, ave_ifmedia_upd, ave_ifmedia_sts);
+	ifmedia_init(ifm, 0, ether_mediachange, ave_ifmedia_sts);
 	mii_attach(sc->sc_dev, mii, 0x, sc->sc_phy_id,
 	MII_OFFSET_ANY, MIIF_DOPAUSE);
 	if (LIST_FIRST(>mii_phys) == NULL) {
@@ -586,7 +584,7 @@ ave_init(struct ifnet *ifp)
 	/* accept multicast frame or run promisc mode */
 	ave_set_rcvfilt(sc);
 
-	(void)ave_ifmedia_upd(ifp);
+	(void)ether_mediachange(ifp);
 
 	csr = CSR_READ(sc, AVECFG);
 	if (ifp->if_capenable & IFCAP_CSUM_IPv4_Tx) {
@@ -636,49 +634,6 @@ ave_stop(struct ifnet *ifp, int disable)
 	ifp->if_timer = 0;
 }
 
-static int
-ave_ifmedia_upd(struct ifnet *ifp)
-{
-	struct ave_softc *sc = ifp->if_softc;
-	struct ifmedia *ifm = >sc_mii.mii_media;
-	uint32_t txcr, rxcr, csr;
-
-	txcr = CSR_READ(sc, AVETXC);
-	rxcr = CSR_READ(sc, AVERXC);
-	CSR_WRITE(sc, AVERXC, rxcr &~ RXC_EN); /* stop Rx first */
-
-	if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_AUTO) {
-		; /* restart AN */
-		; /* enable AN */
-		; /* advertise flow control pause */
-		; /* adv. 1000FDX,100FDX,100HDX,10FDX,10HDX */
-	} else {
-#if 1 /* XXX not sure to belong here XXX */
-		txcr &= ~(TXC_SPD1000 | TXC_SPD100);
-		rxcr &= ~RXC_USEFDX;
-		if ((sc->sc_100mii == 0) /* RGMII model */
-		 && IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_1000_T)
-			txcr |= TXC_SPD1000;
-		else if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_100_TX)
-			txcr |= TXC_SPD100;
-		if (ifm->ifm_media & IFM_FDX)
-			rxcr |= RXC_USEFDX;	
-
-		/* adjust LINKSEL when RMII/MII too */
-		if (sc->sc_100mii) {
-			csr = CSR_READ(sc, AVELINKSEL) &~ LINKSEL_SPD100;
-			if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_100_TX)
-csr |= LINKSEL_SPD100;
-			CSR_WRITE(sc, AVELINKSEL, csr);
-		}
-#endif
-	}
-	sc->sc_rxc = rxcr;
-	CSR_WRITE(sc, AVETXC, txcr);
-	CSR_WRITE(sc, AVERXC, rxcr | RXC_EN);
-	return 0;
-}
-
 static void
 ave_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
 {
@@ -696,7 +651,8 @@ mii_statchg(struct ifnet *ifp)
 {
 	struct ave_softc *sc = ifp->if_softc;
 	struct mii_data *mii = >sc_mii;
-	uint32_t txcr, rxcr;
+	struct ifmedia *ifm = >mii_media;
+	uint32_t txcr, rxcr, lsel;
 
 	/* Get flow control negotiation result. */
 	if 

CVS commit: src/sys/arch/arm/sociox

2020-03-27 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Mar 27 13:00:13 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
extend mii_statchg() to use ether_mediachange(). care about hash filter 
selection.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-27 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Mar 27 09:19:33 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
try to be better register descriptions


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.19 src/sys/arch/arm/sociox/if_scx.c:1.20
--- src/sys/arch/arm/sociox/if_scx.c:1.19	Fri Mar 27 07:59:50 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Fri Mar 27 09:19:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.19 2020/03/27 07:59:50 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.20 2020/03/27 09:19:33 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -40,24 +40,24 @@
  *   to designify ring number from which to arrive or to which go.
  * - memory mapped EEPROM to hold MAC address. The rest of the area is
  *   occupied by a set of ucode for two DMA engines and one packet engine.
- * - The size of frame address filter is 16 plus 32.
+ * - The size of frame address filter is 16 plus 16.
  * - The first slot is my own station address. Always enabled to perform
  *   to identify oneself.
- * - 1~16 are for supplimental MAC addresses. Independently enabled for
+ * - 1~15 are for supplimental MAC addresses. Independently enabled for
  *   use. Good to catch multicast. Byte-wise selective match available.
  *   Use the mask to catch { 0x01, 0x00, 0x00 } and/or { 0x33, 0x33 }.
  * - 16~32 might be exact match without byte-mask.
  * - The size of multicast hash filter store is 64 bit.
- * - Socionext/Linaro "NetSec" code makes many cut shorts. Some constants
- *   are left unexplained. The values should be handled via external
- *   controls like FDT descriptions. Fortunately, Intel/Altera CycloneV PDFs
- *   describe every detail of "such the instance of" DW EMAC IP and
- *   most of them are likely applicable to SC2A11 GbE.
- * - DW EMAC implmentation (0x20) is 0x10.0x36
+ * - Socionext/Linaro "NetSec" code contains some constants left unexplained.
+ *   Fortunately, Intel/Altera CycloneV PDFs describe every detail of
+ *   "such the instance of" DW EMAC IP and most of them are likely applicable
+ *   to SC2A11 GbE.
+ * - not known "NetSec" instanciates DW timestamp or builds its own.
+ * - DW EMAC implmentation (0x20) is known 0x10.36
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.19 2020/03/27 07:59:50 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.20 2020/03/27 09:19:33 nisimura Exp $");
 
 #include 
 #include 
@@ -212,7 +212,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define GMACMAH0	0x0040		/* MAC address 0 47:32 */
 #define GMACMAL0	0x0044		/* MAC address 0 31:0 */
 #define GMACMAH(i) 	((i)*8+0x40)	/* supplimental MAC addr 1 - 15 */
-#define GMACMAL(i) 	((i)*8+0x44)
+#define GMACMAL(i) 	((i)*8+0x44)	/* bit 31 to use, 30 SA,
+	 * 29:24 byte-wise don'care */
 #define GMACMIISR	0x00d8		/* resolved xMII link status */
 	/*  3   link up detected
 	 *  2:1 resovled speed
@@ -227,12 +228,12 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define GMACMHT(i)	((i)*4+0x500)
 #define GMACVHT		0x0588		/* VLAN tag hash */
 
-/* 0x0700-0734 */
+/* 0x0700-0734 ??? */
 #define GMACAMAH(i)	((i)*8+0x800)	/* supplimental MAC addr 16-31 */
-#define GMACAMAL(i)	((i)*8+0x804)
+#define GMACAMAL(i)	((i)*8+0x804)	/* bit 31 to use */
 
 #define GMACBMR		0x1000		/* DMA bus mode control
-	 * 244PBL 8?
+	 * 244PBL 8???
 	 * 23USP
 	 * 22:17 RPBL
 	 * 16fixed burst, or undefined b.
@@ -841,12 +842,11 @@ scx_reset(struct scx_softc *sc)
 	int loop = 0, busy;
 
 	mac_write(sc, GMACOMR, 0);
-	mac_write(sc, GMACBMR, BMR_RST); /* may take for a while */
+	mac_write(sc, GMACBMR, BMR_RST);
 	do {
 		DELAY(1);
 		busy = mac_read(sc, GMACBMR) & BMR_RST;
 	} while (++loop < 3000 && busy);
-printf("BMR reset done with %d loop\n", loop);
 	mac_write(sc, GMACBMR, _BMR);
 	mac_write(sc, GMACAFR, 0);
 



CVS commit: src/sys/arch/arm/sociox

2020-03-27 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Mar 27 09:19:33 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
try to be better register descriptions


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-27 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Mar 27 07:59:50 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
more register mashup work


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.18 src/sys/arch/arm/sociox/if_scx.c:1.19
--- src/sys/arch/arm/sociox/if_scx.c:1.18	Fri Mar 27 06:32:49 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Fri Mar 27 07:59:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.18 2020/03/27 06:32:49 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.19 2020/03/27 07:59:50 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.18 2020/03/27 06:32:49 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.19 2020/03/27 07:59:50 nisimura Exp $");
 
 #include 
 #include 
@@ -84,7 +84,9 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #include 
 #include 
 
-/* SC2A11 register block 0x100-0x1204? */
+/*
+ * SC2A11 register block 0x100-0x1204?
+ */
 #define SWRESET		0x104
 #define COMINIT		0x120
 #define xINTSR		0x200		/* aggregated interrupt status report */
@@ -96,7 +98,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define xINTBEN		0x23c		/* INT_B enable */
 #define xINTB_SET	0x240		/* bit to set */
 #define xINTB_CLR	0x244		/* bit to clr */
-/* 0x0c-48 *//* pkt,tls,s0,s1 SR/IE/SET/CLR */
+/* 0x00c-048 */		/* pkt,tls,s0,s1 SR/IE/SET/CLR */
 #define TXISR		0x400
 #define TXIEN		0x404
 #define TXI_SET		0x428
@@ -127,6 +129,17 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define MCVER		0x22c		/* micro controller version */
 #define HWVER		0x230		/* hardware version */
 
+/* 0x800 */		/* dec Tx  SR/EN/SET/CLR */
+/* 0x840 */		/* enc Rx  SR/EN/SET/CLR */
+/* 0x880 */		/* enc TLS Tx  SR/IE/SET/CLR */
+/* 0x8c0 */		/* dec TLS Tx  SR/IE/SET/CLR */
+/* 0x900 */		/* enc TLS Rx  SR/IE/SET/CLR */
+/* 0x940 */		/* dec TLS Rx  SR/IE/SET/CLR */
+/* 0x980 */		/* enc RAW Tx  SR/IE/SET/CLR */
+/* 0x9c0 */		/* dec RAW Tx  SR/IE/SET/CLR */
+/* 0xA00 */		/* enc RAW Rx  SR/IE/SET/CLR */
+/* 0xA40 */		/* dec RAW Rx  SR/IE/SET/CLR */
+
 #define MACCMD		0x11c4		/* gmac operation */
 #define  CMD_IOWR	(1U<<28)	/* write op */
 #define  CMD_BUSY	(1U<<31)	/* busy bit */
@@ -136,23 +149,30 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define DESC_INIT	0x11fc		/* desc engine init */
 #define DESC_SRST	0x1204		/* desc engine sw reset */
 
-/* GMAC register block. use mac_write()/mac_read() to handle */
+/*
+ * GMAC register block. use mac_write()/mac_read() to handle
+ */
 #define GMACMCR		0x		/* MAC configuration */
-#define  MCR_IBN	(1U<<30)	/* */
+#define  MCR_IBN	(1U<<30)	/* ??? */
 #define  MCR_CST	(1U<<25)	/* strip CRC */
 #define  MCR_TC		(1U<<24)	/* keep RGMII PHY notified */
 #define  MCR_JE		(1U<<20)	/* ignore oversized >9018 condition */
+#define  MCR_IFG	(7U<<17)	/* 19:17 IFG value 0~7 */
+#define  MCR_DRCS	(1U<<16)	/* ignore (G)MII HDX Tx error */
 #define  MCR_USEMII	(1U<<15)	/* 1: RMII/MII, 0: RGMII (_PS) */
 #define  MCR_SPD100	(1U<<14)	/* force speed 100 (_FES) */
+#define  MCR_DO		(1U<<13)	/* */
+#define  MCR_LOOP	(1U<<12)	/* */
 #define  MCR_USEFDX	(1U<<11)	/* force full duplex */
-#define  MCR_IPCKEN	(1U<<10)	/* handle checksum */
+#define  MCR_IPCEN	(1U<<10)	/* handle checksum */
 #define  MCR_ACS	(1U<<7)		/* auto pad strip CRC */
-#define  MCR_TXE	(1U<<3)		/* start Tx DMA engine */
-#define  MCR_RXE	(1U<<2)		/* start Rx DMA engine */
+#define  MCR_TE		(1U<<3)		/* run Tx MAC engine, 0 to stop */
+#define  MCR_RE		(1U<<2)		/* run Rx MAC engine, 0 to stop */
+#define  MCR_PREA	(3U)		/* 1:0 preamble len. 0~2 */
 #define  _MCR_FDX	0x280c	/* XXX TBD */
 #define  _MCR_HDX	0x0001a00c	/* XXX TBD */
 #define GMACAFR		0x0004		/* frame DA/SA address filter */
-#define  AFR_RA		(1U<<31)	/* receive block all on */
+#define  AFR_RA		(1U<<31)	/* accept all irrecspective of filt. */
 #define  AFR_HPF	(1U<<10)	/* hash+perfect filter, or hash only */
 #define  AFR_SAF	(1U<<9)		/* source address filter */
 #define  AFR_SAIF	(1U<<8)		/* SA inverse filtering */
@@ -161,9 +181,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define  AFR_PM		(1U<<4)		/* accept all multicast frame */
 #define  AFR_DAIF	(1U<<3)		/* DA inverse filtering */
 #define  AFR_MHTE	(1U<<2)		/* use multicast hash table */
-#define  AFR_UHTE	(1U<<1)		/* use additional MAC addresses */
+#define  AFR_UHTE	(1U<<1)		/* use hash table for unicast */
 #define  AFR_PR		(1U<<0)		/* run promisc mode */
-#define  _AFR		0x8001	/* XXX TBD */
 #define GMACMHTH	0x0008		/* 64bit multicast hash table 63:32 */
 #define GMACMHTL	0x000c		/* 64bit multicast hash table 31:0 */
 #define GMACGAR		0x0010		/* MDIO operation */
@@ -184,6 +203,12 @@ __KERNEL_RCSID(0, 

CVS commit: src/sys/arch/arm/sociox

2020-03-27 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Mar 27 07:59:50 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
more register mashup work


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-27 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Mar 27 06:32:49 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
register definition mashed. from UEFI and CycloneV PDF


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.17 src/sys/arch/arm/sociox/if_scx.c:1.18
--- src/sys/arch/arm/sociox/if_scx.c:1.17	Thu Mar 26 10:38:16 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Fri Mar 27 06:32:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.17 2020/03/26 10:38:16 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.18 2020/03/27 06:32:49 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.17 2020/03/26 10:38:16 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.18 2020/03/27 06:32:49 nisimura Exp $");
 
 #include 
 #include 
@@ -84,29 +84,31 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #include 
 #include 
 
-/* SC2A11 register block */
+/* SC2A11 register block 0x100-0x1204? */
 #define SWRESET		0x104
-#define MACADRH		0x10c
-#define MACADRL		0x110
 #define COMINIT		0x120
-#define INTRST		0x200
-#define  IRQ_RX		(1U<<1)
-#define  IRQ_TX		(1U<<0)
-#define INTREN		0x204
-#define INTR_SET	0x234
-#define INTR_CLR	0x238
-#define TXINTST		0x400
-#define TXINTEN		0x404
-#define TXINT_SET	0x428
-#define TXINT_CLR	0x42c
+#define xINTSR		0x200		/* aggregated interrupt status report */
+#define  IRQ_RX		(1U<<1)		/* top level Rx interrupt */
+#define  IRQ_TX		(1U<<0)		/* top level Rx interrupt */
+#define xINTAEN		0x204		/* INT_A enable */
+#define xINTA_SET	0x234		/* bit to set */
+#define xINTA_CLR	0x238		/* bit to clr */
+#define xINTBEN		0x23c		/* INT_B enable */
+#define xINTB_SET	0x240		/* bit to set */
+#define xINTB_CLR	0x244		/* bit to clr */
+/* 0x0c-48 *//* pkt,tls,s0,s1 SR/IE/SET/CLR */
+#define TXISR		0x400
+#define TXIEN		0x404
+#define TXI_SET		0x428
+#define TXI_CLR		0x42c
 #define  TXI_NTOWNR	(1U<<17)
 #define  TXI_TR_ERR	(1U<<16)
 #define  TXI_TXDONE	(1U<<15)
 #define  TXI_TMREXP	(1U<<14)
-#define RXINTST		0x440
-#define RXINTEN		0x444
-#define RXINT_SET	0x468
-#define RXINT_CLR	0x46c
+#define RXISR		0x440
+#define RXIEN		0x444
+#define RXI_SET		0x468
+#define RXI_CLR		0x46c
 #define  RXI_RC_ERR	(1U<<16)
 #define  RXI_PKTCNT	(1U<<15)
 #define  RXI_TMREXP	(1U<<14)
@@ -117,16 +119,22 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define H2MENG		0x210		/* DMAC host2media ucode port */
 #define M2HENG		0x21c		/* DMAC media2host ucode port */
 #define PKTENG		0x0d0		/* packet engine ucode port */
+#define CLKEN		0x100		/* clock distribution enable */
+#define  CLK_G		(1U<<5)
+#define  CLK_ALL	0x24
+#define MACADRH		0x10c		/* ??? */
+#define MACADRL		0x110		/* ??? */
 #define MCVER		0x22c		/* micro controller version */
 #define HWVER		0x230		/* hardware version */
 
-#define MACSTAT		0x1024		/* gmac status */
-#define MACDATA		0x11c0		/* gmac rd/wr data */
 #define MACCMD		0x11c4		/* gmac operation */
 #define  CMD_IOWR	(1U<<28)	/* write op */
 #define  CMD_BUSY	(1U<<31)	/* busy bit */
-#define DESCENG_INIT	0x11fc
-#define DESCENG_SRST	0x1204
+#define MACSTAT		0x1024		/* gmac status */
+#define MACDATA		0x11c0		/* gmac rd/wr data */
+#define MACINTE		0x1028		/* interrupt enable */
+#define DESC_INIT	0x11fc		/* desc engine init */
+#define DESC_SRST	0x1204		/* desc engine sw reset */
 
 /* GMAC register block. use mac_write()/mac_read() to handle */
 #define GMACMCR		0x		/* MAC configuration */
@@ -134,8 +142,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define  MCR_CST	(1U<<25)	/* strip CRC */
 #define  MCR_TC		(1U<<24)	/* keep RGMII PHY notified */
 #define  MCR_JE		(1U<<20)	/* ignore oversized >9018 condition */
-#define  MCR_USEMII	(1U<<15)	/* 1: RMII/MII, 0: RGMII */
-#define  MCR_SPD100	(1U<<14)	/* force speed 100 */
+#define  MCR_USEMII	(1U<<15)	/* 1: RMII/MII, 0: RGMII (_PS) */
+#define  MCR_SPD100	(1U<<14)	/* force speed 100 (_FES) */
 #define  MCR_USEFDX	(1U<<11)	/* force full duplex */
 #define  MCR_IPCKEN	(1U<<10)	/* handle checksum */
 #define  MCR_ACS	(1U<<7)		/* auto pad strip CRC */
@@ -145,19 +153,19 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define  _MCR_HDX	0x0001a00c	/* XXX TBD */
 #define GMACAFR		0x0004		/* frame DA/SA address filter */
 #define  AFR_RA		(1U<<31)	/* receive block all on */
-#define  AFR_HPF	(1U<<10)	/* activate hash or perfect filter */
+#define  AFR_HPF	(1U<<10)	/* hash+perfect filter, or hash only */
 #define  AFR_SAF	(1U<<9)		/* source address filter */
 #define  AFR_SAIF	(1U<<8)		/* SA inverse filtering */
-#define  AFR_PCF	(3U<<6)		/* */
-#define  AFR_RB		(1U<<5)		/* reject broadcast frame */
-#define  AFR_AM		(1U<<4)		/* accept all multicast frame */
+#define 

CVS commit: src/sys/arch/arm/sociox

2020-03-27 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Fri Mar 27 06:32:49 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
register definition mashed. from UEFI and CycloneV PDF


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-26 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Mar 26 10:38:16 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
update register definition. from UEFI source code.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.16 src/sys/arch/arm/sociox/if_scx.c:1.17
--- src/sys/arch/arm/sociox/if_scx.c:1.16	Thu Mar 26 08:28:50 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Thu Mar 26 10:38:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.16 2020/03/26 08:28:50 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.17 2020/03/26 10:38:16 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -40,14 +40,14 @@
  *   to designify ring number from which to arrive or to which go.
  * - memory mapped EEPROM to hold MAC address. The rest of the area is
  *   occupied by a set of ucode for two DMA engines and one packet engine.
- * - The size of frame address filter is unknown. Might be 16 or even 128.
+ * - The size of frame address filter is 16 plus 32.
  * - The first slot is my own station address. Always enabled to perform
  *   to identify oneself.
  * - 1~16 are for supplimental MAC addresses. Independently enabled for
  *   use. Good to catch multicast. Byte-wise selective match available.
  *   Use the mask to catch { 0x01, 0x00, 0x00 } and/or { 0x33, 0x33 }.
- * - 16~128 might be exact match without byte-mask.
- * - The size of multicast hash filter store is unknown. Might be 256 bit.
+ * - 16~32 might be exact match without byte-mask.
+ * - The size of multicast hash filter store is 64 bit.
  * - Socionext/Linaro "NetSec" code makes many cut shorts. Some constants
  *   are left unexplained. The values should be handled via external
  *   controls like FDT descriptions. Fortunately, Intel/Altera CycloneV PDFs
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.16 2020/03/26 08:28:50 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.17 2020/03/26 10:38:16 nisimura Exp $");
 
 #include 
 #include 
@@ -86,6 +86,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 
 /* SC2A11 register block */
 #define SWRESET		0x104
+#define MACADRH		0x10c
+#define MACADRL		0x110
 #define COMINIT		0x120
 #define INTRST		0x200
 #define  IRQ_RX		(1U<<1)
@@ -115,8 +117,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define H2MENG		0x210		/* DMAC host2media ucode port */
 #define M2HENG		0x21c		/* DMAC media2host ucode port */
 #define PKTENG		0x0d0		/* packet engine ucode port */
-#define HWVER0		0x22c
-#define HWVER1		0x230
+#define MCVER		0x22c		/* micro controller version */
+#define HWVER		0x230		/* hardware version */
 
 #define MACSTAT		0x1024		/* gmac status */
 #define MACDATA		0x11c0		/* gmac rd/wr data */
@@ -154,8 +156,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define  AFR_UHTE	(1U<<1)		/* use additional MAC addresses */
 #define  AFR_PM		(1U<<0)		/* run promisc mode */
 #define  _AFR		0x8001	/* XXX TBD */
-#define GMACMHTH	0x0008		/* XXX multicast hash table 63:32 */
-#define GMACMHTL	0x000c		/* XXX multicast hash table 31:0 */
+#define GMACMHTH	0x0008		/* multicast hash table 63:32 */
+#define GMACMHTL	0x000c		/* multicast hash table 31:0 */
 #define GMACGAR		0x0010		/* MDIO operation */
 #define  GAR_PHY	(11)		/* mii phy 15:11 */
 #define  GAR_REG	(6)		/* mii reg 10:6 */
@@ -180,13 +182,13 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 	 *	2 125Mhz (1000Mbps)
 	 *  1   full duplex detected */
 
-#define GMACMHT0	0x0500		/* multicast hash table 0 - 7 */
+#define GMACMHT0	0x0500		/* XXX multicast hash table 0 - 7 */
 #define GMACMHT(i)	((i)*4+0x500)
 #define GMACVHT		0x0588		/* VLAN tag hash */
-#define GMACAMAH(i)	((i)*8+0x800)	/* supplimental MAC addr 16-127 */
+#define GMACAMAH(i)	((i)*8+0x800)	/* supplimental MAC addr 16-31 */
 #define GMACAMAL(i)	((i)*8+0x804)
+#define GMACEVCTL	0x0100		/* event counter control */
 #define GMACEVCNT(i)	((i)*4+0x114)	/* event counter 0x114~284 */
-#define GMACEVCTL	0x0100		/* clear event counter registers */
 
 #define GMACBMR		0x1000		/* DMA bus mode control
 	 * 244PBL
@@ -613,7 +615,7 @@ scx_attach_i(struct scx_softc *sc)
 	uint32_t csr;
 	int i, nseg, error = 0;
 
-	hwver = CSR_READ(sc, HWVER1);	/* Socionext HW */
+	hwver = CSR_READ(sc, HWVER);	/* Socionext HW */
 	/* stored in big endian order */
 	csr = bus_space_read_4(sc->sc_st, sc->sc_eesh, 0);
 	enaddr[0] = csr >> 24;
@@ -953,7 +955,7 @@ scx_set_rcvfilt(struct scx_softc *sc)
 	struct ifnet * const ifp = >ec_if;
 	struct ether_multistep step;
 	struct ether_multi *enm;
-	uint32_t mchash[8]; 	/* 8x 32 = 256 bit */
+	uint32_t mchash[2]; 	/* 2x 32 = 64 bit */
 	uint32_t csr, crc;
 	int i;
 
@@ -972,9 +974,8 @@ scx_set_rcvfilt(struct scx_softc *sc)
 	/* clear 15 entry 

CVS commit: src/sys/arch/arm/sociox

2020-03-26 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Mar 26 10:38:16 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
update register definition. from UEFI source code.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-26 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Mar 26 08:28:50 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
correct global reset logic. still remains MII speed trouble.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.15 src/sys/arch/arm/sociox/if_scx.c:1.16
--- src/sys/arch/arm/sociox/if_scx.c:1.15	Thu Mar 26 01:05:26 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Thu Mar 26 08:28:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.15 2020/03/26 01:05:26 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.16 2020/03/26 08:28:50 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.15 2020/03/26 01:05:26 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.16 2020/03/26 08:28:50 nisimura Exp $");
 
 #include 
 #include 
@@ -202,7 +202,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 	 */
 #define  _BMR		0x00412080	/* XXX TBD */
 #define  _BMR0		0x00020181	/* XXX TBD */
-#define  BMR_RST	(1U<<0)		/* reset op. self clear when done */
+#define  BMR_RST	(1)		/* reset op. self clear when done */
 #define GMACTDS		0x1004		/* write any to resume tdes */
 #define GMACRDS		0x1008		/* write any to resume rdes */
 #define GMACRDLAR	0x100c		/* rdes base address 32bit paddr */
@@ -585,6 +585,8 @@ aprint_normal_dev(self,
 	sc->sc_100mii = (phy_mode && strcmp(phy_mode, "rgmii") != 0);
 	sc->sc_phy_id = (int)acpi_phy;
 	sc->sc_freq = acpi_freq;
+aprint_normal_dev(self,
+"GMACGAR %08x\n", mac_read(sc, GMACGAR));
 
 	scx_attach_i(sc);
 
@@ -631,7 +633,7 @@ scx_attach_i(struct scx_softc *sc)
 
 sc->sc_phy_id = MII_PHY_ANY;
 	sc->sc_mdclk = get_mdioclk(sc->sc_freq); /* 5:2 clk control */
-sc->sc_mdclk = 5; /* XXX */
+sc->sc_mdclk = 0; /* XXX */
 aprint_normal_dev(sc->sc_dev, "using %d for mdclk\n", sc->sc_mdclk);
 sc->sc_mdclk <<= 2;
 
@@ -776,16 +778,18 @@ aprint_normal_dev(sc->sc_dev, "descripto
 static void
 scx_reset(struct scx_softc *sc)
 {
+	int loop = 0, busy;
 
-	mac_write(sc, GMACBMR, BMR_RST); /* may take for a while */
-	(void)spin_waitfor(sc, GMACBMR, BMR_RST);
+	mac_write(sc, GMACBMR, _BMR0); /* may take for a while */
+	do {
+		DELAY(10);
+		busy = mac_read(sc, GMACBMR) & BMR_RST;
+	} while (++loop < 3000 && busy);
+printf("reset done with %d loop\n", loop);
 
 	CSR_WRITE(sc, DESCENG_SRST, 1);
 	CSR_WRITE(sc, DESCENG_INIT, 1);
 	mac_write(sc, GMACBMR, _BMR);
-	mac_write(sc, GMACRDLAR, _RDLAR);
-	mac_write(sc, GMACTDLAR, _TDLAR);
-	mac_write(sc, GMACAFR, _AFR);
 	mac_write(sc, GMACEVCTL, 1);
 }
 
@@ -1444,16 +1448,16 @@ add_rxbuf(struct scx_softc *sc, int i)
 static int
 spin_waitfor(struct scx_softc *sc, int reg, int exist)
 {
-	int val, loop;
+	int busy, loop;
 
-	val = CSR_READ(sc, reg);
-	if ((val & exist) == 0)
+	busy = CSR_READ(sc, reg) & exist;
+	if (busy == 0)
 		return 0;
 	loop = 3000;
 	do {
 		DELAY(10);
-		val = CSR_READ(sc, reg);
-	} while (--loop > 0 && (val & exist));
+		busy = CSR_READ(sc, reg) & exist;
+	} while (--loop > 0 && busy);
 	return (loop > 0) ? 0 : ETIMEDOUT;
 }
 



CVS commit: src/sys/arch/arm/sociox

2020-03-26 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Mar 26 08:28:50 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
correct global reset logic. still remains MII speed trouble.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Mar 26 01:05:26 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
adjust minor comments


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.14 src/sys/arch/arm/sociox/if_scx.c:1.15
--- src/sys/arch/arm/sociox/if_scx.c:1.14	Wed Mar 25 20:19:46 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Thu Mar 26 01:05:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.14 2020/03/25 20:19:46 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.15 2020/03/26 01:05:26 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.14 2020/03/25 20:19:46 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.15 2020/03/26 01:05:26 nisimura Exp $");
 
 #include 
 #include 
@@ -176,7 +176,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 	/*  3   link up detected
 	 *  2:1 resovled speed
 	 *  0 2.5Mhz (10Mbps)
-	 *	1 25Mhz  (100bps)
+	 *	1 25Mhz  (100Mbps)
 	 *	2 125Mhz (1000Mbps)
 	 *  1   full duplex detected */
 
@@ -463,7 +463,6 @@ scx_fdt_attach(device_t parent, device_t
 		goto fail;
 	}
 
-
 	aprint_naive("\n");
 	/* aprint_normal(": Gigabit Ethernet Controller\n"); */
 	aprint_normal_dev(self, "interrupt on %s\n", intrstr);
@@ -475,6 +474,7 @@ scx_fdt_attach(device_t parent, device_t
 	sc->sc_eesh = eebsh;
 	sc->sc_eesz = size[1];
 	sc->sc_dmat = faa->faa_dmat;
+	sc->sc_dmat32 = faa->faa_dmat; /* XXX */
 	sc->sc_phandle = phandle;
 
 	phy_mode = fdtbus_get_string(phandle, "phy-mode");
@@ -583,8 +583,8 @@ scx_acpi_attach(device_t parent, device_
 aprint_normal_dev(self,
 "phy mode %s, phy id %d, freq %ld\n", phy_mode, (int)acpi_phy, acpi_freq);
 	sc->sc_100mii = (phy_mode && strcmp(phy_mode, "rgmii") != 0);
-	sc->sc_freq = acpi_freq;
 	sc->sc_phy_id = (int)acpi_phy;
+	sc->sc_freq = acpi_freq;
 
 	scx_attach_i(sc);
 
@@ -605,13 +605,14 @@ scx_attach_i(struct scx_softc *sc)
 	struct ifnet * const ifp = >sc_ethercom.ec_if;
 	struct mii_data * const mii = >sc_mii;
 	struct ifmedia * const ifm = >mii_media;
-	uint32_t hwver;
+	uint32_t hwver, dwimp;
 	uint8_t enaddr[ETHER_ADDR_LEN];
 	bus_dma_segment_t seg;
 	uint32_t csr;
 	int i, nseg, error = 0;
 
-	hwver = CSR_READ(sc, HWVER1);
+	hwver = CSR_READ(sc, HWVER1);	/* Socionext HW */
+	/* stored in big endian order */
 	csr = bus_space_read_4(sc->sc_st, sc->sc_eesh, 0);
 	enaddr[0] = csr >> 24;
 	enaddr[1] = csr >> 16;
@@ -620,15 +621,15 @@ scx_attach_i(struct scx_softc *sc)
 	csr = bus_space_read_4(sc->sc_st, sc->sc_eesh, 4);
 	enaddr[4] = csr >> 24;
 	enaddr[5] = csr >> 16;
-	csr = mac_read(sc, GMACIMPL);
+	dwimp = mac_read(sc, GMACIMPL);	/* DW EMAC XX.YY */
 
 	aprint_normal_dev(sc->sc_dev,
 	"Socionext NetSec GbE hw %d.%d impl 0x%x\n",
-	hwver >> 16, hwver & 0x, csr);
+	hwver >> 16, hwver & 0x, dwimp);
 	aprint_normal_dev(sc->sc_dev,
 	"Ethernet address %s\n", ether_sprintf(enaddr));
 
-	sc->sc_phy_id = MII_PHY_ANY;
+sc->sc_phy_id = MII_PHY_ANY;
 	sc->sc_mdclk = get_mdioclk(sc->sc_freq); /* 5:2 clk control */
 sc->sc_mdclk = 5; /* XXX */
 aprint_normal_dev(sc->sc_dev, "using %d for mdclk\n", sc->sc_mdclk);
@@ -802,7 +803,7 @@ scx_init(struct ifnet *ifp)
 	/* Reset the chip to a known state. */
 	scx_reset(sc);
 
-	/* set my address in perfect match slot 0 */
+	/* set my address in perfect match slot 0. little endin order */
 	csr = (ea[3] << 24) | (ea[2] << 16) | (ea[1] << 8) |  ea[0];
 	mac_write(sc, GMACMAL0, csr);
 	csr = (ea[5] << 8) | ea[4];
@@ -1077,6 +1078,7 @@ mii_statchg(struct ifnet *ifp)
 	struct scx_softc *sc = ifp->if_softc;
 	struct mii_data *mii = >sc_mii;
 	uint32_t fcr;
+
 #if 1
 	/* decode MIISR register value */
 	uint32_t miisr = mac_read(sc, GMACMIISR);



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Mar 26 01:05:26 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
adjust minor comments


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 23:31:19 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_gpio.c

Log Message:
try to DRT about config messages, redo ...


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sociox/sni_gpio.c

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/sociox/sni_gpio.c
diff -u src/sys/arch/arm/sociox/sni_gpio.c:1.6 src/sys/arch/arm/sociox/sni_gpio.c:1.7
--- src/sys/arch/arm/sociox/sni_gpio.c:1.6	Wed Mar 25 23:29:39 2020
+++ src/sys/arch/arm/sociox/sni_gpio.c	Wed Mar 25 23:31:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_gpio.c,v 1.6 2020/03/25 23:29:39 nisimura Exp $	*/
+/*	$NetBSD: sni_gpio.c,v 1.7 2020/03/25 23:31:19 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.6 2020/03/25 23:29:39 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.7 2020/03/25 23:31:19 nisimura Exp $");
 
 #include 
 #include 
@@ -151,7 +151,7 @@ snigpio_fdt_attach(device_t parent, devi
 	}
 
 	aprint_naive("\n");
-	aprint_normal_dev("Socionext GPIO controller\n");
+	aprint_normal_dev(self, "Socionext GPIO controller\n");
 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 	list = fdtbus_get_string(phandle, "gpio-line-names");
 	if (list)



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 23:31:19 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_gpio.c

Log Message:
try to DRT about config messages, redo ...


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/sociox/sni_gpio.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 23:29:39 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_exiu.c sni_gpio.c

Log Message:
try to DRT about config messages


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sociox/sni_exiu.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sociox/sni_gpio.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 23:29:39 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_exiu.c sni_gpio.c

Log Message:
try to DRT about config messages


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sociox/sni_exiu.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sociox/sni_gpio.c

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/sociox/sni_exiu.c
diff -u src/sys/arch/arm/sociox/sni_exiu.c:1.2 src/sys/arch/arm/sociox/sni_exiu.c:1.3
--- src/sys/arch/arm/sociox/sni_exiu.c:1.2	Thu Mar 19 22:17:45 2020
+++ src/sys/arch/arm/sociox/sni_exiu.c	Wed Mar 25 23:29:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_exiu.c,v 1.2 2020/03/19 22:17:45 nisimura Exp $	*/
+/*	$NetBSD: sni_exiu.c,v 1.3 2020/03/25 23:29:39 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_exiu.c,v 1.2 2020/03/19 22:17:45 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_exiu.c,v 1.3 2020/03/25 23:29:39 nisimura Exp $");
 
 #include 
 #include 
@@ -60,8 +60,8 @@ struct sniexiu_softc {
 	bus_space_handle_t	sc_ioh;
 	bus_addr_t		sc_iob;
 	bus_size_t		sc_ios;
-	kmutex_t		sc_lock;
 	void			*sc_ih;
+	kmutex_t		sc_lock;
 	int			sc_phandle;
 };
 
@@ -98,7 +98,6 @@ sniexiu_fdt_attach(device_t parent, devi
 	bus_size_t size;
 	char intrstr[128];
 	_Bool disable;
-	int error;
 
 	prop_dictionary_get_bool(dict, "disable", );
 	if (disable) {
@@ -106,22 +105,25 @@ sniexiu_fdt_attach(device_t parent, devi
 		aprint_normal(": disabled\n");
 		return;
 	}
-	error = fdtbus_get_reg(phandle, 0, , );
-	if (error) {
-		aprint_error(": couldn't get registers\n");
-		return;
-	}
-	error = bus_space_map(faa->faa_bst, addr, size, 0, );
-	if (error) {
+	if (fdtbus_get_reg(phandle, 0, , ) != 0
+	|| bus_space_map(faa->faa_bst, addr, size, 0, ) != 0) {
 		aprint_error(": unable to map device\n");
 		return;
 	}
-	error = fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr));
-	if (error) {
+	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
 		aprint_error(": failed to decode interrupt\n");
-		return;
+		goto fail;
+	}
+	sc->sc_ih = fdtbus_intr_establish(phandle,
+			0, IPL_NET, 0, sniexiu_intr, sc);
+	if (sc->sc_ih == NULL) {
+		aprint_error_dev(self, "couldn't establish interrupt\n");
+		goto fail;
 	}
 
+	aprint_naive("\n");
+	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
+
 	sc->sc_dev = self;
 	sc->sc_phandle = phandle;
 	sc->sc_iot = faa->faa_bst;
@@ -130,13 +132,6 @@ sniexiu_fdt_attach(device_t parent, devi
 	sc->sc_ios = size;
 	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE);
 
-	sc->sc_ih = fdtbus_intr_establish(phandle,
-			0, IPL_NET, 0, sniexiu_intr, sc);
-	if (sc->sc_ih == NULL) {
-		aprint_error_dev(self, "couldn't establish interrupt\n");
-		goto fail;
-	}
-
 	sniexiu_attach_i(sc);
 	return;
   fail:
@@ -173,30 +168,17 @@ sniexiu_acpi_attach(device_t parent, dev
 	, _resource_parse_ops_default);
 	if (ACPI_FAILURE(rv))
 		return;
-
 	mem = acpi_res_mem(, 0);
 	irq = acpi_res_irq(, 0);
-	if (mem == NULL || irq == NULL) {
+	if (mem == NULL || irq == NULL || mem->ar_length) {
 		aprint_error(": incomplete resources\n");
 		return;
 	}
-	if (mem->ar_length == 0) {
-		aprint_error(": zero length memory resource\n");
-		return;
-	}
 	if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0,
 	)) {
 		aprint_error(": couldn't map registers\n");
 		return;
 	}
-
-	sc->sc_dev = self;
-	sc->sc_iot = aa->aa_memt;
-	sc->sc_ioh = ioh;
-	sc->sc_iob = mem->ar_base;
-	sc->sc_ios = mem->ar_length;
-	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE);
-
 	sc->sc_ih = acpi_intr_establish(self,
 	(uint64_t)(uintptr_t)aa->aa_node->ad_handle,
 	IPL_BIO, false, sniexiu_intr, sc, device_xname(self));
@@ -205,20 +187,31 @@ sniexiu_acpi_attach(device_t parent, dev
 		goto fail;
 	}
 
+	aprint_naive("\n");
+
+	sc->sc_dev = self;
+	sc->sc_iot = aa->aa_memt;
+	sc->sc_ioh = ioh;
+	sc->sc_iob = mem->ar_base;
+	sc->sc_ios = mem->ar_length;
+	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE);
+
 	sniexiu_attach_i(sc);
+
+	acpi_resource_cleanup();
+	return;
  fail:
+	bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
 	acpi_resource_cleanup();
+	return;
 }
 
 static void
 sniexiu_attach_i(struct sniexiu_softc *sc)
 {
-
-	aprint_naive(": External IRQ controller\n");
-	aprint_normal(": External IRQ controller\n");
-
+	
+	aprint_normal_dev(sc->sc_dev, "Socionext External IRQ controller\n");
 	/* AAA */
-
 	return;
 }
 

Index: src/sys/arch/arm/sociox/sni_gpio.c
diff -u src/sys/arch/arm/sociox/sni_gpio.c:1.5 src/sys/arch/arm/sociox/sni_gpio.c:1.6
--- src/sys/arch/arm/sociox/sni_gpio.c:1.5	Wed Mar 25 19:03:44 2020
+++ src/sys/arch/arm/sociox/sni_gpio.c	Wed Mar 25 23:29:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_gpio.c,v 1.5 2020/03/25 19:03:44 nisimura Exp $	*/
+/*	$NetBSD: sni_gpio.c,v 

CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 23:20:38 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c sni_i2c.c

Log Message:
DRT about config messages


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sociox/sni_emmc.c \
src/sys/arch/arm/sociox/sni_i2c.c

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/sociox/sni_emmc.c
diff -u src/sys/arch/arm/sociox/sni_emmc.c:1.5 src/sys/arch/arm/sociox/sni_emmc.c:1.6
--- src/sys/arch/arm/sociox/sni_emmc.c:1.5	Wed Mar 25 22:15:53 2020
+++ src/sys/arch/arm/sociox/sni_emmc.c	Wed Mar 25 23:20:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_emmc.c,v 1.5 2020/03/25 22:15:53 nisimura Exp $	*/
+/*	$NetBSD: sni_emmc.c,v 1.6 2020/03/25 23:20:38 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.5 2020/03/25 22:15:53 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.6 2020/03/25 23:20:38 nisimura Exp $");
 
 #include 
 #include 
@@ -132,6 +132,7 @@ sniemmc_fdt_attach(device_t parent, devi
 	}
 
 	aprint_naive("\n");
+	aprint_normal_dev(self, "Socionext eMMC controller\n");
 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
 	sc->sc.sc_dev = self;
@@ -199,6 +200,7 @@ sniemmc_acpi_attach(device_t parent, dev
 	}
 
 	aprint_naive("\n");
+	aprint_normal_dev(self, "Socionext eMMC controller\n");
 
 	sc->sc.sc_dev = self;
 	sc->sc.sc_dmat = aa->aa_dmat;
@@ -227,7 +229,7 @@ sniemmc_attach_i(device_t self)
 	sc->sc.sc_flags |= SDHC_FLAG_32BIT_ACCESS;
 	sc->sc.sc_clkbase = 5;	/* Default to 50MHz */
 
-	aprint_normal_dev(sc->sc.sc_dev, "Socionext eMMC controller\n");
+	aprint_normal_dev(sc->sc.sc_dev, "doing sdhc_host() ...\n");
 #if 0
 	error = sdhc_host_found(>sc, sc->sc_iot, sc->sc_ioh, sc->sc_ios);
 #endif
Index: src/sys/arch/arm/sociox/sni_i2c.c
diff -u src/sys/arch/arm/sociox/sni_i2c.c:1.5 src/sys/arch/arm/sociox/sni_i2c.c:1.6
--- src/sys/arch/arm/sociox/sni_i2c.c:1.5	Wed Mar 25 22:15:53 2020
+++ src/sys/arch/arm/sociox/sni_i2c.c	Wed Mar 25 23:20:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_i2c.c,v 1.5 2020/03/25 22:15:53 nisimura Exp $	*/
+/*	$NetBSD: sni_i2c.c,v 1.6 2020/03/25 23:20:38 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.5 2020/03/25 22:15:53 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.6 2020/03/25 23:20:38 nisimura Exp $");
 
 #include 
 #include 
@@ -61,7 +61,6 @@ static void sniiic_acpi_attach(device_t,
 struct sniiic_softc {
 	device_t		sc_dev;
 	struct i2c_controller	sc_ic;
-	device_t		sc_i2cdev;
 	bus_space_tag_t		sc_iot;
 	bus_space_handle_t	sc_ioh;
 	bus_addr_t		sc_iob;
@@ -70,8 +69,7 @@ struct sniiic_softc {
 	kmutex_t		sc_lock;
 	kmutex_t		sc_mtx;
 	kcondvar_t		sc_cv;
-	int			sc_opflags;
-	bool			sc_busy;
+	volatile bool		sc_busy;
 	int			sc_phandle;
 };
 
@@ -81,6 +79,8 @@ CFATTACH_DECL_NEW(sniiic_fdt, sizeof(str
 CFATTACH_DECL_NEW(sniiic_acpi, sizeof(struct sniiic_softc),
 sniiic_acpi_match, sniiic_acpi_attach, NULL, NULL);
 
+void sni_i2c_common_i(struct sniiic_softc *);
+
 static int sni_i2c_acquire_bus(void *, int);
 static void sni_i2c_release_bus(void *, int);
 static int sni_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *,
@@ -148,7 +148,6 @@ sniiic_fdt_attach(device_t parent, devic
 	}
 
 	aprint_naive("\n");
-	aprint_normal_dev(self, "Socionext I2C controller\n");
 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
 	sc->sc_dev = self;
@@ -156,15 +155,8 @@ sniiic_fdt_attach(device_t parent, devic
 	sc->sc_ioh = ioh;
 	sc->sc_iob = addr;
 	sc->sc_ios = size;
-	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE);
-	mutex_init(>sc_mtx, MUTEX_DEFAULT, IPL_BIO);
-	cv_init(>sc_cv, device_xname(self));
 
-	iic_tag_init(>sc_ic);
-	sc->sc_ic.ic_cookie = sc;
-	sc->sc_ic.ic_acquire_bus = sni_i2c_acquire_bus;
-	sc->sc_ic.ic_release_bus = sni_i2c_release_bus;
-	sc->sc_ic.ic_exec = sni_i2c_exec;
+	sni_i2c_common_i(sc);
 
 	fdtbus_register_i2c_controller(self, phandle, _i2c_funcs);
 #if 0
@@ -226,22 +218,14 @@ sniiic_acpi_attach(device_t parent, devi
 	}
 
 	aprint_naive("\n");
-	aprint_normal_dev(self, "Socionext I2C controller\n");
 
 	sc->sc_dev = self;
 	sc->sc_iot = aa->aa_memt;
 	sc->sc_ioh = ioh;
 	sc->sc_iob = mem->ar_base;
 	sc->sc_ios = mem->ar_length;
-	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE);
-	mutex_init(>sc_mtx, MUTEX_DEFAULT, IPL_NET);
-	cv_init(>sc_cv, device_xname(self));
 
-	iic_tag_init(>sc_ic);	
-	sc->sc_ic.ic_cookie = sc;
-	sc->sc_ic.ic_acquire_bus = sni_i2c_acquire_bus;
-	sc->sc_ic.ic_release_bus = sni_i2c_release_bus;
-	sc->sc_ic.ic_exec = sni_i2c_exec;
+	sni_i2c_common_i(sc);
 
 	memset(, 0, sizeof(iba));
 	iba.iba_tag = >sc_ic;
@@ -258,6 +242,24 @@ sniiic_acpi_attach(device_t parent, devi
 	

CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 23:20:38 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c sni_i2c.c

Log Message:
DRT about config messages


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/sociox/sni_emmc.c \
src/sys/arch/arm/sociox/sni_i2c.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 22:15:53 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c sni_i2c.c

Log Message:
better boot messaging, redo


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sociox/sni_emmc.c \
src/sys/arch/arm/sociox/sni_i2c.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 22:15:53 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c sni_i2c.c

Log Message:
better boot messaging, redo


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sociox/sni_emmc.c \
src/sys/arch/arm/sociox/sni_i2c.c

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/sociox/sni_emmc.c
diff -u src/sys/arch/arm/sociox/sni_emmc.c:1.4 src/sys/arch/arm/sociox/sni_emmc.c:1.5
--- src/sys/arch/arm/sociox/sni_emmc.c:1.4	Wed Mar 25 22:11:00 2020
+++ src/sys/arch/arm/sociox/sni_emmc.c	Wed Mar 25 22:15:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_emmc.c,v 1.4 2020/03/25 22:11:00 nisimura Exp $	*/
+/*	$NetBSD: sni_emmc.c,v 1.5 2020/03/25 22:15:53 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.4 2020/03/25 22:11:00 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.5 2020/03/25 22:15:53 nisimura Exp $");
 
 #include 
 #include 
@@ -132,7 +132,7 @@ sniemmc_fdt_attach(device_t parent, devi
 	}
 
 	aprint_naive("\n");
-	aprint_normal_dev(self, ": interrupting on %s\n", intrstr);
+	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
 	sc->sc.sc_dev = self;
 	sc->sc.sc_dmat = faa->faa_dmat;
Index: src/sys/arch/arm/sociox/sni_i2c.c
diff -u src/sys/arch/arm/sociox/sni_i2c.c:1.4 src/sys/arch/arm/sociox/sni_i2c.c:1.5
--- src/sys/arch/arm/sociox/sni_i2c.c:1.4	Wed Mar 25 22:11:00 2020
+++ src/sys/arch/arm/sociox/sni_i2c.c	Wed Mar 25 22:15:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_i2c.c,v 1.4 2020/03/25 22:11:00 nisimura Exp $	*/
+/*	$NetBSD: sni_i2c.c,v 1.5 2020/03/25 22:15:53 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.4 2020/03/25 22:11:00 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.5 2020/03/25 22:15:53 nisimura Exp $");
 
 #include 
 #include 
@@ -148,8 +148,8 @@ sniiic_fdt_attach(device_t parent, devic
 	}
 
 	aprint_naive("\n");
-	aprint_normal_dev(self, ": Socionext I2C controller\n");
-	aprint_normal_dev(self, ": interrupting on %s\n", intrstr);
+	aprint_normal_dev(self, "Socionext I2C controller\n");
+	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
 	sc->sc_dev = self;
 	sc->sc_iot = faa->faa_bst;
@@ -226,7 +226,7 @@ sniiic_acpi_attach(device_t parent, devi
 	}
 
 	aprint_naive("\n");
-	aprint_normal_dev(self, ": Socionext I2C controller\n");
+	aprint_normal_dev(self, "Socionext I2C controller\n");
 
 	sc->sc_dev = self;
 	sc->sc_iot = aa->aa_memt;



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 22:11:00 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c sni_i2c.c

Log Message:
better boot messaging


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sociox/sni_emmc.c \
src/sys/arch/arm/sociox/sni_i2c.c

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/sociox/sni_emmc.c
diff -u src/sys/arch/arm/sociox/sni_emmc.c:1.3 src/sys/arch/arm/sociox/sni_emmc.c:1.4
--- src/sys/arch/arm/sociox/sni_emmc.c:1.3	Wed Mar 18 10:05:24 2020
+++ src/sys/arch/arm/sociox/sni_emmc.c	Wed Mar 25 22:11:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_emmc.c,v 1.3 2020/03/18 10:05:24 nisimura Exp $	*/
+/*	$NetBSD: sni_emmc.c,v 1.4 2020/03/25 22:11:00 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.3 2020/03/18 10:05:24 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_emmc.c,v 1.4 2020/03/25 22:11:00 nisimura Exp $");
 
 #include 
 #include 
@@ -66,12 +66,12 @@ struct sniemmc_softc {
 	bus_space_handle_t	sc_ioh;
 	bus_addr_t		sc_iob;
 	bus_size_t		sc_ios;
-	struct sdhc_host	*sc_hosts[1];
 	void			*sc_ih;
-	int			sc_phandle;
+	struct sdhc_host	*sc_hosts[1];
 	bus_dmamap_t		sc_dmamap;
 	bus_dma_segment_t	sc_segs[1];
 	kcondvar_t		sc_cv;
+	int			sc_phandle;
 };
 
 CFATTACH_DECL_NEW(sniemmc_fdt, sizeof(struct sniemmc_softc),
@@ -105,10 +105,8 @@ sniemmc_fdt_attach(device_t parent, devi
 	bus_space_handle_t ioh;
 	bus_addr_t addr;
 	bus_size_t size;
-	void *ih;
 	char intrstr[128];
 	_Bool disable;
-	int error;
 
 	prop_dictionary_get_bool(dict, "disable", );
 	if (disable) {
@@ -116,24 +114,25 @@ sniemmc_fdt_attach(device_t parent, devi
 		aprint_normal(": disabled\n");
 		return;
 	}
-	error = fdtbus_get_reg(phandle, 0, , );
-	if (error) {
-		aprint_error(": couldn't get registers\n");
-		return;
-	}
-	error = bus_space_map(faa->faa_bst, addr, size, 0, );
-	if (error) {
+	if (fdtbus_get_reg(phandle, 0, , ) != 0
+	|| bus_space_map(faa->faa_bst, addr, size, 0, ) != 0) {
 		aprint_error(": unable to map device\n");
 		return;
 	}
-	error = fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr));
-	if (error) {
+	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
 		aprint_error(": failed to decode interrupt\n");
-		return;
+		goto fail;
+	}
+	sc->sc_ih = fdtbus_intr_establish(phandle, 0, IPL_SDMMC, 0,
+	sdhc_intr, >sc);
+	if (sc->sc_ih == NULL) {
+		aprint_error_dev(self, "couldn't establish interrupt on %s\n",
+		intrstr);
+		goto fail;
 	}
 
-	aprint_naive(": SDHC controller\n");
-	aprint_normal(": SDHC controller\n");
+	aprint_naive("\n");
+	aprint_normal_dev(self, ": interrupting on %s\n", intrstr);
 
 	sc->sc.sc_dev = self;
 	sc->sc.sc_dmat = faa->faa_dmat;
@@ -144,18 +143,7 @@ sniemmc_fdt_attach(device_t parent, devi
 	sc->sc_iob = addr;
 	sc->sc_ios = size;
 
-	ih = fdtbus_intr_establish(phandle, 0, IPL_SDMMC, 0,
-	sdhc_intr, >sc);
-	if (ih == NULL) {
-		aprint_error_dev(self, "couldn't establish interrupt on %s\n",
-		intrstr);
-		goto fail;
-	}
-	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
-	sc->sc_ih = ih;
-
 	config_defer(self, sniemmc_attach_i);
-
 	return;
  fail:
 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
@@ -186,31 +174,31 @@ sniemmc_acpi_attach(device_t parent, dev
 	struct acpi_mem *mem;
 	struct acpi_irq *irq;
 	ACPI_STATUS rv;
-	void *ih;
 
 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
 	, _resource_parse_ops_default);
 	if (ACPI_FAILURE(rv))
 		return;
-
 	mem = acpi_res_mem(, 0);
 	irq = acpi_res_irq(, 0);
-	if (mem == NULL || irq == NULL) {
+	if (mem == NULL || irq == NULL || mem->ar_length == 0) {
 		aprint_error(": incomplete resources\n");
 		return;
 	}
-	if (mem->ar_length == 0) {
-		aprint_error(": zero length memory resource\n");
-		return;
-	}
 	if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0,
 	)) {
 		aprint_error(": couldn't map registers\n");
 		return;
 	}
+	sc->sc_ih = acpi_intr_establish(self,
+	(uint64_t)(uintptr_t)aa->aa_node->ad_handle,
+	IPL_BIO, false, sdhc_intr, >sc, device_xname(self));
+	if (sc->sc_ih == NULL) {
+		aprint_error_dev(self, "couldn't establish interrupt\n");
+		goto fail;
+	}
 
-	aprint_naive(": SDHC controller\n");
-	aprint_normal(": SDHC controller\n");
+	aprint_naive("\n");
 
 	sc->sc.sc_dev = self;
 	sc->sc.sc_dmat = aa->aa_dmat;
@@ -219,20 +207,10 @@ sniemmc_acpi_attach(device_t parent, dev
 	sc->sc_ioh = ioh;
 	sc->sc_ios = mem->ar_length;
 
-	ih = acpi_intr_establish(self,
-	(uint64_t)(uintptr_t)aa->aa_node->ad_handle,
-	IPL_BIO, false, sdhc_intr, >sc, device_xname(self));
-	if (ih == NULL) {
-		aprint_error_dev(self, "couldn't establish interrupt\n");
-		goto fail;
-	}
-	sc->sc_ih = ih;
-
 	config_defer(self, sniemmc_attach_i);
 
 	

CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 22:11:00 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_emmc.c sni_i2c.c

Log Message:
better boot messaging


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sociox/sni_emmc.c \
src/sys/arch/arm/sociox/sni_i2c.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 20:19:46 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
use dma32 for descriptor store. likely still missing freq designation(s)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.13 src/sys/arch/arm/sociox/if_scx.c:1.14
--- src/sys/arch/arm/sociox/if_scx.c:1.13	Wed Mar 25 01:39:49 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Wed Mar 25 20:19:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.13 2020/03/25 01:39:49 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.14 2020/03/25 20:19:46 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -53,10 +53,11 @@
  *   controls like FDT descriptions. Fortunately, Intel/Altera CycloneV PDFs
  *   describe every detail of "such the instance of" DW EMAC IP and
  *   most of them are likely applicable to SC2A11 GbE.
+ * - DW EMAC implmentation (0x20) is 0x10.0x36
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.13 2020/03/25 01:39:49 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.14 2020/03/25 20:19:46 nisimura Exp $");
 
 #include 
 #include 
@@ -166,7 +167,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define  FCR_RFE	(1U<<2)		/* accept PAUSE to throttle Tx */
 #define  FCR_TFE	(1U<<1)		/* generate PAUSE to moderate Rx lvl */
 #define GMACVTAG	0x001c		/* VLAN tag control */
-#define GMACIMPL	0x0020		/* implementation number . */
+#define GMACIMPL	0x0020		/* implementation number XX.YY */
 #define GMACMAH0	0x0040		/* MAC address 0 47:32 */
 #define GMACMAL0	0x0044		/* MAC address 0 31:0 */
 #define GMACMAH(i) 	((i)*8+0x40)	/* supplimental MAC addr 1 - 15 */
@@ -174,7 +175,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define GMACMIISR	0x00d8		/* resolved xMII link status */
 	/*  3   link up detected
 	 *  2:1 resovled speed
-	 *  0 2.5Mhz (10Mbps) 
+	 *  0 2.5Mhz (10Mbps)
 	 *	1 25Mhz  (100bps)
 	 *	2 125Mhz (1000Mbps)
 	 *  1   full duplex detected */
@@ -306,6 +307,7 @@ struct scx_softc {
 	bus_space_handle_t sc_eesh;	/* eeprom section handle */
 	bus_size_t sc_eesz;		/* eeprom map size */
 	bus_dma_tag_t sc_dmat;		/* bus DMA tag */
+	bus_dma_tag_t sc_dmat32;
 	struct ethercom sc_ethercom;	/* Ethernet common data */
 	struct mii_data sc_mii;		/* MII */
 	callout_t sc_tick_ch;		/* PHY monitor callout */
@@ -319,6 +321,7 @@ struct scx_softc {
 	int sc_ucodeloaded;		/* ucode for H2M/M2H/PKT */
 	int sc_100mii;			/* 1 for RMII/MII, 0 for RGMII */
 	int sc_phandle;			/* fdt phandle */
+	uint64_t sc_freq;
 
 	bus_dmamap_t sc_cddmamap;	/* control data DMA map */
 #define sc_cddma	sc_cddmamap->dm_segs[0].ds_addr
@@ -399,12 +402,12 @@ static void txreap(struct scx_softc *);
 static void rxintr(struct scx_softc *);
 static int add_rxbuf(struct scx_softc *, int);
 
-static int get_mdioclk(uint32_t);
 static int spin_waitfor(struct scx_softc *, int, int);
 static int mac_read(struct scx_softc *, int);
 static void mac_write(struct scx_softc *, int, int);
 static void loaducode(struct scx_softc *);
 static void injectucode(struct scx_softc *, int, bus_addr_t, bus_size_t);
+static int get_mdioclk(uint32_t);
 
 #define CSR_READ(sc,off) \
 	bus_space_read_4((sc)->sc_st, (sc)->sc_sh, (off))
@@ -460,14 +463,9 @@ scx_fdt_attach(device_t parent, device_t
 		goto fail;
 	}
 
-	phy_mode = fdtbus_get_string(phandle, "phy-mode");
-	if (phy_mode == NULL) {
-		aprint_error(": missing 'phy-mode' property\n");
-		phy_mode = "rgmii";
-	}
 
 	aprint_naive("\n");
-	aprint_normal(": Gigabit Ethernet Controller\n");
+	/* aprint_normal(": Gigabit Ethernet Controller\n"); */
 	aprint_normal_dev(self, "interrupt on %s\n", intrstr);
 
 	sc->sc_dev = self;
@@ -478,7 +476,15 @@ scx_fdt_attach(device_t parent, device_t
 	sc->sc_eesz = size[1];
 	sc->sc_dmat = faa->faa_dmat;
 	sc->sc_phandle = phandle;
-	sc->sc_100mii = (strcmp(phy_mode, "rgmii") != 0);
+
+	phy_mode = fdtbus_get_string(phandle, "phy-mode");
+	if (phy_mode == NULL)
+		aprint_error(": missing 'phy-mode' property\n");
+	sc->sc_100mii = (phy_mode != NULL && strcmp(phy_mode, "rgmii") != 0);
+sc->sc_phy_id = 7; /* XXX */
+sc->sc_freq = 250 * 1000 * 1000; /* XXX */
+aprint_normal_dev(self,
+"phy mode %s, phy id %d, freq %ld\n", phy_mode, sc->sc_phy_id, sc->sc_freq);
 
 	scx_attach_i(sc);
 	return;
@@ -515,13 +521,14 @@ scx_acpi_attach(device_t parent, device_
 	struct acpi_resources res;
 	struct acpi_mem *mem;
 	struct acpi_irq *irq;
+	char *phy_mode;
+	ACPI_INTEGER acpi_phy, acpi_freq;
 	ACPI_STATUS rv;
 
 	rv = acpi_resource_parse(self, handle, "_CRS",
 	, _resource_parse_ops_default);
 	if (ACPI_FAILURE(rv))
 		return;
-acpi_resource_print(self, );
 	mem = acpi_res_mem(, 0);
 	irq = 

CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 20:19:46 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
use dma32 for descriptor store. likely still missing freq designation(s)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 18:42:17 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_gpio.c

Log Message:
try to decode _DSD ACPI resource


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sociox/sni_gpio.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 19:03:44 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_gpio.c

Log Message:
describe DeveloperBox pin assignment correctly


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sociox/sni_gpio.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 19:03:44 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_gpio.c

Log Message:
describe DeveloperBox pin assignment correctly


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/arm/sociox/sni_gpio.c

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/sociox/sni_gpio.c
diff -u src/sys/arch/arm/sociox/sni_gpio.c:1.4 src/sys/arch/arm/sociox/sni_gpio.c:1.5
--- src/sys/arch/arm/sociox/sni_gpio.c:1.4	Wed Mar 25 18:42:16 2020
+++ src/sys/arch/arm/sociox/sni_gpio.c	Wed Mar 25 19:03:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_gpio.c,v 1.4 2020/03/25 18:42:16 nisimura Exp $	*/
+/*	$NetBSD: sni_gpio.c,v 1.5 2020/03/25 19:03:44 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.4 2020/03/25 18:42:16 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.5 2020/03/25 19:03:44 nisimura Exp $");
 
 #include 
 #include 
@@ -82,21 +82,21 @@ CFATTACH_DECL_NEW(snigpio_acpi, sizeof(s
  * "DevelopmentBox" implementation
  *DSW3-PIN1,  DSW3-PIN2,  DSW3-PIN3,DSW3-PIN4,
  *DSW3-PIN5,  DSW3-PIN6,  DSW3-PIN7,DSW3-PIN8,
- *PEC-PD8,PEC-PD9,PEC-PD10, PEC-PD11,
- *NC, NC, PCIE1EXTINT,  PCIE0EXTINT,
- *PHY_P2_2,   PHY_P1_2,   NC,   NC,
- *NC, NC, NC,   NC,
- *NC, NC, PEC-PD26, PEC-PD27,
- *PEC-PD28,   PEC-PD29,   PEC-PD30, PEC-PD31;
+ *PSIN#,  PWROFF#,GPIO-A,   GPIO-B,
+ *GPIO-C, GPIO-D, PCIE1EXTINT,  PCIE0EXTINT,
+ *PHY2-INT#,  PHY1-INT#,  GPIO-E,   GPIO-F,
+ *GPIO-G, GPIO-H, GPIO-I,   GPIO-J,
+ *GPIO-K, GPIO-L, PEC-PD26, PEC-PD27,
+ *PEC-PD28,   PEC-PD29,   PEC-PD30, PEC-PD31
  *
- *PD/PC/PB/PA 0-7 in this order.
  *DSW3-PIN1 -- what's "varstore" really this
  *DSW3-PIN3 -- tweek PCIe bus implementation error toggle
+ *PowerButton (PWROFF#) can be detectable.
  *
  *  96board mezzanine
  *i2c  "/i2c@51221000"
  *spi  "/spi@5481"
- *gpio "/gpio@5100" pinA-L (10-25) level? sensitive
+ *gpio "/gpio@5100" pinA-L (10-25) down edge sensitive
  */
 static void snigpio_attach_i(struct snigpio_softc *);
 static int snigpio_intr(void *);
@@ -225,15 +225,13 @@ snigpio_acpi_attach(device_t parent, dev
 	sc->sc_ioh = ioh;
 	sc->sc_ios = mem->ar_length;
 
+	snigpio_attach_i(sc);
+
 	/* dig _DSD property to show 32 of GPIO line usage */
 	rv = acpi_dsd_string(handle, "gpio-line-names", );
-	if (ACPI_FAILURE(rv))
-		list = NULL;
-	else
+	if (ACPI_SUCCESS(rv))
 		aprint_normal_dev(self, "%s\n", list);
 
-	snigpio_attach_i(sc);
-
 	acpi_resource_cleanup();
 	return;
  fail:



CVS commit: src/sys/arch/arm/sociox

2020-03-25 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 18:42:17 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_gpio.c

Log Message:
try to decode _DSD ACPI resource


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sociox/sni_gpio.c

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/sociox/sni_gpio.c
diff -u src/sys/arch/arm/sociox/sni_gpio.c:1.3 src/sys/arch/arm/sociox/sni_gpio.c:1.4
--- src/sys/arch/arm/sociox/sni_gpio.c:1.3	Tue Mar 24 11:40:08 2020
+++ src/sys/arch/arm/sociox/sni_gpio.c	Wed Mar 25 18:42:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_gpio.c,v 1.3 2020/03/24 11:40:08 nisimura Exp $	*/
+/*	$NetBSD: sni_gpio.c,v 1.4 2020/03/25 18:42:16 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.3 2020/03/24 11:40:08 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.4 2020/03/25 18:42:16 nisimura Exp $");
 
 #include 
 #include 
@@ -88,6 +88,15 @@ CFATTACH_DECL_NEW(snigpio_acpi, sizeof(s
  *NC, NC, NC,   NC,
  *NC, NC, PEC-PD26, PEC-PD27,
  *PEC-PD28,   PEC-PD29,   PEC-PD30, PEC-PD31;
+ *
+ *PD/PC/PB/PA 0-7 in this order.
+ *DSW3-PIN1 -- what's "varstore" really this
+ *DSW3-PIN3 -- tweek PCIe bus implementation error toggle
+ *
+ *  96board mezzanine
+ *i2c  "/i2c@51221000"
+ *spi  "/spi@5481"
+ *gpio "/gpio@5100" pinA-L (10-25) level? sensitive
  */
 static void snigpio_attach_i(struct snigpio_softc *);
 static int snigpio_intr(void *);
@@ -154,7 +163,6 @@ snigpio_fdt_attach(device_t parent, devi
 	snigpio_attach_i(sc);
 
 /* dig FDT description to show 32 of GPIO line usage */
-/* DIPSW3 1-8 usage remain unclear */
 
 	return;
  fail:
@@ -181,11 +189,13 @@ snigpio_acpi_attach(device_t parent, dev
 {
 	struct snigpio_softc * const sc = device_private(self);
 	struct acpi_attach_args *aa = aux;
+	ACPI_HANDLE handle = aa->aa_node->ad_handle;
 	bus_space_handle_t ioh;
 	struct acpi_resources res;
 	struct acpi_mem *mem;
 	struct acpi_irq *irq;
 	ACPI_STATUS rv;
+	char *list;
 
 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
 	, _resource_parse_ops_default);
@@ -215,10 +225,14 @@ snigpio_acpi_attach(device_t parent, dev
 	sc->sc_ioh = ioh;
 	sc->sc_ios = mem->ar_length;
 
-	snigpio_attach_i(sc);
+	/* dig _DSD property to show 32 of GPIO line usage */
+	rv = acpi_dsd_string(handle, "gpio-line-names", );
+	if (ACPI_FAILURE(rv))
+		list = NULL;
+	else
+		aprint_normal_dev(self, "%s\n", list);
 
-/* dig _DSD property to show 32 of GPIO line usage */
-/* DIPSW3 1-8 usage remain unclear */
+	snigpio_attach_i(sc);
 
 	acpi_resource_cleanup();
 	return;



CVS commit: src/sys/arch/arm/sociox

2020-03-24 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 01:39:50 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
make sure to use mac_write() for GMACxxx registers. try to decode xMII link 
status report


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-24 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Mar 25 01:39:50 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
make sure to use mac_write() for GMACxxx registers. try to decode xMII link 
status report


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.12 src/sys/arch/arm/sociox/if_scx.c:1.13
--- src/sys/arch/arm/sociox/if_scx.c:1.12	Tue Mar 24 13:44:21 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Wed Mar 25 01:39:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.12 2020/03/24 13:44:21 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.13 2020/03/25 01:39:49 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.12 2020/03/24 13:44:21 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.13 2020/03/25 01:39:49 nisimura Exp $");
 
 #include 
 #include 
@@ -83,6 +83,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #include 
 #include 
 
+/* SC2A11 register block */
 #define SWRESET		0x104
 #define COMINIT		0x120
 #define INTRST		0x200
@@ -124,6 +125,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define DESCENG_INIT	0x11fc
 #define DESCENG_SRST	0x1204
 
+/* GMAC register block. use mac_write()/mac_read() to handle */
 #define GMACMCR		0x		/* MAC configuration */
 #define  MCR_IBN	(1U<<30)	/* */
 #define  MCR_CST	(1U<<25)	/* strip CRC */
@@ -169,13 +171,21 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define GMACMAL0	0x0044		/* MAC address 0 31:0 */
 #define GMACMAH(i) 	((i)*8+0x40)	/* supplimental MAC addr 1 - 15 */
 #define GMACMAL(i) 	((i)*8+0x44)
-#define GMACMDSR	0x00d8		/* GMII/RGMII/MII command/status */
+#define GMACMIISR	0x00d8		/* resolved xMII link status */
+	/*  3   link up detected
+	 *  2:1 resovled speed
+	 *  0 2.5Mhz (10Mbps) 
+	 *	1 25Mhz  (100bps)
+	 *	2 125Mhz (1000Mbps)
+	 *  1   full duplex detected */
+
 #define GMACMHT0	0x0500		/* multicast hash table 0 - 7 */
 #define GMACMHT(i)	((i)*4+0x500)
 #define GMACVHT		0x0588		/* VLAN tag hash */
 #define GMACAMAH(i)	((i)*8+0x800)	/* supplimental MAC addr 16-127 */
 #define GMACAMAL(i)	((i)*8+0x804)
 #define GMACEVCNT(i)	((i)*4+0x114)	/* event counter 0x114~284 */
+#define GMACEVCTL	0x0100		/* clear event counter registers */
 
 #define GMACBMR		0x1000		/* DMA bus mode control
 	 * 244PBL
@@ -202,8 +212,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define  OMR_TXE	(1U<<13)	/* start Tx DMA engine, 0 to stop */
 #define  OMR_RXE	(1U<<1)		/* start Rx DMA engine, 0 to stop */
 
-static int get_mdioclk(uint32_t);
-
 /* descriptor format definition */
 struct tdes {
 	uint32_t t0, t1, t2, t3;
@@ -390,6 +398,8 @@ static int scx_intr(void *);
 static void txreap(struct scx_softc *);
 static void rxintr(struct scx_softc *);
 static int add_rxbuf(struct scx_softc *, int);
+
+static int get_mdioclk(uint32_t);
 static int spin_waitfor(struct scx_softc *, int, int);
 static int mac_read(struct scx_softc *, int);
 static void mac_write(struct scx_softc *, int, int);
@@ -585,7 +595,7 @@ scx_attach_i(struct scx_softc *sc)
 	csr = bus_space_read_4(sc->sc_st, sc->sc_eesh, 4);
 	enaddr[4] = csr >> 24;
 	enaddr[5] = csr >> 16;
-	csr = CSR_READ(sc, GMACIMPL);
+	csr = mac_read(sc, GMACIMPL);
 
 	aprint_normal_dev(sc->sc_dev, "NetSec GbE (%d.%d) impl (%x.%x)\n",
 	hwver >> 16, hwver & 0x, csr >> 16, csr & 0x);
@@ -747,6 +757,7 @@ scx_reset(struct scx_softc *sc)
 	mac_write(sc, GMACRDLAR, _RDLAR);
 	mac_write(sc, GMACTDLAR, _TDLAR);
 	mac_write(sc, GMACAFR, _AFR);
+	mac_write(sc, GMACEVCTL, 1);
 }
 
 static int
@@ -763,28 +774,43 @@ scx_init(struct ifnet *ifp)
 	/* Reset the chip to a known state. */
 	scx_reset(sc);
 
-	/* build sane Tx and load Rx descriptors with mbuf */
-	for (i = 0; i < MD_NTXDESC; i++)
-		sc->sc_txdescs[i].t0 = T0_OWN;
-	sc->sc_txdescs[MD_NTXDESC - 1].t0 |= T0_EOD; /* tie off the ring */
-	for (i = 0; i < MD_NRXDESC; i++)
-		(void)add_rxbuf(sc, i);
-
 	/* set my address in perfect match slot 0 */
 	csr = (ea[3] << 24) | (ea[2] << 16) | (ea[1] << 8) |  ea[0];
-	CSR_WRITE(sc, GMACMAL0, csr);
+	mac_write(sc, GMACMAL0, csr);
 	csr = (ea[5] << 8) | ea[4];
-	CSR_WRITE(sc, GMACMAH0, csr | 1U<<31); /* always valid? */
+	mac_write(sc, GMACMAH0, csr | 1U<<31); /* always valid? */
 
 	/* accept multicast frame or run promisc mode */
 	scx_set_rcvfilt(sc);
 
 	(void)scx_ifmedia_upd(ifp);
 
+	/* build sane Tx */
+	memset(sc->sc_txdescs, 0, sizeof(struct tdes) * MD_NTXDESC);
+	sc->sc_txdescs[MD_NTXDESC - 1].t0 |= T0_EOD; /* tie off the ring */
+	SCX_CDTXSYNC(sc, 0, MD_NTXDESC,
+		BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
+	sc->sc_txfree = MD_NTXDESC;
+	sc->sc_txnext = 0;
+	for (i = 0; i < 

CVS commit: src/sys/arch/arm/sociox

2020-03-24 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Mar 24 13:44:21 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
add more register description


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-24 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Mar 24 13:44:21 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
add more register description


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.11 src/sys/arch/arm/sociox/if_scx.c:1.12
--- src/sys/arch/arm/sociox/if_scx.c:1.11	Tue Mar 24 13:07:46 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Tue Mar 24 13:44:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.11 2020/03/24 13:07:46 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.12 2020/03/24 13:44:21 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.11 2020/03/24 13:07:46 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.12 2020/03/24 13:44:21 nisimura Exp $");
 
 #include 
 #include 
@@ -169,11 +169,13 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define GMACMAL0	0x0044		/* MAC address 0 31:0 */
 #define GMACMAH(i) 	((i)*8+0x40)	/* supplimental MAC addr 1 - 15 */
 #define GMACMAL(i) 	((i)*8+0x44)
+#define GMACMDSR	0x00d8		/* GMII/RGMII/MII command/status */
 #define GMACMHT0	0x0500		/* multicast hash table 0 - 7 */
 #define GMACMHT(i)	((i)*4+0x500)
 #define GMACVHT		0x0588		/* VLAN tag hash */
 #define GMACAMAH(i)	((i)*8+0x800)	/* supplimental MAC addr 16-127 */
 #define GMACAMAL(i)	((i)*8+0x804)
+#define GMACEVCNT(i)	((i)*4+0x114)	/* event counter 0x114~284 */
 
 #define GMACBMR		0x1000		/* DMA bus mode control
 	 * 244PBL
@@ -185,15 +187,17 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 	 *  1rxtx ratio 21
 	 *  0rxtx ratio 11
 	 * 13:8  PBL possible DMA burst len
-	 * 0 reset op. self clear
+	 *  0reset op. self clear
 	 */
 #define  _BMR		0x00412080	/* XXX TBD */
 #define  _BMR0		0x00020181	/* XXX TBD */
 #define  BMR_RST	(1U<<0)		/* reset op. self clear when done */
-#define GMACRDLAR	0x100c		/* */
-#define  _RDLAR		0x18000		/* XXX TBD */
-#define GMACTDLAR	0x1010		/* */
-#define  _TDLAR		0x1c000		/* XXX TBD */
+#define GMACTDS		0x1004		/* write any to resume tdes */
+#define GMACRDS		0x1008		/* write any to resume rdes */
+#define GMACRDLAR	0x100c		/* rdes base address 32bit paddr */
+#define  _RDLAR		0x18000		/* XXX TBD system SRAM with CC ? */
+#define GMACTDLAR	0x1010		/* tdes base address 32bit paddr */
+#define  _TDLAR		0x1c000		/* XXX TBD system SRAM with CC ? */
 #define GMACOMR		0x1018		/* DMA operation */
 #define  OMR_TXE	(1U<<13)	/* start Tx DMA engine, 0 to stop */
 #define  OMR_RXE	(1U<<1)		/* start Rx DMA engine, 0 to stop */
@@ -1203,7 +1207,7 @@ scx_start(struct ifnet *ifp)
 		BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
 
 		/* Tell DMA start transmit */
-		/* CSR_WRITE(sc, MDTSC, 1); */
+		/* CSR_WRITE(sc, GMACTDS, 1); */
 
 		txs->txs_mbuf = m0;
 		txs->txs_firstdesc = sc->sc_txnext;



CVS commit: src/sys/arch/arm/sociox

2020-03-24 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Mar 24 13:07:46 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
add more registers supposed to exist


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/sociox/if_scx.c

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



CVS commit: src/sys/arch/arm/sociox

2020-03-24 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Mar 24 13:07:46 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: if_scx.c

Log Message:
add more registers supposed to exist


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/sociox/if_scx.c

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/sociox/if_scx.c
diff -u src/sys/arch/arm/sociox/if_scx.c:1.10 src/sys/arch/arm/sociox/if_scx.c:1.11
--- src/sys/arch/arm/sociox/if_scx.c:1.10	Tue Mar 24 11:26:21 2020
+++ src/sys/arch/arm/sociox/if_scx.c	Tue Mar 24 13:07:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_scx.c,v 1.10 2020/03/24 11:26:21 nisimura Exp $	*/
+/*	$NetBSD: if_scx.c,v 1.11 2020/03/24 13:07:46 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.10 2020/03/24 11:26:21 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.11 2020/03/24 13:07:46 nisimura Exp $");
 
 #include 
 #include 
@@ -170,17 +170,20 @@ __KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1
 #define GMACMAH(i) 	((i)*8+0x40)	/* supplimental MAC addr 1 - 15 */
 #define GMACMAL(i) 	((i)*8+0x44)
 #define GMACMHT0	0x0500		/* multicast hash table 0 - 7 */
-#define GMACMHT(i)	((i)*4+0500)
+#define GMACMHT(i)	((i)*4+0x500)
+#define GMACVHT		0x0588		/* VLAN tag hash */
+#define GMACAMAH(i)	((i)*8+0x800)	/* supplimental MAC addr 16-127 */
+#define GMACAMAL(i)	((i)*8+0x804)
 
 #define GMACBMR		0x1000		/* DMA bus mode control
 	 * 244PBL
 	 * 22:17 RPBL
 	 * 16fix burst
 	 * 15:14 priority between Rx and Tx
-	 *  3rxtx41
-	 *  2rxtx31
-	 *  1rxtx21
-	 *  0rxtx11
+	 *  3rxtx ratio 41
+	 *  2rxtx ratio 31
+	 *  1rxtx ratio 21
+	 *  0rxtx ratio 11
 	 * 13:8  PBL possible DMA burst len
 	 * 0 reset op. self clear
 	 */



CVS commit: src/sys/arch/arm/sociox

2020-03-24 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Mar 24 11:40:08 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_gpio.c

Log Message:
try to show 32 GPIO line usage


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sociox/sni_gpio.c

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/sociox/sni_gpio.c
diff -u src/sys/arch/arm/sociox/sni_gpio.c:1.2 src/sys/arch/arm/sociox/sni_gpio.c:1.3
--- src/sys/arch/arm/sociox/sni_gpio.c:1.2	Thu Mar 19 20:53:53 2020
+++ src/sys/arch/arm/sociox/sni_gpio.c	Tue Mar 24 11:40:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sni_gpio.c,v 1.2 2020/03/19 20:53:53 nisimura Exp $	*/
+/*	$NetBSD: sni_gpio.c,v 1.3 2020/03/24 11:40:08 nisimura Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.2 2020/03/19 20:53:53 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.3 2020/03/24 11:40:08 nisimura Exp $");
 
 #include 
 #include 
@@ -64,6 +64,7 @@ struct snigpio_softc {
 	bus_space_handle_t	sc_ioh;
 	bus_addr_t		sc_iob;
 	bus_size_t		sc_ios;
+	void			*sc_ih;
 	kmutex_t		sc_lock;
 	struct gpio_chipset_tag	sc_gpio_gc;
 	gpio_pin_t		sc_gpio_pins[32];
@@ -77,7 +78,19 @@ CFATTACH_DECL_NEW(snigpio_fdt, sizeof(st
 CFATTACH_DECL_NEW(snigpio_acpi, sizeof(struct snigpio_softc),
 snigpio_acpi_match, snigpio_acpi_attach, NULL, NULL);
 
+/*
+ * "DevelopmentBox" implementation
+ *DSW3-PIN1,  DSW3-PIN2,  DSW3-PIN3,DSW3-PIN4,
+ *DSW3-PIN5,  DSW3-PIN6,  DSW3-PIN7,DSW3-PIN8,
+ *PEC-PD8,PEC-PD9,PEC-PD10, PEC-PD11,
+ *NC, NC, PCIE1EXTINT,  PCIE0EXTINT,
+ *PHY_P2_2,   PHY_P1_2,   NC,   NC,
+ *NC, NC, NC,   NC,
+ *NC, NC, PEC-PD26, PEC-PD27,
+ *PEC-PD28,   PEC-PD29,   PEC-PD30, PEC-PD31;
+ */
 static void snigpio_attach_i(struct snigpio_softc *);
+static int snigpio_intr(void *);
 
 static int
 snigpio_fdt_match(device_t parent, struct cfdata *match, void *aux)
@@ -102,8 +115,8 @@ snigpio_fdt_attach(device_t parent, devi
 	bus_space_handle_t ioh;
 	bus_addr_t addr;
 	bus_size_t size;
+	char intrstr[128];
 	_Bool disable;
-	int error;
 
 	prop_dictionary_get_bool(dict, "disable", );
 	if (disable) {
@@ -111,16 +124,25 @@ snigpio_fdt_attach(device_t parent, devi
 		aprint_normal(": disabled\n");
 		return;
 	}
-	error = fdtbus_get_reg(phandle, 0, , );
-	if (error) {
-		aprint_error(": couldn't get registers\n");
-		return;
-	}
-	error = bus_space_map(faa->faa_bst, addr, size, 0, );
-	if (error) {
+	if (fdtbus_get_reg(phandle, 0, , ) != 0
+	|| bus_space_map(faa->faa_bst, addr, size, 0, ) != 0) {
 		aprint_error(": unable to map device\n");
 		return;
 	}
+	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
+		aprint_error(": failed to decode interrupt\n");
+		goto fail;
+	}
+	sc->sc_ih = fdtbus_intr_establish(phandle,
+			0, IPL_VM, 0, snigpio_intr, sc);
+	if (sc->sc_ih == NULL) {
+		aprint_error_dev(self, "couldn't establish interrupt\n");
+		goto fail;
+	}
+
+	aprint_naive("\n");
+	aprint_normal(": GPIO controller\n");
+	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
 
 	sc->sc_dev = self;
 	sc->sc_phandle = phandle;
@@ -131,7 +153,13 @@ snigpio_fdt_attach(device_t parent, devi
 
 	snigpio_attach_i(sc);
 
+/* dig FDT description to show 32 of GPIO line usage */
+/* DIPSW3 1-8 usage remain unclear */
+
 	return;
+ fail:
+	bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
+	return;	
 }
 
 static int
@@ -163,22 +191,24 @@ snigpio_acpi_attach(device_t parent, dev
 	, _resource_parse_ops_default);
 	if (ACPI_FAILURE(rv))
 		return;
-
 	mem = acpi_res_mem(, 0);
 	irq = acpi_res_irq(, 0);
-	if (mem == NULL || irq == NULL) {
+	if (mem == NULL || irq == NULL || mem->ar_length == 0) {
 		aprint_error(": incomplete resources\n");
 		return;
 	}
-	if (mem->ar_length == 0) {
-		aprint_error(": zero length memory resource\n");
-		return;
-	}
 	if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0,
 	)) {
 		aprint_error(": couldn't map registers\n");
 		return;
 	}
+	sc->sc_ih = acpi_intr_establish(self,
+	(uint64_t)(uintptr_t)aa->aa_node->ad_handle,
+	IPL_VM, false, snigpio_intr, sc, device_xname(self));
+	if (sc->sc_ih == NULL) {
+		aprint_error_dev(self, "couldn't establish interrupt\n");
+		goto fail;
+	}
 
 	sc->sc_dev = self;
 	sc->sc_iot = aa->aa_memt;
@@ -186,31 +216,46 @@ snigpio_acpi_attach(device_t parent, dev
 	sc->sc_ios = mem->ar_length;
 
 	snigpio_attach_i(sc);
+
+/* dig _DSD property to show 32 of GPIO line usage */
+/* DIPSW3 1-8 usage remain unclear */
+
+	acpi_resource_cleanup();
+	return;
+ fail:
+	acpi_resource_cleanup();
+	bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
+	return;	
 }
 
 static void
 snigpio_attach_i(struct snigpio_softc *sc)
 {
+	struct 

CVS commit: src/sys/arch/arm/sociox

2020-03-24 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Tue Mar 24 11:40:08 UTC 2020

Modified Files:
src/sys/arch/arm/sociox: sni_gpio.c

Log Message:
try to show 32 GPIO line usage


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sociox/sni_gpio.c

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



  1   2   >