From 45222e6db5ecd2ef8e9990fc200737e49be7888e Mon Sep 17 00:00:00 2001 From: kanoqwq Date: Fri, 2 Oct 2026 17:58:40 +0800 Subject: [PATCH] fix: consolidate TF networking and USB latency fixes --- .gitignore | 2 +- docs/FINDINGS.md | 71 +++++++++++++++++ openwrt/build-rootfs.sh | 6 ++ .../etc/sysctl.d/99-mu300-console.conf | 4 + openwrt/overlay/etc/uci-defaults/90-mu300 | 4 + openwrt/patches/fw4-sipa-offload.patch | 14 ++++ .../sipa_delegate/sipa_dele_cp_in_ap.c | 39 ++++++---- .../modules/sprd_wlan_combo/sc2355/pcie.c | 14 ---- .../modules/sprd_wlan_combo/sc2355/reorder.c | 36 ++++++++- .../modules/sprd_wlan_combo/sc2355/reorder.h | 2 +- upstream/modules/sprd_wlan_combo/sc2355/rx.c | 78 ++++++++++++++++--- .../0008-usb-ncm-flush-small-frames.patch | 34 ++++++++ 12 files changed, 262 insertions(+), 42 deletions(-) create mode 100644 openwrt/overlay/etc/sysctl.d/99-mu300-console.conf create mode 100644 openwrt/patches/fw4-sipa-offload.patch create mode 100644 upstream/patches/0008-usb-ncm-flush-small-frames.patch diff --git a/.gitignore b/.gitignore index d6c1b38b..ab211f65 100644 --- a/.gitignore +++ b/.gitignore @@ -33,7 +33,7 @@ backup/ arch/*.tar.gz arch/ArchLinuxARM-* android/magisk/*.zip -/mu300-linux-openwrt-tf.zip +/mu300-linux-openwrt-tf*.zip /tools/pcmhost/pcmhost # built by tools/ctlset/build.sh diff --git a/docs/FINDINGS.md b/docs/FINDINGS.md index 023492ee..71cf8bea 100644 --- a/docs/FINDINGS.md +++ b/docs/FINDINGS.md @@ -1492,6 +1492,13 @@ is no longer devm-allocated. The 5.4 kernel has the same driver in its own tree panic - not syncing: CFI failure (target: 0x0)" in `dele-4-5`, caught while testing v2026.09.29); it gets the same fix as `kernel/patches/sipa-delegate-einprogress.patch`. +On 2026-10-02 a separate delegate bug caused a 6.18.54 trial to panic after 4792 seconds and fall back to Android. +The CP sent ENABLE while the IPA device was already runtime-active. `pm_runtime_get_sync()` returned 1 (success), but +`cp_dele_on_commad()` treated every nonzero result as failure and retried forever with `mdelay(1)` and a printk on +each iteration. The `dele-4-5` thread then hit a 22-second soft lockup in `console_flush_all`. The handler now uses +`pm_runtime_resume_and_get()` (0 on success, negative on failure), acknowledges errors without spinning, and avoids +taking a second reference for a repeated ENABLE. The matching 6.18.54 and 7.2.8 `sipa-dele.ko` modules were rebuilt. + ### 31g. Three warnings on every boot, three vendor bugs 6.18 printed three `WARNING:`s on every boot; each one is a bug in the vendor drivers: * `kernel/softirq.c:429 __local_bh_enable_ip` from `sc2355_free_cmd_buf`: the Wi-Fi command list's `complock` is @@ -1794,6 +1801,70 @@ byte 0x3bf (0x20 set: off), in the configuration block at 0x3b0 that also holds `mu300-nfc on|off` changes that bit alone. With it on, URLs and text written by `mu300-nfc` reached a phone; a Wi-Fi record joins Android phones, while iOS reads URL records by itself but does nothing with a WSC record. +### 33i. USB ping is not the Wi-Fi latency baseline + +On the 6.18 trial boot, Windows 11's `UsbNcm.sys` on the high-speed (480 Mb/s) gadget link pinged +`192.168.77.1` at 3–7 ms (20 packets, mean 4 ms); the device pinged Windows at +0.924–6.362 ms (20 packets, mean 4.586 ms). The same device pinging its own +`192.168.77.1` was 0.062–0.437 ms (mean 0.280 ms), with no loss in any series. +The gadget NCM transmit aggregation timeout in the 6.18 source is 300 microseconds, +so it cannot by itself explain a consistent 4–5 ms. The extra time lies around +the USB transfer and host path, not the bridge or Linux IP response: simultaneous +`tcpdump` on `usb0` measured just 0.130–0.176 ms from request ingress to reply +egress while Windows reported 3–6 ms RTT. This does **not** establish a common +IP-stack delay that would also explain the phone's 10–15 ms Wi-Fi RTT. + +CPU0 deep idle is, however, a demonstrated contributor to USB RTT. At 100 ms +intervals, disabling the 20 ms `cluster-pd` cpuidle state on all CPUs reduced +Windows USB RTT from 4.375 to 2.325 ms (40 packets each); restoring it returned +RTT to 4.475 ms. Disabling that state only on CPU0, where dwc3 and WCN IRQs +actually execute, yielded 2.625 ms; disabling CPU0's shallower `core-sleep-lit` +as well yielded 2.325 ms. At the normal one-second ping interval, CPU0 +`cluster-pd` disabled yielded 1–4 ms, mean 2 ms (12 packets). All cpuidle +settings were restored after the tests. Whether this also improves Wi-Fi RTT +needs a phone-side comparison; a previous CPU0-only Wi-Fi test showed no clear +benefit. Permanently disabling deep idle trades standby power for latency and +is not yet a chosen fix. + +Removing two misleading SC2355 idle-path log messages (`to free list empty` and +`out of time` between normal TX completions) eliminated those messages in the +live 6.18 driver, but the user's phone ping did not noticeably improve. This is +log-overhead cleanup, not a demonstrated Wi-Fi latency fix. The 6.18 driver +must not be hot-unloaded while hostapd is active: an earlier `wifi down` returned +before hostapd exited, and unloading it then caused a hostapd cfg80211 use-after-free +and a panic. Replace the module file and reboot instead. + +A second controlled check disabled `wlan0` RPS temporarily (`04` → `00`), keeping +the hotspot up. The phone reported no meaningful RTT change, so RPS was restored +to `04`; there is no reason to persist that setting. During this check, 20 ICMP +request/reply pairs captured on `wlan0` spent only 0.15–0.33 ms between Linux RX +and Linux TX. As on USB, most measured RTT is outside the Linux IP response path. +At the time, `wlan0` had zero link errors/drops and CPU was mostly idle. The +two media have not been shown to share a single larger bottleneck: CPU0 deep +idle explains about 2 ms of the USB RTT, but the phone did not show a comparable +Wi-Fi gain when it was disabled. Do not attribute the remaining Wi-Fi 10–15 ms +to RPS, flow offload, or the Linux bridge without new evidence. + +### 33j. USB NCM short-frame latency, fixed in the 6.18 trial + +The gadget NCM function delayed an underfilled NTB for 300 microseconds and +completed it from a soft hrtimer callback. Although the timer value is short, +the actual short-frame path added several milliseconds on this device. The +`0008-usb-ncm-flush-small-frames.patch` trial packages frames of at most 256 +bytes immediately, leaving the ordinary aggregation window for larger frames. +It changes neither USB enumeration nor the early DHCP/host-lease recovery path. + +On the same Windows USB NCM link, 100 ICMP pings at 100 ms intervals went from +mean 4.42 ms (40-packet pre-change baseline, 2–7 ms) to mean 1.02 ms (100 +packets, 0–3 ms), with no loss. The device's cpuidle settings were both back +to their defaults (`state1/disable=0`, `state2/disable=0`) for the patched +measurement. At the standard one-second interval, 20 pings were all at most +3 ms and most were under 1 ms. `iperf3` on the USB link transferred 321 Mbit/s +host-to-device and 342 Mbit/s device-to-host using two streams, with no TCP +retransmits reported in the reverse test. USB came back automatically after +the kernel-only trial boot; no manual replug was needed. The user's Android +default-boot choice and five-failure fallback were restored after validation. + ### 33h. A trial guard that outlived its experiment, again The U30 Air restarted about every ten minutes after coming back from Android (`su -c mu300-linux`). init said diff --git a/openwrt/build-rootfs.sh b/openwrt/build-rootfs.sh index 2bddf91f..8e2c92ca 100755 --- a/openwrt/build-rootfs.sh +++ b/openwrt/build-rootfs.sh @@ -67,6 +67,7 @@ done # shellcheck disable=SC2046 docker run --rm --platform linux/arm64 \ -v "$TOP/rootfs/overlay/opt/mu300":/in/opt-mu300:ro -v "$TOP/rootfs/overlay/etc/mu300/vpn.conf.example":/in/vpn.conf.example:ro -v "$TOP/openwrt/overlay":/in/overlay:ro \ + -v "$TOP/openwrt/patches/fw4-sipa-offload.patch":/in/fw4-sipa-offload.patch:ro \ -v "$TOP/boot/module-order.txt":/in/module-order.txt:ro -v "$IN/out/modules":/in/modules:ro \ $(opt out/modules.builtin modules.builtin) $(opt out/modules.builtin.modinfo modules.builtin.modinfo) \ $(opt firmware firmware) $(opt android-subset android-subset) $(opt android-gpu-subset android-gpu-subset) \ @@ -99,6 +100,11 @@ printf "127.0.0.1\tlocalhost\n\n::1\tlocalhost ip6-localhost ip6-loopback\nff02: printf "mu300\n" > $R/etc/hostname # the real one comes from uci (etc/uci-defaults/90-mu300) cp -a /in/opt-mu300 $R/opt/mu300 cp -a /in/overlay/. $R/ +# mu300cell reports sipa_eth0 as l3_device only. fw4 otherwise omits it from +# its software flowtable, leaving cellular downlink on the slow forwarding path. +# Fail the build if a changed fw4 version no longer matches this targeted patch. +apk add patch >/dev/null +patch --batch --fuzz=0 -d $R -p1 -i /in/fw4-sipa-offload.patch if [ -d /in/luci-plugin ]; then cp -a /in/luci-plugin/root/. $R/ cp -a /in/luci-plugin/htdocs/. $R/www/ diff --git a/openwrt/overlay/etc/sysctl.d/99-mu300-console.conf b/openwrt/overlay/etc/sysctl.d/99-mu300-console.conf new file mode 100644 index 00000000..db4bc66f --- /dev/null +++ b/openwrt/overlay/etc/sysctl.d/99-mu300-console.conf @@ -0,0 +1,4 @@ +# Keep the UART console from synchronously printing the noisy vendor WLAN log. +# Messages remain available in dmesg/logread and pstore after a crash. +# /etc/sysctl.conf is loaded later and may override this for serial debugging. +kernel.printk = 1 diff --git a/openwrt/overlay/etc/uci-defaults/90-mu300 b/openwrt/overlay/etc/uci-defaults/90-mu300 index 12971976..3e88662a 100755 --- a/openwrt/overlay/etc/uci-defaults/90-mu300 +++ b/openwrt/overlay/etc/uci-defaults/90-mu300 @@ -59,6 +59,10 @@ set dhcp.mu300_usb.broadcast='1' UCI zone=$(uci -q show firewall | sed -n "s/^\(firewall\.@zone\[[0-9]*\]\)\.name='wan'$/\1/p") [ -n "$zone" ] && uci -q set $zone.masq6='1' +# Use the kernel's software flowtable for forwarded TCP/UDP traffic. The +# Unisoc SIPA and SC2355 drivers do not provide nftables hardware flow offload. +uci -q set firewall.@defaults[0].flow_offloading='1' +uci -q set firewall.@defaults[0].flow_offloading_hw='0' # Before netifd creates br-lan, the early management address lives directly on # usb0. Give that local-only path the same input policy as LAN; forwarding stays # blocked, and once bridged packets enter through br-lan as usual. diff --git a/openwrt/patches/fw4-sipa-offload.patch b/openwrt/patches/fw4-sipa-offload.patch new file mode 100644 index 00000000..76009b94 --- /dev/null +++ b/openwrt/patches/fw4-sipa-offload.patch @@ -0,0 +1,14 @@ +--- a/usr/share/ucode/fw4.uc ++++ b/usr/share/ucode/fw4.uc +@@ -551,6 +551,11 @@ + if (fs.access(`/sys/class/net/${device}`)) + push(devices, device); + ++ /* mu300cell exposes sipa_eth0 as l3_device only, so fw4's ++ * physical-device discovery misses its software ingress hook. */ ++ if (fs.access('/sys/class/net/sipa_eth0')) ++ push(devices, 'sipa_eth0'); ++ + devices = sort(uniq(devices)); + } + diff --git a/upstream/modules/sprd_modem/sipa_delegate/sipa_dele_cp_in_ap.c b/upstream/modules/sprd_modem/sipa_delegate/sipa_dele_cp_in_ap.c index a8e4c2bc..1d336279 100644 --- a/upstream/modules/sprd_modem/sipa_delegate/sipa_dele_cp_in_ap.c +++ b/upstream/modules/sprd_modem/sipa_delegate/sipa_dele_cp_in_ap.c @@ -16,7 +16,6 @@ #endif #define pr_fmt(fmt) "sipa_dele: " fmt -#include #include #include #include @@ -42,28 +41,38 @@ static void cp_dele_on_commad(void *priv, u16 flag, u32 data) switch (flag) { case SMSG_FLG_DELE_ENABLE: delegator->pd_eb_flag = true; -check_again: - ret = pm_runtime_get_sync(delegator->pdev); - if (ret) { - pm_runtime_put(delegator->pdev); - pr_warn("sipa_dele get pd fail ret = %d\n", ret); - mdelay(1); - goto check_again; - } else { - delegator->pd_get_flag = true; - sipa_set_enabled(true); + /* A repeated ENABLE must not take another runtime-PM reference. */ + if (delegator->pd_get_flag) { sipa_dele_start_done_work(delegator, SMSG_FLG_DELE_ENABLE, SMSG_VAL_DELE_REQ_SUCCESS); - pr_info("sipa_dele get pd success ret = %d\n", ret); + break; } + /* get_sync() can return 1 on success and keeps its reference on error. */ + ret = pm_runtime_resume_and_get(delegator->pdev); + if (ret < 0) { + delegator->pd_eb_flag = false; + pr_warn("sipa_dele get pd fail ret = %d\n", ret); + sipa_dele_start_done_work(delegator, + SMSG_FLG_DELE_ENABLE, + SMSG_VAL_DELE_REQ_FAIL); + break; + } + delegator->pd_get_flag = true; + sipa_set_enabled(true); + sipa_dele_start_done_work(delegator, + SMSG_FLG_DELE_ENABLE, + SMSG_VAL_DELE_REQ_SUCCESS); + pr_info("sipa_dele get pd success ret = %d\n", ret); break; case SMSG_FLG_DELE_DISABLE: delegator->pd_eb_flag = false; - sipa_set_enabled(false); - pm_runtime_put(delegator->pdev); - delegator->pd_get_flag = false; + if (delegator->pd_get_flag) { + sipa_set_enabled(false); + pm_runtime_put(delegator->pdev); + delegator->pd_get_flag = false; + } break; default: break; diff --git a/upstream/modules/sprd_wlan_combo/sc2355/pcie.c b/upstream/modules/sprd_wlan_combo/sc2355/pcie.c index cda3fd9d..04c6a71d 100644 --- a/upstream/modules/sprd_wlan_combo/sc2355/pcie.c +++ b/upstream/modules/sprd_wlan_combo/sc2355/pcie.c @@ -1911,7 +1911,6 @@ int sc2355_pcie_fc_get_send_num(struct sprd_hif *hif, { int free_num = 0; struct tx_mgmt *tx_mgmt = hif->tx_mgmt; - static unsigned long caller_jiffies; /*send all data in buff with PCIe interface*/ unsigned int tx_buf_max = get_max_fw_tx_dscr() > pcie_get_tx_buf_num() ? @@ -1922,12 +1921,6 @@ int sc2355_pcie_fc_get_send_num(struct sprd_hif *hif, return 0; free_num = atomic_read(&tx_mgmt->xmit_msg_list.free_num); - if (printk_timed_ratelimit(&caller_jiffies, 1000)) { - pr_debug("%s, free_num=%d, data_num=%d\n", __func__, - free_num, data_num); - if (list_empty(&tx_mgmt->xmit_msg_list.to_free_list)) - pr_info("%s: to free list empty\n", __func__); - } if ((free_num + data_num) >= tx_buf_max) { pr_debug("%s, free_num=%d, data_num=%d\n", __func__, @@ -1944,7 +1937,6 @@ int sc2355_pcie_fc_test_send_num(struct sprd_hif *hif, { int free_num = 0; struct tx_mgmt *tx_mgmt = hif->tx_mgmt; - static unsigned long caller_jiffies; /*send all data in buff with PCIe interface, TODO*/ unsigned int tx_buf_max = get_max_fw_tx_dscr() > pcie_get_tx_buf_num() ? @@ -1955,12 +1947,6 @@ int sc2355_pcie_fc_test_send_num(struct sprd_hif *hif, return 0; free_num = atomic_read(&tx_mgmt->xmit_msg_list.free_num); - if (printk_timed_ratelimit(&caller_jiffies, 1000)) { - pr_debug("%s,%d free_num=%d, data_num=%d\n", __func__, - __LINE__, free_num, data_num); - if (list_empty(&tx_mgmt->xmit_msg_list.to_free_list)) - pr_info("%s: to free list empty\n", __func__); - } if ((free_num + data_num) >= tx_buf_max) { pr_err("%s,%d free_num=%d, data_num=%d\n", diff --git a/upstream/modules/sprd_wlan_combo/sc2355/reorder.c b/upstream/modules/sprd_wlan_combo/sc2355/reorder.c index d2b3d82b..6a8ab741 100644 --- a/upstream/modules/sprd_wlan_combo/sc2355/reorder.c +++ b/upstream/modules/sprd_wlan_combo/sc2355/reorder.c @@ -9,6 +9,8 @@ * as published by the Free Software Foundation. */ +#include + #include "cmdevt.h" #include "common/cmd.h" #include "common/common.h" @@ -19,6 +21,27 @@ static void reorder_ba_timeout(struct timer_list *t); +/* Opt-in, bounded-cost diagnostics for distinguishing BA stalls from other + * Wi-Fi latency. Disabled unless explicitly enabled through sysfs. */ +static bool mu300_ba_probe; +static atomic64_t mu300_ba_packets = ATOMIC64_INIT(0); +static atomic64_t mu300_ba_fast = ATOMIC64_INIT(0); +static atomic64_t mu300_ba_timeouts = ATOMIC64_INIT(0); +module_param_named(mu300_ba_probe, mu300_ba_probe, bool, 0644); + +static int mu300_ba_stats_get(char *buffer, const struct kernel_param *kp) +{ + return scnprintf(buffer, 128, "packets=%lld fast=%lld timeouts=%lld\n", + (long long)atomic64_read(&mu300_ba_packets), + (long long)atomic64_read(&mu300_ba_fast), + (long long)atomic64_read(&mu300_ba_timeouts)); +} + +static const struct kernel_param_ops mu300_ba_stats_ops = { + .get = mu300_ba_stats_get, +}; +module_param_cb(mu300_ba_stats, &mu300_ba_stats_ops, NULL, 0444); + static inline unsigned int reorder_get_index_size(unsigned int size) { unsigned int index_size = MIN_INDEX_SIZE; @@ -77,8 +100,11 @@ reorder_set_skb_list(struct rx_ba_entry *ba_entry, static inline void reorder_mod_timer(struct rx_ba_node *ba_node) { if (ba_node->rx_ba->buff_cnt) { - mod_timer(&ba_node->reorder_timer, - jiffies + RX_BA_LOSS_RECOVERY_TIMEOUT); + /* A stream of out-of-order frames must not keep moving the + * deadline forward and hold an older frame indefinitely. */ + if (!timer_pending(&ba_node->reorder_timer)) + mod_timer(&ba_node->reorder_timer, + jiffies + RX_BA_LOSS_RECOVERY_TIMEOUT); } else { del_timer(&ba_node->reorder_timer); ba_node->timeout_cnt = 0; @@ -383,6 +409,8 @@ static void reorder_msdu_process(struct rx_ba_entry *ba_entry, spin_lock_bh(&ba_node->ba_node_lock); if (likely(ba_node->active)) { + if (unlikely(READ_ONCE(mu300_ba_probe))) + atomic64_inc(&mu300_ba_packets); pr_debug("%s: seq: %d, last_msdu_of_mpdu: %d\n", __func__, seq_num, last_msdu_flag); pr_debug("%s: win_start: %d, win_tail: %d, buff_cnt: %d\n", @@ -391,6 +419,8 @@ static void reorder_msdu_process(struct rx_ba_entry *ba_entry, if (seq_num == ba_node_desc->win_start && !ba_node_desc->buff_cnt && last_msdu_flag) { + if (unlikely(READ_ONCE(mu300_ba_probe))) + atomic64_inc(&mu300_ba_fast); reorder_send_order_msdu(ba_entry, msdu_desc, skb, ba_node_desc); goto out; @@ -747,6 +777,8 @@ static void reorder_ba_timeout(struct timer_list *t) spin_lock_bh(&ba_node->ba_node_lock); if (ba_node->active && ba_node_desc->buff_cnt && !timer_pending(&ba_node->reorder_timer)) { + if (unlikely(READ_ONCE(mu300_ba_probe))) + atomic64_inc(&mu300_ba_timeouts); pos_seqno = reorder_get_first_seqno_in_buff(ba_node_desc); reorder_send_msdu_with_gap(ba_entry, ba_node_desc, pos_seqno); ba_node_desc->win_start = pos_seqno; diff --git a/upstream/modules/sprd_wlan_combo/sc2355/reorder.h b/upstream/modules/sprd_wlan_combo/sc2355/reorder.h index 164786eb..373211f5 100644 --- a/upstream/modules/sprd_wlan_combo/sc2355/reorder.h +++ b/upstream/modules/sprd_wlan_combo/sc2355/reorder.h @@ -18,7 +18,7 @@ #include "common/hif.h" #define NUM_TIDS 8 -#define RX_BA_LOSS_RECOVERY_TIMEOUT (HZ / 10) +#define RX_BA_LOSS_RECOVERY_TIMEOUT msecs_to_jiffies(20) #define MAX_TIMEOUT_CNT 60 #define MIN_INDEX_SIZE BIT(6) #define INDEX_SIZE_MASK(index_size) ((index_size) - 1) diff --git a/upstream/modules/sprd_wlan_combo/sc2355/rx.c b/upstream/modules/sprd_wlan_combo/sc2355/rx.c index 5019414f..020bb656 100644 --- a/upstream/modules/sprd_wlan_combo/sc2355/rx.c +++ b/upstream/modules/sprd_wlan_combo/sc2355/rx.c @@ -9,6 +9,10 @@ * as published by the Free Software Foundation. */ +#include +#include +#include +#include #include #include "cmdevt.h" @@ -20,6 +24,65 @@ #include "rx.h" #include "txrx.h" +/* Opt-in diagnostic: driver ingress to network-stack delivery for ICMP. + * No timestamping or per-packet accounting occurs while disabled. */ +static bool mu300_rx_probe; +static atomic64_t mu300_rx_0_5 = ATOMIC64_INIT(0); +static atomic64_t mu300_rx_5_10 = ATOMIC64_INIT(0); +static atomic64_t mu300_rx_10_20 = ATOMIC64_INIT(0); +static atomic64_t mu300_rx_20_50 = ATOMIC64_INIT(0); +static atomic64_t mu300_rx_50_plus = ATOMIC64_INIT(0); +module_param_named(mu300_rx_probe, mu300_rx_probe, bool, 0644); + +static int mu300_rx_stats_get(char *buffer, const struct kernel_param *kp) +{ + return scnprintf(buffer, 160, "lt5=%lld 5to10=%lld 10to20=%lld 20to50=%lld ge50=%lld\n", + (long long)atomic64_read(&mu300_rx_0_5), + (long long)atomic64_read(&mu300_rx_5_10), + (long long)atomic64_read(&mu300_rx_10_20), + (long long)atomic64_read(&mu300_rx_20_50), + (long long)atomic64_read(&mu300_rx_50_plus)); +} + +static const struct kernel_param_ops mu300_rx_stats_ops = { + .get = mu300_rx_stats_get, +}; +module_param_cb(mu300_rx_stats, &mu300_rx_stats_ops, NULL, 0444); + +static void mu300_rx_probe_icmp(struct sk_buff *skb) +{ + const struct ethhdr *eth; + const struct iphdr *ip; + const struct icmphdr *icmp; + s64 ms; + + if (skb->len < ETH_HLEN + sizeof(*ip)) + return; + eth = (const struct ethhdr *)skb->data; + if (eth->h_proto != htons(ETH_P_IP)) + return; + ip = (const struct iphdr *)(skb->data + ETH_HLEN); + if (ip->protocol != IPPROTO_ICMP || ip->ihl < 5 || + skb->len < ETH_HLEN + ip->ihl * 4 + sizeof(*icmp)) + return; + icmp = (const struct icmphdr *)(skb->data + ETH_HLEN + ip->ihl * 4); + if (icmp->type != ICMP_ECHO && icmp->type != ICMP_ECHOREPLY) + return; + if (!ktime_to_ns(skb->tstamp)) + return; + ms = ktime_ms_delta(ktime_get(), skb->tstamp); + if (ms < 5) + atomic64_inc(&mu300_rx_0_5); + else if (ms < 10) + atomic64_inc(&mu300_rx_5_10); + else if (ms < 20) + atomic64_inc(&mu300_rx_10_20); + else if (ms < 50) + atomic64_inc(&mu300_rx_20_50); + else + atomic64_inc(&mu300_rx_50_plus); +} + static bool rx_mh_ipv6_ext_hdr(unsigned char nexthdr) { return (nexthdr == NEXTHDR_HOP || @@ -191,6 +254,10 @@ static void rx_skb_process(struct sprd_priv *priv, struct sk_buff *skb) ndev = vif->ndev; skb_reserve(skb, msdu_desc->msdu_offset); skb_put(skb, msdu_desc->msdu_len); + if (unlikely(READ_ONCE(mu300_rx_probe))) { + mu300_rx_probe_icmp(skb); + skb->tstamp = 0; + } eth = (struct ethhdr *)skb->data; if (eth->h_proto == htons(ETH_P_IPV6)) @@ -313,7 +380,6 @@ sc2355_rx_mh_addr_process(struct rx_mgmt *rx_mgmt, void *data, struct sprd_common_hdr *hdr = (struct sprd_common_hdr *)(data + hif->hif_offset); struct sprd_work *misc_work = NULL; - static unsigned long time; pr_debug("%s: rx_data_addr=0x%lx\n", __func__, (unsigned long)data); @@ -325,14 +391,6 @@ sc2355_rx_mh_addr_process(struct rx_mgmt *rx_mgmt, void *data, } else { pr_debug("%s: Add TX complete code here\n", __func__); - - if (time != 0 && ((jiffies - time) >= msecs_to_jiffies(1000))) { - pr_err_ratelimited("%s: out of time %d\n", - __func__, jiffies_to_msecs(jiffies - time)); - } - - time = jiffies; - sc2355_tx_free_data_num(hif, (unsigned char *)data); misc_work = sprd_alloc_work(sizeof(void *)); @@ -433,6 +491,8 @@ void sc2355_rx_up(struct rx_mgmt *rx_mgmt) void sc2355_rx_process(struct rx_mgmt *rx_mgmt, struct sk_buff *pskb) { + if (pskb && unlikely(READ_ONCE(mu300_rx_probe))) + pskb->tstamp = ktime_get(); sc2355_reorder_data_process(&rx_mgmt->ba_entry, pskb); if (!work_pending(&rx_mgmt->rx_net_work)) diff --git a/upstream/patches/0008-usb-ncm-flush-small-frames.patch b/upstream/patches/0008-usb-ncm-flush-small-frames.patch new file mode 100644 index 00000000..97057ab5 --- /dev/null +++ b/upstream/patches/0008-usb-ncm-flush-small-frames.patch @@ -0,0 +1,34 @@ +From: mu300-linux +Subject: [PATCH] usb: gadget: ncm: send small latency-sensitive frames immediately + +NCM waits 300 us before completing an underfilled NTB, with the flush +performed by a soft hrtimer callback. On the MU300 USB gadget, this +turned single short frames into multi-millisecond ping latency. Keep +aggregation for larger frames, but submit short frames synchronously. + +The 6.18.54 TF trial measured 100 Windows-to-gadget pings at 100 ms +intervals: mean 4.42 ms before, 1.02 ms after, with no loss. Both +directions sustained over 320 Mbit/s on the existing high-speed link. + +--- a/drivers/usb/gadget/function/f_ncm.c ++++ b/drivers/usb/gadget/function/f_ncm.c +@@ -1011,6 +1011,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port, + + if (skb) { + int ncb_len = 0; ++ bool low_latency = skb->len <= 256; + __le16 *ntb_data; + __le16 *ntb_ndp; + int dgram_pad; +@@ -1114,6 +1115,11 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port, + skb_put_data(ncm->skb_tx_data, skb->data, skb->len); + dev_consume_skb_any(skb); + skb = NULL; ++ /* Do not hold interactive, short frames for NTB aggregation. ++ * Larger frames retain the normal 300 us aggregation window. ++ */ ++ if (low_latency && !skb2) ++ skb2 = package_for_tx(ncm); + + } else if (ncm->skb_tx_data) { + /* If we get here ncm_wrap_ntb() was called with NULL skb,