net: macb: Add on the fly CPU endianness detection
authorArun Chandran <achandran@mvista.com>
Sun, 1 Mar 2015 06:08:02 +0000 (11:38 +0530)
committerDavid S. Miller <davem@davemloft.net>
Mon, 2 Mar 2015 04:05:23 +0000 (23:05 -0500)
Program management descriptor's access mode according to the
dynamically detected CPU endianness.

Signed-off-by: Arun Chandran <achandran@mvista.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Tested-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/cadence/macb.c

index 05fb36da0cff0590d82536877b2c661ac2e68fa6..1fe8b946243af5187851569a13be4c5e914dade0 100644 (file)
@@ -1578,6 +1578,7 @@ static u32 macb_dbw(struct macb *bp)
 static void macb_configure_dma(struct macb *bp)
 {
        u32 dmacfg;
+       u32 tmp, ncr;
 
        if (macb_is_gem(bp)) {
                dmacfg = gem_readl(bp, DMACFG) & ~GEM_BF(RXBS, -1L);
@@ -1586,10 +1587,23 @@ static void macb_configure_dma(struct macb *bp)
                        dmacfg = GEM_BFINS(FBLDO, bp->dma_burst_length, dmacfg);
                dmacfg |= GEM_BIT(TXPBMS) | GEM_BF(RXBMS, -1L);
                dmacfg &= ~GEM_BIT(ENDIA_PKT);
-               /* Tell the chip to byteswap descriptors on big-endian hosts */
-#ifdef __BIG_ENDIAN
-               dmacfg |= GEM_BIT(ENDIA_DESC);
-#endif
+
+               /* Find the CPU endianness by using the loopback bit of net_ctrl
+                * register. save it first. When the CPU is in big endian we
+                * need to program swaped mode for management descriptor access.
+                */
+               ncr = macb_readl(bp, NCR);
+               __raw_writel(MACB_BIT(LLB), bp->regs + MACB_NCR);
+               tmp =  __raw_readl(bp->regs + MACB_NCR);
+
+               if (tmp == MACB_BIT(LLB))
+                       dmacfg &= ~GEM_BIT(ENDIA_DESC);
+               else
+                       dmacfg |= GEM_BIT(ENDIA_DESC); /* CPU in big endian */
+
+               /* Restore net_ctrl */
+               macb_writel(bp, NCR, ncr);
+
                if (bp->dev->features & NETIF_F_HW_CSUM)
                        dmacfg |= GEM_BIT(TXCOEN);
                else
This page took 0.026204 seconds and 5 git commands to generate.