[rtems-libbsd commit] sdk_dpaa: Port to RTEMS

Sebastian Huber sebh at rtems.org
Tue Jan 23 13:59:45 UTC 2018


Module:    rtems-libbsd
Branch:    master
Commit:    d62a3df1c770a64aff894bb3e698130ddf722ad0
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=d62a3df1c770a64aff894bb3e698130ddf722ad0

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Jan 17 13:28:45 2018 +0100

sdk_dpaa: Port to RTEMS

Update #3277.

---

 libbsd.py                                          |   6 +
 libbsd_waf.py                                      |   3 +
 .../drivers/net/ethernet/freescale/dpaa/dpaa_eth.c |  82 ++++++++
 .../drivers/net/ethernet/freescale/dpaa/dpaa_eth.h |   4 +
 .../net/ethernet/freescale/sdk_dpaa/dpaa_eth.h     |  60 ++++++
 .../ethernet/freescale/sdk_dpaa/dpaa_eth_base.c    |  20 ++
 .../ethernet/freescale/sdk_dpaa/dpaa_eth_base.h    |   2 +
 .../ethernet/freescale/sdk_dpaa/dpaa_eth_common.h  |   4 +
 .../ethernet/freescale/sdk_dpaa/dpaa_eth_macless.c | 146 +++++++++++++++
 .../ethernet/freescale/sdk_dpaa/dpaa_eth_trace.h   |   0
 .../net/ethernet/freescale/sdk_dpaa/fm_ext.h       |   0
 .../ethernet/freescale/sdk_dpaa/lnxwrp_fsl_fman.h  |   0
 rtemsbsd/include/bsp/nexus-devices.h               |   8 +
 rtemsbsd/powerpc/include/linux/fsl_bman.h          |   1 +
 rtemsbsd/powerpc/include/linux/fsl_qman.h          |   1 +
 rtemsbsd/powerpc/include/linux/highmem.h           |   0
 rtemsbsd/powerpc/include/linux/net_tstamp.h        |   0
 .../net/ethernet/freescale/sdk_dpaa/if_ml.c        | 208 +++++++++++++++++++++
 18 files changed, 545 insertions(+)

diff --git a/libbsd.py b/libbsd.py
index 380634f..7234f2b 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -4539,6 +4539,9 @@ def dpaa(mm):
             'drivers/net/ethernet/freescale/fman/fman_sp.h',
             'drivers/net/ethernet/freescale/dpaa/dpaa_eth.h',
             'drivers/net/ethernet/freescale/dpaa/dpaa_eth_trace.h',
+            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth.h',
+            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.h',
+            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_common.h',
             'drivers/soc/fsl/qbman/qman_priv.h',
             'drivers/soc/fsl/qbman/bman_test.h',
             'drivers/soc/fsl/qbman/dpaa_sys.h',
@@ -4557,6 +4560,8 @@ def dpaa(mm):
             'drivers/net/ethernet/freescale/fman/fman_sp.c',
             'drivers/net/ethernet/freescale/fman/fman_tgec.c',
             'drivers/net/ethernet/freescale/fman/mac.c',
+            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.c',
+            'drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_macless.c',
             'drivers/soc/fsl/qbman/bman.c',
             'drivers/soc/fsl/qbman/bman_ccsr.c',
             'drivers/soc/fsl/qbman/bman_test_api.c',
@@ -4576,6 +4581,7 @@ def dpaa(mm):
             'sys/powerpc/fman_muram.c',
             'sys/powerpc/linux_compat.c',
             'sys/powerpc/drivers/net/ethernet/freescale/dpaa/if_fmanmac.c',
+            'sys/powerpc/drivers/net/ethernet/freescale/sdk_dpaa/if_ml.c',
         ],
         mm.generator['source']()
     )
diff --git a/libbsd_waf.py b/libbsd_waf.py
index 6f8d11d..2d60737 100644
--- a/libbsd_waf.py
+++ b/libbsd_waf.py
@@ -2438,6 +2438,8 @@ def build(bld):
                    'linux/drivers/net/ethernet/freescale/fman/fman_sp.c',
                    'linux/drivers/net/ethernet/freescale/fman/fman_tgec.c',
                    'linux/drivers/net/ethernet/freescale/fman/mac.c',
+                   'linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.c',
+                   'linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_macless.c',
                    'linux/drivers/soc/fsl/qbman/bman.c',
                    'linux/drivers/soc/fsl/qbman/bman_ccsr.c',
                    'linux/drivers/soc/fsl/qbman/bman_test_api.c',
@@ -2448,6 +2450,7 @@ def build(bld):
                    'linux/drivers/soc/fsl/qbman/qman_test_stash.c',
                    'rtemsbsd/sys/powerpc/compat.c',
                    'rtemsbsd/sys/powerpc/drivers/net/ethernet/freescale/dpaa/if_fmanmac.c',
