Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14842645rwb; Mon, 28 Nov 2022 05:36:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf7qewy2tNpAvOyYDrzLc9BI0keAi6tbBW4K5f6L1e7OhsFmIVL7KJCVZ3uCwVM+EcBAU168 X-Received: by 2002:a17:907:2a92:b0:7bd:7f47:d5bb with SMTP id fl18-20020a1709072a9200b007bd7f47d5bbmr10921565ejc.625.1669642588944; Mon, 28 Nov 2022 05:36:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669642588; cv=none; d=google.com; s=arc-20160816; b=urRNhQaUs45bNFxMGqHpfu/xHLdVuaiRl93S11x2OmkGvTVrf1Z+9rfHHKTRo8EdC2 fqCS54QVFQfp5QF/1CseZ2OyP+Pkfa4Euiv7H3FIn45Id/VMSu8ZV5XFsg7Jxkb2PRKb xOzrKDTq6SyWcyTMpTxMWn7lOX4zM5klbdd+M3CHV2sU5eKkrQq/MQPd8wqtUs4HDd5F Sn3VKAZ/9MuuyJLCc3XtbKyENfOtcz8nkX0CQ4qzEFis+b/uohL0NU0RaDljxiI5DleO vXJJC3ufiYhL9ayxw7OnIMIs55ODG+R7lv+9ECFrdU4AwMyP/a9b8pjJbx5zdLO99Ntx ylVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=TJ0+Z9tTMqBJ8c2ELAhw3it3uTNfstKY3dqsvI5Xo/s=; b=LvUCrs4+7oqq+sjdleTAhsUiYtcpIpmFmRY1o4S6CW4H3Rt4+yGBfbEvP5L9S8Fvak z99JiatODZL3li2Iis26NokiGwhtuX7T//667qVA2MAJcGnaaNofksYe+SKi8QILalqi SAeTN/viRwbbYUj8FV2R8Sbd8XD+B8jWwRCccsq94UUoW3AI0ASnc4gfVJMw1btoF5OE 08iSZd3qsaDqfVVcnHLce3BD45Fn+cp3OsYYlbZEEsjiAnN4PTxtB5YEKxz2xJiXKq5V qutPla8bgOblhTkZYxaeeuj7j+lA5gGBOq1KogJDNcSAilPgFa3KOMuTJbjaaLMRB2DA GU1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AFN3WKv1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xc1-20020a170907074100b0078de51e1c3dsi9456822ejb.840.2022.11.28.05.36.08; Mon, 28 Nov 2022 05:36:28 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AFN3WKv1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231777AbiK1N3R (ORCPT + 67 others); Mon, 28 Nov 2022 08:29:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231773AbiK1N3O (ORCPT ); Mon, 28 Nov 2022 08:29:14 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 495D71CFCD for ; Mon, 28 Nov 2022 05:29:12 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 02CB1B80BA6 for ; Mon, 28 Nov 2022 13:29:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD332C433C1; Mon, 28 Nov 2022 13:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669642149; bh=YzLvejoEX32ZSiRN/J9lyWo8MYx3z7PhhgVHuNta2TY=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=AFN3WKv1EwrTajpkqhqUPx6VFiAzPSKr/3T7ZBn5X4NaUCNEEKzgZ7bADEtAlzp7C 4gNZ5i6lC9IJOz2CIH7Bio5Dnt75ryY+Iq/InMgDqgs64KaQEvK47rNeppLvomE47M Ptgl3NmeqSV54zreWMSXAvyZHH70u8k110UKMYRXH0LOSGvY50ncRhIu5hR9AhYkDT oEfeMLa0UWSY+49fF2Jx3Yj/2yD7WHCc5pbm3zIxPHLSvjAEZqRtgRSTzBbHtRWH+I 4jUgGVSVF6rb9AzKJ7D5DOosKKB0o7C6EDhujrXBhFl5Syy2zwAXcb0/z0n4f13C9h nL+U+0xv5khvQ== From: Kalle Valo To: Ping-Ke Shih Cc: , Subject: Re: [PATCH 3/6] wifi: rtw89: introduce helpers to wait/complete on condition References: <20221118051042.29968-1-pkshih@realtek.com> <20221118051042.29968-4-pkshih@realtek.com> Date: Mon, 28 Nov 2022 15:29:05 +0200 In-Reply-To: <20221118051042.29968-4-pkshih@realtek.com> (Ping-Ke Shih's message of "Fri, 18 Nov 2022 13:10:39 +0800") Message-ID: <87sfi35hsu.fsf@kernel.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 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. > --- 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. > +#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? > +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. -- https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches