[PATCH v2 5/6] Ported driver usb_ethernet(smsc) to RTEMS. USB DMA related functions commented out, since DMA support for raspberry is underdevelopment.
Deval Shah
deval.maker at gmail.com
Fri Aug 19 17:13:26 UTC 2016
---
freebsd/sys/dev/usb/net/if_smsc.c | 34 ++++++++++++++++++++++++++
freebsd/sys/dev/usb/net/if_smscreg.h | 1 +
freebsd/sys/dev/usb/net/usb_ethernet.c | 12 +++++++++
freebsd/sys/sys/sysctl.h | 1 +
rtemsbsd/include/machine/rtems-bsd-nexus-bus.h | 18 ++++++++++++++
5 files changed, 66 insertions(+)
diff --git a/freebsd/sys/dev/usb/net/if_smsc.c b/freebsd/sys/dev/usb/net/if_smsc.c
index 3bdd35a..a55d4e7 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 /* __rtems__ */
#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 /* __rtems__ */
off += (sizeof(rxhdr) + ETHER_ALIGN);
rxhdr = le32toh(rxhdr);
@@ -1008,9 +1012,17 @@ 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 +1033,18 @@ 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 /* __rtems__ */
/* Check if RX TCP/UDP checksumming is being offloaded */
if ((ifp->if_capenable & IFCAP_RXCSUM) != 0) {
@@ -1061,9 +1079,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 /* __rtems__ */
/* The data is copied in network order, but the
* csum algorithm in the kernel expects it to be
* in host network order.
@@ -1165,19 +1185,29 @@ 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 /* __rtems__ */
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 /* __rtems__ */
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 /* __rtems__ */
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 +1225,11 @@ 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..de923e9 100644
--- a/freebsd/sys/dev/usb/net/usb_ethernet.c
+++ b/freebsd/sys/dev/usb/net/usb_ethernet.c
@@ -582,7 +582,11 @@ 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 +609,22 @@ 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..b7283e2 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/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)
--
2.7.4
More information about the devel
mailing list