From 7a2651f6334e8d8260714cccf73cee1b3fcdfb61 Mon Sep 17 00:00:00 2001 From: Gabor Juhos Date: Tue, 31 May 2011 22:53:09 +0000 Subject: [PATCH] ar71xx: ag71xx: prepare to make ring sizes configurable SVN-Revision: 27040 --- .../ar71xx/files/drivers/net/ag71xx/ag71xx.h | 8 +--- .../files/drivers/net/ag71xx/ag71xx_debugfs.c | 13 +++--- .../files/drivers/net/ag71xx/ag71xx_main.c | 46 ++++++++++--------- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx.h b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx.h index 9e0ce9b3e4..64a82f1f25 100644 --- a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx.h +++ b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx.h @@ -54,12 +54,8 @@ #define AG71XX_RX_PKT_SIZE \ (AG71XX_RX_PKT_RESERVE + ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN) -#define AG71XX_TX_RING_SIZE 64 -#define AG71XX_TX_THRES_STOP (AG71XX_TX_RING_SIZE - 4) -#define AG71XX_TX_THRES_WAKEUP \ - (AG71XX_TX_RING_SIZE - (AG71XX_TX_RING_SIZE / 4)) - -#define AG71XX_RX_RING_SIZE 128 +#define AG71XX_TX_RING_SIZE_DEFAULT 64 +#define AG71XX_RX_RING_SIZE_DEFAULT 128 #ifdef CONFIG_AG71XX_DEBUG #define DBG(fmt, args...) printk(KERN_DEBUG fmt, ## args) diff --git a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_debugfs.c b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_debugfs.c index 90a50dad07..65f2be198f 100644 --- a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_debugfs.c +++ b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_debugfs.c @@ -155,7 +155,6 @@ static ssize_t read_file_ring(struct file *file, char __user *user_buf, size_t count, loff_t *ppos, struct ag71xx *ag, struct ag71xx_ring *ring, - unsigned ring_size, unsigned desc_reg) { char *buf; @@ -168,7 +167,7 @@ static ssize_t read_file_ring(struct file *file, char __user *user_buf, u32 desc_hw; int i; - buflen = (ring_size * DESC_PRINT_LEN); + buflen = (ring->size * DESC_PRINT_LEN); buf = kmalloc(buflen, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -179,10 +178,10 @@ static ssize_t read_file_ring(struct file *file, char __user *user_buf, spin_lock_irqsave(&ag->lock, flags); - curr = (ring->curr % ring_size); - dirty = (ring->dirty % ring_size); + curr = (ring->curr % ring->size); + dirty = (ring->dirty % ring->size); desc_hw = ag71xx_rr(ag, desc_reg); - for (i = 0; i < ring_size; i++) { + for (i = 0; i < ring->size; i++) { struct ag71xx_buf *ab = &ring->buf[i]; u32 desc_dma = ((u32) ring->descs_dma) + i * ring->desc_size; @@ -214,7 +213,7 @@ static ssize_t read_file_tx_ring(struct file *file, char __user *user_buf, struct ag71xx *ag = file->private_data; return read_file_ring(file, user_buf, count, ppos, ag, &ag->tx_ring, - AG71XX_TX_RING_SIZE, AG71XX_REG_TX_DESC); + AG71XX_REG_TX_DESC); } static const struct file_operations ag71xx_fops_tx_ring = { @@ -229,7 +228,7 @@ static ssize_t read_file_rx_ring(struct file *file, char __user *user_buf, struct ag71xx *ag = file->private_data; return read_file_ring(file, user_buf, count, ppos, ag, &ag->rx_ring, - AG71XX_RX_RING_SIZE, AG71XX_REG_RX_DESC); + AG71XX_REG_RX_DESC); } static const struct file_operations ag71xx_fops_rx_ring = { diff --git a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_main.c b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_main.c index a2b4bfeb30..f1eb0716a0 100644 --- a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_main.c +++ b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_main.c @@ -90,7 +90,7 @@ static void ag71xx_ring_free(struct ag71xx_ring *ring) ring->descs_cpu, ring->descs_dma); } -static int ag71xx_ring_alloc(struct ag71xx_ring *ring, unsigned int size) +static int ag71xx_ring_alloc(struct ag71xx_ring *ring) { int err; int i; @@ -103,22 +103,21 @@ static int ag71xx_ring_alloc(struct ag71xx_ring *ring, unsigned int size) ring->desc_size = roundup(ring->desc_size, cache_line_size()); } - ring->descs_cpu = dma_alloc_coherent(NULL, size * ring->desc_size, + ring->descs_cpu = dma_alloc_coherent(NULL, ring->size * ring->desc_size, &ring->descs_dma, GFP_ATOMIC); if (!ring->descs_cpu) { err = -ENOMEM; goto err; } - ring->size = size; - ring->buf = kzalloc(size * sizeof(*ring->buf), GFP_KERNEL); + ring->buf = kzalloc(ring->size * sizeof(*ring->buf), GFP_KERNEL); if (!ring->buf) { err = -ENOMEM; goto err; } - for (i = 0; i < size; i++) { + for (i = 0; i < ring->size; i++) { int idx = i * ring->desc_size; ring->buf[i].desc = (struct ag71xx_desc *)&ring->descs_cpu[idx]; DBG("ag71xx: ring %p, desc %d at %p\n", @@ -137,7 +136,7 @@ static void ag71xx_ring_tx_clean(struct ag71xx *ag) struct net_device *dev = ag->dev; while (ring->curr != ring->dirty) { - u32 i = ring->dirty % AG71XX_TX_RING_SIZE; + u32 i = ring->dirty % ring->size; if (!ag71xx_desc_empty(ring->buf[i].desc)) { ring->buf[i].desc->ctrl = 0; @@ -162,9 +161,9 @@ static void ag71xx_ring_tx_init(struct ag71xx *ag) struct ag71xx_ring *ring = &ag->tx_ring; int i; - for (i = 0; i < AG71XX_TX_RING_SIZE; i++) { + for (i = 0; i < ring->size; i++) { ring->buf[i].desc->next = (u32) (ring->descs_dma + - ring->desc_size * ((i + 1) % AG71XX_TX_RING_SIZE)); + ring->desc_size * ((i + 1) % ring->size)); ring->buf[i].desc->ctrl = DESC_EMPTY; ring->buf[i].skb = NULL; @@ -185,7 +184,7 @@ static void ag71xx_ring_rx_clean(struct ag71xx *ag) if (!ring->buf) return; - for (i = 0; i < AG71XX_RX_RING_SIZE; i++) + for (i = 0; i < ring->size; i++) if (ring->buf[i].skb) { dma_unmap_single(&ag->dev->dev, ring->buf[i].dma_addr, AG71XX_RX_PKT_SIZE, DMA_FROM_DEVICE); @@ -219,16 +218,16 @@ static int ag71xx_ring_rx_init(struct ag71xx *ag) int ret; ret = 0; - for (i = 0; i < AG71XX_RX_RING_SIZE; i++) { + for (i = 0; i < ring->size; i++) { ring->buf[i].desc->next = (u32) (ring->descs_dma + - ring->desc_size * ((i + 1) % AG71XX_RX_RING_SIZE)); + ring->desc_size * ((i + 1) % ring->size)); DBG("ag71xx: RX desc at %p, next is %08x\n", ring->buf[i].desc, ring->buf[i].desc->next); } - for (i = 0; i < AG71XX_RX_RING_SIZE; i++) { + for (i = 0; i < ring->size; i++) { struct sk_buff *skb; dma_addr_t dma_addr; @@ -269,7 +268,7 @@ static int ag71xx_ring_rx_refill(struct ag71xx *ag) for (; ring->curr - ring->dirty > 0; ring->dirty++) { unsigned int i; - i = ring->dirty % AG71XX_RX_RING_SIZE; + i = ring->dirty % ring->size; if (ring->buf[i].skb == NULL) { dma_addr_t dma_addr; @@ -307,13 +306,13 @@ static int ag71xx_rings_init(struct ag71xx *ag) { int ret; - ret = ag71xx_ring_alloc(&ag->tx_ring, AG71XX_TX_RING_SIZE); + ret = ag71xx_ring_alloc(&ag->tx_ring); if (ret) return ret; ag71xx_ring_tx_init(ag); - ret = ag71xx_ring_alloc(&ag->rx_ring, AG71XX_RX_RING_SIZE); + ret = ag71xx_ring_alloc(&ag->rx_ring); if (ret) return ret; @@ -631,7 +630,7 @@ static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb, dma_addr_t dma_addr; int i; - i = ring->curr % AG71XX_TX_RING_SIZE; + i = ring->curr % ring->size; desc = ring->buf[i].desc; if (!ag71xx_desc_empty(desc)) @@ -659,7 +658,7 @@ static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb, wmb(); ring->curr++; - if (ring->curr == (ring->dirty + AG71XX_TX_THRES_STOP)) { + if (ring->curr == (ring->dirty + ring->size)) { DBG("%s: tx queue full\n", ag->dev->name); netif_stop_queue(dev); } @@ -760,7 +759,7 @@ static int ag71xx_tx_packets(struct ag71xx *ag) sent = 0; while (ring->dirty != ring->curr) { - unsigned int i = ring->dirty % AG71XX_TX_RING_SIZE; + unsigned int i = ring->dirty % ring->size; struct ag71xx_desc *desc = ring->buf[i].desc; struct sk_buff *skb = ring->buf[i].skb; @@ -781,7 +780,7 @@ static int ag71xx_tx_packets(struct ag71xx *ag) DBG("%s: %d packets sent out\n", ag->dev->name, sent); - if ((ring->curr - ring->dirty) < AG71XX_TX_THRES_WAKEUP) + if ((ring->curr - ring->dirty) < (ring->size * 3) / 4) netif_wake_queue(ag->dev); return sent; @@ -797,7 +796,7 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit) dev->name, limit, ring->curr, ring->dirty); while (done < limit) { - unsigned int i = ring->curr % AG71XX_RX_RING_SIZE; + unsigned int i = ring->curr % ring->size; struct ag71xx_desc *desc = ring->buf[i].desc; struct sk_buff *skb; int pktlen; @@ -806,7 +805,7 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit) if (ag71xx_desc_empty(desc)) break; - if ((ring->dirty + AG71XX_RX_RING_SIZE) == ring->curr) { + if ((ring->dirty + ring->size) == ring->curr) { ag71xx_assert(0); break; } @@ -876,7 +875,7 @@ static int ag71xx_poll(struct napi_struct *napi, int limit) ag71xx_debugfs_update_napi_stats(ag, rx_done, tx_done); rx_ring = &ag->rx_ring; - if (rx_ring->buf[rx_ring->dirty % AG71XX_RX_RING_SIZE].skb == NULL) + if (rx_ring->buf[rx_ring->dirty % rx_ring->size].skb == NULL) goto oom; status = ag71xx_rr(ag, AG71XX_REG_RX_STATUS); @@ -1074,6 +1073,9 @@ static int __devinit ag71xx_probe(struct platform_device *pdev) ag->oom_timer.data = (unsigned long) dev; ag->oom_timer.function = ag71xx_oom_timer_handler; + ag->tx_ring.size = AG71XX_TX_RING_SIZE_DEFAULT; + ag->rx_ring.size = AG71XX_RX_RING_SIZE_DEFAULT; + memcpy(dev->dev_addr, pdata->mac_addr, ETH_ALEN); netif_napi_add(dev, &ag->napi, ag71xx_poll, AG71XX_NAPI_WEIGHT); -- 2.30.2