+                   'rtemsbsd/sys/powerpc/drivers/net/ethernet/freescale/sdk_dpaa/if_ml.c',
                    'rtemsbsd/sys/powerpc/fdt_phy.c',
                    'rtemsbsd/sys/powerpc/fman_muram.c',
                    'rtemsbsd/sys/powerpc/linux_compat.c']
diff --git a/linux/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/linux/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index bf7a277..9fc5da0 100644
--- a/linux/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/linux/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -3373,3 +3373,85 @@ module_exit(dpaa_unload);
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_DESCRIPTION("FSL DPAA Ethernet driver");
 #endif /* __rtems__ */
+#ifdef __rtems__
+static enum qman_cb_dqrr_result
+shared_rx_dqrr(struct qman_portal *portal, struct qman_fq *fq,
+    const struct qm_dqrr_entry *dq)
+{
+	const struct qm_fd *fd;
+	struct net_device *net_dev;
+	struct ifnet *ifp;
+	u32 fd_status;
+	enum qm_fd_format fd_format;
+	struct mbuf *m;
+	int len;
+	void *dst;
+
+	fd = &dq->fd;
+	fd_status = be32_to_cpu(fd->status);
+	fd_format = qm_fd_get_format(fd);
+	net_dev = ((struct dpaa_fq *)fq)->net_dev;
+	ifp = net_dev->ifp;
+
+	if (unlikely(fd_status & FM_FD_STAT_RX_ERRORS) != 0) {
+		if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
+		goto out;
+	}
+
+	BSD_ASSERT((be32_to_cpu(fd->status) & FM_FD_STAT_L4CV) == 0);
+	BSD_ASSERT(fd_format == qm_fd_contig);
+
+	m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
+	if (unlikely(m == NULL)) {
+		if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1);
+		goto out;
+	}
+
+	len = qm_fd_get_length(fd);
+	dst = mtod(m, char *) + ETHER_ALIGN;
+	m->m_pkthdr.rcvif = ifp;
+	m->m_pkthdr.len = len;
+	m->m_len = len;
+	m->m_data = dst;
+	memcpy(dst, (const void *)(qm_fd_addr(fd) +
+	    qm_fd_get_offset(fd)), (size_t)len);
+
+	if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
+	(*ifp->if_input)(ifp, m);
+
+out:
+
+	dpaa_fd_release(net_dev, fd);
+	return (qman_cb_dqrr_consume);
+}
+
+static enum qman_cb_dqrr_result
+shared_tx_error_dqrr(struct qman_portal *portal, struct qman_fq *fq,
+    const struct qm_dqrr_entry *dq)
+{
+	BSD_ASSERT(0);
+	return (qman_cb_dqrr_consume);
+}
+
+static enum qman_cb_dqrr_result
+shared_tx_default_dqrr(struct qman_portal *portal, struct qman_fq *fq,
+    const struct qm_dqrr_entry *dq)
+{
+	BSD_ASSERT(0);
+	return (qman_cb_dqrr_consume);
+}
+
+static void shared_ern(struct qman_portal *portal, struct qman_fq *fq,
+    const union qm_mr_entry *msg)
+{
+	BSD_ASSERT(0);
+}
+
+const struct dpaa_fq_cbs shared_fq_cbs = {
+	.rx_defq = { .cb = { .dqrr = shared_rx_dqrr } },
+	.tx_defq = { .cb = { .dqrr = shared_tx_default_dqrr } },
+	.rx_errq = { .cb = { .dqrr = shared_rx_dqrr } },
+	.tx_errq = { .cb = { .dqrr = shared_tx_error_dqrr } },
+	.egress_ern = { .cb = { .ern = shared_ern } }
+};
+#endif /* __rtems__ */
diff --git a/linux/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h b/linux/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
index 08e5fd6..e4f3b88 100644
--- a/linux/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
+++ b/linux/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
@@ -215,6 +215,10 @@ void dpaa_eth_sysfs_init(struct device *dev);
 
 void dpaa_cleanup_tx_fd(struct ifnet *ifp, const struct qm_fd *fd);
 
+/* Compatibility for SDK DPAA */
+
+extern const struct dpaa_fq_cbs shared_fq_cbs;
+
 #ifdef QORIQ_IS_HYPERVISOR_GUEST
 int dpaa_bp_alloc_pool(struct dpaa_bp *dpaa_bp);
 
