Commit b1bfbe70 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: dma: move mt76x02_init_{tx,rx}_queue in mt76 module

Move mt76x02_init_tx_queue and mt76x02_init_rx_queue in mt76
module in order to be reused adding support for mt7603 driver
and remove duplicated code.
Squash mt76x02_init_tx_queue and mt76x02_init_rx_queue in
mt76_dma_alloc_queue
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 9220f695
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
#define DMA_DUMMY_TXWI ((void *) ~0) #define DMA_DUMMY_TXWI ((void *) ~0)
static int static int
mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q) mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q,
int idx, int n_desc, int bufsize,
u32 ring_base)
{ {
int size; int size;
int i; int i;
...@@ -29,6 +31,11 @@ mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q) ...@@ -29,6 +31,11 @@ mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q)
spin_lock_init(&q->lock); spin_lock_init(&q->lock);
INIT_LIST_HEAD(&q->swq); INIT_LIST_HEAD(&q->swq);
q->regs = dev->mmio.regs + ring_base + idx * MT_RING_SIZE;
q->ndesc = n_desc;
q->buf_size = bufsize;
q->hw_idx = idx;
size = q->ndesc * sizeof(struct mt76_desc); size = q->ndesc * sizeof(struct mt76_desc);
q->desc = dmam_alloc_coherent(dev->dev, size, &q->desc_dma, GFP_KERNEL); q->desc = dmam_alloc_coherent(dev->dev, size, &q->desc_dma, GFP_KERNEL);
if (!q->desc) if (!q->desc)
......
...@@ -150,7 +150,9 @@ struct mt76_mcu_ops { ...@@ -150,7 +150,9 @@ struct mt76_mcu_ops {
struct mt76_queue_ops { struct mt76_queue_ops {
int (*init)(struct mt76_dev *dev); int (*init)(struct mt76_dev *dev);
int (*alloc)(struct mt76_dev *dev, struct mt76_queue *q); int (*alloc)(struct mt76_dev *dev, struct mt76_queue *q,
int idx, int n_desc, int bufsize,
u32 ring_base);
int (*add_buf)(struct mt76_dev *dev, struct mt76_queue *q, int (*add_buf)(struct mt76_dev *dev, struct mt76_queue *q,
struct mt76_queue_buf *buf, int nbufs, u32 info, struct mt76_queue_buf *buf, int nbufs, u32 info,
......
...@@ -8,15 +8,12 @@ static int ...@@ -8,15 +8,12 @@ static int
mt7603_init_tx_queue(struct mt7603_dev *dev, struct mt76_queue *q, mt7603_init_tx_queue(struct mt7603_dev *dev, struct mt76_queue *q,
int idx, int n_desc) int idx, int n_desc)
{ {
int ret; int err;
q->hw_idx = idx;
q->regs = dev->mt76.mmio.regs + MT_TX_RING_BASE + idx * MT_RING_SIZE;
q->ndesc = n_desc;
ret = mt76_queue_alloc(dev, q); err = mt76_queue_alloc(dev, q, idx, n_desc, 0,
if (ret) MT_TX_RING_BASE);
return ret; if (err < 0)
return err;
mt7603_irq_enable(dev, MT_INT_TX_DONE(idx)); mt7603_irq_enable(dev, MT_INT_TX_DONE(idx));
...@@ -119,15 +116,12 @@ static int ...@@ -119,15 +116,12 @@ static int
mt7603_init_rx_queue(struct mt7603_dev *dev, struct mt76_queue *q, mt7603_init_rx_queue(struct mt7603_dev *dev, struct mt76_queue *q,
int idx, int n_desc, int bufsize) int idx, int n_desc, int bufsize)
{ {
int ret; int err;
q->regs = dev->mt76.mmio.regs + MT_RX_RING_BASE + idx * MT_RING_SIZE;
q->ndesc = n_desc;
q->buf_size = bufsize;
ret = mt76_queue_alloc(dev, q); err = mt76_queue_alloc(dev, q, idx, n_desc, bufsize,
if (ret) MT_RX_RING_BASE);
return ret; if (err < 0)
return err;
mt7603_irq_enable(dev, MT_INT_RX_DONE(idx)); mt7603_irq_enable(dev, MT_INT_RX_DONE(idx));
......
...@@ -156,15 +156,12 @@ static int ...@@ -156,15 +156,12 @@ static int
mt76x02_init_tx_queue(struct mt76x02_dev *dev, struct mt76_queue *q, mt76x02_init_tx_queue(struct mt76x02_dev *dev, struct mt76_queue *q,
int idx, int n_desc) int idx, int n_desc)
{ {
int ret; int err;
q->regs = dev->mt76.mmio.regs + MT_TX_RING_BASE + idx * MT_RING_SIZE; err = mt76_queue_alloc(dev, q, idx, n_desc, 0,
q->ndesc = n_desc; MT_TX_RING_BASE);
q->hw_idx = idx; if (err < 0)
return err;
ret = mt76_queue_alloc(dev, q);
if (ret)
return ret;
mt76x02_irq_enable(dev, MT_INT_TX_DONE(idx)); mt76x02_irq_enable(dev, MT_INT_TX_DONE(idx));
...@@ -175,15 +172,12 @@ static int ...@@ -175,15 +172,12 @@ static int
mt76x02_init_rx_queue(struct mt76x02_dev *dev, struct mt76_queue *q, mt76x02_init_rx_queue(struct mt76x02_dev *dev, struct mt76_queue *q,
int idx, int n_desc, int bufsize) int idx, int n_desc, int bufsize)
{ {
int ret; int err;
q->regs = dev->mt76.mmio.regs + MT_RX_RING_BASE + idx * MT_RING_SIZE; err = mt76_queue_alloc(dev, q, idx, n_desc, bufsize,
q->ndesc = n_desc; MT_RX_RING_BASE);
q->buf_size = bufsize; if (err < 0)
return err;
ret = mt76_queue_alloc(dev, q);
if (ret)
return ret;
mt76x02_irq_enable(dev, MT_INT_RX_DONE(idx)); mt76x02_irq_enable(dev, MT_INT_RX_DONE(idx));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment