linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Sperl <martin-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Linus Walleij
	<linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
Subject: Re: Depreciated spi_master.transfer and "prepared spi messages" for an optimized pipelined-SPI-DMA-driver
Date: Mon, 4 Nov 2013 22:43:03 +0100	[thread overview]
Message-ID: <5A55A832-5313-499C-A483-BF5A6649D69D@sperl.org> (raw)
In-Reply-To: <20131104184511.GR2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>

Hi Mark!

I just found out that I am in a chicken or egg situation:
There is no DMA support whatsoever in the upstream RPI support.
So sending any patches for spi with DMA becomes impossible right now.

Setting up a system that runs the upstream kernel without patches will be 
some effort on my side so that may take quite some time for me to start.

Until then I will need to "work" with the tainted kernel and APIs from the
foundation using their special APIs, which you obviously can not accept 
for moving them upstream.

That is why I just wanted to share with you what may get achieved with your 
new interface and what is missing from my perspective to make it work in
a practical manner. 

And that is why I have added only the link to the driver.

I am in a sort of situation that makes it hard to move in either direction.

I believe we all got our interests:
* you want your prepared interface tested in a driver
* I want to get the spi-dma driver in the main-line
* some other people want the dma engine work to get started for the RPI,
  so that they can get to real productive work on USB and others.

All I can give you right now is the feedback from my experience with this out 
of kernel driver, which is not a candidate for merging in its current state 
due to limitations mentioned above.

The results look promising and will improve further!

The only thing I can think of that would help me (and others) in the long 
run is getting those missing parts of your prepare API into the kernel 
early to avoid code duplication (see earlier email with the basics).

By then I may have the driver up and running quite well on the Foundation RPI 
kernel and hopefully some people should also have tested it with more devices.

As soon as that is stable and I get a "vanilla" kernel running with the 
improvements I had recommended from my experience, I can start some basics 
of dmaengine for the RPI (allocation and release DMA to start keeping 
everything else in the driver for now) and then we can really start talking 
about patches for the spi-driver to send.

again: first the dma-engine part would need to be upstream before I assume
you would accept to merge the driver, as the functionality would NOT work
otherwise. So we talk about 3.15 at the very earliest...

So is the presented idea an approach to move forward on?
Or do you have a better approach which we could follow to get us out of this 
tie?

Thanks,
	Martin

P.s: here the pieces of code for which I have earlier only shown the 
prototypes - these are untested and I am not sure they will even compile as
is because I had to modify the driver specific version here in this email
to make them work with the list/lock variables in the master-structure - the 
driver specific code works. Also no documentation for the functions.

That is the best I can do for now.

/* generic wrapper functions for device drivers to use */
static int bcm2835dma_spi_prepare_message(struct spi_device *spi,
	struct spi_message *msg)
{
	if(spi->master->prepare_message) {
		return spi->master->prepare_message(spi,msg);
	} else {
		return 0;
	}
}

static int bcm2835dma_spi_unprepare_message(struct spi_device *spi,
	struct spi_message* msg)
{
	if(spi->master->unprepare_message) {
		return spi->master->unprepare_message(spi,msg);
	} else {
		return 0;
	}
}

in struct spi_master
/* note that it misses initialization for those two fields */
	struct list_head	prepared_messages_list;
	spinlock_t		prepared_messages_lock;

/* functions used to store/find/remove prepared objects 
 * for now putting them in a simple list.
 * only bus drivers should call these really in their (un)prepare code
 * later on it may be worthwhile changing this structure to
 * be in a binary tree - the big question is: how many prepared messages
 * may we expect on a single SPI bus?
 * alternatively we could also move it of to the spi_device structure.
 */

/* the structure to embed in the bus specific implementation */
struct spi_prepared_message {
	/* the list in which we store the prepared messages */
	struct list_head prepared_list;
	/* the identification data for searching the list*/
	struct spi_device *spi;
	struct spi_message *message;
	/* maybe some search-statistics, so that we can reorder/optimize
	 * the list to make the searches for the most commonly used 
	 * messages faster by being in "front"
         */
};

static struct spi_prepared_message *spi_find_prepared_message_nolock(
        struct spi_device *spi,
        struct spi_message *message)
{
        struct spi_master *master=spi->master;
        /* ideally this would be in master */
        struct spi_prepared_message *prepared;
        /* now loop the entries */
        list_for_each_entry(prepared, &master->prepared_messages_list, prepared_list) {
                /* if we match, then return */
                if ((prepared->spi==spi)
                        && (prepared->message==message))
                        return prepared;
        }
        /* return not found */
        return NULL;
}

static struct spi_prepared_message *spi_find_prepared_message(
        struct spi_device *spi,
        struct spi_message *message)
{
        struct spi_prepared_message *prepared;
        struct spi_master *master=spi->master;
        unsigned long flags;
	/* lock */
        spin_lock_irqsave(&master->prepared_messages_lock,flags);
        /* try to find it */
        prepared=spi_find_prepared_message_nolock(spi,message);
        /* and unlock and return */
        spin_unlock_irqrestore(&master->prepared_messages_lock,flags);
        return prepared;
}

