Skip to contentSkip to conversation

SPI

PATCH dmitry pervushin 4 participants 9 messages Nov 11, 2005 – Nov 23, 2005 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

This is an updated version of SPI framework from me, Dmitry Pervushin. It seems that now it is good time to consolidate our SPI frameworks to push it to kernel :)

We've tested our SPI core as well with bus drivers with wireless LAN driver and achieved good performance with relatively small overhead. This proves the viability of this framework in real life even in real-time environment. The size of .text is
still about 2,500 bytes, that is comparable with David Brownell's framework size.

I think now is the time to start the final convergence process for these two cores and get the final core
into the mainline kernel. And in order to understand where we need to converge, I created the main differences
list (see below).

The list of main differences between David Brownell's SPI framework (A) and my one (B):
- (A) uses more complicated structure of SPI message, that contains one or more atomic transfers, and (B)
offers the only spi_msg that represents the atomic transfer on SPI bus.
The similar approach can be imple-
mented in (B), and actually is implemented. But my imp[ression is that
such enhancement may be added later..
- (A) uses workqueues to queue and handle SPI messages, and (B) allocates the kernel thread to the same purpose.
Using workqueues is not very good solution in real-time environment; I
think that allocating and starting the
separate thread will give us more predictable and stable results;
- (A) has some assumptions on buffers that are passed down to spi functions. If some controller driver (or bus driver
in terms of (B)) tries to perform DMA transfers, it must copy the
passed buffers to some memory allocated
using GFP_DMA flag and map it using dma_map_single. From the other
hand, (B) relies on callbacks provided
by SPI device driver to allocate memory for DMA transfers, but keeps
ability to pass user-allocated buffers down
to SPI functions by specifying flags in SPI message. SPI message being
a fundamental essense looks better to me when
it's as simple as possible. Especially when we don't lose any
flexibility which is exacly our case (buffers that are
allocated as well as message itself/provided by user, DMA-capable
buffers..)
- (A) retrieves SPI message from the queue in sequential order (FIFO), but (B) provides more flexible way by providing
special callback to retrieve next message from queue. This callback may
implement its own discipline of scheduling
SPI messages. In any way, the default is FIFO.
- (A) uses standartized way to provide CS information, and (B) relies on functional drivers callbacks, which looks more
flexible to me.

 linux/include/linux/spi.h |  285 +++++++++++++++
 linux/Documentation/spi.txt          |  382 ++++++++++++++++++++
 linux/arch/arm/Kconfig               |    2 
 linux/drivers/Kconfig                |    2 
 linux/drivers/Makefile               |    1 
 linux/drivers/spi/Kconfig            |   33 +
 linux/drivers/spi/Makefile           |   14 
 linux/drivers/spi/spi-core.c         |  645 +++++++++++++++++++++++++++++++++++
 linux/drivers/spi/spi-dev.c          |  219 +++++++++++
 9 files changed, 1583 insertions(+)
arch/arm/Kconfig +2 -0
Index: linux/arch/arm/Kconfig
===================================================================
@@ -834,6 +834,8 @@ source "drivers/ssi/Kconfig"
 
 source "drivers/mmc/Kconfig"
 
+source "drivers/spi/Kconfig"
+
 endmenu
 
 source "ktools/Kconfig"
drivers/Kconfig +2 -0
Index: linux/drivers/Kconfig
===================================================================
@@ -42,6 +42,8 @@ source "drivers/char/Kconfig"
 
 source "drivers/i2c/Kconfig"
 
+source "drivers/spi/Kconfig"
+
 source "drivers/w1/Kconfig"
 
 source "drivers/misc/Kconfig"
drivers/Makefile +1 -0
Index: linux/drivers/Makefile
===================================================================
@@ -67,3 +67,4 @@ obj-$(CONFIG_DPM)		+= dpm/
 obj-$(CONFIG_MMC)		+= mmc/
 obj-y				+= firmware/
 obj-$(CONFIG_EVENT_BROKER)	+= evb/
+obj-$(CONFIG_SPI)		+= spi/
drivers/spi/Kconfig new file +33 -0
Index: linux/drivers/spi/Kconfig
===================================================================
@@ -0,0 +1,33 @@
+#
+# SPI device configuration
+#
+menu "SPI support"
+
+config SPI
+	default Y
+	tristate "SPI (Serial Peripheral Interface) bus support"
+        default false
+	help
+	  Say Y if you need to enable SPI support on your kernel.
+ 	  Say M if you want to create the spi-core loadable module.
+
+config SPI_DEBUG
+	bool "SPI debug output"
+	depends on SPI
+	default false
+	help
+          Say Y there if you'd like to see debug output from SPI drivers
+	  If unsure, say N
+
+config SPI_CHARDEV
+	default Y
+	tristate "SPI device interface"
+	depends on SPI
+	help
+	  Say Y here to use /dev/spiNN device files. They make it possible to have user-space
+	  programs use the SPI bus.
+	  This support is also available as a module.  If so, the module
+	  will be called spi-dev.
+
+endmenu
+
drivers/spi/Makefile new file +14 -0
Index: linux/drivers/spi/Makefile
===================================================================
@@ -0,0 +1,14 @@
+#
+# Makefile for the kernel spi bus driver.
+#
+
+obj-$(CONFIG_SPI) += spi-core.o
+# bus drivers
+# ...functional drivers
+# ...and the common spi-dev driver
+obj-$(CONFIG_SPI_CHARDEV) += spi-dev.o
+
+ifeq ($(CONFIG_SPI_DEBUG),y)
+EXTRA_CFLAGS += -DDEBUG
+endif
+
drivers/spi/spi-core.c new file +645 -0

645 lines not on this page · raw message

drivers/spi/spi-dev.c new file +219 -0

219 lines not on this page · raw message

Documentation/spi.txt new file +382 -0

382 lines not on this page · raw message

include/linux/spi.h new file +285 -0

285 lines not on this page · raw message

#1 lore raw
Quoted 17 lines · --- dmitry pervushin

This is an updated version of SPI framework from me, Dmitry Pervushin. It seems that now it is good time to consolidate our SPI frameworks to push it to kernel :)

We've tested our SPI core as well with bus drivers with wireless LAN driver and achieved good performance with relatively small overhead. This proves the viability of this framework in real life even in real-time environment. The size of .text is
still about 2,500 bytes, that is comparable with David Brownell's framework size.

I think now is the time to start the final convergence process for these two cores and get the final core
into the mainline kernel. And in order to understand where we need to converge, I created the main differences
list (see below).

Quoted 8 lines

