Skip to contentSkip to conversation

PowerPC PCI DMA issues (prefetch/coherency?)

DISCUSSION Adam Zilkie 10 participants 40 messages Sep 2, 2009 – Sep 11, 2009

lore
Share & tools
lore
#0 lore raw

Hi Chris,

I am having a problem similar to what you described in this discussion. We are using the ppc arch with 2.6.24 with CONFIG_SEQUOIA with compiles arch/ppc/kernel/head_44x.c (quite different
from /arch/powerpc/kernel/head_32.S). I would like to apply your backporting patch to this architecture. Any help would be appreciated.

Regards,
Adam

Signature · 5 lines
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.
#1 lore raw

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following section:
#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_GUARDED)
#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if that fixes your issue - this causes the 'M' bit to be set on the page which sure enforce cache coherency. If it doesn't, you'll need to check the 'M' bit isn't being masked out in head_44x.S (it was originally masked out on arch/powerpc, but was fixed in later kernels when the cache coherency issues with non-SMP systems were resolved).

The patch I had fixed two problems on 2.6.26 for 'powerpc':
1) It stopped the 'M' bit being masked out (head_32.S)
2) It set the cache coherency ('M' bit) flag on each page table entry (pgtable-ppc32.h)

Hope this helps!

Cheers,
Chris

Quoted 12 lines · Adam Zilkie

Hi Chris,

I am having a problem similar to what you described in this discussion. We are using the ppc arch with 2.6.24 with CONFIG_SEQUOIA with compiles arch/ppc/kernel/head_44x.c (quite different
from /arch/powerpc/kernel/head_32.S). I would like to apply your backporting patch to this architecture. Any help would be appreciated.

Regards,
Adam

Signature · 19 lines
______________________________
Chris Pringle
Software Design Engineer

Miranda Technologies Ltd.
Hithercroft Road
Wallingford
Oxfordshire OX10 9DG
UK

Tel. +44 1491 820206
Fax. +44 1491 820001
www.miranda.com

____________________________

Miranda Technologies Limited
Registered in England and Wales CN 02017053
Registered Office: James House, Mere Park, Dedmere Road, Marlow, Bucks, SL7 1FJ
#2 lore raw
Quoted 9 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following section:
#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_GUARDED)
#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Quoted 6 lines

Try adding _PAGE_COHERENT to the appropriate line above and see if that fixes your issue - this causes the 'M' bit to be set on the page which sure enforce cache coherency. If it doesn't, you'll need to check the 'M' bit isn't being masked out in head_44x.S (it was originally masked out on arch/powerpc, but was fixed in later kernels when the cache coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx. AFAIK, the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency isn't enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make sure they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

#36 lore raw
In reply to Chris Pringle

Hi,

This doesn't seem right. If we are talking about a single CPU core chip, i.e., just one data cache, then setting M is typically a) useless and could even b) cause a performance penalty depending on a chip's implementation.
The M bit is required if *other* cores with caches need to see changes for coherency of their caches. You wouldn't set it for one core only because your own core knows about its own cache.
The possible performance penalty could happen because you need some way to tell the others that they better intercept a transaction. And that could, depending on the chip, by a clock extra or so per transaction. Now, in theory, a DMA engine could have caches, read from cache content first, and could snoop the bus on global transactions like another core, but I have never heard of such a beast.=20

Hope this helps,

Heinz

-----Original Message-----
From: linuxppc-dev-bounces+heinz.wrobel=3Dfreescale.com@lists.ozlabs.org [mailto:linuxppc-dev-bounces+heinz.wrobel=3Dfreescale.com@lists.ozlabs.or= g
] On Behalf Of Chris Pringle
Sent: Donnerstag, 3. September 2009 10:05
To: [email protected]
Cc: Tom Burns; Andrea Zypchen; [email protected]
Subject: Re: AW: PowerPC PCI DMA issues (prefetch/coherency?)

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following section:
#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_GUARDED)
#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if that fixes your issue - this causes the 'M' bit to be set on the page which sure enforce cache coherency. If it doesn't, you'll need to check the 'M' bit isn't being masked out in head_44x.S (it was originally masked out on arch/powerpc, but was fixed in later kernels when the cache coherency issues with non-SMP systems were resolved).

The patch I had fixed two problems on 2.6.26 for 'powerpc':
1) It stopped the 'M' bit being masked out (head_32.S)
2) It set the cache coherency ('M' bit) flag on each page table entry (pgtable-ppc32.h)

Hope this helps!

Cheers,
Chris

Quoted 3 lines · Adam Zilkie

Hi Chris,

I am having a problem similar to what you described in this

discussion.

Quoted 9 lines

We are using the ppc arch with 2.6.24 with CONFIG_SEQUOIA with=20 compiles arch/ppc/kernel/head_44x.c (quite different from=20 /arch/powerpc/kernel/head_32.S). I would like to apply your=20 backporting patch to this architecture. Any help would be appreciated.

Regards,
Adam

=20

--=20

______________________________
Chris Pringle
Software Design Engineer

Miranda Technologies Ltd.
Hithercroft Road
Wallingford
Oxfordshire OX10 9DG
UK

Tel. +44 1491 820206
Fax. +44 1491 820001
www.miranda.com

____________________________

Miranda Technologies Limited
Registered in England and Wales CN 02017053 Registered Office: James House, Mere Park, Dedmere Road, Marlow, Bucks, SL7 1FJ
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#37 lore raw

In our case, we were suffering coherency issues on an 8260 when using DMA with PCI. Setting the 'M' bit cured all of our DMA coherency issues.

There is a comment in "pgtable-ppc32.h" on 2.6.29.6 that says:
"We always set _PAGE_COHERENT when SMP is enabled *or* the processor might need it for DMA coherency". Freescale had also suggested setting the 'M' bit when we submitted a support request.

I've no idea how this bit affects other PowerPC chips. Looking briefly through some of the header files, it looks as if the 'M' bit should not be set for 44x, so the issue is probably not the same as the one I had.

Cheers,
Chris

Quoted 56 lines · Wrobel Heinz-R39252 wrote:

Hi,

This doesn't seem right. If we are talking about a single CPU core chip, i.e., just one data cache, then setting M is typically a) useless and could even b) cause a performance penalty depending on a chip's implementation.
The M bit is required if *other* cores with caches need to see changes for coherency of their caches. You wouldn't set it for one core only because your own core knows about its own cache.
The possible performance penalty could happen because you need some way to tell the others that they better intercept a transaction. And that could, depending on the chip, by a clock extra or so per transaction. Now, in theory, a DMA engine could have caches, read from cache content first, and could snoop the bus on global transactions like another core, but I have never heard of such a beast.

Hope this helps,

Heinz

-----Original Message-----
From: [email protected] [mailto:[email protected] ] On Behalf Of Chris Pringle
Sent: Donnerstag, 3. September 2009 10:05
To: [email protected]
Cc: Tom Burns; Andrea Zypchen; [email protected]
Subject: Re: AW: PowerPC PCI DMA issues (prefetch/coherency?)

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following section:
#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_GUARDED)
#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if that fixes your issue - this causes the 'M' bit to be set on the page which sure enforce cache coherency. If it doesn't, you'll need to check the 'M' bit isn't being masked out in head_44x.S (it was originally masked out on arch/powerpc, but was fixed in later kernels when the cache coherency issues with non-SMP systems were resolved).

The patch I had fixed two problems on 2.6.26 for 'powerpc':
1) It stopped the 'M' bit being masked out (head_32.S)
2) It set the cache coherency ('M' bit) flag on each page table entry (pgtable-ppc32.h)

Hope this helps!

Cheers,
Chris

Quoted 18 lines
Quoted 4 lines · Adam Zilkie

Hi Chris,

I am having a problem similar to what you described in this

discussion.

Quoted 7 lines

We are using the ppc arch with 2.6.24 with CONFIG_SEQUOIA with compiles arch/ppc/kernel/head_44x.c (quite different from /arch/powerpc/kernel/head_32.S). I would like to apply your backporting patch to this architecture. Any help would be appreciated.

Regards,
Adam

____________________________

Miranda Technologies Limited
Registered in England and Wales CN 02017053
Registered Office: James House, Mere Park, Dedmere Road, Marlow, Bucks, SL7 1FJ

#39 lore raw
In reply to Chris Pringle

Chris,

I noticed the following comment in pgtable.h:

* - CACHE COHERENT bit (M) has no effect on PPC440 core, because it
* doesn't support SMP. So we can use this as software bit, like
* DIRTY.

And _PAGE_COHERENT is not defined for the 44x (giving a compile error when I add it the _PAGE_BASE line as you suggested). This would confirm that the M bit is meaningless for the PPC440

Regards,
Adam

Quoted 41 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following section:
#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_GUARDED)
#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if that fixes your issue - this causes the 'M' bit to be set on the page which sure enforce cache coherency. If it doesn't, you'll need to check the 'M' bit isn't being masked out in head_44x.S (it was originally masked out on arch/powerpc, but was fixed in later kernels when the cache coherency issues with non-SMP systems were resolved).

The patch I had fixed two problems on 2.6.26 for 'powerpc':
1) It stopped the 'M' bit being masked out (head_32.S)
2) It set the cache coherency ('M' bit) flag on each page table entry (pgtable-ppc32.h)

Hope this helps!

Cheers,
Chris

Quoted 12 lines · Adam Zilkie

Hi Chris,

I am having a problem similar to what you described in this discussion. We are using the ppc arch with 2.6.24 with CONFIG_SEQUOIA with compiles arch/ppc/kernel/head_44x.c (quite different
from /arch/powerpc/kernel/head_32.S). I would like to apply your backporting patch to this architecture. Any help would be appreciated.

Regards,
Adam

Signature · 5 lines
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.
#3 lore raw
In reply to Benjamin Herrenschmidt

Ben,

Thanks for your info.

Are you sure there is L2 cache on the 440?

I am seeing this problem with our custom IDE driver which is based on pretty old code. Our driver uses pci_alloc_consistent() to allocate the physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Regards,
Adam

Quoted 33 lines · Benjamin Herrenschmidt
Quoted 9 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following section:
#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_GUARDED)
#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Quoted 6 lines

Try adding _PAGE_COHERENT to the appropriate line above and see if that fixes your issue - this causes the 'M' bit to be set on the page which sure enforce cache coherency. If it doesn't, you'll need to check the 'M' bit isn't being masked out in head_44x.S (it was originally masked out on arch/powerpc, but was fixed in later kernels when the cache coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx. AFAIK, the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency isn't enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make sure they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

Signature · 5 lines
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.
#4 lore raw
Quoted 5 lines · Adam Zilkie

