2002-12-30 10:13:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2002
|
|
|
|
* Hidetoshi Shimokawa. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
*
|
|
|
|
* This product includes software developed by Hidetoshi Shimokawa.
|
|
|
|
*
|
|
|
|
* 4. Neither the name of the author nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2008-12-12 18:17:23 +00:00
|
|
|
#if defined(__FreeBSD__)
|
2005-05-20 12:50:47 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2008-12-12 18:17:23 +00:00
|
|
|
#endif
|
2005-05-20 12:50:47 +00:00
|
|
|
|
2002-12-30 10:13:16 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/malloc.h>
|
2005-05-20 12:50:47 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
2002-12-30 10:13:16 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
2008-12-12 18:17:23 +00:00
|
|
|
#if defined(__FreeBSD__)
|
2004-05-26 22:59:55 +00:00
|
|
|
#include <sys/eui64.h>
|
2002-12-30 10:13:16 +00:00
|
|
|
#include <dev/firewire/firewire.h>
|
|
|
|
#include <dev/firewire/iec13213.h>
|
2003-09-25 09:33:16 +00:00
|
|
|
#include <dev/firewire/fwphyreg.h>
|
2006-10-26 22:33:38 +00:00
|
|
|
#include <dev/firewire/iec68113.h>
|
2008-12-12 18:17:23 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
#include "eui64.h"
|
|
|
|
#include <dev/ieee1394/firewire.h>
|
|
|
|
#include <dev/ieee1394/iec13213.h>
|
|
|
|
#include <dev/ieee1394/fwphyreg.h>
|
|
|
|
#include <dev/ieee1394/iec68113.h>
|
|
|
|
#else
|
|
|
|
#warning "You need to add support for your OS"
|
|
|
|
#endif
|
|
|
|
|
2002-12-30 10:13:16 +00:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-10-26 22:33:38 +00:00
|
|
|
#include <sysexits.h>
|
2002-12-30 10:13:16 +00:00
|
|
|
#include <unistd.h>
|
2008-09-10 18:09:52 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2006-10-26 22:33:38 +00:00
|
|
|
#include "fwmethods.h"
|
2002-12-30 10:13:16 +00:00
|
|
|
|
2006-10-26 22:33:38 +00:00
|
|
|
static void sysctl_set_int(const char *, int);
|
2005-05-20 12:50:47 +00:00
|
|
|
|
2003-01-04 10:32:31 +00:00
|
|
|
static void
|
2002-12-30 10:13:16 +00:00
|
|
|
usage(void)
|
|
|
|
{
|
2003-01-24 03:40:36 +00:00
|
|
|
fprintf(stderr,
|
2008-12-12 18:17:23 +00:00
|
|
|
"%s [-u bus_num] [-prt] [-c node] [-d node] [-o node] [-s node]\n"
|
2008-09-10 18:09:52 +00:00
|
|
|
"\t [-l file] [-g gap_count] [-f force_root ] [-b pri_req]\n"
|
|
|
|
"\t [-M mode] [-R filename] [-S filename] [-m EUI64 | hostname]\n"
|
2003-08-05 03:26:14 +00:00
|
|
|
"\t-u: specify bus number\n"
|
2008-09-10 18:09:52 +00:00
|
|
|
"\t-p: Display current PHY register settings\n"
|
2003-04-29 13:49:21 +00:00
|
|
|
"\t-r: bus reset\n"
|
|
|
|
"\t-t: read topology map\n"
|
2008-09-10 18:09:52 +00:00
|
|
|
"\t-c: read configuration ROM\n"
|
2003-04-29 13:49:21 +00:00
|
|
|
"\t-d: hex dump of configuration ROM\n"
|
2008-09-10 18:09:52 +00:00
|
|
|
"\t-o: send link-on packet to the node\n"
|
|
|
|
"\t-s: write RESET_START register on the node\n"
|
2003-04-29 13:49:21 +00:00
|
|
|
"\t-l: load and parse hex dump file of configuration ROM\n"
|
2008-12-12 18:17:23 +00:00
|
|
|
"\t-g: set gap count\n"
|
|
|
|
"\t-f: force root node\n"
|
2008-09-10 18:09:52 +00:00
|
|
|
"\t-b: set PRIORITY_BUDGET register on all supported nodes\n"
|
|
|
|
"\t-M: specify dv or mpeg\n"
|
2006-10-26 22:33:38 +00:00
|
|
|
"\t-R: Receive DV or MPEG TS stream\n"
|
2004-10-29 01:24:32 +00:00
|
|
|
"\t-S: Send DV stream\n"
|
2008-12-12 18:17:23 +00:00
|
|
|
"\t-m: set fwmem target\n"
|
|
|
|
, getprogname() );
|
|
|
|
fprintf(stderr, "\n");
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
|
|
|
|
2004-05-26 22:59:55 +00:00
|
|
|
static void
|
|
|
|
fweui2eui64(const struct fw_eui64 *fweui, struct eui64 *eui)
|
|
|
|
{
|
|
|
|
*(u_int32_t*)&(eui->octet[0]) = htonl(fweui->hi);
|
|
|
|
*(u_int32_t*)&(eui->octet[4]) = htonl(fweui->lo);
|
|
|
|
}
|
|
|
|
|
2008-09-10 18:09:52 +00:00
|
|
|
static void
|
|
|
|
get_dev(int fd, struct fw_devlstreq *data)
|
2002-12-30 10:13:16 +00:00
|
|
|
{
|
2003-01-25 14:47:33 +00:00
|
|
|
if (data == NULL)
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_SOFTWARE, "%s: data malloc", __func__);
|
2002-12-30 10:13:16 +00:00
|
|
|
if( ioctl(fd, FW_GDEVLST, data) < 0) {
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl", __func__);
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-26 22:59:55 +00:00
|
|
|
static int
|
|
|
|
str2node(int fd, const char *nodestr)
|
|
|
|
{
|
|
|
|
struct eui64 eui, tmpeui;
|
|
|
|
struct fw_devlstreq *data;
|
|
|
|
char *endptr;
|
|
|
|
int i, node;
|
|
|
|
|
|
|
|
if (nodestr == '\0')
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deal with classic node specifications.
|
|
|
|
*/
|
|
|
|
node = strtol(nodestr, &endptr, 0);
|
|
|
|
if (*endptr == '\0')
|
|
|
|
goto gotnode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to get an eui and match it against available nodes.
|
|
|
|
*/
|
|
|
|
if (eui64_hostton(nodestr, &eui) != 0 && eui64_aton(nodestr, &eui) != 0)
|
|
|
|
return (-1);
|
|
|
|
|
2008-09-10 18:09:52 +00:00
|
|
|
data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
|
|
|
|
if (data == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s: data malloc", __func__);
|
|
|
|
get_dev(fd,data);
|
2004-05-26 22:59:55 +00:00
|
|
|
|
|
|
|
for (i = 0; i < data->info_len; i++) {
|
|
|
|
fweui2eui64(&data->dev[i].eui, &tmpeui);
|
|
|
|
if (memcmp(&eui, &tmpeui, sizeof(struct eui64)) == 0) {
|
|
|
|
node = data->dev[i].dst;
|
2011-12-21 20:27:41 +00:00
|
|
|
free(data);
|
2004-05-26 22:59:55 +00:00
|
|
|
goto gotnode;
|
|
|
|
}
|
|
|
|
}
|
2008-09-10 18:09:52 +00:00
|
|
|
if (i >= data->info_len) {
|
|
|
|
if (data != NULL)
|
|
|
|
free(data);
|
2004-05-26 22:59:55 +00:00
|
|
|
return (-1);
|
2008-09-10 18:09:52 +00:00
|
|
|
}
|
2004-05-26 22:59:55 +00:00
|
|
|
|
|
|
|
gotnode:
|
|
|
|
if (node < 0 || node > 63)
|
|
|
|
return (-1);
|
|
|
|
else
|
|
|
|
return (node);
|
|
|
|
}
|
|
|
|
|
2003-01-04 10:32:31 +00:00
|
|
|
static void
|
2002-12-30 10:13:16 +00:00
|
|
|
list_dev(int fd)
|
|
|
|
{
|
2003-01-25 14:47:33 +00:00
|
|
|
struct fw_devlstreq *data;
|
|
|
|
struct fw_devinfo *devinfo;
|
2004-05-26 22:59:55 +00:00
|
|
|
struct eui64 eui;
|
2008-03-05 01:30:48 +00:00
|
|
|
char addr[EUI64_SIZ], hostname[40];
|
2002-12-30 10:13:16 +00:00
|
|
|
int i;
|
|
|
|
|
2008-09-10 18:09:52 +00:00
|
|
|
data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
|
|
|
|
if (data == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:data malloc", __func__);
|
|
|
|
get_dev(fd, data);
|
2003-01-25 14:47:33 +00:00
|
|
|
printf("%d devices (info_len=%d)\n", data->n, data->info_len);
|
2008-03-05 01:30:48 +00:00
|
|
|
printf("node EUI64 status hostname\n");
|
2003-01-25 14:47:33 +00:00
|
|
|
for (i = 0; i < data->info_len; i++) {
|
|
|
|
devinfo = &data->dev[i];
|
2004-05-26 22:59:55 +00:00
|
|
|
fweui2eui64(&devinfo->eui, &eui);
|
|
|
|
eui64_ntoa(&eui, addr, sizeof(addr));
|
2008-03-05 01:30:48 +00:00
|
|
|
if (eui64_ntohost(hostname, sizeof(hostname), &eui))
|
|
|
|
hostname[0] = 0;
|
|
|
|
printf("%4d %s %6d %s\n",
|
2003-02-09 07:26:48 +00:00
|
|
|
(devinfo->status || i == 0) ? devinfo->dst : -1,
|
2004-05-26 22:59:55 +00:00
|
|
|
addr,
|
2008-03-05 01:30:48 +00:00
|
|
|
devinfo->status,
|
|
|
|
hostname
|
2002-12-30 10:13:16 +00:00
|
|
|
);
|
|
|
|
}
|
2003-01-25 14:47:33 +00:00
|
|
|
free((void *)data);
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
|
|
|
|
2003-01-04 10:32:31 +00:00
|
|
|
static u_int32_t
|
2005-05-20 12:50:47 +00:00
|
|
|
read_write_quad(int fd, struct fw_eui64 eui, u_int32_t addr_lo, int readmode, u_int32_t data)
|
2002-12-30 10:13:16 +00:00
|
|
|
{
|
|
|
|
struct fw_asyreq *asyreq;
|
|
|
|
u_int32_t *qld, res;
|
|
|
|
|
|
|
|
asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16);
|
2008-09-10 18:09:52 +00:00
|
|
|
if (asyreq == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
|
2002-12-30 10:13:16 +00:00
|
|
|
asyreq->req.len = 16;
|
2003-04-29 13:49:21 +00:00
|
|
|
#if 0
|
|
|
|
asyreq->req.type = FWASREQNODE;
|
|
|
|
asyreq->pkt.mode.rreqq.dst = FWLOCALBUS | node;
|
|
|
|
#else
|
2002-12-30 10:13:16 +00:00
|
|
|
asyreq->req.type = FWASREQEUI;
|
|
|
|
asyreq->req.dst.eui = eui;
|
|
|
|
#endif
|
|
|
|
asyreq->pkt.mode.rreqq.tlrt = 0;
|
2005-05-20 12:50:47 +00:00
|
|
|
if (readmode)
|
2002-12-30 10:13:16 +00:00
|
|
|
asyreq->pkt.mode.rreqq.tcode = FWTCODE_RREQQ;
|
|
|
|
else
|
|
|
|
asyreq->pkt.mode.rreqq.tcode = FWTCODE_WREQQ;
|
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
asyreq->pkt.mode.rreqq.dest_hi = 0xffff;
|
|
|
|
asyreq->pkt.mode.rreqq.dest_lo = addr_lo;
|
2002-12-30 10:13:16 +00:00
|
|
|
|
|
|
|
qld = (u_int32_t *)&asyreq->pkt;
|
2005-05-20 12:50:47 +00:00
|
|
|
if (!readmode)
|
2008-03-05 01:30:48 +00:00
|
|
|
asyreq->pkt.mode.wreqq.data = htonl(data);
|
2002-12-30 10:13:16 +00:00
|
|
|
|
|
|
|
if (ioctl(fd, FW_ASYREQ, asyreq) < 0) {
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl", __func__);
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
|
|
|
res = qld[3];
|
|
|
|
free(asyreq);
|
2005-05-20 12:50:47 +00:00
|
|
|
if (readmode)
|
2002-12-30 10:13:16 +00:00
|
|
|
return ntohl(res);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2003-01-04 10:32:31 +00:00
|
|
|
|
2008-09-10 18:09:52 +00:00
|
|
|
/*
|
|
|
|
* Send a PHY Config Packet
|
|
|
|
* ieee 1394a-2005 4.3.4.3
|
|
|
|
*
|
|
|
|
* Message ID Root ID R T Gap Count
|
|
|
|
* 00(2 bits) (6 bits) 1 1 (6 bits)
|
|
|
|
*
|
|
|
|
* if "R" is set, then Root ID will be the next
|
|
|
|
* root node upon the next bus reset.
|
|
|
|
* if "T" is set, then Gap Count will be the
|
|
|
|
* value that all nodes use for their Gap Count
|
|
|
|
* if "R" and "T" are not set, then this message
|
|
|
|
* is either ignored or interpreted as an extended
|
|
|
|
* PHY config Packet as per 1394a-2005 4.3.4.4
|
|
|
|
*/
|
2003-01-04 10:32:31 +00:00
|
|
|
static void
|
2002-12-30 10:13:16 +00:00
|
|
|
send_phy_config(int fd, int root_node, int gap_count)
|
|
|
|
{
|
|
|
|
struct fw_asyreq *asyreq;
|
|
|
|
|
|
|
|
asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12);
|
2008-09-10 18:09:52 +00:00
|
|
|
if (asyreq == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
|
2002-12-30 10:13:16 +00:00
|
|
|
asyreq->req.len = 12;
|
|
|
|
asyreq->req.type = FWASREQNODE;
|
|
|
|
asyreq->pkt.mode.ld[0] = 0;
|
|
|
|
asyreq->pkt.mode.ld[1] = 0;
|
|
|
|
asyreq->pkt.mode.common.tcode = FWTCODE_PHY;
|
|
|
|
if (root_node >= 0)
|
2008-09-10 18:09:52 +00:00
|
|
|
asyreq->pkt.mode.ld[1] |= ((root_node << 24) | (1 << 23));
|
2002-12-30 10:13:16 +00:00
|
|
|
if (gap_count >= 0)
|
2008-09-10 18:09:52 +00:00
|
|
|
asyreq->pkt.mode.ld[1] |= ((1 << 22) | (gap_count << 16));
|
2002-12-30 10:13:16 +00:00
|
|
|
asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1];
|
|
|
|
|
|
|
|
printf("send phy_config root_node=%d gap_count=%d\n",
|
|
|
|
root_node, gap_count);
|
|
|
|
|
2003-04-30 03:38:07 +00:00
|
|
|
if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl", __func__);
|
2003-04-30 03:38:07 +00:00
|
|
|
free(asyreq);
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
|
|
|
|
2003-04-29 13:49:21 +00:00
|
|
|
static void
|
2008-09-10 18:09:52 +00:00
|
|
|
link_on(int fd, int node)
|
2003-04-29 13:49:21 +00:00
|
|
|
{
|
|
|
|
struct fw_asyreq *asyreq;
|
|
|
|
|
|
|
|
asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12);
|
2008-09-10 18:09:52 +00:00
|
|
|
if (asyreq == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
|
2003-04-29 13:49:21 +00:00
|
|
|
asyreq->req.len = 12;
|
|
|
|
asyreq->req.type = FWASREQNODE;
|
|
|
|
asyreq->pkt.mode.common.tcode = FWTCODE_PHY;
|
|
|
|
asyreq->pkt.mode.ld[1] |= (1 << 30) | ((node & 0x3f) << 24);
|
|
|
|
asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1];
|
|
|
|
|
2003-04-30 03:38:07 +00:00
|
|
|
if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl", __func__);
|
2003-04-30 03:38:07 +00:00
|
|
|
free(asyreq);
|
2003-04-29 13:49:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reset_start(int fd, int node)
|
|
|
|
{
|
|
|
|
struct fw_asyreq *asyreq;
|
|
|
|
|
|
|
|
asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16);
|
2008-09-10 18:09:52 +00:00
|
|
|
if (asyreq == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
|
2003-04-29 13:49:21 +00:00
|
|
|
asyreq->req.len = 16;
|
|
|
|
asyreq->req.type = FWASREQNODE;
|
|
|
|
asyreq->pkt.mode.wreqq.dst = FWLOCALBUS | (node & 0x3f);
|
|
|
|
asyreq->pkt.mode.wreqq.tlrt = 0;
|
|
|
|
asyreq->pkt.mode.wreqq.tcode = FWTCODE_WREQQ;
|
|
|
|
|
|
|
|
asyreq->pkt.mode.wreqq.dest_hi = 0xffff;
|
|
|
|
asyreq->pkt.mode.wreqq.dest_lo = 0xf0000000 | RESET_START;
|
|
|
|
|
|
|
|
asyreq->pkt.mode.wreqq.data = htonl(0x1);
|
|
|
|
|
2003-04-30 03:38:07 +00:00
|
|
|
if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl", __func__);
|
2003-04-30 03:38:07 +00:00
|
|
|
free(asyreq);
|
2003-04-29 13:49:21 +00:00
|
|
|
}
|
|
|
|
|
2003-01-04 10:32:31 +00:00
|
|
|
static void
|
2006-10-26 22:33:38 +00:00
|
|
|
set_pri_req(int fd, u_int32_t pri_req)
|
2002-12-30 10:13:16 +00:00
|
|
|
{
|
2003-01-25 14:47:33 +00:00
|
|
|
struct fw_devlstreq *data;
|
|
|
|
struct fw_devinfo *devinfo;
|
2004-05-26 22:59:55 +00:00
|
|
|
struct eui64 eui;
|
|
|
|
char addr[EUI64_SIZ];
|
2002-12-30 10:13:16 +00:00
|
|
|
u_int32_t max, reg, old;
|
|
|
|
int i;
|
|
|
|
|
2008-09-10 18:09:52 +00:00
|
|
|
data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
|
|
|
|
if (data == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:data malloc", __func__);
|
|
|
|
get_dev(fd, data);
|
2002-12-30 10:13:16 +00:00
|
|
|
#define BUGET_REG 0xf0000218
|
2003-01-25 14:47:33 +00:00
|
|
|
for (i = 0; i < data->info_len; i++) {
|
|
|
|
devinfo = &data->dev[i];
|
|
|
|
if (!devinfo->status)
|
2002-12-30 10:13:16 +00:00
|
|
|
continue;
|
2003-01-25 14:47:33 +00:00
|
|
|
reg = read_write_quad(fd, devinfo->eui, BUGET_REG, 1, 0);
|
2004-05-26 22:59:55 +00:00
|
|
|
fweui2eui64(&devinfo->eui, &eui);
|
|
|
|
eui64_ntoa(&eui, addr, sizeof(addr));
|
|
|
|
printf("%d %s, %08x",
|
|
|
|
devinfo->dst, addr, reg);
|
2006-10-26 22:33:38 +00:00
|
|
|
if (reg > 0) {
|
2002-12-30 10:13:16 +00:00
|
|
|
old = (reg & 0x3f);
|
|
|
|
max = (reg & 0x3f00) >> 8;
|
|
|
|
if (pri_req > max)
|
|
|
|
pri_req = max;
|
|
|
|
printf(" 0x%x -> 0x%x\n", old, pri_req);
|
2003-01-25 14:47:33 +00:00
|
|
|
read_write_quad(fd, devinfo->eui, BUGET_REG, 0, pri_req);
|
2002-12-30 10:13:16 +00:00
|
|
|
} else {
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
2003-01-25 14:47:33 +00:00
|
|
|
free((void *)data);
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
|
|
|
|
2003-01-04 10:32:31 +00:00
|
|
|
static void
|
2006-10-26 22:33:38 +00:00
|
|
|
parse_bus_info_block(u_int32_t *p)
|
2002-12-30 10:13:16 +00:00
|
|
|
{
|
2004-05-26 22:59:55 +00:00
|
|
|
char addr[EUI64_SIZ];
|
2003-06-10 02:32:22 +00:00
|
|
|
struct bus_info *bi;
|
2004-05-26 22:59:55 +00:00
|
|
|
struct eui64 eui;
|
2003-06-10 02:32:22 +00:00
|
|
|
|
|
|
|
bi = (struct bus_info *)p;
|
2004-05-26 22:59:55 +00:00
|
|
|
fweui2eui64(&bi->eui64, &eui);
|
|
|
|
eui64_ntoa(&eui, addr, sizeof(addr));
|
2003-06-10 02:32:22 +00:00
|
|
|
printf("bus_name: 0x%04x\n"
|
|
|
|
"irmc:%d cmc:%d isc:%d bmc:%d pmc:%d\n"
|
|
|
|
"cyc_clk_acc:%d max_rec:%d max_rom:%d\n"
|
|
|
|
"generation:%d link_spd:%d\n"
|
2004-05-26 22:59:55 +00:00
|
|
|
"EUI64: %s\n",
|
2003-06-10 02:32:22 +00:00
|
|
|
bi->bus_name,
|
|
|
|
bi->irmc, bi->cmc, bi->isc, bi->bmc, bi->pmc,
|
|
|
|
bi->cyc_clk_acc, bi->max_rec, bi->max_rom,
|
|
|
|
bi->generation, bi->link_spd,
|
2004-05-26 22:59:55 +00:00
|
|
|
addr);
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
|
|
|
|
2003-01-04 10:32:31 +00:00
|
|
|
static int
|
2002-12-30 10:13:16 +00:00
|
|
|
get_crom(int fd, int node, void *crom_buf, int len)
|
|
|
|
{
|
|
|
|
struct fw_crom_buf buf;
|
2003-01-28 17:00:23 +00:00
|
|
|
int i, error;
|
2003-01-25 14:47:33 +00:00
|
|
|
struct fw_devlstreq *data;
|
2002-12-30 10:13:16 +00:00
|
|
|
|
2008-09-10 18:09:52 +00:00
|
|
|
data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
|
|
|
|
if (data == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:data malloc", __func__);
|
|
|
|
get_dev(fd, data);
|
2002-12-30 10:13:16 +00:00
|
|
|
|
2003-01-25 14:47:33 +00:00
|
|
|
for (i = 0; i < data->info_len; i++) {
|
|
|
|
if (data->dev[i].dst == node && data->dev[i].eui.lo != 0)
|
2002-12-30 10:13:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-01-25 14:47:33 +00:00
|
|
|
if (i == data->info_len)
|
|
|
|
errx(1, "no such node %d.", node);
|
|
|
|
else
|
|
|
|
buf.eui = data->dev[i].eui;
|
|
|
|
free((void *)data);
|
2002-12-30 10:13:16 +00:00
|
|
|
|
|
|
|
buf.len = len;
|
|
|
|
buf.ptr = crom_buf;
|
2003-07-12 09:36:53 +00:00
|
|
|
bzero(crom_buf, len);
|
2002-12-30 10:13:16 +00:00
|
|
|
if ((error = ioctl(fd, FW_GCROM, &buf)) < 0) {
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl", __func__);
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
2003-01-25 14:47:33 +00:00
|
|
|
|
2002-12-30 10:13:16 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2003-01-04 10:32:31 +00:00
|
|
|
static void
|
2002-12-30 10:13:16 +00:00
|
|
|
show_crom(u_int32_t *crom_buf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct crom_context cc;
|
|
|
|
char *desc, info[256];
|
2005-05-20 12:50:47 +00:00
|
|
|
static const char *key_types = "ICLD";
|
2002-12-30 10:13:16 +00:00
|
|
|
struct csrreg *reg;
|
|
|
|
struct csrdirectory *dir;
|
|
|
|
struct csrhdr *hdr;
|
2003-04-17 03:38:03 +00:00
|
|
|
u_int16_t crc;
|
2002-12-30 10:13:16 +00:00
|
|
|
|
2003-04-17 03:38:03 +00:00
|
|
|
printf("first quad: 0x%08x ", *crom_buf);
|
2004-10-23 23:28:08 +00:00
|
|
|
if (crom_buf[0] == 0) {
|
|
|
|
printf("(Invalid Configuration ROM)\n");
|
|
|
|
return;
|
|
|
|
}
|
2002-12-30 10:13:16 +00:00
|
|
|
hdr = (struct csrhdr *)crom_buf;
|
|
|
|
if (hdr->info_len == 1) {
|
|
|
|
/* minimum ROM */
|
|
|
|
reg = (struct csrreg *)hdr;
|
|
|
|
printf("verndor ID: 0x%06x\n", reg->val);
|
|
|
|
return;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
printf("info_len=%d crc_len=%d crc=0x%04x",
|
|
|
|
hdr->info_len, hdr->crc_len, hdr->crc);
|
|
|
|
crc = crom_crc(crom_buf+1, hdr->crc_len);
|
|
|
|
if (crc == hdr->crc)
|
|
|
|
printf("(OK)\n");
|
|
|
|
else
|
|
|
|
printf("(NG)\n");
|
2006-10-26 22:33:38 +00:00
|
|
|
parse_bus_info_block(crom_buf+1);
|
2002-12-30 10:13:16 +00:00
|
|
|
|
|
|
|
crom_init_context(&cc, crom_buf);
|
|
|
|
dir = cc.stack[0].dir;
|
2004-05-23 10:06:33 +00:00
|
|
|
if (!dir) {
|
|
|
|
printf("no root directory - giving up\n");
|
|
|
|
return;
|
|
|
|
}
|
2003-04-17 03:38:03 +00:00
|
|
|
printf("root_directory: len=0x%04x(%d) crc=0x%04x",
|
2002-12-30 10:13:16 +00:00
|
|
|
dir->crc_len, dir->crc_len, dir->crc);
|
2003-04-17 03:38:03 +00:00
|
|
|
crc = crom_crc((u_int32_t *)&dir->entry[0], dir->crc_len);
|
|
|
|
if (crc == dir->crc)
|
|
|
|
printf("(OK)\n");
|
|
|
|
else
|
|
|
|
printf("(NG)\n");
|
2003-01-04 10:32:31 +00:00
|
|
|
if (dir->crc_len < 1)
|
|
|
|
return;
|
2002-12-30 10:13:16 +00:00
|
|
|
while (cc.depth >= 0) {
|
|
|
|
desc = crom_desc(&cc, info, sizeof(info));
|
|
|
|
reg = crom_get(&cc);
|
|
|
|
for (i = 0; i < cc.depth; i++)
|
|
|
|
printf("\t");
|
|
|
|
printf("%02x(%c:%02x) %06x %s: %s\n",
|
|
|
|
reg->key,
|
|
|
|
key_types[(reg->key & CSRTYPE_MASK)>>6],
|
|
|
|
reg->key & CSRKEY_MASK, reg->val,
|
|
|
|
desc, info);
|
|
|
|
crom_next(&cc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DUMP_FORMAT "%08x %08x %08x %08x %08x %08x %08x %08x\n"
|
|
|
|
|
2003-01-04 10:32:31 +00:00
|
|
|
static void
|
2002-12-30 10:13:16 +00:00
|
|
|
dump_crom(u_int32_t *p)
|
|
|
|
{
|
|
|
|
int len=1024, i;
|
|
|
|
|
|
|
|
for (i = 0; i < len/(4*8); i ++) {
|
|
|
|
printf(DUMP_FORMAT,
|
|
|
|
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
|
|
|
|
p += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-04 10:32:31 +00:00
|
|
|
static void
|
2002-12-30 10:13:16 +00:00
|
|
|
load_crom(char *filename, u_int32_t *p)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
int len=1024, i;
|
|
|
|
|
|
|
|
if ((file = fopen(filename, "r")) == NULL)
|
2008-12-12 18:17:23 +00:00
|
|
|
err(1, "load_crom %s", filename);
|
2002-12-30 10:13:16 +00:00
|
|
|
for (i = 0; i < len/(4*8); i ++) {
|
|
|
|
fscanf(file, DUMP_FORMAT,
|
|
|
|
p, p+1, p+2, p+3, p+4, p+5, p+6, p+7);
|
|
|
|
p += 8;
|
|
|
|
}
|
2010-12-09 08:36:23 +00:00
|
|
|
fclose(file);
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_topology_map(int fd)
|
|
|
|
{
|
|
|
|
struct fw_topology_map *tmap;
|
|
|
|
union fw_self_id sid;
|
|
|
|
int i;
|
2005-05-20 12:50:47 +00:00
|
|
|
static const char *port_status[] = {" ", "-", "P", "C"};
|
|
|
|
static const char *pwr_class[] = {" 0W", "15W", "30W", "45W",
|
2002-12-30 10:13:16 +00:00
|
|
|
"-1W", "-2W", "-5W", "-9W"};
|
2005-05-20 12:50:47 +00:00
|
|
|
static const char *speed[] = {"S100", "S200", "S400", "S800"};
|
2002-12-30 10:13:16 +00:00
|
|
|
tmap = malloc(sizeof(struct fw_topology_map));
|
|
|
|
if (tmap == NULL)
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_SOFTWARE, "%s:tmap malloc", __func__);
|
2002-12-30 10:13:16 +00:00
|
|
|
if (ioctl(fd, FW_GTPMAP, tmap) < 0) {
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl", __func__);
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
|
|
|
printf("crc_len: %d generation:%d node_count:%d sid_count:%d\n",
|
|
|
|
tmap->crc_len, tmap->generation,
|
|
|
|
tmap->node_count, tmap->self_id_count);
|
|
|
|
printf("id link gap_cnt speed delay cIRM power port0 port1 port2"
|
|
|
|
" ini more\n");
|
|
|
|
for (i = 0; i < tmap->crc_len - 2; i++) {
|
|
|
|
sid = tmap->self_id[i];
|
|
|
|
if (sid.p0.sequel) {
|
|
|
|
printf("%02d sequel packet\n", sid.p0.phy_id);
|
|
|
|
continue;
|
|
|
|
}
|
2009-02-17 23:56:16 +00:00
|
|
|
printf("%02d %2d %2d %4s %d %3s"
|
2002-12-30 10:13:16 +00:00
|
|
|
" %s %s %s %d %d\n",
|
|
|
|
sid.p0.phy_id,
|
|
|
|
sid.p0.link_active,
|
|
|
|
sid.p0.gap_count,
|
|
|
|
speed[sid.p0.phy_speed],
|
|
|
|
sid.p0.contender,
|
|
|
|
pwr_class[sid.p0.power_class],
|
|
|
|
port_status[sid.p0.port0],
|
|
|
|
port_status[sid.p0.port1],
|
|
|
|
port_status[sid.p0.port2],
|
|
|
|
sid.p0.initiated_reset,
|
|
|
|
sid.p0.more_packets
|
|
|
|
);
|
|
|
|
}
|
|
|
|
free(tmap);
|
|
|
|
}
|
|
|
|
|
2003-09-25 09:33:16 +00:00
|
|
|
static void
|
|
|
|
read_phy_registers(int fd, u_int8_t *buf, int offset, int len)
|
|
|
|
{
|
|
|
|
struct fw_reg_req_t reg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
reg.addr = offset + i;
|
|
|
|
if (ioctl(fd, FWOHCI_RDPHYREG, ®) < 0)
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl", __func__);
|
2003-09-25 09:33:16 +00:00
|
|
|
buf[i] = (u_int8_t) reg.data;
|
|
|
|
printf("0x%02x ", reg.data);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
read_phy_page(int fd, u_int8_t *buf, int page, int port)
|
|
|
|
{
|
|
|
|
struct fw_reg_req_t reg;
|
|
|
|
|
|
|
|
reg.addr = 0x7;
|
|
|
|
reg.data = ((page & 7) << 5) | (port & 0xf);
|
|
|
|
if (ioctl(fd, FWOHCI_WRPHYREG, ®) < 0)
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl", __func__);
|
2003-09-25 09:33:16 +00:00
|
|
|
read_phy_registers(fd, buf, 8, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_phy_registers(int fd)
|
|
|
|
{
|
|
|
|
struct phyreg_base b;
|
|
|
|
struct phyreg_page0 p;
|
|
|
|
struct phyreg_page1 v;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("=== base register ===\n");
|
|
|
|
read_phy_registers(fd, (u_int8_t *)&b, 0, 8);
|
|
|
|
printf(
|
|
|
|
"Physical_ID:%d R:%d CPS:%d\n"
|
|
|
|
"RHB:%d IBR:%d Gap_Count:%d\n"
|
|
|
|
"Extended:%d Num_Ports:%d\n"
|
|
|
|
"PHY_Speed:%d Delay:%d\n"
|
|
|
|
"LCtrl:%d C:%d Jitter:%d Pwr_Class:%d\n"
|
|
|
|
"WDIE:%d ISBR:%d CTOI:%d CPSI:%d STOI:%d PEI:%d EAA:%d EMC:%d\n"
|
|
|
|
"Max_Legacy_SPD:%d BLINK:%d Bridge:%d\n"
|
|
|
|
"Page_Select:%d Port_Select%d\n",
|
|
|
|
b.phy_id, b.r, b.cps,
|
|
|
|
b.rhb, b.ibr, b.gap_count,
|
|
|
|
b.extended, b.num_ports,
|
|
|
|
b.phy_speed, b.delay,
|
|
|
|
b.lctrl, b.c, b.jitter, b.pwr_class,
|
|
|
|
b.wdie, b.isbr, b.ctoi, b.cpsi, b.stoi, b.pei, b.eaa, b.emc,
|
|
|
|
b.legacy_spd, b.blink, b.bridge,
|
|
|
|
b.page_select, b.port_select
|
|
|
|
);
|
|
|
|
|
|
|
|
for (i = 0; i < b.num_ports; i ++) {
|
|
|
|
printf("\n=== page 0 port %d ===\n", i);
|
|
|
|
read_phy_page(fd, (u_int8_t *)&p, 0, i);
|
|
|
|
printf(
|
|
|
|
"Astat:%d BStat:%d Ch:%d Con:%d RXOK:%d Dis:%d\n"
|
|
|
|
"Negotiated_speed:%d PIE:%d Fault:%d Stanby_fault:%d Disscrm:%d B_Only:%d\n"
|
|
|
|
"DC_connected:%d Max_port_speed:%d LPP:%d Cable_speed:%d\n"
|
|
|
|
"Connection_unreliable:%d Beta_mode:%d\n"
|
|
|
|
"Port_error:0x%x\n"
|
|
|
|
"Loop_disable:%d In_standby:%d Hard_disable:%d\n",
|
|
|
|
p.astat, p.bstat, p.ch, p.con, p.rxok, p.dis,
|
|
|
|
p.negotiated_speed, p.pie, p.fault, p.stanby_fault, p.disscrm, p.b_only,
|
|
|
|
p.dc_connected, p.max_port_speed, p.lpp, p.cable_speed,
|
|
|
|
p.connection_unreliable, p.beta_mode,
|
|
|
|
p.port_error,
|
|
|
|
p.loop_disable, p.in_standby, p.hard_disable
|
|
|
|
);
|
|
|
|
}
|
|
|
|
printf("\n=== page 1 ===\n");
|
|
|
|
read_phy_page(fd, (u_int8_t *)&v, 1, 0);
|
|
|
|
printf(
|
|
|
|
"Compliance:%d\n"
|
|
|
|
"Vendor_ID:0x%06x\n"
|
|
|
|
"Product_ID:0x%06x\n",
|
|
|
|
v.compliance,
|
|
|
|
(v.vendor_id[0] << 16) | (v.vendor_id[1] << 8) | v.vendor_id[2],
|
|
|
|
(v.product_id[0] << 16) | (v.product_id[1] << 8) | v.product_id[2]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-09-10 18:09:52 +00:00
|
|
|
static int
|
|
|
|
open_dev(int *fd, char *devname)
|
2003-08-05 03:26:14 +00:00
|
|
|
{
|
|
|
|
if (*fd < 0) {
|
2008-09-10 18:09:52 +00:00
|
|
|
*fd = open(devname, O_RDWR);
|
2003-08-05 03:26:14 +00:00
|
|
|
if (*fd < 0)
|
2008-09-10 18:09:52 +00:00
|
|
|
return(-1);
|
2003-08-05 03:26:14 +00:00
|
|
|
|
|
|
|
}
|
2008-09-10 18:09:52 +00:00
|
|
|
return(0);
|
2003-08-05 03:26:14 +00:00
|
|
|
}
|
|
|
|
|
2006-10-26 22:33:38 +00:00
|
|
|
static void
|
2005-05-20 12:50:47 +00:00
|
|
|
sysctl_set_int(const char *name, int val)
|
2004-10-23 23:28:08 +00:00
|
|
|
{
|
|
|
|
if (sysctlbyname(name, NULL, NULL, &val, sizeof(int)) < 0)
|
|
|
|
err(1, "sysctl %s failed.", name);
|
|
|
|
}
|
|
|
|
|
2006-10-26 22:33:38 +00:00
|
|
|
static fwmethod *
|
|
|
|
detect_recv_fn(int fd, char ich)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
struct fw_isochreq isoreq;
|
|
|
|
struct fw_isobufreq bufreq;
|
|
|
|
int len;
|
|
|
|
u_int32_t *ptr;
|
|
|
|
struct ciphdr *ciph;
|
|
|
|
fwmethod *retfn;
|
2008-09-10 18:09:52 +00:00
|
|
|
#define RECV_NUM_PACKET 16
|
|
|
|
#define RECV_PACKET_SZ 1024
|
2006-10-26 22:33:38 +00:00
|
|
|
|
|
|
|
bufreq.rx.nchunk = 8;
|
2008-09-10 18:09:52 +00:00
|
|
|
bufreq.rx.npacket = RECV_NUM_PACKET;
|
|
|
|
bufreq.rx.psize = RECV_PACKET_SZ;
|
2006-10-26 22:33:38 +00:00
|
|
|
bufreq.tx.nchunk = 0;
|
|
|
|
bufreq.tx.npacket = 0;
|
|
|
|
bufreq.tx.psize = 0;
|
|
|
|
|
|
|
|
if (ioctl(fd, FW_SSTBUF, &bufreq) < 0)
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl FW_SSTBUF", __func__);
|
2006-10-26 22:33:38 +00:00
|
|
|
|
|
|
|
isoreq.ch = ich & 0x3f;
|
|
|
|
isoreq.tag = (ich >> 6) & 3;
|
|
|
|
|
|
|
|
if (ioctl(fd, FW_SRSTREAM, &isoreq) < 0)
|
2008-09-10 18:09:52 +00:00
|
|
|
err(EX_IOERR, "%s: ioctl FW_SRSTREAM", __func__);
|
2006-10-26 22:33:38 +00:00
|
|
|
|
2008-09-10 18:09:52 +00:00
|
|
|
buf = (char *)malloc(RECV_NUM_PACKET * RECV_PACKET_SZ);
|
|
|
|
if (buf == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:buf malloc", __func__);
|
|
|
|
/*
|
|
|
|
* fwdev.c seems to return EIO on error and
|
|
|
|
* the return value of the last uiomove
|
|
|
|
* on success. For now, checking that the
|
|
|
|
* return is not less than zero should be
|
|
|
|
* sufficient. fwdev.c::fw_read() should
|
|
|
|
* return the total length read, not the value
|
|
|
|
* of the last uiomove().
|
|
|
|
*/
|
|
|
|
len = read(fd, buf, RECV_NUM_PACKET * RECV_PACKET_SZ);
|
|
|
|
if (len < 0)
|
2008-12-12 18:17:23 +00:00
|
|
|
err(EX_IOERR, "%s: error reading from device", __func__);
|
2006-10-26 22:33:38 +00:00
|
|
|
ptr = (u_int32_t *) buf;
|
|
|
|
ciph = (struct ciphdr *)(ptr + 1);
|
|
|
|
|
|
|
|
switch(ciph->fmt) {
|
|
|
|
case CIP_FMT_DVCR:
|
|
|
|
fprintf(stderr, "Detected DV format on input.\n");
|
|
|
|
retfn = dvrecv;
|
|
|
|
break;
|
|
|
|
case CIP_FMT_MPEG:
|
|
|
|
fprintf(stderr, "Detected MPEG TS format on input.\n");
|
|
|
|
retfn = mpegtsrecv;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errx(1, "Unsupported format for receiving: fmt=0x%x", ciph->fmt);
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
return retfn;
|
|
|
|
}
|
|
|
|
|
2002-12-30 10:13:16 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2008-09-10 18:09:52 +00:00
|
|
|
#define MAX_BOARDS 10
|
2002-12-30 10:13:16 +00:00
|
|
|
u_int32_t crom_buf[1024/4];
|
2008-09-10 18:09:52 +00:00
|
|
|
u_int32_t crom_buf_hex[1024/4];
|
|
|
|
char devbase[64];
|
|
|
|
const char *device_string = "/dev/fw";
|
|
|
|
int fd = -1, ch, len=1024;
|
|
|
|
int32_t current_board = 0;
|
|
|
|
/*
|
|
|
|
* If !command_set, then -u will display the nodes for the board.
|
|
|
|
* This emulates the previous behavior when -u is passed by itself
|
|
|
|
*/
|
|
|
|
bool command_set = false;
|
|
|
|
bool open_needed = false;
|
2006-10-26 22:33:38 +00:00
|
|
|
long tmp;
|
2004-10-23 23:28:08 +00:00
|
|
|
struct fw_eui64 eui;
|
|
|
|
struct eui64 target;
|
2006-10-26 22:33:38 +00:00
|
|
|
fwmethod *recvfn = NULL;
|
2008-09-10 18:09:52 +00:00
|
|
|
/*
|
|
|
|
* Holders for which functions
|
|
|
|
* to iterate through
|
|
|
|
*/
|
|
|
|
bool display_board_only = false;
|
|
|
|
bool display_crom = false;
|
|
|
|
bool send_bus_reset = false;
|
|
|
|
bool display_crom_hex = false;
|
|
|
|
bool load_crom_from_file = false;
|
|
|
|
bool set_fwmem_target = false;
|
|
|
|
bool dump_topology = false;
|
|
|
|
bool dump_phy_reg = false;
|
|
|
|
|
|
|
|
int32_t priority_budget = -1;
|
|
|
|
int32_t set_root_node = -1;
|
|
|
|
int32_t set_gap_count = -1;
|
|
|
|
int32_t send_link_on = -1;
|
|
|
|
int32_t send_reset_start = -1;
|
|
|
|
|
|
|
|
char *crom_string = NULL;
|
|
|
|
char *crom_string_hex = NULL;
|
|
|
|
char *recv_data = NULL;
|
|
|
|
char *send_data = NULL;
|
2002-12-30 10:13:16 +00:00
|
|
|
|
|
|
|
if (argc < 2) {
|
2008-09-10 18:09:52 +00:00
|
|
|
for (current_board = 0; current_board < MAX_BOARDS; current_board++) {
|
2008-12-12 18:17:23 +00:00
|
|
|
snprintf(devbase, sizeof(devbase), "%s%d.0", device_string, current_board);
|
2008-09-10 18:09:52 +00:00
|
|
|
if (open_dev(&fd, devbase) < 0) {
|
|
|
|
if (current_board == 0) {
|
|
|
|
usage();
|
2008-12-12 18:17:23 +00:00
|
|
|
err(EX_IOERR, "%s: Error opening firewire controller #%d %s",
|
|
|
|
__func__, current_board, devbase);
|
2008-09-10 18:09:52 +00:00
|
|
|
}
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
list_dev(fd);
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
}
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
2008-09-10 18:09:52 +00:00
|
|
|
/*
|
|
|
|
* Parse all command line options, then execute requested operations.
|
|
|
|
*/
|
|
|
|
while ((ch = getopt(argc, argv, "M:f:g:m:o:s:b:prtc:d:l:u:R:S:")) != -1) {
|
2002-12-30 10:13:16 +00:00
|
|
|
switch(ch) {
|
|
|
|
case 'b':
|
2008-09-10 18:09:52 +00:00
|
|
|
priority_budget = strtol(optarg, NULL, 0);
|
|
|
|
if (priority_budget < 0 || priority_budget > INT32_MAX)
|
2008-12-12 18:17:23 +00:00
|
|
|
errx(EX_USAGE, "%s: priority_budget out of range: %s", __func__, optarg);
|
2008-09-10 18:09:52 +00:00
|
|
|
command_set = true;
|
|
|
|
open_needed = true;
|
|
|
|
display_board_only = false;
|
2002-12-30 10:13:16 +00:00
|
|
|
break;
|
|
|
|
case 'c':
|
2008-09-10 18:09:52 +00:00
|
|
|
crom_string = malloc(strlen(optarg)+1);
|
|
|
|
if (crom_string == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:crom_string malloc", __func__);
|
|
|
|
if ( (strtol(crom_string, NULL, 0) < 0) || strtol(crom_string, NULL, 0) > MAX_BOARDS)
|
2008-12-12 18:17:23 +00:00
|
|
|
errx(EX_USAGE, "%s:Invalid value for node", __func__);
|
2008-09-10 18:09:52 +00:00
|
|
|
strcpy(crom_string, optarg);
|
|
|
|
display_crom = 1;
|
|
|
|
open_needed = true;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2002-12-30 10:13:16 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
2008-09-10 18:09:52 +00:00
|
|
|
crom_string_hex = malloc(strlen(optarg)+1);
|
|
|
|
if (crom_string_hex == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:crom_string_hex malloc", __func__);
|
|
|
|
strcpy(crom_string_hex, optarg);
|
|
|
|
display_crom_hex = 1;
|
|
|
|
open_needed = true;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2002-12-30 10:13:16 +00:00
|
|
|
break;
|
2008-03-05 01:30:48 +00:00
|
|
|
case 'f':
|
2008-09-10 18:09:52 +00:00
|
|
|
#define MAX_PHY_CONFIG 0x3f
|
|
|
|
set_root_node = strtol(optarg, NULL, 0);
|
|
|
|
if ( (set_root_node < 0) || (set_root_node > MAX_PHY_CONFIG) )
|
2008-12-12 18:17:23 +00:00
|
|
|
errx(EX_USAGE, "%s:set_root_node out of range", __func__);
|
2008-09-10 18:09:52 +00:00
|
|
|
open_needed = true;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2008-03-05 01:30:48 +00:00
|
|
|
break;
|
2003-08-05 03:26:14 +00:00
|
|
|
case 'g':
|
2008-09-10 18:09:52 +00:00
|
|
|
set_gap_count = strtol(optarg, NULL, 0);
|
|
|
|
if ( (set_gap_count < 0) || (set_gap_count > MAX_PHY_CONFIG) )
|
2008-12-12 18:17:23 +00:00
|
|
|
errx(EX_USAGE, "%s:set_gap_count out of range", __func__);
|
2008-09-10 18:09:52 +00:00
|
|
|
open_needed = true;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2003-08-05 03:26:14 +00:00
|
|
|
break;
|
2002-12-30 10:13:16 +00:00
|
|
|
case 'l':
|
2008-09-10 18:09:52 +00:00
|
|
|
load_crom_from_file = 1;
|
2002-12-30 10:13:16 +00:00
|
|
|
load_crom(optarg, crom_buf);
|
2008-09-10 18:09:52 +00:00
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2002-12-30 10:13:16 +00:00
|
|
|
break;
|
2004-10-23 23:28:08 +00:00
|
|
|
case 'm':
|
2008-09-10 18:09:52 +00:00
|
|
|
set_fwmem_target = 1;
|
|
|
|
open_needed = 0;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
|
|
|
if (eui64_hostton(optarg, &target) != 0 &&
|
|
|
|
eui64_aton(optarg, &target) != 0)
|
2008-12-12 18:17:23 +00:00
|
|
|
errx(EX_USAGE, "%s: invalid target: %s", __func__, optarg);
|
2004-10-23 23:28:08 +00:00
|
|
|
break;
|
2003-08-05 03:26:14 +00:00
|
|
|
case 'o':
|
2008-09-10 18:09:52 +00:00
|
|
|
send_link_on = str2node(fd, optarg);
|
2008-12-12 18:17:23 +00:00
|
|
|
if ( (send_link_on < 0) || (send_link_on > MAX_PHY_CONFIG) )
|
|
|
|
errx(EX_USAGE, "%s: node out of range: %s\n",__func__, optarg);
|
2008-09-10 18:09:52 +00:00
|
|
|
open_needed = true;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2003-08-05 03:26:14 +00:00
|
|
|
break;
|
2003-09-25 09:33:16 +00:00
|
|
|
case 'p':
|
2008-09-10 18:09:52 +00:00
|
|
|
dump_phy_reg = 1;
|
|
|
|
open_needed = true;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2003-09-25 09:33:16 +00:00
|
|
|
break;
|
2003-08-05 03:26:14 +00:00
|
|
|
case 'r':
|
2008-09-10 18:09:52 +00:00
|
|
|
send_bus_reset = 1;
|
|
|
|
open_needed = true;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2003-08-05 03:26:14 +00:00
|
|
|
break;
|
|
|
|
case 's':
|
2008-09-10 18:09:52 +00:00
|
|
|
send_reset_start = str2node(fd, optarg);
|
2008-12-12 18:17:23 +00:00
|
|
|
if ( (send_reset_start < 0) || (send_reset_start > MAX_PHY_CONFIG) )
|
|
|
|
errx(EX_USAGE, "%s: node out of range: %s\n", __func__, optarg);
|
2008-09-10 18:09:52 +00:00
|
|
|
open_needed = true;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2003-08-05 03:26:14 +00:00
|
|
|
break;
|
|
|
|
case 't':
|
2008-09-10 18:09:52 +00:00
|
|
|
dump_topology = 1;
|
|
|
|
open_needed = true;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2003-08-05 03:26:14 +00:00
|
|
|
break;
|
|
|
|
case 'u':
|
2008-09-10 18:09:52 +00:00
|
|
|
if(!command_set)
|
|
|
|
display_board_only = true;
|
|
|
|
current_board = strtol(optarg, NULL, 0);
|
|
|
|
open_needed = true;
|
2003-08-05 03:26:14 +00:00
|
|
|
break;
|
2006-10-26 22:33:38 +00:00
|
|
|
case 'M':
|
|
|
|
switch (optarg[0]) {
|
|
|
|
case 'm':
|
|
|
|
recvfn = mpegtsrecv;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
recvfn = dvrecv;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errx(EX_USAGE, "unrecognized method: %s",
|
|
|
|
optarg);
|
|
|
|
}
|
2008-09-10 18:09:52 +00:00
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2006-10-26 22:33:38 +00:00
|
|
|
break;
|
2003-01-23 16:10:12 +00:00
|
|
|
case 'R':
|
2008-09-10 18:09:52 +00:00
|
|
|
recv_data = malloc(strlen(optarg)+1);
|
|
|
|
if (recv_data == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:recv_data malloc", __func__);
|
|
|
|
strcpy(recv_data, optarg);
|
|
|
|
open_needed = false;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2003-01-23 16:10:12 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
2008-09-10 18:09:52 +00:00
|
|
|
send_data = malloc(strlen(optarg)+1);
|
|
|
|
if (send_data == NULL)
|
|
|
|
err(EX_SOFTWARE, "%s:send_data malloc", __func__);
|
|
|
|
strcpy(send_data, optarg);
|
|
|
|
open_needed = true;
|
|
|
|
command_set = true;
|
|
|
|
display_board_only = false;
|
2003-01-23 16:10:12 +00:00
|
|
|
break;
|
2008-12-12 18:17:23 +00:00
|
|
|
case '?':
|
2002-12-30 10:13:16 +00:00
|
|
|
default:
|
|
|
|
usage();
|
2008-12-12 18:17:23 +00:00
|
|
|
warnc(EINVAL, "%s: Unknown command line arguments", __func__);
|
2008-09-10 18:09:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} /* end while */
|
|
|
|
|
2008-12-12 18:17:23 +00:00
|
|
|
/*
|
|
|
|
* Catch the error case when the user
|
|
|
|
* executes the command with non ''-''
|
|
|
|
* delimited arguments.
|
|
|
|
* Generate the usage() display and exit.
|
|
|
|
*/
|
|
|
|
if (!command_set && !display_board_only) {
|
|
|
|
usage();
|
|
|
|
warnc(EINVAL, "%s: Unknown command line arguments", __func__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-10 18:09:52 +00:00
|
|
|
/*
|
|
|
|
* If -u <bus_number> is passed, execute
|
|
|
|
* command for that card only.
|
|
|
|
*
|
|
|
|
* If -u <bus_number> is not passed, execute
|
|
|
|
* command for card 0 only.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if(open_needed){
|
2008-12-12 18:17:23 +00:00
|
|
|
snprintf(devbase, sizeof(devbase), "%s%d.0", device_string, current_board);
|
2008-09-10 18:09:52 +00:00
|
|
|
if (open_dev(&fd, devbase) < 0) {
|
2008-12-12 18:17:23 +00:00
|
|
|
err(EX_IOERR, "%s: Error opening firewire controller #%d %s", __func__, current_board, devbase);
|
2002-12-30 10:13:16 +00:00
|
|
|
}
|
2008-09-10 18:09:52 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* display the nodes on this board "-u"
|
|
|
|
* only
|
|
|
|
*/
|
|
|
|
if (display_board_only)
|
|
|
|
list_dev(fd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dump_phy_reg "-p"
|
|
|
|
*/
|
|
|
|
if (dump_phy_reg)
|
|
|
|
dump_phy_registers(fd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* send a BUS_RESET Event "-r"
|
|
|
|
*/
|
|
|
|
if (send_bus_reset) {
|
|
|
|
if(ioctl(fd, FW_IBUSRST, &tmp) < 0)
|
2008-12-12 18:17:23 +00:00
|
|
|
err(EX_IOERR, "%s: Ioctl of bus reset failed for %s", __func__, devbase);
|
2008-09-10 18:09:52 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Print out the CROM for this node "-c"
|
|
|
|
*/
|
|
|
|
if (display_crom) {
|
|
|
|
tmp = str2node(fd, crom_string);
|
|
|
|
get_crom(fd, tmp, crom_buf, len);
|
|
|
|
show_crom(crom_buf);
|
|
|
|
free(crom_string);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Hex Dump the CROM for this node "-d"
|
|
|
|
*/
|
|
|
|
if (display_crom_hex) {
|
|
|
|
tmp = str2node(fd, crom_string_hex);
|
|
|
|
get_crom(fd, tmp, crom_buf_hex, len);
|
|
|
|
dump_crom(crom_buf_hex);
|
|
|
|
free(crom_string_hex);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Set Priority Budget to value for this node "-b"
|
|
|
|
*/
|
|
|
|
if (priority_budget >= 0)
|
|
|
|
set_pri_req(fd, priority_budget);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Explicitly set the root node of this bus to value "-f"
|
|
|
|
*/
|
|
|
|
if (set_root_node >= 0)
|
|
|
|
send_phy_config(fd, set_root_node, -1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the gap count for this card/bus "-g"
|
|
|
|
*/
|
|
|
|
if (set_gap_count >= 0)
|
|
|
|
send_phy_config(fd, -1, set_gap_count);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load a CROM from a file "-l"
|
|
|
|
*/
|
|
|
|
if (load_crom_from_file)
|
|
|
|
show_crom(crom_buf);
|
|
|
|
/*
|
|
|
|
* Set the fwmem target for a node to argument "-m"
|
|
|
|
*/
|
|
|
|
if (set_fwmem_target) {
|
|
|
|
eui.hi = ntohl(*(u_int32_t*)&(target.octet[0]));
|
|
|
|
eui.lo = ntohl(*(u_int32_t*)&(target.octet[4]));
|
2008-12-12 18:17:23 +00:00
|
|
|
#if defined(__FreeBSD__)
|
2008-09-10 18:09:52 +00:00
|
|
|
sysctl_set_int("hw.firewire.fwmem.eui64_hi", eui.hi);
|
|
|
|
sysctl_set_int("hw.firewire.fwmem.eui64_lo", eui.lo);
|
2008-12-12 18:17:23 +00:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
sysctl_set_int("hw.fwmem.eui64_hi", eui.hi);
|
|
|
|
sysctl_set_int("hw.fwmem.eui64_lo", eui.lo);
|
|
|
|
#else
|
|
|
|
#warning "You need to add support for your OS"
|
|
|
|
#endif
|
|
|
|
|
2008-09-10 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a link on to this board/bus "-o"
|
|
|
|
*/
|
|
|
|
if (send_link_on >= 0)
|
|
|
|
link_on(fd, send_link_on);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a reset start to this board/bus "-s"
|
|
|
|
*/
|
|
|
|
if (send_reset_start >= 0)
|
|
|
|
reset_start(fd, send_reset_start);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump the node topology for this board/bus "-t"
|
|
|
|
*/
|
|
|
|
if (dump_topology)
|
|
|
|
show_topology_map(fd);
|
|
|
|
|
|
|
|
/*
|
2011-12-30 10:58:14 +00:00
|
|
|
* Receive data file from node "-R"
|
2008-09-10 18:09:52 +00:00
|
|
|
*/
|
|
|
|
#define TAG (1<<6)
|
|
|
|
#define CHANNEL 63
|
|
|
|
if (recv_data != NULL){
|
|
|
|
if (recvfn == NULL) { /* guess... */
|
|
|
|
recvfn = detect_recv_fn(fd, TAG | CHANNEL);
|
|
|
|
close(fd);
|
2009-01-02 08:21:21 +00:00
|
|
|
fd = -1;
|
2008-09-10 18:09:52 +00:00
|
|
|
}
|
2008-12-12 18:17:23 +00:00
|
|
|
snprintf(devbase, sizeof(devbase), "%s%d.0", device_string, current_board);
|
2008-09-10 18:09:52 +00:00
|
|
|
if (open_dev(&fd, devbase) < 0)
|
2008-12-12 18:17:23 +00:00
|
|
|
err(EX_IOERR, "%s: Error opening firewire controller #%d %s in recv_data\n", __func__, current_board, devbase);
|
2008-09-10 18:09:52 +00:00
|
|
|
(*recvfn)(fd, recv_data, TAG | CHANNEL, -1);
|
|
|
|
free(recv_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send data file to node "-S"
|
|
|
|
*/
|
|
|
|
if (send_data != NULL){
|
|
|
|
dvsend(fd, send_data, TAG | CHANNEL, -1);
|
|
|
|
free(send_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd > 0) {
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
}
|
2002-12-30 10:13:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|