The list of main differences between David Brownell's SPI framework (A) and my one (B):
- (A) uses more complicated structure of SPI message, that contains one or more atomic transfers, and (B)
offers the only spi_msg that represents the atomic transfer on SPI bus.
The similar approach can be imple-
mented in (B), and actually is implemented. But my imp[ression is that
such enhancement may be added later..

I wouldn't have said that the message structure in (A) is more complex then (B). For example, in
(B) you have many flags which controls things like SPI mode which are not needed in every message. Once the SPI controller has been setup for a particular slave device you don't need to constantly send this information.
In (B) how to do you handle SPI devices which require to send several messages with out releasing their cs? There are/will be some devices which require this.

Quoted 5 lines

- (A) uses workqueues to queue and handle SPI messages, and (B) allocates the kernel thread to the same purpose.
Using workqueues is not very good solution in real-time environment; I
think that allocating and starting the
separate thread will give us more predictable and stable results;

Where does (A) use a workqueue? (A) doesn't use a workqueue or thread and instead leaves it up to the adapter driver how to handle the messages that it gets sent (which in the case of some drivers will mean no thread or workqueue). (B) is _forcing_ a thread on the adapter which the adapter may not need.

Quoted 6 lines

- (A) has some assumptions on buffers that are passed down to spi functions. If some controller driver (or bus driver
in terms of (B)) tries to perform DMA transfers, it must copy the
passed buffers to some memory allocated
using GFP_DMA flag and map it using dma_map_single. From the other
hand, (B) relies on callbacks provided

Quoted 8 lines

by SPI device driver to allocate memory for DMA transfers, but keeps
ability to pass user-allocated buffers down
to SPI functions by specifying flags in SPI message. SPI message being
a fundamental essense looks better to me when
it's as simple as possible. Especially when we don't lose any
flexibility which is exacly our case (buffers that are
allocated as well as message itself/provided by user, DMA-capable
buffers..)

But allocating and freeing buffer is a core kernel thing not a SPI thing. To me you are adding more complexity then is needed and your saying this is keeping things simple?

Quoted 5 lines

- (A) retrieves SPI message from the queue in sequential order (FIFO), but (B) provides more flexible way by providing
special callback to retrieve next message from queue. This callback may
implement its own discipline of scheduling
SPI messages. In any way, the default is FIFO.

I think (A) is missing a method of adding extra spi_message(s) in callback to extend the current transfer on that SPI device. I can imagine a case where you will be required to read status information from a device and in this status information is the length of the data it has just received (for example if it was a network adapter). Straight after reading this information the device would start sending the data it has received but when the read status message was issued the length of the data wasn't known. Currently with (A) we would have to stop the transfer and restart the whole thing again, this time using the length of the data we found form the last message.

A better solution would to be able to add an extra message during the callback from the first message as now we know then length we can setup a transfer that would be the correct size. However, this message must be the next message that the adapter sends as if another message for another SPI device was sent before then the cs line of the device we are talking to would be deselected and we would have to start again.

My proposal is that in the callback from a spi_message being sent it returns a pointer to the next spi_message which the adapter will send before it continues sending any other messages (this is like the adapter being locked by the SPI device), if no other messages need to be sent atomically in the callback of current message then the SPI device driver would just return NULL.

Example:
========
/* callback/complete routine of a SPI device/protocol driver */ int my_spi_callback (void *data)

{ 
	struct my_status_struct = data; 
	struct spi_message read_message; 
	 
	/* Check to see if we have received any data */ 
	if (my_status_struct->read_length) 
	{ 
		/* Create a new spi_message to read the data which will be 
		 * the very next thing the device will send */ 
		  
		 read_message = kzalloc(...) 
		 ... 
		 return read_message; 
	} 
	else 
		/* No data to be read so don't append another message */ 
		return NULL; 
} 
Quoted 3 lines

- (A) uses standartized way to provide CS information, and (B) relies on functional drivers callbacks, which looks more
flexible to me.

I'm not sure what you mean here. You need to provide the cs numbers with SPI device in order for the core to create the unique addres and entry in sysfs.
However, (A) is not checking to see if the cs that a registering device wants to use is already in use, this needs to be added, and the same is true for registering spi masters.

Mark

___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com

#2 lore raw
Quoted 11 lines · Mark Underwood
Quoted 10 lines

The list of main differences between David Brownell's SPI framework (A) and my one (B):
- (A) uses more complicated structure of SPI message, that contains one or more atomic transfers, and (B)
offers the only spi_msg that represents the atomic transfer on SPI bus. The similar approach can be imple-
mented in (B), and actually is implemented. But my imp[ression is that such enhancement may be added later..

Quoted 7 lines

I wouldn't have said that the message structure in (A) is more complex then (B). For example, in
(B) you have many flags which controls things like SPI mode which are not needed in every message. Once the SPI controller has been setup for a particular slave device you don't need to constantly send this information. In (B) how to do you handle SPI devices which require to send several messages with out releasing their cs? There are/will be some devices which require this.

Please see the explanation for the 'flags' in Documentation/spi.txt within the patch.

Quoted 9 lines
Quoted 8 lines

- (A) uses workqueues to queue and handle SPI messages, and (B)
allocates the kernel thread to the same purpose.
Using workqueues is not very good solution in real-time environment; I
think that allocating and starting the separate thread will give us more predictable and stable results;

Quoted 6 lines

Where does (A) use a workqueue? (A) doesn't use a workqueue or thread and instead leaves it up to the adapter driver how to handle the messages that it gets sent (which in the case of some drivers will mean no thread or workqueue). (B) is _forcing_ a thread on the adapter which the adapter may not need.

I bet the drivers that don't need neither threads not workqueue there's no need in async transfers as well. :)
On the other hand, threads is a flexible mechanism for handling async stuff, and there won't be a lot of threads so the overhead won't be high.
You might also want to ask why you can't change the steering wheel placement in your car from right-side to rleft-side although you travel by car to continental Europe once per decade. ;-)

Quoted 17 lines
Quoted 16 lines

- (A) has some assumptions on buffers that are passed down to spi
functions. If some controller driver (or bus driver
in terms of (B)) tries to perform DMA transfers, it must copy the
passed buffers to some memory allocated
using GFP_DMA flag and map it using dma_map_single. From the other
hand, (B) relies on callbacks provided by SPI device driver to allocate memory for DMA transfers, but keeps ability to pass user-allocated buffers down
to SPI functions by specifying flags in SPI message. SPI message being
a fundamental essense looks better to me when it's as simple as possible. Especially when we don't lose any flexibility which is exacly our case (buffers that are
allocated as well as message itself/provided by user, DMA-capable
buffers..)

Quoted 4 lines

But allocating and freeing buffer is a core kernel thing not a SPI thing. To me you are adding more complexity then is needed and your saying this is keeping things simple?

I'm afraid that you're not quite getting the whole concept. The concept is to provide thorough and stable solution.
Given that the buffer passed is declared as, say, static, the whole kernel might crash if we try to pass it to DMA. David's core itself is not capable of filtering that and letting the driver decide adds more complexity to the driver. If we're choosing between adding complexity to the core and adding it to the particular drivers, it's definitely better to add it to the core cuz it's done _once_.

Quoted 11 lines
Quoted 5 lines

- (A) uses standartized way to provide CS information, and (B) relies on functional drivers callbacks, which looks more
flexible to me.

I'm not sure what you mean here. You need to provide the cs numbers with SPI device in order for
the core to create the unique addres and entry in sysfs. However, (A) is not checking to see if the cs that a registering device wants to use is already in use, this needs to be added, and the same is true for registering spi masters.

Can you please elaborate on that?

Vitaly

#3 lore raw
Quoted 19 lines · --- Vitaly Wool
Quoted 11 lines · Mark Underwood
Quoted 10 lines

The list of main differences between David Brownell's SPI framework (A) and my one (B):
- (A) uses more complicated structure of SPI message, that contains one or more atomic transfers, and (B)
offers the only spi_msg that represents the atomic transfer on SPI bus. The similar approach can be imple-
mented in (B), and actually is implemented. But my imp[ression is that such enhancement may be added later..

Quoted 1 line

I wouldn't have said that the message structure in (A) is more complex then (B). For example,

in

Quoted 1 line

(B) you have many flags which controls things like SPI mode which are not needed in every

message.

Quoted 1 line

Once the SPI controller has been setup for a particular slave device you don't need to

constantly

Quoted 8 lines
Quoted 2 lines

send this information.
In (B) how to do you handle SPI devices which require to send several messages with out

releasing

Quoted 3 lines

their cs? There are/will be some devices which require this.

Please see the explanation for the 'flags' in Documentation/spi.txt within the patch.

I can see that you can leave cs active at the end of a transfer but that's not my point. How do you make sure that message for other SPI devices don't get send while the cs of the current device is high?

Quoted 20 lines
Quoted 11 lines
Quoted 10 lines

- (A) uses workqueues to queue and handle SPI messages, and (B) allocates the kernel thread to the same purpose.
Using workqueues is not very good solution in real-time environment; I think that allocating and starting the
separate thread will give us more predictable and stable results;

Quoted 1 line

Where does (A) use a workqueue? (A) doesn't use a workqueue or thread and instead leaves it up

to

Quoted 1 line

the adapter driver how to handle the messages that it gets sent (which in the case of some

drivers

Quoted 1 line

will mean no thread or workqueue). (B) is _forcing_ a thread on the adapter which the adapter

may

Quoted 3 lines

not need.

Quoted 7 lines

I bet the drivers that don't need neither threads not workqueue there's no need in async transfers as well. :)
On the other hand, threads is a flexible mechanism for handling async stuff, and there won't be a lot of threads so the overhead won't be high. You might also want to ask why you can't change the steering wheel placement in your car from right-side to rleft-side although you travel by car to continental Europe once per decade. ;-)

Sorry I'm not following you here.

Example:
An interrupt driven PIO doesn't need a thread or a workqueue. When it is idle the call to its transfer function can start off the first transfer and after that the interrupt routine will check for a new transfer when it has finished the current one. David provided other examples so if you are still not sure search through the archives.

Quoted 24 lines
Quoted 20 lines
Quoted 19 lines

- (A) has some assumptions on buffers that are passed down to spi functions. If some controller driver (or bus driver
in terms of (B)) tries to perform DMA transfers, it must copy the passed buffers to some memory allocated
using GFP_DMA flag and map it using dma_map_single. From the other hand, (B) relies on callbacks provided
by SPI device driver to allocate memory for DMA transfers, but keeps ability to pass user-allocated buffers down
to SPI functions by specifying flags in SPI message. SPI message being a fundamental essense looks better to me when
it's as simple as possible. Especially when we don't lose any flexibility which is exacly our case (buffers that are allocated as well as message itself/provided by user, DMA-capable buffers..)

Quoted 4 lines

But allocating and freeing buffer is a core kernel thing not a SPI thing. To me you are adding more complexity then is needed and your saying this is keeping things simple?

Quoted 9 lines

I'm afraid that you're not quite getting the whole concept. The concept is to provide thorough and stable solution.
Given that the buffer passed is declared as, say, static, the whole kernel might crash if we try to pass it to DMA. David's core itself is not capable of filtering that and letting the driver decide adds more complexity to the driver.
If we're choosing between adding complexity to the core and adding it to the particular drivers, it's definitely better to add it to the core cuz it's done _once_.

I'm not 100% sure how David is handling this, but one option would be to have a not_dmaable flag which states that the buffers used in this message are not DMAable and in this case the adapter driver will either do a PIO transfer or bounce the data to/from a DMAable buffer it allocated itself. I don't see why a SPI adapter driver needs to supply alloc/free callbacks when a simple flag would do the job.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

- (A) uses standartized way to provide CS information, and (B) relies on functional drivers callbacks, which looks more
flexible to me.

I'm not sure what you mean here. You need to provide the cs numbers with SPI device in order

Quoted 8 lines

for

Quoted 2 lines

the core to create the unique addres and entry in sysfs.
However, (A) is not checking to see if the cs that a registering device wants to use is already

in

Quoted 3 lines

use, this needs to be added, and the same is true for registering spi masters.

Can you please elaborate on that?

If I register a SPI device on cs1 of spi-1 and later try to register another device on cs1 of spi-1 I would expect the spi core layer to fail the registration of the second device.

Mark

Quoted 8 lines

Vitaly
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com

#4 lore raw
In reply to Mark Underwood
Quoted 5 lines · Mark Underwood
Quoted 2 lines · --- dmitry pervushin

The list of main differences between David Brownell's SPI framework (A) and my one (B):

A == http://marc.theaimsgroup.com/?l=linux-kernel&m=113169588230519&w=2
plus a handful of rather minor tweaks (ssize_t, comments, etc).

B == http://sourceforge.net/mailarchive/message.php?msg_id=13824397
but it needs updates to match current 2.6.15-rc code.

Quoted 11 lines
Quoted 6 lines

- (A) uses more complicated structure of SPI message, that contains one or more atomic transfers, and (B)
offers the only spi_msg that represents the atomic transfer on SPI bus. The similar approach can be implemented
in (B), and actually is implemented. But my imp[ression is that such enhancement may be added later..

I wouldn't have said that the message structure in (A) is more complex then (B). For example, in
(B) you have many flags which controls things like SPI mode which are not needed in every message. Once the SPI controller has been setup for a particular slave device you don't need to constantly send this information.

And in fact, constantly sending it means some drivers will have to waste time constantly checking it, in case it changed. If that setup is stored in controller registers, it's a lot better to just have the setup() call be responsible for changing the communication parameters. (This is the approach used by both MMC and PCMCIA, for what it's worth...)

Quoted 2 lines

In (B) how to do you handle SPI devices which require to send several messages with out releasing their cs? There are/will be some devices which require this.

In fact, that's why the transfer segments are grouped. One builds SPI protocol requests out of several such segments. A very common idiom is writing a command, then reading its response. Chipselect must stay active during the whole sequence.

Adding support for such a basic mechanism "later" doesn't seem like a good idea to me.

Quoted 10 lines
Quoted 5 lines

- (A) uses workqueues to queue and handle SPI messages, and (B) allocates the kernel thread to the same purpose.
Using workqueues is not very good solution in real-time environment; I think that allocating and starting the
separate thread will give us more predictable and stable results;

Where does (A) use a workqueue? (A) doesn't use a workqueue or thread and instead leaves it up to the adapter driver how to handle the messages that it gets sent (which in the case of some drivers will mean no thread or workqueue). (B) is _forcing_ a thread on the adapter which the adapter may not need.

Exactly. That's one of the things I meant when I recently listed some of the top goals of the framework I did:

(a) SPI shouldn't perpetuate the driver model botches of I2C;
(b) ditto I2C's "everything is synchronous" botches;
(c) it should work well with DMA, to support things like DataFlash;
(d) given the variety of SPI chips, protocol controls are needed;
(e) place minimal implementation constraints on controller drivers.

So for example one way you know that (c) is well met is that it's the same approach used in USB (both host and peripheral/gadget sides); that's been working well for quite a few years now. (Despite comments from Dmitry and Vitaly to the contrary.)

Quoted 2 lines
Quoted 2 lines

- (A) has some assumptions on buffers that are passed down to spi functions.

Make that "requirements"; FWIW they're the same ones that apply to all other kernel driver frameworks I've seen: that buffers be DMA-safe. It would not be helpful (IMO) to define different rules; that's also called the "Principle of Least Astonishment". :)

Quoted 4 lines
Quoted 4 lines

If some controller driver (or bus driver
in terms of (B)) tries to perform DMA transfers, it must copy the passed buffers to some memory allocated
using GFP_DMA flag and map it using dma_map_single.

Based on this and other comments from Dmitry/Vitaly, I suspect they don't see how the Linux DMA APIs work. The correct statement is that if a controller driver wants to use DMA, it must dma_{map,unmap}_single(). The upper level drivers don't _need_ to worry about that.

However, some key infrastructure is in place to let SPI protocol drivers (the ones passing messages through the controller then the bus) provide pre-mapped buffers if the eventually _want_ to do that. They'd likely be allocated with dma_alloc_coherent() or through a dma_pool. That would be useful for cases like an MMC/SD block driver that talks SPI, since the scatterlists will come down from the block layer ... lower level drivers should be able to ignore details like how dma_{map,unmap}_sg() works.

Quoted 11 lines
Quoted 10 lines

From the other
hand, (B) relies on callbacks provided
by SPI device driver to allocate memory for DMA transfers, but keeps ability to pass user-allocated buffers down
to SPI functions by specifying flags in SPI message. SPI message being a fundamental essense looks better to me when
it's as simple as possible. Especially when we don't lose any flexibility which is exacly our case (buffers that are allocated as well as message itself/provided by user, DMA-capable buffers..)

Quoted 2 lines

But allocating and freeing buffer is a core kernel thing not a SPI thing. To me you are adding more complexity then is needed and your saying this is keeping things simple?

That's how I read his comments too. Moreover, that particular kind of complexity is the confusing kind ... it makes it a lot harder to see what's going on, since it's all hidden behind layers of indirection. Indirection is of course useful sometimes. But not in this case, where there are much simpler idioms, with the advantage that most other kernel APIs use them.

Quoted 1 line
Quoted 1 line

- (A) retrieves SPI message from the queue in sequential order (FIFO),

Only with respect to a given device. It would make no sense to reorder the queue so that writing X, then Y, then Z would morph into "X Z Y" or "Z Y X". :)