Ben,

Thanks for your info.

Are you sure there is L2 cache on the 440?

It depends on which 440 SoC you have. It also depends on that being configured in the kernel even if it does exist.

Quoted 5 lines

I am seeing this problem with our custom IDE driver which is based on pretty old code. Our driver uses pci_alloc_consistent() to allocate the physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

I would suggest updating the code. I have no idea if that is the problem, but it should probably be done anyway.

josh

#5 lore raw
In reply to Adam Zilkie

Hi Adam,

Quoted 1 line

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands board) have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

        L2C0: l2c {
              ...
        }
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on=20 pretty old code. Our driver uses pci_alloc_consistent() to allocate the

physical DMA memory and alloc_pages() to allocate a virtual page. It=20 then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I=20 should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut=09

Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Chris Pringle

Hi Adam,
=20
If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 2 lines
Quoted 2 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 5 lines
Quoted 5 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif
=20
Try adding _PAGE_COHERENT to the appropriate line above and see if

that=20

Quoted 1 line
Quoted 1 line

fixes your issue - this causes the 'M' bit to be set on the page

which=20

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to check

the=20

Quoted 1 line
Quoted 1 line

'M' bit isn't being masked out in head_44x.S (it was originally

masked=20

Quoted 7 lines
Quoted 2 lines

out on arch/powerpc, but was fixed in later kernels when the cache=20 coherency issues with non-SMP systems were resolved).

=20
I have some doubts about the usefulness of doing that for 4xx. AFAIK, the 440 core just ignores M.
=20
The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 3 lines

enabled or not working ?
=20
The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 9 lines

they use the appropriate DMA APIs which will do cache flushing when needed.
=20
Adam, what driver is causing you that sort of problems ? =20
Cheers,
Ben.
=20
=20

--=20
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
--------------------------------------------------------

CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, = is for the sole use of the intended recipient(s) and contains = information that is confidential and proprietary to AppliedMicro = Corporation or its subsidiaries. It is to be used solely for the purpose = of furthering the parties' business relationship. All unauthorized = review, use, disclosure or distribution is prohibited. If you are not = the intended recipient, please contact the sender by reply e-mail and = destroy all copies of the original message.

#38 lore raw
In reply to Wrobel Heinz-R39252
Quoted 15 lines · On Thu, 2009-09-03 at 13:20 +0100, Wrobel Heinz-R39252 wrote:

Hi,

This doesn't seem right. If we are talking about a single CPU core chip, i.e., just one data cache, then setting M is typically a) useless and could even b) cause a performance penalty depending on a chip's implementation.
The M bit is required if *other* cores with caches need to see changes for coherency of their caches. You wouldn't set it for one core only because your own core knows about its own cache.
The possible performance penalty could happen because you need some way to tell the others that they better intercept a transaction. And that could, depending on the chip, by a clock extra or so per transaction. Now, in theory, a DMA engine could have caches, read from cache content first, and could snoop the bus on global transactions like another core, but I have never heard of such a beast.

Actually there are some freescale part, afaik, that require M for proper cache coherency :-) I don't have names off the top of my mind, I think it has to be with PCI inbound buffers.

In this case, however, it's 440 on which I believe M is simply ignored.

Cheers,
Ben.

Quoted 56 lines

Hope this helps,

Heinz

-----Original Message-----
From: [email protected] [mailto:[email protected] ] On Behalf Of Chris Pringle
Sent: Donnerstag, 3. September 2009 10:05
To: [email protected]
Cc: Tom Burns; Andrea Zypchen; [email protected]
Subject: Re: AW: PowerPC PCI DMA issues (prefetch/coherency?)

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following section:
#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_GUARDED)
#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if that fixes your issue - this causes the 'M' bit to be set on the page which sure enforce cache coherency. If it doesn't, you'll need to check the 'M' bit isn't being masked out in head_44x.S (it was originally masked out on arch/powerpc, but was fixed in later kernels when the cache coherency issues with non-SMP systems were resolved).

The patch I had fixed two problems on 2.6.26 for 'powerpc':
1) It stopped the 'M' bit being masked out (head_32.S)
2) It set the cache coherency ('M' bit) flag on each page table entry (pgtable-ppc32.h)

Hope this helps!

Cheers,
Chris

Quoted 3 lines · Adam Zilkie

Hi Chris,

I am having a problem similar to what you described in this

discussion.

Quoted 9 lines

We are using the ppc arch with 2.6.24 with CONFIG_SEQUOIA with compiles arch/ppc/kernel/head_44x.c (quite different from /arch/powerpc/kernel/head_32.S). I would like to apply your backporting patch to this architecture. Any help would be appreciated.

Regards,
Adam

#6 lore raw
In reply to Prodyut Hazarika

Hi Prodyut,

Yes, I am using the 440EPx (same as the sequoia board).
Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus (using the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA memory using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the buffer was used.

Regards,
Adam

Quoted 72 lines · Prodyut Hazarika

Hi Adam,

Quoted 1 line

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands board) have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

        L2C0: l2c {
              ...
        }
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on pretty old code. Our driver uses pci_alloc_consistent() to allocate the

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut

Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 2 lines
Quoted 2 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 5 lines
Quoted 5 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 1 line
Quoted 1 line

fixes your issue - this causes the 'M' bit to be set on the page

which

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 1 line
Quoted 1 line

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 7 lines
Quoted 2 lines

out on arch/powerpc, but was fixed in later kernels when the cache coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx. AFAIK, the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 3 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 9 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

Signature · 5 lines
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.
#7 lore raw

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board).=20 Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 4 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 3 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.=20

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 5 lines · Prodyut Hazarika

Hi Adam,
=20

Quoted 1 line

Are you sure there is L2 cache on the 440?

=20
It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 7 lines
        L2C0: l2c {
              ...
        }

=20

Quoted 3 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 26 lines

=20

Quoted 3 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It=20 then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I=20 should convert these to the DMA API calls as you suggest.

=20
Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too
=20
Thanks
Prodyut=09
=20

Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Chris Pringle

Hi Adam,
=20
If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 2 lines
Quoted 2 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 5 lines
Quoted 5 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif
=20
Try adding _PAGE_COHERENT to the appropriate line above and see if

Quoted 12 lines

that=20

Quoted 1 line
Quoted 1 line

fixes your issue - this causes the 'M' bit to be set on the page

which=20

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to check

the=20

Quoted 1 line
Quoted 1 line

'M' bit isn't being masked out in head_44x.S (it was originally

masked=20

Quoted 5 lines
Quoted 3 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

=20
I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 17 lines
Quoted 3 lines

the 440 core just ignores M.
=20
The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 3 lines

enabled or not working ?
=20
The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 9 lines

they use the appropriate DMA APIs which will do cache flushing when needed.
=20
Adam, what driver is causing you that sort of problems ? =20
Cheers,
Ben.
=20
=20

--=20
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.
--------------------------------------------------------

CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, = is for the sole use of the intended recipient(s) and contains = information that is confidential and proprietary to AppliedMicro = Corporation or its subsidiaries. It is to be used solely for the purpose = of furthering the parties' business relationship. All unauthorized = review, use, disclosure or distribution is prohibited. If you are not = the intended recipient, please contact the sender by reply e-mail and = destroy all copies of the original message.

#8 lore raw

All,

We have found that using flush_dcache_range() after each DMA solves the problem. Ideally, we'd like to be able to allocate the virtual page in cache inhibited memory to avoid the performance loss from all the flush calls. To do this, we'd have to change our TLB sizes and reserve a TLB in memory as cache inhibited (using the 'I' bit). Will update if this works as well. Thanks for your help in this.

Regards,
Adam

Quoted 123 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 4 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 3 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 5 lines · Prodyut Hazarika

Hi Adam,

Quoted 1 line

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 7 lines
        L2C0: l2c {
              ...
        }
Quoted 3 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 25 lines
Quoted 4 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut

Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 2 lines
Quoted 2 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 4 lines
Quoted 4 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Quoted 13 lines
Quoted 1 line
Quoted 1 line

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 1 line
Quoted 1 line

fixes your issue - this causes the 'M' bit to be set on the page

which

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 1 line
Quoted 1 line

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 5 lines
Quoted 3 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 17 lines
Quoted 3 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 3 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 9 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

Signature · 13 lines
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the
addressee and may contain privileged or confidential information. Any
unauthorized disclosure is strictly prohibited. If you have received
this message in error, please notify us immediately so that we may
correct our internal records. Please then delete the original message.
Thank you.
--------------------------------------------------------

CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and contains information that is confidential and proprietary to AppliedMicro Corporation or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. All unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.
Signature · 5 lines
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.
#9 lore raw
Quoted 2 lines

We have found that using flush_dcache_range() after each DMA solves

the

Quoted 2 lines

problem. Ideally, we'd like to be able to allocate the virtual page in cache inhibited memory to avoid the performance loss from all the

flush

Quoted 3 lines

calls. To do this, we'd have to change our TLB sizes and reserve a TLB in memory as cache inhibited (using the 'I' bit). Will update if this works as well. Thanks for your help in this.

Aren't you using dma_alloc_coherent to get buffers that are shared between CPU and external devices?

Thanks
Prodyut

Quoted 6 lines · Prodyut Hazarika

Hi Adam,
=20

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board).=20 Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 1 line

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on

timing)

Quoted 1 line
Quoted 1 line

end up being partially corrupted when we try to parse the data in

the

Quoted 5 lines
Quoted 2 lines

virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 2 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of

16byte

Quoted 6 lines
Quoted 1 line

cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.=20

=20
This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region

has

Quoted 13 lines

the CacheInhibit bit set.
You will need a BDI connected to your system.
=20
Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.
=20
Thanks
Prodyut
=20
On Thu, 2009-09-03 at 13:27 -0700, Prodyut Hazarika wrote:

Quoted 8 lines
Quoted 5 lines

Hi Adam,
=20

Quoted 1 line

Are you sure there is L2 cache on the 440?

=20
It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 2 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC.

440EPx

Quoted 3 lines
Quoted 3 lines

has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is

L2C.

Quoted 7 lines
Quoted 7 lines

For example, in canyonlands.dts (460EX based board), we have the L2C entry.

        L2C0: l2c {
              ...
        }

=20

Quoted 1 line

I am seeing this problem with our custom IDE driver which is based

on

Quoted 5 lines

=20

Quoted 1 line
Quoted 1 line

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 2 lines

=20

Quoted 1 line

physical DMA memory and alloc_pages() to allocate a virtual page.

It=20

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I

should convert these to the DMA API calls as you suggest.

=20
Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent()

should

Quoted 10 lines
Quoted 10 lines

