public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Max Filippov <jcmvbkbc@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 6/7] net/ethoc: support private memory configurations
Date: Tue,  2 Aug 2016 14:31:09 +0300	[thread overview]
Message-ID: <1470137470-6051-7-git-send-email-jcmvbkbc@gmail.com> (raw)
In-Reply-To: <1470137470-6051-1-git-send-email-jcmvbkbc@gmail.com>

The ethoc device can be configured to have a private memory region
instead of having access to the main memory. In that case egress packets
must be copied into that memory for transmission and pointers to that
memory need to be passed to net_process_received_packet or returned from
the recv callback.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
 drivers/net/ethoc.c                  | 46 ++++++++++++++++++++++++++++++++----
 include/dm/platform_data/net_ethoc.h |  1 +
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index e25dd1b..fa623d5 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -179,6 +179,8 @@ struct ethoc {
 	u32 num_rx;
 	u32 cur_rx;
 	void __iomem *iobase;
+	void __iomem *packet;
+	phys_addr_t packet_phys;
 };
 
 /**
@@ -247,6 +249,7 @@ static inline void ethoc_disable_rx_and_tx(struct ethoc *priv)
 static int ethoc_init_ring(struct ethoc *priv)
 {
 	struct ethoc_bd bd;
+	phys_addr_t addr = priv->packet_phys;
 	int i;
 
 	priv->cur_tx = 0;
@@ -258,6 +261,10 @@ static int ethoc_init_ring(struct ethoc *priv)
 	bd.addr = 0;
 
 	for (i = 0; i < priv->num_tx; i++) {
+		if (addr) {
+			bd.addr = addr;
+			addr += PKTSIZE_ALIGN;
+		}
 		if (i == priv->num_tx - 1)
 			bd.stat |= TX_BD_WRAP;
 
@@ -267,7 +274,12 @@ static int ethoc_init_ring(struct ethoc *priv)
 	bd.stat = RX_BD_EMPTY | RX_BD_IRQ;
 
 	for (i = 0; i < priv->num_rx; i++) {
-		bd.addr = virt_to_phys(net_rx_packets[i]);
+		if (addr) {
+			bd.addr = addr;
+			addr += PKTSIZE_ALIGN;
+		} else {
+			bd.addr = virt_to_phys(net_rx_packets[i]);
+		}
 		if (i == priv->num_rx - 1)
 			bd.stat |= RX_BD_WRAP;
 
@@ -367,7 +379,10 @@ static int ethoc_rx_common(struct ethoc *priv, uchar **packetp)
 		int size = bd.stat >> 16;
 
 		size -= 4;	/* strip the CRC */
