Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-19 Thread Alessio Igor Bogani
Hi,

On 19 October 2015 at 11:19, Dmitry Kalinkin  wrote:
[...]
> There is no optimal solution. In vanilla kernel you have just two drivers. You
> can either have 8 GE PIO2 boards or 4 GE PIO2 boards and any amount of boards
> potentially accessible through vme_user. None of this provides for the case
> when you have a crate with more than 8 GE PIO2 boards in it. Indeed, if you
> have built your little proprietary system around one or two drivers so it just
> fits using up all of the DMA resources and you somehow still need vme_user,
> this patch will surely break it for you. But if we really care about *all*
> users then there is no difference in how much resources are used by any 
> driver,
> there is always a setup for which they won’t be enough.
>> The number of VME windows is limited, so having a user space shim either hog 
>> or limit the number of resources available either in kernel space or user 
>> space is not an optimal solution.
> How vme_user is different from proprietary driver A to deserve such 
> discrimination?
> Would it be more optimal if proprietary driver A would take less resources 
> that
> could have otherwise been exposed to the userspace?
>
> I agree that due to the nature of vme_user it should have some knobs to tune
> it’s resource consumption, but I don’t think these should be some special ugly
> knobs that only a userspace driver gets. The solution could have been to use
> same kind of module params as in vme_pio2. But instead of implementing that, I
> spent my time unknowingly arguing over whether mainline kernel developers
> should be denied breaking certain proprietary systems lurking in the shadow of
> the VME subsystem. Wonderful.

IMHO VME stack should handle bus resources dynamically not matter from
where the requests come from (user-space or kernel-space).

Ciao,
Alessio
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-19 Thread Dmitry Kalinkin

> On 2015/10/18, at 18:04, Martyn Welch  wrote:
> 
> 
> 
> On 18/10/15 18:53, Dmitry Kalinkin wrote:
>> On Sun, Oct 18, 2015 at 10:31 AM, Martyn Welch  wrote:
>>> 
>>> On 11/10/15 01:13, Dmitry Kalinkin wrote:
 This introduces a new dma device that provides a single ioctl call that
 provides DMA read and write functionality to the user space.
 
 Signed-off-by: Dmitry Kalinkin 
 Cc: Igor Alekseev 
 ---
 
 In the last reply Martyn suggested a rework of this to make it use existing
 bus/vme/ctl instead of creating a new bus/vme/dma%i device and also
 dynamically
 allocate a dma resource in each request.
 
 I think this doesn't need those adjustments. I think that dynamic 
 allocation
 doesn't solve any practical problem that isn't caused by current kernel
 api.
>>> 
>>> That would depend on what resources had already been allocated to other
>>> drivers using the kernel api and what resources the underlying bridge had to
>>> make available. This driver will currently only load if all the resources it
>>> wishes to expose to user space are available. That said, such a modification
>>> is clearly separate from adding DMA support to user space, so the argument
>>> is rather academic.
>> Other drives meaning vme_pio, I don't see any others. All this time
>> we are discussing how many GE PIO boards one can plug into a crate
>> with or without vme_user. Most of people have zero of them.
>> Also, VME DMA API has no users in kernel, we are just adding one now.
> 
> Unfortunately not all users of Linux upstream or even publicise their 
> drivers. This is especially true of some industries where VME gets used. 
There is no optimal solution. In vanilla kernel you have just two drivers. You
can either have 8 GE PIO2 boards or 4 GE PIO2 boards and any amount of boards
potentially accessible through vme_user. None of this provides for the case
when you have a crate with more than 8 GE PIO2 boards in it. Indeed, if you
have built your little proprietary system around one or two drivers so it just
fits using up all of the DMA resources and you somehow still need vme_user,
this patch will surely break it for you. But if we really care about *all*
users then there is no difference in how much resources are used by any driver,
there is always a setup for which they won’t be enough.
> The number of VME windows is limited, so having a user space shim either hog 
> or limit the number of resources available either in kernel space or user 
> space is not an optimal solution.
How vme_user is different from proprietary driver A to deserve such 
discrimination?
Would it be more optimal if proprietary driver A would take less resources that
could have otherwise been exposed to the userspace?

I agree that due to the nature of vme_user it should have some knobs to tune
it’s resource consumption, but I don’t think these should be some special ugly
knobs that only a userspace driver gets. The solution could have been to use
same kind of module params as in vme_pio2. But instead of implementing that, I
spent my time unknowingly arguing over whether mainline kernel developers
should be denied breaking certain proprietary systems lurking in the shadow of
the VME subsystem. Wonderful.
> 
I also think that separate device is a good feature because it allows
 for
 discovery of dma capatibility from userspace.
>>> 
>>> Given the current user space api, that's true.
>>> 
 The interface with separate
 chardev also allows to provide DMA read() and write() syscalls that can
 come handy in pair with /bin/dd.
>>> 
>>> But this patch doesn't implement such a feature does it?
>> Actually, initial (never published) version of this patch exposed
>> read(),write(),
>> and an ioctl to set the access cycle. It was working, but with subtlety for
>> A64 addressing. I come across some problems when using large offsets
>> that would not fit in signed long long. I was using FMODE_UNSIGNED_OFFSET
>> to fix the kernel side of things, but it seemed like userspace didn't like
>> the "negative" offsets. I've looked a bit at glibc sources and decided
>> to give up.
>> Now that I remember this, my original argument is kind of busted.
>>> (Generally happy with this for now, however couple of comments below.)
>>> 
>>> 
 v5:
 Added a validation for dma_op argument in vme_user_sg_to_dma_list(). It is
 already checked in caller but we would like to silence a warning:
 
 drivers/staging/vme/devices/vme_user.c: In function
 'vme_user_ioctl.isra.4':
>> drivers/staging/vme/devices/vme_user.c:324:7: warning: 'dest' may be
>> used uninitialized in this function [-Wmaybe-uninitialized]
ret = vme_dma_list_add(dma_list, src, dest, hw_len);
^
 drivers/staging/vme/devices/vme_user.c:296:52: note: 'dest' was
 declared here
struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
 

Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-19 Thread Alessio Igor Bogani
Hi,

On 19 October 2015 at 00:04, Martyn Welch  wrote:
> On 18/10/15 18:53, Dmitry Kalinkin wrote:
[...]
>> Other drives meaning vme_pio, I don't see any others. All this time
>> we are discussing how many GE PIO boards one can plug into a crate
>> with or without vme_user. Most of people have zero of them.
>> Also, VME DMA API has no users in kernel, we are just adding one now.
>
>
> Unfortunately not all users of Linux upstream or even publicise their
> drivers. This is especially true of some industries where VME gets used. The
> number of VME windows is limited, so having a user space shim either hog or
> limit the number of resources available either in kernel space or user space
> is not an optimal solution.

