developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame^] | 1 | From 0e3c9337e58e45f3e2ec3a00692dedc994c1bac8 Mon Sep 17 00:00:00 2001 |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 2 | From: Evelyn Tsai <evelyn.tsai@mediatek.com> |
| 3 | Date: Sun, 4 Feb 2024 17:52:44 +0800 |
developer | a20cdc2 | 2024-05-31 18:57:31 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 2008/2015] wifi: mt76: connac: wed: add wed rx copy skb |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com> |
| 7 | --- |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 8 | dma.c | 71 +++++++++++++++++++++++++++++++++++++++++++++-------------- |
| 9 | wed.c | 37 ++++++++++++++++++++++--------- |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 10 | 2 files changed, 80 insertions(+), 28 deletions(-) |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 11 | |
| 12 | diff --git a/dma.c b/dma.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 13 | index 9cd97d2..d17fc88 100644 |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 14 | --- a/dma.c |
| 15 | +++ b/dma.c |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 16 | @@ -225,10 +225,10 @@ void mt76_dma_queue_reset(struct mt76_dev *dev, struct mt76_queue *q) |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 17 | |
| 18 | static int |
| 19 | mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q, |
| 20 | - struct mt76_queue_buf *buf, void *data) |
| 21 | + struct mt76_queue_buf *buf, void *data, |
| 22 | + struct mt76_rxwi_cache *rxwi) |
| 23 | { |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 24 | struct mt76_queue_entry *entry = &q->entry[q->head]; |
| 25 | - struct mt76_rxwi_cache *rxwi = NULL; |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 26 | struct mt76_desc *desc; |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 27 | int idx = q->head; |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 28 | u32 buf1 = 0, ctrl; |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 29 | @@ -249,9 +249,11 @@ mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q, |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 30 | #endif |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 31 | |
| 32 | if (mt76_queue_is_wed_rx(q)) { |
| 33 | - rxwi = mt76_get_rxwi(dev); |
| 34 | - if (!rxwi) |
| 35 | - return -ENOMEM; |
| 36 | + if (!rxwi) { |
| 37 | + rxwi = mt76_get_rxwi(dev); |
| 38 | + if (!rxwi) |
| 39 | + return -ENOMEM; |
| 40 | + } |
| 41 | |
| 42 | rx_token = mt76_rx_token_consume(dev, data, rxwi, buf->addr); |
| 43 | if (rx_token < 0) { |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 44 | @@ -421,7 +423,7 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, struct mt76_queue *q, bool flush) |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 45 | |
| 46 | static void * |
| 47 | mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx, |
| 48 | - int *len, u32 *info, bool *more, bool *drop) |
| 49 | + int *len, u32 *info, bool *more, bool *drop, bool flush) |
| 50 | { |
| 51 | struct mt76_queue_entry *e = &q->entry[idx]; |
| 52 | struct mt76_desc *desc = &q->desc[idx]; |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 53 | @@ -478,11 +480,44 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx, |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 54 | SKB_WITH_OVERHEAD(q->buf_size), |
| 55 | DMA_FROM_DEVICE); |
| 56 | |
| 57 | - buf = r->ptr; |
| 58 | - r->dma_addr = 0; |
| 59 | - r->ptr = NULL; |
| 60 | + if (flush) { |
| 61 | + buf = r->ptr; |
| 62 | + r->dma_addr = 0; |
| 63 | + r->ptr = NULL; |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 64 | + |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 65 | + mt76_put_rxwi(dev, r); |
| 66 | + } else { |
| 67 | + struct mt76_queue_buf qbuf; |
| 68 | + |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 69 | + buf = page_frag_alloc(&q->rx_page, q->buf_size, GFP_ATOMIC | GFP_DMA32); |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 70 | + if (!buf) |
| 71 | + return NULL; |
| 72 | + |
| 73 | + memcpy(buf, r->ptr, SKB_WITH_OVERHEAD(q->buf_size)); |
| 74 | + |
| 75 | + r->dma_addr = dma_map_single(dev->dma_dev, r->ptr, |
| 76 | + SKB_WITH_OVERHEAD(q->buf_size), |
| 77 | + DMA_FROM_DEVICE); |
| 78 | + if (unlikely(dma_mapping_error(dev->dma_dev, r->dma_addr))) { |
| 79 | + skb_free_frag(r->ptr); |
| 80 | + mt76_put_rxwi(dev, r); |
| 81 | + return NULL; |
| 82 | + } |
| 83 | + |
| 84 | + qbuf.addr = r->dma_addr; |
| 85 | + qbuf.len = SKB_WITH_OVERHEAD(q->buf_size); |
| 86 | + qbuf.skip_unmap = false; |
| 87 | + |
| 88 | + if (mt76_dma_add_rx_buf(dev, q, &qbuf, r->ptr, r) < 0) { |
| 89 | + dma_unmap_single(dev->dma_dev, r->dma_addr, |
| 90 | + SKB_WITH_OVERHEAD(q->buf_size), |
| 91 | + DMA_FROM_DEVICE); |
| 92 | + skb_free_frag(r->ptr); |
| 93 | + mt76_put_rxwi(dev, r); |
| 94 | + return NULL; |
| 95 | + } |
| 96 | + } |
| 97 | |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 98 | - mt76_put_rxwi(dev, r); |
| 99 | if (drop) |
| 100 | *drop |= !!(buf1 & MT_DMA_CTL_WO_DROP); |
| 101 | } else { |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 102 | @@ -519,7 +554,7 @@ mt76_dma_dequeue(struct mt76_dev *dev, struct mt76_queue *q, bool flush, |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 103 | q->tail = (q->tail + 1) % q->ndesc; |
| 104 | q->queued--; |
| 105 | |
| 106 | - return mt76_dma_get_buf(dev, q, idx, len, info, more, drop); |
| 107 | + return mt76_dma_get_buf(dev, q, idx, len, info, more, drop, flush); |
| 108 | } |
| 109 | |
| 110 | static int |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 111 | @@ -690,7 +725,7 @@ int mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q) |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 112 | done: |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 113 | qbuf.len = len - offset; |
| 114 | qbuf.skip_unmap = false; |
| 115 | - if (mt76_dma_add_rx_buf(dev, q, &qbuf, buf) < 0) { |
| 116 | + if (mt76_dma_add_rx_buf(dev, q, &qbuf, buf, NULL) < 0) { |
| 117 | dma_unmap_single(dev->dma_dev, addr, len, |
| 118 | DMA_FROM_DEVICE); |
| 119 | skb_free_frag(buf); |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 120 | @@ -791,12 +826,14 @@ mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q) |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 121 | |
| 122 | spin_unlock_bh(&q->lock); |
| 123 | |
| 124 | - if (!q->rx_page.va) |
| 125 | - return; |
| 126 | + if (FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) != MT76_WED_Q_RX) { |
| 127 | + if (!q->rx_page.va) |
| 128 | + return; |
| 129 | |
| 130 | - page = virt_to_page(q->rx_page.va); |
| 131 | - __page_frag_cache_drain(page, q->rx_page.pagecnt_bias); |
| 132 | - memset(&q->rx_page, 0, sizeof(q->rx_page)); |
| 133 | + page = virt_to_page(q->rx_page.va); |
| 134 | + __page_frag_cache_drain(page, q->rx_page.pagecnt_bias); |
| 135 | + memset(&q->rx_page, 0, sizeof(q->rx_page)); |
| 136 | + } |
| 137 | } |
| 138 | |
| 139 | static void |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 140 | diff --git a/wed.c b/wed.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 141 | index c03b52f..70e4057 100644 |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 142 | --- a/wed.c |
| 143 | +++ b/wed.c |
| 144 | @@ -9,12 +9,9 @@ |
| 145 | void mt76_wed_release_rx_buf(struct mtk_wed_device *wed) |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 146 | { |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 147 | struct mt76_dev *dev = container_of(wed, struct mt76_dev, mmio.wed); |
| 148 | - u32 length; |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 149 | + struct page *page; |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 150 | int i; |
| 151 | |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 152 | - length = SKB_DATA_ALIGN(NET_SKB_PAD + wed->wlan.rx_size + |
| 153 | - sizeof(struct skb_shared_info)); |
| 154 | - |
| 155 | for (i = 0; i < dev->rx_token_size; i++) { |
| 156 | struct mt76_rxwi_cache *r; |
| 157 | |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 158 | @@ -24,13 +21,33 @@ void mt76_wed_release_rx_buf(struct mtk_wed_device *wed) |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 159 | |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 160 | dma_unmap_single(dev->dma_dev, r->dma_addr, |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 161 | wed->wlan.rx_size, DMA_FROM_DEVICE); |
| 162 | - __free_pages(virt_to_page(r->ptr), get_order(length)); |
| 163 | + skb_free_frag(r->ptr); |
| 164 | r->ptr = NULL; |
| 165 | |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 166 | mt76_put_rxwi(dev, r); |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 167 | } |
| 168 | |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 169 | mt76_free_pending_rxwi(dev); |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 170 | + |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 171 | + mt76_for_each_q_rx(dev, i) { |
| 172 | + struct mt76_queue *q = &dev->q_rx[i]; |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 173 | + |
| 174 | + if (mt76_queue_is_wed_rx(q)) { |
| 175 | + if (!q->rx_page.va) |
| 176 | + continue; |
| 177 | + |
| 178 | + page = virt_to_page(q->rx_page.va); |
| 179 | + __page_frag_cache_drain(page, q->rx_page.pagecnt_bias); |
| 180 | + memset(&q->rx_page, 0, sizeof(q->rx_page)); |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + if (!wed->rx_buf_ring.rx_page.va) |
| 185 | + return; |
| 186 | + |
| 187 | + page = virt_to_page(wed->rx_buf_ring.rx_page.va); |
| 188 | + __page_frag_cache_drain(page, wed->rx_buf_ring.rx_page.pagecnt_bias); |
| 189 | + memset(&wed->rx_buf_ring.rx_page, 0, sizeof(wed->rx_buf_ring.rx_page)); |
| 190 | } |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 191 | EXPORT_SYMBOL_GPL(mt76_wed_release_rx_buf); |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 192 | |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 193 | @@ -48,25 +65,23 @@ u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size) |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 194 | for (i = 0; i < size; i++) { |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 195 | struct mt76_rxwi_cache *r = mt76_get_rxwi(dev); |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 196 | dma_addr_t phy_addr; |
| 197 | - struct page *page; |
| 198 | int token; |
| 199 | void *ptr; |
| 200 | |
| 201 | if (!r) |
| 202 | goto unmap; |
| 203 | |
| 204 | - page = __dev_alloc_pages(GFP_KERNEL, get_order(length)); |
| 205 | - if (!page) { |
| 206 | + ptr = page_frag_alloc(&wed->rx_buf_ring.rx_page, length, GFP_ATOMIC); |
| 207 | + if (!ptr) { |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 208 | mt76_put_rxwi(dev, r); |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 209 | goto unmap; |
| 210 | } |
| 211 | |
| 212 | - ptr = page_address(page); |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 213 | phy_addr = dma_map_single(dev->dma_dev, ptr, |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 214 | wed->wlan.rx_size, |
| 215 | DMA_TO_DEVICE); |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 216 | if (unlikely(dma_mapping_error(dev->dev, phy_addr))) { |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 217 | - __free_pages(page, get_order(length)); |
| 218 | + skb_free_frag(ptr); |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 219 | mt76_put_rxwi(dev, r); |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 220 | goto unmap; |
| 221 | } |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 222 | @@ -76,7 +91,7 @@ u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size) |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 223 | if (token < 0) { |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 224 | dma_unmap_single(dev->dma_dev, phy_addr, |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 225 | wed->wlan.rx_size, DMA_TO_DEVICE); |
| 226 | - __free_pages(page, get_order(length)); |
| 227 | + skb_free_frag(ptr); |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 228 | mt76_put_rxwi(dev, r); |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 229 | goto unmap; |
| 230 | } |
| 231 | -- |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 232 | 2.18.0 |
developer | da18a74 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 233 | |