Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp936392imm; Wed, 10 Oct 2018 06:41:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV60KPxIS61BXiWoHoSZbWTQ2S4kk0Th+ONcpwTgcm6g2/yOjAaei43hD5WH4LpTiAtEGnUIb X-Received: by 2002:a65:609a:: with SMTP id t26-v6mr29184825pgu.41.1539178911250; Wed, 10 Oct 2018 06:41:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539178911; cv=none; d=google.com; s=arc-20160816; b=l0GiLdkqq2U2tv8Pv7aW0g4x9ujE0qzp5+LxxZknzi8dujAsW8Jll9OYJak9G9qD7a Tf54OKf6bSRF3S6T+YLeZk3GZHC/qtoHh43rqLF4rXbpJ1FwDlqSzakwjjRBUdhFL0B2 xb9Q9/246lWx+ZSAGOJ1fKB1AfLPCHzmSJUOEsMV7+X7Is/DQGTlLUgn+ZgncVDDrsSq Hz80gTkg50wf36yyDK8InY5R6ZKXyPB23QbYwbcUeaYpdbsUsqtBY1f2BXy5V7sPE9A7 niBAJRrh3eD2yOvJIfiCf1OJasDDg6fGhxVHV9U+WPZTFDmvbOKVcDsUAchotPYcoft4 MCVw== 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=PFn4xGie/YYS0IPB/YmE3CtH/AaSzdjHQ0tQ73Qdz2Y=; b=l35UdvzX9uXKfCXqUmFUi9TbQagtreSAwMulrpklJMSfwTHKvx/9hv2lE+k8Kk/S/G hP0sfctQWVfBw/gGusKoSntnfE7Oga1dSldFWXYqjuvz7ya+2rpCrjJEuHMhTauWEeCn cKxujZDL3JDL6Y4+Qf3G4Eogt/Rpj1oo4L91AWldC4TO7vpisp3/MfFm31Lnmjifjckm PG6PSQBczqMBq/IkgYn3Gt1ZokykbKhJ2jAGzHFdnn+WZzEYouZDDQ8UUeAPJJZuOYxy eYqMIek+0nGRucRix9Dyxgww500aKGQuC1RkXf9f2Pc1tvW7ppwwkfIU2VvgkmvPJSYD NmDg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i23-v6si25532533pfj.269.2018.10.10.06.41.36; Wed, 10 Oct 2018 06:41:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726910AbeJJVDC (ORCPT + 99 others); Wed, 10 Oct 2018 17:03:02 -0400 Received: from xavier.telenet-ops.be ([195.130.132.52]:54854 "EHLO xavier.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbeJJVDB (ORCPT ); Wed, 10 Oct 2018 17:03:01 -0400 Received: from ramsan.of.borg ([84.194.111.163]) by xavier.telenet-ops.be with bizsmtp id lpgl1y00z3XaVaC01pgmPe; Wed, 10 Oct 2018 15:40:46 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1gAEjF-000072-UI; Wed, 10 Oct 2018 15:40:45 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1gAEjF-0002Ak-TE; Wed, 10 Oct 2018 15:40:45 +0200 From: Geert Uytterhoeven To: Arnd Bergmann , Greg Kroah-Hartman , Srinivas Kandagatla Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, linux-mtd@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 3/3] eeprom: at25: Split writes in two SPI transfers to optimize DMA Date: Wed, 10 Oct 2018 15:40:36 +0200 Message-Id: <20181010134036.8296-4-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181010134036.8296-1-geert+renesas@glider.be> References: <20181010134036.8296-1-geert+renesas@glider.be> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently EEPROM writes are implemented using a single SPI transfer, which contains all of command, address, and payload data bytes. As some SPI controllers impose limitations on transfers with respect to the use of DMA, they may have to fall back to PIO. E.g. DMA may require the transfer length to be a multiple of 4 bytes. Optimize writes for DMA by splitting writes in two SPI transfers: - The first transfer contains command and address bytes, - The second transfer contains the actual payload data, now stored at the start of the (kmalloc() aligned) buffer, to improve payload alignment. E.g. for a 25LC040 EEPROM with a page size 16 bytes, a 16-byte write aligned to the page size was transferred using an 18-byte write. After this change, the write is split in a 2-byte and an aligned 16-byte write. Note that EEPROM reads already use a similar scheme, due to the different data directions for command and address bytes versus payload data. Signed-off-by: Geert Uytterhoeven --- drivers/misc/eeprom/at25.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c index 5c8dc7ad391435f7..f84d1681835b4ded 100644 --- a/drivers/misc/eeprom/at25.c +++ b/drivers/misc/eeprom/at25.c @@ -136,6 +136,7 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) int status = 0; unsigned buf_size; u8 *bounce; + struct spi_transfer t[2]; if (unlikely(off >= at25->chip.byte_len)) return -EFBIG; @@ -160,7 +161,7 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) unsigned long timeout, retries; unsigned segment; unsigned offset = off; - u8 *cp = bounce; + u8 *cp = bounce + buf_size; int sr; u8 instr; @@ -194,9 +195,17 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) segment = buf_size - (offset % buf_size); if (segment > count) segment = count; - memcpy(cp, buf, segment); - status = spi_write(at25->spi, bounce, - segment + at25->addrlen + 1); + memcpy(bounce, buf, segment); + + memset(t, 0, sizeof(t)); + + t[0].tx_buf = bounce + buf_size; + t[0].len = at25->addrlen + 1; + + t[1].tx_buf = bounce; + t[1].len = segment; + + status = spi_sync_transfer(at25->spi, t, ARRAY_SIZE(t)); dev_dbg(&at25->spi->dev, "write %u bytes at %u --> %d\n", segment, offset, status); if (status < 0) -- 2.17.1