work too
=20
Thanks
Prodyut=09
=20

Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Chris Pringle

Hi Adam,
=20
If you have a look in include/asm-ppc/pgtable.h for the

following

Quoted 9 lines
Quoted 9 lines

section:

Quoted 2 lines
Quoted 2 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 5 lines
Quoted 5 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif
=20
Try adding _PAGE_COHERENT to the appropriate line above and see

if

Quoted 4 lines
Quoted 4 lines

that=20

Quoted 1 line
Quoted 1 line

fixes your issue - this causes the 'M' bit to be set on the page

which=20

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to

check

Quoted 4 lines
Quoted 4 lines

the=20

Quoted 1 line
Quoted 1 line

'M' bit isn't being masked out in head_44x.S (it was originally

masked=20

Quoted 1 line
Quoted 1 line

out on arch/powerpc, but was fixed in later kernels when the

cache

Quoted 12 lines

=20

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

coherency issues with non-SMP systems were resolved).

=20
I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 7 lines
Quoted 3 lines

the 440 core just ignores M.
=20
The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 3 lines

enabled or not working ?
=20
The L1 cache on 440 is simply not coherent, so drivers have to

make

Quoted 2 lines
Quoted 2 lines

sure

Quoted 1 line

they use the appropriate DMA APIs which will do cache flushing

when

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

needed.
=20
Adam, what driver is causing you that sort of problems ? =20
Cheers,
Ben.
=20
=20

Quoted 6 lines

--=20
Adam Zilkie
Software Designer,
International Datacasting Corp.
=20
This message and the documents attached hereto are intended only for

the

Quoted 8 lines

addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.
--------------------------------------------------------
=20
CONFIDENTIALITY NOTICE: This e-mail message, including any

attachments, is for the sole use of the intended recipient(s) and contains information that is confidential and proprietary to AppliedMicro Corporation or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. All unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

Quoted 1 line

=20

--=20
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.

#10 lore raw

We are using pci_alloc_consistent()

Adam

Quoted 163 lines · Prodyut Hazarika
Quoted 1 line

We have found that using flush_dcache_range() after each DMA solves

the

Quoted 2 lines

problem. Ideally, we'd like to be able to allocate the virtual page in cache inhibited memory to avoid the performance loss from all the

flush

Quoted 3 lines

calls. To do this, we'd have to change our TLB sizes and reserve a TLB in memory as cache inhibited (using the 'I' bit). Will update if this works as well. Thanks for your help in this.

Aren't you using dma_alloc_coherent to get buffers that are shared between CPU and external devices?

Thanks
Prodyut

Quoted 6 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 1 line

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on

timing)

Quoted 1 line
Quoted 1 line

end up being partially corrupted when we try to parse the data in

the

Quoted 5 lines
Quoted 2 lines

virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 2 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of

16byte

Quoted 6 lines
Quoted 1 line

cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region

has

Quoted 12 lines

the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 9 lines
Quoted 5 lines · Prodyut Hazarika

Hi Adam,

Quoted 1 line

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 2 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC.

440EPx

Quoted 3 lines
Quoted 3 lines

has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is

L2C.

Quoted 7 lines
Quoted 7 lines

For example, in canyonlands.dts (460EX based board), we have the L2C entry.

        L2C0: l2c {
              ...
        }
Quoted 1 line

I am seeing this problem with our custom IDE driver which is based

on

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 2 lines
Quoted 2 lines

physical DMA memory and alloc_pages() to allocate a virtual page.

It

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I

should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent()

should

Quoted 10 lines
Quoted 10 lines

work too

Thanks
Prodyut

Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the

following

Quoted 9 lines
Quoted 9 lines

section:

Quoted 2 lines
Quoted 2 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 5 lines
Quoted 5 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see

if

Quoted 4 lines
Quoted 4 lines

that

Quoted 1 line
Quoted 1 line

fixes your issue - this causes the 'M' bit to be set on the page

which

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to

check

Quoted 4 lines
Quoted 4 lines

the

Quoted 1 line
Quoted 1 line

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 1 line
Quoted 1 line

out on arch/powerpc, but was fixed in later kernels when the

cache

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 7 lines
Quoted 3 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 3 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to

make

Quoted 2 lines
Quoted 2 lines

sure

Quoted 1 line

they use the appropriate DMA APIs which will do cache flushing

when

Quoted 14 lines
Quoted 8 lines
Quoted 8 lines

needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

Signature · 5 lines
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for

the

Quoted 8 lines

addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.
--------------------------------------------------------

CONFIDENTIALITY NOTICE: This e-mail message, including any

attachments, is for the sole use of the intended recipient(s) and contains information that is confidential and proprietary to AppliedMicro Corporation or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. All unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

Quoted 1 line
Signature · 5 lines
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.
#35 lore raw
In reply to Adam Zilkie
Quoted 12 lines · Adam Zilkie

Hi Prodyut,

Yes, I am using the 440EPx (same as the sequoia board).
Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus (using the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA memory using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the buffer was used.

Smells to me like you aren't properly using the dma or pci dma APIs to flush/invalidate the cache around your transfers.

Ben.

Quoted 76 lines

Regards,
Adam

Quoted 72 lines · Prodyut Hazarika

Hi Adam,

Quoted 1 line

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands board) have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

        L2C0: l2c {
              ...
        }
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on pretty old code. Our driver uses pci_alloc_consistent() to allocate the

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut

Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 2 lines
Quoted 2 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 5 lines
Quoted 5 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 1 line
Quoted 1 line

fixes your issue - this causes the 'M' bit to be set on the page

which

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 1 line
Quoted 1 line

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 7 lines
Quoted 2 lines

out on arch/powerpc, but was fixed in later kernels when the cache coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx. AFAIK, the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 3 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 9 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

#12 lore raw
In reply to Adam Zilkie
Quoted 8 lines · Adam Zilkie

All,

We have found that using flush_dcache_range() after each DMA solves the problem. Ideally, we'd like to be able to allocate the virtual page in cache inhibited memory to avoid the performance loss from all the flush calls. To do this, we'd have to change our TLB sizes and reserve a TLB in memory as cache inhibited (using the 'I' bit). Will update if this works as well. Thanks for your help in this.

I think the problem is that you are manipulating the TLB directly, which you shouldn't have to do. You also shouldn't have to use flush_dcache_range() yourself neither.

It should all be handled by the DMA and PCI DMA APIs, you are just not using those correctly.

You have two choice. You can either allocate memory permanently mapped with I=1, in which case, use pci_alloc_consistent() (or dma_alloc_coherent(), same thing).

Or you can use "normal" memory and ensure you flush/invalidate the cache at the right time, which you can do with something like pci_map_sg/pci_unmap_sg (or dma_* variants) or the dma_sync_* functions.

It's all pretty standard mechanisms in Linux, other platforms also have non-coherent DMA (such as some ARMs) and those functions are generic.

Cheers,
Ben.

Quoted 127 lines

Regards,
Adam

Quoted 123 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 4 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 3 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 5 lines · Prodyut Hazarika

Hi Adam,

Quoted 1 line

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 7 lines
        L2C0: l2c {
              ...
        }
Quoted 3 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 25 lines
Quoted 4 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut

Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 2 lines
Quoted 2 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 4 lines
Quoted 4 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Quoted 13 lines
Quoted 1 line
Quoted 1 line

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 1 line
Quoted 1 line

fixes your issue - this causes the 'M' bit to be set on the page

which

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 1 line
Quoted 1 line

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 5 lines
Quoted 3 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 17 lines
Quoted 3 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 3 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 9 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

Signature · 13 lines
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for the
addressee and may contain privileged or confidential information. Any
unauthorized disclosure is strictly prohibited. If you have received
this message in error, please notify us immediately so that we may
correct our internal records. Please then delete the original message.
Thank you.
--------------------------------------------------------

CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and contains information that is confidential and proprietary to AppliedMicro Corporation or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. All unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.
#11 lore raw
In reply to Adam Zilkie
Quoted 1 line · Adam Zilkie

We are using pci_alloc_consistent()

Then your flush should have no effect since pci_alloc_consistent will return I=1 mapped memory, unless you don't have CONFIG_NOT_COHERENT_CACHE for some reason.

Cheers,
Ben.

Quoted 166 lines

Adam

Quoted 163 lines · Prodyut Hazarika
Quoted 1 line

We have found that using flush_dcache_range() after each DMA solves

the

Quoted 2 lines

problem. Ideally, we'd like to be able to allocate the virtual page in cache inhibited memory to avoid the performance loss from all the

flush

Quoted 3 lines

calls. To do this, we'd have to change our TLB sizes and reserve a TLB in memory as cache inhibited (using the 'I' bit). Will update if this works as well. Thanks for your help in this.

Aren't you using dma_alloc_coherent to get buffers that are shared between CPU and external devices?

Thanks
Prodyut

Quoted 6 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 1 line

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on

timing)

Quoted 1 line
Quoted 1 line

end up being partially corrupted when we try to parse the data in

the

Quoted 5 lines
Quoted 2 lines

virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 2 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of

16byte

Quoted 6 lines
Quoted 1 line

cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region

has

Quoted 12 lines

the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 9 lines
Quoted 5 lines · Prodyut Hazarika

Hi Adam,

Quoted 1 line

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 2 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC.

440EPx

Quoted 3 lines
Quoted 3 lines

has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is

L2C.

Quoted 7 lines
Quoted 7 lines

For example, in canyonlands.dts (460EX based board), we have the L2C entry.

        L2C0: l2c {
              ...
        }
Quoted 1 line

I am seeing this problem with our custom IDE driver which is based

on

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 2 lines
Quoted 2 lines

physical DMA memory and alloc_pages() to allocate a virtual page.

It

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I

should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent()

should

Quoted 10 lines
Quoted 10 lines

work too

Thanks
Prodyut

Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the

following

Quoted 9 lines
Quoted 9 lines

section:

Quoted 2 lines
Quoted 2 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 5 lines
Quoted 5 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see

if

Quoted 4 lines
Quoted 4 lines

that

Quoted 1 line
Quoted 1 line

fixes your issue - this causes the 'M' bit to be set on the page

which

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to

check

Quoted 4 lines
Quoted 4 lines

the

Quoted 1 line
Quoted 1 line

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 1 line
Quoted 1 line

out on arch/powerpc, but was fixed in later kernels when the

cache

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 7 lines
Quoted 3 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 3 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to

make

Quoted 2 lines
Quoted 2 lines

sure

Quoted 1 line

they use the appropriate DMA APIs which will do cache flushing

when

Quoted 14 lines
Quoted 8 lines
Quoted 8 lines

needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

Signature · 5 lines
Adam Zilkie
Software Designer,
International Datacasting Corp.