We aren't an industry but we are exactly in that position: we have a
bunch of unpublished kernel driver for VME boards almost all built on
top of the customized old vmelinux.org stack.
We already tried to port a driver to current stack but we stuck on the
static resource management approach in particular for limited VME
windows (when the customization of the old stack was made for handle
VME windows dynamically).

Ciao,
Alessio
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-19 Thread Alessio Igor Bogani
Hi,

On 19 October 2015 at 11:19, Dmitry Kalinkin  wrote:
[...]
> There is no optimal solution. In vanilla kernel you have just two drivers. You
> can either have 8 GE PIO2 boards or 4 GE PIO2 boards and any amount of boards
> potentially accessible through vme_user. None of this provides for the case
> when you have a crate with more than 8 GE PIO2 boards in it. Indeed, if you
> have built your little proprietary system around one or two drivers so it just
> fits using up all of the DMA resources and you somehow still need vme_user,
> this patch will surely break it for you. But if we really care about *all*
> users then there is no difference in how much resources are used by any 
> driver,
> there is always a setup for which they won’t be enough.
>> The number of VME windows is limited, so having a user space shim either hog 
>> or limit the number of resources available either in kernel space or user 
>> space is not an optimal solution.
> How vme_user is different from proprietary driver A to deserve such 
> discrimination?
> Would it be more optimal if proprietary driver A would take less resources 
> that
> could have otherwise been exposed to the userspace?
>
> I agree that due to the nature of vme_user it should have some knobs to tune
> it’s resource consumption, but I don’t think these should be some special ugly
> knobs that only a userspace driver gets. The solution could have been to use
> same kind of module params as in vme_pio2. But instead of implementing that, I
> spent my time unknowingly arguing over whether mainline kernel developers
> should be denied breaking certain proprietary systems lurking in the shadow of
> the VME subsystem. Wonderful.

IMHO VME stack should handle bus resources dynamically not matter from
where the requests come from (user-space or kernel-space).

Ciao,
Alessio
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-19 Thread Dmitry Kalinkin

> On 2015/10/18, at 18:04, Martyn Welch  wrote:
> 
> 
> 
> On 18/10/15 18:53, Dmitry Kalinkin wrote:
>> On Sun, Oct 18, 2015 at 10:31 AM, Martyn Welch  wrote:
>>> 
>>> On 11/10/15 01:13, Dmitry Kalinkin wrote:
 This introduces a new dma device that provides a single ioctl call that
 provides DMA read and write functionality to the user space.
 
 Signed-off-by: Dmitry Kalinkin 
 Cc: Igor Alekseev 
 ---
 
 In the last reply Martyn suggested a rework of this to make it use existing
 bus/vme/ctl instead of creating a new bus/vme/dma%i device and also
 dynamically
 allocate a dma resource in each request.
 
 I think this doesn't need those adjustments. I think that dynamic 
 allocation
 doesn't solve any practical problem that isn't caused by current kernel
 api.
>>> 
>>> That would depend on what resources had already been allocated to other
>>> drivers using the kernel api and what resources the underlying bridge had to
>>> make available. This driver will currently only load if all the resources it
>>> wishes to expose to user space are available. That said, such a modification
>>> is clearly separate from adding DMA support to user space, so the argument
>>> is rather academic.
>> Other drives meaning vme_pio, I don't see any others. All this time
>> we are discussing how many GE PIO boards one can plug into a crate
>> with or without vme_user. Most of people have zero of them.
>> Also, VME DMA API has no users in kernel, we are just adding one now.
> 
> Unfortunately not all users of Linux upstream or even publicise their 
> drivers. This is especially true of some industries where VME gets used. 
There is no optimal solution. In vanilla kernel you have just two drivers. You
can either have 8 GE PIO2 boards or 4 GE PIO2 boards and any amount of boards
potentially accessible through vme_user. None of this provides for the case
when you have a crate with more than 8 GE PIO2 boards in it. Indeed, if you
have built your little proprietary system around one or two drivers so it just
fits using up all of the DMA resources and you somehow still need vme_user,
this patch will surely break it for you. But if we really care about *all*
users then there is no difference in how much resources are used by any driver,
there is always a setup for which they won’t be enough.
> The number of VME windows is limited, so having a user space shim either hog 
> or limit the number of resources available either in kernel space or user 
> space is not an optimal solution.
How vme_user is different from proprietary driver A to deserve such 
discrimination?
Would it be more optimal if proprietary driver A would take less resources that
could have otherwise been exposed to the userspace?

I agree that due to the nature of vme_user it should have some knobs to tune
it’s resource consumption, but I don’t think these should be some special ugly
knobs that only a userspace driver gets. The solution could have been to use
same kind of module params as in vme_pio2. But instead of implementing that, I
spent my time unknowingly arguing over whether mainline kernel developers
should be denied breaking certain proprietary systems lurking in the shadow of
the VME subsystem. Wonderful.
> 
I also think that separate device is a good feature because it allows
 for
 discovery of dma capatibility from userspace.
>>> 
>>> Given the current user space api, that's true.
>>> 
 The interface with separate
 chardev also allows to provide DMA read() and write() syscalls that can
 come handy in pair with /bin/dd.
>>> 
>>> But this patch doesn't implement such a feature does it?
>> Actually, initial (never published) version of this patch exposed
>> read(),write(),
>> and an ioctl to set the access cycle. It was working, but with subtlety for
>> A64 addressing. I come across some problems when using large offsets
>> that would not fit in signed long long. I was using FMODE_UNSIGNED_OFFSET
>> to fix the kernel side of things, but it seemed like userspace didn't like
>> the "negative" offsets. I've looked a bit at glibc sources and decided
>> to give up.
>> Now that I remember this, my original argument is kind of busted.
>>> (Generally happy with this for now, however couple of comments below.)
>>> 
>>> 
 v5:
 Added a validation for dma_op argument in vme_user_sg_to_dma_list(). It is
 already checked in caller but we would like to silence a warning:
 
 drivers/staging/vme/devices/vme_user.c: In function
 'vme_user_ioctl.isra.4':
>> drivers/staging/vme/devices/vme_user.c:324:7: warning: 'dest' may be
>> used uninitialized in this function [-Wmaybe-uninitialized]
ret = vme_dma_list_add(dma_list, src, dest, hw_len);
^
 drivers/staging/vme/devices/vme_user.c:296:52: note: 'dest' was
 declared here

Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-19 Thread Alessio Igor Bogani
Hi,

On 19 October 2015 at 00:04, Martyn Welch  wrote:
> On 18/10/15 18:53, Dmitry Kalinkin wrote:
[...]
>> Other drives meaning vme_pio, I don't see any others. All this time
>> we are discussing how many GE PIO boards one can plug into a crate
>> with or without vme_user. Most of people have zero of them.
>> Also, VME DMA API has no users in kernel, we are just adding one now.
>
>
> Unfortunately not all users of Linux upstream or even publicise their
> drivers. This is especially true of some industries where VME gets used. The
> number of VME windows is limited, so having a user space shim either hog or
> limit the number of resources available either in kernel space or user space
> is not an optimal solution.

We aren't an industry but we are exactly in that position: we have a
bunch of unpublished kernel driver for VME boards almost all built on
top of the customized old vmelinux.org stack.
We already tried to port a driver to current stack but we stuck on the
static resource management approach in particular for limited VME
windows (when the customization of the old stack was made for handle
VME windows dynamically).

Ciao,
Alessio
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-18 Thread Martyn Welch



On 18/10/15 18:53, Dmitry Kalinkin wrote:

On Sun, Oct 18, 2015 at 10:31 AM, Martyn Welch  wrote:


On 11/10/15 01:13, Dmitry Kalinkin wrote:

This introduces a new dma device that provides a single ioctl call that
provides DMA read and write functionality to the user space.

Signed-off-by: Dmitry Kalinkin 
Cc: Igor Alekseev 
---

In the last reply Martyn suggested a rework of this to make it use existing
bus/vme/ctl instead of creating a new bus/vme/dma%i device and also
dynamically
allocate a dma resource in each request.

I think this doesn't need those adjustments. I think that dynamic allocation
doesn't solve any practical problem that isn't caused by current kernel
api.


That would depend on what resources had already been allocated to other
drivers using the kernel api and what resources the underlying bridge had to
make available. This driver will currently only load if all the resources it
wishes to expose to user space are available. That said, such a modification
is clearly separate from adding DMA support to user space, so the argument
is rather academic.

Other drives meaning vme_pio, I don't see any others. All this time
we are discussing how many GE PIO boards one can plug into a crate
with or without vme_user. Most of people have zero of them.
Also, VME DMA API has no users in kernel, we are just adding one now.


Unfortunately not all users of Linux upstream or even publicise their 
drivers. This is especially true of some industries where VME gets used. 
The number of VME windows is limited, so having a user space shim either 
hog or limit the number of resources available either in kernel space or 
user space is not an optimal solution.



I also think that separate device is a good feature because it allows
for
discovery of dma capatibility from userspace.


Given the current user space api, that's true.


The interface with separate
chardev also allows to provide DMA read() and write() syscalls that can
come handy in pair with /bin/dd.


But this patch doesn't implement such a feature does it?

Actually, initial (never published) version of this patch exposed
read(),write(),
and an ioctl to set the access cycle. It was working, but with subtlety for
A64 addressing. I come across some problems when using large offsets
that would not fit in signed long long. I was using FMODE_UNSIGNED_OFFSET
to fix the kernel side of things, but it seemed like userspace didn't like
the "negative" offsets. I've looked a bit at glibc sources and decided
to give up.
Now that I remember this, my original argument is kind of busted.

(Generally happy with this for now, however couple of comments below.)



v5:
Added a validation for dma_op argument in vme_user_sg_to_dma_list(). It is
already checked in caller but we would like to silence a warning:

 drivers/staging/vme/devices/vme_user.c: In function
'vme_user_ioctl.isra.4':

drivers/staging/vme/devices/vme_user.c:324:7: warning: 'dest' may be
used uninitialized in this function [-Wmaybe-uninitialized]

ret = vme_dma_list_add(dma_list, src, dest, hw_len);
^
 drivers/staging/vme/devices/vme_user.c:296:52: note: 'dest' was
declared here
struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
 ^

drivers/staging/vme/devices/vme_user.c:324:7: warning: 'src' may be used
uninitialized in this function [-Wmaybe-uninitialized]

ret = vme_dma_list_add(dma_list, src, dest, hw_len);
^
 drivers/staging/vme/devices/vme_user.c:296:46: note: 'src' was
declared here
struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;

---
   drivers/staging/vme/devices/vme_user.c | 205
-
   drivers/staging/vme/devices/vme_user.h |  11 ++
   2 files changed, 213 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/vme/devices/vme_user.c
b/drivers/staging/vme/devices/vme_user.c
index 8e61a3b..2434e5f 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -79,15 +79,18 @@ static unsigned int bus_num;
* We shall support 4 masters and 4 slaves with this driver.
*/


The comment just above here (cropped in the patch) describes the interface
that this driver exposes and what is documented in
Documentation/devices.txt.

I've come across a long time ago and at the time I realized that this
document is generally outdated and is not required to be updated.
First, "Last revised: 6th April 2009"
Second, the device path information is long obsolete in the light of udev.
Third, they want submissions on a separate list 
Fourth, "20 block Hitachi CD-ROM (under development) 0 = /dev/hitcd"
-- this is not for real.


Yup, I agree, devices.txt is probably well out of date and is a product 
of long since deprecated practices.


That said, the comment in vme_user.c is at odds with what the code 
implements after this patch is applied and that is something we very 
much have control over.



Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-18 Thread Dmitry Kalinkin
On Sun, Oct 18, 2015 at 10:31 AM, Martyn Welch  wrote:
>
>
> On 11/10/15 01:13, Dmitry Kalinkin wrote:
>>
>> This introduces a new dma device that provides a single ioctl call that
>> provides DMA read and write functionality to the user space.
>>
>> Signed-off-by: Dmitry Kalinkin 
>> Cc: Igor Alekseev 
>> ---
>>
>> In the last reply Martyn suggested a rework of this to make it use existing
>> bus/vme/ctl instead of creating a new bus/vme/dma%i device and also
>> dynamically
>> allocate a dma resource in each request.
>>
>> I think this doesn't need those adjustments. I think that dynamic allocation
>> doesn't solve any practical problem that isn't caused by current kernel
>> api.
>
>
> That would depend on what resources had already been allocated to other
> drivers using the kernel api and what resources the underlying bridge had to
> make available. This driver will currently only load if all the resources it
> wishes to expose to user space are available. That said, such a modification
> is clearly separate from adding DMA support to user space, so the argument
> is rather academic.
Other drives meaning vme_pio, I don't see any others. All this time
we are discussing how many GE PIO boards one can plug into a crate
with or without vme_user. Most of people have zero of them.
Also, VME DMA API has no users in kernel, we are just adding one now.
>
>>I also think that separate device is a good feature because it allows
>> for
>> discovery of dma capatibility from userspace.
>
>
> Given the current user space api, that's true.
>
>> The interface with separate
>> chardev also allows to provide DMA read() and write() syscalls that can
>> come handy in pair with /bin/dd.
>
>
> But this patch doesn't implement such a feature does it?
Actually, initial (never published) version of this patch exposed
read(),write(),
and an ioctl to set the access cycle. It was working, but with subtlety for
A64 addressing. I come across some problems when using large offsets
that would not fit in signed long long. I was using FMODE_UNSIGNED_OFFSET
to fix the kernel side of things, but it seemed like userspace didn't like
the "negative" offsets. I've looked a bit at glibc sources and decided
to give up.
Now that I remember this, my original argument is kind of busted.
>
> (Generally happy with this for now, however couple of comments below.)
>
>
>>
>> v5:
>> Added a validation for dma_op argument in vme_user_sg_to_dma_list(). It is
>> already checked in caller but we would like to silence a warning:
>>
>> drivers/staging/vme/devices/vme_user.c: In function
>> 'vme_user_ioctl.isra.4':

 drivers/staging/vme/devices/vme_user.c:324:7: warning: 'dest' may be
 used uninitialized in this function [-Wmaybe-uninitialized]
>>
>>ret = vme_dma_list_add(dma_list, src, dest, hw_len);
>>^
>> drivers/staging/vme/devices/vme_user.c:296:52: note: 'dest' was
>> declared here
>>struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
>> ^

 drivers/staging/vme/devices/vme_user.c:324:7: warning: 'src' may be used
 uninitialized in this function [-Wmaybe-uninitialized]
