linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amit Uttamchandani <amit.uttam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Ned Forrester <nforrester-/d+BM93fTQY@public.gmane.org>
Cc: spi-devel
	<spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: Re: Spinlock vs mutexes for spi network driver
Date: Thu, 18 Mar 2010 13:09:40 -0700	[thread overview]
Message-ID: <20100318200940.GC16834@canoga.com> (raw)
In-Reply-To: <4BA262B1.5050001-/d+BM93fTQY@public.gmane.org>

On Thu, Mar 18, 2010 at 01:28:17PM -0400, Ned Forrester wrote:

[...]

> 
> The message is atomic in the sense that the controller driver guarantees
> to complete all the transfers defined in the message (assuming no
> errors) before it handles the next message.  Each transfer may change
> the clock or bits/word, and may also ask for the chip select to
> manipulated (or not) at the end of the transfer.  There is no guarantee
> that the next message processed by the controller driver will be for the
> same device as the previous message; the controller driver just takes
> the next message in the queue, which could have come from any of the
> protocol drivers that is operating devices on the bus.  Only when there
> is a single device on the bus is the next device certain to be the same
> as the last device.

That's good to know that it is queuing the messages. I am assuming that
this goes for all messages going into the controller right? Not just for
one specific spi message? (e.g. different spi messages from different
function calls in the same driver).

> 
> Normally, there is no locking used with SPI bus messages (except for
> spinlocks within the controller driver and its interrupt routines).
> Each protocol driver sends messages that accomplish complete tasks,
> after which the chip select to the device can be de-asserted.
> 
> Apparently, there is an issue with certain types of memory cards (SD,
> MMC?), that prevents these cards from being used on a multi-device bus
> within the present transaction model of the SPI core.  I am not familiar
> with the details, but I gather that the chip select must stay asserted
> between messages, and the needed operations cannot be combined into a
> single message (probably because the next action depends on the results
> of previous actions).  These devices are traditionally accommodated by
> making them the only device on the bus, which is somewhat inconvenient.
>  To get around this problem there have been recent proposals to
> introduce some form of locking so that the protocol driver for a memory
> device can be assured of exclusive access to the bus for a short period
> of time.  I suspect that this is patch set you are referring to.
> 

Yes, I think those are the ones I was talking about.

> In general, the design of the SPI core and controller drivers prevents
> the type of collision that you describe above.  The controller driver
> can only respond to one message at a time, and will complete that
> message before taking the next in the queue.  Only if you need to
> guarantee an un-interrupted sequence of messages, such as seems to be
> necessary for those memories, would locking be necessary.  The bus can
> only be locked in a cooperative or centralized way; there is no way to
> prevent another protocol driver from inserting a message in the
> controller driver's queue, unless all drivers have been programmed to
> respect the locks, or unless the queue mechanism is altered to pass
> messages to the controller driver only from a protocol driver that is
> holding the lock, and to put all messages from other, non lock-aware,
> drivers in a separate holding queue.  I think the latter is the method
> implemented by the proposed locking patches, but I'm not sure (I haven't
> been paying a lot of attention to that).
> 

So using spi_read and spi_write functions (which in turn calls spi_sync)
guarantees a blocking transfer. Which in my understanding means in the
code, the spi transfer will complete before moving onto the next line.

e.g.:

 -> private data manipulation code
 
 -> use spi transfer to read large amounts of data
 will it wait here until transfer is complete before moving to next
 line?

 -> use data read from spi transfer

> I'm assuming that you are using the SPI-core/protocol driver/controller
> driver model in the system that you have having trouble with.  If you
> are somehow attaching two controller drivers to the same bus, there
> there is only trouble to be had.  I hope the kernel prevents assignment
> of the same hardware resources to two drivers.
> 

Yes, I am only using one controller. In this case it is the
omap2_mcspi.c. I only have one SPI device connected.

I guess my problem seems to lie elsewhere. It could be a flaky hardware
from my end. I am transferring data to and fro an FPGA.

Could I be using SPI with dma to improve speed and maybe have access to
more resource in system memory?

Thanks again for the explanation,
Amit

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

  parent reply	other threads:[~2010-03-18 20:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-17 20:49 Spinlock vs mutexes for spi network driver Amit Uttamchandani
     [not found] ` <20100317204915.GB6358-QCuvCd35e3/QT0dZR+AlfA@public.gmane.org>
2010-03-17 21:28   ` Ned Forrester
     [not found]     ` <4BA14970.3050603-/d+BM93fTQY@public.gmane.org>
2010-03-18 16:46       ` Amit Uttamchandani
     [not found]         ` <20100318164641.GA22298-QCuvCd35e3/QT0dZR+AlfA@public.gmane.org>
2010-03-18 17:28           ` Ned Forrester
     [not found]             ` <4BA262B1.5050001-/d+BM93fTQY@public.gmane.org>
2010-03-18 20:09               ` Amit Uttamchandani [this message]
     [not found]                 ` <20100318200940.GC16834-QCuvCd35e3/QT0dZR+AlfA@public.gmane.org>
2010-03-18 22:11                   ` Ned Forrester
     [not found]                     ` <4BA2A4F4.60207-/d+BM93fTQY@public.gmane.org>
2010-03-18 23:14                       ` Ned Forrester
2010-03-19  9:35                       ` Amit Uttamchandani

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=20100318200940.GC16834@canoga.com \
    --to=amit.uttam-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=nforrester-/d+BM93fTQY@public.gmane.org \
    --cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@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).