Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1512668ybz; Wed, 22 Apr 2020 23:40:47 -0700 (PDT) X-Google-Smtp-Source: APiQypJ6SD7TKlIe7Sz3InyIYZwGGNU+UnON38Yo8mg/RK/lEnEwLZmfuryB9p9hlGBkduip8P1t X-Received: by 2002:a05:6402:30ad:: with SMTP id df13mr1524470edb.339.1587624047216; Wed, 22 Apr 2020 23:40:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587624047; cv=none; d=google.com; s=arc-20160816; b=oYLWnQ3uHeGEORn6tjt2ZXoDKnftWIpSFHAezztW0gY13iE1Bw1M+IJ8o3xYDZtvUc xrrqHlnuX5dBdmQ77bpWwiI+9/2NM26PYNEUFl6tTZYfwpDm/HMyAL6deyv97bpIW6xZ R3/IoSLu49PpotUxQXK1OjAME1eOUsnegoNa7J2wJ2CKic8lOrfZ4l1n9feo/narHz9t ZIb2KtcA0Qfdmb6ZejgI3O3ji3J69dPPJaryODy9CaGxOn+yDSMEvWOE+7hHqBS3Gnfv Wws52xlIF/k+a5Tx58q6PUq/l9wmEJBQdaGWKgkUlObH19MLa0wf9draGo68h2PQ0uzQ lH1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=AArpnGHN1Uy178t3LFZOdAwMjPeyM81XcYiLQdXlPJk=; b=fPavE4wuphjYwrb0zvzGjfoR2/fBOyxHFHEneXT5izKbxxutWYSFGo67flAgS7YSD1 6k0E2bP13iEpaSqmD+pVk0jJvbInKN7OzfcqsQgvybHzltTdwy8LXk7D7oMwYL71aP+W JFS6tkoQgcuK8Czc6ZJNNOS4+9jPEyL0NNaqSgy4D/7QdcqazDmq7cmgMHfPi+QNarNR fiLzvvJQU0Q3Zt7k5AfhUm6TNWIv64zWnJHA8QOH55eAmQamDOlk3pG/eirJ1iVcbDY5 0NndJC0V01VGdBJpavglnMc726A6UzHyp3irWODx46zY+oAblxAhReVkMBrso+CyHBbh zcQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y12si706848edf.435.2020.04.22.23.40.24; Wed, 22 Apr 2020 23:40:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726857AbgDWGib (ORCPT + 99 others); Thu, 23 Apr 2020 02:38:31 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54346 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725562AbgDWGib (ORCPT ); Thu, 23 Apr 2020 02:38:31 -0400 Received: from 61-220-137-37.hinet-ip.hinet.net ([61.220.137.37] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jRVV3-0002HD-PO; Thu, 23 Apr 2020 06:38:18 +0000 From: Kai-Heng Feng To: yhchuang@realtek.com, kvalo@codeaurora.org Cc: Kai-Heng Feng , Dejin Zheng , "David S. Miller" , Alexios Zavras , Jonathan Corbet , Mark Brown , Thomas Gleixner , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/2] iopoll: Introduce read_poll_timeout_atomic macro Date: Thu, 23 Apr 2020 14:38:09 +0800 Message-Id: <20200423063811.2636-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Like read_poll_timeout, an atomic variant for multiple parameter read function can be useful. Will be used by a later patch. Signed-off-by: Kai-Heng Feng --- include/linux/iopoll.h | 62 +++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index cb20c733b15a..bc89ac625f26 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -57,6 +57,48 @@ (cond) ? 0 : -ETIMEDOUT; \ }) +/** + * read_poll_timeout_atomic - Periodically poll an address until a condition is + * met or a timeout occurs + * @op: accessor function (takes @addr as its only argument) + * @addr: Address to poll + * @val: Variable to read the value into + * @cond: Break condition (usually involving @val) + * @delay_us: Time to udelay between reads in us (0 tight-loops). Should + * be less than ~10us since udelay is used (see + * Documentation/timers/timers-howto.rst). + * @timeout_us: Timeout in us, 0 means never timeout + * @delay_before_read: if it is true, delay @delay_us before read. + * + * Returns 0 on success and -ETIMEDOUT upon a timeout. In either + * case, the last read value at @args is stored in @val. + * + * When available, you'll probably want to use one of the specialized + * macros defined below rather than this macro directly. + */ +#define read_poll_timeout_atomic(op, val, cond, delay_us, timeout_us, \ + delay_before_read, args...) \ +({ \ + u64 __timeout_us = (timeout_us); \ + unsigned long __delay_us = (delay_us); \ + ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ + if (delay_before_read && __delay_us) \ + udelay(__delay_us); \ + for (;;) { \ + (val) = op(args); \ + if (cond) \ + break; \ + if (__timeout_us && \ + ktime_compare(ktime_get(), __timeout) > 0) { \ + (val) = op(args); \ + break; \ + } \ + if (__delay_us) \ + udelay(__delay_us); \ + } \ + (cond) ? 0 : -ETIMEDOUT; \ +}) + /** * readx_poll_timeout - Periodically poll an address until a condition is met or a timeout occurs * @op: accessor function (takes @addr as its only argument) @@ -96,25 +138,7 @@ * macros defined below rather than this macro directly. */ #define readx_poll_timeout_atomic(op, addr, val, cond, delay_us, timeout_us) \ -({ \ - u64 __timeout_us = (timeout_us); \ - unsigned long __delay_us = (delay_us); \ - ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ - for (;;) { \ - (val) = op(addr); \ - if (cond) \ - break; \ - if (__timeout_us && \ - ktime_compare(ktime_get(), __timeout) > 0) { \ - (val) = op(addr); \ - break; \ - } \ - if (__delay_us) \ - udelay(__delay_us); \ - } \ - (cond) ? 0 : -ETIMEDOUT; \ -}) - + read_poll_timeout_atomic(op, val, cond, delay_us, timeout_us, false, addr) #define readb_poll_timeout(addr, val, cond, delay_us, timeout_us) \ readx_poll_timeout(readb, addr, val, cond, delay_us, timeout_us) -- 2.17.1