>>
>>ret = vme_dma_list_add(dma_list, src, dest, hw_len);
>>^
>> drivers/staging/vme/devices/vme_user.c:296:46: note: 'src' was
>> declared here
>>struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
>>
>> ---
>>   drivers/staging/vme/devices/vme_user.c | 205
>> -
>>   drivers/staging/vme/devices/vme_user.h |  11 ++
>>   2 files changed, 213 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/staging/vme/devices/vme_user.c
>> b/drivers/staging/vme/devices/vme_user.c
>> index 8e61a3b..2434e5f 100644
>> --- a/drivers/staging/vme/devices/vme_user.c
>> +++ b/drivers/staging/vme/devices/vme_user.c
>> @@ -79,15 +79,18 @@ static unsigned int bus_num;
>>* We shall support 4 masters and 4 slaves with this driver.
>>*/
>
>
> The comment just above here (cropped in the patch) describes the interface
> that this driver exposes and what is documented in
> Documentation/devices.txt.
I've come across a long time ago and at the time I realized that this
document is generally outdated and is not required to be updated.
First, "Last revised: 6th April 2009"
Second, the device path information is long obsolete in the light of udev.
Third, they want submissions on a separate list 
Fourth, "20 block Hitachi CD-ROM (under development) 0 = /dev/hitcd"
-- this is not for real.
>
> I think this comment either needs updating to reflect the changes introduced
> in this patch, or deleted.
>
> (As an aside:
>
> The interface in Docmentation/devices.txt is an interesting oddity - it
> existed before any VME drivers were present in the kernel. Given that the
> driver at vmelinux.org hasn't been updated since some time in the 2.4 kernel
> series and the lack of mainlined drivers other than this one using that
> interface, 

Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-18 Thread Martyn Welch



On 11/10/15 01:13, Dmitry Kalinkin wrote:

This introduces a new dma device that provides a single ioctl call that
provides DMA read and write functionality to the user space.

Signed-off-by: Dmitry Kalinkin 
Cc: Igor Alekseev 
---
 
In the last reply Martyn suggested a rework of this to make it use existing

bus/vme/ctl instead of creating a new bus/vme/dma%i device and also dynamically
allocate a dma resource in each request.
 
I think this doesn't need those adjustments. I think that dynamic allocation

doesn't solve any practical problem that isn't caused by current kernel api.


That would depend on what resources had already been allocated to other 
drivers using the kernel api and what resources the underlying bridge 
had to make available. This driver will currently only load if all the 
resources it wishes to expose to user space are available. That said, 
such a modification is clearly separate from adding DMA support to user 
space, so the argument is rather academic.


   
I also think that separate device is a good feature because it allows for

discovery of dma capatibility from userspace.


Given the current user space api, that's true.


The interface with separate
chardev also allows to provide DMA read() and write() syscalls that can
come handy in pair with /bin/dd.


But this patch doesn't implement such a feature does it?

(Generally happy with this for now, however couple of comments below.)



v5:
Added a validation for dma_op argument in vme_user_sg_to_dma_list(). It is
already checked in caller but we would like to silence a warning:

drivers/staging/vme/devices/vme_user.c: In function 'vme_user_ioctl.isra.4':

drivers/staging/vme/devices/vme_user.c:324:7: warning: 'dest' may be used 
uninitialized in this function [-Wmaybe-uninitialized]

   ret = vme_dma_list_add(dma_list, src, dest, hw_len);
   ^
drivers/staging/vme/devices/vme_user.c:296:52: note: 'dest' was declared 
here
   struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
^

drivers/staging/vme/devices/vme_user.c:324:7: warning: 'src' may be used 
uninitialized in this function [-Wmaybe-uninitialized]

   ret = vme_dma_list_add(dma_list, src, dest, hw_len);
   ^
drivers/staging/vme/devices/vme_user.c:296:46: note: 'src' was declared here
   struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;

---
  drivers/staging/vme/devices/vme_user.c | 205 -
  drivers/staging/vme/devices/vme_user.h |  11 ++
  2 files changed, 213 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/vme/devices/vme_user.c 
b/drivers/staging/vme/devices/vme_user.c
index 8e61a3b..2434e5f 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -79,15 +79,18 @@ static unsigned int bus_num;
   * We shall support 4 masters and 4 slaves with this driver.
   */


The comment just above here (cropped in the patch) describes the 
interface that this driver exposes and what is documented in 
Documentation/devices.txt.


I think this comment either needs updating to reflect the changes 
introduced in this patch, or deleted.


(As an aside:

The interface in Docmentation/devices.txt is an interesting oddity - it 
existed before any VME drivers were present in the kernel. Given that 
the driver at vmelinux.org hasn't been updated since some time in the 
2.4 kernel series and the lack of mainlined drivers other than this one 
using that interface, should we update that file to reflect the additions?


If we were to modify this driver sufficiently, so that chrdevs were 
dynamically allocated for example, should we delete that entry?

)


  #define VME_MAJOR 221 /* VME Major Device Number */
-#define VME_DEVS   9   /* Number of dev entries */
+#define VME_DEVS   10  /* Number of dev entries */
  
  #define MASTER_MINOR	0

  #define MASTER_MAX3
  #define SLAVE_MINOR   4
  #define SLAVE_MAX 7
  #define CONTROL_MINOR 8
+#define DMA_MINOR  9
  
-#define PCI_BUF_SIZE  0x2	/* Size of one slave image buffer */

+#define PCI_BUF_SIZE   0x2 /* Size of one slave image buffer */
+
+#define VME_MAX_DMA_LEN0x400   /* Maximal DMA transfer length 
*/
  
  /*

   * Structure to handle image related parameters.
@@ -112,7 +115,7 @@ static const int type[VME_DEVS] = { MASTER_MINOR,   
MASTER_MINOR,
MASTER_MINOR,   MASTER_MINOR,
SLAVE_MINOR,SLAVE_MINOR,
SLAVE_MINOR,SLAVE_MINOR,
-   CONTROL_MINOR
+   CONTROL_MINOR,  DMA_MINOR
};
  
  struct 

Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-18 Thread Martyn Welch



On 18/10/15 18:53, Dmitry Kalinkin wrote:

On Sun, Oct 18, 2015 at 10:31 AM, Martyn Welch  wrote:


On 11/10/15 01:13, Dmitry Kalinkin wrote:

This introduces a new dma device that provides a single ioctl call that
provides DMA read and write functionality to the user space.

Signed-off-by: Dmitry Kalinkin 
Cc: Igor Alekseev 
---

In the last reply Martyn suggested a rework of this to make it use existing
bus/vme/ctl instead of creating a new bus/vme/dma%i device and also
dynamically
allocate a dma resource in each request.

I think this doesn't need those adjustments. I think that dynamic allocation
doesn't solve any practical problem that isn't caused by current kernel
api.


That would depend on what resources had already been allocated to other
drivers using the kernel api and what resources the underlying bridge had to
make available. This driver will currently only load if all the resources it
wishes to expose to user space are available. That said, such a modification
is clearly separate from adding DMA support to user space, so the argument
is rather academic.

Other drives meaning vme_pio, I don't see any others. All this time
we are discussing how many GE PIO boards one can plug into a crate
with or without vme_user. Most of people have zero of them.
Also, VME DMA API has no users in kernel, we are just adding one now.


Unfortunately not all users of Linux upstream or even publicise their 
drivers. This is especially true of some industries where VME gets used. 
The number of VME windows is limited, so having a user space shim either 
hog or limit the number of resources available either in kernel space or 
user space is not an optimal solution.



I also think that separate device is a good feature because it allows
for
discovery of dma capatibility from userspace.


Given the current user space api, that's true.


The interface with separate
chardev also allows to provide DMA read() and write() syscalls that can
come handy in pair with /bin/dd.


But this patch doesn't implement such a feature does it?

Actually, initial (never published) version of this patch exposed
read(),write(),
and an ioctl to set the access cycle. It was working, but with subtlety for
A64 addressing. I come across some problems when using large offsets
that would not fit in signed long long. I was using FMODE_UNSIGNED_OFFSET
to fix the kernel side of things, but it seemed like userspace didn't like
the "negative" offsets. I've looked a bit at glibc sources and decided
to give up.
Now that I remember this, my original argument is kind of busted.

(Generally happy with this for now, however couple of comments below.)



v5:
Added a validation for dma_op argument in vme_user_sg_to_dma_list(). It is
already checked in caller but we would like to silence a warning:

 drivers/staging/vme/devices/vme_user.c: In function
'vme_user_ioctl.isra.4':

drivers/staging/vme/devices/vme_user.c:324:7: warning: 'dest' may be
used uninitialized in this function [-Wmaybe-uninitialized]

ret = vme_dma_list_add(dma_list, src, dest, hw_len);
^
 drivers/staging/vme/devices/vme_user.c:296:52: note: 'dest' was
declared here
struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
 ^

drivers/staging/vme/devices/vme_user.c:324:7: warning: 'src' may be used
uninitialized in this function [-Wmaybe-uninitialized]

ret = vme_dma_list_add(dma_list, src, dest, hw_len);
^
 drivers/staging/vme/devices/vme_user.c:296:46: note: 'src' was
declared here
struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;

---
   drivers/staging/vme/devices/vme_user.c | 205
-
   drivers/staging/vme/devices/vme_user.h |  11 ++
   2 files changed, 213 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/vme/devices/vme_user.c
b/drivers/staging/vme/devices/vme_user.c
index 8e61a3b..2434e5f 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -79,15 +79,18 @@ static unsigned int bus_num;
* We shall support 4 masters and 4 slaves with this driver.
*/


The comment just above here (cropped in the patch) describes the interface
that this driver exposes and what is documented in
Documentation/devices.txt.

I've come across a long time ago and at the time I realized that this
document is generally outdated and is not required to be updated.
First, "Last revised: 6th April 2009"
Second, the device path information is long obsolete in the light of udev.
Third, they want submissions on a separate list 
Fourth, "20 block Hitachi CD-ROM (under development) 0 = /dev/hitcd"
-- this is not for real.


Yup, I agree, devices.txt is probably well out of date and is a product 
of long since deprecated practices.


That said, the comment in vme_user.c is at odds with what the code 

Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-18 Thread Martyn Welch



On 11/10/15 01:13, Dmitry Kalinkin wrote:

This introduces a new dma device that provides a single ioctl call that
provides DMA read and write functionality to the user space.

Signed-off-by: Dmitry Kalinkin 
Cc: Igor Alekseev 
---
 
In the last reply Martyn suggested a rework of this to make it use existing

bus/vme/ctl instead of creating a new bus/vme/dma%i device and also dynamically
allocate a dma resource in each request.
 
I think this doesn't need those adjustments. I think that dynamic allocation

doesn't solve any practical problem that isn't caused by current kernel api.


That would depend on what resources had already been allocated to other 
drivers using the kernel api and what resources the underlying bridge 
had to make available. This driver will currently only load if all the 
resources it wishes to expose to user space are available. That said, 
such a modification is clearly separate from adding DMA support to user 
space, so the argument is rather academic.


   
I also think that separate device is a good feature because it allows for

discovery of dma capatibility from userspace.


Given the current user space api, that's true.


The interface with separate
chardev also allows to provide DMA read() and write() syscalls that can
come handy in pair with /bin/dd.


But this patch doesn't implement such a feature does it?

(Generally happy with this for now, however couple of comments below.)



v5:
Added a validation for dma_op argument in vme_user_sg_to_dma_list(). It is
already checked in caller but we would like to silence a warning:

drivers/staging/vme/devices/vme_user.c: In function 'vme_user_ioctl.isra.4':

drivers/staging/vme/devices/vme_user.c:324:7: warning: 'dest' may be used 
uninitialized in this function [-Wmaybe-uninitialized]

   ret = vme_dma_list_add(dma_list, src, dest, hw_len);
   ^
drivers/staging/vme/devices/vme_user.c:296:52: note: 'dest' was declared 
here
   struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
^

drivers/staging/vme/devices/vme_user.c:324:7: warning: 'src' may be used 
uninitialized in this function [-Wmaybe-uninitialized]

   ret = vme_dma_list_add(dma_list, src, dest, hw_len);
   ^
drivers/staging/vme/devices/vme_user.c:296:46: note: 'src' was declared here
   struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;

---
  drivers/staging/vme/devices/vme_user.c | 205 -
  drivers/staging/vme/devices/vme_user.h |  11 ++
  2 files changed, 213 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/vme/devices/vme_user.c 
b/drivers/staging/vme/devices/vme_user.c
index 8e61a3b..2434e5f 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -79,15 +79,18 @@ static unsigned int bus_num;
   * We shall support 4 masters and 4 slaves with this driver.
   */


The comment just above here (cropped in the patch) describes the 
interface that this driver exposes and what is documented in 
Documentation/devices.txt.


I think this comment either needs updating to reflect the changes 
introduced in this patch, or deleted.


(As an aside:

The interface in Docmentation/devices.txt is an interesting oddity - it 
existed before any VME drivers were present in the kernel. Given that 
the driver at vmelinux.org hasn't been updated since some time in the 
2.4 kernel series and the lack of mainlined drivers other than this one 
using that interface, should we update that file to reflect the additions?


If we were to modify this driver sufficiently, so that chrdevs were 
dynamically allocated for example, should we delete that entry?

)


  #define VME_MAJOR 221 /* VME Major Device Number */
-#define VME_DEVS   9   /* Number of dev entries */
+#define VME_DEVS   10  /* Number of dev entries */
  
  #define MASTER_MINOR	0

  #define MASTER_MAX3
  #define SLAVE_MINOR   4
  #define SLAVE_MAX 7
  #define CONTROL_MINOR 8
+#define DMA_MINOR  9
  
-#define PCI_BUF_SIZE  0x2	/* Size of one slave image buffer */

+#define PCI_BUF_SIZE   0x2 /* Size of one slave image buffer */
+
+#define VME_MAX_DMA_LEN0x400   /* Maximal DMA transfer length 
*/
  
  /*

   * Structure to handle image related parameters.
@@ -112,7 +115,7 @@ static const int type[VME_DEVS] = { MASTER_MINOR,   
MASTER_MINOR,
MASTER_MINOR,   MASTER_MINOR,
SLAVE_MINOR,SLAVE_MINOR,
SLAVE_MINOR,SLAVE_MINOR,
-   CONTROL_MINOR
+   CONTROL_MINOR,  DMA_MINOR
 

Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-18 Thread Dmitry Kalinkin
On Sun, Oct 18, 2015 at 10:31 AM, Martyn Welch  wrote:
>
>
> On 11/10/15 01:13, Dmitry Kalinkin wrote:
>>
>> This introduces a new dma device that provides a single ioctl call that
>> provides DMA read and write functionality to the user space.
>>
>> Signed-off-by: Dmitry Kalinkin 
>> Cc: Igor Alekseev 
>> ---
>>
>> In the last reply Martyn suggested a rework of this to make it use existing
>> bus/vme/ctl instead of creating a new bus/vme/dma%i device and also
>> dynamically
>> allocate a dma resource in each request.
>>
>> I think this doesn't need those adjustments. I think that dynamic allocation
>> doesn't solve any practical problem that isn't caused by current kernel
>> api.
>
>
> That would depend on what resources had already been allocated to other
> drivers using the kernel api and what resources the underlying bridge had to
> make available. This driver will currently only load if all the resources it
> wishes to expose to user space are available. That said, such a modification
> is clearly separate from adding DMA support to user space, so the argument
> is rather academic.
Other drives meaning vme_pio, I don't see any others. All this time
we are discussing how many GE PIO boards one can plug into a crate
with or without vme_user. Most of people have zero of them.
Also, VME DMA API has no users in kernel, we are just adding one now.
>
>>I also think that separate device is a good feature because it allows
>> for
>> discovery of dma capatibility from userspace.
>
>
> Given the current user space api, that's true.
>
>> The interface with separate
>> chardev also allows to provide DMA read() and write() syscalls that can
>> come handy in pair with /bin/dd.
>
>
> But this patch doesn't implement such a feature does it?
Actually, initial (never published) version of this patch exposed
read(),write(),
and an ioctl to set the access cycle. It was working, but with subtlety for
A64 addressing. I come across some problems when using large offsets
that would not fit in signed long long. I was using FMODE_UNSIGNED_OFFSET
to fix the kernel side of things, but it seemed like userspace didn't like
the "negative" offsets. I've looked a bit at glibc sources and decided
to give up.
Now that I remember this, my original argument is kind of busted.
>
> (Generally happy with this for now, however couple of comments below.)
>
>
>>
>> v5:
>> Added a validation for dma_op argument in vme_user_sg_to_dma_list(). It is
>> already checked in caller but we would like to silence a warning:
>>
>> drivers/staging/vme/devices/vme_user.c: In function
>> 'vme_user_ioctl.isra.4':

 drivers/staging/vme/devices/vme_user.c:324:7: warning: 'dest' may be
 used uninitialized in this function [-Wmaybe-uninitialized]
>>
>>ret = vme_dma_list_add(dma_list, src, dest, hw_len);
>>^
>> drivers/staging/vme/devices/vme_user.c:296:52: note: 'dest' was
>> declared here
>>struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
>> ^

 drivers/staging/vme/devices/vme_user.c:324:7: warning: 'src' may be used
 uninitialized in this function [-Wmaybe-uninitialized]
>>
>>ret = vme_dma_list_add(dma_list, src, dest, hw_len);
>>^
>> drivers/staging/vme/devices/vme_user.c:296:46: note: 'src' was
>> declared here
>>struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
>>
>> ---
>>   drivers/staging/vme/devices/vme_user.c | 205
>> -
>>   drivers/staging/vme/devices/vme_user.h |  11 ++
>>   2 files changed, 213 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/staging/vme/devices/vme_user.c
>> b/drivers/staging/vme/devices/vme_user.c
>> index 8e61a3b..2434e5f 100644
>> --- a/drivers/staging/vme/devices/vme_user.c
>> +++ b/drivers/staging/vme/devices/vme_user.c
>> @@ -79,15 +79,18 @@ static unsigned int bus_num;
>>* We shall support 4 masters and 4 slaves with this driver.
>>*/
>
>
> The comment just above here (cropped in the patch) describes the interface
> that this driver exposes and what is documented in
> Documentation/devices.txt.
I've come across a long time ago and at the time I realized that this
document is generally outdated and is not required to be updated.
First, "Last revised: 6th April 2009"
Second, the device path information is long obsolete in the light of udev.
Third, they want submissions on a separate list 
Fourth, "20 block Hitachi CD-ROM (under development) 0 = /dev/hitcd"
-- this is not for real.
>
> I think this comment either needs updating to reflect the changes introduced
> in this patch, or deleted.
>
> (As an aside:
>
> The interface in Docmentation/devices.txt is an interesting oddity - it
> existed before any VME drivers were present in the kernel. Given that the
> driver at vmelinux.org hasn't been updated since some time in the 2.4 kernel

Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-17 Thread Dmitry Kalinkin

> On 2015/10/17, at 23:52, Greg Kroah-Hartman  
> wrote:
> 
> On Sun, Oct 11, 2015 at 03:13:25AM +0300, Dmitry Kalinkin wrote:
>> This introduces a new dma device that provides a single ioctl call that
>> provides DMA read and write functionality to the user space.
>> 
>> Signed-off-by: Dmitry Kalinkin 
>> Cc: Igor Alekseev 
>> ---  
>>
>> 
> 
> Ugh, trailing whitespace hurts the eyes...
> 
> Anyway, I need an ack from Martyn before I can accept this type of
> thing.
> 
> thanks,
> 
> greg k-h

This fail is sponsored by vim :set colorcolumn=80 + clipboard copy-paste.--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-17 Thread Greg Kroah-Hartman
On Sun, Oct 11, 2015 at 03:13:25AM +0300, Dmitry Kalinkin wrote:
> This introduces a new dma device that provides a single ioctl call that
> provides DMA read and write functionality to the user space.
> 
> Signed-off-by: Dmitry Kalinkin 
> Cc: Igor Alekseev 
> ---   
>   
>   
>   

Ugh, trailing whitespace hurts the eyes...

Anyway, I need an ack from Martyn before I can accept this type of
thing.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-17 Thread Dmitry Kalinkin

> On 2015/10/17, at 23:52, Greg Kroah-Hartman  
> wrote:
> 
> On Sun, Oct 11, 2015 at 03:13:25AM +0300, Dmitry Kalinkin wrote:
>> This introduces a new dma device that provides a single ioctl call that
>> provides DMA read and write functionality to the user space.
>> 
>> Signed-off-by: Dmitry Kalinkin 
>> Cc: Igor Alekseev 
>> ---  
>>
>> 
> 
> Ugh, trailing whitespace hurts the eyes...
> 
> Anyway, I need an ack from Martyn before I can accept this type of
> thing.
> 
> thanks,
> 
> greg k-h

This fail is sponsored by vim :set colorcolumn=80 + clipboard copy-paste.--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCHv5] staging: vme_user: provide DMA functionality

2015-10-17 Thread Greg Kroah-Hartman
On Sun, Oct 11, 2015 at 03:13:25AM +0300, Dmitry Kalinkin wrote:
> This introduces a new dma device that provides a single ioctl call that
> provides DMA read and write functionality to the user space.
> 
> Signed-off-by: Dmitry Kalinkin 
> Cc: Igor Alekseev 
> ---   
>   
>   
>   

Ugh, trailing whitespace hurts the eyes...

Anyway, I need an ack from Martyn before I can accept this type of
thing.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv5] staging: vme_user: provide DMA functionality

