Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2959181imm; Sun, 29 Jul 2018 07:16:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeXu/3S6Zj58I10ZCb6gI/d8sglewMYE03TY4Zy5m0i6Wctvpf7+8K5zkxQyzTXBJZYMQIH X-Received: by 2002:a63:ba43:: with SMTP id l3-v6mr12504416pgu.295.1532873765579; Sun, 29 Jul 2018 07:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532873765; cv=none; d=google.com; s=arc-20160816; b=zPH7OYIZTgC8IX5bXQv1yi9mVhw/bAXLwL6O2EHOm3QPvNHfpJDvqPzZ36fl5xpwbP Qin7Kmc25xL24pmzRAgmHnv51b0g7RXqMOcYlIr/8IlcguchUXMVZ9iQf6+UPjhNK7Ln /E44REOPs5BWqDv6NtzByU4eAXxhy2PZBY9DeqX5yZOEqz2cWYdZvXPI8LTws7WVFX4k tW6dY2GP+ja1hiBUxIcD021dZzrMLzbgobR42UHONdHW8hKZWPScCDVF6/HL9zBM7Qwm uYqBAQixOuEmIlff95dlcDrH1fXfVjsfYO5LaFTtvnZCUc5y6olU2r75XsaG6ljRNYc9 GASw== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=bgNu5LgSX8fFKDvO30Ae8hHfWRzOacOvGP3ObXSNYFE=; b=NHdsibuA5DsYWNQgIfnZuCD5DbGt/MH8/EGv+n2z8xSjt58vImTr3L77LkfT/yRHaI naMYu8tA4wUCC4pnDrAsGA7YeqIL2PStOczVxQRQuztZWxKt8HflHOkPuDmXfG1Sn/96 h72mUXzvBPtloFNRxWRebWLF1udeo1pWEy+PmEzwQH1qYIArUwQaFgeBwtzTZzMlWLai DRWPwmvgrCV+DNlhr/AIYSmkU5w/Jx86ZzeJUiGynRzFvj8es0zmKr5f1YxFXMo+eaWC R5ZKJa8cwHfyAANoy862ml8BS0mGj5vVgSFu1IET6wb+oNJyMjHSfQ3Or84Zk7p/hrdz JXMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hw7k4s08; 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 k1-v6si8382563pgj.522.2018.07.29.07.15.36; Sun, 29 Jul 2018 07:16:05 -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=hw7k4s08; 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 S1728628AbeG2Poq (ORCPT + 99 others); Sun, 29 Jul 2018 11:44:46 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:53013 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726411AbeG2Poq (ORCPT ); Sun, 29 Jul 2018 11:44:46 -0400 Received: by mail-wm0-f65.google.com with SMTP id o11-v6so10233116wmh.2 for ; Sun, 29 Jul 2018 07:14:09 -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 :in-reply-to:references; bh=bgNu5LgSX8fFKDvO30Ae8hHfWRzOacOvGP3ObXSNYFE=; b=hw7k4s08P/Bo7LST3dgzxW12SyY/tUK6lH1+TVHhmnE/B53Ehh4koQA+ptGGTpps31 M7pVitYtEUKq3lHARttEU2ymLNzwXd+0Gnw88ktavBsILPMhf+oGf/LZd+t2Nc9Jo77H 6+50jfl9U8KbA43YIDq1R9uvh2BiizMnVXCijfT0HIhYZqYO8sTFSehOaCufnGXwvdJA p4FfFvQQZVssJmw9szaaCFF2I34aJz89gTMEnDO0cP3lyBUzXmCj8YGJMPeXlF/XHK6z skT+VOtygaLIUoRB5Doo1rhR5ngP1jWdsCEGpu2BPov+u6EfFKB+8as1PMRWzG8KbHti JL4w== 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:in-reply-to:references; bh=bgNu5LgSX8fFKDvO30Ae8hHfWRzOacOvGP3ObXSNYFE=; b=jzm4gkA80oCuQie64216+o8FgtMKik4zJdFqAY5mCGImzsrfITL7zUa4w+EYlfQWxs 8OTW94w8p0mddPqsE2K1mwaMXxz5c6r4gKDRFRu2ImCI4lwCmAyLJYOLWJEeKLT5GzyS tSsertA+jwA20lJeN35Fildme+J6BzHpWatufXOCx6DSSW1AiuFq77ZpEhHprIDvE4PI QVDdxHYd+OiH01GBr/QZVmPsxlChlh9JhFmMletGzqLhr+oYIaB7iA7y/BYm4ZOdNQUC KZJrEXfmpv2v915hGbBXLYLuox8eMIO5Lz3P1psgyQmA8U9q+kmcxLMdnTC6ycU+33RK HZIQ== X-Gm-Message-State: AOUpUlFAO0E0riOEI+4ONRju8Yi4FtaMM7MW2xCAL2XQQAPBRe92XipY eclZEpRhrNPXvTXBMcyQyto= X-Received: by 2002:a1c:d10c:: with SMTP id i12-v6mr7005761wmg.133.1532873648345; Sun, 29 Jul 2018 07:14:08 -0700 (PDT) Received: from we.local (ppp-2-87-92-87.home.otenet.gr. [2.87.92.87]) by smtp.gmail.com with ESMTPSA id q77-v6sm2960362wmb.38.2018.07.29.07.14.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Jul 2018 07:14:07 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by we.local (Postfix) with ESMTP id 709956408D2; Sun, 29 Jul 2018 17:14:06 +0300 (EEST) X-Virus-Scanned: amavisd-new at local X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from we.local ([127.0.0.1]) by localhost (we.local [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lAtOjIRfZTtN; Sun, 29 Jul 2018 17:14:05 +0300 (EEST) Received: by we.local (Postfix, from userid 1000) id EDAD36408D3; Sun, 29 Jul 2018 17:14:05 +0300 (EEST) From: Georgios Tsotsos To: Greg Kroah-Hartman Cc: Georgios Tsotsos , Aaro Koskinen , James Hogan , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] Staging: octeon-usb: Changes macro CVMX_WAIT_FOR_FIELD32 to function call. Date: Sun, 29 Jul 2018 17:13:35 +0300 Message-Id: <20180729141335.32501-2-tsotsos@gmail.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180729141335.32501-1-tsotsos@gmail.com> References: <20180729141335.32501-1-tsotsos@gmail.com> In-Reply-To: <20180727151527.GA2209@kroah.com> References: <20180727151527.GA2209@kroah.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replacing CVMX_WAIT_FOR_FIELD32 macro with equivalent function. Signed-off-by: Georgios Tsotsos --- v2: Changed CVMX_WAIT_FOR_FIELD32 syntax to avoid checkpatch check notice and tried to make the macro more readable. v3: Changed CVMX_WAIT_FOR_FIELD32 macro to function according as refereed in commit message and suggested by Greg Kroah-Hartman v4: Added patch version text drivers/staging/octeon-usb/octeon-hcd.c | 65 +++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/drivers/staging/octeon-usb/octeon-hcd.c b/drivers/staging/octeon-usb/octeon-hcd.c index 4615133292b5..8a7bdf1a9fe6 100644 --- a/drivers/staging/octeon-usb/octeon-hcd.c +++ b/drivers/staging/octeon-usb/octeon-hcd.c @@ -377,29 +377,6 @@ struct octeon_hcd { struct cvmx_usb_tx_fifo nonperiodic; }; -/* This macro spins on a register waiting for it to reach a condition. */ -#define CVMX_WAIT_FOR_FIELD32(address, _union, cond, timeout_usec) \ - ({int result; \ - do { \ - u64 done = cvmx_get_cycle() + (u64)timeout_usec * \ - octeon_get_clock_rate() / 1000000; \ - union _union c; \ - \ - while (1) { \ - c.u32 = cvmx_usb_read_csr32(usb, address); \ - \ - if (cond) { \ - result = 0; \ - break; \ - } else if (cvmx_get_cycle() > done) { \ - result = -1; \ - break; \ - } else \ - __delay(100); \ - } \ - } while (0); \ - result; }) - /* * This macro logically sets a single field in a CSR. It does the sequence * read, modify, and write @@ -593,6 +570,42 @@ static inline int cvmx_usb_get_data_pid(struct cvmx_usb_pipe *pipe) return 0; /* Data0 */ } +/** + * Loop through register until txfflsh or rxfflsh become zero. + * + * @usb: USB block + * @address: 64bit address to read + * @timeout_usec: Timeout + * @fflsh_type: Indicates fflsh type, 0 for txfflsh, 1 for rxfflsh + * + */ +static int cvmx_wait_for_field32(struct octeon_hcd *usb, u64 address, + u64 timeout_usec, int fflsh_type) +{ + int result; + u64 done = cvmx_get_cycle() + timeout_usec * + (u64)octeon_get_clock_rate / 1000000; + + union cvmx_usbcx_grstctl c; + + while (1) { + c.u32 = cvmx_usb_read_csr32(usb, address); + if (fflsh_type == 0 && c.s.txfflsh == 0) { + result = 0; + break; + } else if (fflsh_type == 1 && c.s.rxfflsh == 0) { + result = 0; + break; + } else if (cvmx_get_cycle() > done) { + result = -1; + break; + } + + __delay(100); + } + return result; +} + static void cvmx_fifo_setup(struct octeon_hcd *usb) { union cvmx_usbcx_ghwcfg3 usbcx_ghwcfg3; @@ -635,11 +648,9 @@ static void cvmx_fifo_setup(struct octeon_hcd *usb) /* Flush all FIFOs */ USB_SET_FIELD32(address, cvmx_usbcx_grstctl, txfnum, 0x10); USB_SET_FIELD32(address, cvmx_usbcx_grstctl, txfflsh, 1); - CVMX_WAIT_FOR_FIELD32(address, cvmx_usbcx_grstctl, - c.s.txfflsh == 0, 100); + cvmx_wait_for_field32(usb, address, 0, 100); USB_SET_FIELD32(address, cvmx_usbcx_grstctl, rxfflsh, 1); - CVMX_WAIT_FOR_FIELD32(address, cvmx_usbcx_grstctl, - c.s.rxfflsh == 0, 100); + cvmx_wait_for_field32(usb, address, 1, 100); } /** -- 2.16.4