]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
wifi: ath12k: use 128 bytes aligned iova in transmit path for WCN7850
authorBaochen Qiang <quic_bqiang@quicinc.com>
Thu, 1 Aug 2024 15:04:07 +0000 (18:04 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Aug 2024 15:35:54 +0000 (17:35 +0200)
[ Upstream commit 38055789d15155109b41602ad719d770af507030 ]

In transmit path, it is likely that the iova is not aligned to PCIe TLP
max payload size, which is 128 for WCN7850. Normally in such cases hardware
is expected to split the packet into several parts in a manner such that
they, other than the first one, have aligned iova. However due to hardware
limitations, WCN7850 does not behave like that properly with some specific
unaligned iova in transmit path. This easily results in target hang in a
KPI transmit test: packet send/receive failure, WMI command send timeout
etc. Also fatal error seen in PCIe level:

...
Capabilities: ...
...
DevSta: ... FatalErr+ ...
...
...

Work around this by manually moving/reallocating payload buffer such that
we can map it to a 128 bytes aligned iova. The moving requires sufficient
head room or tail room in skb: for the former we can do ourselves a favor
by asking some extra bytes when registering with mac80211, while for the
latter we can do nothing.

Moving/reallocating buffer consumes additional CPU cycles, but the good news
is that an aligned iova increases PCIe efficiency. In my tests on some X86
platforms the KPI results are almost consistent.

Since this is seen only with WCN7850, add a new hardware parameter to
differentiate from others.

Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3

Signed-off-by: Baochen Qiang <quic_bqiang@quicinc.com>
Cc: <stable@vger.kernel.org>
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
Link: https://patch.msgid.link/20240715023814.20242-1-quic_bqiang@quicinc.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/wireless/ath/ath12k/dp_tx.c
drivers/net/wireless/ath/ath12k/hw.c
drivers/net/wireless/ath/ath12k/hw.h
drivers/net/wireless/ath/ath12k/mac.c

index a7c7a868c14ce05dab713f29cb76e7faa9681343..fca9f7e510b4108de431a1313af2d61872550c7a 100644 (file)
@@ -124,6 +124,60 @@ static void ath12k_hal_tx_cmd_ext_desc_setup(struct ath12k_base *ab,
                                                 HAL_TX_MSDU_EXT_INFO1_ENCRYPT_TYPE);
 }
 