diff --git a/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth.h b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth.h
new file mode 100644
index 0000000..1488493
--- /dev/null
+++ b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2018 embedded brains GmbH
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SDK_DPAA_DPAA_ETH_H
+#define	_SDK_DPAA_DPAA_ETH_H
+
+#include "../dpaa/dpaa_eth.h"
+
+#define	dpa_bp dpaa_bp
+#define	dpa_fq_alloc dpaa_fq_alloc
+#define	dpa_fq_cbs_t dpaa_fq_cbs
+#define	dpa_fq_list dpaa_fq_list
+#define	dpa_fq_setup dpaa_fq_setup
+#define	dpa_fq_type dpaa_fq_type
+#define	dpa_get_channel dpaa_get_channel
+#define	dpa_percpu_priv_s dpaa_percpu_priv
+#define	dpa_priv_s dpaa_priv
+
+enum port_type { RX, TX };
+
+struct fqid_cell {
+	uint32_t start;
+	uint32_t count;
+};
+
+struct ifnet;
+
+struct if_ml_softc {
+	struct ifnet *ifp;
+	struct mtx mtx;
+	struct net_device net_dev;
+};
+
+void if_ml_attach(struct if_ml_softc *sc, int unit,
+    const uint8_t *mac_address);
+
+#endif /* _SDK_DPAA_DPAA_ETH_H */
diff --git a/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.c b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.c
index 2256d4f..31768f1 100644
--- a/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.c
+++ b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.c
@@ -59,10 +59,12 @@
 
 MODULE_LICENSE("Dual BSD/GPL");
 
+#ifndef __rtems__
 uint8_t advanced_debug = -1;
 module_param(advanced_debug, byte, S_IRUGO);
 MODULE_PARM_DESC(advanced_debug, "Module/Driver verbosity level");
 EXPORT_SYMBOL(advanced_debug);
+#endif /* __rtems__ */
 
 static int dpa_bp_cmp(const void *dpa_bp0, const void *dpa_bp1)
 {
@@ -76,6 +78,9 @@ dpa_bp_probe(struct platform_device *_of_dev, size_t *count)
 	int			 i, lenp, na, ns, err;
 	struct device		*dev;
 	struct device_node	*dev_node;
+#ifdef __rtems__
+	struct device_node	dns;
+#endif /* __rtems__ */
 	const __be32		*bpool_cfg;
 	struct dpa_bp		*dpa_bp;
 	u32			bpid;
@@ -95,7 +100,11 @@ dpa_bp_probe(struct platform_device *_of_dev, size_t *count)
 		return ERR_PTR(-ENOMEM);
 	}
 
+#ifndef __rtems__
 	dev_node = of_find_node_by_path("/");