static int spi_add_prepared_message(
        struct spi_prepared_message * prepared)
{
        struct spi_device *spi=prepared->spi;
        struct spi_master *master=spi->master;
        struct spi_message *message=prepared->message;
        unsigned long flags;
	/* lock */
        spin_lock_irqsave(&master->prepared_messages_lock,flags);
        /* find the entry and croak if it has beeen prepared before */
        if (spi_find_prepared_message_nolock(spi,message)) {
	        spin_unlock_irqrestore(&master->prepared_messages_lock,flags);
                dev_err(&spi->dev,"SPI message has already been prepared once\n");
                return -EPERM;
        }
        /* now add it to the list at tail*/
        list_add_tail(&prepared->prepared_list,&master->prepared_messages_list);

        /* unlock and return */
        spin_unlock_irqrestore(&master->prepared_messages_lock,flags);
        return 0;
}

struct spi_prepared_message *spi_remove_prepared_message(
        struct spi_device *spi,
        struct spi_message *message
        )
{
        struct spi_prepared_message *prep=NULL;
        struct spi_master *master=spi->master;
        unsigned long flags;
	/* lock */
        spin_lock_irqsave(&master->prepared_messages_lock,flags);
	/* find the entry */
        prep=spi_find_prepared_message_nolock(spi,message);
        /* now unlink the prepared item - if found  - we could croak otherwise */
        if (prep) {
                list_del(&prep->prepared_list);
	} else {
                dev_err(&spi->dev,"SPI message has not been prepared\n");
	}
        /* unlock and return the version removed from the list*/
        spin_unlock_irqrestore(&master->prepared_messages_lock,flags);
        return prep;
}


On 04.11.2013, at 19:45, Mark Brown wrote:

> On Mon, Nov 04, 2013 at 06:33:19PM +0100, Martin Sperl wrote:
> 
>> The driver itself can get found at: https://github.com/msperl/spi-bcm2835
> 
> Please post code/patches normally rather than linking to git, it's much
> less likely that people will look at some random gitweb thing and much
> harder to respond.

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2013-11-04 21:43 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <F70C4469-6325-48D5-A7CA-52CC1FC404BD@sperl.org>
     [not found] ` <CACRpkdb6y=o4__snBs2DR1f=xW_u7KdkHg3fb7XN5e2gicBJeg@mail.gmail.com>
     [not found]   ` <CACRpkdb6y=o4__snBs2DR1f=xW_u7KdkHg3fb7XN5e2gicBJeg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-10-29 16:59     ` Fwd: Depreciated spi_master.transfer and "prepared spi messages" for an optimized pipelined-SPI-DMA-driver Linus Walleij
     [not found]       ` <CACRpkdb7y88oq7XyVFc_0Nx4pXtaebPe7KB2yizBRJGwWLqJig-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-10-29 17:56         ` Mark Brown
2013-10-29 21:18         ` Martin Sperl
     [not found]           ` <06C7F4D3-EC91-46CF-90BE-FC24D54F2389-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-29 22:53             ` Mark Brown
     [not found]               ` <20131029225353.GB11424-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-10-30 17:11                 ` Martin Sperl
     [not found]                   ` <F64AD25A-C7EC-4A0D-9169-850C12F4D8A3-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-30 21:51                     ` Mark Brown