2015-10-10 Thread Dmitry Kalinkin
This introduces a new dma device that provides a single ioctl call that
provides DMA read and write functionality to the user space.

Signed-off-by: Dmitry Kalinkin 
Cc: Igor Alekseev 
--- 

In the last reply Martyn suggested a rework of this to make it use existing 
bus/vme/ctl instead of creating a new bus/vme/dma%i device and also dynamically 
allocate a dma resource in each request.

I think this doesn't need those adjustments. I think that dynamic allocation
doesn't solve any practical problem that isn't caused by current kernel api.
I also think that separate device is a good feature because it allows for   
discovery of dma capatibility from userspace. The interface with separate   
chardev also allows to provide DMA read() and write() syscalls that can 
come handy in pair with /bin/dd.

v5:
Added a validation for dma_op argument in vme_user_sg_to_dma_list(). It is
already checked in caller but we would like to silence a warning:

   drivers/staging/vme/devices/vme_user.c: In function 'vme_user_ioctl.isra.4':
>> drivers/staging/vme/devices/vme_user.c:324:7: warning: 'dest' may be used 
>> uninitialized in this function [-Wmaybe-uninitialized]
  ret = vme_dma_list_add(dma_list, src, dest, hw_len);
  ^
   drivers/staging/vme/devices/vme_user.c:296:52: note: 'dest' was declared here
  struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
   ^