This message and the documents attached hereto are intended only for

the

Quoted 8 lines

addressee and may contain privileged or confidential information. Any unauthorized disclosure is strictly prohibited. If you have received this message in error, please notify us immediately so that we may correct our internal records. Please then delete the original message. Thank you.
--------------------------------------------------------

CONFIDENTIALITY NOTICE: This e-mail message, including any

attachments, is for the sole use of the intended recipient(s) and contains information that is confidential and proprietary to AppliedMicro Corporation or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. All unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

Quoted 1 line
#13 lore raw
In reply to Prodyut Hazarika

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 144 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 5 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 4 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 2 lines

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 11 lines
        L2C0: l2c {
              ...
        }
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 36 lines
Quoted 2 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut

Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 6 lines
Quoted 6 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

which

Quoted 16 lines
Quoted 2 lines
Quoted 2 lines

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 8 lines
Quoted 6 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 22 lines
Quoted 4 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 4 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 10 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

#14 lore raw

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing
invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 146 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 139 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 5 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 4 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 11 lines
        L2C0: l2c {
              ...
        }
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 33 lines
Quoted 2 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut

Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 6 lines
Quoted 6 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

Quoted 15 lines

which

Quoted 2 lines
Quoted 2 lines

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 8 lines
Quoted 6 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 22 lines
Quoted 4 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 4 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 10 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

#15 lore raw

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 156 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing
invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 144 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 137 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 5 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 4 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 11 lines
        L2C0: l2c {
              ...
        }
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 31 lines
Quoted 2 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks

Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 6 lines
Quoted 6 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

Quoted 15 lines

which

Quoted 2 lines
Quoted 2 lines

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 8 lines
Quoted 6 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 22 lines
Quoted 4 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 4 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 10 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

#16 lore raw

Hi Mikhail,

Sorry, this DMA code is in a tasklet. Are you suggesting the processor is in supervisor mode at that time? Calling pci_dma_sync_sg_for_cpu() from the tasklet context is what generates the OOPS. The entire oops is as follows, if it's relevant:

