Skip to contentSkip to conversation

imx28 rtcan flexcan system freezes

Xenomai Alexandre COFFIGNAL 3 participants 27 messages Jan 22, 2014 – Jan 31, 2014

lore
Share & tools
lore
#0 lore raw

Hi all,

I use two rtcan flexcan on imx28-evk board.

If both rtcan devices receive a data at the same time, this cause a freeze. After investigation, i found that if I replace in flexcan_rx_interrupt these instructions :
- *(__be32 *)(cf->data + 0) =
- cpu_to_be32(flexcan_read(&mb->data[0]));
- *(__be32 *)(cf->data + 4) =
- cpu_to_be32(flexcan_read(&mb->data[1]));

by these

+ data0 = flexcan_read(&mb->data[0]);
+ data1 = flexcan_read(&mb->data[1]);
+

+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

My config : xenomai 2.6.3, linux 3.8.13,

#1 lore raw
Quoted 26 lines · Alexandre COFFIGNAL

Hi all,

I use two rtcan flexcan on imx28-evk board.

If both rtcan devices receive a data at the same time, this cause a freeze. After investigation, i found that if I replace in flexcan_rx_interrupt these instructions :

(quoted diff) +0 -4
-        *(__be32 *)(cf->data + 0) =
-            cpu_to_be32(flexcan_read(&mb->data[0]));
-        *(__be32 *)(cf->data + 4) =
-            cpu_to_be32(flexcan_read(&mb->data[1]));

by these

(quoted diff) +11 -0
+        data0 = flexcan_read(&mb->data[0]);
+        data1 = flexcan_read(&mb->data[1]);
+
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;
Quoted 2 lines

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

Signature · 1 line
                                                                Gilles.
#2 lore raw
Quoted 27 lines · Gilles Chanteperdrix
Quoted 26 lines · Alexandre COFFIGNAL

Hi all,

I use two rtcan flexcan on imx28-evk board.

If both rtcan devices receive a data at the same time, this cause a freeze. After investigation, i found that if I replace in flexcan_rx_interrupt these instructions :

(quoted diff) +0 -4
-        *(__be32 *)(cf->data + 0) =
-            cpu_to_be32(flexcan_read(&mb->data[0]));
-        *(__be32 *)(cf->data + 4) =
-            cpu_to_be32(flexcan_read(&mb->data[1]));

by these

(quoted diff) +11 -0
+        data0 = flexcan_read(&mb->data[0]);
+        data1 = flexcan_read(&mb->data[1]);
+
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;
Quoted 7 lines
Quoted 2 lines

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

here structures used in flexcan driver, it seem to be aligned

/* Structure of the message buffer */

struct flexcan_mb {
    u32 can_ctrl;
    u32 can_id;
    u32 data[2];
};

/* Structure of the hardware registers */

struct flexcan_regs {
    u32 mcr;        /* 0x00 */
    u32 ctrl;        /* 0x04 */
    u32 timer;        /* 0x08 */
    u32 _reserved1;        /* 0x0c */
    u32 rxgmask;        /* 0x10 */
    u32 rx14mask;        /* 0x14 */
    u32 rx15mask;        /* 0x18 */
    u32 ecr;        /* 0x1c */
    u32 esr;        /* 0x20 */
    u32 imask2;        /* 0x24 */
    u32 imask1;        /* 0x28 */
    u32 iflag2;        /* 0x2c */
    u32 iflag1;        /* 0x30 */
    u32 crl2;        /* 0x34 */
    u32 esr2;        /* 0x38 */
    u32 _reserved2[2];
    u32 crcr;        /* 0x44 */
    u32 rxfgmask;        /* 0x48 */
    u32 rxfir;        /* 0x4c */
    u32 _reserved3[12];
    struct flexcan_mb cantxfg[64];
};
#3 lore raw
Quoted 9 lines · Alexandre COFFIGNAL
Quoted 9 lines
Quoted 9 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Signature · 1 line
					    Gilles.
#4 lore raw
Quoted 12 lines · Gilles Chanteperdrix
Quoted 11 lines · Alexandre COFFIGNAL
Quoted 11 lines
Quoted 11 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Quoted 10 lines
Quoted 6 lines
Quoted 5 lines

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

#5 lore raw
Quoted 19 lines · Alexandre COFFIGNAL
Quoted 17 lines · Gilles Chanteperdrix
Quoted 16 lines · Alexandre COFFIGNAL
Quoted 16 lines
Quoted 11 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

Signature · 1 line
					    Gilles.
#6 lore raw
Quoted 22 lines · Gilles Chanteperdrix
Quoted 21 lines · Alexandre COFFIGNAL
Quoted 19 lines · Gilles Chanteperdrix
Quoted 17 lines · Alexandre COFFIGNAL
Quoted 9 lines
Quoted 9 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;
Quoted 7 lines
Quoted 2 lines

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

here structures used in flexcan driver, it seem to be aligned

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