It's specifically _undefined_ how requests going to different devices are ordered. Some hardware will be happier if things are synchronized (e.g. to a vertical retrace IRQ), some systems might need to prioritize certain devices, and so on.

I do think FIFO makes a good general policy, for boards without any of those special requirements.

Quoted 11 lines
Quoted 4 lines

but (B) provides more flexible way by providing
special callback to retrieve next message from queue. This callback may implement its own discipline of scheduling
SPI messages. In any way, the default is FIFO.

I think (A) is missing a method of adding extra spi_message(s) in callback to extend the current transfer on that SPI device. I can imagine a case where you will be required to read status information from a device and in this status information is the length of the data it has just received (for example if it was a network adapter). Straight after reading this information the device would start sending the data it has received but when the read status message was issued the length of the data wasn't known.

Do you actually have hardware which works that way? That would be an example of a system that needs some specific prioritization of transfers (see below).

Quoted 3 lines

Currently with (A) we would have to stop the transfer and
restart the whole thing again, this time using the length of the data we found form the last message.

Well, each transfer segement would clearly stop, but if that segment had the flag set which says "leave chipselect active", then the controller driver would have the flexibility to prioritize transfers to that chip.

Quoted 5 lines

A better solution would to be able to add an extra message during the callback from the first message as now we know then length we can setup a transfer that would be the correct size. However, this message must be the next message that the adapter sends as if another message for another SPI device was sent before then the cs line of the device we are talking to would be deselected and we would have to start again.