Oops: kernel access of bad area, sig: 11 [#1]
NIP: c0003ab0 LR: c0010c30 CTR: 02400001
REGS: df117bd0 TRAP: 0300   Tainted: P         (2.6.24.2)
MSR: 00029000 <EE,ME>  CR: 44224042  XER: 20000000
DEAR: 3fd39000, ESR: 00800000

TASK = de5db7d0[157] 'cat' THREAD: df116000
GPR00: e11e5854 df117c80 de5db7d0 3fd39000 02400001 0000001f 00000002 0079a169
GPR08: 00000001 c0310000 00000000 c0010c84 24224042 101c0dac c0310000 10177000
GPR16: deb14200 df116000 e12062d0 e11f6104 de0f16c0 e11f0000 c0310000 e11f59cc
GPR24: e11f62d0 e11f0000 e11f0000 00000000 00000002 defee014 3fd39008 87d39009
NIP [c0003ab0] invalidate_dcache_range+0x1c/0x30
LR [c0010c30] __dma_sync+0x58/0xac

Call Trace:

[df117c80] [0000000a] 0xa (unreliable)
[df117c90] [e11e5854] DoTasklet+0x67c/0xc90 [ideDriverDuo_cyph] [df117ce0] [c001ee24] tasklet_action+0x60/0xcc
[df117cf0] [c001ef04] __do_softirq+0x74/0xe0
[df117d10] [c00067a8] do_softirq+0x54/0x58
[df117d20] [c001edb4] irq_exit+0x48/0x58
[df117d30] [c00069d0] do_IRQ+0x6c/0xc0
[df117d40] [c00020e0] ret_from_except+0x0/0x18
[df117e00] [c00501e0] unmap_vmas+0x2c4/0x560
[df117e90] [c0053ebc] exit_mmap+0x64/0xec
[df117ec0] [c00171ac] mmput+0x50/0xd4
[df117ed0] [c001aef8] exit_mm+0x80/0xe0
[df117ef0] [c001c818] do_exit+0x134/0x6f8
[df117f30] [c001ce14] do_group_exit+0x38/0x74
[df117f40] [c0001a80] ret_from_syscall+0x0/0x3c
Instruction dump:
7c0018ac 38630020 4200fff8 7c0004ac 4e800020 38a0001f 7c632878 7c832050 7c842a14 5484d97f 4d820020 7c8903a6 <7c001bac> 38630020 4200fff8 7c0004ac

Kernel panic - not syncing: Aiee, killing interrupt handler!

Rebooting in 180 seconds..

Cheers,
Tom

Quoted 164 lines · Mikhail Zolotaryov

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 156 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing
invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 144 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 137 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 5 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 4 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 11 lines
        L2C0: l2c {
              ...
        }
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 31 lines
Quoted 2 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks

Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 6 lines
Quoted 6 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

Quoted 15 lines

which

Quoted 2 lines
Quoted 2 lines

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 8 lines
Quoted 6 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 22 lines
Quoted 4 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 4 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 10 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

#17 lore raw

Hi Tom,

In my case __dma_sync() calls flush_dcache_range() (it's due to alignment) from a tasklet - no OOPS. It uses dcbf instruction instead of dcbi - that's the difference as dcbf is not privileged.

Quoted 214 lines · Tom Burns

Hi Mikhail,

Sorry, this DMA code is in a tasklet. Are you suggesting the processor is in supervisor mode at that time? Calling pci_dma_sync_sg_for_cpu() from the tasklet context is what generates the OOPS. The entire oops is as follows, if it's relevant:

Oops: kernel access of bad area, sig: 11 [#1]
NIP: c0003ab0 LR: c0010c30 CTR: 02400001
REGS: df117bd0 TRAP: 0300   Tainted: P         (2.6.24.2)
MSR: 00029000 <EE,ME>  CR: 44224042  XER: 20000000
DEAR: 3fd39000, ESR: 00800000

TASK = de5db7d0[157] 'cat' THREAD: df116000
GPR00: e11e5854 df117c80 de5db7d0 3fd39000 02400001 0000001f 00000002 0079a169
GPR08: 00000001 c0310000 00000000 c0010c84 24224042 101c0dac c0310000 10177000
GPR16: deb14200 df116000 e12062d0 e11f6104 de0f16c0 e11f0000 c0310000 e11f59cc
GPR24: e11f62d0 e11f0000 e11f0000 00000000 00000002 defee014 3fd39008 87d39009
NIP [c0003ab0] invalidate_dcache_range+0x1c/0x30
LR [c0010c30] __dma_sync+0x58/0xac

Call Trace:

[df117c80] [0000000a] 0xa (unreliable)
[df117c90] [e11e5854] DoTasklet+0x67c/0xc90 [ideDriverDuo_cyph] [df117ce0] [c001ee24] tasklet_action+0x60/0xcc
[df117cf0] [c001ef04] __do_softirq+0x74/0xe0
[df117d10] [c00067a8] do_softirq+0x54/0x58
[df117d20] [c001edb4] irq_exit+0x48/0x58
[df117d30] [c00069d0] do_IRQ+0x6c/0xc0
[df117d40] [c00020e0] ret_from_except+0x0/0x18
[df117e00] [c00501e0] unmap_vmas+0x2c4/0x560
[df117e90] [c0053ebc] exit_mmap+0x64/0xec
[df117ec0] [c00171ac] mmput+0x50/0xd4
[df117ed0] [c001aef8] exit_mm+0x80/0xe0
[df117ef0] [c001c818] do_exit+0x134/0x6f8
[df117f30] [c001ce14] do_group_exit+0x38/0x74
[df117f40] [c0001a80] ret_from_syscall+0x0/0x3c
Instruction dump:
7c0018ac 38630020 4200fff8 7c0004ac 4e800020 38a0001f 7c632878 7c832050 7c842a14 5484d97f 4d820020 7c8903a6 <7c001bac> 38630020 4200fff8 7c0004ac

Kernel panic - not syncing: Aiee, killing interrupt handler!

Rebooting in 180 seconds..

Cheers,
Tom

Quoted 164 lines · Mikhail Zolotaryov

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 156 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing
invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 144 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 137 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 5 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 4 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 11 lines
        L2C0: l2c {
              ...
        }
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 31 lines
Quoted 2 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks

Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 6 lines
Quoted 6 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

Quoted 15 lines

which

Quoted 2 lines
Quoted 2 lines

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 8 lines
Quoted 6 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 22 lines
Quoted 4 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 4 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 10 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

#22 lore raw
In reply to Mikhail Zolotaryov

Hi,

Thank you everyone for your help.

I've been looking into the other dma/pci API calls (dma_alloc_coherent, pci_alloc_consistent). I don't see how either of these return memory mapped to a TLB with the I bit set to 1 in kernel 2.6.24. In our kernel code, the only use of the PPC44x_TLB_I define is in head_44x.S in _start. We have CONFIG_NON_COHERENT_CACHE enabled.

We changed our code to use dma_alloc_coherent, removed our manual cacheline flushing, and saw the corrupted data return. To me this means dma_alloc_coherent cannot be setting the I=1 bit in the TLB entry.

I tried, using our JTAG debugger (BDI3000), to pause operation after calling dma_alloc_coherent to examine the TLB entry for the memory returned by the call (which was just past CONFIG_CONSISTENT_START=0xff100000). The TLB list loaded at the time that I paused operation did not show a mapping for this area. I guess the kernel swaps TLB entries on the fly so it isn't limited to only 64 entries? I will try to sleep in the same context as the dma_alloc_coherent call to try to catch the TLB entry while loaded to see if it has the I bit set.

If that fails, any ideas?

Thanks,
Tom Burns
International Datacasting Corporation

Quoted 164 lines · Mikhail Zolotaryov

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 156 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing
invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 144 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 137 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 5 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 4 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 11 lines
        L2C0: l2c {
              ...
        }
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 31 lines
Quoted 2 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks

Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 6 lines
Quoted 6 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

Quoted 15 lines

which

Quoted 2 lines
Quoted 2 lines

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 8 lines
Quoted 6 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 22 lines
Quoted 4 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 4 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 10 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

#23 lore raw
Quoted 6 lines

Tom Burns wrote=20
Hi,
=20
Thank you everyone for your help.
=20
I've been looking into the other dma/pci API calls

(dma_alloc_coherent,

Quoted 7 lines

pci_alloc_consistent). I don't see how either of these return memory mapped to a TLB with the I bit set to 1 in kernel 2.6.24. In our kernel
code, the only use of the PPC44x_TLB_I define is in head_44x.S in _start. We have CONFIG_NON_COHERENT_CACHE enabled.
=20
We changed our code to use dma_alloc_coherent, removed our manual

Quoted 8 lines

cacheline flushing, and saw the corrupted data return. To me this means
dma_alloc_coherent cannot be setting the I=3D1 bit in the TLB entry. =20
I tried, using our JTAG debugger (BDI3000), to pause operation after calling dma_alloc_coherent to examine the TLB entry for the memory returned by the call (which was just past CONFIG_CONSISTENT_START=3D0xff100000). The TLB list loaded at the =

time

Quoted 4 lines

that I paused operation did not show a mapping for this area. I guess the kernel swaps TLB entries on the fly so it isn't limited to only 64 entries? I will try to sleep in the same context as the dma_alloc_coherent call to try to catch the TLB entry while loaded to

Quoted 8 lines

see if it has the I bit set.
=20
If that fails, any ideas?
=20
Thanks,
Tom Burns
International Datacasting Corporation
=20

There is also a patch that was submitted for 440EPX a couple of years back. The 440EPX SOC causes hangs with Memory Read Multiple (MRM) commands. Whether MRM is used or not depends on the value of PCI_CACHE_LINE_SIZE register. I see that the changes are no longer present in linux 2.6.30+ kernels. Although the patch certainly resolved the hang issue with Silicon Image 680 PATA card as the 680 driver attempts to use MRM commands - I don't know if it would resolve the data corruption issue. It is certainly worth trying in my opinion. Below is a link to the patch submission:

http://git.denx.de/?p=3Dlinux-2.6-denx.git;a=3Dcommit;h=3Dcffefde924123e6=
85327
48dd58fcb780eab5e219

Quoted 7 lines
Quoted 6 lines · Mikhail Zolotaryov

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call

directly

Quoted 20 lines
Quoted 2 lines
Quoted 2 lines

the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache

line

Quoted 17 lines
Quoted 17 lines

management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 10 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 3 lines · Prodyut Hazarika

Hi Adam,

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 1 line

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on

timing)

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

end up being partially corrupted when we try to parse the data

in

Quoted 4 lines

the

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

virtual page. We have confirmed the data is good before the PCI-

IDE

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

bridge. We are creating two 8K pages and map them to physical

DMA

Quoted 19 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

memory

Quoted 2 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of

16byte

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA

region

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

has
the CacheInhibit bit set.
You will need a BDI connected to your system.

Quoted 28 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Also, you will need to invalidate and flush the lines

appropriately,

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

since in 440 cores,
L1Cache coherency is managed entirely by software. Please look at drivers/net/ibm_newemac/mal.c and core.c for

example on

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines

how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 6 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx
has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there

is

Quoted 34 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

L2C.
For example, in canyonlands.dts (460EX based board), we have the

L2C

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

entry.

        L2C0: l2c {
              ...
        }
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to

allocate

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

the

Quoted 1 line
Quoted 1 line

physical DMA memory and alloc_pages() to allocate a virtual

page.

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

It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you

suggest.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

Could you give more details on the consistency problem? It is a

good

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

idea to change to the new DMA APIs, but pci_alloc_consistent()

should

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

work too

Thanks
Prodyut On Thu, 2009-09-03 at 19:57 +1000, Benjamin

Herrenschmidt

Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines · wrote:
Quoted 3 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the

following

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 1 line
Quoted 1 line

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 5 lines
Quoted 5 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and

see

Quoted 12 lines

if

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

that

Quoted 1 line
Quoted 1 line

fixes your issue - this causes the 'M' bit to be set on the

page

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

which

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to

check

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

the

Quoted 1 line
Quoted 1 line

'M' bit isn't being masked out in head_44x.S (it was

originally

Quoted 50 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

masked

Quoted 1 line
Quoted 1 line

out on arch/powerpc, but was fixed in later kernels when the

cache

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

coherency issues with non-SMP systems were resolved).

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

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 3 lines
Quoted 3 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache

coherency

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

isn't

Quoted 3 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to

make

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

sure

Quoted 1 line

they use the appropriate DMA APIs which will do cache flushing

when

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

needed.

Adam, what driver is causing you that sort of problems ?

Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Cheers,
Ben.

=20
=20
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#33 lore raw
In reply to Tom Burns
Quoted 9 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Wait a minute.... usermode ? You are doing all of that from userspace ? I don't understand the story here. You can't call all those kernel APIs form userspace in the first place, indeed... But then an IDE driver has nothing to do in userspace neither.

Cheers,
Ben.

Quoted 162 lines

Regards,
Tom Burns
International Datacasting Corporation

Quoted 151 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 142 lines · Prodyut Hazarika

Hi Adam,

Quoted 3 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 5 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 4 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 11 lines
        L2C0: l2c {
              ...
        }
Quoted 6 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 35 lines
Quoted 4 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut

Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 6 lines
Quoted 6 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

Quoted 15 lines

which

Quoted 2 lines
Quoted 2 lines

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 8 lines
Quoted 6 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 22 lines
Quoted 4 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 4 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 10 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#21 lore raw
In reply to Tom Burns
Quoted 6 lines · Tom Burns

Hi Mikhail,

Sorry, this DMA code is in a tasklet. Are you suggesting the processor is in supervisor mode at that time? Calling pci_dma_sync_sg_for_cpu() from the tasklet context is what generates the OOPS. The entire oops is as follows, if it's relevant:

Yes. A tasklet runs in supervisor mode.

Quoted 1 line
Oops: kernel access of bad area, sig: 11 [#1]

That seems to indicate that your passed an incorrect address to dcbi (ie, an address that isn't currently mapped, 0x3fd39000 according to your log), so that looks like a driver bug to me (unless something is busted in 2.6.24 version of __dma_sync on 44x...)

Cheers,
Ben.

Quoted 229 lines

NIP: c0003ab0 LR: c0010c30 CTR: 02400001
REGS: df117bd0 TRAP: 0300 Tainted: P (2.6.24.2)
MSR: 00029000 <EE,ME> CR: 44224042 XER: 20000000
DEAR: 3fd39000, ESR: 00800000
TASK = de5db7d0[157] 'cat' THREAD: df116000
GPR00: e11e5854 df117c80 de5db7d0 3fd39000 02400001 0000001f 00000002 0079a169
GPR08: 00000001 c0310000 00000000 c0010c84 24224042 101c0dac c0310000 10177000
GPR16: deb14200 df116000 e12062d0 e11f6104 de0f16c0 e11f0000 c0310000 e11f59cc
GPR24: e11f62d0 e11f0000 e11f0000 00000000 00000002 defee014 3fd39008 87d39009
NIP [c0003ab0] invalidate_dcache_range+0x1c/0x30
LR [c0010c30] __dma_sync+0x58/0xac

Call Trace:

[df117c80] [0000000a] 0xa (unreliable)
[df117c90] [e11e5854] DoTasklet+0x67c/0xc90 [ideDriverDuo_cyph] [df117ce0] [c001ee24] tasklet_action+0x60/0xcc
[df117cf0] [c001ef04] __do_softirq+0x74/0xe0
[df117d10] [c00067a8] do_softirq+0x54/0x58
[df117d20] [c001edb4] irq_exit+0x48/0x58
[df117d30] [c00069d0] do_IRQ+0x6c/0xc0
[df117d40] [c00020e0] ret_from_except+0x0/0x18
[df117e00] [c00501e0] unmap_vmas+0x2c4/0x560
[df117e90] [c0053ebc] exit_mmap+0x64/0xec
[df117ec0] [c00171ac] mmput+0x50/0xd4
[df117ed0] [c001aef8] exit_mm+0x80/0xe0
[df117ef0] [c001c818] do_exit+0x134/0x6f8
[df117f30] [c001ce14] do_group_exit+0x38/0x74
[df117f40] [c0001a80] ret_from_syscall+0x0/0x3c
Instruction dump:
7c0018ac 38630020 4200fff8 7c0004ac 4e800020 38a0001f 7c632878 7c832050 7c842a14 5484d97f 4d820020 7c8903a6 <7c001bac> 38630020 4200fff8 7c0004ac

Kernel panic - not syncing: Aiee, killing interrupt handler!

Rebooting in 180 seconds..

Cheers,
Tom

Quoted 180 lines · Mikhail Zolotaryov

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 171 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 154 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 145 lines · Prodyut Hazarika

Hi Adam,

Quoted 3 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 5 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 4 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has
the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 9 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx
has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C.
For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 12 lines
        L2C0: l2c {
              ...
        }
Quoted 7 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 34 lines
Quoted 4 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut On Thu, 2009-09-03 at 19:57 +1000, Benjamin Herrenschmidt

Quoted 6 lines · wrote:
Quoted 4 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 6 lines
Quoted 6 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

Quoted 15 lines

which

Quoted 2 lines
Quoted 2 lines

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 8 lines
Quoted 6 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 22 lines
Quoted 4 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 4 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 10 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#18 lore raw
In reply to Mikhail Zolotaryov
Quoted 5 lines · Mikhail Zolotaryov

Hi Tom,

In my case __dma_sync() calls flush_dcache_range() (it's due to alignment) from a tasklet - no OOPS. It uses dcbf instruction instead of dcbi - that's the difference as dcbf is not privileged.

What it calls depends on the direction of the transfer. The tasklet runs in priviledged mode, dcbi should work just fine... if passed a correct address :-)

Cheers,
Ben.

Quoted 244 lines
Quoted 43 lines · Tom Burns

Hi Mikhail,

Sorry, this DMA code is in a tasklet. Are you suggesting the processor is in supervisor mode at that time? Calling pci_dma_sync_sg_for_cpu() from the tasklet context is what generates the OOPS. The entire oops is as follows, if it's relevant:

Oops: kernel access of bad area, sig: 11 [#1]
NIP: c0003ab0 LR: c0010c30 CTR: 02400001
REGS: df117bd0 TRAP: 0300   Tainted: P         (2.6.24.2)
MSR: 00029000 <EE,ME>  CR: 44224042  XER: 20000000
DEAR: 3fd39000, ESR: 00800000

TASK = de5db7d0[157] 'cat' THREAD: df116000
GPR00: e11e5854 df117c80 de5db7d0 3fd39000 02400001 0000001f 00000002 0079a169
GPR08: 00000001 c0310000 00000000 c0010c84 24224042 101c0dac c0310000 10177000
GPR16: deb14200 df116000 e12062d0 e11f6104 de0f16c0 e11f0000 c0310000 e11f59cc
GPR24: e11f62d0 e11f0000 e11f0000 00000000 00000002 defee014 3fd39008 87d39009
NIP [c0003ab0] invalidate_dcache_range+0x1c/0x30
LR [c0010c30] __dma_sync+0x58/0xac

Call Trace:

[df117c80] [0000000a] 0xa (unreliable)
[df117c90] [e11e5854] DoTasklet+0x67c/0xc90 [ideDriverDuo_cyph] [df117ce0] [c001ee24] tasklet_action+0x60/0xcc
[df117cf0] [c001ef04] __do_softirq+0x74/0xe0
[df117d10] [c00067a8] do_softirq+0x54/0x58
[df117d20] [c001edb4] irq_exit+0x48/0x58
[df117d30] [c00069d0] do_IRQ+0x6c/0xc0
[df117d40] [c00020e0] ret_from_except+0x0/0x18
[df117e00] [c00501e0] unmap_vmas+0x2c4/0x560
[df117e90] [c0053ebc] exit_mmap+0x64/0xec
[df117ec0] [c00171ac] mmput+0x50/0xd4
[df117ed0] [c001aef8] exit_mm+0x80/0xe0
[df117ef0] [c001c818] do_exit+0x134/0x6f8
[df117f30] [c001ce14] do_group_exit+0x38/0x74
[df117f40] [c0001a80] ret_from_syscall+0x0/0x3c
Instruction dump:
7c0018ac 38630020 4200fff8 7c0004ac 4e800020 38a0001f 7c632878 7c832050 7c842a14 5484d97f 4d820020 7c8903a6 <7c001bac> 38630020 4200fff8 7c0004ac

Quoted 196 lines
Kernel panic - not syncing: Aiee, killing interrupt handler!

Rebooting in 180 seconds..

Cheers,
Tom

Quoted 186 lines · Mikhail Zolotaryov

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 177 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 160 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 151 lines · Prodyut Hazarika

Hi Adam,

Quoted 3 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 7 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing)
end up being partially corrupted when we try to parse the data in the
virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 5 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte
cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has
the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on
how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 9 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx
has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C.
For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 12 lines
        L2C0: l2c {
              ...
        }
Quoted 7 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 36 lines
Quoted 5 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should
work too

Thanks
Prodyut On Thu, 2009-09-03 at 19:57 +1000, Benjamin

Quoted 6 lines · Herrenschmidt
Quoted 4 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 6 lines
Quoted 6 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

Quoted 15 lines

which

Quoted 2 lines
Quoted 2 lines

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 8 lines
Quoted 6 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 22 lines
Quoted 4 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 4 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 10 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#31 lore raw
In reply to Tom Burns
Quoted 9 lines · Tom Burns

Hi,

Thank you everyone for your help.

I've been looking into the other dma/pci API calls (dma_alloc_coherent, pci_alloc_consistent). I don't see how either of these return memory mapped to a TLB with the I bit set to 1 in kernel 2.6.24. In our kernel code, the only use of the PPC44x_TLB_I define is in head_44x.S in _start. We have CONFIG_NON_COHERENT_CACHE enabled.

It uses _PAGE_NO_CACHE which translates into the I bit in the TLB from the TLB miss handler.

Quoted 3 lines

We changed our code to use dma_alloc_coherent, removed our manual cacheline flushing, and saw the corrupted data return. To me this means dma_alloc_coherent cannot be setting the I=1 bit in the TLB entry.

It must and it is. However, what are you allocating with dma_alloc_coherent ? The actual data buffers must -also- be properly cache managed, probably via dma_sync().

It would help tremendously if you sent us the source of the driver :-)

Quoted 10 lines

I tried, using our JTAG debugger (BDI3000), to pause operation after calling dma_alloc_coherent to examine the TLB entry for the memory returned by the call (which was just past CONFIG_CONSISTENT_START=0xff100000). The TLB list loaded at the time that I paused operation did not show a mapping for this area. I guess the kernel swaps TLB entries on the fly so it isn't limited to only 64 entries? I will try to sleep in the same context as the dma_alloc_coherent call to try to catch the TLB entry while loaded to see if it has the I bit set.

Ben.

Quoted 193 lines

If that fails, any ideas?

Thanks,
Tom Burns
International Datacasting Corporation

Quoted 180 lines · Mikhail Zolotaryov

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 171 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 154 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 145 lines · Prodyut Hazarika

Hi Adam,

Quoted 3 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 5 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 4 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 1 line

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has
the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 7 lines · Prodyut Hazarika

Hi Adam,

Quoted 2 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 9 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx
has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C.
For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 12 lines
        L2C0: l2c {
              ...
        }
Quoted 7 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 34 lines
Quoted 4 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut On Thu, 2009-09-03 at 19:57 +1000, Benjamin Herrenschmidt

Quoted 6 lines · wrote:
Quoted 4 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 6 lines
Quoted 6 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

Quoted 15 lines

which

Quoted 2 lines
Quoted 2 lines

sure enforce cache coherency. If it doesn't, you'll need to check

the

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 8 lines
Quoted 6 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 22 lines
Quoted 4 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 4 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 10 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#24 lore raw
In reply to Pravin Bathija
Quoted 10 lines · Pravin Bathija

There is also a patch that was submitted for 440EPX a couple of years back. The 440EPX SOC causes hangs with Memory Read Multiple (MRM) commands. Whether MRM is used or not depends on the value of PCI_CACHE_LINE_SIZE register. I see that the changes are no longer present in linux 2.6.30+ kernels. Although the patch certainly resolved the hang issue with Silicon Image 680 PATA card as the 680 driver attempts to use MRM commands - I don't know if it would resolve the data corruption issue. It is certainly worth trying in my opinion. Below is a link to the patch submission:

Quoted 2 lines

http://git.denx.de/?p=linux-2.6-denx.git;a=commit;h=cffefde924123e685327
48dd58fcb780eab5e219

The changes in the above repository is a quick hack that can't be merged as-is (and afaik hasn't been submitted).

If indeed we need to clamp the PCI cache line size on those critters, then we need something in ppc4xx_pci.c to detect the need, set pci_cache_line_size to 0 and eventually fixup the existing values in devices in case u-boot don't have them right.

Care to send a patch ? :-)