I think, i can't get cf->data to be properly aligned because "cf" is receive internal frame representation within the ring buffer of a struct rtcan_socket and struct rtcan_rb_frame is a generic structure used in all rtcan drivers .

#7 lore raw
Quoted 31 lines · Alexandre COFFIGNAL
Quoted 29 lines · Gilles Chanteperdrix
Quoted 27 lines · Alexandre COFFIGNAL
Quoted 17 lines · Gilles Chanteperdrix
Quoted 16 lines · Alexandre COFFIGNAL
Quoted 16 lines
Quoted 11 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

Quoted 6 lines
Quoted 1 line

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

Quoted 7 lines
Quoted 3 lines

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

I think, i can't get cf->data to be properly aligned because "cf" is receive internal frame representation within the ring buffer of a struct rtcan_socket and struct rtcan_rb_frame is a generic structure used in all rtcan drivers .

Well, if you fix rtcan_rb_frame to be aligned, it will be aligned for all drivers, so that looks like a worthwile improvement...

Signature · 1 line
					    Gilles.
#8 lore raw
Quoted 35 lines · Gilles Chanteperdrix
Quoted 34 lines · Alexandre COFFIGNAL
Quoted 32 lines · Gilles Chanteperdrix
Quoted 19 lines · Alexandre COFFIGNAL
Quoted 17 lines · Gilles Chanteperdrix
Quoted 16 lines · Alexandre COFFIGNAL
Quoted 16 lines
Quoted 11 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

Quoted 9 lines
Quoted 4 lines

I think, i can't get cf->data to be properly aligned because "cf" is receive internal frame representation within the ring buffer of a struct rtcan_socket and struct rtcan_rb_frame is a generic structure used in all rtcan drivers .

Well, if you fix rtcan_rb_frame to be aligned, it will be aligned for all drivers, so that looks like a worthwile improvement...

Wolfgang, what do you think? Should we change the alignment of rtcan_rb_frame::data, or use put_unaligned on ARM?

Signature · 1 line
                                                                Gilles.
#9 lore raw

Hi Gilles,

On Thu, 23 Jan 2014 11:04:44 +0100, Gilles Chanteperdrix

Quoted 34 lines · <[email protected]> wrote:
Quoted 31 lines · Gilles Chanteperdrix
Quoted 29 lines · Alexandre COFFIGNAL
Quoted 25 lines · Gilles Chanteperdrix
Quoted 23 lines · Alexandre COFFIGNAL
Quoted 19 lines · Gilles Chanteperdrix
Quoted 17 lines · Alexandre COFFIGNAL
Quoted 17 lines
Quoted 17 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
 
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
 
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
 
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
 
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
 
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
 
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
 
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

rtcan flexcan works perfectly.

is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

arrange to get it properly aligned? Failing that, you should use

put_unaligned instead of open coding it.

How are unaligned accesses handled on your system? Alexandre,

what does "cat /proc/cpu/alignment" report? Aligned access

would be better, I agree.

Quoted 54 lines
Quoted 40 lines
Quoted 39 lines
Quoted 26 lines
Quoted 18 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

here structures used in flexcan driver, it seem to be aligned

Quoted 9 lines

I am talking about the alignment of cf->data, since obviously, that

is

the one which is causing problems.

Quoted 5 lines

Thank a lot, put_unaligned fix this issue if you want, i can send a

path

Quoted 7 lines

The other solution (getting cf->data to be properly aligned) would be

more efficient, why is not it possible to get cf->data properly

aligned?

I think, i can't get cf->data to be properly aligned because "cf" is

receive internal frame representation within the ring buffer

of a struct rtcan_socket and struct rtcan_rb_frame is a generic

Quoted 11 lines
Quoted 1 line

structure used in all rtcan drivers .

Well, if you fix rtcan_rb_frame to be aligned, it will be aligned for

all drivers, so that looks like a worthwile improvement...

Quoted 3 lines

Wolfgang, what do you think? Should we change the alignment of

rtcan_rb_frame::data, or use put_unaligned on ARM?

I realized the mail and wonder why this problem does not show up with

vanilla

Linux. Maybe we need to port over some patch from there. I will have a

closer

look this even or over the weekend.

Wolfgang.

#10 lore raw
Quoted 5 lines · Wolfgang Grandegger

How are unaligned accesses handled on your system? Alexandre,

what does "cat /proc/cpu/alignment" report? Aligned access

would be better, I agree.

The imx28 can not support unaligned accesses in hardware. The unaligned access causes an exception, /proc/cpu/alignment thus only allow choosing how the exception is handled.

Quoted 9 lines
Quoted 3 lines

Wolfgang, what do you think? Should we change the alignment of

rtcan_rb_frame::data, or use put_unaligned on ARM?

I realized the mail and wonder why this problem does not show up with

vanilla

Vanilla handles the alignment trap by emulating the faulting instruction. Last time I checked, there were some problems related to running the emulation over xenomai domain, though looking at the code now, I see nothing which would prevent us from doing it.