+#else /* __rtems__ */
+	dev_node = of_find_node_by_path(&dns, "/");
+#endif /* __rtems__ */
 	if (unlikely(dev_node == NULL)) {
 		dev_err(dev, "of_find_node_by_path(/) failed\n");
 		return ERR_PTR(-EINVAL);
@@ -107,8 +116,13 @@ dpa_bp_probe(struct platform_device *_of_dev, size_t *count)
 	for (i = 0; i < *count; i++) {
 		of_node_put(dev_node);
 
+#ifndef __rtems__
 		dev_node = of_parse_phandle(dev->of_node,
 				"fsl,bman-buffer-pools", i);
+#else /* __rtems__ */
+		dev_node = of_parse_phandle(&dns, dev->of_node,
+				"fsl,bman-buffer-pools", i);
+#endif /* __rtems__ */
 		if (dev_node == NULL) {
 			dev_err(dev, "of_find_node_by_phandle() failed\n");
 			return ERR_PTR(-EFAULT);
@@ -133,18 +147,22 @@ dpa_bp_probe(struct platform_device *_of_dev, size_t *count)
 		bpool_cfg = of_get_property(dev_node, "fsl,bpool-ethernet-cfg",
 					&lenp);
 		if (bpool_cfg && (lenp == (2 * ns + na) * sizeof(*bpool_cfg))) {
+#ifndef __rtems__
 			const uint32_t *seed_pool;
+#endif /* __rtems__ */
 
 			dpa_bp[i].config_count =
 				(int)of_read_number(bpool_cfg, ns);
 			dpa_bp[i].size	=
 				(size_t)of_read_number(bpool_cfg + ns, ns);
+#ifndef __rtems__
 			dpa_bp[i].paddr	=
 				of_read_number(bpool_cfg + 2 * ns, na);
 
 			seed_pool = of_get_property(dev_node,
 					"fsl,bpool-ethernet-seeds", &lenp);
 			dpa_bp[i].seed_pool = !!seed_pool;
+#endif /* __rtems__ */
 
 		} else {
 			dev_err(dev,
@@ -167,6 +185,7 @@ _return_of_node_put:
 }
 EXPORT_SYMBOL(dpa_bp_probe);
 
+#ifndef __rtems__
 int dpa_bp_shared_port_seed(struct dpa_bp *bp)
 {
 	void __iomem **ptr;
@@ -263,3 +282,4 @@ static void __exit __cold dpa_advanced_unload(void)
 
 }
 module_exit(dpa_advanced_unload);
+#endif /* __rtems__ */
diff --git a/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.h b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.h
index 6f57041..84e00cd 100644
--- a/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.h
+++ b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_base.h
@@ -39,7 +39,9 @@
 
 extern uint8_t advanced_debug;
 extern const struct dpa_fq_cbs_t shared_fq_cbs;
+#ifndef __rtems__
 extern int __hot dpa_shared_tx(struct sk_buff *skb, struct net_device *net_dev);
+#endif /* __rtems__ */
 
 struct dpa_bp * __cold __must_check /* __attribute__((nonnull)) */
 dpa_bp_probe(struct platform_device *_of_dev, size_t *count);
diff --git a/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_common.h b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_common.h
index 022b4c2..70d6bb6 100644
--- a/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_common.h
+++ b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_common.h
@@ -40,6 +40,7 @@
 #include "dpaa_eth.h"
 #include "lnxwrp_fsl_fman.h"
 
+#ifndef __rtems__
 #define dpaa_eth_init_port(type, port, param, errq_id, defq_id, buf_layout,\
 			   frag_enabled) \
 { \
@@ -167,10 +168,12 @@ int dpa_set_mac_address(struct net_device *net_dev, void *addr);
 void dpa_set_rx_mode(struct net_device *net_dev);
 void dpa_set_buffers_layout(struct mac_device *mac_dev,
 		struct dpa_buffer_layout_s *layout);
+#endif /* __rtems__ */
 int __attribute__((nonnull))
 dpa_bp_alloc(struct dpa_bp *dpa_bp);
 void __cold __attribute__((nonnull))
 dpa_bp_free(struct dpa_priv_s *priv);
+#ifndef __rtems__
 struct dpa_bp *dpa_bpid2pool(int bpid);
 void dpa_bpid2pool_map(int bpid, struct dpa_bp *dpa_bp);
 bool dpa_bpid2pool_use(int bpid);
@@ -225,5 +228,6 @@ int dpa_proxy_set_mac_address(struct proxy_device *proxy_dev,
 			  struct net_device *net_dev);
 int dpa_proxy_set_rx_mode(struct proxy_device *proxy_dev,
 		      struct net_device *net_dev);
+#endif /* __rtems__ */
 
 #endif /* __DPAA_ETH_COMMON_H */
diff --git a/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_macless.c b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_macless.c
index b21afa3..7198fe1 100644
--- a/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_macless.c
+++ b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_macless.c
@@ -1,5 +1,7 @@
 #include <machine/rtems-bsd-kernel-space.h>
 
+#include <rtems/bsd/local/opt_dpaa.h>
+
 /* Copyright 2008-2013 Freescale Semiconductor Inc.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -61,6 +63,7 @@
  */
 #define DPA_DEFAULT_TX_HEADROOM	64
 
+#ifndef __rtems__
 #define DPA_DESCRIPTION "FSL DPAA MACless Ethernet driver"
 
 MODULE_LICENSE("Dual BSD/GPL");
@@ -78,8 +81,10 @@ static int __cold dpa_macless_stop(struct net_device *net_dev);
 static int __cold dpa_macless_set_address(struct net_device *net_dev,
 					  void *addr);
 static void __cold dpa_macless_set_rx_mode(struct net_device *net_dev);
+#endif /* __rtems__ */
 
 static int dpaa_eth_macless_probe(struct platform_device *_of_dev);
+#ifndef __rtems__
 static netdev_features_t
 dpa_macless_fix_features(struct net_device *dev, netdev_features_t features);
 
@@ -118,12 +123,14 @@ static struct platform_driver dpa_macless_driver = {
 	.probe		= dpaa_eth_macless_probe,
 	.remove		= dpa_remove
 };
+#endif /* __rtems__ */
 
 static const char macless_frame_queues[][25] = {
 	[RX] = "fsl,qman-frame-queues-rx",
 	[TX] = "fsl,qman-frame-queues-tx"
 };
 
+#ifndef __rtems__
 static int __cold dpa_macless_start(struct net_device *net_dev)
 {
 	const struct dpa_priv_s *priv = netdev_priv(net_dev);
@@ -235,6 +242,7 @@ static int dpa_macless_netdev_init(struct device_node *dpa_node,
 				macless_tx_timeout);
 	}
 }
+#endif /* __rtems__ */
 
 /* Probing of FQs for MACless ports */
 static int dpa_fq_probe_macless(struct device *dev, struct list_head *list,
@@ -271,9 +279,11 @@ dpa_macless_proxy_probe(struct platform_device *_of_dev)
 {
 	struct device		*dev;
 	const phandle		*proxy_prop;
+#ifndef __rtems__
 	struct proxy_device	*proxy_dev;
 	struct device_node	*proxy_node;
 	struct platform_device  *proxy_pdev;
+#endif /* __rtems__ */
 	int lenp;
 
 	dev = &_of_dev->dev;
@@ -282,6 +292,7 @@ dpa_macless_proxy_probe(struct platform_device *_of_dev)
 	if (!proxy_prop)
 		return NULL;
 
+#ifndef __rtems__
 	proxy_node = of_find_node_by_phandle(*proxy_prop);
 	if (!proxy_node) {
 		dev_err(dev, "Cannot find proxy node\n");
@@ -300,6 +311,10 @@ dpa_macless_proxy_probe(struct platform_device *_of_dev)
 	of_node_put(proxy_node);
 
 	return proxy_dev;
+#else /* __rtems__ */
+	BSD_ASSERT(0);
+	return (NULL);
+#endif /* __rtems__ */
 }
 
 static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
@@ -313,8 +328,12 @@ static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
 	struct dpa_priv_s *priv = NULL;
 	struct dpa_percpu_priv_s *percpu_priv;
 	static struct proxy_device *proxy_dev;
+#ifndef __rtems__
 	struct task_struct *kth;
 	static u8 macless_idx;
+#else /* __rtems__ */
+	struct dpaa_fq *dpaa_fq, *tmp;
+#endif /* __rtems__ */
 
 	dev = &_of_dev->dev;
 
@@ -328,12 +347,15 @@ static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
 	if (IS_ERR(dpa_bp))
 		return PTR_ERR(dpa_bp);
 
+#ifndef __rtems__
 	for (i = 0; i < count; i++)
 		dpa_bp[i].seed_cb = dpa_bp_shared_port_seed;
+#endif /* __rtems__ */
 
 	proxy_dev = dpa_macless_proxy_probe(_of_dev);
 
 
+#ifndef __rtems__
 	/* Allocate this early, so we can store relevant information in
 	 * the private area (needed by 1588 code in dpa_mac_probe)
 	 */
@@ -345,10 +367,19 @@ static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
 
 	/* Do this here, so we can be verbose early */
 	SET_NETDEV_DEV(net_dev, dev);
+#else /* __rtems__ */
+	net_dev = _of_dev->platform_data;
+#endif /* __rtems__ */
 	dev_set_drvdata(dev, net_dev);
 
+#ifndef __rtems__
 	priv = netdev_priv(net_dev);
+#else /* __rtems__ */
+	priv = malloc(sizeof(*priv), M_KMALLOC, M_WAITOK | M_ZERO);
+	net_dev->priv = priv;
+#endif /* __rtems__ */
 	priv->net_dev = net_dev;
+#ifndef __rtems__
 	sprintf(priv->if_type, "macless%d", macless_idx++);
 
 	priv->msg_enable = netif_msg_init(advanced_debug, -1);
@@ -370,6 +401,9 @@ static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
 		/* control over proxy's mac device */
 		priv->peer = (void *)proxy_dev;
 	}
+#else /* __rtems__ */
+	(void)proxy_dev;
+#endif /* __rtems__ */
 
 	INIT_LIST_HEAD(&priv->dpa_fq_list);
 
@@ -381,10 +415,24 @@ static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
 		goto fq_probe_failed;
 
 	/* bp init */
+#ifndef __rtems__
 	priv->bp_count = count;
 	err = dpa_bp_create(net_dev, dpa_bp, count);
 	if (err < 0)
 		goto bp_create_failed;
+#else /* __rtems__ */
+	BSD_ASSERT(count == DPAA_BPS_NUM);
+	for (i = 0; i < DPAA_BPS_NUM; i++) {
+		int err;
+
+		dpa_bp[i].raw_size = dpa_bp[i].size;
+		dpa_bp[i].dev = dev;
+
+		err = dpaa_bp_alloc_pool(&dpa_bp[i]);
+		BSD_ASSERT(err == 0);
+		priv->dpaa_bps[i] = &dpa_bp[i];
+	}
+#endif /* __rtems__ */
 
 	channel = dpa_get_channel();
 
@@ -398,6 +446,7 @@ static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
 	/* Start a thread that will walk the cpus with affine portals
 	 * and add this pool channel to each's dequeue mask.
 	 */
+#ifndef __rtems__
 	kth = kthread_run(dpaa_eth_add_channel,
 			  (void *)(unsigned long)priv->channel,
 			  "dpaa_%p:%d", net_dev, priv->channel);
@@ -405,6 +454,9 @@ static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
 		err = -ENOMEM;
 		goto add_channel_failed;
 	}
+#else /* __rtems__ */
+	dpaa_eth_add_channel(priv->channel);
+#endif /* __rtems__ */
 
 	dpa_fq_setup(priv, &shared_fq_cbs, NULL);
 
@@ -417,9 +469,17 @@ static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
 	 * because the ERN notifications will be received by the
 	 * partition doing qman_enqueue.
 	 */
+#ifndef __rtems__
 	err = dpa_fqs_init(dev,  &priv->dpa_fq_list, true);
 	if (err < 0)
 		goto fq_alloc_failed;
+#else /* __rtems__ */
+	list_for_each_entry_safe(dpaa_fq, tmp, &priv->dpaa_fq_list, list) {
+		err = dpaa_fq_init(dpaa_fq, true);
+		if (err < 0)
+			goto fq_alloc_failed;
+	}
+#endif /* __rtems__ */
 
 	priv->tx_headroom = DPA_DEFAULT_TX_HEADROOM;
 
@@ -435,6 +495,7 @@ static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
 		memset(percpu_priv, 0, sizeof(*percpu_priv));
 	}
 
+#ifndef __rtems__
 	err = dpa_macless_netdev_init(dpa_node, net_dev);
 	if (err < 0)
 		goto netdev_init_failed;
@@ -443,27 +504,39 @@ static int dpaa_eth_macless_probe(struct platform_device *_of_dev)
 
 	pr_info("fsl_dpa_macless: Probed %s interface as %s\n",
 			priv->if_type, net_dev->name);
+#endif /* __rtems__ */
 
 	return 0;
 
+#ifndef __rtems__
 netdev_init_failed:
+#endif /* __rtems__ */
 alloc_percpu_failed:
 fq_alloc_failed:
+#ifndef __rtems__
 	if (net_dev)
 		dpa_fq_free(dev, &priv->dpa_fq_list);
 add_channel_failed:
+#endif /* __rtems__ */
 get_channel_failed:
+#ifndef __rtems__
 	if (net_dev)
 		dpa_bp_free(priv);
 bp_create_failed:
+#endif /* __rtems__ */
 fq_probe_failed:
+#ifndef __rtems__
 	dev_set_drvdata(dev, NULL);
 	if (net_dev)
 		free_netdev(net_dev);
+#else /* __rtems__ */
+	BSD_ASSERT(0);
+#endif /* __rtems__ */
 
 	return err;
 }
 
+#ifndef __rtems__
 static int __init __cold dpa_macless_load(void)
 {
 	int	 _errno;
@@ -496,3 +569,76 @@ static void __exit __cold dpa_macless_unload(void)
 		KBUILD_BASENAME".c", __func__);
 }
 module_exit(dpa_macless_unload);
