From patchwork Tue Aug 6 17:39:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 13755127 X-Patchwork-Delegate: pkshih@realtek.com Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B47D22066 for ; Tue, 6 Aug 2024 17:39:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722965999; cv=none; b=O6Tb32JASYxZDcP4GVfSqWqLqrBboa+gjHcVKqHBODesCqS/jrBMBwwwy376QXcR74uaEbreVSGgWN6KJpqedTioe+NYv9th+20ovW6T85420gQut3DArbJT5Cd9dW3vUlwj3QdneEq0uiQ/z8izDHJ76/bAX9aYmVHTKTVRqSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722965999; c=relaxed/simple; bh=8v10EiR8fmwFKuTCYVbk/iN7VD1OxzrSnlIxpSSWBII=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:Content-Type; b=dV7nReyG97eaEpkT+U0O6+crGjzpseH4dIvAJkaXoUgkpiViqPbQtikUQwiE2vh5e4xaoRlgiUdLevECXotIE6a1yHg6KWOSVBzzfokwNY+rdX/X8A9xgUvpZqaKym60I85jq6eCEHTU0sVATWhQPJ2TI67/EwpxYPPzqxsp6rw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IWQHFYHm; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IWQHFYHm" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a7ad02501c3so91666166b.2 for ; Tue, 06 Aug 2024 10:39:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722965996; x=1723570796; darn=vger.kernel.org; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=rv2VT0KZMUtpwqkZKBoiIPgAdLzhKPHmAOmQsdHVXxA=; b=IWQHFYHmyvkacc/tl3JxE71rL/aC7fIWg76Ox0e+joax6JTlU2t0oH09VDEaxlKfBj zmyZ8oQJYf2LwqjDbs64FZkYOpWVVlC0aXN8zUt+nkIO+AgTSgaia/sA7C7wSpPdz4oQ BnTPiZeBJgdvg7t962R4bba6SIBSq/ZIziCaDZGg7jwGzISePx7ZkkxG3jvuKL1iZxtC L01kB8nV+LwASTPYU0cS+cMAkrQ1Lbc0Moq3o9hr2fAjIFUu6nOAXEa8XzWt/PkweQXH mXZPrUmv1SRFTLYJaP/mzIoARoAAqPPlWPfFPmpf0KoJQ2BzVw7ASA0+9c1Fi15BVSWl XIFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722965996; x=1723570796; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=rv2VT0KZMUtpwqkZKBoiIPgAdLzhKPHmAOmQsdHVXxA=; b=CrC7iQ3eNgYpEoyGGvtdXdVLk9uCK91YCbxtSrFIxPC51LqmNdTvi9o+twd8rSyaPo qNoszHy6SkbHwbz8N1S4jS2lWYDG7s0T2caLYGcLdvjZ7mTGpATJ0iMgcpFwwqH0IUZp 9gd+N7YheWt+ikoZPcDPTGknXsXMJoVq/K0WyrdIQbMCQguN9TEhkYOXymqbzsN0bVIM Wt+ivBQzfXcZ57QoeCdZE2UTNlozw0XtiKiGcT3/xNOTjKOKxXYjgIOkAlvuQrRL/yfF 3meJ2EMXkpcWdS3I9aznNds7oCkx9BeUpgzhlxBfjpt7Ecjw7PFrRhZDJByM0LZwroCY hTbg== X-Gm-Message-State: AOJu0YzLFnkIpGL9KhniiFwENilEZh28rCZejAlmqgoBtcqsvyDF992R F8hHxdII62d2dFELUFAg0u68zUXkfQoopMLEBnp1nlW1Gth11v415WXiLQ== X-Google-Smtp-Source: AGHT+IHydnXgalYUqiWVa9S4hyyqkKDA6J9vTBne4xO5mautr2PHlgL7w3gQe0KnY1OU5mGrOQKNQA== X-Received: by 2002:a17:907:7fa9:b0:a77:dd1c:6276 with SMTP id a640c23a62f3a-a7dc4fdf7ecmr1383219466b.7.1722965995725; Tue, 06 Aug 2024 10:39:55 -0700 (PDT) Received: from [192.168.0.50] ([79.119.240.114]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9ec8879sm566711566b.211.2024.08.06.10.39.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Aug 2024 10:39:55 -0700 (PDT) Message-ID: Date: Tue, 6 Aug 2024 20:39:52 +0300 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Bitterblue Smith Subject: [PATCH v3 1/4] wifi: rtw88: usb: Init RX burst length according to USB speed To: "linux-wireless@vger.kernel.org" Cc: Ping-Ke Shih , Sascha Hauer Content-Language: en-US This is needed in order to make USB RX aggregation work with RTL8811CU (and presumably RTL8822BU and RTL8822CU also). I don't know what BIT_DMA_BURST_CNT, BIT_DMA_MODE, and BIT_DROP_DATA_EN are doing. Tested with RTL8811CU and RTL8723DU. The RX speed is unchanged in my tests. Tested-by: Sascha Hauer Signed-off-by: Bitterblue Smith --- v3: - Add Tested-by: Sascha Hauer v2: - Move the code to rtw_usb_interface_cfg. - Let RTL8723DU and all other USB devices use it, not just RTL8822CU, RTL8822BU, and RTL8821CU. - Use the speed member of struct usb_device to determine the USB speed instead of reading hardware registers. - Update the subject line. - Add more information to the commit message. - Rebase on top of the latest rtw-next. --- drivers/net/wireless/realtek/rtw88/reg.h | 6 ++++++ drivers/net/wireless/realtek/rtw88/usb.c | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/realtek/rtw88/reg.h b/drivers/net/wireless/realtek/rtw88/reg.h index e7b24465f549..4d9b8668e8b0 100644 --- a/drivers/net/wireless/realtek/rtw88/reg.h +++ b/drivers/net/wireless/realtek/rtw88/reg.h @@ -322,6 +322,12 @@ #define REG_RXDMA_DPR 0x028C #define REG_RXDMA_MODE 0x0290 #define BIT_DMA_MODE BIT(1) +#define BIT_DMA_BURST_CNT GENMASK(3, 2) +#define BIT_DMA_BURST_SIZE GENMASK(5, 4) +#define BIT_DMA_BURST_SIZE_64 2 +#define BIT_DMA_BURST_SIZE_512 1 +#define BIT_DMA_BURST_SIZE_1024 0 + #define REG_RXPKTNUM 0x02B0 #define REG_INT_MIG 0x0304 diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c index 9145c11a063e..1c40d46a7eb4 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.c +++ b/drivers/net/wireless/realtek/rtw88/usb.c @@ -720,9 +720,30 @@ static void rtw_usb_link_ps(struct rtw_dev *rtwdev, bool enter) /* empty function for rtw_hci_ops */ } +static void rtw_usb_init_burst_pkt_len(struct rtw_dev *rtwdev) +{ + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev); + enum usb_device_speed speed = rtwusb->udev->speed; + u8 rxdma, burst_size; + + rxdma = BIT_DMA_BURST_CNT | BIT_DMA_MODE; + + if (speed == USB_SPEED_SUPER) + burst_size = BIT_DMA_BURST_SIZE_1024; + else if (speed == USB_SPEED_HIGH) + burst_size = BIT_DMA_BURST_SIZE_512; + else + burst_size = BIT_DMA_BURST_SIZE_64; + + u8p_replace_bits(&rxdma, burst_size, BIT_DMA_BURST_SIZE); + + rtw_write8(rtwdev, REG_RXDMA_MODE, rxdma); + rtw_write16_set(rtwdev, REG_TXDMA_OFFSET_CHK, BIT_DROP_DATA_EN); +} + static void rtw_usb_interface_cfg(struct rtw_dev *rtwdev) { - /* empty function for rtw_hci_ops */ + rtw_usb_init_burst_pkt_len(rtwdev); } static struct rtw_hci_ops rtw_usb_ops = { From patchwork Tue Aug 6 17:41:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 13755128 X-Patchwork-Delegate: pkshih@realtek.com Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC3D022066 for ; Tue, 6 Aug 2024 17:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722966111; cv=none; b=cRmYtZcVdyl9N92DAsb0JW9vxpb2QajxtxzFYxG4wmQsCYRUW60fUXjHP9OnHzu4G9PH6l/wKysgkVjm37WIA19TAPf/J/1pNz6DbjJQm8SUAoPh4P0S1KvcoB4rQ4YMHm6kxY72adtaXdlcEAwbZonHFjV0/LpmI4ZBkRVbDXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722966111; c=relaxed/simple; bh=upiTBLlg7VxCx0CSSAePmJDlnlqmRC56LZHzO+bM1KU=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=J/36g8vsI1+ayleKoF56M91IODVLWZkyrtt0O3hNFEqVqARbBJcrBc+mWi6/cNXliuCbNXZ7MFubtqN13BssxlZQSGKN7jgBa+Mae1YBjduXrUhGtYTyX2/LHnzpZ5LMiP3UbZsbjECnDe6W5iExCNTZRHMaSD0gjCUvEQerJeE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LVnqE+Ha; arc=none smtp.client-ip=209.85.208.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LVnqE+Ha" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2f16d2f2b68so15516811fa.3 for ; Tue, 06 Aug 2024 10:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722966108; x=1723570908; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=slI+qX01R47ENT1ojgGknQ5DSnRZOPUCXDhz08hB2tY=; b=LVnqE+HaBWImyiCPWEmF7EGcQ6tLWsc2bK9IEclb3X2UldMDz/m36Y5hSfkHPDj+3I f6Zqc6BP8qF4a0q2EJDZnS8B69/lTk9X8WqRsI4DP27R6UQXfIvvIGWwI0kUwCecIVZ+ rbmb+JdE0BeDt3vDlzqjVAnzaQodGYhyZ/mCbfwXZWNe/ue13qsaMpcSKm5UYLHxj5af 1YuJf2fdnr3OIiv/+flA14KY3jIaIxnprXoKwPOExPVY86e+06NkDhBTCE8/0jUEQD4S HbIFVq5GdIfTI3QDKt+NudOttuNMsW6QNHSBN8a3N2Uwju12nd9CeDOQXTGDjqw22iQD JGNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722966108; x=1723570908; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=slI+qX01R47ENT1ojgGknQ5DSnRZOPUCXDhz08hB2tY=; b=lU7J14HZicFB5KVBjmXJJe87KxcyV/w2aQFqUTRbEc5Hw1PtzQp3YStus4E7lVVZU4 noEb3SgRXoD9pXLYLBgSPku48msha1u9x8HgYhtwiFNAWiFJonX5bEn0EsAzBqbAi6PS gc8PyuEx0scBc2LJcnuqc5VX6B0HADugZbfX/qgeh5b6vkJYkg9bC1GmnhNsqXoIvSUT B/LerDALHzrGktET11zGAInEWpizcNoCa+Zv22KCSd4xMQwoOqJLyWiuIq/pb5OnkExp QzRM7TWWRzoqSuArrgUz0PDv6Gsces95nKuGxjKktmF13ioYmgikPSPdVIcaPKk8jhlx BcJQ== X-Gm-Message-State: AOJu0Yy11itWhMGcqKUTMSBuQSd+vuFl/GvAhRY/dhZZv6mkfDDyi3qf EMnOzhKajIfo5ricwLc49KWk5aUQpSBv12u26pHe+1hw1O6hD8o9iycUGA== X-Google-Smtp-Source: AGHT+IHVE00Mt0v1z5+mmTTNYLPe5UK8SIPVyMKl2n4GRwE7HrCnlmo7SOyLRDVqCwMYKt+bhmYgSQ== X-Received: by 2002:a2e:9804:0:b0:2ef:24f3:fb9c with SMTP id 38308e7fff4ca-2f15ab2a4a3mr129487251fa.38.1722966107467; Tue, 06 Aug 2024 10:41:47 -0700 (PDT) Received: from [192.168.0.50] ([79.119.240.114]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9bc3cfesm567908966b.2.2024.08.06.10.41.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Aug 2024 10:41:47 -0700 (PDT) Message-ID: <780fc4fa-ffe6-40d9-b5f1-ae7efb9289aa@gmail.com> Date: Tue, 6 Aug 2024 20:41:46 +0300 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 2/4] wifi: rtw88: usb: Update the RX stats after every frame From: Bitterblue Smith To: "linux-wireless@vger.kernel.org" Cc: Ping-Ke Shih , Sascha Hauer References: Content-Language: en-US In-Reply-To: Update the number of received unicast data frames and bytes every time a frame is received. This is what the PCI and SDIO drivers do. This has an influence on the power saving, bluetooth coexistence, and (in a future patch) the use of RX aggregation. Tested with RTL8811CU and RTL8723DU. Tested-by: Sascha Hauer Signed-off-by: Bitterblue Smith --- v3: - Add Tested-by: Sascha Hauer v2: - Rebase on top of the latest rtw-next. --- drivers/net/wireless/realtek/rtw88/usb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c index 1c40d46a7eb4..10f1d724370e 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.c +++ b/drivers/net/wireless/realtek/rtw88/usb.c @@ -581,6 +581,7 @@ static void rtw_usb_rx_handler(struct work_struct *work) skb_reserve(skb, pkt_offset); rtw_update_rx_freq_for_invalid(rtwdev, skb, &rx_status, &pkt_stat); + rtw_rx_stats(rtwdev, pkt_stat.vif, skb); memcpy(skb->cb, &rx_status, sizeof(rx_status)); ieee80211_rx_irqsafe(rtwdev->hw, skb); } From patchwork Tue Aug 6 17:45:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 13755129 X-Patchwork-Delegate: pkshih@realtek.com Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51CCB3D0AD for ; Tue, 6 Aug 2024 17:45:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722966346; cv=none; b=Ax8qVb1I5hg9q8hPmD1zq1RroG9Sjv5zA8v27pwHD4QK8mdBOQqlX4Pr3tg4ot4ufwwIYnCiDfcw36CSuayyfkthGfYCcYhUW5R5sKjrPSORSQhA8FWeNcmBYa0BYbFpEqqhx8UNmigLW0N0y+FQ0tnlKikWsz9tuNxMlAya3QU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722966346; c=relaxed/simple; bh=qwp8f/6oLNNoDKE8g2OuXvofWoHsRonlEQIfZJgviyM=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=SANJbs3lidFB/xa9WDakjW69sMXEP7PM1YRzjdGI/1FkzIqzz+CnPd2syPqS9zU5g55NmcwbSdaZnahtq/n5870DZsIADIs5FUMPZDZaV6kZPimqDMVbcR7i7jrZbB+48WveaxI7NXJamKfVFemQ0udaM4xrdGBdL1ZRcgtVg+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aHgoggsG; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aHgoggsG" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-52f04b3cb33so2207057e87.0 for ; Tue, 06 Aug 2024 10:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722966342; x=1723571142; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=njw+nS9DRHdxmEl5+QU5MdQhy7Zg/xVhGhLV8YKYLH4=; b=aHgoggsGXhOjtR6hkVffssRRSM9xOPMpgFjzZY1goisalhAAyhHZ1SiVlwBIObTv10 oHQ8Hewr+YPkdy7OeDxKsMFwqnDXdrLkC5iirvg6nOeuK9swIyOIt43who0EiAb1GLD7 hjeDl7ci7YRZiLarpA8X1JLBLggHpCemFyMycvPIOob16WORIqt6OzpWDUi6sAFRUHtC UVtr6cHUE1+qfhA/M0CZYEi6s++osfKLESzk4VeDZbtFULOED1D7lTcZyWuVpafYgnU7 lxWlMLec3NAz+d2mFhNBmfB1Xbg589jHyDPNd8EU9UT6tImh2FUy61zB+3mCRtWpAFgw sOSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722966342; x=1723571142; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=njw+nS9DRHdxmEl5+QU5MdQhy7Zg/xVhGhLV8YKYLH4=; b=gPfWDBB6bI0hs/YUr9TXrM1YynWuUMSgZ4oYhH/Nzl1cSA5PrNVrIZ3BV5metUq9GB fg6/UhXnrh8RRTBsntCazOgH4Z/5XB0Xla3UzC9bC2Fj0yuokL/3z8+Bz43FTjZu62WT 9cQqsIRc18ruPKqOUY6kVu3goWN0m9DKX3+qEUZkh83fiud0jidESAIo1i7e+PbU9K1W 7G9N2Ix/uC1xhAUZp+1ITQmMpzWAkaroVLg7IxpvcQC38w6ndfj0ofVeWKD8xxwbE7nq nUB/nt/sZM+OCIR8ye8NeZw3Q4aZX9mFVuUjgbL+5RWkSltLkglRt1WQzoHG9foynEQT xWVQ== X-Gm-Message-State: AOJu0YwvO2E+Ve49CHJNA62nlM4UQuv1mZC+DzEUwzBqRqqpFFqBb/dQ Nj+/fQU2ldyL1mTgOpDMMKiKRgYJVvloY58FzxurVOyIDOX2O00i+DXd5A== X-Google-Smtp-Source: AGHT+IGeNKrXGNOm9/NBB2LK9a6wBJ6zDpk/QRkcPIw3AshlumdKqKX1yGh7tfgF22z/TUiQIbAQoQ== X-Received: by 2002:ac2:4bc1:0:b0:52c:c9e4:3291 with SMTP id 2adb3069b0e04-530bb3c193fmr11008014e87.60.1722966341976; Tue, 06 Aug 2024 10:45:41 -0700 (PDT) Received: from [192.168.0.50] ([79.119.240.114]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9d88650sm561377766b.152.2024.08.06.10.45.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Aug 2024 10:45:41 -0700 (PDT) Message-ID: <489fdb38-e191-4f73-98b5-882e49b2f3c1@gmail.com> Date: Tue, 6 Aug 2024 20:45:38 +0300 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 3/4] wifi: rtw88: usb: Support RX aggregation From: Bitterblue Smith To: "linux-wireless@vger.kernel.org" Cc: Ping-Ke Shih , Sascha Hauer References: Content-Language: en-US In-Reply-To: The chips can be configured to aggregate several frames into a single USB transfer. Modify rtw_usb_rx_handler() to support this case. RX aggregation improves the RX speed on certain ARM systems, like the NanoPi NEO Core2. Currently none of the chips are configured to aggregate frames. Tested with RTL8811CU and RTL8723DU. Reviewed-by: Sascha Hauer Tested-by: Sascha Hauer Signed-off-by: Bitterblue Smith --- v3: - Don't initialise next_skb. - Add Tested-by and Reviewed-by: Sascha Hauer v2: - Simplify the code and make it more readable. - Rebase on top of latest rtw-next. --- drivers/net/wireless/realtek/rtw88/usb.c | 61 ++++++++++++++++-------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c index 10f1d724370e..4c7ba5c76a57 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.c +++ b/drivers/net/wireless/realtek/rtw88/usb.c @@ -546,11 +546,12 @@ static void rtw_usb_rx_handler(struct work_struct *work) struct rtw_usb *rtwusb = container_of(work, struct rtw_usb, rx_work); struct rtw_dev *rtwdev = rtwusb->rtwdev; const struct rtw_chip_info *chip = rtwdev->chip; - struct rtw_rx_pkt_stat pkt_stat; + u32 pkt_desc_sz = chip->rx_pkt_desc_sz; struct ieee80211_rx_status rx_status; + u32 pkt_offset, next_pkt, urb_len; + struct rtw_rx_pkt_stat pkt_stat; + struct sk_buff *next_skb; struct sk_buff *skb; - u32 pkt_desc_sz = chip->rx_pkt_desc_sz; - u32 pkt_offset; u8 *rx_desc; int limit; @@ -559,31 +560,48 @@ static void rtw_usb_rx_handler(struct work_struct *work) if (!skb) break; - rx_desc = skb->data; - chip->ops->query_rx_desc(rtwdev, rx_desc, &pkt_stat, - &rx_status); - pkt_offset = pkt_desc_sz + pkt_stat.drv_info_sz + - pkt_stat.shift; - - if (pkt_stat.is_c2h) { - skb_put(skb, pkt_stat.pkt_len + pkt_offset); - rtw_fw_c2h_cmd_rx_irqsafe(rtwdev, pkt_offset, skb); - continue; - } - if (skb_queue_len(&rtwusb->rx_queue) >= RTW_USB_MAX_RXQ_LEN) { dev_dbg_ratelimited(rtwdev->dev, "failed to get rx_queue, overflow\n"); dev_kfree_skb_any(skb); continue; } - skb_put(skb, pkt_stat.pkt_len); - skb_reserve(skb, pkt_offset); + urb_len = skb->len; + + do { + rx_desc = skb->data; + chip->ops->query_rx_desc(rtwdev, rx_desc, &pkt_stat, + &rx_status); + pkt_offset = pkt_desc_sz + pkt_stat.drv_info_sz + + pkt_stat.shift; + + next_pkt = round_up(pkt_stat.pkt_len + pkt_offset, 8); + + if (urb_len >= next_pkt + pkt_desc_sz) + next_skb = skb_clone(skb, GFP_KERNEL); + else + next_skb = NULL; + + if (pkt_stat.is_c2h) { + skb_trim(skb, pkt_stat.pkt_len + pkt_offset); + rtw_fw_c2h_cmd_rx_irqsafe(rtwdev, pkt_offset, skb); + } else { + skb_pull(skb, pkt_offset); + skb_trim(skb, pkt_stat.pkt_len); + rtw_update_rx_freq_for_invalid(rtwdev, skb, + &rx_status, + &pkt_stat); + rtw_rx_stats(rtwdev, pkt_stat.vif, skb); + memcpy(skb->cb, &rx_status, sizeof(rx_status)); + ieee80211_rx_irqsafe(rtwdev->hw, skb); + } + + skb = next_skb; + if (skb) + skb_pull(skb, next_pkt); - rtw_update_rx_freq_for_invalid(rtwdev, skb, &rx_status, &pkt_stat); - rtw_rx_stats(rtwdev, pkt_stat.vif, skb); - memcpy(skb->cb, &rx_status, sizeof(rx_status)); - ieee80211_rx_irqsafe(rtwdev->hw, skb); + urb_len -= next_pkt; + } while (skb); } } @@ -627,6 +645,7 @@ static void rtw_usb_read_port_complete(struct urb *urb) if (skb) dev_kfree_skb_any(skb); } else { + skb_put(skb, urb->actual_length); skb_queue_tail(&rtwusb->rx_queue, skb); queue_work(rtwusb->rxwq, &rtwusb->rx_work); } From patchwork Tue Aug 6 17:47:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bitterblue Smith X-Patchwork-Id: 13755130 X-Patchwork-Delegate: pkshih@realtek.com Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9688F762EF for ; Tue, 6 Aug 2024 17:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722966461; cv=none; b=sodDgwd+slpt5OcKBMp3OduKQGUhGkPuqCy6CrAgQNFbMesjVSX7O0Y+QvafJSikWUX5KnwlChj3xRKoLz//qTpgyiGm0NZXmSuDMcvJzlmM5oftzh17vR1x6TymG+2qE2OJeDqU8FPk9DdfqFjgD1npB7jQkultkRrjkckHLvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722966461; c=relaxed/simple; bh=F1Xqqw5H1d6LJpgWNtIHaaR0eHJG4G3BgRkpUgm5ypk=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=GuQAr7EEA6Ke6Z6+MjzGQMWGUNdvX+yDqKI6xsvpifXzqoRsJGWU4p2bHDwlZLJhOcAoGi+IEpfUTzl+7NiQzMc3Spa1UwZ5A93XENiPHNYQxpAuHWEzOzxrosWU8Yab+a/XFdrbEzeu1mLrCNimyUkAkUlehAe4QWqY7K7Frl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JH2w2BoO; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JH2w2BoO" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a7ad02501c3so92533866b.2 for ; Tue, 06 Aug 2024 10:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722966458; x=1723571258; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=iD5zmmU44/dH61DO+JJYxKDQxPxwOjlmbQ3tJbwIFf0=; b=JH2w2BoOIhM7GWrPVPhnIXkBgJUQFKEu+PP+whgp5BUmeDgZuf50Q8ytZwYyPT17b+ UOTFDMpn/vXSBl+WknxFaxaCLdrzCNqPD+w31fGMPyjnFmwcLqZWeBr1xmIs43Ad2Hn8 cf51kOs/2rzd7BITz2kw3gXkzLZhr5TSGeG/o0AXA01I9SWqYAWcT0yNMh2fJT2S4xpX uwDm7XZ+tPO04uTdQTXwnAJoe2q4YFxwXZksKwvXXxjtMx560s6uzxo35FCEcDlnkz5o JgqjwpM+9gP+kAQwM7+rks9+nbv2HAb9R55lukBrv8PFaRlvDCGI+pOFEwT2wZABYpWa pdEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722966458; x=1723571258; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iD5zmmU44/dH61DO+JJYxKDQxPxwOjlmbQ3tJbwIFf0=; b=HCaXngh7K25HnZhLqcfOZxFXvixjlOWGE1HMI9kGq1ywK5HqZtPTtzSdkb74nnT1As l/uByQsgZCtYCs9cd4PRzCOEowBI4ce3NDbYEMRjsVZIKzvFuVNzjMjirDWFVt4PxS/R RQqvBuKmf1+krk1hPY+DyNMuz8b9/1mEToSYcjDY8YDdsATdaXWp/bNN93lGIKsfBmgf OCJVUpPRklcKUCxL1oU2VeCQQ3qR2x6RSIe3qFTmZnoy97HKR5T/Yht8R8Z9HVk7Wfky 4ckFhbmI4xxh6YjsPvuQSUelbw+dUMvL/Gfpvlsflzn9jdiNZlEIgp5/5hHPPTQhSq2T NuuA== X-Gm-Message-State: AOJu0YySO+FXbgKXgEeWhqLA8w3pS2zMFafd2Wekn2nMA1f8CcCstKZ1 7uHWy8kfW5Wu/ovK0QXMPLbRUPFSWmJjfxVWldlSnZJP6bdh4RlPZsoXtg== X-Google-Smtp-Source: AGHT+IEYpN2N7OrZdWozvLORzvd0sl5GL3UY+uCvT2P30MrZHfNn1LvQWLrUbN4wXamfUwUZMwVt5Q== X-Received: by 2002:a17:906:c115:b0:a7d:9f92:9107 with SMTP id a640c23a62f3a-a7dc51bdf6cmr1051189966b.58.1722966457550; Tue, 06 Aug 2024 10:47:37 -0700 (PDT) Received: from [192.168.0.50] ([79.119.240.114]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9c0b6casm564509766b.51.2024.08.06.10.47.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Aug 2024 10:47:37 -0700 (PDT) Message-ID: <3b7b3655-9ec5-4277-b0ff-5535b1fdf281@gmail.com> Date: Tue, 6 Aug 2024 20:47:35 +0300 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 4/4] wifi: rtw88: Enable USB RX aggregation for 8822c/8822b/8821c From: Bitterblue Smith To: "linux-wireless@vger.kernel.org" Cc: Ping-Ke Shih , Sascha Hauer References: Content-Language: en-US In-Reply-To: Enable USB RX aggregation when there is at least 1 Mbps RX or TX traffic, otherwise disable it. USB RX aggregation improves the RX speed on certain ARM systems, like the NanoPi NEO Core2. With RTL8821CU, before: 28 Mbps, after: 231 Mbps. The official drivers for these chips use the same logic for SDIO, but for some reason the SDIO driver in rtw88 always enables RX aggregation, so this patch only toggles aggregation for USB devices. RTL8703B is likely not found in USB devices, and RTL8723DU doesn't like aggregation. Tested-by: Sascha Hauer Signed-off-by: Bitterblue Smith --- v3: - Add Tested-by: Sascha Hauer v2: - Rename {tx,rx}_unicast_shift to {tx,rx}_unicast_mbps. - Move the RX aggregation code from rtw8822c.c, rtw8822b.c, rtw8821c.c to usb.c. - Delete the rx_aggregation member from struct rtw_chip_ops and add dynamic_rx_agg member to struct rtw_hci_ops. - Rebase on top of the latest rtw-next. --- drivers/net/wireless/realtek/rtw88/hci.h | 7 ++++ drivers/net/wireless/realtek/rtw88/main.c | 13 +++++--- drivers/net/wireless/realtek/rtw88/pci.c | 1 + drivers/net/wireless/realtek/rtw88/sdio.c | 1 + drivers/net/wireless/realtek/rtw88/usb.c | 40 +++++++++++++++++++++++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/hci.h b/drivers/net/wireless/realtek/rtw88/hci.h index 830d7532f2a3..96aeda26014e 100644 --- a/drivers/net/wireless/realtek/rtw88/hci.h +++ b/drivers/net/wireless/realtek/rtw88/hci.h @@ -18,6 +18,7 @@ struct rtw_hci_ops { void (*deep_ps)(struct rtw_dev *rtwdev, bool enter); void (*link_ps)(struct rtw_dev *rtwdev, bool enter); void (*interface_cfg)(struct rtw_dev *rtwdev); + void (*dynamic_rx_agg)(struct rtw_dev *rtwdev, bool enable); int (*write_data_rsvd_page)(struct rtw_dev *rtwdev, u8 *buf, u32 size); int (*write_data_h2c)(struct rtw_dev *rtwdev, u8 *buf, u32 size); @@ -72,6 +73,12 @@ static inline void rtw_hci_interface_cfg(struct rtw_dev *rtwdev) rtwdev->hci.ops->interface_cfg(rtwdev); } +static inline void rtw_hci_dynamic_rx_agg(struct rtw_dev *rtwdev, bool enable) +{ + if (rtwdev->hci.ops->dynamic_rx_agg) + rtwdev->hci.ops->dynamic_rx_agg(rtwdev, enable); +} + static inline int rtw_hci_write_data_rsvd_page(struct rtw_dev *rtwdev, u8 *buf, u32 size) { diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c index 9c58b7a41b95..fd944248e6e7 100644 --- a/drivers/net/wireless/realtek/rtw88/main.c +++ b/drivers/net/wireless/realtek/rtw88/main.c @@ -212,6 +212,7 @@ static void rtw_watch_dog_work(struct work_struct *work) struct rtw_traffic_stats *stats = &rtwdev->stats; struct rtw_watch_dog_iter_data data = {}; bool busy_traffic = test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags); + u32 tx_unicast_mbps, rx_unicast_mbps; bool ps_active; mutex_lock(&rtwdev->mutex); @@ -236,13 +237,17 @@ static void rtw_watch_dog_work(struct work_struct *work) else ps_active = false; - ewma_tp_add(&stats->tx_ewma_tp, - (u32)(stats->tx_unicast >> RTW_TP_SHIFT)); - ewma_tp_add(&stats->rx_ewma_tp, - (u32)(stats->rx_unicast >> RTW_TP_SHIFT)); + tx_unicast_mbps = stats->tx_unicast >> RTW_TP_SHIFT; + rx_unicast_mbps = stats->rx_unicast >> RTW_TP_SHIFT; + + ewma_tp_add(&stats->tx_ewma_tp, tx_unicast_mbps); + ewma_tp_add(&stats->rx_ewma_tp, rx_unicast_mbps); stats->tx_throughput = ewma_tp_read(&stats->tx_ewma_tp); stats->rx_throughput = ewma_tp_read(&stats->rx_ewma_tp); + rtw_hci_dynamic_rx_agg(rtwdev, + tx_unicast_mbps >= 1 || rx_unicast_mbps >= 1); + /* reset tx/rx statictics */ stats->tx_unicast = 0; stats->rx_unicast = 0; diff --git a/drivers/net/wireless/realtek/rtw88/pci.c b/drivers/net/wireless/realtek/rtw88/pci.c index 5d0580da13fb..0b9b8807af2c 100644 --- a/drivers/net/wireless/realtek/rtw88/pci.c +++ b/drivers/net/wireless/realtek/rtw88/pci.c @@ -1601,6 +1601,7 @@ static struct rtw_hci_ops rtw_pci_ops = { .deep_ps = rtw_pci_deep_ps, .link_ps = rtw_pci_link_ps, .interface_cfg = rtw_pci_interface_cfg, + .dynamic_rx_agg = NULL, .read8 = rtw_pci_read8, .read16 = rtw_pci_read16, diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c index 763aa8212a4b..21d0754dd7f6 100644 --- a/drivers/net/wireless/realtek/rtw88/sdio.c +++ b/drivers/net/wireless/realtek/rtw88/sdio.c @@ -1157,6 +1157,7 @@ static struct rtw_hci_ops rtw_sdio_ops = { .deep_ps = rtw_sdio_deep_ps, .link_ps = rtw_sdio_link_ps, .interface_cfg = rtw_sdio_interface_cfg, + .dynamic_rx_agg = NULL, .read8 = rtw_sdio_read8, .read16 = rtw_sdio_read16, diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c index 4c7ba5c76a57..cbb5e17e65d1 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.c +++ b/drivers/net/wireless/realtek/rtw88/usb.c @@ -766,6 +766,45 @@ static void rtw_usb_interface_cfg(struct rtw_dev *rtwdev) rtw_usb_init_burst_pkt_len(rtwdev); } +static void rtw_usb_dynamic_rx_agg_v1(struct rtw_dev *rtwdev, bool enable) +{ + u8 size, timeout; + u16 val16; + + rtw_write32_set(rtwdev, REG_RXDMA_AGG_PG_TH, BIT_EN_PRE_CALC); + rtw_write8_set(rtwdev, REG_TXDMA_PQ_MAP, BIT_RXDMA_AGG_EN); + rtw_write8_clr(rtwdev, REG_RXDMA_AGG_PG_TH + 3, BIT(7)); + + if (enable) { + size = 0x5; + timeout = 0x20; + } else { + size = 0x0; + timeout = 0x1; + } + val16 = u16_encode_bits(size, BIT_RXDMA_AGG_PG_TH) | + u16_encode_bits(timeout, BIT_DMA_AGG_TO_V1); + + rtw_write16(rtwdev, REG_RXDMA_AGG_PG_TH, val16); +} + +static void rtw_usb_dynamic_rx_agg(struct rtw_dev *rtwdev, bool enable) +{ + switch (rtwdev->chip->id) { + case RTW_CHIP_TYPE_8822C: + case RTW_CHIP_TYPE_8822B: + case RTW_CHIP_TYPE_8821C: + rtw_usb_dynamic_rx_agg_v1(rtwdev, enable); + break; + case RTW_CHIP_TYPE_8723D: + /* Doesn't like aggregation. */ + break; + case RTW_CHIP_TYPE_8703B: + /* Likely not found in USB devices. */ + break; + } +} + static struct rtw_hci_ops rtw_usb_ops = { .tx_write = rtw_usb_tx_write, .tx_kick_off = rtw_usb_tx_kick_off, @@ -775,6 +814,7 @@ static struct rtw_hci_ops rtw_usb_ops = { .deep_ps = rtw_usb_deep_ps, .link_ps = rtw_usb_link_ps, .interface_cfg = rtw_usb_interface_cfg, + .dynamic_rx_agg = rtw_usb_dynamic_rx_agg, .write8 = rtw_usb_write8, .write16 = rtw_usb_write16,