Signature · 1 line
					    Gilles.
#11 lore raw

On Thu, 23 Jan 2014 13:05:40 +0100, Gilles Chanteperdrix

Quoted 46 lines · <[email protected]> wrote:
Quoted 9 lines · Wolfgang Grandegger

How are unaligned accesses handled on your system? Alexandre,

what does "cat /proc/cpu/alignment" report? Aligned access

would be better, I agree.

The imx28 can not support unaligned accesses in hardware. The unaligned

access causes an exception, /proc/cpu/alignment thus only allow choosing

how the exception is handled.

Quoted 12 lines
Quoted 5 lines

Wolfgang, what do you think? Should we change the alignment of

rtcan_rb_frame::data, or use put_unaligned on ARM?

Quoted 5 lines

I realized the mail and wonder why this problem does not show up with

vanilla

Quoted 7 lines

Vanilla handles the alignment trap by emulating the faulting

instruction. Last time I checked, there were some problems related to

running the emulation over xenomai domain, though looking at the code

now, I see nothing which would prevent us from doing it.

Yes, I know. But the handling of unaligned accesses via trap handler must

be

enabled by the user and I'm not aware that this is needed for vanilla

Linux.

Wolfgang.

#12 lore raw
Quoted 10 lines · Wolfgang Grandegger
Quoted 7 lines

Vanilla handles the alignment trap by emulating the faulting

instruction. Last time I checked, there were some problems related to

running the emulation over xenomai domain, though looking at the code

now, I see nothing which would prevent us from doing it.

Quoted 7 lines

Yes, I know. But the handling of unaligned accesses via trap handler must

be

enabled by the user and I'm not aware that this is needed for vanilla

Linux.

I remember reading on the LAKML that the alignment trap is needed for kernel operations, notably for the IP stack.

Signature · 1 line
					    Gilles.
#14 lore raw
In reply to Wolfgang Grandegger
Quoted 70 lines · Wolfgang Grandegger

Hi Gilles,

On Thu, 23 Jan 2014 11:04:44 +0100, Gilles Chanteperdrix

Quoted 16 lines · <[email protected]> wrote:
Quoted 15 lines · Gilles Chanteperdrix
Quoted 14 lines · Alexandre COFFIGNAL
Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Alexandre COFFIGNAL
Quoted 11 lines · Gilles Chanteperdrix
Quoted 10 lines · Alexandre COFFIGNAL
Quoted 10 lines
Quoted 10 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Probably mb->data does not have the right alignment. Could you

not

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

How are unaligned accesses handled on your system? Alexandre,

what does "cat /proc/cpu/alignment" report? Aligned access

would be better, I agree.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is
the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

I think, i can't get cf->data to be properly aligned because "cf" is receive internal frame representation within the ring buffer of a struct rtcan_socket and struct rtcan_rb_frame is a generic structure used in all rtcan drivers .

Well, if you fix rtcan_rb_frame to be aligned, it will be aligned for all drivers, so that looks like a worthwile improvement...

Wolfgang, what do you think? Should we change the alignment of rtcan_rb_frame::data, or use put_unaligned on ARM?

I realized the mail and wonder why this problem does not show up with

vanilla

Linux. Maybe we need to port over some patch from there. I will have a

closer

look this even or over the weekend.

Quoted 8 lines

Wolfgang.

_______________________________________________
Xenomai mailing list
[email protected]
http://www.xenomai.org/mailman/listinfo/xenomai

Hi,

"cat /proc/cpu/alignment" report

User:           0
System:         0
Skipped:        0
Half:           0
Word:           0
DWord:          0
Multi:          0
User faults:    0 (ignored)

something wrong with that ?

Alexandre.

#13 lore raw
In reply to Gilles Chanteperdrix
Quoted 5 lines · Gilles Chanteperdrix

Vanilla handles the alignment trap by emulating the faulting instruction. Last time I checked, there were some problems related to running the emulation over xenomai domain, though looking at the code now, I see nothing which would prevent us from doing it.

Correction: the emulation code would require changing probe_kernel_address to be able to run over non-linux stacks.

Signature · 1 line
					    Gilles.
#15 lore raw
In reply to Alexandre COFFIGNAL
Quoted 95 lines · Alexandre COFFIGNAL
Quoted 70 lines · Wolfgang Grandegger

Hi Gilles,

On Thu, 23 Jan 2014 11:04:44 +0100, Gilles Chanteperdrix

Quoted 16 lines · <[email protected]> wrote:
Quoted 15 lines · Gilles Chanteperdrix
Quoted 14 lines · Alexandre COFFIGNAL
Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Alexandre COFFIGNAL
Quoted 11 lines · Gilles Chanteperdrix
Quoted 10 lines · Alexandre COFFIGNAL
Quoted 10 lines
Quoted 10 lines

+ cf->data[3]=((data0 >> 0) & 0xFF) ;

