Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp259840rwb; Mon, 28 Nov 2022 20:28:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Ke+GrU7pTQTxqg64pQHWpwcUkyQeC0disamQoejpaHErKlYl4Lh/McvjTk12ofYr/mK1n X-Received: by 2002:a05:6402:444a:b0:459:401:c23e with SMTP id o10-20020a056402444a00b004590401c23emr35873424edb.23.1669696129820; Mon, 28 Nov 2022 20:28:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669696129; cv=none; d=google.com; s=arc-20160816; b=KaVqqu2rc77DqTchcusSAFmjmnfctYjIFMePA9P9GzfOz6CDE7EAnPmSeHqIGGoY3Y Th8cTZ8PtfJBmXorsa8yYzo2aklvF16/vR+1e5uBLxR4YhF+tv2YddAZzh8BWFw6LcMt OS3qU9zOzbObfnbNkTOBgfKyXLroHtZgoCexQ4sOcnvoWC4C5hlpuGf5miu7b6TvDJVF RDRVd+SXhnZLfamuqcgixWlqX9jpmtY+cXKj7MZHsSr84PEldRhTPUxlKqj+08a9Fm+M SB454L0r8uceuYFWcT8HmGcDd2AaF0kkNKnLQ+2bTHQdRsy7EdFROVi0oAoMYDFgP0bI KfvQ== 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=OZlzhIdpaq88t7fhbDHz6wMSFfLdVsC/6uNn1fjaEOw=; b=JKIHwxaYEOFqBD5zPwW/a+lFL0CJ6b19nbU4pVlsmMMWG21nCVL3+RkUKe5krXZytv aj9lFCj8+e4mFY5dlZSfqBLt3WFfilrkFylA1626rHNGOCiX6xuNLUf0c5xVc702ZxVP pToLF3ZKqiQrU+HtwPqTMICj70au2AGG6ODdBu8aL/PD1bqHpmas0oC91Gx2Efr0XKQC zRh9Xpf2r3mT9sdEXj3r35UhIxPJyrvd3SP0IplcrcBlxnn8W1Z4Mfg3uk0+jt4rkyfi /6QjCkkksAI366rEXADU854k8opAdmhioBrIcbXLpd43yYdiODSYENwAl2Ww19dHneep cl2A== 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 cf26-20020a0564020b9a00b0046b51067317si2484551edb.301.2022.11.28.20.28.28; Mon, 28 Nov 2022 20:28:49 -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 S235259AbiK2ESb convert rfc822-to-8bit (ORCPT + 67 others); Mon, 28 Nov 2022 23:18:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbiK2ES3 (ORCPT ); Mon, 28 Nov 2022 23:18:29 -0500 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C831EBE4 for ; Mon, 28 Nov 2022 20:18:27 -0800 (PST) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 2AT4HS6x8028673, 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 2AT4HS6x8028673 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Tue, 29 Nov 2022 12:17:28 +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.9; Tue, 29 Nov 2022 12:18:12 +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; Tue, 29 Nov 2022 12:18:12 +0800 Received: from RTEXMBS04.realtek.com.tw ([fe80::15b5:fc4b:72f3:424b]) by RTEXMBS04.realtek.com.tw ([fe80::15b5:fc4b:72f3:424b%5]) with mapi id 15.01.2375.007; Tue, 29 Nov 2022 12:18:12 +0800 From: Ping-Ke Shih To: Kalle Valo CC: Kevin Yang , "linux-wireless@vger.kernel.org" Subject: RE: [PATCH 3/6] wifi: rtw89: introduce helpers to wait/complete on condition Thread-Topic: [PATCH 3/6] wifi: rtw89: introduce helpers to wait/complete on condition Thread-Index: AQHY+wxGkFx0DY+dqU+L+TRf49zoQK5UZLq/gAD3tKA= Date: Tue, 29 Nov 2022 04:18:12 +0000 Message-ID: <019c1e3d4fb54b189b98e8b238fe3c9c@realtek.com> References: <20221118051042.29968-1-pkshih@realtek.com> <20221118051042.29968-4-pkshih@realtek.com> <87sfi35hsu.fsf@kernel.org> In-Reply-To: <87sfi35hsu.fsf@kernel.org> 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-attachmentfiltering-interceptor-info: no applicable attachment filtering rules found x-kse-antivirus-interceptor-info: scan successful x-kse-antivirus-info: =?us-ascii?Q?Clean,_bases:_2022/11/28_=3F=3F_11:42:00?= x-kse-bulkmessagesfiltering-scan-result: protection disabled Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 > -----Original Message----- > From: Kalle Valo > Sent: Monday, November 28, 2022 9:29 PM > To: Ping-Ke Shih > Cc: Kevin Yang ; linux-wireless@vger.kernel.org > Subject: Re: [PATCH 3/6] wifi: rtw89: introduce helpers to wait/complete on condition > > Ping-Ke Shih writes: > > > From: Zong-Zhe Yang > > > > MCC (multi-channel concurrency) related H2Cs require to wait for C2H > > responses to judge the execution result and data. We introduce helpers > > to assist this process. Besides, we would like the helpers to be generic > > for use in driver even outside of MCC H2C/C2H, so we make a independent > > patch for them. > > > > In the following, I describe the things first. > > ``` > > (A) C2H is generated by FW, and then transferred upto driver. Hence, > > driver cannot get it immediately without a bit waitting/blocking. > > For this, we choose to use wait_for_completion_*() instead of > > busy polling. > > (B) From the driver management perspective, a scenario, e.g. MCC, > > may have mulitple kind of H2C functions requiring this process > > to wait for corresponding C2Hs. But, the driver management flow > > uses mutex to protect each behavior. So, one scenario triggers > > one H2C function at one time. To avoid rampant instances of > > struct completion for each H2C function, we choose to use one > > struct completion with one condition flag for one scenario. > > (C) C2Hs, which H2Cs will be waitting for, cannot be ordered with > > driver management flow, i.e. cannot enqueue work to the same > > ordered workqueue and cannot lock by the same mutex, to prevent > > H2C side from getting no C2H responses. So, those C2Hs are parsed > > in interrupt context directly as done in previous commit. > > (D) Following (C), the above underline H2Cs and C2Hs will be handled > > in different contexts without sync. So, we use atomic_cmpxchg() > > to compare and change the condition in atomic. > > ``` > > > > So, we introduce struct rtw89_wait_info which combines struct completion > > and atomic_t. Then, the below are the descriptions for helper functions. > > * rtw89_wait_for_cond() to wait for a completion based on a condition. > > * rtw89_complete_cond() to complete a given condition and carry data. > > Each rtw89_wait_info instance independently determines the meaning of > > its waitting conditions. But, RTW89_WAIT_COND_IDLE (UINT_MAX) is reserved. > > > > Signed-off-by: Zong-Zhe Yang > > Signed-off-by: Ping-Ke Shih > > Just nitpicking a couple of items: > > Otherwise an excellent commit log but the meaning of C2H and H2C is not > clear for me. I guess they mean "chip to host" and "host to chip", but > would be good to clarify that in the beginning. will add them by v2. > > > --- a/drivers/net/wireless/realtek/rtw89/core.h > > +++ b/drivers/net/wireless/realtek/rtw89/core.h > > @@ -2802,6 +2802,34 @@ struct rtw89_mac_info { > > u8 cpwm_seq_num; > > }; > > > > +struct rtw89_completion_data { > > + bool err; > > +#define RTW89_COMPLETION_BUF_SIZE 24 > > + u8 buf[RTW89_COMPLETION_BUF_SIZE]; > > +}; > > Having a define withing a struct looks odd to me, I would prefer to have > it outside of the struct. will fix it by v2. > > > +#define rtw89_completion_cast(cmpl_data, ptr) \ > > +({ \ > > + typecheck(struct rtw89_completion_data *, cmpl_data); \ > > + BUILD_BUG_ON(sizeof(*(ptr)) > RTW89_COMPLETION_BUF_SIZE); \ > > + (typeof(ptr))(cmpl_data)->buf; \ > > +}) > > Wouldn't this be cleaner as a static inline function? inline function isn't suitable, because 'ptr' could be various type. We plan to do casting barely at callers. > > > +struct rtw89_wait_info { > > +#define RTW89_WAIT_COND_IDLE UINT_MAX > > + atomic_t cond; > > + struct completion completion; > > + struct rtw89_completion_data data; > > +}; > > Also here would prefer the define outside the struct. will fix it by v2. Thank you Ping-Ke