+#else /* __rtems__ */
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+
+#include <bsp/fdt.h>
+
+static const char dpaa_ml_compatible[] = "fsl,dpa-ethernet-macless";
+
+static int
+dpaa_ml_attach(device_t dev)
+{
+	const char *fdt;
+	int node;
+	int unit;
+
+	fdt = bsp_fdt_get();
+	node = -1;
+	unit = 0;
+
+	while (true) {
+		struct if_ml_softc *sc;
+		struct platform_device of_dev;
+		struct device_node dn;
+		int err;
+
+		node = fdt_node_offset_by_compatible(fdt, node, dpaa_ml_compatible);
+		if (node < 0) {
+			break;
+		}
+
+		sc = malloc(sizeof(*sc), M_KMALLOC, M_WAITOK | M_ZERO);
+
+		memset(&of_dev, 0, sizeof(of_dev));
+		memset(&dn, 0, sizeof(dn));
+		dn.offset = node;
+		dn.full_name = dpaa_ml_compatible;
+		of_dev.dev.of_node = &dn;
+		of_dev.platform_data = &sc->net_dev;
+
+		err = dpaa_eth_macless_probe(&of_dev);
+		BSD_ASSERT(err == 0);
+
+		if_ml_attach(sc, unit, of_get_mac_address(&dn));
+		++unit;
+	}
+
+	return (0);
+}
+
+static device_method_t dpaa_ml_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe, bus_generic_probe),
+	DEVMETHOD(device_attach, dpaa_ml_attach),
+	DEVMETHOD(device_detach, bus_generic_detach),
+	DEVMETHOD(device_suspend, bus_generic_suspend),
+	DEVMETHOD(device_resume, bus_generic_resume),
+	DEVMETHOD(device_shutdown, bus_generic_shutdown),
+
+	DEVMETHOD_END
+};
+
+driver_t dpaa_ml_driver = {
+	.name = "dpaa_ml",
+	.methods = dpaa_ml_methods
+};
+
+static devclass_t dpaa_ml_devclass;
+
+DRIVER_MODULE(dpaa_ml, nexus, dpaa_ml_driver, dpaa_ml_devclass, 0, 0);
+#endif /* __rtems__ */
diff --git a/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_trace.h b/linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth_trace.h
new file mode 100644
index 0000000..e69de29
diff --git a/linux/drivers/net/ethernet/freescale/sdk_dpaa/fm_ext.h b/linux/drivers/net/ethernet/freescale/sdk_dpaa/fm_ext.h
new file mode 100644
index 0000000..e69de29
diff --git a/linux/drivers/net/ethernet/freescale/sdk_dpaa/lnxwrp_fsl_fman.h b/linux/drivers/net/ethernet/freescale/sdk_dpaa/lnxwrp_fsl_fman.h
new file mode 100644
index 0000000..e69de29
diff --git a/rtemsbsd/include/bsp/nexus-devices.h b/rtemsbsd/include/bsp/nexus-devices.h
index a44149a..dc90322 100644
--- a/rtemsbsd/include/bsp/nexus-devices.h
+++ b/rtemsbsd/include/bsp/nexus-devices.h
@@ -146,6 +146,12 @@ RTEMS_BSD_DRIVER_REPHY;
 
 #include <bsp/irq.h>
 