Cheers,
Ben

#25 lore raw
Quoted 17 lines · On Friday 11 September 2009 04:44:34 Benjamin Herrenschmidt wrote:
Quoted 10 lines · Pravin Bathija

There is also a patch that was submitted for 440EPX a couple of years back. The 440EPX SOC causes hangs with Memory Read Multiple (MRM) commands. Whether MRM is used or not depends on the value of PCI_CACHE_LINE_SIZE register. I see that the changes are no longer present in linux 2.6.30+ kernels. Although the patch certainly resolved the hang issue with Silicon Image 680 PATA card as the 680 driver attempts to use MRM commands - I don't know if it would resolve the data corruption issue. It is certainly worth trying in my opinion. Below is a link to the patch submission:

Quoted 2 lines

http://git.denx.de/?p=linux-2.6-denx.git;a=commit;h=cffefde924123e685327
48dd58fcb780eab5e219

The changes in the above repository is a quick hack that can't be merged as-is (and afaik hasn't been submitted).

Quoted 6 lines

If indeed we need to clamp the PCI cache line size on those critters, then we need something in ppc4xx_pci.c to detect the need, set pci_cache_line_size to 0 and eventually fixup the existing values in devices in case u-boot don't have them right.

Care to send a patch ? :-)

It's already there. See commit:

5ce4b59653b2c2053cd9a011918ac1e4747f24cc

powerpc/4xx: Workaround for PPC440EPx/GRx PCI_28 Errata

Cheers,
Stefan

#26 lore raw
Quoted 7 lines · Stefan Roese

It's already there. See commit:

5ce4b59653b2c2053cd9a011918ac1e4747f24cc

powerpc/4xx: Workaround for PPC440EPx/GRx PCI_28 Errata

Ok, that's another way to do it. Will catch nasty drivers who try to write directly rather than clear pci_cache_line_size I suppose...

Cheers,
Ben.

#27 lore raw
Quoted 9 lines · On Friday 11 September 2009 07:17:50 Benjamin Herrenschmidt wrote:
Quoted 5 lines · Stefan Roese

It's already there. See commit:

5ce4b59653b2c2053cd9a011918ac1e4747f24cc

powerpc/4xx: Workaround for PPC440EPx/GRx PCI_28 Errata

Ok, that's another way to do it. Will catch nasty drivers who try to write directly rather than clear pci_cache_line_size I suppose...

Correct. IIRC, some PATA driver as Pravin already mentioned.

Cheers,
Stefan

#28 lore raw
Quoted 5 lines

Stefan Roese wrote:
Correct. IIRC, some PATA driver as Pravin already mentioned.

Cheers,
Stefan

Thanks Stefan. The whole intention of the patch/hack (or whatever one might call it :) ) was to avoid rogue drivers from setting pci_cache_line_size to non-zero value even though the underlying hardware doesn't support MRM calls. Nonetheless this approach works only if the drivers use the kernel API for PCI config space access provided by the powerpc platform driver.

Regards,
Pravin

Quoted 9 lines · On Friday 11 September 2009 07:17:50 Benjamin Herrenschmidt wrote:
Quoted 5 lines · Stefan Roese

It's already there. See commit:

5ce4b59653b2c2053cd9a011918ac1e4747f24cc

powerpc/4xx: Workaround for PPC440EPx/GRx PCI_28 Errata

Ok, that's another way to do it. Will catch nasty drivers who try to write directly rather than clear pci_cache_line_size I suppose...

#29 lore raw
Quoted 7 lines · Pravin Bathija

Thanks Stefan. The whole intention of the patch/hack (or whatever one might call it :) ) was to avoid rogue drivers from setting pci_cache_line_size to non-zero value even though the underlying hardware doesn't support MRM calls. Nonetheless this approach works only if the drivers use the kernel API for PCI config space access provided by the powerpc platform driver.

Do you know many drivers that do config space accesses without using the config space accessors ?

Such drivers should be banned to oblivion.

Cheers,
Ben.

#19 lore raw
In reply to Benjamin Herrenschmidt
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 4 lines · Mikhail Zolotaryov

Hi Tom,

In my case __dma_sync() calls flush_dcache_range() (it's due to alignment) from a tasklet - no OOPS. It uses dcbf instruction instead of dcbi - that's the difference as dcbf is not privileged.

What it calls depends on the direction of the transfer.

Would not agree with you in this point as __dma_sync() code is:

case DMA_FROM_DEVICE:
/*
* invalidate only when cache-line aligned otherwise
there is
* the potential for discarding uncommitted data from
the cache

                */
               if ((start & (L1_CACHE_BYTES - 1)) || (size & 
(L1_CACHE_BYTES - 1)))
                       flush_dcache_range(start, end);
               else
                       invalidate_dcache_range(start, end);
               break;

So, actual instruction used depends on address/size alignment.

Quoted 271 lines

The tasklet runs
in priviledged mode, dcbi should work just fine... if passed a correct address :-)