I suspect that in terms of API, *if* that semantic is really needed (as in, you have hardware that needs it) then it should be made into a flag in the spi_message.

Clearly, it'd make things more complicated for the SPI controller driver; drivers that don't implement that semantic would need to know when it's required, so they could fail cleanly. And drivers that _do_ know about it would need to avoid doing things like shuffling completions off to some tasklet (while starting the next transfer ASAP, getting I/O overlap) ... they'd need to make stronger guarantees about transaction sequencing, at a certain cost in terms of potential throughput.

Quoted 4 lines

My proposal is that in the callback from a spi_message being sent it returns a pointer to the next spi_message which the adapter will send before it continues sending any other messages (this is like the adapter being locked by the SPI device), if no other messages need to be sent atomically in the callback of current message then the SPI device driver would just return NULL.

The thing I don't like about that model is that, just like the Linux-USB API for interrupt and isochronous transfers in the 2.4 kernels, it swallows fault modes so that drivers can't know when things break.

Better IMO to just keep the same API in all cases, and require that callback to directly submit a (new?) transfer if that's needed. If the controller can't accept it, it'll know right away, and then the protocol driver will be able to do something appropriate.

Quoted 6 lines
Quoted 3 lines

- (A) uses standartized way to provide CS information, and (B) relies on functional drivers callbacks, which looks more
flexible to me.

I'm not sure what you mean here. You need to provide the cs numbers with SPI device in order for the core to create the unique addres and entry in sysfs.

I'm not sure what he means either. :)

Stephen's PXA2xx SPI driver uses callbacks internally, but that's kind of specific to that PXA hardware ... there's no chipselect handled by the controller, one of the dozens of GPIOs must be chosen and that's clearly a board-specific mechanism (uses controller_data as I recall). He tells me he plans to post the latest version of that -- many updates including PXA255 SSP support (not just NSSP) and code shrinkage -- early next week.

But most of the SPI controllers I've seen just have a fixed number of chipselects, typically four, handled directly by the controller. That's why the "standardized way" is just to use a 0..N chipselect number.

Quoted 2 lines

However, (A) is not checking to see if the cs that a registering device wants to use is already in use, this needs to be added, and the same is true for registering spi masters.

Yes, I even have a "FIXME Paranoia argues that ..." comment in that code. I think the best way to handle that is probably to get the driver name out of the device name, thereby punting that check to the driver model. So the devices would have names like "spi3.2" and the driver name would be in "modalias"; I think that'll be a simple enough change to the framework, now that I've thought of it. This is not a case where we _need_ to act much like platform_device.

- Dave

#5 lore raw
Quoted 15 lines · David Brownell
Quoted 8 lines
Quoted 8 lines

- (A) uses more complicated structure of SPI message, that contains one or more atomic transfers, and (B)
offers the only spi_msg that represents the atomic transfer on SPI bus. The similar approach can be implemented
in (B), and actually is implemented. But my imp[ression is that such enhancement may be added later..

Quoted 6 lines

I wouldn't have said that the message structure in (A) is more complex then (B). For example, in
(B) you have many flags which controls things like SPI mode which are not needed in every message. Once the SPI controller has been setup for a particular slave device you don't need to constantly send this information.

Quoted 8 lines

And in fact, constantly sending it means some drivers will have to waste time constantly checking it, in case it changed. If that setup is stored in controller registers, it's a lot better to just have the setup() call be responsible for changing the communication parameters. (This is the approach used by both MMC and PCMCIA, for what it's worth...)

I'm not aware if MMC/PCMCIA guys are happy with this approach :), but anyway what you're talking about here makes sense.

Quoted 7 lines
Quoted 6 lines

In (B) how to do you handle SPI devices which require to send several messages with out releasing their cs? There are/will be some devices which require this.

Quoted 9 lines

In fact, that's why the transfer segments are grouped. One builds SPI protocol requests out of several such segments. A very common idiom is writing a command, then reading its response. Chipselect must stay active during the whole sequence.

Adding support for such a basic mechanism "later" doesn't seem like a good idea to me.

It is supported by means of flags. I'm afraid your note is pointless here.

Quoted 26 lines
Quoted 10 lines
Quoted 10 lines

- (A) uses workqueues to queue and handle SPI messages, and (B) allocates the kernel thread to the same purpose.
Using workqueues is not very good solution in real-time environment; I think that allocating and starting the
separate thread will give us more predictable and stable results;

Quoted 6 lines

Where does (A) use a workqueue? (A) doesn't use a workqueue or thread and instead leaves it up to the adapter driver how to handle the messages that it gets sent (which in the case of some drivers will mean no thread or workqueue). (B) is _forcing_ a thread on the adapter which the adapter may not need.

Exactly. That's one of the things I meant when I recently listed some of the top goals of the framework I did:

(a) SPI shouldn't perpetuate the driver model botches of I2C;
(b) ditto I2C's "everything is synchronous" botches;
(c) it should work well with DMA, to support things like DataFlash;
(d) given the variety of SPI chips, protocol controls are needed;
(e) place minimal implementation constraints on controller drivers.

Quoted 6 lines

So for example one way you know that (c) is well met is that it's the same approach used in USB (both host and peripheral/gadget sides); that's been working well for quite a few years now. (Despite comments from Dmitry and Vitaly to the contrary.)

Lemme point you out that if somehting is "working" on a limited number of platforms within the limited number of use cases, that's not necessarily a correct implementation.

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

- (A) has some assumptions on buffers that are passed down to spi functions.

Quoted 6 lines

Make that "requirements"; FWIW they're the same ones that apply to all other kernel driver frameworks I've seen: that buffers be DMA-safe. It would not be helpful (IMO) to define different rules; that's also called the "Principle of Least Astonishment". :)

Yeah within this requirement it's correct. But that requirement may really make the SPI controller driver a lot more complex if
- it has to send something received from the userland
- it needs to timely send some credentials (what is the case for the WLAN driver, for instance).

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines

If some controller driver (or bus driver
in terms of (B)) tries to perform DMA transfers, it must copy the passed buffers to some memory allocated
using GFP_DMA flag and map it using dma_map_single.

Quoted 6 lines

Based on this and other comments from Dmitry/Vitaly, I suspect they don't see how the Linux DMA APIs work. The correct statement is that if a controller driver wants to use DMA, it must dma_{map,unmap}_single(). The upper level drivers don't _need_ to worry about that.

The upper level drivers do need to worry about their buffers being DMAable then which requirement adds more complexity.
For instance, that means that the upper level drivers can't use static/const for the data being sent, what might be pretty much annoying when you have to send the same data multiple times. Our approach is definitely more robust, although it may be reasonable to simplify it somehow.

Quoted 32 lines
Quoted 3 lines
Quoted 3 lines

- (A) retrieves SPI message from the queue in sequential order (FIFO),

Only with respect to a given device. It would make no sense to reorder the queue so that writing X, then Y, then Z would morph into "X Z Y" or "Z Y X". :)

It's specifically _undefined_ how requests going to different devices are ordered. Some hardware will be happier if things are synchronized (e.g. to a vertical retrace IRQ), some systems might need to prioritize certain devices, and so on.

I do think FIFO makes a good general policy, for boards without any of those special requirements.

Quoted 6 lines
Quoted 6 lines

but (B) provides more flexible way by providing
special callback to retrieve next message from queue. This callback may implement its own discipline of scheduling
SPI messages. In any way, the default is FIFO.

Quoted 8 lines

I think (A) is missing a method of adding extra spi_message(s) in callback to extend the current transfer on that SPI device. I can imagine a case where you will be required to read status information from a device and in this status information is the length of the data it has just received (for example if it was a network adapter). Straight after reading this information the device would start sending the data it has received but when the read status message was issued the length of the data wasn't known.

Quoted 4 lines

Do you actually have hardware which works that way? That would be an example of a system that needs some specific prioritization of transfers (see below).

Let's just agree on the _fact_ that here our approach overcame yours. IMO it's pretty evident.

Quoted 13 lines
Quoted 7 lines

Currently with (A) we would have to stop the transfer and restart the whole thing again, this time using the length of the data we found form the last message.

Well, each transfer segement would clearly stop, but if that segment had the flag set which says "leave chipselect active", then the controller driver would have the flexibility to prioritize transfers to that chip.

Hey, you've told us earlier you don't need any flags, right?
If we start talking about flags necessity, then your *complicated* approach to the spi_message doesn't make sense, sorry.

Quoted 19 lines
Quoted 9 lines
Quoted 5 lines

- (A) uses standartized way to provide CS information, and (B) relies on functional drivers callbacks, which looks more
flexible to me.

I'm not sure what you mean here. You need to provide the cs numbers with SPI device in order for the core to create the unique addres and entry in sysfs.

I'm not sure what he means either. :)

Stephen's PXA2xx SPI driver uses callbacks internally, but that's kind of specific to that PXA hardware ... there's no chipselect handled by the controller, one of the dozens of GPIOs must be chosen and that's clearly a board-specific mechanism (uses controller_data as I recall). He tells me he plans to post the latest version of that -- many updates including PXA255 SSP support (not just NSSP) and code shrinkage -- early next week.

Quoted 5 lines

But most of the SPI controllers I've seen just have a fixed number of chipselects, typically four, handled directly by the controller. That's why the "standardized way" is just to use a 0..N chipselect number.

Suppose we have a specific driver or system service (API) implemented to handle chip selects. We'll have to duplicate its functionality within your approach what is incorrect in architectural terms. Our approach is free from this drawback.

Vitaly

#6 lore raw
Quoted 44 lines · --- Vitaly Wool
Quoted 9 lines · David Brownell
Quoted 9 lines
Quoted 8 lines

- (A) uses more complicated structure of SPI message, that contains one or more atomic transfers, and (B)
offers the only spi_msg that represents the atomic transfer on SPI bus. The similar approach can be implemented
in (B), and actually is implemented. But my imp[ression is that such enhancement may be added later..

I wouldn't have said that the message structure in (A) is more complex then (B). For example,

in

Quoted 1 line
Quoted 1 line

(B) you have many flags which controls things like SPI mode which are not needed in every

message.

Quoted 1 line
Quoted 1 line

Once the SPI controller has been setup for a particular slave device you don't need to

constantly

Quoted 4 lines
Quoted 3 lines

send this information.

Quoted 8 lines

And in fact, constantly sending it means some drivers will have to waste time constantly checking it, in case it changed. If that setup is stored in controller registers, it's a lot better to just have the setup() call be responsible for changing the communication parameters. (This is the approach used by both MMC and PCMCIA, for what it's worth...)

I'm not aware if MMC/PCMCIA guys are happy with this approach :), but anyway what you're talking about here makes sense.

Quoted 3 lines
Quoted 3 lines

In (B) how to do you handle SPI devices which require to send several messages with out

releasing

Quoted 9 lines
Quoted 3 lines

their cs? There are/will be some devices which require this.

In fact, that's why the transfer segments are grouped. One builds SPI protocol requests out of several such segments. A very common idiom is writing a command, then reading its response. Chipselect must stay active during the whole sequence.

Quoted 5 lines
Quoted 4 lines

Adding support for such a basic mechanism "later" doesn't seem like a good idea to me.

It is supported by means of flags. I'm afraid your note is pointless here.

How does this work? As I said before I can see that you can leave a cs active, but how can you make sure the next message is for that SPI device and not for another one?

Quoted 36 lines
Quoted 4 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

- (A) uses workqueues to queue and handle SPI messages, and (B) allocates the kernel thread to the same purpose.
Using workqueues is not very good solution in real-time environment; I think that allocating and starting the
separate thread will give us more predictable and stable results;

Where does (A) use a workqueue? (A) doesn't use a workqueue or thread and instead leaves it up

to

Quoted 1 line
Quoted 1 line

the adapter driver how to handle the messages that it gets sent (which in the case of some

drivers

Quoted 1 line
Quoted 1 line

will mean no thread or workqueue). (B) is _forcing_ a thread on the adapter which the adapter

may

Quoted 13 lines
Quoted 3 lines

not need.

Exactly. That's one of the things I meant when I recently listed some of the top goals of the framework I did:

(a) SPI shouldn't perpetuate the driver model botches of I2C;
(b) ditto I2C's "everything is synchronous" botches;
(c) it should work well with DMA, to support things like DataFlash;
(d) given the variety of SPI chips, protocol controls are needed;
(e) place minimal implementation constraints on controller drivers.

Quoted 6 lines

So for example one way you know that (c) is well met is that it's the same approach used in USB (both host and peripheral/gadget sides); that's been working well for quite a few years now. (Despite comments from Dmitry and Vitaly to the contrary.)

Quoted 3 lines

Lemme point you out that if somehting is "working" on a limited number of platforms within the limited number of use cases, that's not necessarily a correct implementation.

No, but it's a good indication :).

Quoted 80 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines

- (A) has some assumptions on buffers that are passed down to spi functions.

Quoted 6 lines

Make that "requirements"; FWIW they're the same ones that apply to all other kernel driver frameworks I've seen: that buffers be DMA-safe. It would not be helpful (IMO) to define different rules; that's also called the "Principle of Least Astonishment". :)

Yeah within this requirement it's correct. But that requirement may really make the SPI controller driver a lot more complex if
- it has to send something received from the userland
- it needs to timely send some credentials (what is the case for the WLAN driver, for instance).

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines

If some controller driver (or bus driver
in terms of (B)) tries to perform DMA transfers, it must copy the passed buffers to some memory allocated
using GFP_DMA flag and map it using dma_map_single.

