Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8543018rwb; Thu, 24 Nov 2022 00:35:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf4FWIYAnYzh3/asdpPFCtrfwnjQEy1z/LsMpazY6xCob7X5GJTf8ombOzQXQ5rX6rU2nFQA X-Received: by 2002:a63:e505:0:b0:44a:2a6a:bb90 with SMTP id r5-20020a63e505000000b0044a2a6abb90mr30187654pgh.314.1669278901396; Thu, 24 Nov 2022 00:35:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669278901; cv=none; d=google.com; s=arc-20160816; b=P9ky2mO7i0X0Od74qjl/e84jZMUdj6UH8vkDUC/N+4qI1t7Ga5t80Xs+WXyv4vOQ4+ uzhKdrM+NNq6CvgxjU71d3C5DTBgVlrvEb8inzctPlp+h4vTVwa7OMsFSIxN72BAz4di vLE0mukaPiQRSqWUlapNg4f36bLC2cdGG1obEX1bnLFk4N0K8ud/Tk3kxU+X2m1X7CqW hYQvR9ieBg8UVksxUqFcC6qOwvPAWP+1fw8od9c6wE+vEwzlqyTFmMH0E41Q7xvIk7dO n6PzQ8zZwyjkIT/LuhS7/ORPcHHIuO74/3UwSIwSF1pAHdg+/Zy1lTPioR9/5EbyGhwD ovXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:from:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date; bh=KbKueYmjg4s1/xCID4EK2lqkf973XmQ8uAGC44vFLvc=; b=bNaACCk81XH2X5lb1PTvKnbrJipACazdnXfXjFUgbKUM7vzmH4Zvnjbekl1sw90pZd HdiEBGN9Zbu9k0AcOTFYFaw1BVSZFwNRwe7IrcmJoJaGP1fv5O1lP0LR6mKcIr1k9whv FailQe1/A0BOIRDiGwkJLtY9+3h3/ef1ixxns3CQPE/rLxCLjErXfdFHZdvB/w6SwI9A Lq7FqGV/xZkjSvLwwCPrAJSPG+AWBj4SOvS5ufI0a69UnvQok3Chd0LSMmMyAvt8mhGu F5MnRdlPTZ+yC/Ur6mTGsH1rjuQ8kyA76OCQFbVjRL8lYd2Bkmvd+kjEmLIONfWGyW4P /Lzg== 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 74-20020a63044d000000b00476a48051edsi597731pge.476.2022.11.24.00.34.52; Thu, 24 Nov 2022 00:35:01 -0800 (PST) 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 S229645AbiKXI3H (ORCPT + 68 others); Thu, 24 Nov 2022 03:29:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiKXI3H (ORCPT ); Thu, 24 Nov 2022 03:29:07 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EC997DED2 for ; Thu, 24 Nov 2022 00:29:06 -0800 (PST) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oy7bN-00076W-SS; Thu, 24 Nov 2022 09:28:57 +0100 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1oy7bN-0006DA-A1; Thu, 24 Nov 2022 09:28:57 +0100 Date: Thu, 24 Nov 2022 09:28:57 +0100 To: Ping-Ke Shih Cc: tony0620emma@gmail.com, kvalo@kernel.org, neo_jou@realtek.com, linux-wireless@vger.kernel.org Subject: Re: [PATCH] wifi: rtw88: fix race condition when doing H2C command Message-ID: <20221124082857.GA23682@pengutronix.de> References: <20221124064442.28042-1-pkshih@realtek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221124064442.28042-1-pkshih@realtek.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain User-Agent: Mutt/1.10.1 (2018-07-13) From: Sascha Hauer X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 On Thu, Nov 24, 2022 at 02:44:42PM +0800, Ping-Ke Shih wrote: > From: Ji-Pin Jou > > For SDIO/USB interface, since the tranferring speed is slower than > that in PCIE, it may have race condition when the driver sets down > H2C command to the FW. > > In the function rtw_fw_send_h2c_command, before the patch, box_reg > is written first, then box_ex_reg is written. FW starts to work and > fetch the value of box_ex_reg, when the most significant byte of > box_reg(4 bytes) is written. Meanwhile, for SDIO/USB interface, > since the transferring speed is slow, the driver is still in writing > the new value of box_ex_reg through the bus, and FW may get the > wrong value of box_ex_reg at the moment. > > To prevent the above driver/FW racing situation, box_ex_reg is > written first then box_reg. Furthermore, it is written in 4 bytes at > a time, instead of written in one byte one by one. It can increase > the speed for SDIO/USB interface. > > Signed-off-by: Ji-Pin Jou > Signed-off-by: Ping-Ke Shih This solves the issue with the RTW88 USB patch set reported here: https://lore.kernel.org/linux-wireless/20221122145527.GA29978@pengutronix.de/ Tested-by: Sascha Hauer Sascha > --- > drivers/net/wireless/realtek/rtw88/fw.c | 8 +++----- > drivers/net/wireless/realtek/rtw88/fw.h | 5 +++++ > 2 files changed, 8 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/wireless/realtek/rtw88/fw.c b/drivers/net/wireless/realtek/rtw88/fw.c > index 0b5f903c0f366..b290811d75e1c 100644 > --- a/drivers/net/wireless/realtek/rtw88/fw.c > +++ b/drivers/net/wireless/realtek/rtw88/fw.c > @@ -311,10 +311,10 @@ EXPORT_SYMBOL(rtw_fw_c2h_cmd_isr); > static void rtw_fw_send_h2c_command(struct rtw_dev *rtwdev, > u8 *h2c) > { > + struct rtw_h2c_cmd *h2c_cmd = (struct rtw_h2c_cmd *)h2c; > u8 box; > u8 box_state; > u32 box_reg, box_ex_reg; > - int idx; > int ret; > > rtw_dbg(rtwdev, RTW_DBG_FW, > @@ -356,10 +356,8 @@ static void rtw_fw_send_h2c_command(struct rtw_dev *rtwdev, > goto out; > } > > - for (idx = 0; idx < 4; idx++) > - rtw_write8(rtwdev, box_reg + idx, h2c[idx]); > - for (idx = 0; idx < 4; idx++) > - rtw_write8(rtwdev, box_ex_reg + idx, h2c[idx + 4]); > + rtw_write32(rtwdev, box_ex_reg, le32_to_cpu(h2c_cmd->msg_ext)); > + rtw_write32(rtwdev, box_reg, le32_to_cpu(h2c_cmd->msg)); > > if (++rtwdev->h2c.last_box_num >= 4) > rtwdev->h2c.last_box_num = 0; > diff --git a/drivers/net/wireless/realtek/rtw88/fw.h b/drivers/net/wireless/realtek/rtw88/fw.h > index a5a965803a3cc..bca610dc99ab7 100644 > --- a/drivers/net/wireless/realtek/rtw88/fw.h > +++ b/drivers/net/wireless/realtek/rtw88/fw.h > @@ -81,6 +81,11 @@ struct rtw_c2h_adaptivity { > u8 option; > } __packed; > > +struct rtw_h2c_cmd { > + __le32 msg; > + __le32 msg_ext; > +} __packed; > + > enum rtw_rsvd_packet_type { > RSVD_BEACON, > RSVD_DUMMY, > -- > 2.25.1 > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |