2007-03-26 16:49:12 -04:00
|
|
|
/* -*- c-basic-offset: 8 -*-
|
|
|
|
*
|
2000-06-14 11:01:42 -04:00
|
|
|
* libraw1394 - library for raw access to the 1394 bus with the Linux subsystem.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999,2000 Andreas Bombe
|
|
|
|
*
|
|
|
|
* This library is licensed under the GNU Lesser General Public License (LGPL),
|
|
|
|
* version 2.1 or later. See the file COPYING.LIB in the distribution for
|
|
|
|
* details.
|
|
|
|
*/
|
1999-12-02 18:07:38 -05:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2001-01-26 21:28:29 -05:00
|
|
|
#include <string.h>
|
2000-03-16 17:22:05 -05:00
|
|
|
#include <sys/poll.h>
|
2002-10-23 17:18:49 -04:00
|
|
|
#include <stdlib.h>
|
2007-03-26 16:49:12 -04:00
|
|
|
#include <arpa/inet.h>
|
1999-12-02 18:07:38 -05:00
|
|
|
|
2001-06-07 20:31:12 -04:00
|
|
|
#include "../src/raw1394.h"
|
|
|
|
#include "../src/csr.h"
|
1999-12-02 18:07:38 -05:00
|
|
|
|
|
|
|
|
2007-03-26 16:49:12 -04:00
|
|
|
#define TESTADDR (CSR_REGISTER_BASE + CSR_CONFIG_ROM)
|
1999-12-02 18:07:38 -05:00
|
|
|
|
|
|
|
const char not_compatible[] = "\
|
2003-07-12 20:49:54 -04:00
|
|
|
This libraw1394 does not work with your version of Linux. You need a different\n\
|
|
|
|
version that matches your kernel (see kernel help text for the raw1394 option to\n\
|
1999-12-02 18:07:38 -05:00
|
|
|
find out which is the correct version).\n";
|
|
|
|
|
|
|
|
const char not_loaded[] = "\
|
2003-07-12 20:49:54 -04:00
|
|
|
This probably means that you don't have raw1394 support in the kernel or that\n\
|
1999-12-02 18:07:38 -05:00
|
|
|
you haven't loaded the raw1394 module.\n";
|
|
|
|
|
|
|
|
quadlet_t buffer;
|
|
|
|
|
2001-01-26 21:28:29 -05:00
|
|
|
int my_tag_handler(raw1394handle_t handle, unsigned long tag,
|
|
|
|
raw1394_errcode_t errcode)
|
1999-12-02 18:07:38 -05:00
|
|
|
{
|
2001-01-26 21:28:29 -05:00
|
|
|
int err = raw1394_errcode_to_errno(errcode);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
printf("failed with error: %s\n", strerror(err));
|
1999-12-02 18:07:38 -05:00
|
|
|
} else {
|
2001-01-26 21:28:29 -05:00
|
|
|
printf("completed with value 0x%08x\n", buffer);
|
1999-12-02 18:07:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-26 16:49:12 -04:00
|
|
|
static const unsigned char fcp_data[] =
|
|
|
|
{ 0x1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
|
|
|
|
2000-03-16 17:22:05 -05:00
|
|
|
int my_fcp_handler(raw1394handle_t handle, nodeid_t nodeid, int response,
|
|
|
|
size_t length, unsigned char *data)
|
|
|
|
{
|
2008-12-07 08:24:56 -05:00
|
|
|
printf(" got fcp %s from node %d of %d bytes:",
|
|
|
|
(response ? "response" : "command"), nodeid & 0x3f, length);
|
2000-03-16 17:22:05 -05:00
|
|
|
|
2007-03-26 16:49:12 -04:00
|
|
|
if (memcmp(fcp_data, data, sizeof fcp_data) != 0)
|
|
|
|
printf("ERROR: fcp payload not correct\n");
|
|
|
|
|
2000-03-16 17:22:05 -05:00
|
|
|
while (length) {
|
|
|
|
printf(" %02x", *data);
|
|
|
|
data++;
|
|
|
|
length--;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
2000-06-22 12:22:00 -04:00
|
|
|
|
|
|
|
return 0;
|
2000-03-16 17:22:05 -05:00
|
|
|
}
|
1999-12-02 18:07:38 -05:00
|
|
|
|
2007-03-26 16:49:12 -04:00
|
|
|
static void
|
|
|
|
test_fcp(raw1394handle_t handle)
|
|
|
|
{
|
2008-12-07 08:24:56 -05:00
|
|
|
printf("\n - testing FCP monitoring on local node\n");
|
2007-03-26 16:49:12 -04:00
|
|
|
raw1394_set_fcp_handler(handle, my_fcp_handler);
|
|
|
|
raw1394_start_fcp_listen(handle);
|
|
|
|
raw1394_write(handle, raw1394_get_local_id(handle),
|
|
|
|
CSR_REGISTER_BASE + CSR_FCP_COMMAND, sizeof(fcp_data),
|
|
|
|
(quadlet_t *)fcp_data);
|
|
|
|
raw1394_write(handle, raw1394_get_local_id(handle),
|
|
|
|
CSR_REGISTER_BASE + CSR_FCP_RESPONSE, sizeof(fcp_data),
|
|
|
|
(quadlet_t *)fcp_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
read_topology_map(raw1394handle_t handle)
|
|
|
|
{
|
|
|
|
quadlet_t map[70];
|
|
|
|
nodeid_t local_id;
|
|
|
|
int node_count, self_id_count, i, retval;
|
|
|
|
|
|
|
|
local_id = raw1394_get_local_id(handle) | 0xffc0;
|
|
|
|
|
|
|
|
retval = raw1394_read(handle, local_id,
|
|
|
|
CSR_REGISTER_BASE + CSR_TOPOLOGY_MAP, 12, &map[0]);
|
2008-12-07 08:24:56 -05:00
|
|
|
if (retval < 0) {
|
|
|
|
perror("\n - topology map: raw1394_read failed with error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-26 16:49:12 -04:00
|
|
|
self_id_count = ntohl(map[2]) & 0xffff;
|
|
|
|
node_count = ntohl(map[2]) >> 16;
|
|
|
|
retval = raw1394_read(handle, local_id,
|
|
|
|
CSR_REGISTER_BASE + CSR_TOPOLOGY_MAP + 12,
|
|
|
|
self_id_count * sizeof map[0], &map[3]);
|
2008-12-07 08:24:56 -05:00
|
|
|
if (retval < 0) {
|
|
|
|
perror("\n - topology map: raw1394_read failed with error");
|
|
|
|
return;
|
|
|
|
}
|
2007-03-26 16:49:12 -04:00
|
|
|
|
2008-12-07 08:24:56 -05:00
|
|
|
printf("\n - topology map: %d nodes, %d self ids, generation %d\n",
|
2007-03-26 16:49:12 -04:00
|
|
|
node_count, self_id_count, ntohl(map[1]));
|
|
|
|
for (i = 0; i < self_id_count; i++)
|
2008-12-07 08:24:56 -05:00
|
|
|
printf(" 0x%08x\n", ntohl(map[3 + i]));
|
2007-03-26 16:49:12 -04:00
|
|
|
}
|
1999-12-02 18:07:38 -05:00
|
|
|
|
2008-12-07 08:24:56 -05:00
|
|
|
static void
|
|
|
|
test_config_rom(raw1394handle_t handle)
|
1999-12-02 18:07:38 -05:00
|
|
|
{
|
2008-12-07 08:24:56 -05:00
|
|
|
quadlet_t rom[0x100] = { 0, };
|
|
|
|
size_t rom_size;
|
|
|
|
unsigned char rom_version;
|
|
|
|
int i, retval;
|
|
|
|
|
|
|
|
printf("\n - testing config rom\n");
|
|
|
|
retval = raw1394_get_config_rom(handle, rom, 0x100,
|
|
|
|
&rom_size, &rom_version);
|
|
|
|
printf(" get_config_rom returned %d, romsize %d, rom_version %d\n",
|
|
|
|
retval, rom_size, rom_version);
|
|
|
|
printf(" here are the first 10 quadlets:\n");
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
printf(" 0x%08x\n", i, rom[i]);
|
|
|
|
|
|
|
|
retval = raw1394_update_config_rom(handle, rom, rom_size, rom_version);
|
|
|
|
printf(" update_config_rom returned %d\n", retval);
|
|
|
|
}
|
1999-12-02 18:07:38 -05:00
|
|
|
|
2008-12-07 08:24:56 -05:00
|
|
|
int test_card(int card)
|
|
|
|
{
|
|
|
|
raw1394handle_t handle;
|
|
|
|
struct raw1394_portinfo pinf;
|
|
|
|
tag_handler_t std_handler;
|
|
|
|
struct pollfd pfd;
|
|
|
|
int i, n, numcards, retval;
|
|
|
|
|
|
|
|
handle = raw1394_new_handle();
|
|
|
|
|
|
|
|
if (!handle) {
|
|
|
|
if (!errno) {
|
|
|
|
printf(not_compatible);
|
|
|
|
} else {
|
|
|
|
perror("couldn't get handle");
|
|
|
|
printf(not_loaded);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (card == 0) {
|
|
|
|
printf("successfully got handle\n");
|
|
|
|
printf("current generation number: %d\n",
|
|
|
|
raw1394_get_generation(handle));
|
|
|
|
}
|
|
|
|
|
|
|
|
numcards = raw1394_get_port_info(handle, &pinf, 1);
|
|
|
|
if (numcards < card)
|
|
|
|
perror("couldn't get card info");
|
|
|
|
else if (card == 0)
|
|
|
|
printf("%d card%s found\n",
|
|
|
|
numcards, numcards == 1 ? "" : "s");
|
|
|
|
|
|
|
|
if (numcards <= card)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
printf("\ncard %d, name: %s\n", card, pinf.name);
|
|
|
|
|
|
|
|
if (raw1394_set_port(handle, card) < 0) {
|
|
|
|
perror("couldn't set port");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = raw1394_get_nodecount(handle);
|
|
|
|
printf("%d nodes on bus, local ID is %d, IRM is %d\n",
|
|
|
|
n,
|
|
|
|
raw1394_get_local_id(handle) & 0x3f,
|
|
|
|
raw1394_get_irm_id(handle) & 0x3f);
|
|
|
|
|
|
|
|
if (n > 0) {
|
|
|
|
printf("\n - doing transactions with custom tag handler\n");
|
|
|
|
std_handler = raw1394_set_tag_handler(handle, my_tag_handler);
|
|
|
|
}
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
printf(" read from node %d... ", i);
|
|
|
|
fflush(stdout);
|
|
|
|
buffer = 0;
|
|
|
|
|
|
|
|
if (raw1394_start_read(handle, 0xffc0 | i, TESTADDR, 4,
|
|
|
|
&buffer, 0) < 0) {
|
2008-09-30 17:05:32 -04:00
|
|
|
perror("failed");
|
2008-12-07 08:24:56 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (raw1394_loop_iterate(handle))
|
|
|
|
perror("failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n > 0) {
|
|
|
|
printf("\n - using standard tag handler and synchronous calls\n");
|
|
|
|
raw1394_set_tag_handler(handle, std_handler);
|
|
|
|
}
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
printf(" read from node %d... ", i);
|
|
|
|
fflush(stdout);
|
|
|
|
buffer = 0;
|
|
|
|
|
|
|
|
retval = raw1394_read(handle, 0xffc0 | i, TESTADDR, 4, &buffer);
|
|
|
|
if (retval < 0)
|
|
|
|
perror("failed with error");
|
|
|
|
else
|
|
|
|
printf("completed with value 0x%08x\n", buffer);
|
|
|
|
}
|
1999-12-02 18:07:38 -05:00
|
|
|
|
2007-03-26 16:49:12 -04:00
|
|
|
test_fcp(handle);
|
|
|
|
read_topology_map(handle);
|
2008-12-07 08:24:56 -05:00
|
|
|
test_config_rom(handle);
|
2002-10-23 17:18:49 -04:00
|
|
|
|
2008-12-07 08:24:56 -05:00
|
|
|
printf("\n - posting 0xdeadbeef as an echo request\n");
|
2007-03-26 16:49:12 -04:00
|
|
|
raw1394_echo_request(handle, 0xdeadbeef);
|
2002-10-23 17:18:49 -04:00
|
|
|
|
2008-12-07 08:24:56 -05:00
|
|
|
printf(" polling for leftover messages\n");
|
|
|
|
pfd.fd = raw1394_get_fd(handle);
|
|
|
|
pfd.events = POLLIN;
|
|
|
|
pfd.revents = 0;
|
|
|
|
while (1) {
|
|
|
|
retval = poll(&pfd, 1, 10);
|
|
|
|
if (retval < 1)
|
|
|
|
break;
|
2007-03-26 16:49:12 -04:00
|
|
|
retval = raw1394_loop_iterate(handle);
|
|
|
|
if (retval != 0)
|
2008-12-07 08:24:56 -05:00
|
|
|
printf(" raw1394_loop_iterate() returned 0x%08x\n",
|
|
|
|
retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval < 0)
|
|
|
|
perror("poll failed");
|
|
|
|
out:
|
|
|
|
raw1394_destroy_handle(handle);
|
|
|
|
return numcards;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int card = 0, numcards;
|
|
|
|
|
|
|
|
do
|
|
|
|
numcards = test_card(card);
|
|
|
|
while (++card < numcards);
|
2000-03-16 17:22:05 -05:00
|
|
|
|
2008-12-07 08:24:56 -05:00
|
|
|
return numcards < 0;
|
1999-12-02 18:07:38 -05:00
|
|
|
}
|