1 // SPDX-License-Identifier: ISC
3 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
6 #include <linux/dma-mapping.h>
10 #if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
12 #define Q_READ(_dev, _q, _field) ({ \
13 u32 _offset = offsetof(struct mt76_queue_regs, _field); \
15 if ((_q)->flags & MT_QFLAG_WED) \
16 _val = mtk_wed_device_reg_read(&(_dev)->mmio.wed, \
20 _val = readl(&(_q)->regs->_field); \
24 #define Q_WRITE(_dev, _q, _field, _val) do { \
25 u32 _offset = offsetof(struct mt76_queue_regs, _field); \
26 if ((_q)->flags & MT_QFLAG_WED) \
27 mtk_wed_device_reg_write(&(_dev)->mmio.wed, \
28 ((_q)->wed_regs + _offset), \
31 writel(_val, &(_q)->regs->_field); \
36 #define Q_READ(_dev, _q, _field) readl(&(_q)->regs->_field)
37 #define Q_WRITE(_dev, _q, _field, _val) writel(_val, &(_q)->regs->_field)
41 static struct mt76_txwi_cache *
42 mt76_alloc_txwi(struct mt76_dev *dev)
44 struct mt76_txwi_cache *t;
49 size = L1_CACHE_ALIGN(dev->drv->txwi_size + sizeof(*t));
50 txwi = kzalloc(size, GFP_ATOMIC);
54 addr = dma_map_single(dev->dma_dev, txwi, dev->drv->txwi_size,
56 t = (struct mt76_txwi_cache *)(txwi + dev->drv->txwi_size);
62 static struct mt76_txwi_cache *
63 mt76_alloc_rxwi(struct mt76_dev *dev)
65 struct mt76_txwi_cache *t;
67 t = kzalloc(L1_CACHE_ALIGN(sizeof(*t)), GFP_ATOMIC);
75 static struct mt76_txwi_cache *
76 __mt76_get_txwi(struct mt76_dev *dev)
78 struct mt76_txwi_cache *t = NULL;
80 spin_lock(&dev->lock);
81 if (!list_empty(&dev->txwi_cache)) {
82 t = list_first_entry(&dev->txwi_cache, struct mt76_txwi_cache,
86 spin_unlock(&dev->lock);
91 static struct mt76_txwi_cache *
92 __mt76_get_rxwi(struct mt76_dev *dev)
94 struct mt76_txwi_cache *t = NULL;
96 spin_lock_bh(&dev->wed_lock);
97 if (!list_empty(&dev->rxwi_cache)) {
98 t = list_first_entry(&dev->rxwi_cache, struct mt76_txwi_cache,
102 spin_unlock_bh(&dev->wed_lock);
107 static struct mt76_txwi_cache *
108 mt76_get_txwi(struct mt76_dev *dev)
110 struct mt76_txwi_cache *t = __mt76_get_txwi(dev);
115 return mt76_alloc_txwi(dev);
118 struct mt76_txwi_cache *
119 mt76_get_rxwi(struct mt76_dev *dev)
121 struct mt76_txwi_cache *t = __mt76_get_rxwi(dev);
126 return mt76_alloc_rxwi(dev);
128 EXPORT_SYMBOL_GPL(mt76_get_rxwi);
131 mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t)
136 spin_lock(&dev->lock);
137 list_add(&t->list, &dev->txwi_cache);
138 spin_unlock(&dev->lock);
140 EXPORT_SYMBOL_GPL(mt76_put_txwi);
143 mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *t)
148 spin_lock_bh(&dev->wed_lock);
149 list_add(&t->list, &dev->rxwi_cache);
150 spin_unlock_bh(&dev->wed_lock);
152 EXPORT_SYMBOL_GPL(mt76_put_rxwi);
155 mt76_free_pending_txwi(struct mt76_dev *dev)
157 struct mt76_txwi_cache *t;
160 while ((t = __mt76_get_txwi(dev)) != NULL) {
161 dma_unmap_single(dev->dma_dev, t->dma_addr, dev->drv->txwi_size,
163 kfree(mt76_get_txwi_ptr(dev, t));
169 mt76_free_pending_rxwi(struct mt76_dev *dev)
171 struct mt76_txwi_cache *t;
174 while ((t = __mt76_get_rxwi(dev)) != NULL) {
176 mt76_put_page_pool_buf(t->ptr, false);
181 EXPORT_SYMBOL_GPL(mt76_free_pending_rxwi);
184 mt76_dma_sync_idx(struct mt76_dev *dev, struct mt76_queue *q)
186 Q_WRITE(dev, q, desc_base, q->desc_dma);
187 Q_WRITE(dev, q, ring_size, q->ndesc);
188 q->head = Q_READ(dev, q, dma_idx);
193 mt76_dma_queue_reset(struct mt76_dev *dev, struct mt76_queue *q)
200 /* clear descriptors */
201 for (i = 0; i < q->ndesc; i++)
202 q->desc[i].ctrl = cpu_to_le32(MT_DMA_CTL_DMA_DONE);
204 Q_WRITE(dev, q, cpu_idx, 0);
205 Q_WRITE(dev, q, dma_idx, 0);
206 mt76_dma_sync_idx(dev, q);
210 mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q,
211 struct mt76_queue_buf *buf, void *data)
213 struct mt76_desc *desc = &q->desc[q->head];
214 struct mt76_queue_entry *entry = &q->entry[q->head];
215 struct mt76_txwi_cache *txwi = NULL;
220 ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len);
222 if (mt76_queue_is_wed_rx(q)) {
223 txwi = mt76_get_rxwi(dev);
227 rx_token = mt76_rx_token_consume(dev, data, txwi, buf->addr);
229 mt76_put_rxwi(dev, txwi);
233 buf1 |= FIELD_PREP(MT_DMA_CTL_TOKEN, rx_token);
234 ctrl |= MT_DMA_CTL_TO_HOST;
237 WRITE_ONCE(desc->buf0, cpu_to_le32(buf->addr));
238 WRITE_ONCE(desc->buf1, cpu_to_le32(buf1));
239 WRITE_ONCE(desc->ctrl, cpu_to_le32(ctrl));
240 WRITE_ONCE(desc->info, 0);
242 entry->dma_addr[0] = buf->addr;
243 entry->dma_len[0] = buf->len;
246 entry->wcid = 0xffff;
247 entry->skip_buf1 = true;
248 q->head = (q->head + 1) % q->ndesc;
255 mt76_dma_add_buf(struct mt76_dev *dev, struct mt76_queue *q,
256 struct mt76_queue_buf *buf, int nbufs, u32 info,
257 struct sk_buff *skb, void *txwi)
259 struct mt76_queue_entry *entry;
260 struct mt76_desc *desc;
265 q->entry[q->head].txwi = DMA_DUMMY_DATA;
266 q->entry[q->head].skip_buf0 = true;
269 for (i = 0; i < nbufs; i += 2, buf += 2) {
270 u32 buf0 = buf[0].addr, buf1 = 0;
273 next = (q->head + 1) % q->ndesc;
275 desc = &q->desc[idx];
276 entry = &q->entry[idx];
278 if (buf[0].skip_unmap)
279 entry->skip_buf0 = true;
280 entry->skip_buf1 = i == nbufs - 1;
282 entry->dma_addr[0] = buf[0].addr;
283 entry->dma_len[0] = buf[0].len;
285 ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len);
287 entry->dma_addr[1] = buf[1].addr;
288 entry->dma_len[1] = buf[1].len;
290 ctrl |= FIELD_PREP(MT_DMA_CTL_SD_LEN1, buf[1].len);
291 if (buf[1].skip_unmap)
292 entry->skip_buf1 = true;
296 ctrl |= MT_DMA_CTL_LAST_SEC0;
297 else if (i == nbufs - 2)
298 ctrl |= MT_DMA_CTL_LAST_SEC1;
300 WRITE_ONCE(desc->buf0, cpu_to_le32(buf0));
301 WRITE_ONCE(desc->buf1, cpu_to_le32(buf1));
302 WRITE_ONCE(desc->info, cpu_to_le32(info));
303 WRITE_ONCE(desc->ctrl, cpu_to_le32(ctrl));
309 q->entry[idx].txwi = txwi;
310 q->entry[idx].skb = skb;
311 q->entry[idx].wcid = 0xffff;
317 mt76_dma_tx_cleanup_idx(struct mt76_dev *dev, struct mt76_queue *q, int idx,
318 struct mt76_queue_entry *prev_e)
320 struct mt76_queue_entry *e = &q->entry[idx];
323 dma_unmap_single(dev->dma_dev, e->dma_addr[0], e->dma_len[0],
327 dma_unmap_single(dev->dma_dev, e->dma_addr[1], e->dma_len[1],
330 if (e->txwi == DMA_DUMMY_DATA)
333 if (e->skb == DMA_DUMMY_DATA)
337 memset(e, 0, sizeof(*e));
341 mt76_dma_kick_queue(struct mt76_dev *dev, struct mt76_queue *q)
344 Q_WRITE(dev, q, cpu_idx, q->head);
348 mt76_dma_tx_cleanup(struct mt76_dev *dev, struct mt76_queue *q, bool flush)
350 struct mt76_queue_entry entry;
356 spin_lock_bh(&q->cleanup_lock);
360 last = Q_READ(dev, q, dma_idx);
362 while (q->queued > 0 && q->tail != last) {
363 mt76_dma_tx_cleanup_idx(dev, q, q->tail, &entry);
364 mt76_queue_tx_complete(dev, q, &entry);
367 if (!(dev->drv->drv_flags & MT_DRV_TXWI_NO_FREE))
368 mt76_put_txwi(dev, entry.txwi);
371 if (!flush && q->tail == last)
372 last = Q_READ(dev, q, dma_idx);
374 spin_unlock_bh(&q->cleanup_lock);
377 spin_lock_bh(&q->lock);
378 mt76_dma_sync_idx(dev, q);
379 mt76_dma_kick_queue(dev, q);
380 spin_unlock_bh(&q->lock);
384 wake_up(&dev->tx_wait);
388 mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx,
389 int *len, u32 *info, bool *more, bool *drop)
391 struct mt76_queue_entry *e = &q->entry[idx];
392 struct mt76_desc *desc = &q->desc[idx];
396 u32 ctrl = le32_to_cpu(READ_ONCE(desc->ctrl));
397 *len = FIELD_GET(MT_DMA_CTL_SD_LEN0, ctrl);
398 *more = !(ctrl & MT_DMA_CTL_LAST_SEC0);
402 *info = le32_to_cpu(desc->info);
404 if (mt76_queue_is_wed_rx(q)) {
405 u32 buf1 = le32_to_cpu(desc->buf1);
406 u32 token = FIELD_GET(MT_DMA_CTL_TOKEN, buf1);
407 struct mt76_txwi_cache *t = mt76_rx_token_release(dev, token);
412 dma_sync_single_for_cpu(dev->dma_dev, t->dma_addr,
413 SKB_WITH_OVERHEAD(q->buf_size),
414 page_pool_get_dma_dir(q->page_pool));
420 mt76_put_rxwi(dev, t);
423 u32 ctrl = le32_to_cpu(READ_ONCE(desc->ctrl));
425 *drop = !!(ctrl & (MT_DMA_CTL_TO_HOST_A |
428 *drop |= !!(buf1 & MT_DMA_CTL_WO_DROP);
433 dma_sync_single_for_cpu(dev->dma_dev, e->dma_addr[0],
434 SKB_WITH_OVERHEAD(q->buf_size),
435 page_pool_get_dma_dir(q->page_pool));
442 mt76_dma_dequeue(struct mt76_dev *dev, struct mt76_queue *q, bool flush,
443 int *len, u32 *info, bool *more, bool *drop)
452 q->desc[idx].ctrl |= cpu_to_le32(MT_DMA_CTL_DMA_DONE);
453 else if (!(q->desc[idx].ctrl & cpu_to_le32(MT_DMA_CTL_DMA_DONE)))
456 q->tail = (q->tail + 1) % q->ndesc;
459 return mt76_dma_get_buf(dev, q, idx, len, info, more, drop);
463 mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q,
464 struct sk_buff *skb, u32 tx_info)
466 struct mt76_queue_buf buf = {};
469 if (test_bit(MT76_MCU_RESET, &dev->phy.state))
472 if (q->queued + 1 >= q->ndesc - 1)
475 addr = dma_map_single(dev->dma_dev, skb->data, skb->len,
477 if (unlikely(dma_mapping_error(dev->dma_dev, addr)))
483 spin_lock_bh(&q->lock);
484 mt76_dma_add_buf(dev, q, &buf, 1, tx_info, skb, NULL);
485 mt76_dma_kick_queue(dev, q);
486 spin_unlock_bh(&q->lock);
496 mt76_dma_tx_queue_skb(struct mt76_dev *dev, struct mt76_queue *q,
497 enum mt76_txq_id qid, struct sk_buff *skb,
498 struct mt76_wcid *wcid, struct ieee80211_sta *sta)
500 struct ieee80211_tx_status status = {
503 struct mt76_tx_info tx_info = {
506 struct ieee80211_hw *hw;
507 int len, n = 0, ret = -ENOMEM;
508 struct mt76_txwi_cache *t;
509 struct sk_buff *iter;
513 if (test_bit(MT76_RESET, &dev->phy.state))
516 t = mt76_get_txwi(dev);
520 txwi = mt76_get_txwi_ptr(dev, t);
522 skb->prev = skb->next = NULL;
523 if (dev->drv->drv_flags & MT_DRV_TX_ALIGNED4_SKBS)
524 mt76_insert_hdr_pad(skb);
526 len = skb_headlen(skb);
527 addr = dma_map_single(dev->dma_dev, skb->data, len, DMA_TO_DEVICE);
528 if (unlikely(dma_mapping_error(dev->dma_dev, addr)))
531 tx_info.buf[n].addr = t->dma_addr;
532 tx_info.buf[n++].len = dev->drv->txwi_size;
533 tx_info.buf[n].addr = addr;
534 tx_info.buf[n++].len = len;
536 skb_walk_frags(skb, iter) {
537 if (n == ARRAY_SIZE(tx_info.buf))
540 addr = dma_map_single(dev->dma_dev, iter->data, iter->len,
542 if (unlikely(dma_mapping_error(dev->dma_dev, addr)))
545 tx_info.buf[n].addr = addr;
546 tx_info.buf[n++].len = iter->len;
550 if (q->queued + (tx_info.nbuf + 1) / 2 >= q->ndesc - 1) {
555 dma_sync_single_for_cpu(dev->dma_dev, t->dma_addr, dev->drv->txwi_size,
557 ret = dev->drv->tx_prepare_skb(dev, txwi, qid, wcid, sta, &tx_info);
558 dma_sync_single_for_device(dev->dma_dev, t->dma_addr, dev->drv->txwi_size,
563 return mt76_dma_add_buf(dev, q, tx_info.buf, tx_info.nbuf,
564 tx_info.info, tx_info.skb, t);
567 for (n--; n > 0; n--)
568 dma_unmap_single(dev->dma_dev, tx_info.buf[n].addr,
569 tx_info.buf[n].len, DMA_TO_DEVICE);
572 #ifdef CONFIG_NL80211_TESTMODE
573 /* fix tx_done accounting on queue overflow */
574 if (mt76_is_testmode_skb(dev, skb, &hw)) {
575 struct mt76_phy *phy = hw->priv;
577 if (tx_info.skb == phy->test.tx_skb)
582 mt76_put_txwi(dev, t);
585 status.skb = tx_info.skb;
586 hw = mt76_tx_status_get_hw(dev, tx_info.skb);
587 spin_lock_bh(&dev->rx_lock);
588 ieee80211_tx_status_ext(hw, &status);
589 spin_unlock_bh(&dev->rx_lock);
595 mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q,
598 int len = SKB_WITH_OVERHEAD(q->buf_size);
604 spin_lock_bh(&q->lock);
606 while (q->queued < q->ndesc - 1) {
607 enum dma_data_direction dir;
608 struct mt76_queue_buf qbuf;
613 buf = mt76_get_page_pool_buf(q, &offset, q->buf_size);
617 addr = page_pool_get_dma_addr(virt_to_head_page(buf)) + offset;
618 dir = page_pool_get_dma_dir(q->page_pool);
619 dma_sync_single_for_device(dev->dma_dev, addr, len, dir);
621 qbuf.addr = addr + q->buf_offset;
622 qbuf.len = len - q->buf_offset;
623 qbuf.skip_unmap = false;
624 if (mt76_dma_add_rx_buf(dev, q, &qbuf, buf) < 0) {
625 mt76_put_page_pool_buf(buf, allow_direct);
632 mt76_dma_kick_queue(dev, q);
634 spin_unlock_bh(&q->lock);
639 int mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset)
641 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
642 struct mtk_wed_device *wed = &dev->mmio.wed;
650 if (!mtk_wed_device_active(wed))
651 q->flags &= ~MT_QFLAG_WED;
653 if (!(q->flags & MT_QFLAG_WED))
656 type = FIELD_GET(MT_QFLAG_WED_TYPE, q->flags);
657 ring = FIELD_GET(MT_QFLAG_WED_RING, q->flags);
661 ret = mtk_wed_device_tx_ring_setup(wed, ring, q->regs, reset);
663 q->wed_regs = wed->tx_ring[ring].reg_base;
665 case MT76_WED_Q_TXFREE:
666 /* WED txfree queue needs ring to be initialized before setup */
668 mt76_dma_queue_reset(dev, q);
669 mt76_dma_rx_fill(dev, q, false);
672 ret = mtk_wed_device_txfree_ring_setup(wed, q->regs);
674 q->wed_regs = wed->txfree_ring.reg_base;
677 ret = mtk_wed_device_rx_ring_setup(wed, ring, q->regs, reset);
679 q->wed_regs = wed->rx_ring[ring].reg_base;
690 EXPORT_SYMBOL_GPL(mt76_dma_wed_setup);
693 mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q,
694 int idx, int n_desc, int bufsize,
699 spin_lock_init(&q->lock);
700 spin_lock_init(&q->cleanup_lock);
702 q->regs = dev->mmio.regs + ring_base + idx * MT_RING_SIZE;
704 q->buf_size = bufsize;
707 size = q->ndesc * sizeof(struct mt76_desc);
708 q->desc = dmam_alloc_coherent(dev->dma_dev, size, &q->desc_dma, GFP_KERNEL);
712 size = q->ndesc * sizeof(*q->entry);
713 q->entry = devm_kzalloc(dev->dev, size, GFP_KERNEL);
717 ret = mt76_create_page_pool(dev, q);
721 ret = mt76_dma_wed_setup(dev, q, false);
725 if (q->flags != MT_WED_Q_TXFREE)
726 mt76_dma_queue_reset(dev, q);
732 mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q)
740 spin_lock_bh(&q->lock);
743 buf = mt76_dma_dequeue(dev, q, true, NULL, NULL, &more, NULL);
747 mt76_put_page_pool_buf(buf, false);
751 dev_kfree_skb(q->rx_head);
755 spin_unlock_bh(&q->lock);
759 mt76_dma_rx_reset(struct mt76_dev *dev, enum mt76_rxq_id qid)
761 struct mt76_queue *q = &dev->q_rx[qid];
767 for (i = 0; i < q->ndesc; i++)
768 q->desc[i].ctrl = cpu_to_le32(MT_DMA_CTL_DMA_DONE);
770 mt76_dma_rx_cleanup(dev, q);
772 /* reset WED rx queues */
773 mt76_dma_wed_setup(dev, q, true);
774 if (q->flags != MT_WED_Q_TXFREE) {
775 mt76_dma_sync_idx(dev, q);
776 mt76_dma_rx_fill(dev, q, false);
781 mt76_add_fragment(struct mt76_dev *dev, struct mt76_queue *q, void *data,
782 int len, bool more, u32 info)
784 struct sk_buff *skb = q->rx_head;
785 struct skb_shared_info *shinfo = skb_shinfo(skb);
786 int nr_frags = shinfo->nr_frags;
788 if (nr_frags < ARRAY_SIZE(shinfo->frags)) {
789 struct page *page = virt_to_head_page(data);
790 int offset = data - page_address(page) + q->buf_offset;
792 skb_add_rx_frag(skb, nr_frags, page, offset, len, q->buf_size);
794 mt76_put_page_pool_buf(data, true);
801 if (nr_frags < ARRAY_SIZE(shinfo->frags))
802 dev->drv->rx_skb(dev, q - dev->q_rx, skb, &info);
808 mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget)
810 int len, data_len, done = 0, dma_idx;
813 bool check_ddone = false;
816 if (IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED) &&
817 q->flags == MT_WED_Q_TXFREE) {
818 dma_idx = Q_READ(dev, q, dma_idx);
822 while (done < budget) {
827 if (q->tail == dma_idx)
828 dma_idx = Q_READ(dev, q, dma_idx);
830 if (q->tail == dma_idx)
834 data = mt76_dma_dequeue(dev, q, false, &len, &info, &more,
843 data_len = q->buf_size;
845 data_len = SKB_WITH_OVERHEAD(q->buf_size);
847 if (data_len < len + q->buf_offset) {
848 dev_kfree_skb(q->rx_head);
854 mt76_add_fragment(dev, q, data, len, more, info);
858 if (!more && dev->drv->rx_check &&
859 !(dev->drv->rx_check(dev, data, len)))
862 skb = napi_build_skb(data, q->buf_size);
866 skb_reserve(skb, q->buf_offset);
867 skb_mark_for_recycle(skb);
869 *(u32 *)skb->cb = info;
879 dev->drv->rx_skb(dev, q - dev->q_rx, skb, &info);
883 mt76_put_page_pool_buf(data, true);
886 mt76_dma_rx_fill(dev, q, true);
890 int mt76_dma_rx_poll(struct napi_struct *napi, int budget)
892 struct mt76_dev *dev;
893 int qid, done = 0, cur;
895 dev = container_of(napi->dev, struct mt76_dev, napi_dev);
896 qid = napi - dev->napi;
901 cur = mt76_dma_rx_process(dev, &dev->q_rx[qid], budget - done);
902 mt76_rx_poll_complete(dev, qid, napi);
904 } while (cur && done < budget);
908 if (done < budget && napi_complete(napi))
909 dev->drv->rx_poll_complete(dev, qid);
913 EXPORT_SYMBOL_GPL(mt76_dma_rx_poll);
916 mt76_dma_init(struct mt76_dev *dev,
917 int (*poll)(struct napi_struct *napi, int budget))
921 init_dummy_netdev(&dev->napi_dev);
922 init_dummy_netdev(&dev->tx_napi_dev);
923 snprintf(dev->napi_dev.name, sizeof(dev->napi_dev.name), "%s",
924 wiphy_name(dev->hw->wiphy));
925 dev->napi_dev.threaded = 1;
926 init_completion(&dev->mmio.wed_reset);
927 init_completion(&dev->mmio.wed_reset_complete);
929 mt76_for_each_q_rx(dev, i) {
930 netif_napi_add(&dev->napi_dev, &dev->napi[i], poll);
931 mt76_dma_rx_fill(dev, &dev->q_rx[i], false);
932 napi_enable(&dev->napi[i]);
938 static const struct mt76_queue_ops mt76_dma_ops = {
939 .init = mt76_dma_init,
940 .alloc = mt76_dma_alloc_queue,
941 .reset_q = mt76_dma_queue_reset,
942 .tx_queue_skb_raw = mt76_dma_tx_queue_skb_raw,
943 .tx_queue_skb = mt76_dma_tx_queue_skb,
944 .tx_cleanup = mt76_dma_tx_cleanup,
945 .rx_cleanup = mt76_dma_rx_cleanup,
946 .rx_reset = mt76_dma_rx_reset,
947 .kick = mt76_dma_kick_queue,
950 void mt76_dma_attach(struct mt76_dev *dev)
952 dev->queue_ops = &mt76_dma_ops;
954 EXPORT_SYMBOL_GPL(mt76_dma_attach);
956 void mt76_dma_cleanup(struct mt76_dev *dev)
960 mt76_worker_disable(&dev->tx_worker);
961 netif_napi_del(&dev->tx_napi);
963 for (i = 0; i < ARRAY_SIZE(dev->phys); i++) {
964 struct mt76_phy *phy = dev->phys[i];
970 for (j = 0; j < ARRAY_SIZE(phy->q_tx); j++)
971 mt76_dma_tx_cleanup(dev, phy->q_tx[j], true);
974 for (i = 0; i < ARRAY_SIZE(dev->q_mcu); i++)
975 mt76_dma_tx_cleanup(dev, dev->q_mcu[i], true);
977 mt76_for_each_q_rx(dev, i) {
978 struct mt76_queue *q = &dev->q_rx[i];
980 netif_napi_del(&dev->napi[i]);
981 mt76_dma_rx_cleanup(dev, q);
983 page_pool_destroy(q->page_pool);
986 mt76_free_pending_txwi(dev);
987 mt76_free_pending_rxwi(dev);
989 if (mtk_wed_device_active(&dev->mmio.wed))
990 mtk_wed_device_detach(&dev->mmio.wed);
992 EXPORT_SYMBOL_GPL(mt76_dma_cleanup);