summaryrefslogtreecommitdiff
path: root/drivers/net/wireless/mediatek/mt76/sdio.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/mediatek/mt76/sdio.c')
-rw-r--r--drivers/net/wireless/mediatek/mt76/sdio.c196
1 files changed, 108 insertions, 88 deletions
diff --git a/drivers/net/wireless/mediatek/mt76/sdio.c b/drivers/net/wireless/mediatek/mt76/sdio.c
index 9a4d95a2a707..62b5b912818f 100644
--- a/drivers/net/wireless/mediatek/mt76/sdio.c
+++ b/drivers/net/wireless/mediatek/mt76/sdio.c
@@ -36,46 +36,49 @@ mt76s_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid)
return 0;
}
-static int mt76s_alloc_tx(struct mt76_dev *dev)
+static struct mt76_queue *mt76s_alloc_tx_queue(struct mt76_dev *dev)
{
struct mt76_queue *q;
- int i;
-
- for (i = 0; i < MT_TXQ_MCU_WA; i++) {
- q = devm_kzalloc(dev->dev, sizeof(*q), GFP_KERNEL);
- if (!q)
- return -ENOMEM;
- spin_lock_init(&q->lock);
- q->hw_idx = i;
- dev->q_tx[i] = q;
+ q = devm_kzalloc(dev->dev, sizeof(*q), GFP_KERNEL);
+ if (!q)
+ return ERR_PTR(-ENOMEM);
- q->entry = devm_kcalloc(dev->dev,
- MT_NUM_TX_ENTRIES, sizeof(*q->entry),
- GFP_KERNEL);
- if (!q->entry)
- return -ENOMEM;
+ spin_lock_init(&q->lock);
+ q->entry = devm_kcalloc(dev->dev,
+ MT_NUM_TX_ENTRIES, sizeof(*q->entry),
+ GFP_KERNEL);
+ if (!q->entry)
+ return ERR_PTR(-ENOMEM);
- q->ndesc = MT_NUM_TX_ENTRIES;
- }
+ q->ndesc = MT_NUM_TX_ENTRIES;
- return 0;
+ return q;
}
-void mt76s_stop_txrx(struct mt76_dev *dev)
+static int mt76s_alloc_tx(struct mt76_dev *dev)
{
- struct mt76_sdio *sdio = &dev->sdio;
+ struct mt76_queue *q;
+ int i;
- cancel_work_sync(&sdio->tx.xmit_work);
- cancel_work_sync(&sdio->tx.status_work);
- cancel_work_sync(&sdio->rx.recv_work);
- cancel_work_sync(&sdio->rx.net_work);
- cancel_work_sync(&sdio->stat_work);
- clear_bit(MT76_READING_STATS, &dev->phy.state);
+ for (i = 0; i <= MT_TXQ_PSD; i++) {
+ q = mt76s_alloc_tx_queue(dev);
+ if (IS_ERR(q))
+ return PTR_ERR(q);
- mt76_tx_status_check(dev, NULL, true);
+ q->qid = i;
+ dev->phy.q_tx[i] = q;
+ }
+
+ q = mt76s_alloc_tx_queue(dev);
+ if (IS_ERR(q))
+ return PTR_ERR(q);
+
+ q->qid = MT_MCUQ_WM;
+ dev->q_mcu[MT_MCUQ_WM] = q;
+
+ return 0;
}
-EXPORT_SYMBOL_GPL(mt76s_stop_txrx);
int mt76s_alloc_queues(struct mt76_dev *dev)
{
@@ -131,11 +134,32 @@ mt76s_process_rx_queue(struct mt76_dev *dev, struct mt76_queue *q)
return nframes;
}
-static void mt76s_process_tx_queue(struct mt76_dev *dev, enum mt76_txq_id qid)
+static void mt76s_net_worker(struct mt76_worker *w)
+{
+ struct mt76_sdio *sdio = container_of(w, struct mt76_sdio,
+ net_worker);
+ struct mt76_dev *dev = container_of(sdio, struct mt76_dev, sdio);
+ int i, nframes;
+
+ do {
+ nframes = 0;
+
+ local_bh_disable();
+ rcu_read_lock();
+
+ mt76_for_each_q_rx(dev, i)
+ nframes += mt76s_process_rx_queue(dev, &dev->q_rx[i]);
+
+ rcu_read_unlock();
+ local_bh_enable();
+ } while (nframes > 0);
+}
+
+static int mt76s_process_tx_queue(struct mt76_dev *dev, struct mt76_queue *q)
{
- struct mt76_queue *q = dev->q_tx[qid];
+ bool wake, mcu = q == dev->q_mcu[MT_MCUQ_WM];
struct mt76_queue_entry entry;
- bool wake;
+ int nframes = 0;
while (q->queued > 0) {
if (!q->entry[q->tail].done)
@@ -144,12 +168,13 @@ static void mt76s_process_tx_queue(struct mt76_dev *dev, enum mt76_txq_id qid)
entry = q->entry[q->tail];
q->entry[q->tail].done = false;
- if (qid == MT_TXQ_MCU) {
+ if (mcu) {
dev_kfree_skb(entry.skb);
entry.skb = NULL;
}
mt76_queue_tx_complete(dev, q, &entry);
+ nframes++;
}
wake = q->stopped && q->queued < q->ndesc - 8;
@@ -159,13 +184,35 @@ static void mt76s_process_tx_queue(struct mt76_dev *dev, enum mt76_txq_id qid)
if (!q->queued)
wake_up(&dev->tx_wait);
- if (qid == MT_TXQ_MCU)
- return;
+ if (mcu)
+ goto out;
- mt76_txq_schedule(&dev->phy, qid);
+ mt76_txq_schedule(&dev->phy, q->qid);
if (wake)
- ieee80211_wake_queue(dev->hw, qid);
+ ieee80211_wake_queue(dev->hw, q->qid);
+out:
+ return nframes;
+}
+
+static void mt76s_status_worker(struct mt76_worker *w)
+{
+ struct mt76_sdio *sdio = container_of(w, struct mt76_sdio,
+ status_worker);
+ struct mt76_dev *dev = container_of(sdio, struct mt76_dev, sdio);
+ int i, nframes;
+
+ do {
+ nframes = mt76s_process_tx_queue(dev, dev->q_mcu[MT_MCUQ_WM]);
+
+ for (i = 0; i <= MT_TXQ_PSD; i++)
+ nframes += mt76s_process_tx_queue(dev,
+ dev->phy.q_tx[i]);
+
+ if (dev->drv->tx_status_data &&
+ !test_and_set_bit(MT76_READING_STATS, &dev->phy.state))
+ queue_work(dev->wq, &dev->sdio.stat_work);
+ } while (nframes > 0);
}
static void mt76s_tx_status_data(struct work_struct *work)
@@ -194,11 +241,10 @@ static void mt76s_tx_status_data(struct work_struct *work)
}
static int
-mt76s_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
+mt76s_tx_queue_skb(struct mt76_dev *dev, struct mt76_queue *q,
struct sk_buff *skb, struct mt76_wcid *wcid,
struct ieee80211_sta *sta)
{
- struct mt76_queue *q = dev->q_tx[qid];
struct mt76_tx_info tx_info = {
.skb = skb,
};
@@ -209,7 +255,7 @@ mt76s_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
return -ENOSPC;
skb->prev = skb->next = NULL;
- err = dev->drv->tx_prepare_skb(dev, NULL, qid, wcid, sta, &tx_info);
+ err = dev->drv->tx_prepare_skb(dev, NULL, q->qid, wcid, sta, &tx_info);
if (err < 0)
return err;
@@ -222,10 +268,9 @@ mt76s_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
}
static int
-mt76s_tx_queue_skb_raw(struct mt76_dev *dev, enum mt76_txq_id qid,
+mt76s_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q,
struct sk_buff *skb, u32 tx_info)
{
- struct mt76_queue *q = dev->q_tx[qid];
int ret = -ENOSPC, len = skb->len, pad;
if (q->queued == q->ndesc)
@@ -257,7 +302,7 @@ static void mt76s_tx_kick(struct mt76_dev *dev, struct mt76_queue *q)
{
struct mt76_sdio *sdio = &dev->sdio;
- queue_work(sdio->txrx_wq, &sdio->tx.xmit_work);
+ mt76_worker_schedule(&sdio->txrx_worker);
}
static const struct mt76_queue_ops sdio_queue_ops = {
@@ -266,49 +311,19 @@ static const struct mt76_queue_ops sdio_queue_ops = {
.tx_queue_skb_raw = mt76s_tx_queue_skb_raw,
};
-static void mt76s_tx_work(struct work_struct *work)
-{
- struct mt76_sdio *sdio = container_of(work, struct mt76_sdio,
- tx.status_work);
- struct mt76_dev *dev = container_of(sdio, struct mt76_dev, sdio);
- int i;
-
- for (i = 0; i < MT_TXQ_MCU_WA; i++)
- mt76s_process_tx_queue(dev, i);
-
- if (dev->drv->tx_status_data &&
- !test_and_set_bit(MT76_READING_STATS, &dev->phy.state))
- queue_work(dev->wq, &dev->sdio.stat_work);
-}
-
-static void mt76s_rx_work(struct work_struct *work)
-{
- struct mt76_sdio *sdio = container_of(work, struct mt76_sdio,
- rx.net_work);
- struct mt76_dev *dev = container_of(sdio, struct mt76_dev, sdio);
- int i;
-
- /* rx processing */
- local_bh_disable();
- rcu_read_lock();
-
- mt76_for_each_q_rx(dev, i)
- mt76s_process_rx_queue(dev, &dev->q_rx[i]);
-
- rcu_read_unlock();
- local_bh_enable();
-}
-
void mt76s_deinit(struct mt76_dev *dev)
{
struct mt76_sdio *sdio = &dev->sdio;
int i;
- mt76s_stop_txrx(dev);
- if (sdio->txrx_wq) {
- destroy_workqueue(sdio->txrx_wq);
- sdio->txrx_wq = NULL;
- }
+ mt76_worker_teardown(&sdio->txrx_worker);
+ mt76_worker_teardown(&sdio->status_worker);
+ mt76_worker_teardown(&sdio->net_worker);
+
+ cancel_work_sync(&sdio->stat_work);
+ clear_bit(MT76_READING_STATS, &dev->phy.state);
+
+ mt76_tx_status_check(dev, NULL, true);
sdio_claim_host(sdio->func);
sdio_release_irq(sdio->func);
@@ -335,18 +350,23 @@ int mt76s_init(struct mt76_dev *dev, struct sdio_func *func,
const struct mt76_bus_ops *bus_ops)
{
struct mt76_sdio *sdio = &dev->sdio;
+ int err;
- sdio->txrx_wq = alloc_workqueue("mt76s_txrx_wq",
- WQ_UNBOUND | WQ_HIGHPRI,
- WQ_UNBOUND_MAX_ACTIVE);
- if (!sdio->txrx_wq)
- return -ENOMEM;
+ err = mt76_worker_setup(dev->hw, &sdio->status_worker,
+ mt76s_status_worker, "sdio-status");
+ if (err)
+ return err;
+
+ err = mt76_worker_setup(dev->hw, &sdio->net_worker, mt76s_net_worker,
+ "sdio-net");
+ if (err)
+ return err;
+
+ sched_set_fifo_low(sdio->status_worker.task);
+ sched_set_fifo_low(sdio->net_worker.task);
INIT_WORK(&sdio->stat_work, mt76s_tx_status_data);
- INIT_WORK(&sdio->tx.status_work, mt76s_tx_work);
- INIT_WORK(&sdio->rx.net_work, mt76s_rx_work);
- mutex_init(&sdio->sched.lock);
dev->queue_ops = &sdio_queue_ops;
dev->bus = bus_ops;
dev->sdio.func = func;