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>
|
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
|
|
|
|
2008-12-15 04:47:04 +08:00
|
|
|
int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
|
|
|
|
int page_count, enum dma_data_direction direction)
|
2006-12-20 08:58:27 +08:00
|
|
|
{
|
2008-12-15 04:45:45 +08:00
|
|
|
int i, j;
|
2007-02-17 06:34:38 +08:00
|
|
|
dma_addr_t address;
|
|
|
|
|
|
|
|
buffer->page_count = page_count;
|
|
|
|
buffer->direction = direction;
|
|
|
|
|
|
|
|
buffer->pages = kmalloc(page_count * sizeof(buffer->pages[0]),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (buffer->pages == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (i = 0; i < buffer->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)
|
|
|
|
goto out_pages;
|
2007-03-04 21:45:18 +08:00
|
|
|
|
2007-02-17 06:34:38 +08:00
|
|
|
address = dma_map_page(card->device, buffer->pages[i],
|
|
|
|
0, PAGE_SIZE, direction);
|
2008-07-26 10:44:49 +08:00
|
|
|
if (dma_mapping_error(card->device, address)) {
|
2007-02-17 06:34:38 +08:00
|
|
|
__free_page(buffer->pages[i]);
|
|
|
|
goto out_pages;
|
|
|
|
}
|
|
|
|
set_page_private(buffer->pages[i], address);
|
2006-12-20 08:58:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-02-07 03:49:40 +08:00
|
|
|
|
2007-02-17 06:34:38 +08:00
|
|
|
out_pages:
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
address = page_private(buffer->pages[j]);
|
|
|
|
dma_unmap_page(card->device, address,
|
2009-06-15 06:38:50 +08:00
|
|
|
PAGE_SIZE, direction);
|
2007-02-17 06:34:38 +08:00
|
|
|
__free_page(buffer->pages[j]);
|
|
|
|
}
|
|
|
|
kfree(buffer->pages);
|
|
|
|
out:
|
|
|
|
buffer->pages = NULL;
|
2009-02-04 00:55:19 +08:00
|
|
|
|
2008-12-15 04:45:45 +08:00
|
|
|
return -ENOMEM;
|
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
|
|
|
|
|
|
|
int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
unsigned long uaddr;
|
2009-02-04 00:55:19 +08:00
|
|
|
int i, err;
|
2007-02-17 06:34:38 +08:00
|
|
|
|
|
|
|
uaddr = vma->vm_start;
|
|
|
|
for (i = 0; i < buffer->page_count; i++) {
|
2009-02-04 00:55:19 +08:00
|
|
|
err = vm_insert_page(vma, uaddr, buffer->pages[i]);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2007-02-17 06:34:38 +08:00
|
|
|
uaddr += PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
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
|
|
|
|
2007-02-17 06:34:38 +08:00
|
|
|
for (i = 0; i < buffer->page_count; i++) {
|
|
|
|
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
|
|
|
__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;
|
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
|
|
|
|
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;
|
2006-12-20 08:58:27 +08:00
|
|
|
ctx->callback = callback;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct fw_card *card = ctx->card;
|
|
|
|
|
|
|
|
card->driver->free_iso_context(ctx);
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
{
|
|
|
|
struct fw_card *card = ctx->card;
|
|
|
|
|
2007-02-17 06:34:38 +08:00
|
|
|
return 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
|
|
|
|
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,
|
2009-06-20 19:23:59 +08:00
|
|
|
int bandwidth, bool allocate, __be32 data[2])
|
2009-01-04 23:23:29 +08:00
|
|
|
{
|
|
|
|
int try, new, old = allocate ? BANDWIDTH_AVAILABLE_INITIAL : 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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,
|
2009-06-20 19:23:59 +08:00
|
|
|
u32 channels_mask, u64 offset, bool allocate, __be32 data[2])
|
2009-01-04 23:23:29 +08:00
|
|
|
{
|
2009-06-20 19:23:59 +08:00
|
|
|
__be32 c, all, old;
|
2010-04-12 16:35:18 +08:00
|
|
|
int i, 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;
|
|
|
|
|
2009-01-04 23:23:29 +08:00
|
|
|
for (i = 0; i < 32; i++) {
|
2009-01-09 06:07:40 +08:00
|
|
|
if (!(channels_mask & 1 << i))
|
2009-01-04 23:23:29 +08:00
|
|
|
continue;
|
|
|
|
|
2010-04-12 16:35:18 +08:00
|
|
|
ret = -EBUSY;
|
|
|
|
|
2009-01-09 06:07:40 +08:00
|
|
|
c = cpu_to_be32(1 << (31 - i));
|
|
|
|
if ((old & c) != (all & c))
|
2009-01-04 23:23:29 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
data[0] = old;
|
|
|
|
data[1] = old ^ c;
|
|
|
|
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. */
|
|
|
|
return allocate ? -EAGAIN : i;
|
|
|
|
|
|
|
|
case RCODE_COMPLETE:
|
|
|
|
if (data[0] == old)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
old = data[0];
|
|
|
|
|
|
|
|
/* Is the IRM 1394a-2000 compliant? */
|
2009-01-09 06:07:40 +08:00
|
|
|
if ((data[0] & c) == (data[1] & c))
|
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--;
|
2009-01-04 23:23:29 +08:00
|
|
|
i--;
|
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,
|
2009-06-20 19:23:59 +08:00
|
|
|
int generation, int channel, __be32 buffer[2])
|
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;
|
|
|
|
|
2009-06-20 19:23:59 +08:00
|
|
|
manage_channel(card, irm_id, generation, mask, offset, false, buffer);
|
2009-01-04 23:23:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fw_iso_resource_manage - Allocate or deallocate a channel and/or bandwidth
|
|
|
|
*
|
|
|
|
* In parameters: card, generation, channels_mask, bandwidth, allocate
|
|
|
|
* Out parameters: channel, bandwidth
|
|
|
|
* 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,
|
2009-06-20 19:23:59 +08:00
|
|
|
bool allocate, __be32 buffer[2])
|
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,
|
|
|
|
allocate, buffer);
|
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,
|
|
|
|
allocate, buffer);
|
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;
|
|
|
|
|
2009-06-20 19:23:59 +08:00
|
|
|
ret = manage_bandwidth(card, irm_id, generation, *bandwidth,
|
|
|
|
allocate, buffer);
|
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)
|
|
|
|
deallocate_channel(card, irm_id, generation, c, buffer);
|
2009-01-04 23:23:29 +08:00
|
|
|
*channel = ret;
|
|
|
|
}
|
|
|
|
}
|