[PATCH 4/4] Added ethernet support for Raspberry Pi. USB DMA related functions commented out, since DMA support for raspberry is underdevelopment.

Deval Shah deval.maker at gmail.com
Fri Aug 19 08:46:53 UTC 2016


---
 freebsd/sys/dev/usb/net/if_smsc.c                  | 44 ++++++++++++++++++++++
 freebsd/sys/dev/usb/net/if_smscreg.h               |  1 +
 freebsd/sys/dev/usb/net/usb_ethernet.c             | 17 +++++++++
 freebsd/sys/sys/sysctl.h                           |  1 +
 rtemsbsd/include/bsp/nexus-devices.h               |  2 +
 rtemsbsd/include/machine/rtems-bsd-nexus-bus.h     | 18 +++++++++
 .../include/rtems/bsd/test/network-config.h.in     |  2 +
 7 files changed, 85 insertions(+)

diff --git a/freebsd/sys/dev/usb/net/if_smsc.c b/freebsd/sys/dev/usb/net/if_smsc.c
index 3bdd35a..bdae5eb 100644
--- a/freebsd/sys/dev/usb/net/if_smsc.c
+++ b/freebsd/sys/dev/usb/net/if_smsc.c
@@ -91,7 +91,9 @@ __FBSDID("$FreeBSD$");
 #include <netinet/in.h>
 #include <netinet/ip.h>
 
+#ifndef __rtems__
 #include <rtems/bsd/local/opt_platform.h>
+#endif
 
 #ifdef FDT
 #include <dev/fdt/fdt_common.h>
@@ -996,7 +998,9 @@ smsc_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
 			/* The frame header is always aligned on a 4 byte boundary */
 			off = ((off + 0x3) & ~0x3);
 
+			#ifndef __rtems__
 			usbd_copy_out(pc, off, &rxhdr, sizeof(rxhdr));
+			#endif
 			off += (sizeof(rxhdr) + ETHER_ALIGN);
 			rxhdr = le32toh(rxhdr);
 		
@@ -1008,9 +1012,21 @@ smsc_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
 			
 			if (rxhdr & SMSC_RX_STAT_ERROR) {
 				smsc_dbg_printf(sc, "rx error (hdr 0x%08x)\n", rxhdr);
+
+				#ifndef __rtems__
 				if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
+				#else /* __rtems__ */
+				ifp->if_ierrors++;
+				#endif /* __rtems__ */
+
 				if (rxhdr & SMSC_RX_STAT_COLLISION)
+
+					#ifndef __rtems__
 					if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1);
+					#else /* __rtems__ */
+					sc->ifp->if_collisions += 1;
+					#endif /* __rtems__ */
+
 			} else {
 
 				/* Check if the ethernet frame is too big or too small */
@@ -1021,12 +1037,20 @@ smsc_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
 				m = uether_newbuf();
 				if (m == NULL) {
 					smsc_warn_printf(sc, "failed to create new mbuf\n");
+
+					#ifndef __rtems__
 					if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1);
+					#else /* __rtems__ */
+					ifp->if_iqdrops++;
+					#endif /* __rtems__ */
+
 					goto tr_setup;
 				}
+				#ifndef __rtems__
 				
 				usbd_copy_out(pc, off, mtod(m, uint8_t *), pktlen);
 
