[U-Boot] [PATCH 3/3]: arm: Kirkwood: See to it that sent data is 8-byte aligned

Simon Kagstrom simon.kagstrom at netinsight.net
Thu Jul 2 15:04:01 CEST 2009


See to it that sent data is 8-byte aligned

U-boot might use non-8-byte-aligned addresses for sending data, which
the kwgbe_send doesn't accept (bootp does this for me). This patch
copies the data to be sent to a temporary buffer if it is non-aligned.

Signed-off-by: Simon Kagstrom <simon.kagstrom at netinsight.net>
---
 drivers/net/kirkwood_egiga.c |   26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/net/kirkwood_egiga.c b/drivers/net/kirkwood_egiga.c
index ecd3a28..1fe549c 100644
--- a/drivers/net/kirkwood_egiga.c
+++ b/drivers/net/kirkwood_egiga.c
@@ -481,18 +481,13 @@ static int kwgbe_halt(struct eth_device *dev)
 	return 0;
 }
 
-static int kwgbe_send(struct eth_device *dev, volatile void *dataptr,
+static int kwgbe_send_aligned(struct eth_device *dev, volatile void *dataptr,
 		      int datasize)
 {
 	volatile struct kwgbe_device *dkwgbe = to_dkwgbe(dev);
 	volatile struct kwgbe_registers *regs = dkwgbe->regs;
 	volatile struct kwgbe_txdesc *p_txdesc = dkwgbe->p_txdesc;
 
-	if ((u32) dataptr & 0x07) {
-		printf("Err..(%s) xmit dataptr not 64bit aligned\n",
-			__FUNCTION__);
-		return -1;
-	}
 	p_txdesc->cmd_sts = KWGBE_ZERO_PADDING | KWGBE_GEN_CRC;
 	p_txdesc->cmd_sts |= KWGBE_TX_FIRST_DESC | KWGBE_TX_LAST_DESC;
 	p_txdesc->cmd_sts |= KWGBE_BUFFER_OWNED_BY_DMA;
@@ -519,6 +514,25 @@ static int kwgbe_send(struct eth_device *dev, volatile void *dataptr,
 	return 0;
 }
 
+static int kwgbe_send(struct eth_device *dev, volatile void *dataptr,
+		      int datasize)
+{
+	static u8 __attribute__((aligned(8))) aligned_buf[9000];
+	void *p = (void*)dataptr;
+
+	if ((u32) dataptr & 0x07) {
+		if (datasize > sizeof(aligned_buf)) {
+			printf("Err..(%s) Non-aligned data is too large: %d bytes\n",
+				__FUNCTION__, datasize);
+			return -1;
+		}
+		memcpy(aligned_buf, p, datasize);
+		p = aligned_buf;
+	}
+
+	return kwgbe_send_aligned(dev, p, datasize);
+}
+
 static int kwgbe_recv(struct eth_device *dev)
 {
 	volatile struct kwgbe_device *dkwgbe = to_dkwgbe(dev);
-- 
1.6.0.4



More information about the U-Boot mailing list