>> drivers/staging/vme/devices/vme_user.c:324:7: warning: 'src' may be used 
>> uninitialized in this function [-Wmaybe-uninitialized]
  ret = vme_dma_list_add(dma_list, src, dest, hw_len);
  ^
   drivers/staging/vme/devices/vme_user.c:296:46: note: 'src' was declared here
  struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;

---
 drivers/staging/vme/devices/vme_user.c | 205 -
 drivers/staging/vme/devices/vme_user.h |  11 ++
 2 files changed, 213 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/vme/devices/vme_user.c 
b/drivers/staging/vme/devices/vme_user.c
index 8e61a3b..2434e5f 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -79,15 +79,18 @@ static unsigned int bus_num;
  * We shall support 4 masters and 4 slaves with this driver.
  */
 #define VME_MAJOR  221 /* VME Major Device Number */
-#define VME_DEVS   9   /* Number of dev entries */
+#define VME_DEVS   10  /* Number of dev entries */
 
 #define MASTER_MINOR   0
 #define MASTER_MAX 3
 #define SLAVE_MINOR4
 #define SLAVE_MAX  7
 #define CONTROL_MINOR  8
+#define DMA_MINOR  9
 
-#define PCI_BUF_SIZE  0x2  /* Size of one slave image buffer */
+#define PCI_BUF_SIZE   0x2 /* Size of one slave image buffer */
+
+#define VME_MAX_DMA_LEN0x400   /* Maximal DMA transfer length 
*/
 
 /*
  * Structure to handle image related parameters.
@@ -112,7 +115,7 @@ static const int type[VME_DEVS] = { MASTER_MINOR,   
MASTER_MINOR,
MASTER_MINOR,   MASTER_MINOR,
SLAVE_MINOR,SLAVE_MINOR,
SLAVE_MINOR,SLAVE_MINOR,
-   CONTROL_MINOR
+   CONTROL_MINOR,  DMA_MINOR
};
 
 struct vme_user_vma_priv {
@@ -281,6 +284,172 @@ static loff_t vme_user_llseek(struct file *file, loff_t 
off, int whence)
return -EINVAL;
 }
 
+static int vme_user_sg_to_dma_list(const struct vme_dma_op *dma_op,
+  struct sg_table *sgt,
+  int sg_count, struct vme_dma_list *dma_list)
+{
+   ssize_t pos = 0;
+   struct scatterlist *sg;
+   int i, ret;
+
+   if ((dma_op->dir != VME_DMA_MEM_TO_VME) &&
+   (dma_op->dir != VME_DMA_VME_TO_MEM))
+   return -EINVAL;
+
+   for_each_sg(sgt->sgl, sg, sg_count, i) {
+   struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
+   dma_addr_t hw_address = sg_dma_address(sg);
+   unsigned int hw_len = sg_dma_len(sg);
+
+   vme_attr = vme_dma_vme_attribute(dma_op->vme_addr + pos,
+dma_op->aspace,
+dma_op->cycle,
+dma_op->dwidth);
+   if (!vme_attr)
+   return -ENOMEM;
+
+   pci_attr = vme_dma_pci_attribute(hw_address);
+   if (!pci_attr) {
+

[PATCHv5] staging: vme_user: provide DMA functionality

2015-10-10 Thread Dmitry Kalinkin
This introduces a new dma device that provides a single ioctl call that
provides DMA read and write functionality to the user space.

Signed-off-by: Dmitry Kalinkin 
Cc: Igor Alekseev 
--- 

In the last reply Martyn suggested a rework of this to make it use existing 
bus/vme/ctl instead of creating a new bus/vme/dma%i device and also dynamically 
allocate a dma resource in each request.

I think this doesn't need those adjustments. I think that dynamic allocation
doesn't solve any practical problem that isn't caused by current kernel api.
I also think that separate device is a good feature because it allows for   
discovery of dma capatibility from userspace. The interface with separate   
chardev also allows to provide DMA read() and write() syscalls that can 
come handy in pair with /bin/dd.

v5:
Added a validation for dma_op argument in vme_user_sg_to_dma_list(). It is
already checked in caller but we would like to silence a warning:

   drivers/staging/vme/devices/vme_user.c: In function 'vme_user_ioctl.isra.4':
>> drivers/staging/vme/devices/vme_user.c:324:7: warning: 'dest' may be used 
>> uninitialized in this function [-Wmaybe-uninitialized]
  ret = vme_dma_list_add(dma_list, src, dest, hw_len);
  ^
   drivers/staging/vme/devices/vme_user.c:296:52: note: 'dest' was declared here
  struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
   ^
>> drivers/staging/vme/devices/vme_user.c:324:7: warning: 'src' may be used 
>> uninitialized in this function [-Wmaybe-uninitialized]
  ret = vme_dma_list_add(dma_list, src, dest, hw_len);
  ^
   drivers/staging/vme/devices/vme_user.c:296:46: note: 'src' was declared here
  struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;

---
 drivers/staging/vme/devices/vme_user.c | 205 -
 drivers/staging/vme/devices/vme_user.h |  11 ++
 2 files changed, 213 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/vme/devices/vme_user.c 
b/drivers/staging/vme/devices/vme_user.c
index 8e61a3b..2434e5f 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -79,15 +79,18 @@ static unsigned int bus_num;
  * We shall support 4 masters and 4 slaves with this driver.
  */
 #define VME_MAJOR  221 /* VME Major Device Number */