+				#endif
 				/* Check if RX TCP/UDP checksumming is being offloaded */
 				if ((ifp->if_capenable & IFCAP_RXCSUM) != 0) {
 
@@ -1061,9 +1085,11 @@ smsc_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
 							/* Copy the TCP/UDP checksum from the last 2 bytes
 							 * of the transfer and put in the csum_data field.
 							 */
+							#ifndef __rtems__
 							usbd_copy_out(pc, (off + pktlen),
 							              &m->m_pkthdr.csum_data, 2);
 
+							#endif
 							/* The data is copied in network order, but the
 							 * csum algorithm in the kernel expects it to be
 							 * in host network order.
@@ -1165,19 +1191,31 @@ tr_setup:
 			txhdr = SMSC_TX_CTRL_0_BUF_SIZE(m->m_pkthdr.len) | 
 					SMSC_TX_CTRL_0_FIRST_SEG | SMSC_TX_CTRL_0_LAST_SEG;
 			txhdr = htole32(txhdr);
+			#ifndef __rtems__
 			usbd_copy_in(pc, 0, &txhdr, sizeof(txhdr));
 			
+			#endif
+
 			txhdr = SMSC_TX_CTRL_1_PKT_LENGTH(m->m_pkthdr.len);
 			txhdr = htole32(txhdr);
+			#ifndef __rtems__
 			usbd_copy_in(pc, 4, &txhdr, sizeof(txhdr));
 			
+			#endif
+
 			frm_len += 8;
 
 			/* Next copy in the actual packet */
+			#ifndef __rtems__
 			usbd_m_copy_in(pc, frm_len, m, 0, m->m_pkthdr.len);
+			#endif
 			frm_len += m->m_pkthdr.len;
 
+			#ifndef __rtems__
 			if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
+			#else /* __rtems__ */
+			sc->ifp->if_opackets++;
+			#endif /* __rtems__ */
 
 			/* If there's a BPF listener, bounce a copy of this frame to him */
 			BPF_MTAP(ifp, m);
@@ -1195,7 +1233,13 @@ tr_setup:
 		return;
 
 	default:
+
+		#ifndef __rtems__
 		if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
+		#else /* __rtems__ */
+		sc->ifp->if_oerrors++;
+		#endif /* __rtems__ */
+
 		ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
 		
 		if (error != USB_ERR_CANCELLED) {
diff --git a/freebsd/sys/dev/usb/net/if_smscreg.h b/freebsd/sys/dev/usb/net/if_smscreg.h
index 31a6382..cce37ec 100644
--- a/freebsd/sys/dev/usb/net/if_smscreg.h
+++ b/freebsd/sys/dev/usb/net/if_smscreg.h
@@ -256,6 +256,7 @@ enum {
 };
 
 struct smsc_softc {
+	struct ifnet		*ifp;
 	struct usb_ether  sc_ue;
 	struct mtx        sc_mtx;
 	struct usb_xfer  *sc_xfer[SMSC_N_TRANSFER];
diff --git a/freebsd/sys/dev/usb/net/usb_ethernet.c b/freebsd/sys/dev/usb/net/usb_ethernet.c
index 0d9185d..d179b97 100644
--- a/freebsd/sys/dev/usb/net/usb_ethernet.c
+++ b/freebsd/sys/dev/usb/net/usb_ethernet.c
@@ -582,7 +582,13 @@ uether_rxmbuf(struct usb_ether *ue, struct mbuf *m,
 	UE_LOCK_ASSERT(ue, MA_OWNED);
 
 	/* finalize mbuf */
+
+	#ifndef __rtems__
 	if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
+	#else /* __rtems__ */
+	ifp->if_ipackets++;
+	#endif /* __rtems__ */
+
 	m->m_pkthdr.rcvif = ifp;
 	m->m_pkthdr.len = m->m_len = len;
 
@@ -605,14 +611,25 @@ uether_rxbuf(struct usb_ether *ue, struct usb_page_cache *pc,
 
 	m = uether_newbuf();
 	if (m == NULL) {
+
+		#ifndef __rtems__
 		if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1);
+		#else /* __rtems__ */
+		ifp->if_iqdrops++;
+		#endif /* __rtems__ */
+
 		return (ENOMEM);
 	}
 
 	usbd_copy_out(pc, offset, mtod(m, uint8_t *), len);
 
 	/* finalize mbuf */
+	#ifndef __rtems__
 	if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
+	#else /* __rtems__ */
+	ifp->if_ipackets++;
+	#endif /* __rtems__ */
+
 	m->m_pkthdr.rcvif = ifp;
 	m->m_pkthdr.len = m->m_len = len;
 
diff --git a/freebsd/sys/sys/sysctl.h b/freebsd/sys/sys/sysctl.h
index cfbbc7f..b2656c3 100644
--- a/freebsd/sys/sys/sysctl.h
+++ b/freebsd/sys/sys/sysctl.h
@@ -186,6 +186,7 @@ struct sysctl_oid {
 
 #define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l)
 #define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l)
+#define	SYSCTL_OUT_STR(r, p) (r->oldfunc)(r, p, strlen(p) + 1)
 
 int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
 int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS);
diff --git a/rtemsbsd/include/bsp/nexus-devices.h b/rtemsbsd/include/bsp/nexus-devices.h
index ce9d45c..7ba3541 100644
--- a/rtemsbsd/include/bsp/nexus-devices.h
+++ b/rtemsbsd/include/bsp/nexus-devices.h
@@ -90,6 +90,8 @@ RTEMS_BSD_DRIVER_BCM283X_DWCOTG(BCM2835_USB_BASE,
 			BCM2835_IRQ_ID_USB);
 RTEMS_BSD_DRIVER_USB;
 RTEMS_BSD_DRIVER_USB_MASS;
+RTEMS_BSD_DRIVER_SMSC;
+RTEMS_BSD_DRIVER_UKPHY;
 
 #elif defined(LIBBSP_POWERPC_QORIQ_BSP_H)
 
diff --git a/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h b/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h
index 467ea7b..d0591ec 100644
--- a/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h
+++ b/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h
@@ -71,10 +71,12 @@
  *   RTEMS_BSD_DRIVER_PCI_IGB
  *   RTEMS_BSD_DRIVER_PCI_EM
  *   RTEMS_BSD_DRIVER_PCI_RE
+ *   RTEMS_BSD_DRIVER_SMSC
  *
  *  MMI PHY:
  *   RTEMS_BSD_DRIVER_E1000PHY
  *   RTEMS_BSD_DRIVER_REPHY
+ *   RTEMS_BSD_DRIVER_UKPHY
  *   RTEMS_BSD_DRIVER_MIPHY
  */
 
@@ -354,6 +356,14 @@ extern "C" {
     SYSINIT_DRIVER_REFERENCE(re, pci);
 #endif /* RTEMS_BSD_DRIVER_PCI_RE */
 
+/*
+ * SMSC USB-Ethernet Driver
+ */
+#if !defined(RTEMS_BSD_DRIVER_SMSC)
+  #define RTEMS_BSD_DRIVER_SMSC                 \
+    SYSINIT_DRIVER_REFERENCE(miibus, smsc);
+#endif /* RTEMS_BSD_DRIVER_SMSC */
+
 /**
  ** MMI Physical Layer Support.
  **/
@@ -375,6 +385,14 @@ extern "C" {
 #endif /* RTEMS_BSD_DRIVER_REPHY */
 
 /*
+ * Synopsis(uk) PHY
+ */
+#if !defined(RTEMS_BSD_DRIVER_UKPHY)
+  #define RTEMS_BSD_DRIVER_UKPHY                  \
+    SYSINIT_DRIVER_REFERENCE(ukphy, miibus);
+#endif /* RTEMS_BSD_DRIVER_UKPHY */
+
+/*
  * MI PHY.
  */
 #if !defined(RTEMS_BSD_DRIVER_MIPHY)
diff --git a/testsuite/include/rtems/bsd/test/network-config.h.in b/testsuite/include/rtems/bsd/test/network-config.h.in
index 34c48b4..d74248d 100644
--- a/testsuite/include/rtems/bsd/test/network-config.h.in
+++ b/testsuite/include/rtems/bsd/test/network-config.h.in
@@ -42,6 +42,8 @@
   #define NET_CFG_INTERFACE_0 "cgem0"
 #elif defined(LIBBSP_M68K_GENMCF548X_BSP_H)
   #define NET_CFG_INTERFACE_0 "fec0"
+#elif defined(LIBBSP_ARM_RASPBERRYPI_BSP_H)
+  #define NET_CFG_INTERFACE_0 "ue0"
 #else
   #define NET_CFG_INTERFACE_0 "lo0"
 #endif
-- 
2.7.4




More information about the devel mailing list