Cheers,
Ben.

Quoted 261 lines
Quoted 40 lines · Tom Burns

Hi Mikhail,

Sorry, this DMA code is in a tasklet. Are you suggesting the processor is in supervisor mode at that time? Calling pci_dma_sync_sg_for_cpu() from the tasklet context is what generates the OOPS. The entire oops is as follows, if it's relevant:

Oops: kernel access of bad area, sig: 11 [#1]
NIP: c0003ab0 LR: c0010c30 CTR: 02400001
REGS: df117bd0 TRAP: 0300   Tainted: P         (2.6.24.2)
MSR: 00029000 <EE,ME>  CR: 44224042  XER: 20000000
DEAR: 3fd39000, ESR: 00800000

TASK = de5db7d0[157] 'cat' THREAD: df116000
GPR00: e11e5854 df117c80 de5db7d0 3fd39000 02400001 0000001f 00000002 0079a169
GPR08: 00000001 c0310000 00000000 c0010c84 24224042 101c0dac c0310000 10177000
GPR16: deb14200 df116000 e12062d0 e11f6104 de0f16c0 e11f0000 c0310000 e11f59cc
GPR24: e11f62d0 e11f0000 e11f0000 00000000 00000002 defee014 3fd39008 87d39009
NIP [c0003ab0] invalidate_dcache_range+0x1c/0x30
LR [c0010c30] __dma_sync+0x58/0xac

Call Trace:

[df117c80] [0000000a] 0xa (unreliable)
[df117c90] [e11e5854] DoTasklet+0x67c/0xc90 [ideDriverDuo_cyph] [df117ce0] [c001ee24] tasklet_action+0x60/0xcc
[df117cf0] [c001ef04] __do_softirq+0x74/0xe0
[df117d10] [c00067a8] do_softirq+0x54/0x58
[df117d20] [c001edb4] irq_exit+0x48/0x58
[df117d30] [c00069d0] do_IRQ+0x6c/0xc0
[df117d40] [c00020e0] ret_from_except+0x0/0x18
[df117e00] [c00501e0] unmap_vmas+0x2c4/0x560
[df117e90] [c0053ebc] exit_mmap+0x64/0xec
[df117ec0] [c00171ac] mmput+0x50/0xd4
[df117ed0] [c001aef8] exit_mm+0x80/0xe0
[df117ef0] [c001c818] do_exit+0x134/0x6f8
[df117f30] [c001ce14] do_group_exit+0x38/0x74
[df117f40] [c0001a80] ret_from_syscall+0x0/0x3c
Instruction dump:
7c0018ac 38630020 4200fff8 7c0004ac 4e800020 38a0001f 7c632878 7c832050 7c842a14 5484d97f 4d820020 7c8903a6 <7c001bac> 38630020 4200fff8 7c0004ac

Quoted 214 lines
Kernel panic - not syncing: Aiee, killing interrupt handler!

Rebooting in 180 seconds..

Cheers,
Tom

Quoted 204 lines · Mikhail Zolotaryov

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 196 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing
invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 184 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 177 lines · Prodyut Hazarika

Hi Adam,

Quoted 3 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 6 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 5 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 2 lines

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 10 lines · Prodyut Hazarika

Hi Adam,

Quoted 3 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 14 lines
        L2C0: l2c {
              ...
        }
Quoted 8 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 46 lines
Quoted 3 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks

Quoted 8 lines · Benjamin Herrenschmidt
Quoted 5 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 4 lines
Quoted 4 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 7 lines
Quoted 7 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 3 lines
Quoted 3 lines

fixes your issue - this causes the 'M' bit to be set on the page

which

Quoted 3 lines
Quoted 3 lines

sure enforce cache coherency. If it doesn't, you'll need to check

Quoted 18 lines

the

Quoted 3 lines
Quoted 3 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 11 lines
Quoted 8 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 27 lines
Quoted 5 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 5 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 11 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#20 lore raw
Quoted 5 lines · Mikhail Zolotaryov
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 2 lines · Mikhail Zolotaryov

Hi Tom,

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

In my case __dma_sync() calls flush_dcache_range() (it's due to alignment) from a tasklet - no OOPS. It uses dcbf instruction instead of dcbi - that's the difference as dcbf is not privileged.

What it calls depends on the direction of the transfer.

Would not agree with you in this point as __dma_sync() code is:

Well, it -does- depend on the direction of the transfer... and -also- on the size & alignement :-)

Anyway, that is probably not the problem. From the log I've seen, it just looks like a page fault due to a bad virtual address passed there.

Cheers,
Ben.

Quoted 312 lines

case DMA_FROM_DEVICE:
/*
* invalidate only when cache-line aligned otherwise
there is
* the potential for discarding uncommitted data from
the cache

                 */
                if ((start & (L1_CACHE_BYTES - 1)) || (size & 
(L1_CACHE_BYTES - 1)))
                        flush_dcache_range(start, end);
                else
                        invalidate_dcache_range(start, end);
                break;

So, actual instruction used depends on address/size alignment.

Quoted 296 lines

The tasklet runs
in priviledged mode, dcbi should work just fine... if passed a correct address :-)

Cheers,
Ben.

Quoted 286 lines
Quoted 43 lines · Tom Burns

Hi Mikhail,

Sorry, this DMA code is in a tasklet. Are you suggesting the processor is in supervisor mode at that time? Calling pci_dma_sync_sg_for_cpu() from the tasklet context is what generates the OOPS. The entire oops is as follows, if it's relevant:

Oops: kernel access of bad area, sig: 11 [#1]
NIP: c0003ab0 LR: c0010c30 CTR: 02400001
REGS: df117bd0 TRAP: 0300   Tainted: P         (2.6.24.2)
MSR: 00029000 <EE,ME>  CR: 44224042  XER: 20000000
DEAR: 3fd39000, ESR: 00800000

TASK = de5db7d0[157] 'cat' THREAD: df116000
GPR00: e11e5854 df117c80 de5db7d0 3fd39000 02400001 0000001f 00000002 0079a169
GPR08: 00000001 c0310000 00000000 c0010c84 24224042 101c0dac c0310000 10177000
GPR16: deb14200 df116000 e12062d0 e11f6104 de0f16c0 e11f0000 c0310000 e11f59cc
GPR24: e11f62d0 e11f0000 e11f0000 00000000 00000002 defee014 3fd39008 87d39009
NIP [c0003ab0] invalidate_dcache_range+0x1c/0x30
LR [c0010c30] __dma_sync+0x58/0xac

Call Trace:

[df117c80] [0000000a] 0xa (unreliable)
[df117c90] [e11e5854] DoTasklet+0x67c/0xc90 [ideDriverDuo_cyph] [df117ce0] [c001ee24] tasklet_action+0x60/0xcc
[df117cf0] [c001ef04] __do_softirq+0x74/0xe0
[df117d10] [c00067a8] do_softirq+0x54/0x58
[df117d20] [c001edb4] irq_exit+0x48/0x58
[df117d30] [c00069d0] do_IRQ+0x6c/0xc0
[df117d40] [c00020e0] ret_from_except+0x0/0x18
[df117e00] [c00501e0] unmap_vmas+0x2c4/0x560
[df117e90] [c0053ebc] exit_mmap+0x64/0xec
[df117ec0] [c00171ac] mmput+0x50/0xd4
[df117ed0] [c001aef8] exit_mm+0x80/0xe0
[df117ef0] [c001c818] do_exit+0x134/0x6f8
[df117f30] [c001ce14] do_group_exit+0x38/0x74
[df117f40] [c0001a80] ret_from_syscall+0x0/0x3c
Instruction dump:
7c0018ac 38630020 4200fff8 7c0004ac 4e800020 38a0001f 7c632878 7c832050 7c842a14 5484d97f 4d820020 7c8903a6 <7c001bac> 38630020 4200fff8 7c0004ac

Quoted 236 lines
Kernel panic - not syncing: Aiee, killing interrupt handler!

Rebooting in 180 seconds..

Cheers,
Tom

Quoted 226 lines · Mikhail Zolotaryov

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 217 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 200 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 191 lines · Prodyut Hazarika

Hi Adam,

Quoted 4 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 8 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing)
end up being partially corrupted when we try to parse the data in the
virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 6 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte
cache lines) is overwritten with old data from the last time the

buffer

Quoted 2 lines

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has
the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on
how to do it.

Thanks
Prodyut

Quoted 10 lines · Prodyut Hazarika

Hi Adam,

Quoted 3 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 9 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx
has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C.
For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 15 lines
        L2C0: l2c {
              ...
        }
Quoted 9 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 51 lines
Quoted 6 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should
work too

Thanks
Prodyut On Thu, 2009-09-03 at 19:57 +1000, Benjamin

Quoted 8 lines · Herrenschmidt
Quoted 5 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 4 lines
Quoted 4 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 7 lines
Quoted 7 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 3 lines
Quoted 3 lines

fixes your issue - this causes the 'M' bit to be set on the page

which

Quoted 3 lines
Quoted 3 lines

sure enforce cache coherency. If it doesn't, you'll need to check

Quoted 18 lines

the

Quoted 3 lines
Quoted 3 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 11 lines
Quoted 8 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 27 lines
Quoted 5 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 5 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 11 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#30 lore raw
In reply to Benjamin Herrenschmidt
Quoted 7 lines · Benjamin Herrenschmidt

Do you know many drivers that do config space accesses without using the config space accessors ?

Such drivers should be banned to oblivion.

Cheers,
Ben.

I'm not aware of such drivers in the 2.6.30+ kernel.

Thanks,
Pravin

Quoted 7 lines · Pravin Bathija

Thanks Stefan. The whole intention of the patch/hack (or whatever one might call it :) ) was to avoid rogue drivers from setting pci_cache_line_size to non-zero value even though the underlying hardware doesn't support MRM calls. Nonetheless this approach works only if the drivers use the kernel API for PCI config space access provided by the powerpc platform driver.

#34 lore raw
In reply to Benjamin Herrenschmidt

Hi Ben,

Quoted 4 lines · Benjamin Herrenschmidt
Quoted 2 lines · Tom Burns

Hi,

Quoted 9 lines
Quoted 3 lines

With the default config for the Sequoia board on 2.6.24, calling pci_dma_sync_sg_for_cpu() results in executing
invalidate_dcache_range() in arch/ppc/kernel/misc.S from __dma_sync(). This OOPses on PPC440 since it tries to call directly the assembly instruction dcbi, which can only be executed in supervisor mode. We tried that before resorting to manual cache line management with usermode-safe assembly calls.

