All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 04/35] net: dwc: Make the cache handling less cryptic
Date: Mon, 15 Sep 2014 13:05:57 +0200	[thread overview]
Message-ID: <1410779188-6880-5-git-send-email-marex@denx.de> (raw)
In-Reply-To: <1410779188-6880-1-git-send-email-marex@denx.de>

Add a few new variables to make the cache handling less cryptic.
Add a variable for DMA and DATA descriptor start and end, so the
correctness of the code is easier to inspect.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chin Liang See <clsee@altera.com>
Cc: Dinh Nguyen <dinguyen@altera.com>
Cc: Albert Aribaud <albert.u.boot@aribaud.net>
Cc: Tom Rini <trini@ti.com>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Pavel Machek <pavel@denx.de>
Cc: Joe Hershberger <joe.hershberger@gmail.com>
---
 drivers/net/designware.c | 48 +++++++++++++++++++++++-------------------------
 1 file changed, 23 insertions(+), 25 deletions(-)

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index aaf146d..9ded895 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -279,19 +279,21 @@ static int dw_eth_send(struct eth_device *dev, void *packet, int length)
 	struct eth_dma_regs *dma_p = priv->dma_regs_p;
 	u32 desc_num = priv->tx_currdescnum;
 	struct dmamacdescr *desc_p = &priv->tx_mac_descrtable[desc_num];
-
+	uint32_t desc_start = (uint32_t)desc_p;
+	uint32_t desc_end = desc_start +
+		roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
+	uint32_t data_start = (uint32_t)desc_p->dmamac_addr;
+	uint32_t data_end = data_start +
+		roundup(length, ARCH_DMA_MINALIGN);
 	/*
 	 * Strictly we only need to invalidate the "txrx_status" field
 	 * for the following check, but on some platforms we cannot
-	 * invalidate only 4 bytes, so roundup to
-	 * ARCH_DMA_MINALIGN. This is safe because the individual
-	 * descriptors in the array are each aligned to
-	 * ARCH_DMA_MINALIGN.
+	 * invalidate only 4 bytes, so we flush the entire descriptor,
+	 * which is 16 bytes in total. This is safe because the
+	 * individual descriptors in the array are each aligned to
+	 * ARCH_DMA_MINALIGN and padded appropriately.
 	 */
-	invalidate_dcache_range(
-		(unsigned long)desc_p,
-		(unsigned long)desc_p +
-		roundup(sizeof(desc_p->txrx_status), ARCH_DMA_MINALIGN));
+	invalidate_dcache_range(desc_start, desc_end);
 
 	/* Check if the descriptor is owned by CPU */
 	if (desc_p->txrx_status & DESC_TXSTS_OWNBYDMA) {
@@ -299,12 +301,10 @@ static int dw_eth_send(struct eth_device *dev, void *packet, int length)
 		return -1;
 	}
 
-	memcpy((void *)desc_p->dmamac_addr, packet, length);
+	memcpy(desc_p->dmamac_addr, packet, length);
 
 	/* Flush data to be sent */
-	flush_dcache_range((unsigned long)desc_p->dmamac_addr,
-			   (unsigned long)desc_p->dmamac_addr +
-			   roundup(length, ARCH_DMA_MINALIGN));
+	flush_dcache_range(data_start, data_end);
 
 #if defined(CONFIG_DW_ALTDESCRIPTOR)
 	desc_p->txrx_status |= DESC_TXSTS_TXFIRST | DESC_TXSTS_TXLAST;
@@ -322,8 +322,7 @@ static int dw_eth_send(struct eth_device *dev, void *packet, int length)
 #endif
 
 	/* Flush modified buffer descriptor */
-	flush_dcache_range((unsigned long)desc_p,
-			   (unsigned long)desc_p + sizeof(struct dmamacdescr));
+	flush_dcache_range(desc_start, desc_end);
 
 	/* Test the wrap-around condition. */
 	if (++desc_num >= CONFIG_TX_DESCR_NUM)
@@ -343,11 +342,14 @@ static int dw_eth_recv(struct eth_device *dev)
 	u32 status, desc_num = priv->rx_currdescnum;
 	struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num];
 	int length = 0;
+	uint32_t desc_start = (uint32_t)desc_p;
+	uint32_t desc_end = desc_start +
+		roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
+	uint32_t data_start = (uint32_t)desc_p->dmamac_addr;
+	uint32_t data_end;
 
 	/* Invalidate entire buffer descriptor */
-	invalidate_dcache_range((unsigned long)desc_p,
-				(unsigned long)desc_p +
-				sizeof(struct dmamacdescr));
+	invalidate_dcache_range(desc_start, desc_end);
 
 	status = desc_p->txrx_status;
 
@@ -358,9 +360,8 @@ static int dw_eth_recv(struct eth_device *dev)
 			 DESC_RXSTS_FRMLENSHFT;
 
 		/* Invalidate received data */