Quoted 6 lines

Based on this and other comments from Dmitry/Vitaly, I suspect they don't see how the Linux DMA APIs work. The correct statement is that if a controller driver wants to use DMA, it must dma_{map,unmap}_single(). The upper level drivers don't _need_ to worry about that.

The upper level drivers do need to worry about their buffers being DMAable then which requirement adds more complexity.
For instance, that means that the upper level drivers can't use static/const for the data being sent, what might be pretty much annoying when you have to send the same data multiple times.
Our approach is definitely more robust, although it may be reasonable to simplify it somehow.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

- (A) retrieves SPI message from the queue in sequential order (FIFO),

Only with respect to a given device. It would make no sense to reorder the queue so that writing X, then Y, then Z would morph into "X Z Y" or "Z Y X". :)

Quoted 17 lines

It's specifically _undefined_ how requests going to different devices are ordered. Some hardware will be happier if things are synchronized (e.g. to a vertical retrace IRQ), some systems might need to prioritize certain devices, and so on.

I do think FIFO makes a good general policy, for boards without any of those special requirements.

Quoted 7 lines
Quoted 6 lines

but (B) provides more flexible way by providing
special callback to retrieve next message from queue. This callback may implement its own discipline of scheduling
SPI messages. In any way, the default is FIFO.

I think (A) is missing a method of adding extra spi_message(s) in callback to extend the

current

Quoted 3 lines
Quoted 3 lines

transfer on that SPI device. I can imagine a case where you will be required to read status information from a device and in this status information is the length of the data it has just received (for example if it was a network adapter). Straight after reading this information

the

Quoted 1 line
Quoted 1 line

device would start sending the data it has received but when the read status message was

issued

Quoted 4 lines
Quoted 3 lines

the length of the data wasn't known.

Quoted 6 lines
Quoted 4 lines

Do you actually have hardware which works that way? That would be an example of a system that needs some specific prioritization of transfers (see below).

Let's just agree on the _fact_ that here our approach overcame yours. IMO it's pretty evident.

Neither proposal is complete.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

Currently with (A) we would have to stop the transfer and
restart the whole thing again, this time using the length of the data we found form the last message.

Quoted 8 lines
Quoted 5 lines

Well, each transfer segement would clearly stop, but if that segment had the flag set which says "leave chipselect active", then the controller driver would have the flexibility to prioritize transfers to that chip.

Hey, you've told us earlier you don't need any flags, right? If we start talking about flags necessity, then your *complicated* approach to the spi_message doesn't make sense, sorry.

You don't need _as many_ flags as in (B)

Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

- (A) uses standartized way to provide CS information, and (B) relies on functional drivers callbacks, which looks more
flexible to me.

I'm not sure what you mean here. You need to provide the cs numbers with SPI device in order

for

Quoted 13 lines
Quoted 3 lines

the core to create the unique addres and entry in sysfs.

I'm not sure what he means either. :)

Stephen's PXA2xx SPI driver uses callbacks internally, but that's kind of specific to that PXA hardware ... there's no chipselect handled by the controller, one of the dozens of GPIOs must be chosen and that's clearly a board-specific mechanism (uses controller_data as I recall). He tells me he plans to post the latest version of that -- many updates including PXA255 SSP support (not just NSSP) and code shrinkage -- early next week.

Quoted 5 lines

But most of the SPI controllers I've seen just have a fixed number of chipselects, typically four, handled directly by the controller. That's why the "standardized way" is just to use a 0..N chipselect number.

Quoted 4 lines

Suppose we have a specific driver or system service (API) implemented to handle chip selects. We'll have to duplicate its functionality within your approach what is incorrect in architectural terms. Our approach is free from this drawback.

But suppose you have a SPI controller which has cs lines in the IP block. Are you saying you will write another driver which manipulates the registers in the SPI controller out side of the adapter driver? Some hardware might not support that (i.e. you can't directly controll the cs pin).

Every solution will always work better on some hardware then other hardware. The point is to make the solution work on all types hardware, here I think David's solution is better.

Mark

Quoted 4 lines

Vitaly

___________________________________________________________
Does your mail provider give you FREE antivirus protection? Get Yahoo! Mail http://uk.mail.yahoo.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw
Quoted 8 lines · David Brownell

By the way Vitaly ... I'm still not getting responses directly from you.

Are you pruning me off CC lists, or is there something between us that's filtering out posts? It's certainly hard to respond to comments of yours when I can only find them by going through some list archive I wouldn't normally read...

No, definitely I'm not. I'm just responding with "Reply All" button in my Thunderbird, if you wanna know the details. And I'm quite surprised to hear about the kind of problems you have as you're the only one who's having them.

Quoted 31 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

So for example one way you know that (c) is well met is that it's the same approach used in USB (both host and peripheral/gadget sides); that's been working well for quite a few years now. (Despite comments from Dmitry and Vitaly to the contrary.)

Quoted 6 lines
Quoted 3 lines

Lemme point you out that if somehting is "working" on a limited number of platforms within the limited number of use cases, that's not necessarily a correct implementation.

No, but it's a good indication :).

And I'm not sure what a "limited number of platforms" etc is supposed to suggest. In terms of platforms supporting USB on Linux, there are surely more of them than there are for PCI ... since every PCI platform can support USB, and many non-PCI platforms do also. A better word for that DMA support would seem to be "extensive", not "limited".

In fact, the support for non-PCI platforms was one of the things that led to the last DMA-related reworks for USB. The PCI calls wouldn't work (of course), but USB needs things like DMA-coherent buffers (for transfer and queue head descriptors, used by most controllers) as well as bus-neutral DMA operations. And it even works for things like scatterlist merging through IOMMU mappings ... that wide portability is **very much** a good indication that (c) is a non-issue with the framework I've assembled.

Quoted 7 lines

Vitaly, you're really going to have to come up with some facts if you keep claiming the SPI framework I've posted doesn't support DMA. (I'm not going to let you pull a SCO on us here.) For that matter, you might want to consider the fact that Stephen's pxa2xx_spi driver disproves your arguments (it includes DMA support).

Again, a single working driver cannot disapprove anything.
Evidently enough for anyone more or less familiar with logic, if one claims that something is working, he should prove it's working everywhere not somewhere; on the other hand, to disapprove this statement it's enough to give one example.

However, your latest core should be working on the problematic target as opposed to the previous one. I didn't try that but I think it'll work.
The thing is that what we do in the core to provide DMA capabilities should be implemented in controller driver in your case.
I can agree that it might be considered an addition to the core and not directly included in it, but leaving rather standard operations to the controller driver degrades the added value of the core.