Wait a minute.... usermode ? You are doing all of that from userspace ? I don't understand the story here. You can't call all those kernel APIs form userspace in the first place, indeed... But then an IDE driver has nothing to do in userspace neither.

Sorry, I was referring to whether or not the CPU is in supervisor mode. Our code is all in the kernel, not userspace :). I can see now from the value of MSR at the time of the OOPS that the processor was in supervisor mode, I missed that earlier. Looks like you're right about the bad address, I will investigate.

Thanks,
Tom

Quoted 205 lines

Cheers,
Ben.

Quoted 197 lines

Regards,
Tom Burns
International Datacasting Corporation

Quoted 186 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of __dma_sync / dma_sync_single_for_device of DMA API ? (implies CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 179 lines · Prodyut Hazarika

Hi Adam,

Quoted 3 lines

Yes, I am using the 440EPx (same as the sequoia board). Our ideDriver is DMA'ing blocks of 192-byte data over the PCI bus

(using

Quoted 6 lines

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on timing) end up being partially corrupted when we try to parse the data in the virtual page. We have confirmed the data is good before the PCI-IDE bridge. We are creating two 8K pages and map them to physical DMA

memory

Quoted 5 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of 16byte cache lines) is overwritten with old data from the last time the

buffer

Quoted 2 lines

was used.

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region has the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines appropriately, since in 440 cores,
L1Cache coherency is managed entirely by software.
Please look at drivers/net/ibm_newemac/mal.c and core.c for example on how to do it.

Thanks
Prodyut

Quoted 10 lines · Prodyut Hazarika

Hi Adam,

Quoted 3 lines

Are you sure there is L2 cache on the 440?

It depends on the SoC you are using. SoC like 460EX (Canyonlands

board)

Quoted 7 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC. 440EPx has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is L2C. For example, in canyonlands.dts (460EX based board), we have the L2C entry.

Quoted 14 lines
        L2C0: l2c {
              ...
        }
Quoted 8 lines

I am seeing this problem with our custom IDE driver which is based on

pretty old code. Our driver uses pci_alloc_consistent() to allocate

the

Quoted 48 lines
Quoted 3 lines

physical DMA memory and alloc_pages() to allocate a virtual page. It then uses pci_map_sg() to map to a scatter/gather buffer. Perhaps I should convert these to the DMA API calls as you suggest.

Could you give more details on the consistency problem? It is a good idea to change to the new DMA APIs, but pci_alloc_consistent() should work too

Thanks
Prodyut

Quoted 8 lines · Benjamin Herrenschmidt
Quoted 5 lines · Chris Pringle

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the following

section:

Quoted 4 lines
Quoted 4 lines

#ifdef CONFIG_44x
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED |

_PAGE_GUARDED)

Quoted 7 lines
Quoted 7 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see if

that

Quoted 3 lines
Quoted 3 lines

fixes your issue - this causes the 'M' bit to be set on the page

which

Quoted 3 lines
Quoted 3 lines

sure enforce cache coherency. If it doesn't, you'll need to check

Quoted 18 lines

the

Quoted 3 lines
Quoted 3 lines

'M' bit isn't being masked out in head_44x.S (it was originally

masked

Quoted 11 lines
Quoted 8 lines

out on arch/powerpc, but was fixed in later kernels when the cache

coherency issues with non-SMP systems were resolved).

I have some doubts about the usefulness of doing that for 4xx.

AFAIK,

Quoted 27 lines
Quoted 5 lines

the 440 core just ignores M.

The problem lies probably elsewhere. Maybe the L2 cache coherency

isn't

Quoted 5 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to make

sure

Quoted 11 lines

they use the appropriate DMA APIs which will do cache flushing when needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#32 lore raw
In reply to Tom Burns
Quoted 4 lines

I tried, using our JTAG debugger (BDI3000), to pause operation after=20 calling dma_alloc_coherent to examine the TLB entry for the memory=20 returned by the call (which was just past=20 CONFIG_CONSISTENT_START=3D0xff100000). The TLB list loaded at the =

time=20

Quoted 9 lines

that I paused operation did not show a mapping for this area. I guess

the kernel swaps TLB entries on the fly so it isn't limited to only 64

entries? I will try to sleep in the same context as the=20 dma_alloc_coherent call to try to catch the TLB entry while loaded to=20 see if it has the I bit set.

If that fails, any ideas?

Sleeping won't cause the entry to appear at the TLB.
After the dma_alloc call, try to deference the pointer returned. As a result of the dereference, a DataTLB Miss will happen which will result in
the appropriate entry put in TLB.
Then do a JTAG break right after the dereference, and you should be able to see the TLB entry.

Thanks
Prodyut

Quoted 39 lines · Mikhail Zolotaryov

Hi Tom,

possible solution could be to use tasklet to perform DMA-related job=20 (as in most cases DMA transfer is interrupt driven - makes sense).

Quoted 32 lines · Tom Burns

Hi,

With the default config for the Sequoia board on 2.6.24, calling=20 pci_dma_sync_sg_for_cpu() results in executing invalidate_dcache_range() in arch/ppc/kernel/misc.S from=20 __dma_sync(). This OOPses on PPC440 since it tries to call directly=20 the assembly instruction dcbi, which can only be executed in=20 supervisor mode. We tried that before resorting to manual cache line

management with usermode-safe assembly calls.

Regards,
Tom Burns
International Datacasting Corporation

Quoted 16 lines · Mikhail Zolotaryov

Hi,

Why manage cache lines manually, if appropriate code is a part of=20 __dma_sync / dma_sync_single_for_device of DMA API ? (implies=20 CONFIG_NOT_COHERENT_CACHE enabled, as default for Sequoia Board)

Quoted 9 lines · Prodyut Hazarika

Hi Adam,

=20

Quoted 3 lines

Yes, I am using the 440EPx (same as the sequoia board). Our=20 ideDriver is DMA'ing blocks of 192-byte data over the PCI bus
=20

(using
=20

Quoted 1 line

the Sil0680A PCI-IDE bridge). Most of the DMA's (depending on

timing)

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

end up being partially corrupted when we try to parse the data in

the

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

virtual page. We have confirmed the data is good before the

PCI-IDE

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

bridge. We are creating two 8K pages and map them to physical DMA
=20

memory
=20

Quoted 2 lines

using single-entry scatter/gather structs. When a DMA block is corrupted, we see a random portion of it (always a multiple of

16byte

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

cache lines) is overwritten with old data from the last time the
=20

buffer
=20

Quoted 1 line

was used. =20

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

This looks like a cache coherency problem.
Can you ensure that the TLB entries corresponding to the DMA region

has
the CacheInhibit bit set.
You will need a BDI connected to your system.

Also, you will need to invalidate and flush the lines

appropriately,

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

since in 440 cores,
L1Cache coherency is managed entirely by software. Please look at drivers/net/ibm_newemac/mal.c and core.c for example

on

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

how to do it.

Thanks
Prodyut

On Thu, 2009-09-03 at 13:27 -0700, Prodyut Hazarika wrote:
=20

Quoted 7 lines

Hi Adam,

=20

Quoted 2 lines

Are you sure there is L2 cache on the 440?

     =20

It depends on the SoC you are using. SoC like 460EX (Canyonlands
=20

board)
=20

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

have L2Cache.
It seems you are using a Sequoia board, which has a 440EPx SoC.=20 440EPx
has a 440 cpu core, but no L2Cache.
Could you please tell me which SoC you are using?
You can also refer to the appropriate dts file to see if there is=20 L2C.
For example, in canyonlands.dts (460EX based board), we have the

L2C

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

entry.

        L2C0: l2c {
              ...
        }
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

=20

Quoted 3 lines

I am seeing this problem with our custom IDE driver which is=20 based on

     =20

=20

Quoted 1 line
Quoted 1 line

pretty old code. Our driver uses pci_alloc_consistent() to

allocate

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
     =20

the
=20

Quoted 4 lines
Quoted 4 lines

physical DMA memory and alloc_pages() to allocate a virtual page.

It then uses pci_map_sg() to map to a scatter/gather buffer.=20 Perhaps I should convert these to the DMA API calls as you

suggest.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
     =20

Could you give more details on the consistency problem? It is a

good

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

idea to change to the new DMA APIs, but pci_alloc_consistent()

should

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

work too

Thanks
Prodyut On Thu, 2009-09-03 at 19:57 +1000, Benjamin Herrenschmidt

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

wrote:
=20

Quoted 5 lines · Chris Pringle

=20

Quoted 3 lines

Hi Adam,

If you have a look in include/asm-ppc/pgtable.h for the

following

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
       =20

section:
=20

Quoted 3 lines
Quoted 3 lines

#ifdef CONFIG_44x

#define _PAGE_BASE    (_PAGE_PRESENT | _PAGE_ACCESSED |
       =20
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

_PAGE_GUARDED)
=20

Quoted 5 lines
Quoted 5 lines

#else
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
#endif

Try adding _PAGE_COHERENT to the appropriate line above and see

if

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
       =20

that =20

Quoted 2 lines
Quoted 2 lines

fixes your issue - this causes the 'M' bit to be set on the page

       =20

which =20

Quoted 1 line
Quoted 1 line

sure enforce cache coherency. If it doesn't, you'll need to

check

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
       =20

the =20

Quoted 2 lines
Quoted 2 lines

'M' bit isn't being masked out in head_44x.S (it was originally

       =20

masked =20

Quoted 1 line
Quoted 1 line

out on arch/powerpc, but was fixed in later kernels when the

cache

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
       =20

=20

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

coherency issues with non-SMP systems were resolved).

       =20

I have some doubts about the usefulness of doing that for 4xx.

     =20

AFAIK,
=20

Quoted 2 lines
Quoted 2 lines

the 440 core just ignores M.

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

The problem lies probably elsewhere. Maybe the L2 cache coherency

     =20

isn't
=20

Quoted 3 lines

enabled or not working ?

The L1 cache on 440 is simply not coherent, so drivers have to

make

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
     =20

sure
=20

Quoted 1 line

they use the appropriate DMA APIs which will do cache flushing

when

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

needed.

Adam, what driver is causing you that sort of problems ?

Cheers,
Ben.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
     =20

--------------------------------------------------------

CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, = is for the sole use of the intended recipient(s) and contains = information that is confidential and proprietary to AppliedMicro = Corporation or its subsidiaries. It is to be used solely for the purpose = of furthering the parties' business relationship. All unauthorized = review, use, disclosure or distribution is prohibited. If you are not = the intended recipient, please contact the sender by reply e-mail and = destroy all copies of the original message.