blob: 1f9477c19f64e1a374ec978310eb5e4f8d046674 [file] [log] [blame]
From 4cdf382808962e209db2575b74d5fde2d2e7ac72 Mon Sep 17 00:00:00 2001
From: Evelyn Tsai <evelyn.tsai@mediatek.com>
Date: Sat, 1 Apr 2023 08:18:17 +0800
Subject: [PATCH 0999/1052] wifi: mt76: mt7915: build pass for Linux Kernel 5.4
fixes
---
debugfs.c | 2 ++
dma.c | 73 ++++++++++++++++++++++++-----------------------
dma.h | 3 +-
eeprom.c | 8 +++++-
mac80211.c | 56 ------------------------------------
mcu.c | 1 +
mt76.h | 27 +-----------------
mt7615/mcu.c | 1 +
mt76_connac.h | 2 --
mt76_connac_mcu.c | 47 +-----------------------------
mt76_connac_mcu.h | 4 ---
mt7915/main.c | 25 +++++++---------
mt7915/mcu.c | 1 +
usb.c | 43 ++++++++++++++--------------
wed.c | 62 +++++++++++++++++++++++++---------------
15 files changed, 123 insertions(+), 232 deletions(-)
diff --git a/debugfs.c b/debugfs.c
index c4649ba0..1c8328d5 100644
--- a/debugfs.c
+++ b/debugfs.c
@@ -33,8 +33,10 @@ mt76_napi_threaded_set(void *data, u64 val)
if (!mt76_is_mmio(dev))
return -EOPNOTSUPP;
+#if 0 /* disable in backport 5.15 */
if (dev->napi_dev.threaded != val)
return dev_set_threaded(&dev->napi_dev, val);
+#endif
return 0;
}
diff --git a/dma.c b/dma.c
index f4f88c44..ccdd5646 100644
--- a/dma.c
+++ b/dma.c
@@ -178,7 +178,7 @@ mt76_free_pending_rxwi(struct mt76_dev *dev)
local_bh_disable();
while ((t = __mt76_get_rxwi(dev)) != NULL) {
if (t->ptr)
- mt76_put_page_pool_buf(t->ptr, false);
+ skb_free_frag(t->ptr);
kfree(t);
}
local_bh_enable();
@@ -450,9 +450,9 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx,
if (!t)
return NULL;
- dma_sync_single_for_cpu(dev->dma_dev, t->dma_addr,
- SKB_WITH_OVERHEAD(q->buf_size),
- page_pool_get_dma_dir(q->page_pool));
+ dma_unmap_single(dev->dma_dev, t->dma_addr,
+ SKB_WITH_OVERHEAD(q->buf_size),
+ DMA_FROM_DEVICE);
buf = t->ptr;
t->dma_addr = 0;
@@ -462,9 +462,9 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx,
if (drop)
*drop |= !!(buf1 & MT_DMA_CTL_WO_DROP);
} else {
- dma_sync_single_for_cpu(dev->dma_dev, e->dma_addr[0],
- SKB_WITH_OVERHEAD(q->buf_size),
- page_pool_get_dma_dir(q->page_pool));
+ dma_unmap_single(dev->dma_dev, e->dma_addr[0],
+ SKB_WITH_OVERHEAD(q->buf_size),
+ DMA_FROM_DEVICE);
}
done:
@@ -631,11 +631,11 @@ free_skb:
return ret;
}
-int mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q,
- bool allow_direct)
+int mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q)
{
int len = SKB_WITH_OVERHEAD(q->buf_size);
- int frames = 0;
+ int frames = 0, offset = q->buf_offset;
+ dma_addr_t addr;
if (!q->ndesc)
return 0;
@@ -643,30 +643,30 @@ int mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q,
spin_lock_bh(&q->lock);
while (q->queued < q->ndesc - 1) {
- struct mt76_queue_buf qbuf = {};
- enum dma_data_direction dir;
- dma_addr_t addr;
- int offset;
+ struct mt76_queue_buf qbuf;
void *buf = NULL;
if (mt76_queue_is_wed_rro_ind(q))
goto done;
- buf = mt76_get_page_pool_buf(q, &offset, q->buf_size);
+ buf = page_frag_alloc(&q->rx_page, q->buf_size, GFP_ATOMIC);
if (!buf)
break;
- addr = page_pool_get_dma_addr(virt_to_head_page(buf)) + offset;
- dir = page_pool_get_dma_dir(q->page_pool);
- dma_sync_single_for_device(dev->dma_dev, addr, len, dir);
+ addr = dma_map_single(dev->dma_dev, buf, len, DMA_FROM_DEVICE);
+ if (unlikely(dma_mapping_error(dev->dma_dev, addr))) {
+ skb_free_frag(buf);
+ break;
+ }
- qbuf.addr = addr + q->buf_offset;
+ qbuf.addr = addr + offset;
done:
- qbuf.len = len - q->buf_offset;
+ qbuf.len = len - offset;
qbuf.skip_unmap = false;
if (mt76_dma_add_rx_buf(dev, q, &qbuf, buf) < 0) {
- mt76_put_page_pool_buf(buf, allow_direct);
- break;
+ dma_unmap_single(dev->dma_dev, addr, len,
+ DMA_FROM_DEVICE);
+ skb_free_frag(buf);
}
frames++;
}
@@ -719,10 +719,6 @@ mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q,
if (!q->entry)
return -ENOMEM;
- ret = mt76_create_page_pool(dev, q);
- if (ret)
- return ret;
-
ret = mt76_wed_dma_setup(dev, q, false);
if (ret)
return ret;
@@ -741,6 +737,7 @@ mt76_dma_alloc_queue(struct mt76_dev *dev, struct mt76_queue *q,
static void
mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q)
{
+ struct page *page;
void *buf;
bool more;
@@ -756,7 +753,7 @@ mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q)
break;
if (!mt76_queue_is_wed_rro(q))
- mt76_put_page_pool_buf(buf, false);
+ skb_free_frag(buf);
} while (1);
spin_lock_bh(&q->lock);
@@ -766,6 +763,13 @@ mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q)
}
spin_unlock_bh(&q->lock);
+
+ if (!q->rx_page.va)
+ return;
+
+ page = virt_to_page(q->rx_page.va);
+ __page_frag_cache_drain(page, q->rx_page.pagecnt_bias);
+ memset(&q->rx_page, 0, sizeof(q->rx_page));
}
static void
@@ -796,7 +800,7 @@ mt76_dma_rx_reset(struct mt76_dev *dev, enum mt76_rxq_id qid)
return;
mt76_dma_sync_idx(dev, q);
- mt76_dma_rx_fill(dev, q, false);
+ mt76_dma_rx_fill(dev, q);
}
static void
@@ -813,7 +817,7 @@ mt76_add_fragment(struct mt76_dev *dev, struct mt76_queue *q, void *data,
skb_add_rx_frag(skb, nr_frags, page, offset, len, q->buf_size);
} else {
- mt76_put_page_pool_buf(data, allow_direct);
+ skb_free_frag(data);
}
if (more)
@@ -883,12 +887,11 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget)
!(dev->drv->rx_check(dev, data, len)))
goto free_frag;
- skb = napi_build_skb(data, q->buf_size);
+ skb = build_skb(data, q->buf_size);
if (!skb)
goto free_frag;
skb_reserve(skb, q->buf_offset);
- skb_mark_for_recycle(skb);
*(u32 *)skb->cb = info;
@@ -904,10 +907,10 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget)
continue;
free_frag:
- mt76_put_page_pool_buf(data, allow_direct);
+ skb_free_frag(data);
}
- mt76_dma_rx_fill(dev, q, true);
+ mt76_dma_rx_fill(dev, q);
return done;
}
@@ -952,7 +955,7 @@ mt76_dma_init(struct mt76_dev *dev,
mt76_for_each_q_rx(dev, i) {
netif_napi_add(&dev->napi_dev, &dev->napi[i], poll);
- mt76_dma_rx_fill(dev, &dev->q_rx[i], false);
+ mt76_dma_rx_fill(dev, &dev->q_rx[i]);
napi_enable(&dev->napi[i]);
}
@@ -1007,8 +1010,6 @@ void mt76_dma_cleanup(struct mt76_dev *dev)
netif_napi_del(&dev->napi[i]);
mt76_dma_rx_cleanup(dev, q);
-
- page_pool_destroy(q->page_pool);
}
if (mtk_wed_device_active(&dev->mmio.wed))
diff --git a/dma.h b/dma.h
index 1de5a2b2..619dc0fe 100644
--- a/dma.h
+++ b/dma.h
@@ -79,8 +79,7 @@ enum mt76_dma_wed_ind_reason {
int mt76_dma_rx_poll(struct napi_struct *napi, int budget);
void mt76_dma_attach(struct mt76_dev *dev);
void mt76_dma_cleanup(struct mt76_dev *dev);
-int mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q,
- bool allow_direct);
+int mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q);
void __mt76_dma_queue_reset(struct mt76_dev *dev, struct mt76_queue *q,
bool reset_idx);
void mt76_dma_queue_reset(struct mt76_dev *dev, struct mt76_queue *q);
diff --git a/eeprom.c b/eeprom.c
index ecd09c03..a2673978 100644
--- a/eeprom.c
+++ b/eeprom.c
@@ -163,9 +163,15 @@ void
mt76_eeprom_override(struct mt76_phy *phy)
{
struct mt76_dev *dev = phy->dev;
+#ifdef CONFIG_OF
struct device_node *np = dev->dev->of_node;
+ const u8 *mac = NULL;
- of_get_mac_address(np, phy->macaddr);
+ if (np)
+ mac = of_get_mac_address(np);
+ if (!IS_ERR_OR_NULL(mac))
+ ether_addr_copy(phy->macaddr, mac);
+#endif
if (!is_valid_ether_addr(phy->macaddr)) {
eth_random_addr(phy->macaddr);
diff --git a/mac80211.c b/mac80211.c
index aee6f1e7..4d50bfae 100644
--- a/mac80211.c
+++ b/mac80211.c
@@ -578,47 +578,6 @@ void mt76_unregister_phy(struct mt76_phy *phy)
}
EXPORT_SYMBOL_GPL(mt76_unregister_phy);
-int mt76_create_page_pool(struct mt76_dev *dev, struct mt76_queue *q)
-{
- struct page_pool_params pp_params = {
- .order = 0,
- .flags = PP_FLAG_PAGE_FRAG,
- .nid = NUMA_NO_NODE,
- .dev = dev->dma_dev,
- };
- int idx = q - dev->q_rx;
-
- switch (idx) {
- case MT_RXQ_MAIN:
- case MT_RXQ_BAND1:
- case MT_RXQ_BAND2:
- pp_params.pool_size = 256;
- break;
- default:
- pp_params.pool_size = 16;
- break;
- }
-
- if (mt76_is_mmio(dev)) {
- /* rely on page_pool for DMA mapping */
- pp_params.flags |= PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
- pp_params.dma_dir = DMA_FROM_DEVICE;
- pp_params.max_len = PAGE_SIZE;
- pp_params.offset = 0;
- }
-
- q->page_pool = page_pool_create(&pp_params);
- if (IS_ERR(q->page_pool)) {
- int err = PTR_ERR(q->page_pool);
-
- q->page_pool = NULL;
- return err;
- }
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(mt76_create_page_pool);
-
struct mt76_dev *
mt76_alloc_device(struct device *pdev, unsigned int size,
const struct ieee80211_ops *ops,
@@ -1818,21 +1777,6 @@ void mt76_ethtool_worker(struct mt76_ethtool_worker_info *wi,
}
EXPORT_SYMBOL_GPL(mt76_ethtool_worker);
-void mt76_ethtool_page_pool_stats(struct mt76_dev *dev, u64 *data, int *index)
-{
-#ifdef CONFIG_PAGE_POOL_STATS
- struct page_pool_stats stats = {};
- int i;
-
- mt76_for_each_q_rx(dev, i)
- page_pool_get_stats(dev->q_rx[i].page_pool, &stats);
-
- page_pool_ethtool_stats_get(data, &stats);
- *index += page_pool_ethtool_stats_get_count();
-#endif
-}
-EXPORT_SYMBOL_GPL(mt76_ethtool_page_pool_stats);
-
enum mt76_dfs_state mt76_phy_dfs_state(struct mt76_phy *phy)
{
struct ieee80211_hw *hw = phy->hw;
diff --git a/mcu.c b/mcu.c
index a8cafa39..fa4b0544 100644
--- a/mcu.c
+++ b/mcu.c
@@ -4,6 +4,7 @@
*/
#include "mt76.h"
+#include <linux/moduleparam.h>
struct sk_buff *
__mt76_mcu_msg_alloc(struct mt76_dev *dev, const void *data,
diff --git a/mt76.h b/mt76.h
index 05ee568c..063fc364 100644
--- a/mt76.h
+++ b/mt76.h
@@ -15,11 +15,6 @@
#include <linux/average.h>
#include <linux/soc/mediatek/mtk_wed.h>
#include <net/mac80211.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(6,6,0)
-#include <net/page_pool.h>
-#else
-#include <net/page_pool/helpers.h>
-#endif
#include "util.h"
#include "testmode.h"
@@ -238,7 +233,7 @@ struct mt76_queue {
dma_addr_t desc_dma;
struct sk_buff *rx_head;
- struct page_pool *page_pool;
+ struct page_frag_cache rx_page;
};
struct mt76_mcu_ops {
@@ -1527,7 +1522,6 @@ mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int *actual_len,
return usb_bulk_msg(udev, pipe, data, len, actual_len, timeout);
}
-void mt76_ethtool_page_pool_stats(struct mt76_dev *dev, u64 *data, int *index);
void mt76_ethtool_worker(struct mt76_ethtool_worker_info *wi,
struct mt76_sta_stats *stats, bool eht);
int mt76_skb_adjust_pad(struct sk_buff *skb, int pad);
@@ -1685,25 +1679,6 @@ 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);
int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,
struct mt76_txwi_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)
-{
- struct page *page = virt_to_head_page(buf);
-
- page_pool_put_full_page(page->pp, page, allow_direct);
-}
-
-static inline void *
-mt76_get_page_pool_buf(struct mt76_queue *q, u32 *offset, u32 size)
-{
- struct page *page;
-
- page = page_pool_dev_alloc_frag(q->page_pool, offset, size);
- if (!page)
- return NULL;
-
- return page_address(page) + *offset;
-}
static inline void mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked)
{
diff --git a/mt7615/mcu.c b/mt7615/mcu.c
index c807bd8d..a9310660 100644
--- a/mt7615/mcu.c
+++ b/mt7615/mcu.c
@@ -10,6 +10,7 @@
#include "mcu.h"
#include "mac.h"
#include "eeprom.h"
+#include <linux/moduleparam.h>
static bool prefer_offload_fw = true;
module_param(prefer_offload_fw, bool, 0644);
diff --git a/mt76_connac.h b/mt76_connac.h
index 5028e49a..5356c52c 100644
--- a/mt76_connac.h
+++ b/mt76_connac.h
@@ -56,7 +56,6 @@ enum {
CMD_CBW_10MHZ,
CMD_CBW_5MHZ,
CMD_CBW_8080MHZ,
- CMD_CBW_320MHZ,
CMD_HE_MCS_BW80 = 0,
CMD_HE_MCS_BW160,
@@ -292,7 +291,6 @@ static inline u8 mt76_connac_chan_bw(struct cfg80211_chan_def *chandef)
[NL80211_CHAN_WIDTH_10] = CMD_CBW_10MHZ,
[NL80211_CHAN_WIDTH_20] = CMD_CBW_20MHZ,
[NL80211_CHAN_WIDTH_20_NOHT] = CMD_CBW_20MHZ,
- [NL80211_CHAN_WIDTH_320] = CMD_CBW_320MHZ,
};
if (chandef->width >= ARRAY_SIZE(width_to_bw))
diff --git a/mt76_connac_mcu.c b/mt76_connac_mcu.c
index 4baaaacf..4e84f8d2 100644
--- a/mt76_connac_mcu.c
+++ b/mt76_connac_mcu.c
@@ -4,6 +4,7 @@
#include <linux/firmware.h>
#include "mt76_connac2_mac.h"
#include "mt76_connac_mcu.h"
+#include <linux/module.h>
int mt76_connac_mcu_start_firmware(struct mt76_dev *dev, u32 addr, u32 option)
{
@@ -1357,40 +1358,6 @@ u8 mt76_connac_get_phy_mode(struct mt76_phy *phy, struct ieee80211_vif *vif,
}
EXPORT_SYMBOL_GPL(mt76_connac_get_phy_mode);
-u8 mt76_connac_get_phy_mode_ext(struct mt76_phy *phy, struct ieee80211_vif *vif,
- enum nl80211_band band)
-{
- const struct ieee80211_sta_eht_cap *eht_cap;
- struct ieee80211_supported_band *sband;
- u8 mode = 0;
-
- if (band == NL80211_BAND_6GHZ)
- mode |= PHY_MODE_AX_6G;
-
- sband = phy->hw->wiphy->bands[band];
- eht_cap = ieee80211_get_eht_iftype_cap(sband, vif->type);
-
- if (!eht_cap || !eht_cap->has_eht || !vif->bss_conf.eht_support)
- return mode;
-
- switch (band) {
- case NL80211_BAND_6GHZ:
- mode |= PHY_MODE_BE_6G;
- break;
- case NL80211_BAND_5GHZ:
- mode |= PHY_MODE_BE_5G;
- break;
- case NL80211_BAND_2GHZ:
- mode |= PHY_MODE_BE_24G;
- break;
- default:
- break;
- }
-
- return mode;
-}
-EXPORT_SYMBOL_GPL(mt76_connac_get_phy_mode_ext);
-
const struct ieee80211_sta_he_cap *
mt76_connac_get_he_phy_cap(struct mt76_phy *phy, struct ieee80211_vif *vif)
{
@@ -1406,18 +1373,6 @@ mt76_connac_get_he_phy_cap(struct mt76_phy *phy, struct ieee80211_vif *vif)
}
EXPORT_SYMBOL_GPL(mt76_connac_get_he_phy_cap);
-const struct ieee80211_sta_eht_cap *
-mt76_connac_get_eht_phy_cap(struct mt76_phy *phy, struct ieee80211_vif *vif)
-{
- enum nl80211_band band = phy->chandef.chan->band;
- struct ieee80211_supported_band *sband;
-
- sband = phy->hw->wiphy->bands[band];
-
- return ieee80211_get_eht_iftype_cap(sband, vif->type);
-}
-EXPORT_SYMBOL_GPL(mt76_connac_get_eht_phy_cap);
-
#define DEFAULT_HE_PE_DURATION 4
#define DEFAULT_HE_DURATION_RTS_THRES 1023
static void
diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
index e0255a23..abc57f18 100644
--- a/mt76_connac_mcu.h
+++ b/mt76_connac_mcu.h
@@ -1992,12 +1992,8 @@ void mt76_connac_mcu_reg_wr(struct mt76_dev *dev, u32 offset, u32 val);
const struct ieee80211_sta_he_cap *
mt76_connac_get_he_phy_cap(struct mt76_phy *phy, struct ieee80211_vif *vif);
-const struct ieee80211_sta_eht_cap *
-mt76_connac_get_eht_phy_cap(struct mt76_phy *phy, struct ieee80211_vif *vif);
u8 mt76_connac_get_phy_mode(struct mt76_phy *phy, struct ieee80211_vif *vif,
enum nl80211_band band, struct ieee80211_sta *sta);
-u8 mt76_connac_get_phy_mode_ext(struct mt76_phy *phy, struct ieee80211_vif *vif,
- enum nl80211_band band);
int mt76_connac_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
struct mt76_connac_sta_key_conf *sta_key_conf,
diff --git a/mt7915/main.c b/mt7915/main.c
index 0d2614e1..a3facc9a 100644
--- a/mt7915/main.c
+++ b/mt7915/main.c
@@ -1440,22 +1440,20 @@ void mt7915_get_et_strings(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
u32 sset, u8 *data)
{
- if (sset != ETH_SS_STATS)
- return;
+ if (sset == ETH_SS_STATS)
+ memcpy(data, *mt7915_gstrings_stats,
+ sizeof(mt7915_gstrings_stats));
- memcpy(data, mt7915_gstrings_stats, sizeof(mt7915_gstrings_stats));
- data += sizeof(mt7915_gstrings_stats);
- page_pool_ethtool_stats_get_strings(data);
}
static
int mt7915_get_et_sset_count(struct ieee80211_hw *hw,
struct ieee80211_vif *vif, int sset)
{
- if (sset != ETH_SS_STATS)
- return 0;
+ if (sset == ETH_SS_STATS)
+ return MT7915_SSTATS_LEN;
- return MT7915_SSTATS_LEN + page_pool_ethtool_stats_get_count();
+ return 0;
}
static void mt7915_ethtool_worker(void *wi_data, struct ieee80211_sta *sta)
@@ -1483,7 +1481,7 @@ void mt7915_get_et_stats(struct ieee80211_hw *hw,
.idx = mvif->mt76.idx,
};
/* See mt7915_ampdu_stat_read_phy, etc */
- int i, ei = 0, stats_size;
+ int i, ei = 0;
mutex_lock(&dev->mt76.mutex);
@@ -1595,12 +1593,9 @@ void mt7915_get_et_stats(struct ieee80211_hw *hw,
return;
ei += wi.worker_stat_count;
-
- mt76_ethtool_page_pool_stats(&dev->mt76, &data[ei], &ei);
-
- stats_size = MT7915_SSTATS_LEN + page_pool_ethtool_stats_get_count();
- if (ei != stats_size)
- dev_err(dev->mt76.dev, "ei: %d size: %d", ei, stats_size);
+ if (ei != MT7915_SSTATS_LEN)
+ dev_err(dev->mt76.dev, "ei: %d MT7915_SSTATS_LEN: %d",
+ ei, (int)MT7915_SSTATS_LEN);
}
static void
diff --git a/mt7915/mcu.c b/mt7915/mcu.c
index 9126e62f..34323577 100644
--- a/mt7915/mcu.c
+++ b/mt7915/mcu.c
@@ -6,6 +6,7 @@
#include "mcu.h"
#include "mac.h"
#include "eeprom.h"
+#include <linux/moduleparam.h>
#define fw_name(_dev, name, ...) ({ \
char *_fw; \
diff --git a/usb.c b/usb.c
index 58ff0682..0ca3b069 100644
--- a/usb.c
+++ b/usb.c
@@ -318,27 +318,29 @@ mt76u_set_endpoints(struct usb_interface *intf,
static int
mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76_queue *q, struct urb *urb,
- int nsgs)
+ int nsgs, gfp_t gfp)
{
int i;
for (i = 0; i < nsgs; i++) {
+ struct page *page;
void *data;
int offset;
- data = mt76_get_page_pool_buf(q, &offset, q->buf_size);
+ data = page_frag_alloc(&q->rx_page, q->buf_size, gfp);
if (!data)
break;
- sg_set_page(&urb->sg[i], virt_to_head_page(data), q->buf_size,
- offset);
+ page = virt_to_head_page(data);
+ offset = data - page_address(page);
+ sg_set_page(&urb->sg[i], page, q->buf_size, offset);
}
if (i < nsgs) {
int j;
for (j = nsgs; j < urb->num_sgs; j++)
- mt76_put_page_pool_buf(sg_virt(&urb->sg[j]), false);
+ skb_free_frag(sg_virt(&urb->sg[j]));
urb->num_sgs = i;
}
@@ -351,16 +353,15 @@ mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76_queue *q, struct urb *urb,
static int
mt76u_refill_rx(struct mt76_dev *dev, struct mt76_queue *q,
- struct urb *urb, int nsgs)
+ struct urb *urb, int nsgs, gfp_t gfp)
{
enum mt76_rxq_id qid = q - &dev->q_rx[MT_RXQ_MAIN];
- int offset;
if (qid == MT_RXQ_MAIN && dev->usb.sg_en)
- return mt76u_fill_rx_sg(dev, q, urb, nsgs);
+ return mt76u_fill_rx_sg(dev, q, urb, nsgs, gfp);
urb->transfer_buffer_length = q->buf_size;
- urb->transfer_buffer = mt76_get_page_pool_buf(q, &offset, q->buf_size);
+ urb->transfer_buffer = page_frag_alloc(&q->rx_page, q->buf_size, gfp);
return urb->transfer_buffer ? 0 : -ENOMEM;
}
@@ -398,7 +399,7 @@ mt76u_rx_urb_alloc(struct mt76_dev *dev, struct mt76_queue *q,
if (err)
return err;
- return mt76u_refill_rx(dev, q, e->urb, sg_size);
+ return mt76u_refill_rx(dev, q, e->urb, sg_size, GFP_KERNEL);
}
static void mt76u_urb_free(struct urb *urb)
@@ -406,10 +407,10 @@ static void mt76u_urb_free(struct urb *urb)
int i;
for (i = 0; i < urb->num_sgs; i++)
- mt76_put_page_pool_buf(sg_virt(&urb->sg[i]), false);
+ skb_free_frag(sg_virt(&urb->sg[i]));
if (urb->transfer_buffer)
- mt76_put_page_pool_buf(urb->transfer_buffer, false);
+ skb_free_frag(urb->transfer_buffer);
usb_free_urb(urb);
}
@@ -545,8 +546,6 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct urb *urb,
len -= data_len;
nsgs++;
}
-
- skb_mark_for_recycle(skb);
dev->drv->rx_skb(dev, MT_RXQ_MAIN, skb, NULL);
return nsgs;
@@ -612,7 +611,7 @@ mt76u_process_rx_queue(struct mt76_dev *dev, struct mt76_queue *q)
count = mt76u_process_rx_entry(dev, urb, q->buf_size);
if (count > 0) {
- err = mt76u_refill_rx(dev, q, urb, count);
+ err = mt76u_refill_rx(dev, q, urb, count, GFP_ATOMIC);
if (err < 0)
break;
}
@@ -663,10 +662,6 @@ mt76u_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid)
struct mt76_queue *q = &dev->q_rx[qid];
int i, err;
- err = mt76_create_page_pool(dev, q);
- if (err)
- return err;
-
spin_lock_init(&q->lock);
q->entry = devm_kcalloc(dev->dev,
MT_NUM_RX_ENTRIES, sizeof(*q->entry),
@@ -695,6 +690,7 @@ EXPORT_SYMBOL_GPL(mt76u_alloc_mcu_queue);
static void
mt76u_free_rx_queue(struct mt76_dev *dev, struct mt76_queue *q)
{
+ struct page *page;
int i;
for (i = 0; i < q->ndesc; i++) {
@@ -704,8 +700,13 @@ mt76u_free_rx_queue(struct mt76_dev *dev, struct mt76_queue *q)
mt76u_urb_free(q->entry[i].urb);
q->entry[i].urb = NULL;
}
- page_pool_destroy(q->page_pool);
- q->page_pool = NULL;
+
+ if (!q->rx_page.va)
+ return;
+
+ page = virt_to_page(q->rx_page.va);
+ __page_frag_cache_drain(page, q->rx_page.pagecnt_bias);
+ memset(&q->rx_page, 0, sizeof(q->rx_page));
}
static void mt76u_free_rx(struct mt76_dev *dev)
diff --git a/wed.c b/wed.c
index f89e4537..f7a3f1b3 100644
--- a/wed.c
+++ b/wed.c
@@ -9,8 +9,12 @@
void mt76_wed_release_rx_buf(struct mtk_wed_device *wed)
{
struct mt76_dev *dev = container_of(wed, struct mt76_dev, mmio.wed);
+ u32 length;
int i;
+ length = SKB_DATA_ALIGN(NET_SKB_PAD + wed->wlan.rx_size +
+ sizeof(struct skb_shared_info));
+
for (i = 0; i < dev->rx_token_size; i++) {
struct mt76_txwi_cache *t;
@@ -18,7 +22,9 @@ void mt76_wed_release_rx_buf(struct mtk_wed_device *wed)
if (!t || !t->ptr)
continue;
- mt76_put_page_pool_buf(t->ptr, false);
+ dma_unmap_single(dev->dma_dev, t->dma_addr,
+ wed->wlan.rx_size, DMA_FROM_DEVICE);
+ __free_pages(virt_to_page(t->ptr), get_order(length));
t->ptr = NULL;
mt76_put_rxwi(dev, t);
@@ -33,39 +39,51 @@ u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size)
{
struct mt76_dev *dev = container_of(wed, struct mt76_dev, mmio.wed);
struct mtk_wed_bm_desc *desc = wed->rx_buf_ring.desc;
- struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
- int i, len = SKB_WITH_OVERHEAD(q->buf_size);
- struct mt76_txwi_cache *t = NULL;
+ u32 length;
+ int i;
+
+ length = SKB_DATA_ALIGN(NET_SKB_PAD + wed->wlan.rx_size +
+ sizeof(struct skb_shared_info));
for (i = 0; i < size; i++) {
- enum dma_data_direction dir;
- dma_addr_t addr;
- u32 offset;
+ struct mt76_txwi_cache *t = mt76_get_rxwi(dev);
+ dma_addr_t phy_addr;
+ struct page *page;
int token;
- void *buf;
+ void *ptr;
- t = mt76_get_rxwi(dev);
if (!t)
goto unmap;
- buf = mt76_get_page_pool_buf(q, &offset, q->buf_size);
- if (!buf)
+ page = __dev_alloc_pages(GFP_KERNEL, get_order(length));
+ if (!page) {
+ mt76_put_rxwi(dev, t);
goto unmap;
+ }
- addr = page_pool_get_dma_addr(virt_to_head_page(buf)) + offset;
- dir = page_pool_get_dma_dir(q->page_pool);
- dma_sync_single_for_device(dev->dma_dev, addr, len, dir);
+ ptr = page_address(page);
+ phy_addr = dma_map_single(dev->dma_dev, ptr,
+ wed->wlan.rx_size,
+ DMA_TO_DEVICE);
+ if (unlikely(dma_mapping_error(dev->dev, phy_addr))) {
+ __free_pages(page, get_order(length));
+ mt76_put_rxwi(dev, t);
+ goto unmap;
+ }
- desc->buf0 = cpu_to_le32(addr);
- token = mt76_rx_token_consume(dev, buf, t, addr);
+ desc->buf0 = cpu_to_le32(phy_addr);
+ token = mt76_rx_token_consume(dev, ptr, t, phy_addr);
if (token < 0) {
- mt76_put_page_pool_buf(buf, false);
+ dma_unmap_single(dev->dma_dev, phy_addr,
+ wed->wlan.rx_size, DMA_TO_DEVICE);
+ __free_pages(page, get_order(length));
+ mt76_put_rxwi(dev, t);
goto unmap;
}
token = FIELD_PREP(MT_DMA_CTL_TOKEN, token);
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
- token |= FIELD_PREP(MT_DMA_CTL_SDP0_H, addr >> 32);
+ token |= FIELD_PREP(MT_DMA_CTL_SDP0_H, phy_addr >> 32);
#endif
desc->token |= cpu_to_le32(token);
desc++;
@@ -74,8 +92,6 @@ u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size)
return 0;
unmap:
- if (t)
- mt76_put_rxwi(dev, t);
mt76_wed_release_rx_buf(wed);
return -ENOMEM;
@@ -123,7 +139,7 @@ int mt76_wed_dma_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset)
/* WED txfree queue needs ring to be initialized before setup */
q->flags = 0;
mt76_dma_queue_reset(dev, q);
- mt76_dma_rx_fill(dev, q, false);
+ mt76_dma_rx_fill(dev, q);
ret = mtk_wed_device_txfree_ring_setup(q->wed, q->regs);
if (!ret)
@@ -144,7 +160,7 @@ int mt76_wed_dma_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset)
break;
case MT76_WED_RRO_Q_MSDU_PG:
q->flags &= ~MT_QFLAG_WED;
- __mt76_dma_queue_reset(dev, q, false);
+ __mt76_dma_queue_reset(dev, q);
mtk_wed_device_msdu_pg_rx_ring_setup(q->wed, ring, q->regs);
q->head = q->ndesc - 1;
q->queued = q->head;
@@ -152,7 +168,7 @@ int mt76_wed_dma_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset)
case MT76_WED_RRO_Q_IND:
q->flags &= ~MT_QFLAG_WED;
mt76_dma_queue_reset(dev, q);
- mt76_dma_rx_fill(dev, q, false);
+ mt76_dma_rx_fill(dev, q);
mtk_wed_device_ind_rx_ring_setup(q->wed, q->regs);
break;
default:
--
2.18.0