-		*packetp = net_rx_packets[i];
+		if (priv->packet)
+			*packetp = priv->packet + entry * PKTSIZE_ALIGN;
+		else
+			*packetp = net_rx_packets[i];
 		return size;
 	} else {
 		return 0;
@@ -430,8 +445,15 @@ static int ethoc_send_common(struct ethoc *priv, void *packet, int length)
 		bd.stat |= TX_BD_PAD;
 	else
 		bd.stat &= ~TX_BD_PAD;
-	bd.addr = virt_to_phys(packet);
 
+	if (priv->packet) {
+		void *p = priv->packet + entry * PKTSIZE_ALIGN;
+
+		memcpy(p, packet, length);
+		packet = p;
+	} else {
+		bd.addr = virt_to_phys(packet);
+	}
 	flush_dcache_range((ulong)packet, (ulong)packet + length);
 	bd.stat &= ~(TX_BD_STATS | TX_BD_LEN_MASK);
 	bd.stat |= TX_BD_LEN(length);
@@ -468,12 +490,17 @@ static int ethoc_free_pkt_common(struct ethoc *priv)
 	struct ethoc_bd bd;
 	u32 i = priv->cur_rx % priv->num_rx;
 	u32 entry = priv->num_tx + i;
+	void *src;
 
 	ethoc_read_bd(priv, entry, &bd);
 
+	if (priv->packet)
+		src = priv->packet + entry * PKTSIZE_ALIGN;
+	else
+		src = net_rx_packets[i];
 	/* clear the buffer descriptor so it can be reused */
-	flush_dcache_range((ulong)net_rx_packets[i],
-			   (ulong)net_rx_packets[i] + PKTSIZE_ALIGN);
+	flush_dcache_range((ulong)src,
+			   (ulong)src + PKTSIZE_ALIGN);
 	bd.stat &= ~RX_BD_STATS;
 	bd.stat |= RX_BD_EMPTY;
 	ethoc_write_bd(priv, entry, &bd);
@@ -606,8 +633,12 @@ static void ethoc_stop(struct udevice *dev)
 static int ethoc_ofdata_to_platdata(struct udevice *dev)
 {
 	struct ethoc_eth_pdata *pdata = dev_get_platdata(dev);
+	fdt_addr_t addr;
 
 	pdata->eth_pdata.iobase = dev_get_addr(dev);
+	addr = dev_get_addr_index(dev, 1);
+	if (addr != FDT_ADDR_T_NONE)
+		pdata->packet_base = addr;
 	return 0;
 }
 
@@ -617,6 +648,11 @@ static int ethoc_probe(struct udevice *dev)
 	struct ethoc *priv = dev_get_priv(dev);
 
 	priv->iobase = ioremap(pdata->eth_pdata.iobase, ETHOC_IOSIZE);
+	if (pdata->packet_base) {
+		priv->packet_phys = pdata->packet_base;
+		priv->packet = ioremap(pdata->packet_base,
+				       (1 + PKTBUFSRX) * PKTSIZE_ALIGN);
+	}
 	return 0;
 }
 
diff --git a/include/dm/platform_data/net_ethoc.h b/include/dm/platform_data/net_ethoc.h
index 1d8c73c..3f94bde 100644
--- a/include/dm/platform_data/net_ethoc.h
+++ b/include/dm/platform_data/net_ethoc.h
@@ -13,6 +13,7 @@
 
 struct ethoc_eth_pdata {
 	struct eth_pdata eth_pdata;
+	phys_addr_t packet_base;
 };
 
 #endif
-- 
2.1.4

  parent reply	other threads:[~2016-08-02 11:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-02 11:31 [U-Boot] [PATCH 0/7] net/ethoc improvements Max Filippov
2016-08-02 11:31 ` [U-Boot] [PATCH 1/7] net/ethoc: add Kconfig entry for the driver Max Filippov
2016-08-04 17:11   ` Joe Hershberger
2016-08-02 11:31 ` [U-Boot] [PATCH 2/7] net/ethoc: use priv instead of dev internally Max Filippov
2016-08-04 17:16   ` Joe Hershberger
2016-08-02 11:31 ` [U-Boot] [PATCH 3/7] net/ethoc: add CONFIG_DM_ETH support Max Filippov
2016-08-04  1:16   ` Simon Glass
2016-08-04 17:51   ` Joe Hershberger
2016-08-05 14:06     ` Max Filippov
2016-08-02 11:31 ` [U-Boot] [PATCH 4/7] net/ethoc: support device tree Max Filippov
2016-08-04 18:01   ` Joe Hershberger
2016-08-02 11:31 ` [U-Boot] [PATCH 5/7] net/ethoc: don't mix virtual and physical addresses Max Filippov
2016-08-04 18:08   ` Joe Hershberger
2016-08-02 11:31 ` Max Filippov [this message]
2016-08-04 19:43   ` [U-Boot] [PATCH 6/7] net/ethoc: support private memory configurations Joe Hershberger
2016-08-02 11:31 ` [U-Boot] [PATCH 7/7] net/ethoc: implement MDIO bus and support phylib Max Filippov
2016-08-04 20:48   ` Joe Hershberger
2016-08-05 14:36     ` Max Filippov
2016-08-04 17:10 ` [U-Boot] [PATCH 0/7] net/ethoc improvements Joe Hershberger
2016-08-04 17:26   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1470137470-6051-7-git-send-email-jcmvbkbc@gmail.com \
    --to=jcmvbkbc@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox