2007-05-08 08:33:32 +08:00
|
|
|
/*
|
2009-01-04 23:23:29 +08:00
|
|
|
* Isochronous I/O functionality:
|
|
|
|
* - Isochronous DMA context management
|
|
|
|
* - Isochronous bus resource management (channels, bandwidth), client side
|
2006-12-20 08:58:27 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Kristian Hoegsberg <krh@bitplanet.net>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/dma-mapping.h>
|
2009-01-04 23:23:29 +08:00
|
|
|
#include <linux/errno.h>
|
firewire: reorganize header files
The three header files of firewire-core, i.e.
"drivers/firewire/fw-device.h",
"drivers/firewire/fw-topology.h",
"drivers/firewire/fw-transaction.h",
are replaced by
"drivers/firewire/core.h",
"include/linux/firewire.h".
The latter includes everything which a firewire high-level driver (like
firewire-sbp2) needs besides linux/firewire-constants.h, while core.h
contains the rest which is needed by firewire-core itself and by low-
level drivers (card drivers) like firewire-ohci.
High-level drivers can now also reside outside of drivers/firewire
without having to add drivers/firewire to the header file search path in
makefiles. At least the firedtv driver will be such a driver.
I also considered to spread the contents of core.h over several files,
one for each .c file where the respective implementation resides. But
it turned out that most core .c files will end up including most of the
core .h files. Also, the combined core.h isn't unreasonably big, and it
will lose more of its contents to linux/firewire.h anyway soon when more
firewire drivers are added. (IP-over-1394, firedtv, and there are plans
for one or two more.)
Furthermore, fw-ohci.h is renamed to ohci.h. The name of core.h and
ohci.h is chosen with regard to name changes of the .c files in a
follow-up change.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2009-06-05 22:26:18 +08:00
|
|
|
#include <linux/firewire.h>
|
2009-01-04 23:23:29 +08:00
|
|
|
#include <linux/firewire-constants.h>
|
|
|
|
#include <linux/kernel.h>
|
2006-12-20 08:58:27 +08:00
|
|
|
#include <linux/mm.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-01-04 23:23:29 +08:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/vmalloc.h>
|
2011-07-11 00:16:32 +08:00
|
|
|
#include <linux/export.h>
|
2006-12-20 08:58:27 +08:00
|
|
|
|
2009-06-05 03:09:38 +08:00
|
|
|
#include <asm/byteorder.h>
|
|
|
|
|
firewire: reorganize header files
The three header files of firewire-core, i.e.
"drivers/firewire/fw-device.h",
"drivers/firewire/fw-topology.h",
"drivers/firewire/fw-transaction.h",
are replaced by
"drivers/firewire/core.h",
"include/linux/firewire.h".
The latter includes everything which a firewire high-level driver (like
firewire-sbp2) needs besides linux/firewire-constants.h, while core.h
contains the rest which is needed by firewire-core itself and by low-
level drivers (card drivers) like firewire-ohci.
High-level drivers can now also reside outside of drivers/firewire
without having to add drivers/firewire to the header file search path in
makefiles. At least the firedtv driver will be such a driver.
I also considered to spread the contents of core.h over several files,
one for each .c file where the respective implementation resides. But
it turned out that most core .c files will end up including most of the
core .h files. Also, the combined core.h isn't unreasonably big, and it
will lose more of its contents to linux/firewire.h anyway soon when more
firewire drivers are added. (IP-over-1394, firedtv, and there are plans
for one or two more.)
Furthermore, fw-ohci.h is renamed to ohci.h. The name of core.h and
ohci.h is chosen with regard to name changes of the .c files in a
follow-up change.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2009-06-05 22:26:18 +08:00
|
|
|
#include "core.h"
|
2009-01-04 23:23:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Isochronous DMA context management
|
|
|
|
*/
|
2006-12-20 08:58:27 +08:00
|
|
|
|
2012-04-10 02:51:18 +08:00
|
|
|
int fw_iso_buffer_alloc(struct fw_iso_buffer *buffer, int page_count)
|
2006-12-20 08:58:27 +08:00
|
|
|
{
|
2012-04-10 02:51:18 +08:00
|
|
|
int i;
|
2007-02-17 06:34:38 +08:00
|
|
|
|
2012-04-10 02:51:18 +08:00
|
|
|
buffer->page_count = 0;
|
|
|
|
buffer->page_count_mapped = 0;
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:55:00 +08:00
|
|
|
buffer->pages = kmalloc_array(page_count, sizeof(buffer->pages[0]),
|
|
|
|
GFP_KERNEL);
|
2007-02-17 06:34:38 +08:00
|
|
|
if (buffer->pages == NULL)
|
2012-04-10 02:51:18 +08:00
|
|
|
return -ENOMEM;
|
2007-02-17 06:34:38 +08:00
|
|
|
|
2012-04-10 02:51:18 +08:00
|
|
|
for (i = 0; i < page_count; i++) {
|
2007-02-17 06:34:48 +08:00
|
|
|
buffer->pages[i] = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
|
2007-02-17 06:34:38 +08:00
|
|
|
if (buffer->pages[i] == NULL)
|
2012-04-10 02:51:18 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
buffer->page_count = i;
|
|
|
|
if (i < page_count) {
|
|
|
|
fw_iso_buffer_destroy(buffer, NULL);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2007-03-04 21:45:18 +08:00
|
|
|
|
2012-04-10 02:51:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fw_iso_buffer_map_dma(struct fw_iso_buffer *buffer, struct fw_card *card,
|
|
|
|
enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
dma_addr_t address;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
buffer->direction = direction;
|
|
|
|
|
|
|
|
for (i = 0; i < buffer->page_count; i++) {
|
2007-02-17 06:34:38 +08:00
|
|
|
address = dma_map_page(card->device, buffer->pages[i],
|
|
|
|
0, PAGE_SIZE, direction);
|
2012-04-10 02:51:18 +08:00
|
|
|
if (dma_mapping_error(card->device, address))
|
|
|
|
break;
|
|
|
|
|
2007-02-17 06:34:38 +08:00
|
|
|
set_page_private(buffer->pages[i], address);
|
2006-12-20 08:58:27 +08:00
|
|
|
}
|
2012-04-10 02:51:18 +08:00
|
|
|
buffer->page_count_mapped = i;
|
|
|
|
if (i < buffer->page_count)
|
|
|
|
return -ENOMEM;
|
2006-12-20 08:58:27 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-04-10 02:51:18 +08:00
|
|
|
}
|
2007-02-07 03:49:40 +08:00
|
|
|
|
2012-04-10 02:51:18 +08:00
|
|
|
int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
|
|
|
|
int page_count, enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = fw_iso_buffer_alloc(buffer, page_count);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-02-04 00:55:19 +08:00
|
|
|
|
2012-04-10 02:51:18 +08:00
|
|
|
ret = fw_iso_buffer_map_dma(buffer, card, direction);
|
|
|
|
if (ret < 0)
|
|
|
|
fw_iso_buffer_destroy(buffer, card);
|
|
|
|
|
|
|
|
return ret;
|
2007-02-17 06:34:38 +08:00
|
|
|
}
|
2009-05-19 01:08:06 +08:00
|
|
|
EXPORT_SYMBOL(fw_iso_buffer_init);
|
2007-02-17 06:34:38 +08:00
|
|
|
|
2012-04-10 02:51:18 +08:00
|
|
|
int fw_iso_buffer_map_vma(struct fw_iso_buffer *buffer,
|
|
|
|
struct vm_area_struct *vma)
|
2007-02-17 06:34:38 +08:00
|
|
|
{
|
2019-05-14 08:22:03 +08:00
|
|
|
return vm_map_pages_zero(vma, buffer->pages,
|
|
|
|
buffer->page_count);
|
2006-12-20 08:58:27 +08:00
|
|
|
}
|
|
|
|
|
2007-02-17 06:34:38 +08:00
|
|
|
void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer,
|
|
|
|
struct fw_card *card)
|
2006-12-20 08:58:27 +08:00
|
|
|
{
|
|
|
|
int i;
|
2007-02-17 06:34:38 +08:00
|
|
|
dma_addr_t address;
|
2006-12-20 08:58:27 +08:00
|
|
|
|
2012-04-10 02:51:18 +08:00
|
|
|
for (i = 0; i < buffer->page_count_mapped; i++) {
|
2007-02-17 06:34:38 +08:00
|
|
|
address = page_private(buffer->pages[i]);
|
|
|
|
dma_unmap_page(card->device, address,
|
2009-06-15 06:38:50 +08:00
|
|
|
PAGE_SIZE, buffer->direction);
|
2007-02-17 06:34:38 +08:00
|
|
|
}
|
2012-04-10 02:51:18 +08:00
|
|
|
for (i = 0; i < buffer->page_count; i++)
|
|
|
|
__free_page(buffer->pages[i]);
|
2006-12-20 08:58:27 +08:00
|
|
|
|
2007-02-17 06:34:38 +08:00
|
|
|
kfree(buffer->pages);
|
|
|
|
buffer->pages = NULL;
|
2012-04-10 02:51:18 +08:00
|
|
|
buffer->page_count = 0;
|
|
|
|
buffer->page_count_mapped = 0;
|
2006-12-20 08:58:27 +08:00
|
|
|
}
|
2009-05-19 01:08:06 +08:00
|
|
|
EXPORT_SYMBOL(fw_iso_buffer_destroy);
|
2006-12-20 08:58:27 +08:00
|
|
|
|
2010-07-30 00:19:22 +08:00
|
|
|
/* Convert DMA address to offset into virtually contiguous buffer. */
|
|
|
|
size_t fw_iso_buffer_lookup(struct fw_iso_buffer *buffer, dma_addr_t completed)
|
|
|
|
{
|
2012-06-14 04:28:24 +08:00
|
|
|
size_t i;
|
2010-07-30 00:19:22 +08:00
|
|
|
dma_addr_t address;
|
|
|
|
ssize_t offset;
|
|
|
|
|
|
|
|
for (i = 0; i < buffer->page_count; i++) {
|
|
|
|
address = page_private(buffer->pages[i]);
|
|
|
|
offset = (ssize_t)completed - (ssize_t)address;
|
|
|
|
if (offset > 0 && offset <= PAGE_SIZE)
|
|
|
|
return (i << PAGE_SHIFT) + offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-15 04:47:04 +08:00
|
|
|
struct fw_iso_context *fw_iso_context_create(struct fw_card *card,
|
|
|
|
int type, int channel, int speed, size_t header_size,
|
|
|
|
fw_iso_callback_t callback, void *callback_data)
|
2006-12-20 08:58:27 +08:00
|
|
|
{
|
|
|
|
struct fw_iso_context *ctx;
|
|
|
|
|
2008-12-21 23:39:46 +08:00
|
|
|
ctx = card->driver->allocate_iso_context(card,
|
|
|
|
type, channel, header_size);
|
2006-12-20 08:58:27 +08:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return ctx;
|
|
|
|
|
|
|
|
ctx->card = card;
|
|
|
|
ctx->type = type;
|
2007-02-17 06:34:50 +08:00
|
|
|
ctx->channel = channel;
|
|
|
|
ctx->speed = speed;
|
2007-02-17 06:34:40 +08:00
|
|
|
ctx->header_size = header_size;
|
2010-07-30 00:19:22 +08:00
|
|
|
ctx->callback.sc = callback;
|
2006-12-20 08:58:27 +08:00
|
|
|
ctx->callback_data = callback_data;
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
2009-05-19 01:08:06 +08:00
|
|
|
EXPORT_SYMBOL(fw_iso_context_create);
|
2006-12-20 08:58:27 +08:00
|
|
|
|
|
|
|
void fw_iso_context_destroy(struct fw_iso_context *ctx)
|
|
|
|
{
|
2010-07-30 00:19:22 +08:00
|
|
|
ctx->card->driver->free_iso_context(ctx);
|
2006-12-20 08:58:27 +08:00
|
|
|
}
|
2009-05-19 01:08:06 +08:00
|
|
|
EXPORT_SYMBOL(fw_iso_context_destroy);
|
2006-12-20 08:58:27 +08:00
|
|
|
|
2008-12-15 04:47:04 +08:00
|
|
|
int fw_iso_context_start(struct fw_iso_context *ctx,
|
|
|
|
int cycle, int sync, int tags)
|
2006-12-20 08:58:27 +08:00
|
|
|
{
|
2007-03-15 05:34:54 +08:00
|
|
|
return ctx->card->driver->start_iso(ctx, cycle, sync, tags);
|
2006-12-20 08:58:27 +08:00
|
|
|
}
|
2009-05-19 01:08:06 +08:00
|
|
|
EXPORT_SYMBOL(fw_iso_context_start);
|
2006-12-20 08:58:27 +08:00
|
|
|
|
2010-07-30 00:19:22 +08:00
|
|
|
int fw_iso_context_set_channels(struct fw_iso_context *ctx, u64 *channels)
|
|
|
|
{
|
|
|
|
return ctx->card->driver->set_iso_channels(ctx, channels);
|
|
|
|
}
|
|
|
|
|
2008-12-15 04:47:04 +08:00
|
|
|
int fw_iso_context_queue(struct fw_iso_context *ctx,
|
|
|
|
struct fw_iso_packet *packet,
|
|
|
|
struct fw_iso_buffer *buffer,
|
|
|
|
unsigned long payload)
|
2006-12-20 08:58:27 +08:00
|
|
|
{
|
2010-07-30 00:19:22 +08:00
|
|
|
return ctx->card->driver->queue_iso(ctx, packet, buffer, payload);
|
2006-12-20 08:58:27 +08:00
|
|
|
}
|
2009-05-19 01:08:06 +08:00
|
|
|
EXPORT_SYMBOL(fw_iso_context_queue);
|
2007-02-17 06:34:42 +08:00
|
|
|
|
2011-05-02 15:33:56 +08:00
|
|
|
void fw_iso_context_queue_flush(struct fw_iso_context *ctx)
|
|
|
|
{
|
|
|
|
ctx->card->driver->flush_queue_iso(ctx);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(fw_iso_context_queue_flush);
|
|
|
|
|
2012-03-19 02:06:39 +08:00
|
|
|
int fw_iso_context_flush_completions(struct fw_iso_context *ctx)
|
|
|
|
{
|
|
|
|
return ctx->card->driver->flush_iso_completions(ctx);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(fw_iso_context_flush_completions);
|
|
|
|
|
2008-12-15 04:47:04 +08:00
|
|
|
int fw_iso_context_stop(struct fw_iso_context *ctx)
|
2007-02-17 06:34:42 +08:00
|
|
|
{
|
|
|
|
return ctx->card->driver->stop_iso(ctx);
|
|
|
|
}
|
2009-05-19 01:08:06 +08:00
|
|
|
EXPORT_SYMBOL(fw_iso_context_stop);
|
2009-01-04 23:23:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Isochronous bus resource management (channels, bandwidth), client side
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int manage_bandwidth(struct fw_card *card, int irm_id, int generation,
|
2011-04-22 21:13:54 +08:00
|
|
|
int bandwidth, bool allocate)
|
2009-01-04 23:23:29 +08:00
|
|
|
{
|
|
|
|
int try, new, old = allocate ? BANDWIDTH_AVAILABLE_INITIAL : 0;
|
2011-04-22 21:13:54 +08:00
|
|
|
__be32 data[2];
|
2009-01-04 23:23:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* On a 1394a IRM with low contention, try < 1 is enough.
|
|
|
|
* On a 1394-1995 IRM, we need at least try < 2.
|
|
|
|
* Let's just do try < 5.
|
|
|
|
*/
|
|
|
|
for (try = 0; try < 5; try++) {
|
|
|
|
new = allocate ? old - bandwidth : old + bandwidth;
|
|
|
|
if (new < 0 || new > BANDWIDTH_AVAILABLE_INITIAL)
|
2010-04-12 16:35:18 +08:00
|
|
|
return -EBUSY;
|
2009-01-04 23:23:29 +08:00
|
|
|
|
|
|
|
data[0] = cpu_to_be32(old);
|
|
|
|
data[1] = cpu_to_be32(new);
|
|
|
|
switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
|
|
|
|
irm_id, generation, SCODE_100,
|
|
|
|
CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE,
|
2009-09-05 19:23:49 +08:00
|
|
|
data, 8)) {
|
2009-01-04 23:23:29 +08:00
|
|
|
case RCODE_GENERATION:
|
|
|
|
/* A generation change frees all bandwidth. */
|
|
|
|
return allocate ? -EAGAIN : bandwidth;
|
|
|
|
|
|
|
|
case RCODE_COMPLETE:
|
|
|
|
if (be32_to_cpup(data) == old)
|
|
|
|
return bandwidth;
|
|
|
|
|
|
|
|
old = be32_to_cpup(data);
|
|
|
|
/* Fall through. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int manage_channel(struct fw_card *card, int irm_id, int generation,
|
2011-04-22 21:13:54 +08:00
|
|
|
u32 channels_mask, u64 offset, bool allocate)
|
2009-01-04 23:23:29 +08:00
|
|
|
{
|
2011-01-31 18:58:58 +08:00
|
|
|
__be32 bit, all, old;
|
2011-04-22 21:13:54 +08:00
|
|
|
__be32 data[2];
|
2011-01-31 18:58:58 +08:00
|
|
|
int channel, ret = -EIO, retry = 5;
|
2009-01-04 23:23:29 +08:00
|
|
|
|
2009-01-09 06:07:40 +08:00
|
|
|
old = all = allocate ? cpu_to_be32(~0) : 0;
|
|
|
|
|
2011-01-31 18:58:58 +08:00
|
|
|
for (channel = 0; channel < 32; channel++) {
|
|
|
|
if (!(channels_mask & 1 << channel))
|
2009-01-04 23:23:29 +08:00
|
|
|
continue;
|
|
|
|
|
2010-04-12 16:35:18 +08:00
|
|
|
ret = -EBUSY;
|
|
|
|
|
2011-01-31 18:58:58 +08:00
|
|
|
bit = cpu_to_be32(1 << (31 - channel));
|
|
|
|
if ((old & bit) != (all & bit))
|
2009-01-04 23:23:29 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
data[0] = old;
|
2011-01-31 18:58:58 +08:00
|
|
|
data[1] = old ^ bit;
|
2009-01-04 23:23:29 +08:00
|
|
|
switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
|
|
|
|
irm_id, generation, SCODE_100,
|
2009-09-05 19:23:49 +08:00
|
|
|
offset, data, 8)) {
|
2009-01-04 23:23:29 +08:00
|
|
|
case RCODE_GENERATION:
|
|
|
|
/* A generation change frees all channels. */
|
2011-01-31 18:58:58 +08:00
|
|
|
return allocate ? -EAGAIN : channel;
|
2009-01-04 23:23:29 +08:00
|
|
|
|
|
|
|
case RCODE_COMPLETE:
|
|
|
|
if (data[0] == old)
|
2011-01-31 18:58:58 +08:00
|
|
|
return channel;
|
2009-01-04 23:23:29 +08:00
|
|
|
|
|
|
|
old = data[0];
|
|
|
|
|
|
|
|
/* Is the IRM 1394a-2000 compliant? */
|
2011-01-31 18:58:58 +08:00
|
|
|
if ((data[0] & bit) == (data[1] & bit))
|
2009-01-04 23:23:29 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* 1394-1995 IRM, fall through to retry. */
|
|
|
|
default:
|
2010-04-12 16:35:05 +08:00
|
|
|
if (retry) {
|
|
|
|
retry--;
|
2011-01-31 18:58:58 +08:00
|
|
|
channel--;
|
2010-04-12 16:35:18 +08:00
|
|
|
} else {
|
|
|
|
ret = -EIO;
|
2010-04-12 16:35:05 +08:00
|
|
|
}
|
2009-01-04 23:23:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-12 16:35:18 +08:00
|
|
|
return ret;
|
2009-01-04 23:23:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void deallocate_channel(struct fw_card *card, int irm_id,
|
2011-04-22 21:13:54 +08:00
|
|
|
int generation, int channel)
|
2009-01-04 23:23:29 +08:00
|
|
|
{
|
2009-01-09 06:07:40 +08:00
|
|
|
u32 mask;
|
2009-01-04 23:23:29 +08:00
|
|
|
u64 offset;
|
|
|
|
|
2009-01-09 06:07:40 +08:00
|
|
|
mask = channel < 32 ? 1 << channel : 1 << (channel - 32);
|
2009-01-04 23:23:29 +08:00
|
|
|
offset = channel < 32 ? CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI :
|
|
|
|
CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO;
|
|
|
|
|
2011-04-22 21:13:54 +08:00
|
|
|
manage_channel(card, irm_id, generation, mask, offset, false);
|
2009-01-04 23:23:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-07 19:26:18 +08:00
|
|
|
* fw_iso_resource_manage() - Allocate or deallocate a channel and/or bandwidth
|
2018-09-05 08:02:22 +08:00
|
|
|
* @card: card interface for this action
|
|
|
|
* @generation: bus generation
|
|
|
|
* @channels_mask: bitmask for channel allocation
|
|
|
|
* @channel: pointer for returning channel allocation result
|
|
|
|
* @bandwidth: pointer for returning bandwidth allocation result
|
|
|
|
* @allocate: whether to allocate (true) or deallocate (false)
|
2009-01-04 23:23:29 +08:00
|
|
|
*
|
|
|
|
* In parameters: card, generation, channels_mask, bandwidth, allocate
|
|
|
|
* Out parameters: channel, bandwidth
|
2018-09-05 08:02:22 +08:00
|
|
|
*
|
2009-01-04 23:23:29 +08:00
|
|
|
* This function blocks (sleeps) during communication with the IRM.
|
2009-01-09 06:07:40 +08:00
|
|
|
*
|
2009-01-04 23:23:29 +08:00
|
|
|
* Allocates or deallocates at most one channel out of channels_mask.
|
2009-01-09 06:07:40 +08:00
|
|
|
* channels_mask is a bitfield with MSB for channel 63 and LSB for channel 0.
|
|
|
|
* (Note, the IRM's CHANNELS_AVAILABLE is a big-endian bitfield with MSB for
|
|
|
|
* channel 0 and LSB for channel 63.)
|
|
|
|
* Allocates or deallocates as many bandwidth allocation units as specified.
|
2009-01-04 23:23:29 +08:00
|
|
|
*
|
|
|
|
* Returns channel < 0 if no channel was allocated or deallocated.
|
|
|
|
* Returns bandwidth = 0 if no bandwidth was allocated or deallocated.
|
|
|
|
*
|
|
|
|
* If generation is stale, deallocations succeed but allocations fail with
|
|
|
|
* channel = -EAGAIN.
|
|
|
|
*
|
2009-01-09 06:07:40 +08:00
|
|
|
* If channel allocation fails, no bandwidth will be allocated either.
|
2009-01-04 23:23:29 +08:00
|
|
|
* If bandwidth allocation fails, no channel will be allocated either.
|
2009-01-09 06:07:40 +08:00
|
|
|
* But deallocations of channel and bandwidth are tried independently
|
|
|
|
* of each other's success.
|
2009-01-04 23:23:29 +08:00
|
|
|
*/
|
|
|
|
void fw_iso_resource_manage(struct fw_card *card, int generation,
|
|
|
|
u64 channels_mask, int *channel, int *bandwidth,
|
2011-04-22 21:13:54 +08:00
|
|
|
bool allocate)
|
2009-01-04 23:23:29 +08:00
|
|
|
{
|
2009-01-09 06:07:40 +08:00
|
|
|
u32 channels_hi = channels_mask; /* channels 31...0 */
|
|
|
|
u32 channels_lo = channels_mask >> 32; /* channels 63...32 */
|
2009-01-04 23:23:29 +08:00
|
|
|
int irm_id, ret, c = -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irq(&card->lock);
|
|
|
|
irm_id = card->irm_node->node_id;
|
|
|
|
spin_unlock_irq(&card->lock);
|
|
|
|
|
|
|
|
if (channels_hi)
|
|
|
|
c = manage_channel(card, irm_id, generation, channels_hi,
|
2009-06-20 19:23:59 +08:00
|
|
|
CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI,
|
2011-04-22 21:13:54 +08:00
|
|
|
allocate);
|
2009-01-04 23:23:29 +08:00
|
|
|
if (channels_lo && c < 0) {
|
|
|
|
c = manage_channel(card, irm_id, generation, channels_lo,
|
2009-06-20 19:23:59 +08:00
|
|
|
CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO,
|
2011-04-22 21:13:54 +08:00
|
|
|
allocate);
|
2009-01-04 23:23:29 +08:00
|
|
|
if (c >= 0)
|
|
|
|
c += 32;
|
|
|
|
}
|
|
|
|
*channel = c;
|
|
|
|
|
2009-01-09 06:07:40 +08:00
|
|
|
if (allocate && channels_mask != 0 && c < 0)
|
2009-01-04 23:23:29 +08:00
|
|
|
*bandwidth = 0;
|
|
|
|
|
|
|
|
if (*bandwidth == 0)
|
|
|
|
return;
|
|
|
|
|
2011-04-22 21:13:54 +08:00
|
|
|
ret = manage_bandwidth(card, irm_id, generation, *bandwidth, allocate);
|
2009-01-04 23:23:29 +08:00
|
|
|
if (ret < 0)
|
|
|
|
*bandwidth = 0;
|
|
|
|
|
2010-03-15 20:20:32 +08:00
|
|
|
if (allocate && ret < 0) {
|
|
|
|
if (c >= 0)
|
2011-04-22 21:13:54 +08:00
|
|
|
deallocate_channel(card, irm_id, generation, c);
|
2009-01-04 23:23:29 +08:00
|
|
|
*channel = ret;
|
|
|
|
}
|
|
|
|
}
|
2011-03-15 14:53:21 +08:00
|
|
|
EXPORT_SYMBOL(fw_iso_resource_manage);
|