mirror of
https://github.com/outbackdingo/mt76.git
synced 2026-10-24 13:26:48 +00:00
199 lines
4.6 KiB
C
199 lines
4.6 KiB
C
/*
|
|
* Copyright (C) 2016 Felix Fietkau <[email protected]>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2
|
|
* as published by the Free Software Foundation
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include "mt7603.h"
|
|
#include "mt7603_mac.h"
|
|
#include "dma.h"
|
|
|
|
int
|
|
mt7603_tx_queue_mcu(struct mt7603_dev *dev, enum mt76_txq_id qid,
|
|
struct sk_buff *skb)
|
|
{
|
|
struct mt76_queue *q = &dev->mt76.q_tx[qid];
|
|
struct mt76_queue_buf buf;
|
|
dma_addr_t addr;
|
|
int idx;
|
|
|
|
addr = dma_map_single(dev->mt76.dev, skb->data, skb->len, DMA_TO_DEVICE);
|
|
if (dma_mapping_error(dev->mt76.dev, addr))
|
|
return -ENOMEM;
|
|
|
|
buf.addr = addr;
|
|
buf.len = skb->len;
|
|
spin_lock_bh(&q->lock);
|
|
idx = mt76_queue_add_buf(dev, q, &buf, 1, 0, skb, NULL);
|
|
mt76_queue_kick(dev, q);
|
|
spin_unlock_bh(&q->lock);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
mt7603_init_tx_queue(struct mt7603_dev *dev, struct mt76_queue *q,
|
|
int idx, int n_desc)
|
|
{
|
|
int ret;
|
|
|
|
q->regs = dev->mt76.regs + MT_TX_RING_BASE + idx * MT_RING_SIZE;
|
|
q->ndesc = n_desc;
|
|
|
|
ret = mt76_queue_alloc(dev, q);
|
|
if (ret)
|
|
return ret;
|
|
|
|
mt7603_irq_enable(dev, MT_INT_TX_DONE(idx));
|
|
|
|
return 0;
|
|
}
|
|
|
|
void mt7603_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
|
|
struct sk_buff *skb)
|
|
{
|
|
struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
|
|
__le32 *rxd = (__le32 *) skb->data;
|
|
__le32 *end = (__le32 *) &skb->data[skb->len];
|
|
enum rx_pkt_type type;
|
|
|
|
type = MT76_GET(MT_RXD0_PKT_TYPE, le32_to_cpu(rxd[0]));
|
|
|
|
switch(type) {
|
|
case PKT_TYPE_TXS:
|
|
for (rxd++; rxd + 5 <= end; rxd += 5)
|
|
mt7603_mac_add_txs(dev, rxd);
|
|
dev_kfree_skb(skb);
|
|
break;
|
|
case PKT_TYPE_RX_EVENT:
|
|
skb_queue_tail(&dev->mcu.res_q, skb);
|
|
wake_up(&dev->mcu.wait);
|
|
return;
|
|
case PKT_TYPE_NORMAL:
|
|
if (mt7603_mac_fill_rx(dev, skb) == 0) {
|
|
mt76_rx(&dev->mt76, q, skb);
|
|
return;
|
|
}
|
|
/* fall through */
|
|
default:
|
|
dev_kfree_skb(skb);
|
|
break;
|
|
}
|
|
}
|
|
|
|
static int
|
|
mt7603_init_rx_queue(struct mt7603_dev *dev, struct mt76_queue *q,
|
|
int idx, int n_desc, int bufsize)
|
|
{
|
|
int ret;
|
|
|
|
q->regs = dev->mt76.regs + MT_RX_RING_BASE + idx * MT_RING_SIZE;
|
|
q->ndesc = n_desc;
|
|
q->buf_size = bufsize;
|
|
|
|
ret = mt76_queue_alloc(dev, q);
|
|
if (ret)
|
|
return ret;
|
|
|
|
mt7603_irq_enable(dev, MT_INT_RX_DONE(idx));
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void
|
|
mt7603_tx_tasklet(unsigned long data)
|
|
{
|
|
struct mt7603_dev *dev = (struct mt7603_dev *) data;
|
|
int i;
|
|
|
|
for (i = MT_TXQ_MCU; i >= 0; i--)
|
|
mt76_queue_tx_cleanup(dev, i, false);
|
|
|
|
mt7603_irq_enable(dev, MT_INT_TX_DONE_ALL);
|
|
}
|
|
|
|
int mt7603_dma_init(struct mt7603_dev *dev)
|
|
{
|
|
static const u8 wmm_queue_map[] = {
|
|
[IEEE80211_AC_BE] = 0,
|
|
[IEEE80211_AC_BK] = 1,
|
|
[IEEE80211_AC_VI] = 2,
|
|
[IEEE80211_AC_VO] = 3,
|
|
};
|
|
int ret;
|
|
int i;
|
|
|
|
mt76_dma_attach(&dev->mt76);
|
|
|
|
init_waitqueue_head(&dev->mcu.wait);
|
|
skb_queue_head_init(&dev->mcu.res_q);
|
|
|
|
tasklet_init(&dev->tx_tasklet, mt7603_tx_tasklet, (unsigned long) dev);
|
|
|
|
mt76_clear(dev, MT_WPDMA_GLO_CFG,
|
|
MT_WPDMA_GLO_CFG_TX_DMA_EN |
|
|
MT_WPDMA_GLO_CFG_RX_DMA_EN |
|
|
MT_WPDMA_GLO_CFG_DMA_BURST_SIZE |
|
|
MT_WPDMA_GLO_CFG_TX_WRITEBACK_DONE);
|
|
|
|
mt76_wr(dev, MT_WPDMA_RST_IDX, ~0);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(wmm_queue_map); i++) {
|
|
ret = mt7603_init_tx_queue(dev, &dev->mt76.q_tx[i], wmm_queue_map[i],
|
|
MT_TX_RING_SIZE);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
|
|
ret = mt7603_init_tx_queue(dev, &dev->mt76.q_tx[MT_TXQ_PSD],
|
|
MT_TX_HW_QUEUE_MGMT, MT_TX_RING_SIZE);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = mt7603_init_tx_queue(dev, &dev->mt76.q_tx[MT_TXQ_MCU],
|
|
MT_TX_HW_QUEUE_MCU, MT_MCU_RING_SIZE);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = mt7603_init_tx_queue(dev, &dev->mt76.q_tx[MT_TXQ_BEACON],
|
|
MT_TX_HW_QUEUE_BCN, MT_MCU_RING_SIZE);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = mt7603_init_tx_queue(dev, &dev->mt76.q_tx[MT_TXQ_CAB],
|
|
MT_TX_HW_QUEUE_BMC, MT_MCU_RING_SIZE);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = mt7603_init_rx_queue(dev, &dev->mt76.q_rx[MT_RXQ_MCU], 1,
|
|
MT_MCU_RING_SIZE, MT_RX_BUF_SIZE);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = mt7603_init_rx_queue(dev, &dev->mt76.q_rx[MT_RXQ_MAIN], 0,
|
|
MT_RX_RING_SIZE, MT_RX_BUF_SIZE);
|
|
if (ret)
|
|
return ret;
|
|
|
|
mt76_wr(dev, MT_DELAY_INT_CFG, 0);
|
|
return mt76_init_queues(dev);
|
|
}
|
|
|
|
void mt7603_dma_cleanup(struct mt7603_dev *dev)
|
|
{
|
|
mt76_clear(dev, MT_WPDMA_GLO_CFG,
|
|
MT_WPDMA_GLO_CFG_TX_DMA_EN |
|
|
MT_WPDMA_GLO_CFG_RX_DMA_EN |
|
|
MT_WPDMA_GLO_CFG_TX_WRITEBACK_DONE);
|
|
|
|
tasklet_kill(&dev->tx_tasklet);
|
|
mt76_dma_cleanup(&dev->mt76);
|
|
}
|