Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp65684ybz; Fri, 24 Apr 2020 11:54:12 -0700 (PDT) X-Google-Smtp-Source: APiQypJacireRLj7ye6PQ1ho7IaWgya7i5feYbpqlxHX4Bgy+kP8nx9FD19DfqBIutFHBRD5N/Yy X-Received: by 2002:a50:a68a:: with SMTP id e10mr9030786edc.317.1587754452166; Fri, 24 Apr 2020 11:54:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587754452; cv=none; d=google.com; s=arc-20160816; b=cI1z8T4xdmb8prKImrGHYFshNY4SqnFyYk3Kp3oVRJD2PsDcIEjtlh7wQNw+yh2cFO yCoRgp5RCGYsAcZ58sQAm0x9LiIJN2bxdbhVQiqlhKP6snTrQZ9dISsEqI0nSg5jA/5S EHfbBvY/z2Xng4Sh0cqEzyul+UlSIR7dz+OlwwJay0fu13KqGTSIpWeHW4nOAXS6+EmJ P3VWiklplWGDSa9vt8485/snnz3FctiAZ9yCXQOkVnLsbFl9+Iks1Q1+2xGhfYvgnh+R Uxn7JMqmkGG6SEhZofAaLgaupiQwumcqAXwo+M5bVYYtnc8mFSnPbmzfyM37/+XHjBDw 12NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=0cnt+sXeSw0lOZKLqIA4RRD2Rix/mzyuSdgl7sAvVWg=; b=Mad1F/Aq9YFiIkSZZqEPwBnEeUGVis4fqlmq5gvF14GgsZNAygMiP05yK9Ojsb+vsf 4a53j4CtEOS5Ugfp5rONXA+QtFI4eekajARnojMxuFf16hCesY416rMUwMXGmkcZJSoW FXeGUqY+FDudmaWgM+rP1YEbr/ppyk3HdUO1E+k3KlSF/9e5uUcNC7INC77NbNpBiuEB cO0o8ZjZRpGX8jL4VjUJR2iWxKREFQL0gSlVBjablR6eTEbBqgETE4yzsYBCteSZj84i yBPccGHkTe1hrLp3lJaGxePBcBw6WjBiNVRNan+Bdc8jvshTCCdQjG0iBmfX2cuUM1tt sSlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-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 a72si3456575edf.28.2020.04.24.11.53.48; Fri, 24 Apr 2020 11:54:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-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 S1729212AbgDXStd (ORCPT + 99 others); Fri, 24 Apr 2020 14:49:33 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:34102 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728943AbgDXStc (ORCPT ); Fri, 24 Apr 2020 14:49:32 -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 1jS3O9-0006cb-MJ; Fri, 24 Apr 2020 18:49:26 +0000 From: Kai-Heng Feng To: yhchuang@realtek.com, kvalo@codeaurora.org Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Kai-Heng Feng , "David S. Miller" , Dejin Zheng , Allison Randal , Alexios Zavras , Mauro Carvalho Chehab , Thomas Gleixner , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 1/2] iopoll: Introduce read_poll_timeout_atomic macro Date: Sat, 25 Apr 2020 02:49:14 +0800 Message-Id: <20200424184918.30360-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200423063811.2636-1-kai.heng.feng@canonical.com> References: <20200423063811.2636-1-kai.heng.feng@canonical.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@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 --- v2: - Cc linux-wireless. 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