From patchwork Thu Oct 27 19:27:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9400265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0A35260588 for ; Thu, 27 Oct 2016 19:29:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC8022A396 for ; Thu, 27 Oct 2016 19:29:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1A902A398; Thu, 27 Oct 2016 19:29:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BEF62A396 for ; Thu, 27 Oct 2016 19:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754491AbcJ0T3t (ORCPT ); Thu, 27 Oct 2016 15:29:49 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34323 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754000AbcJ0T3s (ORCPT ); Thu, 27 Oct 2016 15:29:48 -0400 Received: by mail-wm0-f67.google.com with SMTP id y138so4185891wme.1 for ; Thu, 27 Oct 2016 12:29:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=2jJQgkLC5dY/r+/Jv95H0ZyvVNsTkl/OaGLWnvuMNOw=; b=zxMqEXpjDOWndH4xuVroQ7byXonRn4FNvTzKI7oNyO8BnWMjjGlmxoTwR+HF/wQrwC K491uh1GX5uJeXMYN0vafuJfamH/LC54J+TZHnYGw5sdqOqmIdN/qzd8KzjHlgCjWNYj P758NikaI7rGz5TyQTQVmrhXZPHxDIf9SUO3Y0eBHrt/tDLVURoKvSqBKF3obUHbYqwV s7RnUf4nxiAHakm9ynZMHgHuulMwELWTCMT8ms91ANjLIlXeF0PSvR1wylq5orpYaWpZ HSzfNYNI5qEwfi+jlaKCyQi3fIPNiJe8vC5YNgn8DgEvq5djQIXQcJwAQI/TT6K+0Lev htnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=2jJQgkLC5dY/r+/Jv95H0ZyvVNsTkl/OaGLWnvuMNOw=; b=jOrSZiHdWtl61Y1e985lx86YPK6Zp+9O+pJKZ4HUylw5Ou3Uhe4mKFTExqpOKuEFfR OasqoepRrxI5jclM/wNSJghbor98QrbRZT1LswLrxMRE59h8Q5lEQOYCkVOc/3TOYadf oPBBecdNOaiaomDvKBZajSfWuWue9c0tLauG6KZP0LqIuk4jjiFzwGBwB4nvHGNdxknJ gR76zaaWhAItJYtEnOgLxGF/cNKrMQpoe4M+qw/edSAy5WTDeELEXNN/io4h/ZBAuRf+ 7Ja3JAUkyx88R4vkhsCOg/Zuiv+Go0DNUN5ToMUD7y5mPud0u+xlGIAscRSOqA6mn0Ra SDIA== X-Gm-Message-State: ABUngvft9FfgPgL6wC/UK4dhui33QlUoObDScVKpTQJb9BPFxbJhHumG9jnsn+rlzoxMlA== X-Received: by 10.28.19.131 with SMTP id 125mr237834wmt.133.1477596586958; Thu, 27 Oct 2016 12:29:46 -0700 (PDT) Received: from ?IPv6:2003:62:5f6e:ba00:49f8:f47b:2191:41c4? (p200300625F6EBA0049F8F47B219141C4.dip0.t-ipconnect.de. [2003:62:5f6e:ba00:49f8:f47b:2191:41c4]) by smtp.googlemail.com with ESMTPSA id za1sm10163754wjb.8.2016.10.27.12.29.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Oct 2016 12:29:46 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v2 05/09] spi: fsl-espi: fix and improve reading from RX FIFO To: Mark Brown References: <5b98be38-17a2-79a2-14da-fb2bb6f8820f@gmail.com> Cc: "linux-spi@vger.kernel.org" Message-ID: <6ae20ab9-4068-9be7-654d-12424de35716@gmail.com> Date: Thu, 27 Oct 2016 21:27:35 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <5b98be38-17a2-79a2-14da-fb2bb6f8820f@gmail.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the driver polls in the ISR for enough bytes in the RX FIFO. An ISR should never do this. Change it to read as much as possible whenever the ISR is called. This also allows to significantly simplify the code. Signed-off-by: Heiner Kallweit --- v2: - rebased --- drivers/spi/spi-fsl-espi.c | 67 ++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 47 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index d550685..ca14575 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -223,6 +223,24 @@ static void fsl_espi_fill_tx_fifo(struct mpc8xxx_spi *mspi, u32 events) } } +static void fsl_espi_read_rx_fifo(struct mpc8xxx_spi *mspi, u32 events) +{ + u32 rx_fifo_avail = SPIE_RXCNT(events); + + while (rx_fifo_avail >= min(4U, mspi->rx_len) && mspi->rx_len) + if (mspi->rx_len >= 4) { + *(u32 *)mspi->rx = fsl_espi_read_reg(mspi, ESPI_SPIRF); + mspi->rx += 4; + mspi->rx_len -= 4; + rx_fifo_avail -= 4; + } else { + *(u8 *)mspi->rx = fsl_espi_read_reg8(mspi, ESPI_SPIRF); + mspi->rx += 1; + mspi->rx_len -= 1; + rx_fifo_avail -= 1; + } +} + static void fsl_espi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) { @@ -418,53 +436,8 @@ static void fsl_espi_cleanup(struct spi_device *spi) static void fsl_espi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events) { - /* We need handle RX first */ - if (events & SPIE_RNE) { - u32 rx_data, tmp; - u8 rx_data_8; - int rx_nr_bytes = 4; - int ret; - - /* Spin until RX is done */ - if (SPIE_RXCNT(events) < min(4U, mspi->rx_len)) { - ret = spin_event_timeout( - !(SPIE_RXCNT(events = - fsl_espi_read_reg(mspi, ESPI_SPIE)) < - min(4U, mspi->rx_len)), - 10000, 0); /* 10 msec */ - if (!ret) - dev_err(mspi->dev, - "tired waiting for SPIE_RXCNT\n"); - } - - if (mspi->rx_len >= 4) { - rx_data = fsl_espi_read_reg(mspi, ESPI_SPIRF); - } else if (!mspi->rx_len) { - dev_err(mspi->dev, - "unexpected RX(SPIE_RNE) interrupt occurred,\n" - "(local rxlen %d bytes, reg rxlen %d bytes)\n", - min(4U, mspi->rx_len), SPIE_RXCNT(events)); - rx_nr_bytes = 0; - } else { - rx_nr_bytes = mspi->rx_len; - tmp = mspi->rx_len; - rx_data = 0; - while (tmp--) { - rx_data_8 = fsl_espi_read_reg8(mspi, - ESPI_SPIRF); - rx_data |= (rx_data_8 << (tmp * 8)); - } - - rx_data <<= (4 - mspi->rx_len) * 8; - } - - mspi->rx_len -= rx_nr_bytes; - - if (rx_nr_bytes && mspi->rx) { - *(u32 *)mspi->rx = rx_data; - mspi->rx += 4; - } - } + if (mspi->rx_len) + fsl_espi_read_rx_fifo(mspi, events); if (mspi->tx_len) fsl_espi_fill_tx_fifo(mspi, events);