-#define VME_DEVS   9   /* Number of dev entries */
+#define VME_DEVS   10  /* Number of dev entries */
 
 #define MASTER_MINOR   0
 #define MASTER_MAX 3
 #define SLAVE_MINOR4
 #define SLAVE_MAX  7
 #define CONTROL_MINOR  8
+#define DMA_MINOR  9
 
-#define PCI_BUF_SIZE  0x2  /* Size of one slave image buffer */
+#define PCI_BUF_SIZE   0x2 /* Size of one slave image buffer */
+
+#define VME_MAX_DMA_LEN0x400   /* Maximal DMA transfer length 
*/
 
 /*
  * Structure to handle image related parameters.
@@ -112,7 +115,7 @@ static const int type[VME_DEVS] = { MASTER_MINOR,   
MASTER_MINOR,
MASTER_MINOR,   MASTER_MINOR,
SLAVE_MINOR,SLAVE_MINOR,
SLAVE_MINOR,SLAVE_MINOR,
-   CONTROL_MINOR
+   CONTROL_MINOR,  DMA_MINOR
};
 
 struct vme_user_vma_priv {
@@ -281,6 +284,172 @@ static loff_t vme_user_llseek(struct file *file, loff_t 
off, int whence)
return -EINVAL;
 }
 
+static int vme_user_sg_to_dma_list(const struct vme_dma_op *dma_op,
+  struct sg_table *sgt,
+  int sg_count, struct vme_dma_list *dma_list)
+{
+   ssize_t pos = 0;
+   struct scatterlist *sg;
+   int i, ret;
+
+   if ((dma_op->dir != VME_DMA_MEM_TO_VME) &&
+   (dma_op->dir != VME_DMA_VME_TO_MEM))
+   return -EINVAL;
+
+   for_each_sg(sgt->sgl, sg, sg_count, i) {
+   struct vme_dma_attr *pci_attr, *vme_attr, *src, *dest;
+   dma_addr_t hw_address = sg_dma_address(sg);
+   unsigned int hw_len = sg_dma_len(sg);
+
+   vme_attr = vme_dma_vme_attribute(dma_op->vme_addr + pos,
+dma_op->aspace,
+dma_op->cycle,
+dma_op->dwidth);
+   if (!vme_attr)
+   return -ENOMEM;
+
+   pci_attr = vme_dma_pci_attribute(hw_address);