From 09b677d77795a2f594d1e2004c33acf2d2209685 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 6 Dec 2015 23:11:58 +0100 Subject: [PATCH] move rx dma descriptor processing logic to common code Signed-off-by: Felix Fietkau --- dma.c | 40 ++++++++++++++++++++++++++++++++-------- mt76.h | 3 ++- mt76x2_dma.c | 43 ++++++++----------------------------------- 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/dma.c b/dma.c index da9c5bb4..ad2bb940 100644 --- a/dma.c +++ b/dma.c @@ -117,22 +117,46 @@ mt76_dma_cleanup(struct mt76_dev *dev, struct mt76_queue *q, bool flush, } } -static int -mt76_dma_dequeue(struct mt76_dev *dev, struct mt76_queue *q, bool flush) +static void * +mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx, + int *len, u32 *info) { - int ret = -1; + struct mt76_queue_entry *e = &q->entry[idx]; + struct mt76_desc *desc = &q->desc[idx]; + dma_addr_t buf_addr; + void *buf = e->buf; + int buf_len = SKB_WITH_OVERHEAD(q->buf_size); + + buf_addr = ACCESS_ONCE(desc->buf0); + if (len) { + u32 ctl = ACCESS_ONCE(desc->ctrl); + *len = MT76_GET(MT_DMA_CTL_SD_LEN0, ctl); + } + if (info) + *info = le32_to_cpu(desc->info); + + dma_unmap_single(dev->dev, buf_addr, buf_len, DMA_FROM_DEVICE); + e->buf = NULL; + + return buf; +} + +static void * +mt76_dma_dequeue(struct mt76_dev *dev, struct mt76_queue *q, bool flush, + int *len, u32 *info) +{ + int idx = q->tail; if (!q->queued) - return -1; + return NULL; - if (!flush && !(q->desc[q->tail].ctrl & cpu_to_le32(MT_DMA_CTL_DMA_DONE))) - return -1; + if (!flush && !(q->desc[idx].ctrl & cpu_to_le32(MT_DMA_CTL_DMA_DONE))) + return NULL; - ret = q->tail; q->tail = (q->tail + 1) % q->ndesc; q->queued--; - return ret; + return mt76_dma_get_buf(dev, q, idx, len, info); } static void diff --git a/mt76.h b/mt76.h index 6af58626..08dd75fd 100644 --- a/mt76.h +++ b/mt76.h @@ -71,7 +71,8 @@ struct mt76_queue_ops { int (*add_buf)(struct mt76_dev *dev, struct mt76_queue *q, u32 buf0, int len0, u32 buf1, int len1, u32 info); - int (*dequeue)(struct mt76_dev *dev, struct mt76_queue *q, bool flush); + void *(*dequeue)(struct mt76_dev *dev, struct mt76_queue *q, bool flush, + int *len, u32 *info); void (*cleanup)(struct mt76_dev *dev, struct mt76_queue *q, bool flush, void (*done)(struct mt76_dev *dev, struct mt76_queue *q, diff --git a/mt76x2_dma.c b/mt76x2_dma.c index 85df2f0c..8828cc1f 100644 --- a/mt76x2_dma.c +++ b/mt76x2_dma.c @@ -230,44 +230,19 @@ mt76x2_tx_cleanup_entry(struct mt76_dev *mdev, struct mt76_queue *q, q->swq_queued--; } -static void * -mt76x2_rx_get_buf(struct mt76x2_dev *dev, struct mt76_queue *q, int idx, int *len) -{ - struct mt76_queue_entry *e; - dma_addr_t buf_addr; - void *buf; - int buf_len = SKB_WITH_OVERHEAD(q->buf_size); - - e = &q->entry[idx]; - buf = e->buf; - buf_addr = ACCESS_ONCE(q->desc[idx].buf0); - if (len) { - u32 ctl = ACCESS_ONCE(q->desc[idx].ctrl); - *len = MT76_GET(MT_DMA_CTL_SD_LEN0, ctl); - } - dma_unmap_single(dev->mt76.dev, buf_addr, buf_len, DMA_FROM_DEVICE); - e->buf = NULL; - - return buf; -} - static void mt76x2_rx_cleanup(struct mt76x2_dev *dev, struct mt76_queue *q) { void *buf; - int idx; spin_lock_bh(&q->lock); - do { - idx = mt76_queue_dequeue(dev, q, true); - if (idx < 0) + buf = mt76_queue_dequeue(dev, q, true, NULL, NULL); + if (!buf) break; - buf = mt76x2_rx_get_buf(dev, q, idx, NULL); kfree(buf); } while (1); - spin_unlock_bh(&q->lock); } @@ -330,18 +305,18 @@ mt76x2_process_rx_skb(struct mt76x2_dev *dev, struct mt76_queue *q, static int mt76x2_process_rx_queue(struct mt76x2_dev *dev, struct mt76_queue *q, int budget) { - struct mt76_desc *desc; struct sk_buff *skb; unsigned char *data; - int idx, len; + int len; int done = 0; while (done < budget) { - idx = mt76_queue_dequeue(dev, q, false); - if (idx < 0) + u32 info; + + data = mt76_queue_dequeue(dev, q, false, &len, &info); + if (!data) break; - data = mt76x2_rx_get_buf(dev, q, idx, &len); skb = build_skb(data, 0); if (!skb) { kfree(data); @@ -355,9 +330,7 @@ mt76x2_process_rx_queue(struct mt76x2_dev *dev, struct mt76_queue *q, int budget } __skb_put(skb, len); - - desc = &q->desc[idx]; - mt76x2_process_rx_skb(dev, q, skb, le32_to_cpu(desc->info)); + mt76x2_process_rx_skb(dev, q, skb, info); done++; }