2013-10-30  8:40             ` Martin Sperl
     [not found]               ` <02BFF0F6-3836-4DEC-AA53-FF100E037DE9-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-30 17:19                 ` Mark Brown
     [not found]                   ` <20131030171902.GL2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-10-30 18:33                     ` Martin Sperl
     [not found]                       ` <8D8B0BAD-0E00-4147-B4C8-FBB18F060C96-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-30 21:57                         ` Mark Brown
     [not found]                           ` <20131030215716.GV2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-10-30 22:52                             ` Martin Sperl
     [not found]                               ` <3342FD19-4438-463B-89B2-A83D3475AC22-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-31  0:10                                 ` Mark Brown
     [not found]                                   ` <20131031001004.GW2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-04 17:33                                     ` Martin Sperl
     [not found]                                       ` <18639D9A-630E-44F3-AA7A-ADFF5D5E8B56-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-04 18:45                                         ` Mark Brown
     [not found]                                           ` <20131104184511.GR2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-04 21:43                                             ` Martin Sperl [this message]
     [not found]                                               ` <5A55A832-5313-499C-A483-BF5A6649D69D-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-05  1:03                                                 ` Linus Walleij
2013-11-06  9:48                                                 ` Mark Brown
     [not found]                                                   ` <20131106094854.GF11602-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-06 11:28                                                     ` Martin Sperl
     [not found]                                                       ` <844EDAEA-3FDC-48D0-B59E-CECC0A83761E-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-06 11:32                                                         ` Mark Brown
     [not found]                                                           ` <20131106113219.GJ11602-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-06 12:10                                                             ` Martin Sperl
     [not found]                                                               ` <C6C68042-63A0-40FD-8363-B4553ECB4774-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-06 16:24                                                                 ` Mark Brown
     [not found]                                                                   ` <20131106162410.GB2674-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-06 19:54                                                                     ` Martin Sperl
     [not found]                                                                       ` <3B0EDE3F-3386-4879-8D89-2E4577860073-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-06 23:26                                                                         ` Mark Brown
     [not found]                                                                           ` <20131106232605.GC2674-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-07  0:43                                                                             ` Martin Sperl
     [not found]                                                                               ` <72D635F5-4229-4D78-8AA3-1392D5D80127-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-07 20:31                                                                                 ` Mark Brown
     [not found]                                                                                   ` <20131107203127.GB2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-08 14:16                                                                                     ` Martin Sperl
     [not found]                                                                                       ` <86AE15B6-05AF-4EFF-8B8F-10806A7C148B-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-08 16:19                                                                                         ` Mark Brown
     [not found]                                                                                           ` <20131108161957.GP2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-08 17:31                                                                                             ` Martin Sperl
     [not found]                                                                                               ` <5F70E708-89B9-4DCF-A31A-E688BAA0E062-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-08 18:09                                                                                                 ` Mark Brown
     [not found]                                                                                                   ` <20131108180934.GQ2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-08 19:18                                                                                                     ` Martin Sperl
     [not found]                                                                                                       ` <C375DEE6-1AEC-4AFB-A9D6-583DCB4476A3-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-09 18:30                                                                                                         ` Mark Brown
     [not found]                                                                                                           ` <20131109183056.GU2493-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-10 10:54                                                                                                             ` Martin Sperl
     [not found]                                                                                                               ` <6C7903B3-8563-490E-AD7D-BA5D65FFB9BC-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-12  1:19                                                                                                                 ` Mark Brown
     [not found]                                                                                                                   ` <20131112011954.GH2674-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-12 14:42                                                                                                                     ` Martin Sperl
     [not found]                                                                                                                       ` <52823E73.503-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-12 17:59                                                                                                                         ` Martin Sperl
     [not found]                                                                                                                           ` <2252E63E-176C-43F7-B259-D1C3A142DAFE-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-13 15:43                                                                                                                             ` Mark Brown
     [not found]                                                                                                                               ` <20131113154346.GT878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-13 18:35                                                                                                                                 ` Martin Sperl
     [not found]                                                                                                                                   ` <ED58E869-A9F6-4BB2-8EC6-D71F946509DC-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-13 19:33                                                                                                                                     ` Mark Brown
     [not found]                                                                                                                                       ` <20131113193320.GE878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-13 21:31                                                                                                                                         ` Martin Sperl
2013-11-13 15:11                                                                                                                         ` Mark Brown
     [not found]                                                                                                                           ` <20131113151102.GS878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-13 15:48                                                                                                                             ` Martin Sperl
     [not found]                                                                                                                               ` <77070979-0CE4-4C76-B12E-DA94B2577172-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-13 16:59                                                                                                                                 ` Mark Brown
2013-11-14  1:50                                                                                                                         ` Mark Brown
     [not found]                                                                                                                           ` <20131114015009.GB26614-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-14 19:47                                                                                                                             ` Martin Sperl
     [not found]                                                                                                                               ` <9640F4C7-7F82-453E-9D83-5875A1559A20-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-15 11:15                                                                                                                                 ` Martin Sperl
     [not found]                                                                                                                                   ` <5286026B.2090903-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-16 14:23                                                                                                                                     ` Mark Brown
     [not found]                                                                                                                                       ` <20131116142356.GY15393-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-19 13:11                                                                                                                                         ` Martin Sperl
     [not found]                                                                                                                                           ` <528B6370.9000903-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-19 15:02                                                                                                                                             ` Mark Brown
     [not found]                                                                                                                                               ` <20131119150204.GA2674-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-19 15:13                                                                                                                                                 ` Martin Sperl
2013-11-15 13:33                                                                                                                                 ` Mark Brown
     [not found]                                                                                                                                   ` <20131115133312.GE26614-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-15 14:52                                                                                                                                     ` Martin Sperl
     [not found]                                                                                                                                       ` <0BA2243C-2F22-492A-B517-76E243535549-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-16 12:56                                                                                                                                         ` Mark Brown
2013-11-10 11:05                                                                                                             ` Mark Brown
     [not found]                                                                                                               ` <20131110110524.GA878-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-10 16:41                                                                                                                 ` Martin Sperl
     [not found]                                                                                                                   ` <3361A01A-C7D0-4689-AFBD-085D3E62A67C-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-11-11 11:18                                                                                                                     ` Mark Brown
     [not found]                                                                                                                       ` <20131111111842.GE2674-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-11-11 11:44                                                                                                                         ` Martin Sperl
     [not found] ` <F70C4469-6325-48D5-A7CA-52CC1FC404BD-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2013-10-29 19:09   ` Fwd: " Linus Walleij

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=5A55A832-5313-499C-A483-BF5A6649D69D@sperl.org \
    --to=martin-d5rikyn9cnpytjvyw6ydsg@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@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).