Add raw1394_get_speed() API

This lets initiators of isochronous streams or asynchronous streams from
or to the local node figure out what maximum speed can be configured.

Furthermore it can be used to display connection speeds for informative
purposes without having to perform topology analysis (in case of 1394a
buses) or extensive phy port status queries (in case of 1394b buses).

To be in line with other existing libraw1394 APIs which use nodeid_t
variables, this API identifies a node only via a card:nodeID tuple which
is unsafe against generation changes.  A node can only be properly
identified by card:generation:nodeID tuples.  However, since this new
API extension and libraw1394 as a whole is mainly aimed towards existing
libraw1394 client code bases rather than new developments, I decided
against making this call race free but somewhat more difficult to use in
typical existing client code.

A unit test for the new call is added to testlibraw as well.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
This commit is contained in:
Stefan Richter 2012-06-30 18:49:43 +02:00
parent d4e754165e
commit d50f7381b2
5 changed files with 76 additions and 5 deletions

View File

@ -155,6 +155,20 @@ int raw1394_get_nodecount(raw1394handle_t handle)
return ieee1394_get_nodecount(handle->mode.ieee1394); return ieee1394_get_nodecount(handle->mode.ieee1394);
} }
int raw1394_get_speed(raw1394handle_t handle, nodeid_t node)
{
if (!handle) {
errno = EINVAL;
return -1;
}
if (handle->is_fw)
return fw_get_speed(handle->mode.fw, node);
else {
errno = ENOSYS;
return -1;
}
}
int raw1394_get_port_info(raw1394handle_t handle, struct raw1394_portinfo *pinf, int raw1394_get_port_info(raw1394handle_t handle, struct raw1394_portinfo *pinf,
int maxports) int maxports)
{ {

View File

@ -602,6 +602,34 @@ int fw_get_nodecount(fw_handle_t handle)
return (handle->reset.root_node_id & 0x3f) + 1; return (handle->reset.root_node_id & 0x3f) + 1;
} }
int fw_get_speed(fw_handle_t handle, nodeid_t node)
{
int i;
if ((node & ~0x3f) != 0xffc0) {
errno = ENOSYS;
return -1;
}
if (node > handle->reset.root_node_id) {
errno = fw_errcode_to_errno(-RCODE_NO_ACK);
return -1;
}
i = handle->nodes[node & 0x3f];
if (i == -1) {
errno = fw_errcode_to_errno(-RCODE_NO_ACK);
return -1;
}
if (handle->generation != handle->devices[i].generation) {
errno = fw_errcode_to_errno(-RCODE_GENERATION);
return -1;
}
return ioctl(handle->devices[i].fd, FW_CDEV_IOC_GET_SPEED);
}
int fw_get_port_info(fw_handle_t handle, int fw_get_port_info(fw_handle_t handle,
struct raw1394_portinfo *pinf, struct raw1394_portinfo *pinf,
int maxports) int maxports)

View File

@ -144,6 +144,7 @@ int fw_get_fd(fw_handle_t handle);
nodeid_t fw_get_local_id(fw_handle_t handle); nodeid_t fw_get_local_id(fw_handle_t handle);
nodeid_t fw_get_irm_id(fw_handle_t handle); nodeid_t fw_get_irm_id(fw_handle_t handle);
int fw_get_nodecount(fw_handle_t handle); int fw_get_nodecount(fw_handle_t handle);
int fw_get_speed(fw_handle_t handle, nodeid_t node);
int fw_get_port_info(fw_handle_t handle, struct raw1394_portinfo *pinf, int fw_get_port_info(fw_handle_t handle, struct raw1394_portinfo *pinf,
int maxports); int maxports);
int fw_set_port(fw_handle_t handle, int port); int fw_set_port(fw_handle_t handle, int port);

View File

@ -543,6 +543,22 @@ nodeid_t raw1394_get_irm_id(raw1394handle_t handle);
**/ **/
int raw1394_get_nodecount(raw1394handle_t handle); int raw1394_get_nodecount(raw1394handle_t handle);
/**
* raw1394_get_speed - get maximum speed between a node and local node
* @handle: libraw1394 handle
* @node: node ID
*
* Returns: The speed code of the maximum possible transmission speed between
* the node and the local node, taking both link speeds and all intermediate
* phy speeds into account. On error, returns -1 and sets errno.
*
* Bugs: Like much of the rest of the libraw1394 API, this call is prone to
* races with bus resets.
*
* History: New function in libraw1394 v2.1.0.
**/
int raw1394_get_speed(raw1394handle_t handle, nodeid_t node);
struct raw1394_portinfo { struct raw1394_portinfo {
int nodes; int nodes;
char name[32]; char name[32];

View File

@ -229,7 +229,7 @@ int test_card(int card)
struct raw1394_portinfo pinf; struct raw1394_portinfo pinf;
tag_handler_t std_handler; tag_handler_t std_handler;
struct pollfd pfd; struct pollfd pfd;
int i, n, numcards, retval; int i, l, n, numcards, retval, s;
handle = raw1394_new_handle(); handle = raw1394_new_handle();
@ -267,10 +267,22 @@ int test_card(int card)
} }
n = raw1394_get_nodecount(handle); n = raw1394_get_nodecount(handle);
printf("%d nodes on bus, local ID is %d, IRM is %d\n", l = raw1394_get_local_id(handle) & 0x3f;
n, i = raw1394_get_irm_id(handle) & 0x3f;
raw1394_get_local_id(handle) & 0x3f, printf("%d nodes on bus, local ID is %d, IRM is %d\n", n, l, i);
raw1394_get_irm_id(handle) & 0x3f);
if (n > 0)
printf("\n - getting speeds between between nodes and local node\n");
for (i = 0; i < n; i++) {
printf(" node %d: ", i);
fflush(stdout);
s = raw1394_get_speed(handle, 0xffc0 | i);
if (s >= 0)
printf("S%d00%s\n", 1 << s,
i == l ? " (local node)" : "");
else
perror("unknown");
}
if (n > 0) { if (n > 0) {
printf("\n - doing transactions with custom tag handler\n"); printf("\n - doing transactions with custom tag handler\n");