+static void ath12k_dp_tx_move_payload(struct sk_buff *skb,
+                                     unsigned long delta,
+                                     bool head)
+{
+       unsigned long len = skb->len;
+
+       if (head) {
+               skb_push(skb, delta);
+               memmove(skb->data, skb->data + delta, len);
+               skb_trim(skb, len);
+       } else {
+               skb_put(skb, delta);
+               memmove(skb->data + delta, skb->data, len);
+               skb_pull(skb, delta);
+       }
+}
+
+static int ath12k_dp_tx_align_payload(struct ath12k_base *ab,
+                                     struct sk_buff **pskb)
+{
+       u32 iova_mask = ab->hw_params->iova_mask;
+       unsigned long offset, delta1, delta2;
+       struct sk_buff *skb2, *skb = *pskb;
+       unsigned int headroom = skb_headroom(skb);
+       int tailroom = skb_tailroom(skb);
+       int ret = 0;
+
+       offset = (unsigned long)skb->data & iova_mask;
+       delta1 = offset;
+       delta2 = iova_mask - offset + 1;
+
+       if (headroom >= delta1) {
+               ath12k_dp_tx_move_payload(skb, delta1, true);
+       } else if (tailroom >= delta2) {
+               ath12k_dp_tx_move_payload(skb, delta2, false);
+       } else {
+               skb2 = skb_realloc_headroom(skb, iova_mask);
+               if (!skb2) {
+                       ret = -ENOMEM;
+                       goto out;
+               }
+
+               dev_kfree_skb_any(skb);
+
+               offset = (unsigned long)skb2->data & iova_mask;
+               if (offset)
+                       ath12k_dp_tx_move_payload(skb2, offset, true);
+               *pskb = skb2;
+       }
+
+out:
+       return ret;
+}
+
 int ath12k_dp_tx(struct ath12k *ar, struct ath12k_vif *arvif,
                 struct sk_buff *skb)
 {
@@ -145,6 +199,7 @@ int ath12k_dp_tx(struct ath12k *ar, struct ath12k_vif *arvif,
        u8 ring_selector, ring_map = 0;
        bool tcl_ring_retry;
        bool msdu_ext_desc = false;
+       u32 iova_mask = ab->hw_params->iova_mask;
 
        if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
                return -ESHUTDOWN;
@@ -240,6 +295,23 @@ tcl_ring_sel:
                goto fail_remove_tx_buf;
        }
 
+       if (iova_mask &&
+           (unsigned long)skb->data & iova_mask) {
+               ret = ath12k_dp_tx_align_payload(ab, &skb);
+               if (ret) {
+                       ath12k_warn(ab, "failed to align TX buffer %d\n", ret);
+                       /* don't bail out, give original buffer
+                        * a chance even unaligned.
+                        */
+                       goto map;
+               }
+
+               /* hdr is pointing to a wrong place after alignment,
+                * so refresh it for later use.
+                */
+               hdr = (void *)skb->data;
+       }
+map:
        ti.paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE);
        if (dma_mapping_error(ab->dev, ti.paddr)) {
                atomic_inc(&ab->soc_stats.tx_err.misc_fail);
index bff8cf97a18c667817b71429551e86e69d9398ac..2a92147d15fa13d424723f783f0e8677f180f236 100644 (file)
@@ -922,6 +922,8 @@ static const struct ath12k_hw_params ath12k_hw_params[] = {
                .supports_sta_ps = false,
 
                .acpi_guid = NULL,
+
+               .iova_mask = 0,
        },
        {
                .name = "wcn7850 hw2.0",
@@ -997,6 +999,8 @@ static const struct ath12k_hw_params ath12k_hw_params[] = {
                .supports_sta_ps = true,
 
                .acpi_guid = &wcn7850_uuid,
+
+               .iova_mask = ATH12K_PCIE_MAX_PAYLOAD_SIZE - 1,
        },
        {
                .name = "qcn9274 hw2.0",
@@ -1067,6 +1071,8 @@ static const struct ath12k_hw_params ath12k_hw_params[] = {
                .supports_sta_ps = false,
 
                .acpi_guid = NULL,
+
+               .iova_mask = 0,
        },
 };
 
index 2a314cfc8cb84ad0caeb4150b632ce08b001899c..400bda17e02f6c68e496b62223c43a8ed92cdcc9 100644 (file)
@@ -96,6 +96,8 @@
 #define ATH12K_M3_FILE                 "m3.bin"
 #define ATH12K_REGDB_FILE_NAME         "regdb.bin"
 
+#define ATH12K_PCIE_MAX_PAYLOAD_SIZE   128
+
 enum ath12k_hw_rate_cck {
        ATH12K_HW_RATE_CCK_LP_11M = 0,
        ATH12K_HW_RATE_CCK_LP_5_5M,
@@ -214,6 +216,8 @@ struct ath12k_hw_params {
        bool supports_sta_ps;
 
        const guid_t *acpi_guid;
+
+       u32 iova_mask;
 };
 
 struct ath12k_hw_ops {
index ead37a4e002a256b3d47a474042f0bcdc3186625..8474e25d2ac647b5b2c64bf7201fbc471b7357f7 100644 (file)
@@ -8737,6 +8737,7 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah)
 
        hw->vif_data_size = sizeof(struct ath12k_vif);
        hw->sta_data_size = sizeof(struct ath12k_sta);
+       hw->extra_tx_headroom = ab->hw_params->iova_mask;
 
        wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
        wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);