Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/fwctl Backport improvements from FreeBSD.



details:   https://anonhg.NetBSD.org/src/rev/0371a7ff8bad
branches:  trunk
changeset: 757294:0371a7ff8bad
user:      cegger <cegger%NetBSD.org@localhost>
date:      Tue Aug 24 08:41:24 2010 +0000

description:
Backport improvements from FreeBSD.
Introduce two new options:
-f : force root node
-i : set priority budget where supported
developped, tested and reviewed by kiyohara@ and me.

diffstat:

 usr.sbin/fwctl/fwcontrol.c |  704 +++++++++++++++++++++++++++++++-------------
 usr.sbin/fwctl/fwctl.8     |   13 +-
 usr.sbin/fwctl/fwdv.c      |   65 +--
 usr.sbin/fwctl/fwmpegts.c  |   23 +-
 4 files changed, 534 insertions(+), 271 deletions(-)

diffs (truncated from 1413 to 300 lines):

diff -r 911a1fa28e7c -r 0371a7ff8bad usr.sbin/fwctl/fwcontrol.c
--- a/usr.sbin/fwctl/fwcontrol.c        Tue Aug 24 07:27:59 2010 +0000
+++ b/usr.sbin/fwctl/fwcontrol.c        Tue Aug 24 08:41:24 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fwcontrol.c,v 1.8 2010/03/29 10:49:34 cegger Exp $     */
+/*     $NetBSD: fwcontrol.c,v 1.9 2010/08/24 08:41:24 cegger Exp $     */
 /*
  * Copyright (C) 2002
  *     Hidetoshi Shimokawa. All rights reserved.
@@ -32,11 +32,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#if defined(__FreeBSD__)
-
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/fwcontrol/fwcontrol.c,v 1.23 2006/10/26 22:33:38 imp Exp $");
-#endif
+//__FBSDID("$FreeBSD: src/usr.sbin/fwcontrol/fwcontrol.c,v 1.23 2006/10/26 22:33:38 imp Exp $");
+__RCSID("$NetBSD: fwcontrol.c,v 1.9 2010/08/24 08:41:24 cegger Exp $");
 
 #include <sys/param.h>
 #include <sys/malloc.h>
@@ -45,19 +43,11 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/errno.h>
-#if defined(__FreeBSD__)
-#include <sys/eui64.h>
-#include <dev/firewire/firewire.h>
-#include <dev/firewire/iec13213.h>
-#include <dev/firewire/fwphyreg.h>
-#include <dev/firewire/iec68113.h>
-#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>
-#endif
 
 #include <netinet/in.h>
 #include <fcntl.h>
@@ -75,47 +65,44 @@
 usage(void)
 {
        fprintf(stderr,
-               "%s [-prt] [-b pri_req] [-c node] [-d node]"
-               " [-g gap_count] [-l file]\n"
-               "\t[-m EUI64 | hostname] [-o node] [-R filename]"
-               " [-S filename]\n"
-               "\t[-s node] [-u bus_num]\n"
-               "\t-b: set PRIORITY_BUDGET register on all supported nodes\n"
-               "\t-c: read configuration ROM\n"
-               "\t-d: hex dump of configuration ROM\n"
-               "\t-g: broadcast gap_count by phy_config packet\n"
-               "\t-l: load and parse hex dump file of configuration ROM\n"
-               "\t-m: set fwmem target\n"
-               "\t-o: send link-on packet to the node\n"
-               "\t-p: dump PHY registers\n"
-               "\t-R: receive DV or MPEG TS stream\n"
-               "\t-r: bus reset\n"
-               "\t-S: send DV stream\n"
-               "\t-s: write RESET_START register on the node\n"
-               "\t-t: read topology map\n"
-               "\t-u: specify bus number\n", getprogname());
+           "%s [-prt] [-b pri_req] [-c node] [-d node] [-f force_root ]\n"
+           "\t[-g gap_count] [-l file] [-M mode] [-m EUI64 | hostname]\n"
+           "\t[-o node] [-R filename] [-S filename] [-s node] [-u bus_num]\n"
+           "\n"
+           "\t-b: set PRIORITY_BUDGET register on all supported nodes\n"
+           "\t-c: read configuration ROM\n"
+           "\t-d: hex dump of configuration ROM\n"
+           "\t-f: force root node\n"
+           "\t-g: broadcast gap_count by phy_config packet\n"
+           "\t-l: load and parse hex dump file of configuration ROM\n"
+           "\t-M: specify dv or mpeg\n"
+           "\t-m: set fwmem target\n"
+           "\t-o: send link-on packet to the node\n"
+           "\t-p: dump PHY registers\n"
+           "\t-R: receive DV or MPEG TS stream\n"
+           "\t-r: bus reset\n"
+           "\t-S: send DV stream\n"
+           "\t-s: write RESET_START register on the node\n"
+           "\t-t: read topology map\n"
+           "\t-u: specify bus number\n", getprogname());
        exit(EX_USAGE);
 }
 
 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);
+       *(uint32_t*)&(eui->octet[0]) = htonl(fweui->hi);
+       *(uint32_t*)&(eui->octet[4]) = htonl(fweui->lo);
 }
 
-static struct fw_devlstreq *
-get_dev(int fd)
+static void
+get_dev(int fd, struct fw_devlstreq *data)
 {
-       struct fw_devlstreq *data;
 
-       data = malloc(sizeof(*data));
        if (data == NULL)
-               err(1, "malloc");
-       if( ioctl(fd, FW_GDEVLST, data) < 0) {
-                               err(1, "ioctl");
-       }
-       return data;
+               err(EX_SOFTWARE, "%s: data malloc", __func__);
+       if (ioctl(fd, FW_GDEVLST, data) < 0)
+               err(EX_IOERR, "%s: ioctl", __func__);
 }
 
 static int
@@ -127,7 +114,7 @@
        int i, node;
 
        if (nodestr == '\0')
-               return (-1);
+               return -1;
 
        /*
         * Deal with classic node specifications.
@@ -140,25 +127,33 @@
         * Try to get an eui and match it against available nodes.
         */
        if (eui64_hostton(nodestr, &eui) != 0 && eui64_aton(nodestr, &eui) != 0)
