firewire: fw-ohci: use dma_alloc_coherent for ar_buffer
PATCH 1/1 firewire: fw-ohci: use dma_alloc_coherent for ar_buffer
Currently, we do nothing to guarantee we have a consistent DMA buffer for asynchronous receive packets. Rather than doing several sync's following a dma_map_single() to get consistent buffers, just switch to using dma_alloc_coherent().
Resolves constant buffer failures on my own x86_64 laptop w/4GB of RAM and likely to fix a number of other failures witnessed on x86_64 systems with 4GB of RAM or more.
---
drivers/firewire/fw-ohci.c | 18 +++++------------- 1 files changed, 5 insertions(+), 13 deletions(-)
drivers/firewire/fw-ohci.c +5 -13
@@ -284,16 +284,10 @@ static int ar_context_add_page(struct ar_context *ctx)dma_addr_t ab_bus;size_t offset; - ab = (struct ar_buffer *)__get_free_page (GFP_ATOMIC ); + ab =dma_alloc_coherent (dev,PAGE_SIZE , &ab_bus,GFP_ATOMIC );if (ab ==NULL )return -ENOMEM ; - ab_bus =dma_map_single (dev, ab,PAGE_SIZE ,DMA_BIDIRECTIONAL ); -if (dma_mapping_error (ab_bus)) { -free_page ((unsigned long ) ab); -return -ENOMEM ; - } -memset (&ab->descriptor,0 ,sizeof (ab->descriptor)); ab->descriptor.control = cpu_to_le16(DESCRIPTOR_INPUT_MORE | DESCRIPTOR_STATUS |
@@ -304,8 +298,6 @@ static int ar_context_add_page(struct ar_context *ctx) ab->descriptor.res_count =cpu_to_le16 (PAGE_SIZE - offset); ab->descriptor.branch_address =0 ; -dma_sync_single_for_device (dev, ab_bus,PAGE_SIZE ,DMA_BIDIRECTIONAL ); - ctx->last_buffer->descriptor.branch_address =cpu_to_le32 (ab_bus |1 ); ctx->last_buffer->next = ab; ctx->last_buffer = ab;
@@ -409,6 +401,7 @@ static void ar_context_tasklet(unsigned long data)if (d->res_count ==0 ) {size_t size, rest, offset; +dma_addr_t buffer_bus;/* * This descriptor is finished and we may have a
@@ -417,9 +410,7 @@ static void ar_context_tasklet(unsigned long data)*/ offset = offsetof(struct ar_buffer , data); -dma_unmap_single (ohci->card.device, -le32_to_cpu (ab->descriptor.data_address) - offset, -PAGE_SIZE ,DMA_BIDIRECTIONAL ); + buffer_bus =le32_to_cpu (ab->descriptor.data_address) - offset; buffer = ab; ab = ab->next;
@@ -435,7 +426,8 @@ static void ar_context_tasklet(unsigned long data)while (buffer < end) buffer =handle_ar_packet (ctx, buffer); -free_page ((unsigned long )buffer); +dma_free_coherent (ohci->card.device,PAGE_SIZE , + buffer, buffer_bus);ar_context_add_page (ctx); }else { buffer = ctx->pointer;
Signature · 2 lines
Jarod Wilson [email protected]
Quoted 10 lines · Jarod Wilson
Currently, we do nothing to guarantee we have a consistent DMA buffer for asynchronous receive packets. Rather than doing several sync's following a
dma_map_single()to get consistent buffers, just switch to usingdma_alloc_coherent().Resolves constant buffer failures on my own
x86_64laptop w/4GB of RAM and likely to fix a number of other failures witnessed onx86_64systems with 4GB of RAM or more.Signed-off-by Jarod Wilson <[email protected]>
Looks good at first glance. Alas my PCs aren't affected, so I can only test it for lack of regressions.
I'm tempted to push this to Linus later this week. Unless e.g. Kristian has reservations.
Quoted 67 lines
---
drivers/firewire/fw-ohci.c | 18 +++++------------- 1 files changed, 5 insertions(+), 13 deletions(-)drivers/firewire/fw-ohci.c +5
-13@@ -284,16 +284,10 @@ static int ar_context_add_page(struct ar_context *ctx)dma_addr_t ab_bus;size_t offset; - ab = (struct ar_buffer *)__get_free_page (GFP_ATOMIC ); + ab =dma_alloc_coherent (dev,PAGE_SIZE , &ab_bus,GFP_ATOMIC );if (ab ==NULL )return -ENOMEM ; - ab_bus =dma_map_single (dev, ab,PAGE_SIZE ,DMA_BIDIRECTIONAL ); -if (dma_mapping_error (ab_bus)) { -free_page ((unsigned long ) ab); -return -ENOMEM ; - } -memset (&ab->descriptor,0 ,sizeof (ab->descriptor)); ab->descriptor.control = cpu_to_le16(DESCRIPTOR_INPUT_MORE | DESCRIPTOR_STATUS |@@ -304,8 +298,6 @@ static int ar_context_add_page(struct ar_context *ctx) ab->descriptor.res_count =cpu_to_le16 (PAGE_SIZE - offset); ab->descriptor.branch_address =0 ; -dma_sync_single_for_device (dev, ab_bus,PAGE_SIZE ,DMA_BIDIRECTIONAL ); - ctx->last_buffer->descriptor.branch_address =cpu_to_le32 (ab_bus |1 ); ctx->last_buffer->next = ab; ctx->last_buffer = ab;@@ -409,6 +401,7 @@ static void ar_context_tasklet(unsigned long data)if (d->res_count ==0 ) {size_t size, rest, offset; +dma_addr_t buffer_bus;/* * This descriptor is finished and we may have a @@ -417,9 +410,7 @@ static void ar_context_tasklet(unsigned long data)*/ offset = offsetof(struct ar_buffer , data); -dma_unmap_single (ohci->card.device, -le32_to_cpu (ab->descriptor.data_address) - offset, -PAGE_SIZE ,DMA_BIDIRECTIONAL ); + buffer_bus =le32_to_cpu (ab->descriptor.data_address) - offset; buffer = ab; ab = ab->next;@@ -435,7 +426,8 @@ static void ar_context_tasklet(unsigned long data)while (buffer < end) buffer =handle_ar_packet (ctx, buffer); -free_page ((unsigned long )buffer); +dma_free_coherent (ohci->card.device,PAGE_SIZE , + buffer, buffer_bus);ar_context_add_page (ctx); }else { buffer = ctx->pointer;
Signature · 3 lines
Stefan Richter -=====-==--- --== -==-= http://arcgraph.de/sr/
PATCH 1/1 firewire: fw-ohci: shut up false compiler warning on PPC32
Shut up "may be used uninitialised in this function" warnings due to PPC32's implementation of dma_alloc_coherent().
---
updated to be enqueued after patch
"firewire: fw-ohci: use dma_alloc_coherent for ar_buffer"
drivers/firewire/fw-ohci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/firewire/fw-ohci.c +3 -3
@@ -281,7 +281,7 @@ static int ar_context_add_page(struct ar {struct device *dev = ctx->ohci->card.device;struct ar_buffer *ab; -dma_addr_t ab_bus; +dma_addr_t uninitialized_var (ab_bus );size_t offset; ab =dma_alloc_coherent (dev,PAGE_SIZE , &ab_bus,GFP_ATOMIC );
@@ -536,7 +536,7 @@ static int context_add_buffer(struct context *ctx) {struct descriptor_buffer *desc; -dma_addr_t bus_addr; +dma_addr_t uninitialized_var (bus_addr );int offset;/*
@@ -1321,7 +1321,7 @@ ohci_set_config_rom(struct fw_card *cardunsigned long flags;int retval = -EBUSY ;__be32 *next_config_rom; -dma_addr_t next_config_rom_bus; +dma_addr_t uninitialized_var (next_config_rom_bus ); ohci =fw_ohci (card);
Signature · 3 lines
Stefan Richter -=====-==--- --== -===- http://arcgraph.de/sr/
Re: [PATCH update] firewire: fw-ohci: shut up false compiler warning on PPC32
Quoted 8 lines · Stefan Richter
Shut up "may be used uninitialised in this function" warnings due to PPC32's implementation of
dma_alloc_coherent().Signed-off-by Stefan Richter <[email protected]>---
updated to be enqueued after patch
"firewire: fw-ohci: usedma_alloc_coherentforar_buffer"
Signature · 2 lines
Jarod Wilson [email protected]
Quoted 11 lines · I wrote:
Quoted 5 lines · Jarod Wilson
Resolves constant buffer failures on my own
x86_64laptop w/4GB of RAM and likely to fix a number of other failures witnessed onx86_64systems with 4GB of RAM or more.Signed-off-by Jarod Wilson <[email protected]>Looks good at first glance. Alas my PCs aren't affected, so I can only test it for lack of regressions.
I'm tempted to push this to Linus later this week.
I tested it on a 2GB EM64T machine, on PPC32, and i686. I used the latter for stress-tests with SBP-2, DV, and IIDC traffic on two buses with 3 devices each, all active at once.
I had one lock-up during the stress-tests which I suspect is the handle_at_packet panic, http://bugzilla.kernel.org/show_bug.cgi?id=9617
which is unrelated to this patch.
I committed your patch to linux1394-2.6.git, whose shortlog and diff from origin..for-linus looks now like this:
Jarod Wilson (2):
firewire: fw-sbp2: set single-phase retry_limit
firewire: fw-ohci: use dma_alloc_coherent for ar_buffer
Stefan Richter (9):
firewire: endianess fix
firewire: endianess annotations
firewire: fw-ohci: PPC PMac platform code
firewire: fw-ohci: Apple UniNorth 1st generation support
firewire: warn on fatal condition in topology code
firewire: update Kconfig help text
firewire: fw-sbp2: fix for SYM13FW500 bridge (Datafab disk)
ieee1394: sbp2: fix for SYM13FW500 bridge (Datafab disk)
firewire: fw-ohci: shut up false compiler warning on PPC32
drivers/firewire/Kconfig | 50 +++++-------- drivers/firewire/fw-ohci.c | 108 +++++++++++++++++++++------- drivers/firewire/fw-sbp2.c | 36 +++++++++- drivers/firewire/fw-topology.c | 3 +- drivers/firewire/fw-transaction.c | 2 +- drivers/firewire/fw-transaction.h | 6 +- drivers/ieee1394/sbp2.c | 5 ++ 7 files changed, 143 insertions(+), 67 deletions(-)
I'd like to submit this to Linus later today (Friday). It all looks like a bit too much for such a late -rc phase; but half of fw-ohci's diffstat is actually just the added PMac code which has already proven itself in ohci1394.
There are also some small new commits to linux1394-2.6.git master, whose history is once again somewhat obfuscated by my pulling 'origin' and 'for-linus' into master, so that vice versa master can be cleanly pulled into descendants of Linus' tree.
http://me.in-berlin.de/~s5r6/linux1394/updates/2.6.25-rc5/patches/series
gives a better picture of what is currently in the pipeline than git log would give.
Signature · 3 lines
Stefan Richter -=====-==--- --== -===- http://arcgraph.de/sr/