| From 06c6ad7b99c07aedc5403506c91cbb8e11cf95df Mon Sep 17 00:00:00 2001 |
| From: Bo Jiao <Bo.Jiao@mediatek.com> |
| Date: Mon, 6 Feb 2023 13:37:23 +0800 |
| Subject: [PATCH 2000/2008] wifi: mt76: rework wed rx flow |
| |
| Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com> |
| Change-Id: Icd787345c811cb5ad30d9c7c1c5f9e5298bd3be6 |
| --- |
| dma.c | 89 +++++++++++++++++++++++++------------------------ |
| mac80211.c | 2 +- |
| mt76.h | 23 ++++++++----- |
| mt7915/dma.c | 2 -- |
| mt7915/mmio.c | 27 +++++++++++---- |
| mt7915/mt7915.h | 1 + |
| tx.c | 16 ++++----- |
| 7 files changed, 90 insertions(+), 70 deletions(-) |
| |
| diff --git a/dma.c b/dma.c |
| index e1e9062b..35db73b9 100644 |
| --- a/dma.c |
| +++ b/dma.c |
| @@ -59,17 +59,17 @@ mt76_alloc_txwi(struct mt76_dev *dev) |
| return t; |
| } |
| |
| -static struct mt76_txwi_cache * |
| +static struct mt76_rxwi_cache * |
| mt76_alloc_rxwi(struct mt76_dev *dev) |
| { |
| - struct mt76_txwi_cache *t; |
| + struct mt76_rxwi_cache *r; |
| |
| - t = kzalloc(L1_CACHE_ALIGN(sizeof(*t)), GFP_ATOMIC); |
| - if (!t) |
| + r = kzalloc(L1_CACHE_ALIGN(sizeof(*r)), GFP_ATOMIC); |
| + if (!r) |
| return NULL; |
| |
| - t->ptr = NULL; |
| - return t; |
| + r->ptr = NULL; |
| + return r; |
| } |
| |
| static struct mt76_txwi_cache * |
| @@ -88,20 +88,20 @@ __mt76_get_txwi(struct mt76_dev *dev) |
| return t; |
| } |
| |
| -static struct mt76_txwi_cache * |
| +static struct mt76_rxwi_cache * |
| __mt76_get_rxwi(struct mt76_dev *dev) |
| { |
| - struct mt76_txwi_cache *t = NULL; |
| + struct mt76_rxwi_cache *r = NULL; |
| |
| - spin_lock(&dev->wed_lock); |
| + spin_lock(&dev->lock); |
| if (!list_empty(&dev->rxwi_cache)) { |
| - t = list_first_entry(&dev->rxwi_cache, struct mt76_txwi_cache, |
| + r = list_first_entry(&dev->rxwi_cache, struct mt76_rxwi_cache, |
| list); |
| - list_del(&t->list); |
| + list_del(&r->list); |
| } |
| - spin_unlock(&dev->wed_lock); |
| + spin_unlock(&dev->lock); |
| |
| - return t; |
| + return r; |
| } |
| |
| static struct mt76_txwi_cache * |
| @@ -115,13 +115,13 @@ mt76_get_txwi(struct mt76_dev *dev) |
| return mt76_alloc_txwi(dev); |
| } |
| |
| -struct mt76_txwi_cache * |
| +struct mt76_rxwi_cache * |
| mt76_get_rxwi(struct mt76_dev *dev) |
| { |
| - struct mt76_txwi_cache *t = __mt76_get_rxwi(dev); |
| + struct mt76_rxwi_cache *r = __mt76_get_rxwi(dev); |
| |
| - if (t) |
| - return t; |
| + if (r) |
| + return r; |
| |
| return mt76_alloc_rxwi(dev); |
| } |
| @@ -140,14 +140,14 @@ mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t) |
| EXPORT_SYMBOL_GPL(mt76_put_txwi); |
| |
| void |
| -mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *t) |
| +mt76_put_rxwi(struct mt76_dev *dev, struct mt76_rxwi_cache *r) |
| { |
| - if (!t) |
| + if (!r) |
| return; |
| |
| - spin_lock(&dev->wed_lock); |
| - list_add(&t->list, &dev->rxwi_cache); |
| - spin_unlock(&dev->wed_lock); |
| + spin_lock(&dev->lock); |
| + list_add(&r->list, &dev->rxwi_cache); |
| + spin_unlock(&dev->lock); |
| } |
| EXPORT_SYMBOL_GPL(mt76_put_rxwi); |
| |
| @@ -168,13 +168,13 @@ mt76_free_pending_txwi(struct mt76_dev *dev) |
| void |
| mt76_free_pending_rxwi(struct mt76_dev *dev) |
| { |
| - struct mt76_txwi_cache *t; |
| + struct mt76_rxwi_cache *r; |
| |
| local_bh_disable(); |
| - while ((t = __mt76_get_rxwi(dev)) != NULL) { |
| - if (t->ptr) |
| - mt76_put_page_pool_buf(t->ptr, false); |
| - kfree(t); |
| + while ((r = __mt76_get_rxwi(dev)) != NULL) { |
| + if (r->ptr) |
| + mt76_put_page_pool_buf(r->ptr, false); |
| + kfree(r); |
| } |
| local_bh_enable(); |
| } |
| @@ -212,7 +212,7 @@ mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q, |
| { |
| struct mt76_desc *desc = &q->desc[q->head]; |
| struct mt76_queue_entry *entry = &q->entry[q->head]; |
| - struct mt76_txwi_cache *txwi = NULL; |
| + struct mt76_rxwi_cache *rxwi = NULL; |
| u32 buf1 = 0, ctrl; |
| int idx = q->head; |
| int rx_token; |
| @@ -220,13 +220,13 @@ mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q, |
| ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len); |
| |
| if (mt76_queue_is_wed_rx(q)) { |
| - txwi = mt76_get_rxwi(dev); |
| - if (!txwi) |
| + rxwi = mt76_get_rxwi(dev); |
| + if (!rxwi) |
| return -ENOMEM; |
| |
| - rx_token = mt76_rx_token_consume(dev, data, txwi, buf->addr); |
| + rx_token = mt76_rx_token_consume(dev, data, rxwi, buf->addr); |
| if (rx_token < 0) { |
| - mt76_put_rxwi(dev, txwi); |
| + mt76_put_rxwi(dev, rxwi); |
| return -ENOMEM; |
| } |
| |
| @@ -241,7 +241,7 @@ mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q, |
| |
| entry->dma_addr[0] = buf->addr; |
| entry->dma_len[0] = buf->len; |
| - entry->txwi = txwi; |
| + entry->rxwi = rxwi; |
| entry->buf = data; |
| entry->wcid = 0xffff; |
| entry->skip_buf1 = true; |
| @@ -404,20 +404,20 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx, |
| if (mt76_queue_is_wed_rx(q)) { |
| u32 buf1 = le32_to_cpu(desc->buf1); |
| u32 token = FIELD_GET(MT_DMA_CTL_TOKEN, buf1); |
| - struct mt76_txwi_cache *t = mt76_rx_token_release(dev, token); |
| + struct mt76_rxwi_cache *r = mt76_rx_token_release(dev, token); |
| |
| - if (!t) |
| + if (!r) |
| return NULL; |
| |
| - dma_sync_single_for_cpu(dev->dma_dev, t->dma_addr, |
| + dma_sync_single_for_cpu(dev->dma_dev, r->dma_addr, |
| SKB_WITH_OVERHEAD(q->buf_size), |
| page_pool_get_dma_dir(q->page_pool)); |
| |
| - buf = t->ptr; |
| - t->dma_addr = 0; |
| - t->ptr = NULL; |
| + buf = r->ptr; |
| + r->dma_addr = 0; |
| + r->ptr = NULL; |
| |
| - mt76_put_rxwi(dev, t); |
| + mt76_put_rxwi(dev, r); |
| |
| if (drop) { |
| u32 ctrl = le32_to_cpu(READ_ONCE(desc->ctrl)); |
| @@ -977,16 +977,19 @@ void mt76_dma_cleanup(struct mt76_dev *dev) |
| mt76_for_each_q_rx(dev, i) { |
| struct mt76_queue *q = &dev->q_rx[i]; |
| |
| + if (mt76_queue_is_wed_rx(q)) |
| + continue; |
| + |
| netif_napi_del(&dev->napi[i]); |
| mt76_dma_rx_cleanup(dev, q); |
| |
| page_pool_destroy(q->page_pool); |
| } |
| |
| - mt76_free_pending_txwi(dev); |
| - mt76_free_pending_rxwi(dev); |
| - |
| if (mtk_wed_device_active(&dev->mmio.wed)) |
| mtk_wed_device_detach(&dev->mmio.wed); |
| + |
| + mt76_free_pending_txwi(dev); |
| + mt76_free_pending_rxwi(dev); |
| } |
| EXPORT_SYMBOL_GPL(mt76_dma_cleanup); |
| diff --git a/mac80211.c b/mac80211.c |
| index 6430e6ee..5a203d31 100644 |
| --- a/mac80211.c |
| +++ b/mac80211.c |
| @@ -613,7 +613,6 @@ mt76_alloc_device(struct device *pdev, unsigned int size, |
| spin_lock_init(&dev->lock); |
| spin_lock_init(&dev->cc_lock); |
| spin_lock_init(&dev->status_lock); |
| - spin_lock_init(&dev->wed_lock); |
| mutex_init(&dev->mutex); |
| init_waitqueue_head(&dev->tx_wait); |
| |
| @@ -644,6 +643,7 @@ mt76_alloc_device(struct device *pdev, unsigned int size, |
| INIT_LIST_HEAD(&dev->txwi_cache); |
| INIT_LIST_HEAD(&dev->rxwi_cache); |
| dev->token_size = dev->drv->token_size; |
| + dev->rx_token_size = dev->drv->rx_token_size; |
| |
| for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++) |
| skb_queue_head_init(&dev->rx_skb[i]); |
| diff --git a/mt76.h b/mt76.h |
| index 8abb6f41..72c3eb8f 100644 |
| --- a/mt76.h |
| +++ b/mt76.h |
| @@ -180,6 +180,7 @@ struct mt76_queue_entry { |
| }; |
| union { |
| struct mt76_txwi_cache *txwi; |
| + struct mt76_rxwi_cache *rxwi; |
| struct urb *urb; |
| int buf_sz; |
| }; |
| @@ -371,10 +372,14 @@ struct mt76_txwi_cache { |
| struct list_head list; |
| dma_addr_t dma_addr; |
| |
| - union { |
| - struct sk_buff *skb; |
| - void *ptr; |
| - }; |
| + struct sk_buff *skb; |
| +}; |
| + |
| +struct mt76_rxwi_cache { |
| + struct list_head list; |
| + dma_addr_t dma_addr; |
| + |
| + void *ptr; |
| }; |
| |
| struct mt76_rx_tid { |
| @@ -460,6 +465,7 @@ struct mt76_driver_ops { |
| u16 txwi_size; |
| u16 token_size; |
| u8 mcs_rates; |
| + u16 rx_token_size; |
| |
| void (*update_survey)(struct mt76_phy *phy); |
| |
| @@ -810,7 +816,6 @@ struct mt76_dev { |
| |
| struct ieee80211_hw *hw; |
| |
| - spinlock_t wed_lock; |
| spinlock_t lock; |
| spinlock_t cc_lock; |
| |
| @@ -1360,8 +1365,8 @@ mt76_tx_status_get_hw(struct mt76_dev *dev, struct sk_buff *skb) |
| } |
| |
| void mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t); |
| -void mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *t); |
| -struct mt76_txwi_cache *mt76_get_rxwi(struct mt76_dev *dev); |
| +void mt76_put_rxwi(struct mt76_dev *dev, struct mt76_rxwi_cache *r); |
| +struct mt76_rxwi_cache *mt76_get_rxwi(struct mt76_dev *dev); |
| void mt76_free_pending_rxwi(struct mt76_dev *dev); |
| void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames, |
| struct napi_struct *napi); |
| @@ -1515,9 +1520,9 @@ struct mt76_txwi_cache * |
| mt76_token_release(struct mt76_dev *dev, int token, bool *wake); |
| int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi); |
| void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked); |
| -struct mt76_txwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token); |
| +struct mt76_rxwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token); |
| int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr, |
| - struct mt76_txwi_cache *r, dma_addr_t phys); |
| + struct mt76_rxwi_cache *r, dma_addr_t phys); |
| int mt76_create_page_pool(struct mt76_dev *dev, struct mt76_queue *q); |
| static inline void mt76_put_page_pool_buf(void *buf, bool allow_direct) |
| { |
| diff --git a/mt7915/dma.c b/mt7915/dma.c |
| index 86a93ded..848e9843 100644 |
| --- a/mt7915/dma.c |
| +++ b/mt7915/dma.c |
| @@ -493,7 +493,6 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
| mtk_wed_get_rx_capa(&mdev->mmio.wed)) { |
| dev->mt76.q_rx[MT_RXQ_MAIN].flags = |
| MT_WED_Q_RX(MT7915_RXQ_BAND0); |
| - dev->mt76.rx_token_size += MT7915_RX_RING_SIZE; |
| } |
| |
| ret = mt76_queue_alloc(dev, &dev->mt76.q_rx[MT_RXQ_MAIN], |
| @@ -530,7 +529,6 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2) |
| mtk_wed_get_rx_capa(&mdev->mmio.wed)) { |
| dev->mt76.q_rx[MT_RXQ_BAND1].flags = |
| MT_WED_Q_RX(MT7915_RXQ_BAND1); |
| - dev->mt76.rx_token_size += MT7915_RX_RING_SIZE; |
| } |
| |
| /* rx data queue for band1 */ |
| diff --git a/mt7915/mmio.c b/mt7915/mmio.c |
| index 984b5f60..46256842 100644 |
| --- a/mt7915/mmio.c |
| +++ b/mt7915/mmio.c |
| @@ -600,16 +600,28 @@ static void mt7915_mmio_wed_release_rx_buf(struct mtk_wed_device *wed) |
| |
| dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| for (i = 0; i < dev->mt76.rx_token_size; i++) { |
| - struct mt76_txwi_cache *t; |
| + struct mt76_rxwi_cache *r; |
| |
| - t = mt76_rx_token_release(&dev->mt76, i); |
| - if (!t || !t->ptr) |
| + r = mt76_rx_token_release(&dev->mt76, i); |
| + if (!r || !r->ptr) |
| continue; |
| |
| - mt76_put_page_pool_buf(t->ptr, false); |
| - t->ptr = NULL; |
| + mt76_put_page_pool_buf(r->ptr, false); |
| + r->ptr = NULL; |
| |
| - mt76_put_rxwi(&dev->mt76, t); |
| + mt76_put_rxwi(&dev->mt76, r); |
| + } |
| + |
| + mt76_for_each_q_rx(dev, i) { |
| + struct mt76_queue *q = &dev->q_rx[i]; |
| + |
| + if (!mt76_queue_is_wed_rx(q)) |
| + continue; |
| + |
| + netif_napi_del(&dev->napi[i]); |
| + mt76_dma_rx_cleanup(dev, q); |
| + |
| + page_pool_destroy(q->page_pool); |
| } |
| |
| mt76_free_pending_rxwi(&dev->mt76); |
| @@ -812,7 +824,7 @@ int mt7915_mmio_wed_init(struct mt7915_dev *dev, void *pdev_ptr, |
| wed->wlan.reset = mt7915_mmio_wed_reset; |
| wed->wlan.reset_complete = mt7915_mmio_wed_reset_complete; |
| |
| - dev->mt76.rx_token_size = wed->wlan.rx_npkt; |
| + dev->mt76.rx_token_size += wed->wlan.rx_npkt; |
| |
| if (mtk_wed_device_attach(wed)) |
| return 0; |
| @@ -1018,6 +1030,7 @@ struct mt7915_dev *mt7915_mmio_probe(struct device *pdev, |
| SURVEY_INFO_TIME_RX | |
| SURVEY_INFO_TIME_BSS_RX, |
| .token_size = MT7915_TOKEN_SIZE, |
| + .rx_token_size = MT7915_RX_TOKEN_SIZE; |
| .tx_prepare_skb = mt7915_tx_prepare_skb, |
| .tx_complete_skb = mt76_connac_tx_complete_skb, |
| .rx_skb = mt7915_queue_rx_skb, |
| diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| index 103cd0d7..8ee62f63 100644 |
| --- a/mt7915/mt7915.h |
| +++ b/mt7915/mt7915.h |
| @@ -62,6 +62,7 @@ |
| #define MT7915_EEPROM_BLOCK_SIZE 16 |
| #define MT7915_HW_TOKEN_SIZE 4096 |
| #define MT7915_TOKEN_SIZE 8192 |
| +#define MT7915_RX_TOKEN_SIZE 4096 |
| |
| #define MT7915_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */ |
| #define MT7915_CFEND_RATE_11B 0x03 /* 11B LP, 11M */ |
| diff --git a/tx.c b/tx.c |
| index 72b3ec71..6cb71f34 100644 |
| --- a/tx.c |
| +++ b/tx.c |
| @@ -761,16 +761,16 @@ int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi) |
| EXPORT_SYMBOL_GPL(mt76_token_consume); |
| |
| int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr, |
| - struct mt76_txwi_cache *t, dma_addr_t phys) |
| + struct mt76_rxwi_cache *r, dma_addr_t phys) |
| { |
| int token; |
| |
| spin_lock_bh(&dev->rx_token_lock); |
| - token = idr_alloc(&dev->rx_token, t, 0, dev->rx_token_size, |
| + token = idr_alloc(&dev->rx_token, r, 0, dev->rx_token_size, |
| GFP_ATOMIC); |
| if (token >= 0) { |
| - t->ptr = ptr; |
| - t->dma_addr = phys; |
| + r->ptr = ptr; |
| + r->dma_addr = phys; |
| } |
| spin_unlock_bh(&dev->rx_token_lock); |
| |
| @@ -807,15 +807,15 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake) |
| } |
| EXPORT_SYMBOL_GPL(mt76_token_release); |
| |
| -struct mt76_txwi_cache * |
| +struct mt76_rxwi_cache * |
| mt76_rx_token_release(struct mt76_dev *dev, int token) |
| { |
| - struct mt76_txwi_cache *t; |
| + struct mt76_rxwi_cache *r; |
| |
| spin_lock_bh(&dev->rx_token_lock); |
| - t = idr_remove(&dev->rx_token, token); |
| + r = idr_remove(&dev->rx_token, token); |
| spin_unlock_bh(&dev->rx_token_lock); |
| |
| - return t; |
| + return r; |
| } |
| EXPORT_SYMBOL_GPL(mt76_rx_token_release); |
| -- |
| 2.39.2 |
| |