+#ifdef QORIQ_IS_HYPERVISOR_GUEST
+
+RTEMS_BSD_DEFINE_NEXUS_DEVICE(dpaa_ml, 0, 0, NULL);
+
+#else /* !QORIQ_IS_HYPERVISOR_GUEST */
+
 RTEMS_BSD_DEFINE_NEXUS_DEVICE(fman, 0, 0, NULL);
 RTEMS_BSD_DEFINE_NEXUS_DEVICE(fman, 1, 0, NULL);
 
@@ -153,6 +159,8 @@ SYSINIT_DRIVER_REFERENCE(fman_mac, fman);
 SYSINIT_DRIVER_REFERENCE(fman_port, fman_mac);
 SYSINIT_DRIVER_REFERENCE(ukphy, miibus);
 
+#endif /* QORIQ_IS_HYPERVISOR_GUEST */
+
 #else /* QORIQ_CHIP_IS_T_VARIANT(QORIQ_CHIP_VARIANT) */
 
 #include <bsp/irq.h>
diff --git a/rtemsbsd/powerpc/include/linux/fsl_bman.h b/rtemsbsd/powerpc/include/linux/fsl_bman.h
new file mode 100644
index 0000000..0c1028d
--- /dev/null
+++ b/rtemsbsd/powerpc/include/linux/fsl_bman.h
@@ -0,0 +1 @@
+#include <soc/fsl/bman.h>
diff --git a/rtemsbsd/powerpc/include/linux/fsl_qman.h b/rtemsbsd/powerpc/include/linux/fsl_qman.h
new file mode 100644
index 0000000..6acba6b
--- /dev/null
+++ b/rtemsbsd/powerpc/include/linux/fsl_qman.h
@@ -0,0 +1 @@
+#include <soc/fsl/qman.h>
diff --git a/rtemsbsd/powerpc/include/linux/highmem.h b/rtemsbsd/powerpc/include/linux/highmem.h
new file mode 100644
index 0000000..e69de29
diff --git a/rtemsbsd/powerpc/include/linux/net_tstamp.h b/rtemsbsd/powerpc/include/linux/net_tstamp.h
new file mode 100644
index 0000000..e69de29
diff --git a/rtemsbsd/sys/powerpc/drivers/net/ethernet/freescale/sdk_dpaa/if_ml.c b/rtemsbsd/sys/powerpc/drivers/net/ethernet/freescale/sdk_dpaa/if_ml.c
new file mode 100644
index 0000000..b5f3299
--- /dev/null
+++ b/rtemsbsd/sys/powerpc/drivers/net/ethernet/freescale/sdk_dpaa/if_ml.c
@@ -0,0 +1,208 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
+#include <rtems/bsd/local/opt_dpaa.h>
+
+/*
+ * Copyright (c) 2018 embedded brains GmbH
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <machine/rtems-bsd-kernel-space.h>
+
+#include <linux/kernel.h>
+
+#include "../../../../../../../../linux/drivers/net/ethernet/freescale/sdk_dpaa/dpaa_eth.h"
+
+#include <soc/fsl/bman.h>
+
+#include <sys/bus.h>
+#include <sys/callout.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/module.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+
+#include <net/if.h>
+#include <net/ethernet.h>
+#include <net/if_arp.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+#include <net/if_types.h>
+#include <net/if_var.h>
+
+#define	IF_ML_LOCK(sc) mtx_lock(&(sc)->mtx)
+#define	IF_ML_UNLOCK(sc) mtx_unlock(&(sc)->mtx)
+
+static void
+if_ml_start(struct ifnet *ifp)
+{
+	struct if_ml_softc *sc;
+	struct dpaa_priv *priv;
+	int queue;
+	struct dpaa_bp *bp;
+	struct qman_fq *egress_fq;
+
+	sc = ifp->if_softc;
+	priv = netdev_priv(&sc->net_dev);
+	queue = 0;
+	bp = priv->dpaa_bps[queue];
+	egress_fq = priv->egress_fqs[queue];
+
+	for (;;) {
+		struct mbuf *m;
+		struct bm_buffer bmb;
+		struct qm_fd fd;
+		uintptr_t buf_addr;
+		char *dst;
+		int len;
+		int err;
+		int i;
+
+		IF_DEQUEUE(&ifp->if_snd, m);
+		if (m == NULL)
+			break;
+
+		err = bman_acquire(bp->pool, &bmb, 1);
+		if (unlikely(err <= 0)) {
+			if_inc_counter(ifp, IFCOUNTER_OQDROPS, 1);
+			m_freem(m);
+			continue;
+		}
+
+		qm_fd_clear_fd(&fd);
+		len = m->m_pkthdr.len;
+		qm_fd_set_contig(&fd, priv->tx_headroom, len);
+		fd.bpid = bp->bpid;
+		buf_addr = bm_buf_addr(&bmb);
+		qm_fd_addr_set64(&fd, buf_addr);
+		dst = (char *)(buf_addr + priv->tx_headroom);
+
+		do {
+			len = m->m_len;
+			dst = memcpy(dst, mtod(m, const void *), len);
+			dst += len;
+			m = m_free(m);
+		} while (m != NULL);
+
+		for (i = 0; i < DPAA_ENQUEUE_RETRIES; ++i) {
+			err = qman_enqueue(egress_fq, &fd);
+			if (err != -EBUSY) {
+				break;
+			}
+		}
+
+		if (unlikely(err < 0)) {
+			if_inc_counter(ifp, IFCOUNTER_OQDROPS, 1);
+			continue;
+		}
+	}
+}
+
+static void
+if_ml_init_locked(struct if_ml_softc* sc_p)
+{
+	struct ifnet *ifp;
+
+	ifp = sc_p->ifp;
+	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
+		return;
+
+	ifp->if_drv_flags |= IFF_DRV_RUNNING;
+}
+
+static void
+if_ml_stop_locked(struct if_ml_softc* sc_p)
+{
+}
+
+static int
+if_ml_ioctl(struct ifnet* ifp, ioctl_command_t cmd, caddr_t data)
+{
+	struct if_ml_softc *sc;
+	int error;
+
+	sc = ifp->if_softc;
+
+	switch (cmd) {
+	case SIOCSIFFLAGS:
+		IF_ML_LOCK(sc);
+		if (ifp->if_flags & IFF_UP) {
+			if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
+				if_ml_init_locked(sc);
+		} else {
+			if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
+				if_ml_stop_locked(sc);
+		}
+		IF_ML_UNLOCK(sc);
+		error = 0;
+		break;
+
+	default:
+		error = ether_ioctl(ifp, cmd, data);
+		break;
+	}
+
+	return error;
+}
+
+static void
+if_ml_init(void* arg)
+{
+	struct if_ml_softc *sc;
+
+	sc = arg;
+	IF_ML_LOCK(sc);
+	if_ml_init_locked(sc);
+	IF_ML_UNLOCK(sc);
+}
+
+void
+if_ml_attach(struct if_ml_softc *sc, int unit, const uint8_t *mac_address)
+{
+	struct ifnet *ifp;
+
+	BSD_ASSERT(mac_address != NULL);
+
+	sc->ifp = ifp = if_alloc(IFT_ETHER);
+	BSD_ASSERT(ifp != NULL);
+
+	sc->net_dev.ifp = ifp;
+
+	mtx_init(&sc->mtx, "if_ml", MTX_NETWORK_LOCK, MTX_DEF);
+
+	ifp->if_softc = sc;
+	if_initname(ifp, "ml", unit);
+	ifp->if_flags = IFF_SIMPLEX | IFF_MULTICAST | IFF_BROADCAST;
+	ifp->if_start = if_ml_start;
+	ifp->if_ioctl = if_ml_ioctl;
+	ifp->if_init = if_ml_init;
+	IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
+	ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
+	IFQ_SET_READY(&ifp->if_snd);
+
+	ether_ifattach(ifp, mac_address);
+}




More information about the vc mailing list