ar71xx: ag71xx: prepare to make ring sizes configurable
SVN-Revision: 27040
This commit is contained in:
parent
669aba3871
commit
7a2651f633
3 changed files with 32 additions and 35 deletions
|
@ -54,12 +54,8 @@
|
||||||
#define AG71XX_RX_PKT_SIZE \
|
#define AG71XX_RX_PKT_SIZE \
|
||||||
(AG71XX_RX_PKT_RESERVE + ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
|
(AG71XX_RX_PKT_RESERVE + ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
|
||||||
|
|
||||||
#define AG71XX_TX_RING_SIZE 64
|
#define AG71XX_TX_RING_SIZE_DEFAULT 64
|
||||||
#define AG71XX_TX_THRES_STOP (AG71XX_TX_RING_SIZE - 4)
|
#define AG71XX_RX_RING_SIZE_DEFAULT 128
|
||||||
#define AG71XX_TX_THRES_WAKEUP \
|
|
||||||
(AG71XX_TX_RING_SIZE - (AG71XX_TX_RING_SIZE / 4))
|
|
||||||
|
|
||||||
#define AG71XX_RX_RING_SIZE 128
|
|
||||||
|
|
||||||
#ifdef CONFIG_AG71XX_DEBUG
|
#ifdef CONFIG_AG71XX_DEBUG
|
||||||
#define DBG(fmt, args...) printk(KERN_DEBUG fmt, ## args)
|
#define DBG(fmt, args...) printk(KERN_DEBUG fmt, ## args)
|
||||||
|
|
|
@ -155,7 +155,6 @@ static ssize_t read_file_ring(struct file *file, char __user *user_buf,
|
||||||
size_t count, loff_t *ppos,
|
size_t count, loff_t *ppos,
|
||||||
struct ag71xx *ag,
|
struct ag71xx *ag,
|
||||||
struct ag71xx_ring *ring,
|
struct ag71xx_ring *ring,
|
||||||
unsigned ring_size,
|
|
||||||
unsigned desc_reg)
|
unsigned desc_reg)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
|
@ -168,7 +167,7 @@ static ssize_t read_file_ring(struct file *file, char __user *user_buf,
|
||||||
u32 desc_hw;
|
u32 desc_hw;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
buflen = (ring_size * DESC_PRINT_LEN);
|
buflen = (ring->size * DESC_PRINT_LEN);
|
||||||
buf = kmalloc(buflen, GFP_KERNEL);
|
buf = kmalloc(buflen, GFP_KERNEL);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return -ENOMEM;
|
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);
|
spin_lock_irqsave(&ag->lock, flags);
|
||||||
|
|
||||||
curr = (ring->curr % ring_size);
|
curr = (ring->curr % ring->size);
|
||||||
dirty = (ring->dirty % ring_size);
|
dirty = (ring->dirty % ring->size);
|
||||||
desc_hw = ag71xx_rr(ag, desc_reg);
|
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];
|
struct ag71xx_buf *ab = &ring->buf[i];
|
||||||
u32 desc_dma = ((u32) ring->descs_dma) + i * ring->desc_size;
|
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;
|
struct ag71xx *ag = file->private_data;
|
||||||
|
|
||||||
return read_file_ring(file, user_buf, count, ppos, ag, &ag->tx_ring,
|
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 = {
|
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;
|
struct ag71xx *ag = file->private_data;
|
||||||
|
|
||||||
return read_file_ring(file, user_buf, count, ppos, ag, &ag->rx_ring,
|
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 = {
|
static const struct file_operations ag71xx_fops_rx_ring = {
|
||||||
|
|
|
@ -90,7 +90,7 @@ static void ag71xx_ring_free(struct ag71xx_ring *ring)
|
||||||
ring->descs_cpu, ring->descs_dma);
|
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 err;
|
||||||
int i;
|
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->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);
|
&ring->descs_dma, GFP_ATOMIC);
|
||||||
if (!ring->descs_cpu) {
|
if (!ring->descs_cpu) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto err;
|
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) {
|
if (!ring->buf) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < ring->size; i++) {
|
||||||
int idx = i * ring->desc_size;
|
int idx = i * ring->desc_size;
|
||||||
ring->buf[i].desc = (struct ag71xx_desc *)&ring->descs_cpu[idx];
|
ring->buf[i].desc = (struct ag71xx_desc *)&ring->descs_cpu[idx];
|
||||||
DBG("ag71xx: ring %p, desc %d at %p\n",
|
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;
|
struct net_device *dev = ag->dev;
|
||||||
|
|
||||||
while (ring->curr != ring->dirty) {
|
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)) {
|
if (!ag71xx_desc_empty(ring->buf[i].desc)) {
|
||||||
ring->buf[i].desc->ctrl = 0;
|
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;
|
struct ag71xx_ring *ring = &ag->tx_ring;
|
||||||
int i;
|
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->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].desc->ctrl = DESC_EMPTY;
|
||||||
ring->buf[i].skb = NULL;
|
ring->buf[i].skb = NULL;
|
||||||
|
@ -185,7 +184,7 @@ static void ag71xx_ring_rx_clean(struct ag71xx *ag)
|
||||||
if (!ring->buf)
|
if (!ring->buf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < AG71XX_RX_RING_SIZE; i++)
|
for (i = 0; i < ring->size; i++)
|
||||||
if (ring->buf[i].skb) {
|
if (ring->buf[i].skb) {
|
||||||
dma_unmap_single(&ag->dev->dev, ring->buf[i].dma_addr,
|
dma_unmap_single(&ag->dev->dev, ring->buf[i].dma_addr,
|
||||||
AG71XX_RX_PKT_SIZE, DMA_FROM_DEVICE);
|
AG71XX_RX_PKT_SIZE, DMA_FROM_DEVICE);
|
||||||
|
@ -219,16 +218,16 @@ static int ag71xx_ring_rx_init(struct ag71xx *ag)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = 0;
|
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->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",
|
DBG("ag71xx: RX desc at %p, next is %08x\n",
|
||||||
ring->buf[i].desc,
|
ring->buf[i].desc,
|
||||||
ring->buf[i].desc->next);
|
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;
|
struct sk_buff *skb;
|
||||||
dma_addr_t dma_addr;
|
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++) {
|
for (; ring->curr - ring->dirty > 0; ring->dirty++) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
i = ring->dirty % AG71XX_RX_RING_SIZE;
|
i = ring->dirty % ring->size;
|
||||||
|
|
||||||
if (ring->buf[i].skb == NULL) {
|
if (ring->buf[i].skb == NULL) {
|
||||||
dma_addr_t dma_addr;
|
dma_addr_t dma_addr;
|
||||||
|
@ -307,13 +306,13 @@ static int ag71xx_rings_init(struct ag71xx *ag)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = ag71xx_ring_alloc(&ag->tx_ring, AG71XX_TX_RING_SIZE);
|
ret = ag71xx_ring_alloc(&ag->tx_ring);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ag71xx_ring_tx_init(ag);
|
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)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -631,7 +630,7 @@ static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb,
|
||||||
dma_addr_t dma_addr;
|
dma_addr_t dma_addr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = ring->curr % AG71XX_TX_RING_SIZE;
|
i = ring->curr % ring->size;
|
||||||
desc = ring->buf[i].desc;
|
desc = ring->buf[i].desc;
|
||||||
|
|
||||||
if (!ag71xx_desc_empty(desc))
|
if (!ag71xx_desc_empty(desc))
|
||||||
|
@ -659,7 +658,7 @@ static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb,
|
||||||
wmb();
|
wmb();
|
||||||
|
|
||||||
ring->curr++;
|
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);
|
DBG("%s: tx queue full\n", ag->dev->name);
|
||||||
netif_stop_queue(dev);
|
netif_stop_queue(dev);
|
||||||
}
|
}
|
||||||
|
@ -760,7 +759,7 @@ static int ag71xx_tx_packets(struct ag71xx *ag)
|
||||||
|
|
||||||
sent = 0;
|
sent = 0;
|
||||||
while (ring->dirty != ring->curr) {
|
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 ag71xx_desc *desc = ring->buf[i].desc;
|
||||||
struct sk_buff *skb = ring->buf[i].skb;
|
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);
|
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);
|
netif_wake_queue(ag->dev);
|
||||||
|
|
||||||
return sent;
|
return sent;
|
||||||
|
@ -797,7 +796,7 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
|
||||||
dev->name, limit, ring->curr, ring->dirty);
|
dev->name, limit, ring->curr, ring->dirty);
|
||||||
|
|
||||||
while (done < limit) {
|
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 ag71xx_desc *desc = ring->buf[i].desc;
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
int pktlen;
|
int pktlen;
|
||||||
|
@ -806,7 +805,7 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
|
||||||
if (ag71xx_desc_empty(desc))
|
if (ag71xx_desc_empty(desc))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ((ring->dirty + AG71XX_RX_RING_SIZE) == ring->curr) {
|
if ((ring->dirty + ring->size) == ring->curr) {
|
||||||
ag71xx_assert(0);
|
ag71xx_assert(0);
|
||||||
break;
|
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);
|
ag71xx_debugfs_update_napi_stats(ag, rx_done, tx_done);
|
||||||
|
|
||||||
rx_ring = &ag->rx_ring;
|
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;
|
goto oom;
|
||||||
|
|
||||||
status = ag71xx_rr(ag, AG71XX_REG_RX_STATUS);
|
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.data = (unsigned long) dev;
|
||||||
ag->oom_timer.function = ag71xx_oom_timer_handler;
|
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);
|
memcpy(dev->dev_addr, pdata->mac_addr, ETH_ALEN);
|
||||||
|
|
||||||
netif_napi_add(dev, &ag->napi, ag71xx_poll, AG71XX_NAPI_WEIGHT);
|
netif_napi_add(dev, &ag->napi, ag71xx_poll, AG71XX_NAPI_WEIGHT);
|
||||||
|
|
Loading…
Reference in a new issue