Quoted 18 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 7 lines

- (A) has some assumptions on buffers that are passed down to spi functions.

Make that "requirements"; FWIW they're the same ones that apply to all other kernel driver frameworks I've seen: that buffers be DMA-safe. It would not be helpful (IMO) to define different rules; that's also called the "Principle of Least Astonishment". :)

Quoted 4 lines
Quoted 4 lines

Yeah within this requirement it's correct. But that requirement may really make the SPI controller driver a lot more complex if
- it has to send something received from the userland

Quoted 6 lines

Controller drivers don't deal with userland addresses. That's the responsibility of the layers on top ... e.g. the filesystem or driver code that accepts them. Most just copy to/from userspace, but some pay the costs to support direct I/O.

Oh no, you've got me wrong. I was tryng to say that an upper level driver which copies the data from the userspace should be copying it to GFP_DMA buffer, otherwise it won't work or will force the controller driver to allocate/copy.
And putting a requirement on the upper level driver to always do GFP_DMA kmalloc's might put too high restrictions on the memory usage.
Basically the upper level driver shouldn't give a damn whether the buffers should be DMA-able or not since it might be used on different platforms w/ and w/o DMA capabilities. Thus, it's going to be either a requirement for the upper level drivers that implies the SPI core not being transparent to the upper level, or a requirement for each controller driver that might be handling this situation to implement the same thing we did in the core. Neither of these seems reasonable to me.

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

- it needs to timely send some credentials (what is the case for the WLAN driver, for instance).

Quoted 10 lines

Again, not the responsibility of the lowest level driver. A WLAN driver
layered on top could, of course. That's the way such things are done in other driver stacks.

Are you seriously suggesting that an SPI controller driver should have any
clue whatever about credentials?? Which of the dozens of schemes should
become that "special", then ... and why??

I'm afraid that you were not reading my response attentively. Credentials are stored in a staic-allocated buffer in the upper level driver. Then they are passed down to the SPI core which will fail to send the buffer containing the credentials if it's not copied to DMAable memory somewhere in between.

Vitaly

#9 lore raw
Quoted 8 lines
Quoted 4 lines

By the way Vitaly ... I'm still not getting responses directly from you. Are you pruning me off CC lists, or is there something between us that's filtering out posts? It's certainly hard to respond ...

No, definitely I'm not. I'm just responding with "Reply All" button in my Thunderbird, if you wanna know the details.
And I'm quite surprised to hear about the kind of problems you have as you're the only one who's having them.

Well, as was pointed out offline, you aren't always CC'ing me. In this case you did, and I got your message.

Quoted 8 lines
Quoted 5 lines

Vitaly, you're really going to have to come up with some facts if you keep claiming the SPI framework I've posted doesn't support DMA. (I'm not going to let you pull a SCO on us here.) For that matter, you might want to consider the fact that Stephen's pxa2xx_spi driver disproves your arguments (it includes DMA support).

Again, a single working driver cannot disapprove anything.

It certainly can disprove assertions like the one you made...

Quoted 4 lines

Evidently enough for anyone more or less familiar with logic, if one claims that something is working, he should prove it's working everywhere not somewhere; on the other hand, to disapprove this statement it's enough to give one example.

Which is what I did. You said that the approach I was using did NOT support DMA. I disproved it with several counterexamples ... the whole USB stack for one, using that same DMA approach (in "struct urb" on the host side, and "struct usb_request" on the peripheral side), as well as more specifically that pxa2xx_spi driver (with "struct spi_message").

Quoted 5 lines

The thing is that what we do in the core to provide DMA capabilities should be implemented in controller driver in your case.
I can agree that it might be considered an addition to the core and not directly included in it, but leaving rather standard operations to the controller driver degrades the added value of the core.

That's an entirely different argument, note.

And in this case, it was a conscious decision not to require any mid-layer logic to interpose itself between layers of SPI driver. Drivers using PIO shouldn't need to pay mapping costs ... but if the mapping were done in a mid-layer, they would always do so.

Quoted 10 lines
Quoted 6 lines

Controller drivers don't deal with userland addresses. That's the responsibility of the layers on top ... e.g. the filesystem or driver code that accepts them. Most just copy to/from userspace, but some pay the costs to support direct I/O.

Oh no, you've got me wrong. I was tryng to say that an upper level driver which copies the data from the userspace should be copying it to GFP_DMA buffer, otherwise it won't work or will force the controller driver to allocate/copy.

GFP_DMA is not necessary ... plus, it's usually inappropriate. Except for broken hardware, any buffer returned by kmalloc is fine ... and for that broken hardware, the dma mapping calls should be setting up the relevant bounce buffering. (See how ARM does it for various XScale systems, the dmabounce_* code.)

Quoted 3 lines

Basically the upper level driver shouldn't give a damn whether the buffers should be DMA-able or not since it might be used on different platforms w/ and w/o DMA capabilities.

If it were any effort to provide DMA-safe buffers, I might agree. But it isn't; most buffers come from kmalloc() already.

Remember, this is the same requirement applying to the rest of the Linux driver stack. Now that the requirements have been clear for a couple years (Documentation/DMA-mapping.txt, and yes I had something to do with finally getting those rules written down) this is NOT a problem of any note.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

- it needs to timely send some credentials (what is the case for the WLAN driver, for instance).

Again, not the responsibility of the lowest level driver. A WLAN driver
layered on top could, of course. That's the way such things are done in other driver stacks.

Quoted 5 lines
Quoted 3 lines

Are you seriously suggesting that an SPI controller driver should have any
clue whatever about credentials?? Which of the dozens of schemes should
become that "special", then ... and why??

I'm afraid that you were not reading my response attentively.

I was trying, but your words were making no sense to me.

Quoted 4 lines

Credentials are stored in a staic-allocated buffer in the upper level driver. Then they are passed down to the SPI core which will fail to send the buffer containing the credentials if it's not copied to DMAable memory somewhere in between.

So it'd be just like with any other driver stack. In this case, the issue would be with whatever is passing static credentials where DMA-safe buffers are required. (In fact, static buffers work on every Linux platform I've ever worked with, but it's not guaranteed ... the main issue would be the same one that shows up with dma to/from stack, where cacheline sharing causes chaos on systems without dma-coherent cache.)

For what it's worth, usually credentials get copied into an sk_buff, which is DMA-safe since it comes from kmalloc(). If you're talking about some out-of-tree WLAN code, I'd expect those issues would be resolved (in the WLAN code) before that stack gets merged.

- Dave