-               return (-1);
+               return -1;
 
-       data = get_dev(fd);
+       data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
+       if (data == NULL)
+               err(EX_SOFTWARE, "%s: data malloc", __func__);
+       get_dev(fd,data);
 
        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;
+                       if (data != NULL)
+                               free(data);
                        goto gotnode;
                }
        }
-       if (i >= data->info_len)
-               return (-1);
+       if (i >= data->info_len) {
+               if (data != NULL)
+                       free(data);
+               return -1;
+       }
 
 gotnode:
        if (node < 0 || node > 63)
-               return (-1);
+               return -1;
        else
-               return (node);
+               return node;
 }
 
 static void
@@ -167,34 +162,38 @@
        struct fw_devlstreq *data;
        struct fw_devinfo *devinfo;
        struct eui64 eui;
-       char addr[EUI64_SIZ];
+       char addr[EUI64_SIZ], hostname[40];
        int i;
 
-       data = get_dev(fd);
+       data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
+       if (data == NULL)
+               err(EX_SOFTWARE, "%s:data malloc", __func__);
+       get_dev(fd, data);
        printf("%d devices (info_len=%d)\n", data->n, data->info_len);
-       printf("node           EUI64          status\n");
+       printf("node           EUI64          status    hostname\n");
        for (i = 0; i < data->info_len; i++) {
                devinfo = &data->dev[i];
                fweui2eui64(&devinfo->eui, &eui);
                eui64_ntoa(&eui, addr, sizeof(addr));
-               printf("%4d  %s %6d\n",
+               if (eui64_ntohost(hostname, sizeof(hostname), &eui))
+                       hostname[0] = 0;
+               printf("%4d  %s %6d    %s\n",
                        (devinfo->status || i == 0) ? devinfo->dst : -1,
-                       addr,
-                       devinfo->status
-               );
+                       addr, devinfo->status, hostname);
        }
        free((void *)data);
 }
 
-static u_int32_t
-read_write_quad(int fd, struct fw_eui64 eui, u_int32_t addr_lo, int readmode, u_int32_t data)
+static uint32_t
+read_write_quad(int fd, struct fw_eui64 eui, uint32_t addr_lo, int readmode,
+               uint32_t data)
 {
         struct fw_asyreq *asyreq;
-       u_int32_t *qld, res;
+       uint32_t *qld, res;
 
-        asyreq = malloc(sizeof(*asyreq));
+       asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16);
        if (asyreq == NULL)
-               err(1, "malloc");
+               err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
        asyreq->req.len = 16;
 #if 0
        asyreq->req.type = FWASREQNODE;
@@ -212,13 +211,12 @@
        asyreq->pkt.mode.rreqq.dest_hi = 0xffff;
        asyreq->pkt.mode.rreqq.dest_lo = addr_lo;
 
-       qld = (u_int32_t *)&asyreq->pkt;
+       qld = (uint32_t *)&asyreq->pkt;
        if (!readmode)
-               asyreq->pkt.mode.wreqq.data = data;
+               asyreq->pkt.mode.wreqq.data = htonl(data);
 
-       if (ioctl(fd, FW_ASYREQ, asyreq) < 0) {
-                       err(1, "ioctl");
-       }
+       if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
+               err(EX_IOERR, "%s: ioctl", __func__);
        res = qld[3];
        free(asyreq);
        if (readmode)
@@ -227,41 +225,56 @@
                return 0;
 }
 
+/*
+ * 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
+ */
 static void
 send_phy_config(int fd, int root_node, int gap_count)
 {
         struct fw_asyreq *asyreq;
 
-       asyreq = malloc(sizeof(*asyreq));
+       asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12);
        if (asyreq == NULL)
-               err(1, "malloc");
+               err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
        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)
-               asyreq->pkt.mode.ld[1] |= (root_node & 0x3f) << 24 | 1 << 23;
+               asyreq->pkt.mode.ld[1] |= ((root_node << 24) | (1 << 23));
        if (gap_count >= 0)
-               asyreq->pkt.mode.ld[1] |= 1 << 22 | (gap_count & 0x3f) << 16;
+               asyreq->pkt.mode.ld[1] |= ((1 << 22) | (gap_count << 16));
        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);
 
        if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
-                       err(1, "ioctl");
+               err(EX_IOERR, "%s: ioctl", __func__);
        free(asyreq);
 }
 
 static void
-send_link_on(int fd, int node)
+link_on(int fd, int node)
 {
         struct fw_asyreq *asyreq;
 
-       asyreq = malloc(sizeof(*asyreq));
+       asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12);
        if (asyreq == NULL)
-               err(1, "malloc");
+               err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
        asyreq->req.len = 12;
        asyreq->req.type = FWASREQNODE;



Home | Main Index | Thread Index | Old Index