Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3263951ybb; Sun, 22 Mar 2020 19:57:41 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsLaadhBYSvyTWxqgFf5YDHdBbMMnTi9qo0NO+Wn5bgoJxsMUmApNUzNp/WH6pkeBpsGc3L X-Received: by 2002:a54:418a:: with SMTP id 10mr16463602oiy.105.1584932261668; Sun, 22 Mar 2020 19:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584932261; cv=none; d=google.com; s=arc-20160816; b=1FVvjRN+poOga+pPvpAsobjwO2TYR0j/DGFwJFpVWt1pEG2D229Wnwlc0KNUjB2MKZ 7G6nIqDWqqMH7JEKEmn3MncYimrk7eQ0ESnk0tq53paElUhKUCaclBeYAs7JiTTclHyk qG8UXMoAT8tLABar5Q0cNR3Qd2DibmIycPb4wMJ8RPDCeMfrLkU4CoaJG2uMhacNvziW KeFoilXLxYnBbooVFh1Mmr4YaVSRhqZBinbbOgv4ohvLr88Q7nmFgoslXOmWyvzD6wAs u/Oq4t3Q9n49cbmCZHmBu1OI9zAPH87G7mU4UNO+9YJF8x9XauG8b0wGV3gP5RWxJzTu 0ziQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CIaJDacIEM2pET5Cxv3vrEk+VwaiqZRb/EmAApNnPZs=; b=Sis1Pc9LJNGQudTv/mIQk52883gkFIKzFVvt7FtPOaHCSX0CTHN5vbWkcnRw5Ose7g MgPRjDXx8CJaIMD7F/QpvssySnBKJxLN/PXKZEslizmCzP383mRn+BctL/X72qq8bD7E iOZa16K94a+KWXYDCxMRugf/oNi6+omQYKcMP9jyg6byOpbKrlhOqNwXMlGxrYTB9N3l TzdaMn4H4SsBzJDCZtt509WBlJHZ3EpoiKUCOljsAsTtt0UostZCSeRCvOZXatqKE6GY 6PImuEi+wEe84F7E3AcPqMisJy8ObGjkPrcEMwo9J8Z9cXnCEBS/arnAM17U0IidopEw 70pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dgfSrtAv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c21si249328oto.169.2020.03.22.19.57.29; Sun, 22 Mar 2020 19:57:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dgfSrtAv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727159AbgCWC46 (ORCPT + 99 others); Sun, 22 Mar 2020 22:56:58 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45225 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726983AbgCWC46 (ORCPT ); Sun, 22 Mar 2020 22:56:58 -0400 Received: by mail-pl1-f196.google.com with SMTP id b9so5277960pls.12; Sun, 22 Mar 2020 19:56:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CIaJDacIEM2pET5Cxv3vrEk+VwaiqZRb/EmAApNnPZs=; b=dgfSrtAv4UeB4ZVPrRRtCV+Geyg7w+eEn2NT+ZLHuW7qdz6vK58+NrtyGw+ZM6tYOx gOduP0ALtnS0j6yIt87cIMmN9or4v/2C5Jb2WRr7N0suDQ9AujTny/NBpVRrmSmwXMwV SYixJn0JW75cLKQ6giWsKxgttlZEQkk/NXxIyngVne2sRSsyWxDyVC2JcZQkp9Vxvm9K oUknn6HEWL63+zIKFZInppTCzedX5+OZm+4bGM7HFTIP1p/H8lbE58yUO2LRkKf85t1i NfQmNGth87uG3/JQ4Yvrj3ufYpJPDbVTMLL+E1kv/11dV3wnl3y6nDAPks61PSi2LFXc z5mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CIaJDacIEM2pET5Cxv3vrEk+VwaiqZRb/EmAApNnPZs=; b=WoJtjcR+TT3eV81rTh5XOSC5t3YmRSKC4mLRMRIrqIoY3Gm9MQ8TPJx0Ox54t9TXFx TO4aJD7hOdGChY6hjQYjGkh7l/hon2e2FQlLbuFemznU+G+JTnl0ZKmNXdwUboE7i/NP bUTuWXg5b35RjQA9BgB68MYQome1xO4UdaA0UV9OymWmjSEKyZxPZAGYbh81lPLHu2uk cMyuWtzwHU15alU5ReXqtY5xF6ukIQ+3Ye/THddJjTOnS4Xu22Aq41ZDrzS+pZa5yB3+ gw7O9B1U49M31heakJ0RRf67z7EuPrdX1y3m9squp5TDLBD4+oOGzF/yL7/h1G1NQYaz PbJg== X-Gm-Message-State: ANhLgQ0yZWm3bm9irdZTNUhBsXugsnBkRtz0zD2OWY3ji3RWUbvIOwXI fJup+54SXR6PZSXXwNsH7H1kyBVS X-Received: by 2002:a17:90a:6c22:: with SMTP id x31mr22952650pjj.124.1584932217236; Sun, 22 Mar 2020 19:56:57 -0700 (PDT) Received: from localhost (104.128.80.227.16clouds.com. [104.128.80.227]) by smtp.gmail.com with ESMTPSA id a24sm11388020pfl.115.2020.03.22.19.56.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Mar 2020 19:56:56 -0700 (PDT) From: Dejin Zheng To: andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, mchehab+samsung@kernel.org, gregkh@linuxfoundation.org, broonie@kernel.org, tglx@linutronix.de, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Dejin Zheng Subject: [PATCH net-next v6 01/10] iopoll: introduce read_poll_timeout macro Date: Mon, 23 Mar 2020 10:56:24 +0800 Message-Id: <20200323025633.6069-2-zhengdejin5@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200323025633.6069-1-zhengdejin5@gmail.com> References: <20200323025633.6069-1-zhengdejin5@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org this macro is an extension of readx_poll_timeout macro. the accessor function op just supports only one parameter in the readx_poll_timeout macro, but this macro can supports multiple variable parameters for it. so functions like phy_read(struct phy_device *phydev, u32 regnum) and phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum) can also use this poll timeout framework. Signed-off-by: Dejin Zheng --- v5 -> v6: - no changed v4 -> v5: - no changed v3 -> v4: - no changed v2 -> v3: - no changed v1 -> v2: - no changed include/linux/iopoll.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index 35e15dfd4155..7d44a2e20267 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -13,6 +13,46 @@ #include #include +/** + * read_poll_timeout - Periodically poll an address until a condition is + * met or a timeout occurs + * @op: accessor function (takes @args as its arguments) + * @val: Variable to read the value into + * @cond: Break condition (usually involving @val) + * @sleep_us: Maximum time to sleep between reads in us (0 + * tight-loops). Should be less than ~20ms since usleep_range + * is used (see Documentation/timers/timers-howto.rst). + * @timeout_us: Timeout in us, 0 means never timeout + * @args: arguments for @op poll + * + * Returns 0 on success and -ETIMEDOUT upon a timeout. In either + * case, the last read value at @args is stored in @val. Must not + * be called from atomic context if sleep_us or timeout_us are used. + * + * When available, you'll probably want to use one of the specialized + * macros defined below rather than this macro directly. + */ +#define read_poll_timeout(op, val, cond, sleep_us, timeout_us, args...) \ +({ \ + u64 __timeout_us = (timeout_us); \ + unsigned long __sleep_us = (sleep_us); \ + ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ + might_sleep_if((__sleep_us) != 0); \ + for (;;) { \ + (val) = op(args); \ + if (cond) \ + break; \ + if (__timeout_us && \ + ktime_compare(ktime_get(), __timeout) > 0) { \ + (val) = op(args); \ + break; \ + } \ + if (__sleep_us) \ + usleep_range((__sleep_us >> 2) + 1, __sleep_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) -- 2.25.0