(quoted diff) +7 -0
+        cf->data[2]=((data0 >> 8) & 0xFF) ;
+        cf->data[1]=((data0 >> 16) & 0xFF) ;
+        cf->data[0]=((data0 >> 24) & 0xFF) ;
+        cf->data[7]=((data1 >> 0) & 0xFF) ;
+        cf->data[6]=((data1 >> 8) & 0xFF) ;
+        cf->data[5]=((data1 >> 16) & 0xFF) ;
+        cf->data[4]=((data1 >> 24) & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Probably mb->data does not have the right alignment. Could you

not

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

How are unaligned accesses handled on your system? Alexandre,

what does "cat /proc/cpu/alignment" report? Aligned access

would be better, I agree.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is
the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

I think, i can't get cf->data to be properly aligned because "cf" is receive internal frame representation within the ring buffer of a struct rtcan_socket and struct rtcan_rb_frame is a generic structure used in all rtcan drivers .

Well, if you fix rtcan_rb_frame to be aligned, it will be aligned for all drivers, so that looks like a worthwile improvement...

Wolfgang, what do you think? Should we change the alignment of rtcan_rb_frame::data, or use put_unaligned on ARM?

I realized the mail and wonder why this problem does not show up with

vanilla

Linux. Maybe we need to port over some patch from there. I will have a

closer

look this even or over the weekend.

Quoted 8 lines

Wolfgang.

_______________________________________________
Xenomai mailing list
[email protected]
http://www.xenomai.org/mailman/listinfo/xenomai

Hi,

"cat /proc/cpu/alignment" report

User:           0
System:         0
Skipped:        0
Half:           0
Word:           0
DWord:          0
Multi:          0
User faults:    0 (ignored)

something wrong with that ?

Quoted 7 lines

Alexandre.

_______________________________________________
Xenomai mailing list
[email protected]
http://www.xenomai.org/mailman/listinfo/xenomai

For your information :
Actualy my kernel is linux 3.8.13 vanilla from https://www.kernel.org/pub/linux/kernel/v3.x/"
with Adeos/Xenomai Real-time patch 2.6.3 from download.gna.org/xenomai/stable/xenomai-2.6.3.tar.bz2

#26 lore raw
In reply to Alexandre COFFIGNAL
Quoted 31 lines · Alexandre COFFIGNAL
Quoted 29 lines · Gilles Chanteperdrix
Quoted 27 lines · Alexandre COFFIGNAL
Quoted 17 lines · Gilles Chanteperdrix
Quoted 16 lines · Alexandre COFFIGNAL
Quoted 16 lines
Quoted 11 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

Quoted 6 lines
Quoted 1 line

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

Quoted 7 lines
Quoted 3 lines

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

I think, i can't get cf->data to be properly aligned because "cf" is receive internal frame representation within the ring buffer of a struct rtcan_socket and struct rtcan_rb_frame is a generic structure used in all rtcan drivers .

Hi Alexandr,

Could you try the following patch?

(quoted diff) +0 -0

b/ksrc/drivers/can/rtcan_socket.h
index e0a395d..8984121 100644

ksrc/drivers/can/rtcan_socket.h +1 -0
@@ -77,6 +77,7 @@ struct rtcan_rb_frame {
      * existence of a timestamp is indicated by the RTCAN_HAS_TIMESTAMP
      * bit. */
     unsigned char       can_dlc;
+    unsigned short	pad;
 
     /* Data bytes */
     uint8_t             data[8];

Regards.

Signature · 1 line
                                                                Gilles.
#16 lore raw
In reply to Gilles Chanteperdrix
Quoted 36 lines · Gilles Chanteperdrix
Quoted 35 lines · Alexandre COFFIGNAL
Quoted 33 lines · Gilles Chanteperdrix
Quoted 19 lines · Alexandre COFFIGNAL
Quoted 17 lines · Gilles Chanteperdrix
Quoted 16 lines · Alexandre COFFIGNAL
Quoted 16 lines
Quoted 11 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

Quoted 7 lines
Quoted 4 lines

I think, i can't get cf->data to be properly aligned because "cf" is receive internal frame representation within the ring buffer of a struct rtcan_socket and struct rtcan_rb_frame is a generic structure used in all rtcan drivers .

Well, if you fix rtcan_rb_frame to be aligned, it will be aligned for all drivers, so that looks like a worthwile improvement...

I had a closer look. The CAN message (frame) queuing is optimized for size to get as much as possible messages into the queue. Therefore the CAN data are copied using memcpy, but only the real bytes. Directly behind the real data is the 64 bit timestamp, if requested, which is also not aligned. Therefore I suggest to use memcpy or byte accesses in the flexcan driver as well. If this was a good decision is another question.

Wolfgang.

#17 lore raw
Quoted 45 lines · Wolfgang Grandegger
Quoted 36 lines · Gilles Chanteperdrix
Quoted 35 lines · Alexandre COFFIGNAL
Quoted 33 lines · Gilles Chanteperdrix
Quoted 19 lines · Alexandre COFFIGNAL
Quoted 17 lines · Gilles Chanteperdrix
Quoted 16 lines · Alexandre COFFIGNAL
Quoted 16 lines
Quoted 11 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

Quoted 7 lines
Quoted 4 lines

I think, i can't get cf->data to be properly aligned because "cf" is receive internal frame representation within the ring buffer of a struct rtcan_socket and struct rtcan_rb_frame is a generic structure used in all rtcan drivers .

Well, if you fix rtcan_rb_frame to be aligned, it will be aligned for all drivers, so that looks like a worthwile improvement...

Quoted 6 lines

I had a closer look. The CAN message (frame) queuing is optimized for size to get as much as possible messages into the queue. Therefore the CAN data are copied using memcpy, but only the real bytes. Directly behind the real data is the 64 bit timestamp, if requested, which is also not aligned. Therefore I suggest to use memcpy or byte accesses in the flexcan driver as well. If this was a good decision is another question.

Aligning the data begining costs 2 bytes by struct rtcan_rb_frame. How many such structures are there for a typical driver?

Signature · 1 line
                                                                Gilles.
#18 lore raw
Quoted 53 lines · Gilles Chanteperdrix
Quoted 45 lines · Wolfgang Grandegger
Quoted 36 lines · Gilles Chanteperdrix
Quoted 35 lines · Alexandre COFFIGNAL
Quoted 33 lines · Gilles Chanteperdrix
Quoted 19 lines · Alexandre COFFIGNAL
Quoted 17 lines · Gilles Chanteperdrix
Quoted 16 lines · Alexandre COFFIGNAL
Quoted 16 lines
Quoted 11 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

Quoted 7 lines
Quoted 4 lines

I think, i can't get cf->data to be properly aligned because "cf" is receive internal frame representation within the ring buffer of a struct rtcan_socket and struct rtcan_rb_frame is a generic structure used in all rtcan drivers .

Well, if you fix rtcan_rb_frame to be aligned, it will be aligned for all drivers, so that looks like a worthwile improvement...

Quoted 6 lines

I had a closer look. The CAN message (frame) queuing is optimized for size to get as much as possible messages into the queue. Therefore the CAN data are copied using memcpy, but only the real bytes. Directly behind the real data is the 64 bit timestamp, if requested, which is also not aligned. Therefore I suggest to use memcpy or byte accesses in the flexcan driver as well. If this was a good decision is another question.

Quoted 2 lines

Aligning the data begining costs 2 bytes by struct rtcan_rb_frame. How many such structures are there for a typical driver?

Any message in the queue will require two bytes more. I did not say that optimizing for size is necessary, but that's how it was implemented long time ago. And I do not see a need to break that just because of the Flexcan driver.

Wolfgang.

Quoted 2 lines
#19 lore raw
Quoted 54 lines · Wolfgang Grandegger
Quoted 53 lines · Gilles Chanteperdrix
Quoted 51 lines · Wolfgang Grandegger
Quoted 36 lines · Gilles Chanteperdrix
Quoted 35 lines · Alexandre COFFIGNAL
Quoted 33 lines · Gilles Chanteperdrix
Quoted 19 lines · Alexandre COFFIGNAL
Quoted 17 lines · Gilles Chanteperdrix
Quoted 16 lines · Alexandre COFFIGNAL
Quoted 16 lines
Quoted 11 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.
is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you not arrange to get it properly aligned? Failing that, you should use put_unaligned instead of open coding it.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously, that is the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send a path

The other solution (getting cf->data to be properly aligned) would be more efficient, why is not it possible to get cf->data properly aligned?

Quoted 7 lines
Quoted 4 lines

I think, i can't get cf->data to be properly aligned because "cf" is receive internal frame representation within the ring buffer of a struct rtcan_socket and struct rtcan_rb_frame is a generic structure used in all rtcan drivers .

Well, if you fix rtcan_rb_frame to be aligned, it will be aligned for all drivers, so that looks like a worthwile improvement...

I had a closer look. The CAN message (frame) queuing is optimized for size to get as much as possible messages into the queue. Therefore the CAN data are copied using memcpy, but only the real bytes. Directly behind the real data is the 64 bit timestamp, if requested, which is also not aligned. Therefore I suggest to use memcpy or byte accesses in the flexcan driver as well. If this was a good decision is another question.

Quoted 7 lines
Quoted 2 lines

Aligning the data begining costs 2 bytes by struct rtcan_rb_frame. How many such structures are there for a typical driver?

Any message in the queue will require two bytes more. I did not say that optimizing for size is necessary, but that's how it was implemented long time ago. And I do not see a need to break that just because of the Flexcan driver.

IMO, it is not just for the flexcan driver, it will avoid unaligned accesses for all drivers which access data 4 bytes at a time. And I do not think it "breaks" anything. What I do not know is:
- how many struct rtcan_rb_frame are typically in use? If only a few, then adding 2 bytes should not be a problem.
- do all drivers access data 4 bytes at a time? or only the flexcan driver?

Regards.

Signature · 1 line
                                                                Gilles.
#20 lore raw

On Sun, 26 Jan 2014 21:56:10 +0100, Gilles Chanteperdrix

Quoted 42 lines · <[email protected]> wrote:
Quoted 39 lines · Wolfgang Grandegger
Quoted 37 lines · Gilles Chanteperdrix
Quoted 35 lines · Wolfgang Grandegger
Quoted 33 lines · Gilles Chanteperdrix
Quoted 31 lines · Alexandre COFFIGNAL
Quoted 27 lines · Gilles Chanteperdrix
Quoted 25 lines · Alexandre COFFIGNAL
Quoted 21 lines · Gilles Chanteperdrix
Quoted 19 lines · Alexandre COFFIGNAL
Quoted 19 lines
Quoted 19 lines
(quoted diff) +8 -0
+        cf->data[3]=((data0 >> 0)  & 0xFF) ;
 
+        cf->data[2]=((data0 >> 8)  & 0xFF) ;
 
+        cf->data[1]=((data0 >> 16)  & 0xFF) ;
 
+        cf->data[0]=((data0 >> 24)  & 0xFF) ;
 
+        cf->data[7]=((data1 >> 0)  & 0xFF) ;
 
+        cf->data[6]=((data1 >> 8)  & 0xFF) ;
 
+        cf->data[5]=((data1 >> 16)  & 0xFF) ;
 
+        cf->data[4]=((data1 >> 24)  & 0xFF) ;

rtcan flexcan works perfectly.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

is anyone know what is the problem with first instructions ?

Probably mb->data does not have the right alignment. Could you

not

arrange to get it properly aligned? Failing that, you should

use

Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 5 lines

put_unaligned instead of open coding it.

here structures used in flexcan driver, it seem to be aligned

I am talking about the alignment of cf->data, since obviously,

that is

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

the one which is causing problems.

Thank a lot, put_unaligned fix this issue if you want, i can send

a

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

path

The other solution (getting cf->data to be properly aligned) would

be

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

more efficient, why is not it possible to get cf->data properly

aligned?

I think, i can't get cf->data to be properly aligned because "cf"

is

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

receive internal frame representation within the ring buffer

of a struct rtcan_socket and struct rtcan_rb_frame is a generic

structure used in all rtcan drivers .

Well, if you fix rtcan_rb_frame to be aligned, it will be aligned

for

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

all drivers, so that looks like a worthwile improvement...

I had a closer look. The CAN message (frame) queuing is optimized for

size to get as much as possible messages into the queue. Therefore

the

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

CAN data are copied using memcpy, but only the real bytes. Directly

behind the real data is the 64 bit timestamp, if requested, which is

also not aligned. Therefore I suggest to use memcpy or byte accesses

in

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

the flexcan driver as well. If this was a good decision is another

question.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Aligning the data begining costs 2 bytes by struct rtcan_rb_frame. How

many such structures are there for a typical driver?

Any message in the queue will require two bytes more. I did not say

that

Quoted 1 line
Quoted 1 line

optimizing for size is necessary, but that's how it was implemented

long

Quoted 11 lines
Quoted 3 lines

time ago. And I do not see a need to break that just because of the

Flexcan driver.

IMO, it is not just for the flexcan driver, it will avoid unaligned

accesses for all drivers which access data 4 bytes at a time. And I do

not think it "breaks" anything. What I do not know is:

But it's just the Flexcan driver which is doing unaligned accesses.

Quoted 3 lines

- how many struct rtcan_rb_frame are typically in use? If only a few,

then adding 2 bytes should not be a problem.

This depends on the size of the queue. But if the message size changes

it will also change run-time behaviour because less messages will fit

into the queue. That's what I'm more concerned about than the extra

2 bytes.

Quoted 1 line

- do all drivers access data 4 bytes at a time? or only the flexcan

driver?

No, as far as I have seen only the Flexan driver. But I need to check.

Wolfgang.

#21 lore raw
Quoted 10 lines · Wolfgang Grandegger

On Sun, 26 Jan 2014 21:56:10 +0100, Gilles Chanteperdrix

Quoted 5 lines

IMO, it is not just for the flexcan driver, it will avoid unaligned

accesses for all drivers which access data 4 bytes at a time. And I do

not think it "breaks" anything. What I do not know is:

But it's just the Flexcan driver which is doing unaligned accesses.

Ok, can we agree on the following patch then?

ksrc/drivers/can/rtcan_flexcan.c +4 -5
index 8f0e8d1..1674b73 100644
@@ -38,6 +38,7 @@
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
 #include <linux/pinctrl/consumer.h>
 #endif
+#include <asm/unaligned.h>
 
 #include <rtdm/rtdm_driver.h>
 
@@ -497,11 +498,9 @@ static void flexcan_rx_interrupt(struct rtcan_device *dev,
 		cf->can_id |= CAN_RTR_FLAG;
 		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE;
 	} else {
-		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE + cf->can_dlc ;
-		*(__be32 *)(cf->data + 0) =
-			cpu_to_be32(flexcan_read(&mb->data[0]));
-		*(__be32 *)(cf->data + 4) =
-			cpu_to_be32(flexcan_read(&mb->data[1]));
+		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE + cf->can_dlc;
+		put_unaligned_be32(flexcan_read(&mb->data[0]), cf->data + 0);
+		put_unaligned_be32(flexcan_read(&mb->data[1]), cf->data + 4);
 	}
 
 	/* Store the interface index */
Signature · 1 line
                                                                Gilles.
#22 lore raw

On Tue, 28 Jan 2014 23:06:54 +0100, Gilles Chanteperdrix

ksrc/drivers/can/rtcan_flexcan.c static void flexcan_rx_interrupt(struct

Quoted 55 lines · <[email protected]> wrote:
Quoted 18 lines · Wolfgang Grandegger

On Sun, 26 Jan 2014 21:56:10 +0100, Gilles Chanteperdrix

Quoted 9 lines

IMO, it is not just for the flexcan driver, it will avoid unaligned

accesses for all drivers which access data 4 bytes at a time. And I do

not think it "breaks" anything. What I do not know is:

Quoted 1 line

But it's just the Flexcan driver which is doing unaligned accesses.

Ok, can we agree on the following patch then?

(quoted diff) +0 -0

b/ksrc/drivers/can/rtcan_flexcan.c

index 8f0e8d1..1674b73 100644

--- a/ksrc/drivers/can/rtcan_flexcan.c

+++ b/ksrc/drivers/can/rtcan_flexcan.c

ksrc/drivers/can/rtcan_flexcan.c +1 -0
@@ -38,6 +38,7 @@
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
 
 #include <linux/pinctrl/consumer.h>
 
 #endif
 
+#include <asm/unaligned.h>
 
 
 
 #include <rtdm/rtdm_driver.h>
@@ -497,11 +498,9 @@ static void flexcan_rx_interrupt(struct

rtcan_device

Quoted 19 lines
(quoted diff) +1 -5
 *dev,
 
 		cf->can_id |= CAN_RTR_FLAG;
 
 		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE;
 
 	} else {
 
-		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE + cf->can_dlc ;
 
-		*(__be32 *)(cf->data + 0) =
 
-			cpu_to_be32(flexcan_read(&mb->data[0]));
 
-		*(__be32 *)(cf->data + 4) =
 
-			cpu_to_be32(flexcan_read(&mb->data[1]));
 
+		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE + cf->can_dlc;

Review static void flexcan_rx_interrupt(struct

Quoted 10 lines
(quoted diff) +2 -0
 
+		put_unaligned_be32(flexcan_read(&mb->data[0]), cf->data + 0);
 
+		put_unaligned_be32(flexcan_read(&mb->data[1]), cf->data + 4);
 
 	}
 
 
 
 	/* Store the interface index */

D'accord, thanks.

Wolfgang.

#23 lore raw
Quoted 41 lines · Wolfgang Grandegger

ksrc/drivers/can/rtcan_flexcan.c static void flexcan_rx_interrupt(struct

Quoted 24 lines · Gilles Chanteperdrix
Quoted 7 lines · Wolfgang Grandegger

On Sun, 26 Jan 2014 21:56:10 +0100, Gilles Chanteperdrix

Quoted 3 lines

IMO, it is not just for the flexcan driver, it will avoid unaligned accesses for all drivers which access data 4 bytes at a time. And I do not think it "breaks" anything. What I do not know is:

But it's just the Flexcan driver which is doing unaligned accesses.

Ok, can we agree on the following patch then?

ksrc/drivers/can/rtcan_flexcan.c +1 -0
index 8f0e8d1..1674b73 100644
@@ -38,6 +38,7 @@
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
  #include <linux/pinctrl/consumer.h>
  #endif
+#include <asm/unaligned.h>
 
  #include <rtdm/rtdm_driver.h>
 
@@ -497,11 +498,9 @@ static void flexcan_rx_interrupt(struct

rtcan_device

Quoted 14 lines
ksrc/drivers/can/rtcan_flexcan.c +3 -5
 *dev,
  		cf->can_id |= CAN_RTR_FLAG;
  		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE;
  	} else {
-		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE + cf->can_dlc ;
-		*(__be32 *)(cf->data + 0) =
-			cpu_to_be32(flexcan_read(&mb->data[0]));
-		*(__be32 *)(cf->data + 4) =
-			cpu_to_be32(flexcan_read(&mb->data[1]));
+		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE + cf->can_dlc;
+		put_unaligned_be32(flexcan_read(&mb->data[0]), cf->data + 0);
+		put_unaligned_be32(flexcan_read(&mb->data[1]), cf->data + 4);
  	}
 
Quoted 5 lines
Quoted 1 line

/* Store the interface index */

D'accord, thanks.

Wolfgang.

Thank you all for your replies

Alexandre.

#24 lore raw
Quoted 43 lines · Alexandre COFFIGNAL
Quoted 41 lines · Wolfgang Grandegger

ksrc/drivers/can/rtcan_flexcan.c static void flexcan_rx_interrupt(struct

Quoted 24 lines · Gilles Chanteperdrix
Quoted 7 lines · Wolfgang Grandegger

On Sun, 26 Jan 2014 21:56:10 +0100, Gilles Chanteperdrix

Quoted 3 lines

IMO, it is not just for the flexcan driver, it will avoid unaligned accesses for all drivers which access data 4 bytes at a time. And I do not think it "breaks" anything. What I do not know is:

But it's just the Flexcan driver which is doing unaligned accesses.

Ok, can we agree on the following patch then?

ksrc/drivers/can/rtcan_flexcan.c +1 -0
index 8f0e8d1..1674b73 100644
@@ -38,6 +38,7 @@
   #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
   #include <linux/pinctrl/consumer.h>
   #endif
+#include <asm/unaligned.h>
 
   #include <rtdm/rtdm_driver.h>
 
@@ -497,11 +498,9 @@ static void flexcan_rx_interrupt(struct

rtcan_device

Quoted 14 lines
ksrc/drivers/can/rtcan_flexcan.c +3 -5
 *dev,
   		cf->can_id |= CAN_RTR_FLAG;
   		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE;
   	} else {
-		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE + cf->can_dlc ;
-		*(__be32 *)(cf->data + 0) =
-			cpu_to_be32(flexcan_read(&mb->data[0]));
-		*(__be32 *)(cf->data + 4) =
-			cpu_to_be32(flexcan_read(&mb->data[1]));
+		skb->rb_frame_size = EMPTY_RB_FRAME_SIZE + cf->can_dlc;
+		put_unaligned_be32(flexcan_read(&mb->data[0]), cf->data + 0);
+		put_unaligned_be32(flexcan_read(&mb->data[1]), cf->data + 4);
   	}
 
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
   	/* Store the interface index */

D'accord, thanks.

Wolfgang.

Thank you all for your replies

Hi Alexandre,

Did you check the last patch? Does it compile and work for you?

Regards.

Signature · 1 line
					    Gilles.
#25 lore raw
Quoted 49 lines · Gilles Chanteperdrix
Quoted 48 lines · Alexandre COFFIGNAL
Quoted 46 lines · Wolfgang Grandegger

ksrc/drivers/can/rtcan_flexcan.c static void flexcan_rx_interrupt(struct

Quoted 24 lines · Gilles Chanteperdrix
Quoted 7 lines · Wolfgang Grandegger

On Sun, 26 Jan 2014 21:56:10 +0100, Gilles Chanteperdrix

Quoted 3 lines

IMO, it is not just for the flexcan driver, it will avoid unaligned accesses for all drivers which access data 4 bytes at a time. And I do not think it "breaks" anything. What I do not know is:

But it's just the Flexcan driver which is doing unaligned accesses.

Ok, can we agree on the following patch then?

ksrc/drivers/can/rtcan_flexcan.c +1 -0
index 8f0e8d1..1674b73 100644
@@ -38,6 +38,7 @@
   #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
   #include <linux/pinctrl/consumer.h>
   #endif
+#include <asm/unaligned.h>
 
   #include <rtdm/rtdm_driver.h>
 
@@ -497,11 +498,9 @@ static void flexcan_rx_interrupt(struct

rtcan_device

Quoted 14 lines
ksrc/drivers/can/rtcan_flexcan.c +3 -5
 *dev,
           cf->can_id |= CAN_RTR_FLAG;
           skb->rb_frame_size = EMPTY_RB_FRAME_SIZE;
       } else {
-        skb->rb_frame_size = EMPTY_RB_FRAME_SIZE + cf->can_dlc ;
-        *(__be32 *)(cf->data + 0) =
-            cpu_to_be32(flexcan_read(&mb->data[0]));
-        *(__be32 *)(cf->data + 4) =
-            cpu_to_be32(flexcan_read(&mb->data[1]));
+        skb->rb_frame_size = EMPTY_RB_FRAME_SIZE + cf->can_dlc;
+ put_unaligned_be32(flexcan_read(&mb->data[0]), cf->data + 0);
+ put_unaligned_be32(flexcan_read(&mb->data[1]), cf->data + 4);
       }
 
Quoted 1 line
       /* Store the interface index */

D'accord, thanks.

Wolfgang.

Quoted 8 lines
Quoted 1 line

Thank you all for your replies

Hi Alexandre,

Did you check the last patch? Does it compile and work for you?

Regards.

I tested this patch, it works perfectly on i.MX28. Thank you very much.

Regards.