-		invalidate_dcache_range((unsigned long)desc_p->dmamac_addr,
-					(unsigned long)desc_p->dmamac_addr +
-					roundup(length, ARCH_DMA_MINALIGN));
+		data_end = data_start + roundup(length, ARCH_DMA_MINALIGN);
+		invalidate_dcache_range(data_start, data_end);
 
 		NetReceive(desc_p->dmamac_addr, length);
 
@@ -371,10 +372,7 @@ static int dw_eth_recv(struct eth_device *dev)
 		desc_p->txrx_status |= DESC_RXSTS_OWNBYDMA;
 
 		/* Flush only status field - others weren't changed */
-		flush_dcache_range((unsigned long)&desc_p->txrx_status,
-				   (unsigned long)&desc_p->txrx_status +
-					roundup(sizeof(desc_p->txrx_status),
-						ARCH_DMA_MINALIGN));
+		flush_dcache_range(desc_start, desc_end);
 
 		/* Test the wrap-around condition. */
 		if (++desc_num >= CONFIG_RX_DESCR_NUM)
-- 
2.1.0

  parent reply	other threads:[~2014-09-15 11:05 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-15 11:05 [U-Boot] [PATCH 00/35][RFC] arm: socfpga: Usability fixes Marek Vasut
2014-09-15 11:05 ` [U-Boot] [PATCH 01/35] net: Remove unused CONFIG_DW_SEARCH_PHY from configs Marek Vasut
2014-09-15 15:34   ` Dinh Nguyen
2014-09-16 13:56     ` Marek Vasut
2014-09-15 11:05 ` [U-Boot] [PATCH 02/35] net: phy: Cleanup drivers/net/phy/micrel.c Marek Vasut
2014-09-15 11:05 ` [U-Boot] [PATCH 03/35] net: dwc: Fix cache alignment issues Marek Vasut
2014-09-15 15:40   ` Dinh Nguyen
2014-09-15 17:25     ` Marek Vasut
2014-09-15 11:05 ` Marek Vasut [this message]
2014-09-16 13:10   ` [U-Boot] [PATCH 04/35] net: dwc: Make the cache handling less cryptic Pavel Machek
2014-09-16 13:10   ` Pavel Machek
2014-09-16 13:11   ` Pavel Machek
2014-09-16 13:13   ` Pavel Machek
2014-09-16 13:13   ` Pavel Machek
2014-09-16 13:14   ` Pavel Machek
2014-09-16 13:16   ` Pavel Machek
2014-09-16 13:16   ` Pavel Machek
2014-09-16 18:10     ` Marek Vasut
2014-09-16 22:03       ` Dinh Nguyen
2014-09-16 22:12         ` Marek Vasut
2014-09-15 11:05 ` [U-Boot] [PATCH 05/35] mmc: dw_mmc: cleanups Marek Vasut
2014-09-15 16:00   ` Dinh Nguyen
2014-09-15 17:25     ` Marek Vasut
2014-09-15 11:05 ` [U-Boot] [PATCH 06/35] mmc: dw_mmc: Fix cache alignment issue Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 07/35] tools: socfpga: Add socfpga preloader signing to mkimage Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 08/35] arm: socfpga: Complete the list of base addresses Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 09/35] arm: socfpga: Clean up base address file Marek Vasut
2014-09-16 13:12   ` Pavel Machek
2014-09-15 11:06 ` [U-Boot] [PATCH 10/35] arm: socfpga: Add watchdog disable for socfpga Marek Vasut
2014-09-15 16:28   ` Dinh Nguyen
2014-09-16 13:58     ` Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 11/35] arm: socfpga: sysmgr: Clean up system manager Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 12/35] arm: socfpga: clock: Implant order into bit definitions Marek Vasut
2014-09-15 15:26   ` Wolfgang Denk
2014-09-15 21:21     ` Pavel Machek
2014-09-15 21:48       ` Marek Vasut
2014-09-16  8:18         ` Wolfgang Denk
2014-09-16 21:59           ` Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 13/35] arm: socfpga: clock: Drop nonsense inlining from clock manager code Marek Vasut
2014-09-15 19:25   ` Dinh Nguyen
2014-09-16 17:31     ` Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 14/35] arm: socfpga: clock: Add missing stubs into board file Marek Vasut
2014-09-15 19:27   ` Dinh Nguyen
2014-09-18 15:10   ` Pavel Machek
2014-09-15 11:06 ` [U-Boot] [PATCH 15/35] arm: socfpga: clock: Add code to read clock configuration Marek Vasut
2014-09-15 20:09   ` Dinh Nguyen
2014-09-16 18:09     ` Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 16/35] arm: socfpga: clock: Trim down code duplication Marek Vasut
2014-09-16 15:38   ` Dinh Nguyen
2014-09-18 15:12   ` Pavel Machek
2014-09-15 11:06 ` [U-Boot] [PATCH 17/35] arm: socfpga: mmc: Pick the clock from clock manager Marek Vasut
2014-09-16 15:52   ` Dinh Nguyen
2014-09-15 11:06 ` [U-Boot] [PATCH 18/35] arm: socfpga: timer: Pull the timer reload value from config file Marek Vasut
2014-09-15 21:25   ` Pavel Machek
2014-09-16 15:55   ` Dinh Nguyen
2014-09-15 11:06 ` [U-Boot] [PATCH 19/35] arm: socfpga: reset: Add EMAC reset functions Marek Vasut
2014-09-15 21:26   ` Pavel Machek
2014-09-15 11:06 ` [U-Boot] [PATCH 20/35] arm: socfpga: misc: Add proper ethernet initialization Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 21/35] arm: socfpga: misc: Add SD controller init Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 22/35] arm: socfpga: misc: Align print_cpuinfo() output Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 23/35] arm: socfpga: board: Correctly set ATAG position Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 24/35] arm: socfpga: board: Align checkboard() output Marek Vasut
2014-09-15 21:28   ` Pavel Machek
2014-09-15 11:06 ` [U-Boot] [PATCH 25/35] arm: socfpga: fpga: Add SoCFPGA FPGA programming interface Marek Vasut
2014-09-15 15:41   ` Wolfgang Denk
2014-09-16 18:18     ` Marek Vasut
2014-09-16  9:42   ` Michal Simek
2014-09-16 10:12     ` Marek Vasut
2014-09-16 10:33       ` Michal Simek
2014-09-16 20:15         ` Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 26/35] arm: socfpga: reset: Add function to reset FPGA bridges Marek Vasut
2014-09-15 21:31   ` Pavel Machek
2014-09-15 11:06 ` [U-Boot] [PATCH 27/35] arm: socfpga: sysmgr: Add FPGA bits into system manager Marek Vasut
2014-09-15 11:06 ` [U-Boot] [PATCH 28/35] arm: cache: Add support for write-allocate D-Cache Marek Vasut
2014-09-15 21:34   ` Pavel Machek
2014-09-15 11:06 ` [U-Boot] [PATCH 29/35] arm: socfpga: cache: Define cacheline size Marek Vasut
2014-09-15 21:35   ` Pavel Machek
2014-09-15 11:59 ` [U-Boot] [PATCH 30/35] arm: socfpga: cache: Enable D-Cache Marek Vasut
2014-09-15 21:39   ` Pavel Machek
2014-09-15 17:17 ` [U-Boot] [PATCH 31/35] arm: socfpga: cache: Enable PL310 L2 cache Marek Vasut
2014-09-15 17:17 ` [U-Boot] [PATCH 32/35] arm: socfpga: scu: Add SCU register file Marek Vasut
2014-09-15 17:17 ` [U-Boot] [PATCH 33/35] arm: socfpga: nic301: Add NIC-301 GPV " Marek Vasut
2014-09-15 17:17 ` [U-Boot] [PATCH 34/35] arm: socfpga: pl310: Map SDRAM to 0x0 Marek Vasut
2014-09-15 17:18 ` [U-Boot] [PATCH 35/35] arm: socfpga: nic301: Add NIC-301 configuration code Marek Vasut
2014-09-16 13:18 ` [U-Boot] [PATCH 00/35][RFC] arm: socfpga: Usability fixes Pavel Machek
2014-09-16 16:28   ` Dinh Nguyen
2014-09-16 20:43     ` Marek Vasut
2014-09-16 21:29       ` dinguyen
2014-09-16 21:55         ` Marek Vasut
2014-09-16 22:29           ` Dinh Nguyen
2014-09-16 23:52             ` Marek Vasut
2014-09-17 11:07               ` Chin Liang See
2014-09-17 12:35                 ` Marek Vasut
2014-09-17 14:11                 ` Wolfgang Denk
2014-09-19  9:44                   ` Chin Liang See
2014-09-19 11:12                     ` Marek Vasut
2014-09-19 12:06                       ` Marek Vasut
2014-09-17  5:33           ` Wolfgang Denk
2014-09-16 21:35       ` dinguyen
2014-09-16 21:46         ` Marek Vasut
2014-09-16 22:20           ` Dinh Nguyen
2014-09-16 23:52             ` Marek Vasut
2014-09-18 15:19         ` Pavel Machek
2014-09-17 11:29 ` Chin Liang See
2014-09-17 11:52   ` Marek Vasut
2014-09-17 12:00     ` Chin Liang See
2014-09-17 12:39       ` Marek Vasut
2014-09-19  9:32         ` Chin Liang See
2014-09-19 10:36           ` Chin Liang See
2014-09-19 11:11             ` Marek Vasut

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=1410779188-6880-5-git-send-email-marex@denx.de \
    --to=marex@denx.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.