From patchwork Wed Aug 17 19:08: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: 9286359 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 464AE608A1 for ; Wed, 17 Aug 2016 19:12:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30BEC29089 for ; Wed, 17 Aug 2016 19:12:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 257982958C; Wed, 17 Aug 2016 19:12:20 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 5A04A29145 for ; Wed, 17 Aug 2016 19:12:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752761AbcHQTMS (ORCPT ); Wed, 17 Aug 2016 15:12:18 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35310 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752435AbcHQTMR (ORCPT ); Wed, 17 Aug 2016 15:12:17 -0400 Received: by mail-wm0-f68.google.com with SMTP id i5so135675wmg.2 for ; Wed, 17 Aug 2016 12:11:56 -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=ji3smjnmUigMviuS82vps2Q9Hp+2uLXG1FxDBJrvwiY=; b=bpA2qbVEtc0xRbTsX00sxFMDNUXUOVJQffCxrjWj6gxQqKbSDtlUFOEBEuDM0fD2Wb 3cnedJ+44EITnBi8GmC5Xu7l4IXLiwY4Nqk1tMU0yuoVyfzuqp9LH38Qnk7jUWjHzlHN g11me2Y2TOVBP3w3VDhhXDClFi+KCxVpQ2SIyS4OnCsI3skrG+yZNDR3CUu5xQGmz97/ RpkfhamWnlDpmTKygwqRyydcjaxJSghdOiYdkLRxbsNkU2kj3a1wW9lmovwRyA6MMsid 4Iues6KOG9A+R8a/lZseY1ARbtsAIKcJ9a8Js/VD1oTdkzjFVaPtW6m/YeKrg2bd9JfW uCbQ== 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=ji3smjnmUigMviuS82vps2Q9Hp+2uLXG1FxDBJrvwiY=; b=gAxIQrhRWxo2xZu2u0pyA1LJN6q/sHMoiGZ42UHgIFDuBnwGS7XutxHpm+8ZG5YJRr QRqXDhGJfYao3NafZxCgndTbA365Osh25pV5i74nEvtbj7W9g32qSwHoDv6UYzxkf197 F/imNBBnK7p8WId6ZbBnGXYCPUj45jt4s7iiVZyal/UfdISRUkg447KUTKgxeGixZVuw VosFDPhM4FeIySgADRaapZA7GCu5EntKiD5wOxq7lH6puhdGNV6dPlr1WLLO2i6MfysS GdDBnwWdIL7EqXhmVgvb6gz/z8tURDojZhMq16W9dThDkU9lMkFWK4H2VvMmXrqUoaMg fmBA== X-Gm-Message-State: AEkoousJbI9SsqDkvFQPfzjiaMMXnggReI3VJLPcqxInvs8GzEsufkkCq+kTtCAZ5ENssg== X-Received: by 10.194.166.37 with SMTP id zd5mr45463484wjb.170.1471461115596; Wed, 17 Aug 2016 12:11:55 -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 v134sm28023887wmf.10.2016.08.17.12.11.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Aug 2016 12:11:55 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v2 1/3] spi: introduce max_message_size hook in spi_master To: Mark Brown , Brian Norris References: <6c95366c-7fcc-ef4c-033a-f9f6e152a669@gmail.com> <20160816164204.GV9347@sirena.org.uk> Cc: "linux-spi@vger.kernel.org" , MTD Maling List Message-ID: <69c4ce26-7b41-222e-07b2-92818cedd05f@gmail.com> Date: Wed, 17 Aug 2016 21:08: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> 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 Recently a maximum transfer size was was introduced in struct spi_master. However there are also spi controllers with a maximum message size, e.g. fsl-espi has a max message size of 64KB. Introduce a hook max_message_size to deal with such limitations. Also make sure that spi_max_transfer_size doesn't return greater values than spi_max_message_size, even if hook max_transfer_size is not set. Signed-off-by: Heiner Kallweit --- v2: - replace the flag with a hook that allows to define a message size limit independednt of a potential transfer size limit --- include/linux/spi/spi.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 072cb2a..f2d3960 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -312,6 +312,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) * @flags: other constraints relevant to this driver * @max_transfer_size: function that returns the max transfer size for * a &spi_device; may be %NULL, so the default %SIZE_MAX will be used. + * @max_message_size: function that returns the max message size for + * a &spi_device; may be %NULL, so the default %SIZE_MAX will be used. * @io_mutex: mutex for physical bus access * @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for exclusion of multiple callers @@ -442,10 +444,11 @@ struct spi_master { #define SPI_MASTER_MUST_TX BIT(4) /* requires tx */ /* - * on some hardware transfer size may be constrained + * on some hardware transfer / message size may be constrained * the limit may depend on device transfer settings */ size_t (*max_transfer_size)(struct spi_device *spi); + size_t (*max_message_size)(struct spi_device *spi); /* I/O mutex */ struct mutex io_mutex; @@ -905,12 +908,26 @@ extern int spi_async_locked(struct spi_device *spi, struct spi_message *message); static inline size_t -spi_max_transfer_size(struct spi_device *spi) +spi_max_message_size(struct spi_device *spi) { struct spi_master *master = spi->master; - if (!master->max_transfer_size) + if (!master->max_message_size) return SIZE_MAX; - return master->max_transfer_size(spi); + return master->max_message_size(spi); +} + +static inline size_t +spi_max_transfer_size(struct spi_device *spi) +{ + struct spi_master *master = spi->master; + size_t tr_max = SIZE_MAX; + size_t msg_max = spi_max_message_size(spi); + + if (master->max_transfer_size) + tr_max = master->max_transfer_size(spi); + + /* transfer size limit must not be greater than messsage size limit */ + return min(tr_max, msg_max); } /*---------------------------------------------------------------------------*/