From 7d7aa705597c9ff99a94fc4e05571eb298262f0c Mon Sep 17 00:00:00 2001 From: Sham Muthayyan Date: Wed, 14 Feb 2018 16:46:25 +0530 Subject: [PATCH] ipq807x: Add Cache support for ethernet Change-Id: I58bf5e992175e73635f35b2b4bcbb44b501bd799 Signed-off-by: Sham Muthayyan --- drivers/net/ipq807x/ipq807x_edma.c | 44 ++++++++++++++++++++++++------ drivers/net/ipq807x/ipq807x_edma.h | 8 ++++++ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/drivers/net/ipq807x/ipq807x_edma.c b/drivers/net/ipq807x/ipq807x_edma.c index 8d8c747806..88b0971de7 100644 --- a/drivers/net/ipq807x/ipq807x_edma.c +++ b/drivers/net/ipq807x/ipq807x_edma.c @@ -150,7 +150,7 @@ int ipq807x_edma_alloc_rx_buffer(struct ipq807x_edma_hw *ehw, /* * Allocate buffer */ - skb = virt_to_phys(net_rx_packets[counter]); + skb = virt_to_phys(net_rx_packets[next]); /* * Get RXFILL descriptor @@ -178,6 +178,13 @@ int ipq807x_edma_alloc_rx_buffer(struct ipq807x_edma_hw *ehw, */ rxfill_desc->buffer_addr = cpu_to_le32(skb); + flush_dcache_range((unsigned long)rxfill_desc, + (unsigned long)rxfill_desc + + sizeof(struct ipq807x_edma_rxfill_desc)); + flush_dcache_range((unsigned long)(rxfill_desc->buffer_addr), + (unsigned long)(rxfill_desc->buffer_addr) + + PKTSIZE_ALIGN); + num_alloc++; next = counter; } @@ -301,6 +308,11 @@ uint32_t ipq807x_edma_clean_rx(struct ipq807x_edma_common_info *c_info, rxdesc_desc = IPQ807X_EDMA_RXDESC_DESC(rxdesc_ring, cons_idx); + invalidate_dcache_range( + (unsigned long)(rxdesc_desc->buffer_addr), + (unsigned long)((rxdesc_desc->buffer_addr) + + PKTSIZE_ALIGN)); + skb = (void *)rxdesc_desc->buffer_addr; /* @@ -549,6 +561,14 @@ static int ipq807x_eth_snd(struct eth_device *dev, void *packet, int length) txdesc->word1 |= ((length & IPQ807X_EDMA_TXDESC_DATA_LENGTH_MASK) << IPQ807X_EDMA_TXDESC_DATA_LENGTH_SHIFT); + flush_dcache_range((unsigned long)txdesc, + (unsigned long)txdesc + + sizeof(struct ipq807x_edma_txdesc_desc)); + + flush_dcache_range((unsigned long)(txdesc->buffer_addr), + (unsigned long)(txdesc->buffer_addr) + + PKTSIZE_ALIGN); + /* * Update producer index */ @@ -583,6 +603,12 @@ static int ipq807x_eth_recv(struct eth_device *dev) */ for (i = 0; i < ehw->rxdesc_rings; i++) { rxdesc_ring = &ehw->rxdesc_ring[i]; + + invalidate_dcache_range((unsigned long)(&rxdesc_ring->desc[0]), + (unsigned long)(&rxdesc_ring->desc[0] + + (IPQ807X_EDMA_RXDESC_RING_SIZE * + sizeof(struct ipq807x_edma_rxdesc_desc)))); + reg_data = ipq807x_edma_reg_read( IPQ807X_EDMA_REG_RXDESC_INT_STAT( rxdesc_ring->id)); @@ -623,7 +649,7 @@ static int ipq807x_edma_setup_ring_resources(struct ipq807x_edma_hw *ehw) rxfill_ring = &ehw->rxfill_ring[i]; rxfill_ring->count = IPQ807X_EDMA_RXFILL_RING_SIZE; rxfill_ring->id = ehw->rxfill_ring_start + i; - rxfill_ring->desc = ipq807x_alloc_mem( + rxfill_ring->desc = ipq807x_alloc_memalign( sizeof(struct ipq807x_edma_rxfill_desc) * rxfill_ring->count); @@ -653,7 +679,7 @@ static int ipq807x_edma_setup_ring_resources(struct ipq807x_edma_hw *ehw) &ehw->rxfill_ring[index - ehw->rxfill_ring_start]; rxdesc_ring->rxfill = ehw->rxfill_ring; - rxdesc_ring->desc = ipq807x_alloc_mem( + rxdesc_ring->desc = ipq807x_alloc_memalign( sizeof(struct ipq807x_edma_rxdesc_desc) * rxdesc_ring->count); @@ -671,7 +697,7 @@ static int ipq807x_edma_setup_ring_resources(struct ipq807x_edma_hw *ehw) txcmpl_ring = &ehw->txcmpl_ring[i]; txcmpl_ring->count = IPQ807X_EDMA_TXCMPL_RING_SIZE; txcmpl_ring->id = ehw->txcmpl_ring_start + i; - txcmpl_ring->desc = ipq807x_alloc_mem( + txcmpl_ring->desc = ipq807x_alloc_memalign( sizeof(struct ipq807x_edma_txcmpl_desc) * txcmpl_ring->count); @@ -690,7 +716,7 @@ static int ipq807x_edma_setup_ring_resources(struct ipq807x_edma_hw *ehw) txdesc_ring = &ehw->txdesc_ring[i]; txdesc_ring->count = IPQ807X_EDMA_TXDESC_RING_SIZE; txdesc_ring->id = ehw->txdesc_ring_start + i; - txdesc_ring->desc = ipq807x_alloc_mem( + txdesc_ring->desc = ipq807x_alloc_memalign( sizeof(struct ipq807x_edma_txdesc_desc) * txdesc_ring->count); @@ -1112,7 +1138,7 @@ static void ipq807x_edma_set_ring_values(struct ipq807x_edma_hw *edma_hw) */ static int ipq807x_edma_alloc_rings(struct ipq807x_edma_hw *ehw) { - ehw->rxfill_ring = ipq807x_alloc_mem((sizeof( + ehw->rxfill_ring = ipq807x_alloc_memalign((sizeof( struct ipq807x_edma_rxfill_ring) * ehw->rxfill_rings)); @@ -1121,7 +1147,7 @@ static int ipq807x_edma_alloc_rings(struct ipq807x_edma_hw *ehw) return -1; } - ehw->rxdesc_ring = ipq807x_alloc_mem((sizeof( + ehw->rxdesc_ring = ipq807x_alloc_memalign((sizeof( struct ipq807x_edma_rxdesc_ring) * ehw->rxdesc_rings)); @@ -1130,7 +1156,7 @@ static int ipq807x_edma_alloc_rings(struct ipq807x_edma_hw *ehw) goto rxdesc_ring_alloc_fail; } - ehw->txdesc_ring = ipq807x_alloc_mem((sizeof( + ehw->txdesc_ring = ipq807x_alloc_memalign((sizeof( struct ipq807x_edma_txdesc_ring) * ehw->txdesc_rings)); if (!ehw->txdesc_ring) { @@ -1138,7 +1164,7 @@ static int ipq807x_edma_alloc_rings(struct ipq807x_edma_hw *ehw) goto txdesc_ring_alloc_fail; } - ehw->txcmpl_ring = ipq807x_alloc_mem((sizeof( + ehw->txcmpl_ring = ipq807x_alloc_memalign((sizeof( struct ipq807x_edma_txcmpl_ring) * ehw->txcmpl_rings)); diff --git a/drivers/net/ipq807x/ipq807x_edma.h b/drivers/net/ipq807x/ipq807x_edma.h index 44795ca6b5..eaf78f3025 100644 --- a/drivers/net/ipq807x/ipq807x_edma.h +++ b/drivers/net/ipq807x/ipq807x_edma.h @@ -277,6 +277,14 @@ static inline void* ipq807x_alloc_mem(u32 size) return p; } +static inline void* ipq807x_alloc_memalign(u32 size) +{ + void *p = memalign(CONFIG_SYS_CACHELINE_SIZE, size); + if (p != NULL) + memset(p, 0, size); + return p; +} + static inline void ipq807x_free_mem(void *ptr) { if (ptr)