[LEDE-DEV] [PATCH 6/7] ag71xx: Put ring_size in ag71xx_ring struct.
Rosen Penev
rosenp at gmail.com
Thu Dec 7 18:37:16 PST 2017
Less verbose code. Should help when porting some of the other patches.
Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
.../drivers/net/ethernet/atheros/ag71xx/ag71xx.h | 1 +
.../net/ethernet/atheros/ag71xx/ag71xx_main.c | 40 +++++++++-------------
2 files changed, 17 insertions(+), 24 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 9964993..f85e43d 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
@@ -106,6 +106,7 @@ struct ag71xx_ring {
/* "Hot" fields in the data path. */
unsigned int curr;
unsigned int dirty;
+ u16 size;
/* "Cold" fields - not used in the data path. */
struct ag71xx_buf *buf;
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 c1d754f..8ce777c 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
@@ -101,18 +101,15 @@ static inline void ag71xx_dump_intr(struct ag71xx *ag, char *label, u32 intr)
static void ag71xx_ring_free(struct ag71xx_ring *ring)
{
- int ring_size = BIT(ring->order);
kfree(ring->buf);
if (ring->descs_cpu)
- dma_free_coherent(NULL, ring_size * ring->desc_size,
+ dma_free_coherent(NULL, ring->size * ring->desc_size,
ring->descs_cpu, ring->descs_dma);
}
static int ag71xx_ring_alloc(struct ag71xx_ring *ring)
{
- int ring_size = BIT(ring->order);
-
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",
@@ -121,12 +118,12 @@ static int ag71xx_ring_alloc(struct ag71xx_ring *ring)
ring->desc_size = roundup(ring->desc_size, cache_line_size());
}
- ring->descs_cpu = dma_alloc_coherent(NULL, ring_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)
return -ENOMEM;
- ring->buf = kzalloc(ring_size * sizeof(*ring->buf), GFP_KERNEL);
+ ring->buf = kzalloc(ring->size * sizeof(*ring->buf), GFP_KERNEL);
if (!ring->buf)
return -ENOMEM;
@@ -168,15 +165,14 @@ static void ag71xx_ring_tx_clean(struct ag71xx *ag)
static void ag71xx_ring_tx_init(struct ag71xx *ag)
{
struct ag71xx_ring *ring = &ag->tx_ring;
- int ring_size = BIT(ring->order);
- int ring_mask = ring_size - 1;
- int i;
+ int i, next;
- for (i = 0; i < ring_size; i++) {
+ for (i = 0; i < ring->size; i++) {
struct ag71xx_desc *desc = ag71xx_ring_desc(ring, i);
+ next = (i >= ring->size - 1) ? 0 : (i + 1);
desc->next = (u32) (ring->descs_dma +
- ring->desc_size * ((i + 1) & ring_mask));
+ ring->desc_size * next);
desc->ctrl = DESC_EMPTY;
ring->buf[i].skb = NULL;
@@ -193,13 +189,12 @@ static void ag71xx_ring_tx_init(struct ag71xx *ag)
static void ag71xx_ring_rx_clean(struct ag71xx *ag)
{
struct ag71xx_ring *ring = &ag->rx_ring;
- int ring_size = BIT(ring->order);
int i;
if (!ring->buf)
return;
- for (i = 0; i < ring_size; i++)
+ for (i = 0; i < ring->size; i++)
if (ring->buf[i].rx_buf) {
dma_unmap_single(&ag->dev->dev, ring->buf[i].dma_addr,
ag->rx_buf_size, DMA_FROM_DEVICE);
@@ -251,24 +246,24 @@ static bool ag71xx_fill_rx_buf(struct ag71xx *ag, struct ag71xx_buf *buf,
static int ag71xx_ring_rx_init(struct ag71xx *ag)
{
struct ag71xx_ring *ring = &ag->rx_ring;
- int ring_size = BIT(ring->order);
int ring_mask = BIT(ring->order) - 1;
- unsigned int i;
+ unsigned int i, next;
int ret;
int offset = ag71xx_buffer_offset(ag);
ret = 0;
- for (i = 0; i < ring_size; i++) {
+ for (i = 0; i < ring->size; i++) {
struct ag71xx_desc *desc = ag71xx_ring_desc(ring, i);
+ next = (i >= ring->size - 1) ? 0 : (i + 1);
desc->next = (u32) (ring->descs_dma +
- ring->desc_size * ((i + 1) & ring_mask));
+ ring->desc_size * next);
DBG("ag71xx: RX desc at %p, next is %08x\n",
desc, desc->next);
}
- for (i = 0; i < ring_size; i++) {
+ for (i = 0; i < ring->size; i++) {
struct ag71xx_desc *desc = ag71xx_ring_desc(ring, i);
if (!ag71xx_fill_rx_buf(ag, &ring->buf[i], offset,
@@ -790,7 +785,6 @@ static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb,
struct ag71xx *ag = netdev_priv(dev);
struct ag71xx_ring *ring = &ag->tx_ring;
int ring_mask = BIT(ring->order) - 1;
- int ring_size = BIT(ring->order);
struct ag71xx_desc *desc;
dma_addr_t dma_addr;
int i, n, ring_min;
@@ -833,7 +827,7 @@ static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb,
if (ring->desc_split)
ring_min *= AG71XX_TX_RING_DS_PER_PKT;
- if (ring->curr - ring->dirty >= ring_size - ring_min) {
+ if (ring->curr - ring->dirty >= ring->size - ring_min) {
DBG("%s: tx queue full\n", dev->name);
netif_stop_queue(dev);
}
@@ -956,7 +950,6 @@ static int ag71xx_tx_packets(struct ag71xx *ag, bool flush)
struct ag71xx_platform_data *pdata = ag71xx_get_pdata(ag);
bool dma_stuck = false;
int ring_mask = BIT(ring->order) - 1;
- int ring_size = BIT(ring->order);
int sent = 0;
int bytes_compl = 0;
int n = 0;
@@ -1007,7 +1000,7 @@ static int ag71xx_tx_packets(struct ag71xx *ag, bool flush)
return 0;
netdev_completed_queue(ag->dev, sent, bytes_compl);
- if ((ring->curr - ring->dirty) < (ring_size * 3) / 4)
+ if ((ring->curr - ring->dirty) < (ring->size * 3) / 4)
netif_wake_queue(ag->dev);
if (!dma_stuck)
@@ -1023,7 +1016,6 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
int offset = ag71xx_buffer_offset(ag);
unsigned int pktlen_mask = ag->desc_pktlen_mask;
int ring_mask = BIT(ring->order) - 1;
- int ring_size = BIT(ring->order);
struct sk_buff_head queue;
struct sk_buff *skb;
int done = 0;
@@ -1042,7 +1034,7 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
if (ag71xx_desc_empty(desc))
break;
- if ((ring->dirty + ring_size) == ring->curr) {
+ if ((ring->dirty + ring->size) == ring->curr) {
ag71xx_assert(0);
break;
}
--
2.7.4
More information about the Lede-dev
mailing list