developer | f3f5d9b | 2023-02-07 15:24:34 +0800 | [diff] [blame^] | 1 | From 27b1ad3b825b3208c599330f944fc11c120f3d2e Mon Sep 17 00:00:00 2001 |
| 2 | From: Sujuan Chen <sujuan.chen@mediatek.com> |
| 3 | Date: Thu, 5 Jan 2023 16:43:57 +0800 |
| 4 | Subject: [PATCH 3010/3010] mt76: connac: wed: add wed rx copy skb and revert |
| 5 | page_pool |
| 6 | |
| 7 | Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com> |
| 8 | --- |
| 9 | dma.c | 138 ++++++++++++++++++++++++++++++++------------------ |
| 10 | mac80211.c | 57 --------------------- |
| 11 | mt76.h | 22 +------- |
| 12 | mt7915/main.c | 26 ++++------ |
| 13 | mt7915/mmio.c | 77 ++++++++++++++++++++-------- |
| 14 | mt7921/main.c | 31 ++---------- |
| 15 | usb.c | 42 +++++++-------- |
| 16 | 7 files changed, 183 insertions(+), 210 deletions(-) |
| 17 | |
| 18 | diff --git a/dma.c b/dma.c |
| 19 | index 76af6506..79da538c 100644 |
| 20 | --- a/dma.c |
| 21 | +++ b/dma.c |
| 22 | @@ -173,7 +173,7 @@ mt76_free_pending_rxwi(struct mt76_dev *dev) |
| 23 | local_bh_disable(); |
| 24 | while ((r = __mt76_get_rxwi(dev)) != NULL) { |
| 25 | if (r->ptr) |
| 26 | - mt76_put_page_pool_buf(r->ptr, false); |
| 27 | + skb_free_frag(r->ptr); |
| 28 | kfree(r); |
| 29 | } |
| 30 | local_bh_enable(); |
| 31 | @@ -208,11 +208,11 @@ mt76_dma_queue_reset(struct mt76_dev *dev, struct mt76_queue *q) |
| 32 | |
| 33 | static int |
| 34 | mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q, |
| 35 | - struct mt76_queue_buf *buf, void *data) |
| 36 | + struct mt76_queue_buf *buf, void *data, |
| 37 | + struct mt76_rxwi_cache *rxwi) |
| 38 | { |
| 39 | struct mt76_desc *desc = &q->desc[q->head]; |
| 40 | struct mt76_queue_entry *entry = &q->entry[q->head]; |
| 41 | - struct mt76_rxwi_cache *rxwi = NULL; |
| 42 | u32 buf1 = 0, ctrl; |
| 43 | int idx = q->head; |
| 44 | int rx_token; |
| 45 | @@ -220,9 +220,11 @@ mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q, |
| 46 | ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len); |
| 47 | |
| 48 | if (mt76_queue_is_wed_rx(q)) { |
| 49 | - rxwi = mt76_get_rxwi(dev); |
| 50 | - if (!rxwi) |
| 51 | - return -ENOMEM; |
| 52 | + if (!rxwi) { |
| 53 | + rxwi = mt76_get_rxwi(dev); |
| 54 | + if (!rxwi) |
| 55 | + return -ENOMEM; |
| 56 | + } |
| 57 | |
| 58 | rx_token = mt76_rx_token_consume(dev, data, rxwi, buf->addr); |
| 59 | if (rx_token < 0) { |
| 60 | @@ -387,7 +389,7 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, struct mt76_queue *q, bool flush) |
| 61 | |
| 62 | static void * |
| 63 | mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx, |
| 64 | - int *len, u32 *info, bool *more, bool *drop) |
| 65 | + int *len, u32 *info, bool *more, bool *drop, bool flush) |
| 66 | { |
| 67 | struct mt76_queue_entry *e = &q->entry[idx]; |
| 68 | struct mt76_desc *desc = &q->desc[idx]; |
| 69 | @@ -435,15 +437,47 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx, |
| 70 | if (!r) |
| 71 | return NULL; |
| 72 | |
| 73 | - dma_sync_single_for_cpu(dev->dma_dev, r->dma_addr, |
| 74 | - SKB_WITH_OVERHEAD(q->buf_size), |
| 75 | - page_pool_get_dma_dir(q->page_pool)); |
| 76 | + dma_unmap_single(dev->dma_dev, r->dma_addr, |
| 77 | + SKB_WITH_OVERHEAD(q->buf_size), |
| 78 | + DMA_FROM_DEVICE); |
| 79 | |
| 80 | - buf = r->ptr; |
| 81 | - r->dma_addr = 0; |
| 82 | - r->ptr = NULL; |
| 83 | + if (flush) { |
| 84 | + buf = r->ptr; |
| 85 | + r->dma_addr = 0; |
| 86 | + r->ptr = NULL; |
| 87 | |
| 88 | - mt76_put_rxwi(dev, r); |
| 89 | + mt76_put_rxwi(dev, r); |
| 90 | + } else { |
| 91 | + struct mt76_queue_buf qbuf; |
| 92 | + |
| 93 | + buf = page_frag_alloc(&q->rx_page, q->buf_size, GFP_ATOMIC); |
| 94 | + if (!buf) |
| 95 | + return NULL; |
| 96 | + |
| 97 | + memcpy(buf, r->ptr, SKB_WITH_OVERHEAD(q->buf_size)); |
| 98 | + |
| 99 | + r->dma_addr = dma_map_single(dev->dma_dev, r->ptr, |
| 100 | + SKB_WITH_OVERHEAD(q->buf_size), |
| 101 | + DMA_FROM_DEVICE); |
| 102 | + if (unlikely(dma_mapping_error(dev->dma_dev, r->dma_addr))) { |
| 103 | + skb_free_frag(r->ptr); |
| 104 | + mt76_put_rxwi(dev, r); |
| 105 | + return NULL; |
| 106 | + } |
| 107 | + |
| 108 | + qbuf.addr = r->dma_addr; |
| 109 | + qbuf.len = SKB_WITH_OVERHEAD(q->buf_size); |
| 110 | + qbuf.skip_unmap = false; |
| 111 | + |
| 112 | + if (mt76_dma_add_rx_buf(dev, q, &qbuf, r->ptr, r) < 0) { |
| 113 | + dma_unmap_single(dev->dma_dev, r->dma_addr, |
| 114 | + SKB_WITH_OVERHEAD(q->buf_size), |
| 115 | + DMA_FROM_DEVICE); |
| 116 | + skb_free_frag(r->ptr); |
| 117 | + mt76_put_rxwi(dev, r); |
| 118 | + return NULL; |
| 119 | + } |
| 120 | + } |
| 121 | |
| 122 | if (drop) { |
| 123 | u32 ctrl = le32_to_cpu(READ_ONCE(desc->ctrl)); |
| 124 | @@ -463,9 +497,9 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx, |
| 125 | } else { |
| 126 | buf = e->buf; |
| 127 | e->buf = NULL; |
| 128 | - dma_sync_single_for_cpu(dev->dma_dev, e->dma_addr[0], |
| 129 | - SKB_WITH_OVERHEAD(q->buf_size), |
| 130 | - page_pool_get_dma_dir(q->page_pool)); |
| 131 | + dma_unmap_single(dev->dma_dev, e->dma_addr[0], |
| 132 | + SKB_WITH_OVERHEAD(q->buf_size), |
| 133 | + DMA_FROM_DEVICE); |
| 134 | } |
| 135 | |
| 136 | return buf; |
| 137 | @@ -489,7 +523,7 @@ mt76_dma_dequeue(struct mt76_dev *dev, struct mt76_queue *q, bool flush, |
| 138 | q->tail = (q->tail + 1) % q->ndesc; |
| 139 | q->queued--; |
| 140 | |
| 141 | - return mt76_dma_get_buf(dev, q, idx, len, info, more, drop); |
| 142 | + return mt76_dma_get_buf(dev, q, idx, len, info, more, drop, flush); |
| 143 | } |
| 144 | |
| 145 | static int |
| 146 | @@ -616,11 +650,12 @@ free_skb: |
| 147 | } |
| 148 | |
| 149 | static int |
| 150 | -mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q, |
| 151 | - bool allow_direct) |
| 152 | +mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q) |
| 153 | { |
| 154 | int len = SKB_WITH_OVERHEAD(q->buf_size); |
| 155 | - int frames = 0; |
| 156 | + int frames = 0, offset = q->buf_offset; |
| 157 | + dma_addr_t addr; |
| 158 | + bool flags = false; |
| 159 | |
| 160 | if (!q->ndesc) |
| 161 | return 0; |
| 162 | @@ -628,31 +663,35 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q, |
| 163 | spin_lock_bh(&q->lock); |
| 164 | |
| 165 | while (q->queued < q->ndesc - 1) { |
| 166 | - enum dma_data_direction dir; |
| 167 | struct mt76_queue_buf qbuf; |
| 168 | - dma_addr_t addr; |
| 169 | - int offset; |
| 170 | - void *buf; |
| 171 | + void *buf = NULL; |
| 172 | |
| 173 | - buf = mt76_get_page_pool_buf(q, &offset, q->buf_size); |
| 174 | + buf = page_frag_alloc(&q->rx_page, q->buf_size, GFP_ATOMIC); |
| 175 | if (!buf) |
| 176 | break; |
| 177 | |
| 178 | - addr = page_pool_get_dma_addr(virt_to_head_page(buf)) + offset; |
| 179 | - dir = page_pool_get_dma_dir(q->page_pool); |
| 180 | - dma_sync_single_for_device(dev->dma_dev, addr, len, dir); |
| 181 | + addr = dma_map_single(dev->dma_dev, buf, len, DMA_FROM_DEVICE); |
| 182 | + if (unlikely(dma_mapping_error(dev->dma_dev, addr))) { |
| 183 | + skb_free_frag(buf); |
| 184 | + break; |
| 185 | + } |
| 186 | |
| 187 | - qbuf.addr = addr + q->buf_offset; |
| 188 | - qbuf.len = len - q->buf_offset; |
| 189 | + qbuf.addr = addr + offset; |
| 190 | + qbuf.len = len - offset; |
| 191 | qbuf.skip_unmap = false; |
| 192 | - if (mt76_dma_add_rx_buf(dev, q, &qbuf, buf) < 0) { |
| 193 | - mt76_put_page_pool_buf(buf, allow_direct); |
| 194 | + if (mt76_dma_add_rx_buf(dev, q, &qbuf, buf, NULL) < 0) { |
| 195 | + dma_unmap_single(dev->dma_dev, addr, len, |
| 196 | + DMA_FROM_DEVICE); |
| 197 | + skb_free_frag(buf); |
| 198 | break; |
| 199 | } |
| 200 | frames++; |
| 201 | } |
| 202 | |
| 203 | - if (frames) |
| 204 | + flags = (q->flags & MT_QFLAG_WED) && |
| 205 | + FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_Q_RX; |
| 206 | + |
| 207 | + if (frames || flags) |
| 208 | mt76_dma_kick_queue(dev, q); |
| 209 | |
| 210 | spin_unlock_bh(&q->lock); |
| 211 | @@ -690,7 +729,7 @@ int mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset) |
| 212 | /* WED txfree queue needs ring to be initialized before setup */ |
| 213 | q->flags = 0; |
| 214 | mt76_dma_queue_reset(dev, q); |
| 215 | - mt76_dma_rx_fill(dev, q, false); |
| 216 | + mt76_dma_rx_fill(dev, q); |
| 217 | q->flags = flags; |
| 218 | |
| 219 | ret = mtk_wed_device_txfree_ring_setup(wed, q->regs); |
| 220 | @@ -738,10 +777,6 @@ mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q, |
| 221 | if (!q->entry) |
| 222 | return -ENOMEM; |
| 223 | |
| 224 | - ret = mt76_create_page_pool(dev, q); |
| 225 | - if (ret) |
| 226 | - return ret; |
| 227 | - |
| 228 | ret = mt76_dma_wed_setup(dev, q, false); |
| 229 | if (ret) |
| 230 | return ret; |
| 231 | @@ -755,6 +790,7 @@ mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q, |
| 232 | static void |
| 233 | mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q) |
| 234 | { |
| 235 | + struct page *page; |
| 236 | void *buf; |
| 237 | bool more; |
| 238 | |
| 239 | @@ -768,7 +804,7 @@ mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q) |
| 240 | if (!buf) |
| 241 | break; |
| 242 | |
| 243 | - mt76_put_page_pool_buf(buf, false); |
| 244 | + skb_free_frag(buf); |
| 245 | } while (1); |
| 246 | |
| 247 | if (q->rx_head) { |
| 248 | @@ -777,6 +813,15 @@ mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q) |
| 249 | } |
| 250 | |
| 251 | spin_unlock_bh(&q->lock); |
| 252 | + |
| 253 | + if (FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) != MT76_WED_Q_RX) { |
| 254 | + if (!q->rx_page.va) |
| 255 | + return; |
| 256 | + |
| 257 | + page = virt_to_page(q->rx_page.va); |
| 258 | + __page_frag_cache_drain(page, q->rx_page.pagecnt_bias); |
| 259 | + memset(&q->rx_page, 0, sizeof(q->rx_page)); |
| 260 | + } |
| 261 | } |
| 262 | |
| 263 | static void |
| 264 | @@ -797,7 +842,7 @@ mt76_dma_rx_reset(struct mt76_dev *dev, enum mt76_rxq_id qid) |
| 265 | mt76_dma_wed_setup(dev, q, true); |
| 266 | if (q->flags != MT_WED_Q_TXFREE) { |
| 267 | mt76_dma_sync_idx(dev, q); |
| 268 | - mt76_dma_rx_fill(dev, q, false); |
| 269 | + mt76_dma_rx_fill(dev, q); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | @@ -815,7 +860,7 @@ mt76_add_fragment(struct mt76_dev *dev, struct mt76_queue *q, void *data, |
| 274 | |
| 275 | skb_add_rx_frag(skb, nr_frags, page, offset, len, q->buf_size); |
| 276 | } else { |
| 277 | - mt76_put_page_pool_buf(data, true); |
| 278 | + skb_free_frag(data); |
| 279 | } |
| 280 | |
| 281 | if (more) |
| 282 | @@ -888,7 +933,6 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget) |
| 283 | goto free_frag; |
| 284 | |
| 285 | skb_reserve(skb, q->buf_offset); |
| 286 | - skb_mark_for_recycle(skb); |
| 287 | |
| 288 | *(u32 *)skb->cb = info; |
| 289 | |
| 290 | @@ -904,10 +948,10 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget) |
| 291 | continue; |
| 292 | |
| 293 | free_frag: |
| 294 | - mt76_put_page_pool_buf(data, true); |
| 295 | + skb_free_frag(data); |
| 296 | } |
| 297 | |
| 298 | - mt76_dma_rx_fill(dev, q, true); |
| 299 | + mt76_dma_rx_fill(dev, q); |
| 300 | return done; |
| 301 | } |
| 302 | |
| 303 | @@ -952,7 +996,7 @@ mt76_dma_init(struct mt76_dev *dev, |
| 304 | |
| 305 | mt76_for_each_q_rx(dev, i) { |
| 306 | netif_napi_add(&dev->napi_dev, &dev->napi[i], poll); |
| 307 | - mt76_dma_rx_fill(dev, &dev->q_rx[i], false); |
| 308 | + mt76_dma_rx_fill(dev, &dev->q_rx[i]); |
| 309 | napi_enable(&dev->napi[i]); |
| 310 | } |
| 311 | |
| 312 | @@ -1003,8 +1047,6 @@ void mt76_dma_cleanup(struct mt76_dev *dev) |
| 313 | |
| 314 | netif_napi_del(&dev->napi[i]); |
| 315 | mt76_dma_rx_cleanup(dev, q); |
| 316 | - |
| 317 | - page_pool_destroy(q->page_pool); |
| 318 | } |
| 319 | |
| 320 | mt76_free_pending_txwi(dev); |
| 321 | diff --git a/mac80211.c b/mac80211.c |
| 322 | index 95861d47..90447472 100644 |
| 323 | --- a/mac80211.c |
| 324 | +++ b/mac80211.c |
| 325 | @@ -4,7 +4,6 @@ |
| 326 | */ |
| 327 | #include <linux/sched.h> |
| 328 | #include <linux/of.h> |
| 329 | -#include <net/page_pool.h> |
| 330 | #include "mt76.h" |
| 331 | |
| 332 | #define CHAN2G(_idx, _freq) { \ |
| 333 | @@ -569,47 +568,6 @@ void mt76_unregister_phy(struct mt76_phy *phy) |
| 334 | } |
| 335 | EXPORT_SYMBOL_GPL(mt76_unregister_phy); |
| 336 | |
| 337 | -int mt76_create_page_pool(struct mt76_dev *dev, struct mt76_queue *q) |
| 338 | -{ |
| 339 | - struct page_pool_params pp_params = { |
| 340 | - .order = 0, |
| 341 | - .flags = PP_FLAG_PAGE_FRAG, |
| 342 | - .nid = NUMA_NO_NODE, |
| 343 | - .dev = dev->dma_dev, |
| 344 | - }; |
| 345 | - int idx = q - dev->q_rx; |
| 346 | - |
| 347 | - switch (idx) { |
| 348 | - case MT_RXQ_MAIN: |
| 349 | - case MT_RXQ_BAND1: |
| 350 | - case MT_RXQ_BAND2: |
| 351 | - pp_params.pool_size = 256; |
| 352 | - break; |
| 353 | - default: |
| 354 | - pp_params.pool_size = 16; |
| 355 | - break; |
| 356 | - } |
| 357 | - |
| 358 | - if (mt76_is_mmio(dev)) { |
| 359 | - /* rely on page_pool for DMA mapping */ |
| 360 | - pp_params.flags |= PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV; |
| 361 | - pp_params.dma_dir = DMA_FROM_DEVICE; |
| 362 | - pp_params.max_len = PAGE_SIZE; |
| 363 | - pp_params.offset = 0; |
| 364 | - } |
| 365 | - |
| 366 | - q->page_pool = page_pool_create(&pp_params); |
| 367 | - if (IS_ERR(q->page_pool)) { |
| 368 | - int err = PTR_ERR(q->page_pool); |
| 369 | - |
| 370 | - q->page_pool = NULL; |
| 371 | - return err; |
| 372 | - } |
| 373 | - |
| 374 | - return 0; |
| 375 | -} |
| 376 | -EXPORT_SYMBOL_GPL(mt76_create_page_pool); |
| 377 | - |
| 378 | struct mt76_dev * |
| 379 | mt76_alloc_device(struct device *pdev, unsigned int size, |
| 380 | const struct ieee80211_ops *ops, |
| 381 | @@ -1745,21 +1703,6 @@ void mt76_ethtool_worker(struct mt76_ethtool_worker_info *wi, |
| 382 | } |
| 383 | EXPORT_SYMBOL_GPL(mt76_ethtool_worker); |
| 384 | |
| 385 | -void mt76_ethtool_page_pool_stats(struct mt76_dev *dev, u64 *data, int *index) |
| 386 | -{ |
| 387 | -#ifdef CONFIG_PAGE_POOL_STATS |
| 388 | - struct page_pool_stats stats = {}; |
| 389 | - int i; |
| 390 | - |
| 391 | - mt76_for_each_q_rx(dev, i) |
| 392 | - page_pool_get_stats(dev->q_rx[i].page_pool, &stats); |
| 393 | - |
| 394 | - page_pool_ethtool_stats_get(data, &stats); |
| 395 | - *index += page_pool_ethtool_stats_get_count(); |
| 396 | -#endif |
| 397 | -} |
| 398 | -EXPORT_SYMBOL_GPL(mt76_ethtool_page_pool_stats); |
| 399 | - |
| 400 | enum mt76_dfs_state mt76_phy_dfs_state(struct mt76_phy *phy) |
| 401 | { |
| 402 | struct ieee80211_hw *hw = phy->hw; |
| 403 | diff --git a/mt76.h b/mt76.h |
| 404 | index a36a978b..3911d013 100644 |
| 405 | --- a/mt76.h |
| 406 | +++ b/mt76.h |
| 407 | @@ -210,7 +210,7 @@ struct mt76_queue { |
| 408 | |
| 409 | dma_addr_t desc_dma; |
| 410 | struct sk_buff *rx_head; |
| 411 | - struct page_pool *page_pool; |
| 412 | + struct page_frag_cache rx_page; |
| 413 | }; |
| 414 | |
| 415 | struct mt76_mcu_ops { |
| 416 | @@ -1457,7 +1457,6 @@ mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int *actual_len, |
| 417 | return usb_bulk_msg(udev, pipe, data, len, actual_len, timeout); |
| 418 | } |
| 419 | |
| 420 | -void mt76_ethtool_page_pool_stats(struct mt76_dev *dev, u64 *data, int *index); |
| 421 | void mt76_ethtool_worker(struct mt76_ethtool_worker_info *wi, |
| 422 | struct mt76_sta_stats *stats, bool eht); |
| 423 | int mt76_skb_adjust_pad(struct sk_buff *skb, int pad); |
| 424 | @@ -1569,25 +1568,6 @@ void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked); |
| 425 | struct mt76_rxwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token); |
| 426 | int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr, |
| 427 | struct mt76_rxwi_cache *r, dma_addr_t phys); |
| 428 | -int mt76_create_page_pool(struct mt76_dev *dev, struct mt76_queue *q); |
| 429 | -static inline void mt76_put_page_pool_buf(void *buf, bool allow_direct) |
| 430 | -{ |
| 431 | - struct page *page = virt_to_head_page(buf); |
| 432 | - |
| 433 | - page_pool_put_full_page(page->pp, page, allow_direct); |
| 434 | -} |
| 435 | - |
| 436 | -static inline void * |
| 437 | -mt76_get_page_pool_buf(struct mt76_queue *q, u32 *offset, u32 size) |
| 438 | -{ |
| 439 | - struct page *page; |
| 440 | - |
| 441 | - page = page_pool_dev_alloc_frag(q->page_pool, offset, size); |
| 442 | - if (!page) |
| 443 | - return NULL; |
| 444 | - |
| 445 | - return page_address(page) + *offset; |
| 446 | -} |
| 447 | |
| 448 | static inline void mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked) |
| 449 | { |
| 450 | diff --git a/mt7915/main.c b/mt7915/main.c |
| 451 | index 8ebea612..5307e15d 100644 |
| 452 | --- a/mt7915/main.c |
| 453 | +++ b/mt7915/main.c |
| 454 | @@ -1357,22 +1357,19 @@ void mt7915_get_et_strings(struct ieee80211_hw *hw, |
| 455 | struct ieee80211_vif *vif, |
| 456 | u32 sset, u8 *data) |
| 457 | { |
| 458 | - if (sset != ETH_SS_STATS) |
| 459 | - return; |
| 460 | - |
| 461 | - memcpy(data, *mt7915_gstrings_stats, sizeof(mt7915_gstrings_stats)); |
| 462 | - data += sizeof(mt7915_gstrings_stats); |
| 463 | - page_pool_ethtool_stats_get_strings(data); |
| 464 | + if (sset == ETH_SS_STATS) |
| 465 | + memcpy(data, *mt7915_gstrings_stats, |
| 466 | + sizeof(mt7915_gstrings_stats)); |
| 467 | } |
| 468 | |
| 469 | static |
| 470 | int mt7915_get_et_sset_count(struct ieee80211_hw *hw, |
| 471 | struct ieee80211_vif *vif, int sset) |
| 472 | { |
| 473 | - if (sset != ETH_SS_STATS) |
| 474 | - return 0; |
| 475 | + if (sset == ETH_SS_STATS) |
| 476 | + return MT7915_SSTATS_LEN; |
| 477 | |
| 478 | - return MT7915_SSTATS_LEN + page_pool_ethtool_stats_get_count(); |
| 479 | + return 0; |
| 480 | } |
| 481 | |
| 482 | static void mt7915_ethtool_worker(void *wi_data, struct ieee80211_sta *sta) |
| 483 | @@ -1400,7 +1397,7 @@ void mt7915_get_et_stats(struct ieee80211_hw *hw, |
| 484 | }; |
| 485 | struct mib_stats *mib = &phy->mib; |
| 486 | /* See mt7915_ampdu_stat_read_phy, etc */ |
| 487 | - int i, ei = 0, stats_size; |
| 488 | + int i, ei = 0; |
| 489 | |
| 490 | mutex_lock(&dev->mt76.mutex); |
| 491 | |
| 492 | @@ -1481,12 +1478,9 @@ void mt7915_get_et_stats(struct ieee80211_hw *hw, |
| 493 | return; |
| 494 | |
| 495 | ei += wi.worker_stat_count; |
| 496 | - |
| 497 | - mt76_ethtool_page_pool_stats(&dev->mt76, &data[ei], &ei); |
| 498 | - |
| 499 | - stats_size = MT7915_SSTATS_LEN + page_pool_ethtool_stats_get_count(); |
| 500 | - if (ei != stats_size) |
| 501 | - dev_err(dev->mt76.dev, "ei: %d size: %d", ei, stats_size); |
| 502 | + if (ei != MT7915_SSTATS_LEN) |
| 503 | + dev_err(dev->mt76.dev, "ei: %d MT7915_SSTATS_LEN: %d", |
| 504 | + ei, (int)MT7915_SSTATS_LEN); |
| 505 | } |
| 506 | |
| 507 | static void |
| 508 | diff --git a/mt7915/mmio.c b/mt7915/mmio.c |
| 509 | index 6dec9d60..6b9752b2 100644 |
| 510 | --- a/mt7915/mmio.c |
| 511 | +++ b/mt7915/mmio.c |
| 512 | @@ -602,9 +602,14 @@ static void mt7915_mmio_wed_offload_disable(struct mtk_wed_device *wed) |
| 513 | static void mt7915_mmio_wed_release_rx_buf(struct mtk_wed_device *wed) |
| 514 | { |
| 515 | struct mt7915_dev *dev; |
| 516 | + struct page *page; |
| 517 | + u32 length; |
| 518 | int i; |
| 519 | |
| 520 | dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 521 | + length = SKB_DATA_ALIGN(NET_SKB_PAD + wed->wlan.rx_size + |
| 522 | + sizeof(struct skb_shared_info)); |
| 523 | + |
| 524 | for (i = 0; i < dev->mt76.rx_token_size; i++) { |
| 525 | struct mt76_rxwi_cache *r; |
| 526 | |
| 527 | @@ -612,50 +617,82 @@ static void mt7915_mmio_wed_release_rx_buf(struct mtk_wed_device *wed) |
| 528 | if (!r || !r->ptr) |
| 529 | continue; |
| 530 | |
| 531 | - mt76_put_page_pool_buf(r->ptr, false); |
| 532 | + dma_unmap_single(dev->mt76.dma_dev, r->dma_addr, |
| 533 | + wed->wlan.rx_size, DMA_FROM_DEVICE); |
| 534 | + __free_pages(virt_to_page(r->ptr), get_order(length)); |
| 535 | r->ptr = NULL; |
| 536 | |
| 537 | mt76_put_rxwi(&dev->mt76, r); |
| 538 | } |
| 539 | |
| 540 | mt76_free_pending_rxwi(&dev->mt76); |
| 541 | + |
| 542 | + mt76_for_each_q_rx(&dev->mt76, i) { |
| 543 | + if (FIELD_GET(MT_QFLAG_WED_TYPE, |
| 544 | + dev->mt76.q_rx[i].flags) == MT76_WED_Q_RX) { |
| 545 | + struct mt76_queue *q = &dev->mt76.q_rx[i]; |
| 546 | + |
| 547 | + if (!q->rx_page.va) |
| 548 | + continue; |
| 549 | + |
| 550 | + page = virt_to_page(q->rx_page.va); |
| 551 | + __page_frag_cache_drain(page, q->rx_page.pagecnt_bias); |
| 552 | + memset(&q->rx_page, 0, sizeof(q->rx_page)); |
| 553 | + } |
| 554 | + } |
| 555 | + |
| 556 | + if (!wed->rx_buf_ring.rx_page.va) |
| 557 | + return; |
| 558 | + |
| 559 | + page = virt_to_page(wed->rx_buf_ring.rx_page.va); |
| 560 | + __page_frag_cache_drain(page, wed->rx_buf_ring.rx_page.pagecnt_bias); |
| 561 | + memset(&wed->rx_buf_ring.rx_page, 0, sizeof(wed->rx_buf_ring.rx_page)); |
| 562 | } |
| 563 | |
| 564 | static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size) |
| 565 | { |
| 566 | struct mtk_rxbm_desc *desc = wed->rx_buf_ring.desc; |
| 567 | - struct mt76_rxwi_cache *r = NULL; |
| 568 | struct mt7915_dev *dev; |
| 569 | - struct mt76_queue *q; |
| 570 | - int i, len; |
| 571 | + u32 length; |
| 572 | + int i; |
| 573 | |
| 574 | dev = container_of(wed, struct mt7915_dev, mt76.mmio.wed); |
| 575 | - q = &dev->mt76.q_rx[MT_RXQ_MAIN]; |
| 576 | - len = SKB_WITH_OVERHEAD(q->buf_size); |
| 577 | + length = SKB_DATA_ALIGN(NET_SKB_PAD + wed->wlan.rx_size + |
| 578 | + sizeof(struct skb_shared_info)); |
| 579 | |
| 580 | for (i = 0; i < size; i++) { |
| 581 | - enum dma_data_direction dir; |
| 582 | - dma_addr_t addr; |
| 583 | - u32 offset; |
| 584 | + struct mt76_rxwi_cache *r = mt76_get_rxwi(&dev->mt76); |
| 585 | + dma_addr_t phy_addr; |
| 586 | + struct page *page; |
| 587 | int token; |
| 588 | - void *buf; |
| 589 | + void *ptr; |
| 590 | |
| 591 | - r = mt76_get_rxwi(&dev->mt76); |
| 592 | if (!r) |
| 593 | goto unmap; |
| 594 | |
| 595 | - buf = mt76_get_page_pool_buf(q, &offset, q->buf_size); |
| 596 | - if (!buf) |
| 597 | + page = __dev_alloc_pages(GFP_KERNEL, get_order(length)); |
| 598 | + if (!page) { |
| 599 | + mt76_put_rxwi(&dev->mt76, r); |
| 600 | goto unmap; |
| 601 | + } |
| 602 | |
| 603 | - addr = page_pool_get_dma_addr(virt_to_head_page(buf)) + offset; |
| 604 | - dir = page_pool_get_dma_dir(q->page_pool); |
| 605 | - dma_sync_single_for_device(dev->mt76.dma_dev, addr, len, dir); |
| 606 | |
| 607 | - desc->buf0 = cpu_to_le32(addr); |
| 608 | - token = mt76_rx_token_consume(&dev->mt76, buf, r, addr); |
| 609 | + ptr = page_address(page); |
| 610 | + phy_addr = dma_map_single(dev->mt76.dma_dev, ptr, |
| 611 | + wed->wlan.rx_size, |
| 612 | + DMA_TO_DEVICE); |
| 613 | + if (unlikely(dma_mapping_error(dev->mt76.dev, phy_addr))) { |
| 614 | + __free_pages(page, get_order(length)); |
| 615 | + mt76_put_rxwi(&dev->mt76, r); |
| 616 | + goto unmap; |
| 617 | + } |
| 618 | + desc->buf0 = cpu_to_le32(phy_addr); |
| 619 | + token = mt76_rx_token_consume(&dev->mt76, ptr, r, phy_addr); |
| 620 | if (token < 0) { |
| 621 | - mt76_put_page_pool_buf(buf, false); |
| 622 | + dma_unmap_single(dev->mt76.dma_dev, phy_addr, |
| 623 | + wed->wlan.rx_size, DMA_TO_DEVICE); |
| 624 | + __free_pages(page, get_order(length)); |
| 625 | + mt76_put_rxwi(&dev->mt76, r); |
| 626 | goto unmap; |
| 627 | } |
| 628 | |
| 629 | @@ -667,8 +704,6 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size) |
| 630 | return 0; |
| 631 | |
| 632 | unmap: |
| 633 | - if (r) |
| 634 | - mt76_put_rxwi(&dev->mt76, r); |
| 635 | mt7915_mmio_wed_release_rx_buf(wed); |
| 636 | return -ENOMEM; |
| 637 | } |
| 638 | diff --git a/mt7921/main.c b/mt7921/main.c |
| 639 | index 75eaf86c..1434ca79 100644 |
| 640 | --- a/mt7921/main.c |
| 641 | +++ b/mt7921/main.c |
| 642 | @@ -1090,34 +1090,17 @@ static void |
| 643 | mt7921_get_et_strings(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 644 | u32 sset, u8 *data) |
| 645 | { |
| 646 | - struct mt7921_dev *dev = mt7921_hw_dev(hw); |
| 647 | - |
| 648 | if (sset != ETH_SS_STATS) |
| 649 | return; |
| 650 | |
| 651 | memcpy(data, *mt7921_gstrings_stats, sizeof(mt7921_gstrings_stats)); |
| 652 | - |
| 653 | - if (mt76_is_sdio(&dev->mt76)) |
| 654 | - return; |
| 655 | - |
| 656 | - data += sizeof(mt7921_gstrings_stats); |
| 657 | - page_pool_ethtool_stats_get_strings(data); |
| 658 | } |
| 659 | |
| 660 | static int |
| 661 | mt7921_get_et_sset_count(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 662 | int sset) |
| 663 | { |
| 664 | - struct mt7921_dev *dev = mt7921_hw_dev(hw); |
| 665 | - |
| 666 | - if (sset != ETH_SS_STATS) |
| 667 | - return 0; |
| 668 | - |
| 669 | - if (mt76_is_sdio(&dev->mt76)) |
| 670 | - return ARRAY_SIZE(mt7921_gstrings_stats); |
| 671 | - |
| 672 | - return ARRAY_SIZE(mt7921_gstrings_stats) + |
| 673 | - page_pool_ethtool_stats_get_count(); |
| 674 | + return sset == ETH_SS_STATS ? ARRAY_SIZE(mt7921_gstrings_stats) : 0; |
| 675 | } |
| 676 | |
| 677 | static void |
| 678 | @@ -1137,7 +1120,6 @@ void mt7921_get_et_stats(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 679 | struct ethtool_stats *stats, u64 *data) |
| 680 | { |
| 681 | struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv; |
| 682 | - int stats_size = ARRAY_SIZE(mt7921_gstrings_stats); |
| 683 | struct mt7921_phy *phy = mt7921_hw_phy(hw); |
| 684 | struct mt7921_dev *dev = phy->dev; |
| 685 | struct mib_stats *mib = &phy->mib; |
| 686 | @@ -1193,14 +1175,9 @@ void mt7921_get_et_stats(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 687 | return; |
| 688 | |
| 689 | ei += wi.worker_stat_count; |
| 690 | - |
| 691 | - if (!mt76_is_sdio(&dev->mt76)) { |
| 692 | - mt76_ethtool_page_pool_stats(&dev->mt76, &data[ei], &ei); |
| 693 | - stats_size += page_pool_ethtool_stats_get_count(); |
| 694 | - } |
| 695 | - |
| 696 | - if (ei != stats_size) |
| 697 | - dev_err(dev->mt76.dev, "ei: %d SSTATS_LEN: %d", ei, stats_size); |
| 698 | + if (ei != ARRAY_SIZE(mt7921_gstrings_stats)) |
| 699 | + dev_err(dev->mt76.dev, "ei: %d SSTATS_LEN: %zu", |
| 700 | + ei, ARRAY_SIZE(mt7921_gstrings_stats)); |
| 701 | } |
| 702 | |
| 703 | static u64 |
| 704 | diff --git a/usb.c b/usb.c |
| 705 | index b88959ef..3e281715 100644 |
| 706 | --- a/usb.c |
| 707 | +++ b/usb.c |
| 708 | @@ -319,27 +319,29 @@ mt76u_set_endpoints(struct usb_interface *intf, |
| 709 | |
| 710 | static int |
| 711 | mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76_queue *q, struct urb *urb, |
| 712 | - int nsgs) |
| 713 | + int nsgs, gfp_t gfp) |
| 714 | { |
| 715 | int i; |
| 716 | |
| 717 | for (i = 0; i < nsgs; i++) { |
| 718 | + struct page *page; |
| 719 | void *data; |
| 720 | int offset; |
| 721 | |
| 722 | - data = mt76_get_page_pool_buf(q, &offset, q->buf_size); |
| 723 | + data = page_frag_alloc(&q->rx_page, q->buf_size, gfp); |
| 724 | if (!data) |
| 725 | break; |
| 726 | |
| 727 | - sg_set_page(&urb->sg[i], virt_to_head_page(data), q->buf_size, |
| 728 | - offset); |
| 729 | + page = virt_to_head_page(data); |
| 730 | + offset = data - page_address(page); |
| 731 | + sg_set_page(&urb->sg[i], page, q->buf_size, offset); |
| 732 | } |
| 733 | |
| 734 | if (i < nsgs) { |
| 735 | int j; |
| 736 | |
| 737 | for (j = nsgs; j < urb->num_sgs; j++) |
| 738 | - mt76_put_page_pool_buf(sg_virt(&urb->sg[j]), false); |
| 739 | + skb_free_frag(sg_virt(&urb->sg[j])); |
| 740 | urb->num_sgs = i; |
| 741 | } |
| 742 | |
| 743 | @@ -352,16 +354,15 @@ mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76_queue *q, struct urb *urb, |
| 744 | |
| 745 | static int |
| 746 | mt76u_refill_rx(struct mt76_dev *dev, struct mt76_queue *q, |
| 747 | - struct urb *urb, int nsgs) |
| 748 | + struct urb *urb, int nsgs, gfp_t gfp) |
| 749 | { |
| 750 | enum mt76_rxq_id qid = q - &dev->q_rx[MT_RXQ_MAIN]; |
| 751 | - int offset; |
| 752 | |
| 753 | if (qid == MT_RXQ_MAIN && dev->usb.sg_en) |
| 754 | - return mt76u_fill_rx_sg(dev, q, urb, nsgs); |
| 755 | + return mt76u_fill_rx_sg(dev, q, urb, nsgs, gfp); |
| 756 | |
| 757 | urb->transfer_buffer_length = q->buf_size; |
| 758 | - urb->transfer_buffer = mt76_get_page_pool_buf(q, &offset, q->buf_size); |
| 759 | + urb->transfer_buffer = page_frag_alloc(&q->rx_page, q->buf_size, gfp); |
| 760 | |
| 761 | return urb->transfer_buffer ? 0 : -ENOMEM; |
| 762 | } |
| 763 | @@ -399,7 +400,7 @@ mt76u_rx_urb_alloc(struct mt76_dev *dev, struct mt76_queue *q, |
| 764 | if (err) |
| 765 | return err; |
| 766 | |
| 767 | - return mt76u_refill_rx(dev, q, e->urb, sg_size); |
| 768 | + return mt76u_refill_rx(dev, q, e->urb, sg_size, GFP_KERNEL); |
| 769 | } |
| 770 | |
| 771 | static void mt76u_urb_free(struct urb *urb) |
| 772 | @@ -407,10 +408,10 @@ static void mt76u_urb_free(struct urb *urb) |
| 773 | int i; |
| 774 | |
| 775 | for (i = 0; i < urb->num_sgs; i++) |
| 776 | - mt76_put_page_pool_buf(sg_virt(&urb->sg[i]), false); |
| 777 | + skb_free_frag(sg_virt(&urb->sg[i])); |
| 778 | |
| 779 | if (urb->transfer_buffer) |
| 780 | - mt76_put_page_pool_buf(urb->transfer_buffer, false); |
| 781 | + skb_free_frag(urb->transfer_buffer); |
| 782 | |
| 783 | usb_free_urb(urb); |
| 784 | } |
| 785 | @@ -546,8 +547,6 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct urb *urb, |
| 786 | len -= data_len; |
| 787 | nsgs++; |
| 788 | } |
| 789 | - |
| 790 | - skb_mark_for_recycle(skb); |
| 791 | dev->drv->rx_skb(dev, MT_RXQ_MAIN, skb, NULL); |
| 792 | |
| 793 | return nsgs; |
| 794 | @@ -613,7 +612,7 @@ mt76u_process_rx_queue(struct mt76_dev *dev, struct mt76_queue *q) |
| 795 | |
| 796 | count = mt76u_process_rx_entry(dev, urb, q->buf_size); |
| 797 | if (count > 0) { |
| 798 | - err = mt76u_refill_rx(dev, q, urb, count); |
| 799 | + err = mt76u_refill_rx(dev, q, urb, count, GFP_ATOMIC); |
| 800 | if (err < 0) |
| 801 | break; |
| 802 | } |
| 803 | @@ -664,10 +663,6 @@ mt76u_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid) |
| 804 | struct mt76_queue *q = &dev->q_rx[qid]; |
| 805 | int i, err; |
| 806 | |
| 807 | - err = mt76_create_page_pool(dev, q); |
| 808 | - if (err) |
| 809 | - return err; |
| 810 | - |
| 811 | spin_lock_init(&q->lock); |
| 812 | q->entry = devm_kcalloc(dev->dev, |
| 813 | MT_NUM_RX_ENTRIES, sizeof(*q->entry), |
| 814 | @@ -696,6 +691,7 @@ EXPORT_SYMBOL_GPL(mt76u_alloc_mcu_queue); |
| 815 | static void |
| 816 | mt76u_free_rx_queue(struct mt76_dev *dev, struct mt76_queue *q) |
| 817 | { |
| 818 | + struct page *page; |
| 819 | int i; |
| 820 | |
| 821 | for (i = 0; i < q->ndesc; i++) { |
| 822 | @@ -705,7 +701,13 @@ mt76u_free_rx_queue(struct mt76_dev *dev, struct mt76_queue *q) |
| 823 | mt76u_urb_free(q->entry[i].urb); |
| 824 | q->entry[i].urb = NULL; |
| 825 | } |
| 826 | - page_pool_destroy(q->page_pool); |
| 827 | + |
| 828 | + if (!q->rx_page.va) |
| 829 | + return; |
| 830 | + |
| 831 | + page = virt_to_page(q->rx_page.va); |
| 832 | + __page_frag_cache_drain(page, q->rx_page.pagecnt_bias); |
| 833 | + memset(&q->rx_page, 0, sizeof(q->rx_page)); |
| 834 | } |
| 835 | |
| 836 | static void mt76u_free_rx(struct mt76_dev *dev) |
| 837 | -- |
| 838 | 2.18.0 |
| 839 | |