kernel 2.6.15: cpm_uart driver broken?
Hi all,
Situation 1: MPC852T with SMC1 as uart/console, and SCC3/SCC4 as additional uarts. SMC1 works fine, but SCC3/4 don't. On transmission attempt, both UARTS transmit a byte 0x00 instead of what was intended to be transmitted.\
Situation 2: The same as above, but console on either SCC3 or SCC4. The uart being initialized as console works ok, the other two don't.
I'm pretty sure the following is wrong, but I can't seem to fix it either. This seems to apply for both PQ and PQ2 type uarts:
from drivers/serial/cpm_uart/cpm_uart_cpm1.c (line 190):
....
if (is_con) {
/* was hostalloc but changed cause it blows away the */
/* large tlb mapping when pinning the kernel area */
mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
dma_addr = 0;
} else
mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
GFP_KERNEL);....
pinfo->dp_addr = dp_offset; pinfo->mem_addr = mem_addr; pinfo->dma_addr = dma_addr; pinfo->rx_buf = mem_addr;
....
AFAICS pinfo->rx_buf is the pointer to a buffer as seen from the CPM's point of view, so it should hold a physical adress, not a virtual address. It seems to me that it should be more like this (lines marked with ** are changed):
....
if (is_con) {
/* was hostalloc but changed cause it blows away the */
/* large tlb mapping when pinning the kernel area */
mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
** dma_addr = mem_addr;
} else
mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
GFP_KERNEL);....
pinfo->dp_addr = dp_offset; pinfo->mem_addr = mem_addr; pinfo->dma_addr = dma_addr;
** pinfo->rx_buf = dma_addr;
....
This does not work either, but I suspect this is a different problem, because if I change dma_alloc_coherent() for something using kmalloc() and then dma_addr=virt_to_phys(mem_addr), uarts begin to work, but trasmit mixed old and new data from the buffers due to the cache getting in the way. At least reception seems to work ok then.
So, why doesn't dma_alloc_coherent() work the way one would expect? Obviously, changing "if (is_con)" into "if (1)" all three uarts work correctly, but I guess we want to save on DP_RAM usage if ever possible.
What else is wrong here?
Greetings,
Signature · 1 line
David Jander
Quoted 10 lines · On Tue, 18 Apr 2006 14:46:08 +0200 David Jander <[email protected]>…
Hi all,
Situation 1: MPC852T with SMC1 as uart/console, and SCC3/SCC4 as additional uarts. SMC1 works fine, but SCC3/4 don't. On transmission attempt, both UARTS transmit a byte
0x00instead of what was intended to be transmitted.\Situation 2: The same as above, but console on either SCC3 or SCC4. The uart being initialized as console works ok, the other two don't.
Well, existing code works just fine on 885ads and 866ads, that use SMC1 and SMC2 as UARTs.
Quoted 3 lines
I'm pretty sure the following is wrong, but I can't seem to fix it either. This seems to apply for both PQ and PQ2 type uarts:
fromdrivers/serial/cpm_uart/cpm_uart_cpm1.c(line 190):
That's wrong - cpm_uart_cpm1.c applies to PQ only...
Quoted 51 lines
....
if (is_con) { /* was hostalloc but changed cause it blows away the */ /* large tlb mapping when pinning the kernel area */ mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8)); dma_addr = 0; } else mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr, GFP_KERNEL);....
pinfo->dp_addr = dp_offset; pinfo->mem_addr = mem_addr; pinfo->dma_addr = dma_addr; pinfo->rx_buf = mem_addr;....
AFAICS
pinfo->rx_bufis the pointer to a buffer as seen from the CPM's point of view, so it should hold a physical adress, not a virtual address. It seems to me that it should be more like this (lines marked with ** are changed):....
if (is_con) { /* was hostalloc but changed cause it blows away the */ /* large tlb mapping when pinning the kernel area */ mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8)); ** dma_addr = mem_addr; } else mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr, GFP_KERNEL);....
pinfo->dp_addr = dp_offset; pinfo->mem_addr = mem_addr; pinfo->dma_addr = dma_addr;**
pinfo->rx_buf=dma_addr;
....This does not work either, but I suspect this is a different problem, because if I change
dma_alloc_coherent()for something usingkmalloc()and then dma_addr=virt_to_phys(mem_addr), uarts begin to work, but trasmit mixed old and new data from the buffers due to the cache getting in the way. At least reception seems to work ok then.
So, why doesn'tdma_alloc_coherent()work the way one would expect? Obviously, changing "if (is_con)" into "if (1)" all three uarts work correctly, but I guess we want to save onDP_RAMusage if ever possible.
Quoted 2 lines
What else is wrong here?
Well, since it works on other boards, and kmalloc stuff seems to sorta work as well, then I guess reason is screwed DMA thing for your board. Check/alter CONFIG_CONSISTENT_* things and see if it will help.
And, try to just replace dma_alloc_.. with kmalloc (not changing rx_buf etc.) and reproduce the same behavior you had. BTW, rx_buf and tx_buf are never used actually in the code, hereby there is no difference what values they contain...
Signature · 2 lines
Sincerely, Vitaly
Quoted 3 lines · Vitaly Bordug
[..]
Well, existing code works just fine on 885ads and 866ads, that use SMC1 and SMC2 as UARTs.
Interesting.
Quoted 5 lines
Quoted 3 lines
I'm pretty sure the following is wrong, but I can't seem to fix it either. This seems to apply for both PQ and PQ2 type uarts:
fromdrivers/serial/cpm_uart/cpm_uart_cpm1.c(line 190):That's wrong -
cpm_uart_cpm1.capplies to PQ only...
I know. cpm_uart_cpm2.c contains the same code, so it should be as broken as the cpm_uart_cpm1.c.
Quoted 4 lines
[...]
Well, since it works on other boards, and kmalloc stuff seems to sorta work as well, then I guess reason is screwed DMA thing for your board. Check/alter CONFIG_CONSISTENT_* things and see if it will help.
I did not touch de defaults. What are the rules to change them? What do I have to look out for?CONFIG_CONSISTENT_START = 0xff100000 and I suspect a problem here if I was using MTD (currently disabled) since flash is at physical adress 0xfe000000-0xffffffff on my board. Isn't MTD going to io_remap that area to that same virtual adress? How's that supposed to work then?
I changed CONFIG_CONSISTENT_START to 0xfd100000 and now the system freezes when I write to the serial port :-(
Quoted 4 lines
And, try to just replace
dma_alloc_.. with kmalloc (not changingrx_bufetc.) and reproduce the same behavior you had. BTW,rx_bufandtx_bufare never used actually in the code, hereby there is no difference what values they contain...
Argh. Code looks obviously broken, but since it isn't used, it just works. That is not good! We should fix that either way then.
Thanks,
Signature · 1 line
David Jander
Quoted 7 lines · On Tue, 18 Apr 2006 16:05:40 +0200 David Jander <[email protected]>…
Quoted 3 lines · Vitaly Bordug
[..]
Well, existing code works just fine on 885ads and 866ads, that use SMC1 and SMC2 as UARTs.Interesting.
And for PQ2 I can add 8260 , PQ2fads and 8272ads that had no issues with current driver
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
I'm pretty sure the following is wrong, but I can't seem to fix it either. This seems to apply for both PQ and PQ2 type uarts:
fromdrivers/serial/cpm_uart/cpm_uart_cpm1.c(line 190):That's wrong -
cpm_uart_cpm1.capplies to PQ only...I know.
cpm_uart_cpm2.ccontains the same code, so it should be as broken as thecpm_uart_cpm1.c.
pq2 are cache-coherent, so there are no such troubles in there. And allocation routine is different of course.
Quoted 6 lines
Quoted 5 lines
[...]
Well, since it works on other boards, and kmalloc stuff seems to sorta work as well, then I guess reason is screwed DMA thing for your board. Check/alter CONFIG_CONSISTENT_* things and see if it will help.
Quoted 9 lines
I did not touch de defaults. What are the rules to change them? What do I have to look out for?
CONFIG_CONSISTENT_START=0xff100000and I suspect a problem here if I was using MTD (currently disabled) since flash is at physical adress 0xfe000000-0xffffffff on my board. Isn't MTD going toio_remapthat area to that same virtual adress? How's that supposed to work then?
I changedCONFIG_CONSISTENT_STARTto0xfd100000and now the system freezes when I write to the serial port :-(
Unfortunately, I know nothing where the correct thing should be pulled from... But the problem lies in dma stuff from what I can say.
Quoted 7 lines
Quoted 4 lines
And, try to just replace
dma_alloc_.. with kmalloc (not changingrx_bufetc.) and reproduce the same behavior you had. BTW,rx_bufandtx_bufare never used actually in the code, hereby there is no difference what values they contain...Argh. Code looks obviously broken, but since it isn't used, it just works. That is not good! We should fix that either way then.
The overhaul is on the way, I'll put the cleanup of the unused stuff together with other changes.
Signature · 2 lines
Sincerely, Vitaly