Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2331406rwd; Sun, 21 May 2023 18:49:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ73ioomVC0bBow+6dZzTKJLMBlEbC0C3APhqV9dbZdxokY91Gxh/pOdgiC1lB9qfDHcD8PO X-Received: by 2002:a05:6a20:d817:b0:101:2160:ff8f with SMTP id iv23-20020a056a20d81700b001012160ff8fmr9002019pzb.11.1684720173201; Sun, 21 May 2023 18:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684720173; cv=none; d=google.com; s=arc-20160816; b=Y94On5O+ymVMJI7Q11eJG+7t/Gj8ytXYcbFD84fiVIplFTchaaSqusx0u1jmo7/vzz Bec3oocBHXjkYpqCjjeYDG1BqtgqDNJi+7t4/Ypzr9WfZ3TFOz9l2ebcdtzlhouTRFjX MlTMcyrpqsTcr7tLBJl3s4uguVcGnvND+RcfDPSoLqSJKaeJBOX/m00LgzrcbvfsRCcy sz4A9xfnOo+g4zgQyvkR62wx2kZVLvVcA0gWYBJvbypYWxqISE+/meDKjQzLoyi9KSoY ZTTBrl3HdXfchMM/y8o6EsHdUfA0A/a78X45oCkNyVu/fdVrdVylAA9DYDj2+UbUu457 BTVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:authenticated-by; bh=1sVb7pZdxlB3KKpZx388il3URO3/EMeh1ON3G1/dzEg=; b=c0IUE560Yvljf4MPzFmVPbqRiYkZ8tR7TO7QorVqUlHeDYluhL1a7GgYZXh1/AixcZ GqTSbYJSckRxkcN29eSSNuAVmHquQuJY2GT7KTpg7aSFBW1qupZbyfkfGbXUC5uhAbhz 1PaZTORBzkqvDe7aKBCqUH0EknFCRSVn+ES3OJ450j/gHBhmRhmYT4fnLe0Bvnu7V1bD PDBixuQpTHPsyVgdQ62FDkIRsEZEUjq7oGTPzf675pG/ZD1SSrXwS7xG9yGb8rNxv5Kp Y8HDlrLct4FVOIHRE0GpTay6TW2yd6tmR2IyqxtPKLKsFKxilRc17nkl4LOiW1b3Tyms bOng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020a63ab4d000000b0051e011fcd73si3817738pgp.237.2023.05.21.18.49.19; Sun, 21 May 2023 18:49:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231386AbjEVBnZ convert rfc822-to-8bit (ORCPT + 63 others); Sun, 21 May 2023 21:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbjEVBnY (ORCPT ); Sun, 21 May 2023 21:43:24 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24182AF; Sun, 21 May 2023 18:43:20 -0700 (PDT) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 34M1go4iB030448, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.81/5.90) with ESMTPS id 34M1go4iB030448 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK); Mon, 22 May 2023 09:42:50 +0800 Received: from RTEXMBS05.realtek.com.tw (172.21.6.98) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Mon, 22 May 2023 09:43:01 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXMBS05.realtek.com.tw (172.21.6.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 22 May 2023 09:43:00 +0800 Received: from RTEXMBS04.realtek.com.tw ([fe80::e138:e7f1:4709:ff4d]) by RTEXMBS04.realtek.com.tw ([fe80::e138:e7f1:4709:ff4d%5]) with mapi id 15.01.2375.007; Mon, 22 May 2023 09:43:00 +0800 From: Ping-Ke Shih To: Martin Blumenstingl , "linux-wireless@vger.kernel.org" CC: "linux-mmc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "ulf.hansson@linaro.org" , "kvalo@kernel.org" , "tony0620emma@gmail.com" , "Peter Robinson" , "jernej.skrabec@gmail.com" Subject: RE: [PATCH wireless-next v1 1/4] wifi: rtw88: sdio: Check the HISR RX_REQUEST bit in rtw_sdio_rx_isr() Thread-Topic: [PATCH wireless-next v1 1/4] wifi: rtw88: sdio: Check the HISR RX_REQUEST bit in rtw_sdio_rx_isr() Thread-Index: AQHZiaRUyNopi6TOU06ASkVQiZhTKq9liWyA Date: Mon, 22 May 2023 01:43:00 +0000 Message-ID: References: <20230518161749.1311949-1-martin.blumenstingl@googlemail.com> <20230518161749.1311949-2-martin.blumenstingl@googlemail.com> In-Reply-To: <20230518161749.1311949-2-martin.blumenstingl@googlemail.com> Accept-Language: en-US, zh-TW Content-Language: zh-TW X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.21.69.188] x-kse-serverinfo: RTEXMBS05.realtek.com.tw, 9 x-kse-antispam-interceptor-info: fallback x-kse-antivirus-interceptor-info: fallback Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org > -----Original Message----- > From: Martin Blumenstingl > Sent: Friday, May 19, 2023 12:18 AM > To: linux-wireless@vger.kernel.org > Cc: linux-mmc@vger.kernel.org; linux-kernel@vger.kernel.org; ulf.hansson@linaro.org; kvalo@kernel.org; > tony0620emma@gmail.com; Peter Robinson ; Ping-Ke Shih ; > jernej.skrabec@gmail.com; Martin Blumenstingl > Subject: [PATCH wireless-next v1 1/4] wifi: rtw88: sdio: Check the HISR RX_REQUEST bit in rtw_sdio_rx_isr() > > rtw_sdio_rx_isr() is responsible for receiving data from the wifi chip > and is called from the SDIO interrupt handler when the interrupt status > register (HISR) has the RX_REQUEST bit set. After the first batch of > data has been processed by the driver the wifi chip may have more data > ready to be read, which is managed by a loop in rtw_sdio_rx_isr(). > > It turns out that there are cases where the RX buffer length (from the > REG_SDIO_RX0_REQ_LEN register) does not match the data we receive. The > following two cases were observed with a RTL8723DS card: > - RX length is smaller than the total packet length including overhead > and actual data bytes (whose length is part of the buffer we read from > the wifi chip and is stored in rtw_rx_pkt_stat.pkt_len). This can > result in errors like: > skbuff: skb_over_panic: text:ffff8000011924ac len:3341 put:3341 > (one case observed was: RX buffer length = 1536 bytes but > rtw_rx_pkt_stat.pkt_len = 1546 bytes, this is not valid as it means > we need to read beyond the end of the buffer) > - RX length looks valid but rtw_rx_pkt_stat.pkt_len is zero > > Check if the RX_REQUEST is set in the HISR register for each iteration > inside rtw_sdio_rx_isr(). This mimics what the RTL8723DS vendor driver > does and makes the driver only read more data if the RX_REQUEST bit is > set (which seems to be a way for the card's hardware or firmware to > tell the host that data is ready to be processed). > > For RTW_WCPU_11AC chips this check is not needed. The RTL8822BS vendor > driver for example states that this check is unnecessary (but still uses > it) and the RTL8822CS drops this check entirely. > > Signed-off-by: Martin Blumenstingl > --- > drivers/net/wireless/realtek/rtw88/sdio.c | 23 ++++++++++++++++++++--- > 1 file changed, 20 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c > index 06fce7c3adda..32b8c9194b2c 100644 > --- a/drivers/net/wireless/realtek/rtw88/sdio.c > +++ b/drivers/net/wireless/realtek/rtw88/sdio.c > @@ -998,9 +998,9 @@ static void rtw_sdio_rxfifo_recv(struct rtw_dev *rtwdev, u32 rx_len) > > static void rtw_sdio_rx_isr(struct rtw_dev *rtwdev) > { > - u32 rx_len, total_rx_bytes = 0; > + u32 rx_len, hisr, total_rx_bytes = 0; > > - while (total_rx_bytes < SZ_64K) { > + do { > if (rtw_chip_wcpu_11n(rtwdev)) > rx_len = rtw_read16(rtwdev, REG_SDIO_RX0_REQ_LEN); > else > @@ -1012,7 +1012,24 @@ static void rtw_sdio_rx_isr(struct rtw_dev *rtwdev) > rtw_sdio_rxfifo_recv(rtwdev, rx_len); > > total_rx_bytes += rx_len; > - } > + > + if (rtw_chip_wcpu_11n(rtwdev)) > + /* Stop if no more RX requests are pending, even if > + * rx_len could be greater than zero in the next > + * iteration. This is needed because the RX buffer may > + * already contain data while either HW or FW are not > + * done filling that buffer yet. Still reading the > + * buffer can result in packets where > + * rtw_rx_pkt_stat.pkt_len is zero or points beyond the > + * end of the buffer. > + */ > + hisr = rtw_read32(rtwdev, REG_SDIO_HISR); > + else > + /* RTW_WCPU_11AC chips have improved hardware or > + * firmware and can use rx_len unconditionally. > + */ > + hisr = REG_SDIO_HISR_RX_REQUEST; nit: adding braces to these branches would be clearer. If not, this patch still looks good to me, so Reviewed-by: Ping-Ke Shih > + } while (total_rx_bytes < SZ_64K && hisr & REG_SDIO_HISR_RX_REQUEST); > } > > static void rtw_sdio_handle_interrupt(struct sdio_func *sdio_func) > -- > 2.40.1