2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* IEEE 1394 for Linux
|
|
|
|
*
|
|
|
|
* Transaction support.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Andreas E. Bombe
|
|
|
|
*
|
|
|
|
* This code is licensed under the GPL. See the file COPYING in the root
|
|
|
|
* directory of the kernel sources for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/bitops.h>
|
2007-04-10 08:39:07 +08:00
|
|
|
#include <linux/compiler.h>
|
2007-03-12 05:49:05 +08:00
|
|
|
#include <linux/hardirq.h>
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
#include <linux/spinlock.h>
|
2007-04-10 08:39:07 +08:00
|
|
|
#include <linux/string.h>
|
2007-04-10 03:03:15 +08:00
|
|
|
#include <linux/sched.h> /* because linux/wait.h is broken if CONFIG_SMP=n */
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
#include <linux/wait.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-04 00:02:31 +08:00
|
|
|
#include <asm/bug.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/errno.h>
|
2007-04-10 08:39:07 +08:00
|
|
|
#include <asm/system.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "ieee1394.h"
|
|
|
|
#include "ieee1394_types.h"
|
|
|
|
#include "hosts.h"
|
|
|
|
#include "ieee1394_core.h"
|
2005-11-20 10:23:48 +08:00
|
|
|
#include "ieee1394_transactions.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define PREP_ASYNC_HEAD_ADDRESS(tc) \
|
|
|
|
packet->tcode = tc; \
|
|
|
|
packet->header[0] = (packet->node_id << 16) | (packet->tlabel << 10) \
|
|
|
|
| (1 << 8) | (tc << 4); \
|
|
|
|
packet->header[1] = (packet->host->node_id << 16) | (addr >> 32); \
|
|
|
|
packet->header[2] = addr & 0xffffffff
|
|
|
|
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
#ifndef HPSB_DEBUG_TLABELS
|
|
|
|
static
|
|
|
|
#endif
|
2007-04-12 01:54:34 +08:00
|
|
|
DEFINE_SPINLOCK(hpsb_tlabel_lock);
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(tlabel_wq);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void fill_async_readquad(struct hpsb_packet *packet, u64 addr)
|
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
PREP_ASYNC_HEAD_ADDRESS(TCODE_READQ);
|
|
|
|
packet->header_size = 12;
|
|
|
|
packet->data_size = 0;
|
|
|
|
packet->expect_response = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
static void fill_async_readblock(struct hpsb_packet *packet, u64 addr,
|
|
|
|
int length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
PREP_ASYNC_HEAD_ADDRESS(TCODE_READB);
|
|
|
|
packet->header[3] = length << 16;
|
|
|
|
packet->header_size = 16;
|
|
|
|
packet->data_size = 0;
|
|
|
|
packet->expect_response = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
static void fill_async_writequad(struct hpsb_packet *packet, u64 addr,
|
|
|
|
quadlet_t data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
PREP_ASYNC_HEAD_ADDRESS(TCODE_WRITEQ);
|
|
|
|
packet->header[3] = data;
|
|
|
|
packet->header_size = 16;
|
|
|
|
packet->data_size = 0;
|
|
|
|
packet->expect_response = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
static void fill_async_writeblock(struct hpsb_packet *packet, u64 addr,
|
|
|
|
int length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
PREP_ASYNC_HEAD_ADDRESS(TCODE_WRITEB);
|
|
|
|
packet->header[3] = length << 16;
|
|
|
|
packet->header_size = 16;
|
|
|
|
packet->expect_response = 1;
|
|
|
|
packet->data_size = length + (length % 4 ? 4 - (length % 4) : 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_async_lock(struct hpsb_packet *packet, u64 addr, int extcode,
|
2005-11-23 01:34:16 +08:00
|
|
|
int length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
PREP_ASYNC_HEAD_ADDRESS(TCODE_LOCK_REQUEST);
|
|
|
|
packet->header[3] = (length << 16) | extcode;
|
|
|
|
packet->header_size = 16;
|
|
|
|
packet->data_size = length;
|
|
|
|
packet->expect_response = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_iso_packet(struct hpsb_packet *packet, int length, int channel,
|
2005-11-23 01:34:16 +08:00
|
|
|
int tag, int sync)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
packet->header[0] = (length << 16) | (tag << 14) | (channel << 8)
|
|
|
|
| (TCODE_ISO_DATA << 4) | sync;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
packet->header_size = 4;
|
|
|
|
packet->data_size = length;
|
|
|
|
packet->type = hpsb_iso;
|
|
|
|
packet->tcode = TCODE_ISO_DATA;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_phy_packet(struct hpsb_packet *packet, quadlet_t data)
|
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
packet->header[0] = data;
|
|
|
|
packet->header[1] = ~data;
|
|
|
|
packet->header_size = 8;
|
|
|
|
packet->data_size = 0;
|
|
|
|
packet->expect_response = 0;
|
|
|
|
packet->type = hpsb_raw; /* No CRC added */
|
|
|
|
packet->speed_code = IEEE1394_SPEED_100; /* Force speed to be 100Mbps */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_async_stream_packet(struct hpsb_packet *packet, int length,
|
|
|
|
int channel, int tag, int sync)
|
|
|
|
{
|
|
|
|
packet->header[0] = (length << 16) | (tag << 14) | (channel << 8)
|
2005-11-23 01:34:16 +08:00
|
|
|
| (TCODE_STREAM_DATA << 4) | sync;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
packet->header_size = 4;
|
|
|
|
packet->data_size = length;
|
|
|
|
packet->type = hpsb_async;
|
|
|
|
packet->tcode = TCODE_ISO_DATA;
|
|
|
|
}
|
|
|
|
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
/* same as hpsb_get_tlabel, except that it returns immediately */
|
|
|
|
static int hpsb_get_tlabel_atomic(struct hpsb_packet *packet)
|
|
|
|
{
|
|
|
|
unsigned long flags, *tp;
|
|
|
|
u8 *next;
|
|
|
|
int tlabel, n = NODEID_TO_NODE(packet->node_id);
|
|
|
|
|
|
|
|
/* Broadcast transactions are complete once the request has been sent.
|
|
|
|
* Use the same transaction label for all broadcast transactions. */
|
|
|
|
if (unlikely(n == ALL_NODES)) {
|
|
|
|
packet->tlabel = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
tp = packet->host->tl_pool[n].map;
|
|
|
|
next = &packet->host->next_tl[n];
|
|
|
|
|
|
|
|
spin_lock_irqsave(&hpsb_tlabel_lock, flags);
|
|
|
|
tlabel = find_next_zero_bit(tp, 64, *next);
|
|
|
|
if (tlabel > 63)
|
|
|
|
tlabel = find_first_zero_bit(tp, 64);
|
|
|
|
if (tlabel > 63) {
|
|
|
|
spin_unlock_irqrestore(&hpsb_tlabel_lock, flags);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
__set_bit(tlabel, tp);
|
|
|
|
*next = (tlabel + 1) & 63;
|
|
|
|
spin_unlock_irqrestore(&hpsb_tlabel_lock, flags);
|
|
|
|
|
|
|
|
packet->tlabel = tlabel;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* hpsb_get_tlabel - allocate a transaction label
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
* @packet: the packet whose tlabel and tl_pool we set
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Every asynchronous transaction on the 1394 bus needs a transaction
|
|
|
|
* label to match the response to the request. This label has to be
|
|
|
|
* different from any other transaction label in an outstanding request to
|
|
|
|
* the same node to make matching possible without ambiguity.
|
|
|
|
*
|
|
|
|
* There are 64 different tlabels, so an allocated tlabel has to be freed
|
|
|
|
* with hpsb_free_tlabel() after the transaction is complete (unless it's
|
|
|
|
* reused again for the same target node).
|
|
|
|
*
|
|
|
|
* Return value: Zero on success, otherwise non-zero. A non-zero return
|
|
|
|
* generally means there are no available tlabels. If this is called out
|
|
|
|
* of interrupt or atomic context, then it will sleep until can return a
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
* tlabel or a signal is received.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
int hpsb_get_tlabel(struct hpsb_packet *packet)
|
|
|
|
{
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
if (irqs_disabled() || in_atomic())
|
|
|
|
return hpsb_get_tlabel_atomic(packet);
|
|
|
|
|
|
|
|
/* NB: The macro wait_event_interruptible() is called with a condition
|
|
|
|
* argument with side effect. This is only possible because the side
|
|
|
|
* effect does not occur until the condition became true, and
|
|
|
|
* wait_event_interruptible() won't evaluate the condition again after
|
|
|
|
* that. */
|
|
|
|
return wait_event_interruptible(tlabel_wq,
|
|
|
|
!hpsb_get_tlabel_atomic(packet));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hpsb_free_tlabel - free an allocated transaction label
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
* @packet: packet whose tlabel and tl_pool needs to be cleared
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Frees the transaction label allocated with hpsb_get_tlabel(). The
|
|
|
|
* tlabel has to be freed after the transaction is complete (i.e. response
|
|
|
|
* was received for a split transaction or packet was sent for a unified
|
|
|
|
* transaction).
|
|
|
|
*
|
|
|
|
* A tlabel must not be freed twice.
|
|
|
|
*/
|
|
|
|
void hpsb_free_tlabel(struct hpsb_packet *packet)
|
|
|
|
{
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
unsigned long flags, *tp;
|
|
|
|
int tlabel, n = NODEID_TO_NODE(packet->node_id);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-13 06:12:49 +08:00
|
|
|
if (unlikely(n == ALL_NODES))
|
|
|
|
return;
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
tp = packet->host->tl_pool[n].map;
|
|
|
|
tlabel = packet->tlabel;
|
|
|
|
BUG_ON(tlabel > 63 || tlabel < 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
spin_lock_irqsave(&hpsb_tlabel_lock, flags);
|
|
|
|
BUG_ON(!__test_and_clear_bit(tlabel, tp));
|
|
|
|
spin_unlock_irqrestore(&hpsb_tlabel_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
ieee1394: shrink tlabel pools, remove tpool semaphores
This patch reduces the size of struct hpsb_host and also removes
semaphores from ieee1394_transactions.c. On i386, struct hpsb_host
shrinks from 10656 bytes to 6688 bytes. This is accomplished by
- using a single wait_queue for hpsb_get_tlabel instead of many
instances of semaphores,
- using a single lock to serialize access to all tlabel pools (the
protected code regions are small, i.e. lock contention very low),
- omitting the sysfs attribute tlabels_allocations.
Drawback: In the rare case that a process needs to sleep because all
transaction labels for the node are temporarily exhausted, it is also
woken up if a tlabel for a different node became free, checks for an
available tlabel, and is put to sleep again. The check is not costly
and the situation occurs extremely rarely. (Tlabels are typically
only exhausted if there was no context switch to the khpsbpkt thread
which recycles tlables.) Therefore the benefit of reduced tpool size
outweighs this drawback.
The sysfs attributes tlabels_free and tlabels_mask are not compiled
anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set.
The by far biggest member of struct hpsb_host, the struct csr_control
csr (5272 bytes on i386), is now placed at the end of struct hpsb_host.
Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a
condition argument which has a side effect (allocation of a tlabel and
manipulation of the packet). This side effect happens only if the
condition is true. The patch relies on wait_event_interruptible not
evaluating the condition again after it became true.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
2006-07-02 20:17:00 +08:00
|
|
|
wake_up_interruptible(&tlabel_wq);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-03-05 10:06:23 +08:00
|
|
|
/**
|
|
|
|
* hpsb_packet_success - Make sense of the ack and reply codes
|
|
|
|
*
|
|
|
|
* Make sense of the ack and reply codes and return more convenient error codes:
|
|
|
|
* 0 = success. -%EBUSY = node is busy, try again. -%EAGAIN = error which can
|
|
|
|
* probably resolved by retry. -%EREMOTEIO = node suffers from an internal
|
|
|
|
* error. -%EACCES = this transaction is not allowed on requested address.
|
|
|
|
* -%EINVAL = invalid address at node.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
int hpsb_packet_success(struct hpsb_packet *packet)
|
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
switch (packet->ack_code) {
|
|
|
|
case ACK_PENDING:
|
|
|
|
switch ((packet->header[1] >> 12) & 0xf) {
|
|
|
|
case RCODE_COMPLETE:
|
|
|
|
return 0;
|
|
|
|
case RCODE_CONFLICT_ERROR:
|
|
|
|
return -EAGAIN;
|
|
|
|
case RCODE_DATA_ERROR:
|
|
|
|
return -EREMOTEIO;
|
|
|
|
case RCODE_TYPE_ERROR:
|
|
|
|
return -EACCES;
|
|
|
|
case RCODE_ADDRESS_ERROR:
|
|
|
|
return -EINVAL;
|
|
|
|
default:
|
|
|
|
HPSB_ERR("received reserved rcode %d from node %d",
|
|
|
|
(packet->header[1] >> 12) & 0xf,
|
|
|
|
packet->node_id);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
2006-07-04 00:02:31 +08:00
|
|
|
BUG();
|
2005-11-23 01:34:16 +08:00
|
|
|
|
|
|
|
case ACK_BUSY_X:
|
|
|
|
case ACK_BUSY_A:
|
|
|
|
case ACK_BUSY_B:
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
case ACK_TYPE_ERROR:
|
|
|
|
return -EACCES;
|
|
|
|
|
|
|
|
case ACK_COMPLETE:
|
|
|
|
if (packet->tcode == TCODE_WRITEQ
|
|
|
|
|| packet->tcode == TCODE_WRITEB) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
HPSB_ERR("impossible ack_complete from node %d "
|
|
|
|
"(tcode %d)", packet->node_id, packet->tcode);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ACK_DATA_ERROR:
|
|
|
|
if (packet->tcode == TCODE_WRITEB
|
|
|
|
|| packet->tcode == TCODE_LOCK_REQUEST) {
|
|
|
|
return -EAGAIN;
|
|
|
|
} else {
|
|
|
|
HPSB_ERR("impossible ack_data_error from node %d "
|
|
|
|
"(tcode %d)", packet->node_id, packet->tcode);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ACK_ADDRESS_ERROR:
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
case ACK_TARDY:
|
|
|
|
case ACK_CONFLICT_ERROR:
|
|
|
|
case ACKX_NONE:
|
|
|
|
case ACKX_SEND_ERROR:
|
|
|
|
case ACKX_ABORTED:
|
|
|
|
case ACKX_TIMEOUT:
|
|
|
|
/* error while sending */
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
default:
|
|
|
|
HPSB_ERR("got invalid ack %d from node %d (tcode %d)",
|
|
|
|
packet->ack_code, packet->node_id, packet->tcode);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
2006-07-04 00:02:31 +08:00
|
|
|
BUG();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node,
|
|
|
|
u64 addr, size_t length)
|
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
struct hpsb_packet *packet;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (length == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
packet = hpsb_alloc_packet(length);
|
|
|
|
if (!packet)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
packet->host = host;
|
|
|
|
packet->node_id = node;
|
|
|
|
|
|
|
|
if (hpsb_get_tlabel(packet)) {
|
|
|
|
hpsb_free_packet(packet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length == 4)
|
|
|
|
fill_async_readquad(packet, addr);
|
|
|
|
else
|
|
|
|
fill_async_readblock(packet, addr, length);
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
}
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
struct hpsb_packet *hpsb_make_writepacket(struct hpsb_host *host, nodeid_t node,
|
|
|
|
u64 addr, quadlet_t * buffer,
|
|
|
|
size_t length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct hpsb_packet *packet;
|
|
|
|
|
|
|
|
if (length == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
packet = hpsb_alloc_packet(length);
|
|
|
|
if (!packet)
|
|
|
|
return NULL;
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
if (length % 4) { /* zero padding bytes */
|
2005-04-17 06:20:36 +08:00
|
|
|
packet->data[length >> 2] = 0;
|
|
|
|
}
|
|
|
|
packet->host = host;
|
|
|
|
packet->node_id = node;
|
|
|
|
|
|
|
|
if (hpsb_get_tlabel(packet)) {
|
|
|
|
hpsb_free_packet(packet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length == 4) {
|
|
|
|
fill_async_writequad(packet, addr, buffer ? *buffer : 0);
|
|
|
|
} else {
|
|
|
|
fill_async_writeblock(packet, addr, length);
|
|
|
|
if (buffer)
|
|
|
|
memcpy(packet->data, buffer, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
}
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 * buffer,
|
|
|
|
int length, int channel, int tag,
|
|
|
|
int sync)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct hpsb_packet *packet;
|
|
|
|
|
|
|
|
if (length == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
packet = hpsb_alloc_packet(length);
|
|
|
|
if (!packet)
|
|
|
|
return NULL;
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
if (length % 4) { /* zero padding bytes */
|
2005-04-17 06:20:36 +08:00
|
|
|
packet->data[length >> 2] = 0;
|
|
|
|
}
|
|
|
|
packet->host = host;
|
|
|
|
|
2007-04-24 03:27:13 +08:00
|
|
|
/* Because it is too difficult to determine all PHY speeds and link
|
|
|
|
* speeds here, we use S100... */
|
|
|
|
packet->speed_code = IEEE1394_SPEED_100;
|
|
|
|
|
|
|
|
/* ...and prevent hpsb_send_packet() from overriding it. */
|
|
|
|
packet->node_id = LOCAL_BUS | ALL_NODES;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (hpsb_get_tlabel(packet)) {
|
|
|
|
hpsb_free_packet(packet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fill_async_stream_packet(packet, length, channel, tag, sync);
|
|
|
|
if (buffer)
|
|
|
|
memcpy(packet->data, buffer, length);
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hpsb_packet *hpsb_make_lockpacket(struct hpsb_host *host, nodeid_t node,
|
2005-11-23 01:34:16 +08:00
|
|
|
u64 addr, int extcode,
|
|
|
|
quadlet_t * data, quadlet_t arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct hpsb_packet *p;
|
|
|
|
u32 length;
|
|
|
|
|
|
|
|
p = hpsb_alloc_packet(8);
|
2005-11-23 01:34:16 +08:00
|
|
|
if (!p)
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
p->host = host;
|
|
|
|
p->node_id = node;
|
|
|
|
if (hpsb_get_tlabel(p)) {
|
|
|
|
hpsb_free_packet(p);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (extcode) {
|
|
|
|
case EXTCODE_FETCH_ADD:
|
|
|
|
case EXTCODE_LITTLE_ADD:
|
|
|
|
length = 4;
|
|
|
|
if (data)
|
|
|
|
p->data[0] = *data;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
length = 8;
|
|
|
|
if (data) {
|
|
|
|
p->data[0] = arg;
|
|
|
|
p->data[1] = *data;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fill_async_lock(p, addr, extcode, length);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
struct hpsb_packet *hpsb_make_lock64packet(struct hpsb_host *host,
|
|
|
|
nodeid_t node, u64 addr, int extcode,
|
|
|
|
octlet_t * data, octlet_t arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct hpsb_packet *p;
|
|
|
|
u32 length;
|
|
|
|
|
|
|
|
p = hpsb_alloc_packet(16);
|
2005-11-23 01:34:16 +08:00
|
|
|
if (!p)
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
p->host = host;
|
|
|
|
p->node_id = node;
|
|
|
|
if (hpsb_get_tlabel(p)) {
|
|
|
|
hpsb_free_packet(p);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (extcode) {
|
|
|
|
case EXTCODE_FETCH_ADD:
|
|
|
|
case EXTCODE_LITTLE_ADD:
|
|
|
|
length = 8;
|
|
|
|
if (data) {
|
|
|
|
p->data[0] = *data >> 32;
|
|
|
|
p->data[1] = *data & 0xffffffff;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
length = 16;
|
|
|
|
if (data) {
|
|
|
|
p->data[0] = arg >> 32;
|
|
|
|
p->data[1] = arg & 0xffffffff;
|
|
|
|
p->data[2] = *data >> 32;
|
|
|
|
p->data[3] = *data & 0xffffffff;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fill_async_lock(p, addr, extcode, length);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
struct hpsb_packet *hpsb_make_phypacket(struct hpsb_host *host, quadlet_t data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
struct hpsb_packet *p;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
p = hpsb_alloc_packet(0);
|
|
|
|
if (!p)
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
p->host = host;
|
|
|
|
fill_phy_packet(p, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
return p;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct hpsb_packet *hpsb_make_isopacket(struct hpsb_host *host,
|
|
|
|
int length, int channel,
|
|
|
|
int tag, int sync)
|
|
|
|
{
|
|
|
|
struct hpsb_packet *p;
|
|
|
|
|
|
|
|
p = hpsb_alloc_packet(length);
|
2005-11-23 01:34:16 +08:00
|
|
|
if (!p)
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
p->host = host;
|
|
|
|
fill_iso_packet(p, length, channel, tag, sync);
|
|
|
|
|
|
|
|
p->generation = get_hpsb_generation(host);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME - these functions should probably read from / write to user space to
|
|
|
|
* avoid in kernel buffers for user space callers
|
|
|
|
*/
|
|
|
|
|
2007-03-05 10:06:23 +08:00
|
|
|
/**
|
|
|
|
* hpsb_read - generic read function
|
|
|
|
*
|
|
|
|
* Recognizes the local node ID and act accordingly. Automatically uses a
|
|
|
|
* quadlet read request if @length == 4 and and a block read request otherwise.
|
|
|
|
* It does not yet support lengths that are not a multiple of 4.
|
|
|
|
*
|
|
|
|
* You must explicitly specifiy the @generation for which the node ID is valid,
|
|
|
|
* to avoid sending packets to the wrong nodes when we race with a bus reset.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
int hpsb_read(struct hpsb_host *host, nodeid_t node, unsigned int generation,
|
2005-11-23 01:34:16 +08:00
|
|
|
u64 addr, quadlet_t * buffer, size_t length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
struct hpsb_packet *packet;
|
|
|
|
int retval = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
if (length == 0)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
packet = hpsb_make_readpacket(host, node, addr, length);
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
if (!packet) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
packet->generation = generation;
|
2005-11-23 01:34:16 +08:00
|
|
|
retval = hpsb_send_packet_and_wait(packet);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0)
|
|
|
|
goto hpsb_read_fail;
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
retval = hpsb_packet_success(packet);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
if (retval == 0) {
|
|
|
|
if (length == 4) {
|
|
|
|
*buffer = packet->header[3];
|
|
|
|
} else {
|
|
|
|
memcpy(buffer, packet->data, length);
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
hpsb_read_fail:
|
|
|
|
hpsb_free_tlabel(packet);
|
|
|
|
hpsb_free_packet(packet);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-03-05 10:06:23 +08:00
|
|
|
/**
|
|
|
|
* hpsb_write - generic write function
|
|
|
|
*
|
|
|
|
* Recognizes the local node ID and act accordingly. Automatically uses a
|
|
|
|
* quadlet write request if @length == 4 and and a block write request
|
|
|
|
* otherwise. It does not yet support lengths that are not a multiple of 4.
|
|
|
|
*
|
|
|
|
* You must explicitly specifiy the @generation for which the node ID is valid,
|
|
|
|
* to avoid sending packets to the wrong nodes when we race with a bus reset.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
int hpsb_write(struct hpsb_host *host, nodeid_t node, unsigned int generation,
|
2005-11-23 01:34:16 +08:00
|
|
|
u64 addr, quadlet_t * buffer, size_t length)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct hpsb_packet *packet;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (length == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
packet = hpsb_make_writepacket(host, node, addr, buffer, length);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!packet)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
packet->generation = generation;
|
2005-11-23 01:34:16 +08:00
|
|
|
retval = hpsb_send_packet_and_wait(packet);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0)
|
|
|
|
goto hpsb_write_fail;
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
retval = hpsb_packet_success(packet);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
hpsb_write_fail:
|
|
|
|
hpsb_free_tlabel(packet);
|
|
|
|
hpsb_free_packet(packet);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-05-17 12:54:00 +08:00
|
|
|
#if 0
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
int hpsb_lock(struct hpsb_host *host, nodeid_t node, unsigned int generation,
|
2005-11-23 01:34:16 +08:00
|
|
|
u64 addr, int extcode, quadlet_t * data, quadlet_t arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-23 01:34:16 +08:00
|
|
|
struct hpsb_packet *packet;
|
|
|
|
int retval = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
packet = hpsb_make_lockpacket(host, node, addr, extcode, data, arg);
|
2005-11-23 01:34:16 +08:00
|
|
|
if (!packet)
|
|
|
|
return -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
packet->generation = generation;
|
2005-11-23 01:34:16 +08:00
|
|
|
retval = hpsb_send_packet_and_wait(packet);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0)
|
|
|
|
goto hpsb_lock_fail;
|
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
retval = hpsb_packet_success(packet);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
if (retval == 0) {
|
|
|
|
*data = packet->data[0];
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
hpsb_lock_fail:
|
|
|
|
hpsb_free_tlabel(packet);
|
|
|
|
hpsb_free_packet(packet);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int hpsb_send_gasp(struct hpsb_host *host, int channel, unsigned int generation,
|
2005-11-23 01:34:16 +08:00
|
|
|
quadlet_t * buffer, size_t length, u32 specifier_id,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int version)
|
|
|
|
{
|
|
|
|
struct hpsb_packet *packet;
|
|
|
|
int retval = 0;
|
|
|
|
u16 specifier_id_hi = (specifier_id & 0x00ffff00) >> 8;
|
|
|
|
u8 specifier_id_lo = specifier_id & 0xff;
|
|
|
|
|
|
|
|
HPSB_VERBOSE("Send GASP: channel = %d, length = %Zd", channel, length);
|
|
|
|
|
|
|
|
length += 8;
|
|
|
|
|
|
|
|
packet = hpsb_make_streampacket(host, NULL, length, channel, 3, 0);
|
|
|
|
if (!packet)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
packet->data[0] = cpu_to_be32((host->node_id << 16) | specifier_id_hi);
|
2005-11-23 01:34:16 +08:00
|
|
|
packet->data[1] =
|
|
|
|
cpu_to_be32((specifier_id_lo << 24) | (version & 0x00ffffff));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
memcpy(&(packet->data[2]), buffer, length - 8);
|
|
|
|
|
|
|
|
packet->generation = generation;
|
|
|
|
|
|
|
|
packet->no_waiter = 1;
|
|
|
|
|
|
|
|
retval = hpsb_send_packet(packet);
|
|
|
|
if (retval < 0)
|
|
|
|
hpsb_free_packet(packet);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2005-05-17 12:54:00 +08:00
|
|
|
|
2005-11-23 01:34:16 +08:00
|
|
|
#endif /* 0 */
|