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