[LEDE-DEV] [PATCH 5/7] ag71xx: Replace AG71XX_DESC_SIZE macro with a struct member.
Rosen Penev
rosenp at gmail.com
Thu Dec 7 18:37:15 PST 2017
Moves the code more in line with QCA code. Also reduces variable to a u16 instead of s32.
QCA code has the roundup component behind a Makefile config. Not sure if enabled by default so I opted to keep current behavior.
Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
.../files/drivers/net/ethernet/atheros/ag71xx/ag71xx.h | 6 ++----
.../drivers/net/ethernet/atheros/ag71xx/ag71xx_debugfs.c | 2 +-
.../drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c | 16 ++++++++++++----
3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx.h b/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx.h
index 39237aa..9964993 100644
--- a/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx.h
+++ b/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx.h
@@ -90,9 +90,6 @@ struct ag71xx_desc {
u32 pad;
} __attribute__((aligned(4)));
-#define AG71XX_DESC_SIZE roundup(sizeof(struct ag71xx_desc), \
- L1_CACHE_BYTES)
-
struct ag71xx_buf {
union {
struct sk_buff *skb;
@@ -112,6 +109,7 @@ struct ag71xx_ring {
/* "Cold" fields - not used in the data path. */
struct ag71xx_buf *buf;
+ u16 desc_size;
u8 *descs_cpu;
dma_addr_t descs_dma;
u16 desc_split;
@@ -230,7 +228,7 @@ static inline int ag71xx_desc_empty(struct ag71xx_desc *desc)
static inline struct ag71xx_desc *
ag71xx_ring_desc(struct ag71xx_ring *ring, int idx)
{
- return (struct ag71xx_desc *) &ring->descs_cpu[idx * AG71XX_DESC_SIZE];
+ return (struct ag71xx_desc *) &ring->descs_cpu[idx * ring->desc_size];
}
static inline int
diff --git a/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_debugfs.c b/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_debugfs.c
index c86803c..143689b 100644
--- a/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_debugfs.c
+++ b/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_debugfs.c
@@ -186,7 +186,7 @@ static ssize_t read_file_ring(struct file *file, char __user *user_buf,
for (i = 0; i < ring_size; i++) {
struct ag71xx_buf *ab = &ring->buf[i];
struct ag71xx_desc *desc = ag71xx_ring_desc(ring, i);
- u32 desc_dma = ((u32) ring->descs_dma) + i * AG71XX_DESC_SIZE;
+ u32 desc_dma = ((u32) ring->descs_dma) + i * ring->desc_size;
len += snprintf(buf + len, buflen - len,
"%3d %c%c%c %08x %08x %08x %08x %c %10lu\n",
diff --git a/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c b/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c
index 7518352..c1d754f 100644
--- a/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c
+++ b/target/linux/ar71xx/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c
@@ -105,7 +105,7 @@ static void ag71xx_ring_free(struct ag71xx_ring *ring)
kfree(ring->buf);
if (ring->descs_cpu)
- dma_free_coherent(NULL, ring_size * AG71XX_DESC_SIZE,
+ dma_free_coherent(NULL, ring_size * ring->desc_size,
ring->descs_cpu, ring->descs_dma);
}
@@ -113,7 +113,15 @@ static int ag71xx_ring_alloc(struct ag71xx_ring *ring)
{
int ring_size = BIT(ring->order);
- ring->descs_cpu = dma_alloc_coherent(NULL, ring_size * AG71XX_DESC_SIZE,
+ ring->desc_size = sizeof(struct ag71xx_desc);
+ if (ring->desc_size % cache_line_size()) {
+ DBG("ag71xx: ring %p, desc size %u rounded to %u\n",
+ ring, ring->desc_size,
+ roundup(ring->desc_size, cache_line_size()));
+ ring->desc_size = roundup(ring->desc_size, cache_line_size());
+ }
+
+ ring->descs_cpu = dma_alloc_coherent(NULL, ring_size * ring->desc_size,
&ring->descs_dma, GFP_ATOMIC);
if (!ring->descs_cpu)
return -ENOMEM;
@@ -168,7 +176,7 @@ static void ag71xx_ring_tx_init(struct ag71xx *ag)
struct ag71xx_desc *desc = ag71xx_ring_desc(ring, i);
desc->next = (u32) (ring->descs_dma +
- AG71XX_DESC_SIZE * ((i + 1) & ring_mask));
+ ring->desc_size * ((i + 1) & ring_mask));
desc->ctrl = DESC_EMPTY;
ring->buf[i].skb = NULL;
@@ -254,7 +262,7 @@ static int ag71xx_ring_rx_init(struct ag71xx *ag)
struct ag71xx_desc *desc = ag71xx_ring_desc(ring, i);
desc->next = (u32) (ring->descs_dma +
- AG71XX_DESC_SIZE * ((i + 1) & ring_mask));
+ ring->desc_size * ((i + 1) & ring_mask));
DBG("ag71xx: RX desc at %p, next is %08x\n",
desc, desc->next);
--
2.7.4
More information about the Lede-dev
mailing list