From patchwork Wed Aug 17 19:11:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 660224 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sDzRj45sQz9sdg for ; Thu, 18 Aug 2016 05:14:09 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=E3JTl5DD; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1ba6Gd-00015A-7p; Wed, 17 Aug 2016 19:12:47 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1ba6G8-0000xK-Kc for linux-mtd@lists.infradead.org; Wed, 17 Aug 2016 19:12:19 +0000 Received: by mail-wm0-x243.google.com with SMTP id o80so169437wme.0 for ; Wed, 17 Aug 2016 12:11:59 -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=gope11+bV8w4SSq9fOw6Q4LTDGu9psb4dfAsH6st0t8=; b=E3JTl5DDHjGPOzjn6Nd7FzuOx2QsFagc+ZuWdGg4OKwmM/Fb6UqmTmraB4G9fwAG6e hbMz9nDCR8NDHhCM2wVEPVYaKGEdf9WeppHgox2oGN0ouCOnSuNlDI+Waa7snWTgtICO wXis0aLsOP7iUOelgQWNDDnRI3U5h+aaItQojB4Ya8SMDVtvcOXukCyJUZXAoru3w3wf dC9M7zOfAj8NRdO20pkSwZzeKIohoYoUb6kSX49H3v6fPO9hyE7pxaJzJBsQdFHaHRV9 fMC3RLx46FxZkqIwldILoNQZctJ7uf+ez9bIBGsUk28sIXAzPz5Qfo4pk9zvF9SHvLTH 8Dew== 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=gope11+bV8w4SSq9fOw6Q4LTDGu9psb4dfAsH6st0t8=; b=UzZuNcI1wtmnez5N7GXbuQXwtBaevS2Rvw3SEds1/0VfiN+2+tpwcYH9TcqvIEjPP0 a3k6BgfVpJK045WqD8X5qZ9AXlTvKUOcBUwurOuDWCizJp61Vq4ShXAPBPJYEqKvhxe8 xlVWm/n5GhBUte0C5nMgOMiOOiBb8yvkjq/Q/HdC25R3lh0zrr6SEsnujZi/mggMUvhP EPXKIb/gBEDX0bXF9NuPeO39RXQGuDy6O2wGqfqxvDK4ejVpqZ90OugvYdNFc47vUxFe SHsxtpJFheEPhTerbomD7Pz5XaerplgdaoJNvrjOYdWJkJQZqmjQjeGFLs2GSVskJlAq yU3Q== X-Gm-Message-State: AEkoouuHikhxvmpw23JayE9iv421aXO1BxqoOZi9ezRf4wLtecl176vyHbvz+9EuH3qscQ== X-Received: by 10.194.133.200 with SMTP id pe8mr42756134wjb.14.1471461118465; Wed, 17 Aug 2016 12:11:58 -0700 (PDT) Received: from ?IPv6:2003:62:5f55:2b00:2875:7515:2c1f:41b3? (p200300625F552B00287575152C1F41B3.dip0.t-ipconnect.de. [2003:62:5f55:2b00:2875:7515:2c1f:41b3]) by smtp.googlemail.com with ESMTPSA id jv9sm26098135wjb.45.2016.08.17.12.11.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Aug 2016 12:11:58 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v2 3/3] spi: fsl-espi: eliminate spi nor flash read loop To: Mark Brown , Brian Norris References: <6c95366c-7fcc-ef4c-033a-f9f6e152a669@gmail.com> <20160816164204.GV9347@sirena.org.uk> Message-ID: Date: Wed, 17 Aug 2016 21:11:01 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160816164204.GV9347@sirena.org.uk> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160817_121216_939068_E18B8A73 X-CRM114-Status: GOOD ( 16.31 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:243 listed in] [list.dnswl.org] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (hkallweit1[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (hkallweit1[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: MTD Maling List , "linux-spi@vger.kernel.org" Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The fsl-espi driver contains a read loop that implicitely assumes that the device to read from is a m25p80 SPI NOR flash (bytes 2 - 4 of the first write transfer are interpreted as 3 byte flash address). Now that we have such a read loop in the spi-nor driver and are able to correctly indicate the message size limit of the controller, the read loop can be removed from the fsl-espi driver. Signed-off-by: Heiner Kallweit --- v2: - set the new hook max_message_size in spi_master --- drivers/spi/spi-fsl-espi.c | 91 +++++++++++----------------------------------- 1 file changed, 21 insertions(+), 70 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 8d85a3c..96a2442 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -258,23 +258,6 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t) return mpc8xxx_spi->count; } -static inline void fsl_espi_addr2cmd(unsigned int addr, u8 *cmd) -{ - if (cmd) { - cmd[1] = (u8)(addr >> 16); - cmd[2] = (u8)(addr >> 8); - cmd[3] = (u8)(addr >> 0); - } -} - -static inline unsigned int fsl_espi_cmd2addr(u8 *cmd) -{ - if (cmd) - return cmd[1] << 16 | cmd[2] << 8 | cmd[3] << 0; - - return 0; -} - static void fsl_espi_do_trans(struct spi_message *m, struct fsl_espi_transfer *tr) { @@ -366,68 +349,36 @@ static void fsl_espi_cmd_trans(struct spi_message *m, static void fsl_espi_rw_trans(struct spi_message *m, struct fsl_espi_transfer *trans, u8 *rx_buff) { - struct fsl_espi_transfer *espi_trans = trans; - unsigned int total_len = espi_trans->len; struct spi_transfer *t; u8 *local_buf; - u8 *rx_buf = rx_buff; - unsigned int trans_len; - unsigned int addr; - unsigned int tx_only; - unsigned int rx_pos = 0; - unsigned int pos; - int i, loop; + unsigned int tx_only = 0; + int i = 0; local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL); if (!local_buf) { - espi_trans->status = -ENOMEM; + trans->status = -ENOMEM; return; } - for (pos = 0, loop = 0; pos < total_len; pos += trans_len, loop++) { - trans_len = total_len - pos; - - i = 0; - tx_only = 0; - list_for_each_entry(t, &m->transfers, transfer_list) { - if (t->tx_buf) { - memcpy(local_buf + i, t->tx_buf, t->len); - i += t->len; - if (!t->rx_buf) - tx_only += t->len; - } - } - - /* Add additional TX bytes to compensate SPCOM_TRANLEN_MAX */ - if (loop > 0) - trans_len += tx_only; - - if (trans_len > SPCOM_TRANLEN_MAX) - trans_len = SPCOM_TRANLEN_MAX; - - /* Update device offset */ - if (pos > 0) { - addr = fsl_espi_cmd2addr(local_buf); - addr += rx_pos; - fsl_espi_addr2cmd(addr, local_buf); + list_for_each_entry(t, &m->transfers, transfer_list) { + if (t->tx_buf) { + memcpy(local_buf + i, t->tx_buf, t->len); + i += t->len; + if (!t->rx_buf) + tx_only += t->len; } + } - espi_trans->len = trans_len; - espi_trans->tx_buf = local_buf; - espi_trans->rx_buf = local_buf; - fsl_espi_do_trans(m, espi_trans); - - /* If there is at least one RX byte then copy it to rx_buf */ - if (tx_only < SPCOM_TRANLEN_MAX) - memcpy(rx_buf + rx_pos, espi_trans->rx_buf + tx_only, - trans_len - tx_only); - - rx_pos += trans_len - tx_only; + trans->tx_buf = local_buf; + trans->rx_buf = local_buf; + fsl_espi_do_trans(m, trans); - if (loop > 0) - espi_trans->actual_length += espi_trans->len - tx_only; - else - espi_trans->actual_length += espi_trans->len; + if (!trans->status) { + /* If there is at least one RX byte then copy it to rx_buff */ + if (trans->len > tx_only) + memcpy(rx_buff, trans->rx_buf + tx_only, + trans->len - tx_only); + trans->actual_length += trans->len; } kfree(local_buf); @@ -663,7 +614,7 @@ static int fsl_espi_runtime_resume(struct device *dev) } #endif -static size_t fsl_espi_max_transfer_size(struct spi_device *spi) +static size_t fsl_espi_max_message_size(struct spi_device *spi) { return SPCOM_TRANLEN_MAX; } @@ -695,7 +646,7 @@ static struct spi_master * fsl_espi_probe(struct device *dev, master->cleanup = fsl_espi_cleanup; master->transfer_one_message = fsl_espi_do_one_msg; master->auto_runtime_pm = true; - master->max_transfer_size = fsl_espi_max_transfer_size; + master->max_message_size = fsl_espi_max_message_size; mpc8xxx_spi = spi_master_get_devdata(master);