linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>,
	Lee Jones <lee-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Eric Anholt <eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>,
	linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH V2 0/5] spi: spi-message transformation framework
Date: Wed, 9 Dec 2015 10:38:32 +0100	[thread overview]
Message-ID: <5667F698.4040709@martin.sperl.org> (raw)
In-Reply-To: <1449501708-2228-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>

On 07.12.2015 16:21, kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org wrote:
> From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
>
> This patchset implements a spi-message transformation framework in
> SPI-core, that allows drivers to transfor individual spi messages
> into something that can more easily get handled by the HW.
>
> This would typically be used for HW which has some limitations on
> DMA alignment or max transfer sizes.
>
> This patchset implements at this very moment only splitting
> transfers longer than 60k in size into multiple transfers.
>
> Future patches based on this basic patchset:
> * split misalligned transfers (there are probably multiple
>    variations necessary for different HW)
> * merge multiple small transfers into a single transfer
>
> The patch-set essentially is based arround spi resource
> management on a spi_message basis, which was inspired by
> devres.
>
> This framework could also get used to handle spi_unmap_buf
> calls with the framework.
>
> Right now the drivers themselves have to implement
> spi_master.translate_message, but as soon as the "typical"
> HW-variations become apparent this may be reduced to assign
> one of a set of "standard" translation methods to
> spi_master.translate_message instead, but this may require
> some additional parametrization of the HW characteristics.
>
> The whole patch set has been tested successfully on a RPI with:
> * spi_loopback_test
> * enc28j60
> * fb_st7735r - framebuffer playing BigBuckBunny
> * mmc-spi with an out of tree patch to work arround the mmc_spi
>    internal dma mapping issues, that inhibits the driver from working
>    correctly - this got introduced with commit 0589342c27944e50
>     ("of: set dma_mask to point to coherent_dma_mask")
>
> Martin Sperl (5):
>    spi: core: added spi_resource management
>    spi: core: add spi_replace_transfers method
>    spi: core: add spi_split_transfers_maxsize
>    spi: core add spi_master.translate_message
>    spi: bcm2835: make use of the spi_translate_message methods
>
>   drivers/spi/spi-bcm2835.c |   31 +++--
>   drivers/spi/spi.c         |  339 +++++++++++++++++++++++++++++++++++++++++++++
>   include/linux/spi/spi.h   |   92 ++++++++++++
>   3 files changed, 448 insertions(+), 14 deletions(-)

Please note that Patch 1/5 (spi: core: added spi_resource management)
requires that method spi_message_init_no_memset exists(see patch-set
for spi-loopback-test) - this note did not make it into the description
of the second version of this patchset.

In the meantime I have implemented 2 more transformations:
* alignment of buffers (first spi_transfer.tx/rx_buf buffer
   remains unaligned, but has spi_transfer.len < alignment,
   second spi_transfer is fully alligned for rx/tx_buf with
   copying of tx_buf to make it alligned in the case where
   rx_buf and tx_buf are misaligned to different offsets)
* merging multiple tiny transfers

One code issue showed up (but that impacted only the new use-cases)
and there was a missing kerneldoc for one of the spi_statistics
members - these are 2 separate patches.

Should I send these separately or do you want a big patchset that
contains all of them?

Here the some of the statistics when running my spi-loopback-test:
==> /sys/class/spi_master/spi32766/statistics/transfers
1588
==> /sys/class/spi_master/spi32766/statistics/transfers_merged
102
==> /sys/class/spi_master/spi32766/statistics/transfers_split_maxsize
160
==> /sys/class/spi_master/spi32766/statistics/transfers_split_unaligned
372

Based on the above I am starting to think of readying a default
implementation for translation that drivers may use:

int spi_translate_message_size_align_merge(
         struct spi_master *master, struct spi_message *message)
{
         int ret;

         /* translate the message */

         /* fix alignment of transfers by splitting rx_buf/tx_buf
          * (and worsted case copying tx_buf)
          */
         ret = spi_split_transfers_unaligned(master, message,
                                             master->min_dma_len,
                                             master->dma_alignment);
         if (ret)
                 return ret;

         /* limit transfer length */
         if (master->max_dma_len) {
                 ret = spi_split_transfers_maxsize(master, message,
                                                   master->max_dma_len);
                 if (ret)
                         return ret;
         }

         /* merge spi_transfers up to a full page */
         ret = spi_merge_transfers(master, message, 2, PAGE_SIZE);

         return ret;
}

The spi_master driver would need to set these:
	master->translate_message =
		spi_translate_message_size_align_merge;
	master->min_dma_len = BCM2835_SPI_DMA_MIN_LENGTH;
	master->max_dma_len = 15 * PAGE_SIZE;
	master->dma_alignment = 4;

As seen above we would need to define a min_dma_len that can get used
as a parameter to align transfers (if a driver is doing PIO for short
transfers, then it makes no sense aligning them in the first place).

This value could also get used in a default implementation of can_dma.

Note that we could also expose min_dma_size via sysfs.

      parent reply	other threads:[~2015-12-09  9:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-07 15:21 [PATCH V2 0/5] spi: spi-message transformation framework kernel-TqfNSX0MhmxHKSADF0wUEw
     [not found] ` <1449501708-2228-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-12-07 15:21   ` [PATCH V2 1/5] spi: core: added spi_resource management kernel-TqfNSX0MhmxHKSADF0wUEw
     [not found]     ` <1449501708-2228-2-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-12-11 14:30       ` Andy Shevchenko
     [not found]         ` <CAHp75Vf4UGOAz5ZLCBtCeNitYY1h0P6Ae7_puVTfe+KweyeeAA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-11 14:55           ` Martin Sperl
2015-12-07 15:21   ` [PATCH V2 2/5] spi: core: add spi_replace_transfers method kernel-TqfNSX0MhmxHKSADF0wUEw
     [not found]     ` <1449501708-2228-3-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-12-11 14:37       ` Andy Shevchenko
     [not found]         ` <CAHp75Vd_7NBibKFPq++JuDiWp9zkwu9iPrjZyKK6XoL6Lr_S0g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-11 16:04           ` Martin Sperl
2015-12-07 15:21   ` [PATCH V2 3/5] spi: core: add spi_split_transfers_maxsize kernel-TqfNSX0MhmxHKSADF0wUEw
2015-12-07 15:21   ` [PATCH V2 4/5] spi: core add spi_master.translate_message kernel-TqfNSX0MhmxHKSADF0wUEw
2015-12-07 15:21   ` [PATCH V2 5/5] spi: bcm2835: split long transfers kernel-TqfNSX0MhmxHKSADF0wUEw
2015-12-09  9:38   ` Martin Sperl [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5667F698.4040709@martin.sperl.org \
    --to=kernel-tqfnsx0mhmxhksadf0wuew@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org \
    --cc=lee-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).