3 * Hidetoshi Shimokawa. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
16 * This product includes software developed by Hidetoshi Shimokawa.
18 * 4. Neither the name of the author nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/param.h>
39 #include <sys/malloc.h>
40 #include <sys/types.h>
41 #include <sys/sysctl.h>
42 #include <sys/socket.h>
43 #include <sys/ioctl.h>
44 #include <sys/errno.h>
45 #include <sys/eui64.h>
46 #include <dev/firewire/firewire.h>
47 #include <dev/firewire/iec13213.h>
48 #include <dev/firewire/fwphyreg.h>
49 #include <dev/firewire/iec68113.h>
51 #include <netinet/in.h>
61 #include "fwmethods.h"
63 static void sysctl_set_int(const char *, int);
69 "fwcontrol [-u bus_num] [-prt] [-c node] [-d node] [-o node] [-s node]\n"
70 "\t [-l file] [-g gap_count] [-f force_root ] [-b pri_req]\n"
71 "\t [-M mode] [-R filename] [-S filename] [-m EUI64 | hostname]\n"
72 "\t-u: specify bus number\n"
73 "\t-p: Display current PHY register settings\n"
75 "\t-t: read topology map\n"
76 "\t-c: read configuration ROM\n"
77 "\t-d: hex dump of configuration ROM\n"
78 "\t-o: send link-on packet to the node\n"
79 "\t-s: write RESET_START register on the node\n"
80 "\t-l: load and parse hex dump file of configuration ROM\n"
81 "\t-g: broadcast gap_count by phy_config packet\n"
82 "\t-f: broadcast force_root by phy_config packet\n"
83 "\t-b: set PRIORITY_BUDGET register on all supported nodes\n"
84 "\t-M: specify dv or mpeg\n"
85 "\t-R: Receive DV or MPEG TS stream\n"
86 "\t-S: Send DV stream\n"
87 "\t-m: set fwmem target\n");
92 fweui2eui64(const struct fw_eui64 *fweui, struct eui64 *eui)
94 *(u_int32_t*)&(eui->octet[0]) = htonl(fweui->hi);
95 *(u_int32_t*)&(eui->octet[4]) = htonl(fweui->lo);
99 get_dev(int fd, struct fw_devlstreq *data)
102 err(EX_SOFTWARE, "%s: data malloc", __func__);
103 if( ioctl(fd, FW_GDEVLST, data) < 0) {
104 err(EX_IOERR, "%s: ioctl", __func__);
109 str2node(int fd, const char *nodestr)
111 struct eui64 eui, tmpeui;
112 struct fw_devlstreq *data;
120 * Deal with classic node specifications.
122 node = strtol(nodestr, &endptr, 0);
127 * Try to get an eui and match it against available nodes.
129 if (eui64_hostton(nodestr, &eui) != 0 && eui64_aton(nodestr, &eui) != 0)
132 data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
134 err(EX_SOFTWARE, "%s: data malloc", __func__);
137 for (i = 0; i < data->info_len; i++) {
138 fweui2eui64(&data->dev[i].eui, &tmpeui);
139 if (memcmp(&eui, &tmpeui, sizeof(struct eui64)) == 0) {
140 node = data->dev[i].dst;
146 if (i >= data->info_len) {
153 if (node < 0 || node > 63)
162 struct fw_devlstreq *data;
163 struct fw_devinfo *devinfo;
165 char addr[EUI64_SIZ], hostname[40];
168 data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
170 err(EX_SOFTWARE, "%s:data malloc", __func__);
172 printf("%d devices (info_len=%d)\n", data->n, data->info_len);
173 printf("node EUI64 status hostname\n");
174 for (i = 0; i < data->info_len; i++) {
175 devinfo = &data->dev[i];
176 fweui2eui64(&devinfo->eui, &eui);
177 eui64_ntoa(&eui, addr, sizeof(addr));
178 if (eui64_ntohost(hostname, sizeof(hostname), &eui))
180 printf("%4d %s %6d %s\n",
181 (devinfo->status || i == 0) ? devinfo->dst : -1,
191 read_write_quad(int fd, struct fw_eui64 eui, u_int32_t addr_lo, int readmode, u_int32_t data)
193 struct fw_asyreq *asyreq;
196 asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16);
198 err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
199 asyreq->req.len = 16;
201 asyreq->req.type = FWASREQNODE;
202 asyreq->pkt.mode.rreqq.dst = FWLOCALBUS | node;
204 asyreq->req.type = FWASREQEUI;
205 asyreq->req.dst.eui = eui;
207 asyreq->pkt.mode.rreqq.tlrt = 0;
209 asyreq->pkt.mode.rreqq.tcode = FWTCODE_RREQQ;
211 asyreq->pkt.mode.rreqq.tcode = FWTCODE_WREQQ;
213 asyreq->pkt.mode.rreqq.dest_hi = 0xffff;
214 asyreq->pkt.mode.rreqq.dest_lo = addr_lo;
216 qld = (u_int32_t *)&asyreq->pkt;
218 asyreq->pkt.mode.wreqq.data = htonl(data);
220 if (ioctl(fd, FW_ASYREQ, asyreq) < 0) {
221 err(EX_IOERR, "%s: ioctl", __func__);
232 * Send a PHY Config Packet
233 * ieee 1394a-2005 4.3.4.3
235 * Message ID Root ID R T Gap Count
236 * 00(2 bits) (6 bits) 1 1 (6 bits)
238 * if "R" is set, then Root ID will be the next
239 * root node upon the next bus reset.
240 * if "T" is set, then Gap Count will be the
241 * value that all nodes use for their Gap Count
242 * if "R" and "T" are not set, then this message
243 * is either ignored or interpreted as an extended
244 * PHY config Packet as per 1394a-2005 4.3.4.4
247 send_phy_config(int fd, int root_node, int gap_count)
249 struct fw_asyreq *asyreq;
251 asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12);
253 err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
254 asyreq->req.len = 12;
255 asyreq->req.type = FWASREQNODE;
256 asyreq->pkt.mode.ld[0] = 0;
257 asyreq->pkt.mode.ld[1] = 0;
258 asyreq->pkt.mode.common.tcode = FWTCODE_PHY;
260 asyreq->pkt.mode.ld[1] |= ((root_node << 24) | (1 << 23));
262 asyreq->pkt.mode.ld[1] |= ((1 << 22) | (gap_count << 16));
263 asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1];
265 printf("send phy_config root_node=%d gap_count=%d\n",
266 root_node, gap_count);
268 if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
269 err(EX_IOERR, "%s: ioctl", __func__);
274 link_on(int fd, int node)
276 struct fw_asyreq *asyreq;
278 asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12);
280 err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
281 asyreq->req.len = 12;
282 asyreq->req.type = FWASREQNODE;
283 asyreq->pkt.mode.common.tcode = FWTCODE_PHY;
284 asyreq->pkt.mode.ld[1] |= (1 << 30) | ((node & 0x3f) << 24);
285 asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1];
287 if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
288 err(EX_IOERR, "%s: ioctl", __func__);
293 reset_start(int fd, int node)
295 struct fw_asyreq *asyreq;
297 asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16);
299 err(EX_SOFTWARE, "%s:asyreq malloc", __func__);
300 asyreq->req.len = 16;
301 asyreq->req.type = FWASREQNODE;
302 asyreq->pkt.mode.wreqq.dst = FWLOCALBUS | (node & 0x3f);
303 asyreq->pkt.mode.wreqq.tlrt = 0;
304 asyreq->pkt.mode.wreqq.tcode = FWTCODE_WREQQ;
306 asyreq->pkt.mode.wreqq.dest_hi = 0xffff;
307 asyreq->pkt.mode.wreqq.dest_lo = 0xf0000000 | RESET_START;
309 asyreq->pkt.mode.wreqq.data = htonl(0x1);
311 if (ioctl(fd, FW_ASYREQ, asyreq) < 0)
312 err(EX_IOERR, "%s: ioctl", __func__);
317 set_pri_req(int fd, u_int32_t pri_req)
319 struct fw_devlstreq *data;
320 struct fw_devinfo *devinfo;
322 char addr[EUI64_SIZ];
323 u_int32_t max, reg, old;
326 data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
328 err(EX_SOFTWARE, "%s:data malloc", __func__);
330 #define BUGET_REG 0xf0000218
331 for (i = 0; i < data->info_len; i++) {
332 devinfo = &data->dev[i];
333 if (!devinfo->status)
335 reg = read_write_quad(fd, devinfo->eui, BUGET_REG, 1, 0);
336 fweui2eui64(&devinfo->eui, &eui);
337 eui64_ntoa(&eui, addr, sizeof(addr));
338 printf("%d %s, %08x",
339 devinfo->dst, addr, reg);
342 max = (reg & 0x3f00) >> 8;
345 printf(" 0x%x -> 0x%x\n", old, pri_req);
346 read_write_quad(fd, devinfo->eui, BUGET_REG, 0, pri_req);
355 parse_bus_info_block(u_int32_t *p)
357 char addr[EUI64_SIZ];
361 bi = (struct bus_info *)p;
362 fweui2eui64(&bi->eui64, &eui);
363 eui64_ntoa(&eui, addr, sizeof(addr));
364 printf("bus_name: 0x%04x\n"
365 "irmc:%d cmc:%d isc:%d bmc:%d pmc:%d\n"
366 "cyc_clk_acc:%d max_rec:%d max_rom:%d\n"
367 "generation:%d link_spd:%d\n"
370 bi->irmc, bi->cmc, bi->isc, bi->bmc, bi->pmc,
371 bi->cyc_clk_acc, bi->max_rec, bi->max_rom,
372 bi->generation, bi->link_spd,
377 get_crom(int fd, int node, void *crom_buf, int len)
379 struct fw_crom_buf buf;
381 struct fw_devlstreq *data;
383 data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
385 err(EX_SOFTWARE, "%s:data malloc", __func__);
388 for (i = 0; i < data->info_len; i++) {
389 if (data->dev[i].dst == node && data->dev[i].eui.lo != 0)
392 if (i == data->info_len)
393 errx(1, "no such node %d.", node);
395 buf.eui = data->dev[i].eui;
400 bzero(crom_buf, len);
401 if ((error = ioctl(fd, FW_GCROM, &buf)) < 0) {
402 err(EX_IOERR, "%s: ioctl", __func__);
409 show_crom(u_int32_t *crom_buf)
412 struct crom_context cc;
413 char *desc, info[256];
414 static const char *key_types = "ICLD";
416 struct csrdirectory *dir;
420 printf("first quad: 0x%08x ", *crom_buf);
421 if (crom_buf[0] == 0) {
422 printf("(Invalid Configuration ROM)\n");
425 hdr = (struct csrhdr *)crom_buf;
426 if (hdr->info_len == 1) {
428 reg = (struct csrreg *)hdr;
429 printf("verndor ID: 0x%06x\n", reg->val);
432 printf("info_len=%d crc_len=%d crc=0x%04x",
433 hdr->info_len, hdr->crc_len, hdr->crc);
434 crc = crom_crc(crom_buf+1, hdr->crc_len);
439 parse_bus_info_block(crom_buf+1);
441 crom_init_context(&cc, crom_buf);
442 dir = cc.stack[0].dir;
444 printf("no root directory - giving up\n");
447 printf("root_directory: len=0x%04x(%d) crc=0x%04x",
448 dir->crc_len, dir->crc_len, dir->crc);
449 crc = crom_crc((u_int32_t *)&dir->entry[0], dir->crc_len);
454 if (dir->crc_len < 1)
456 while (cc.depth >= 0) {
457 desc = crom_desc(&cc, info, sizeof(info));
459 for (i = 0; i < cc.depth; i++)
461 printf("%02x(%c:%02x) %06x %s: %s\n",
463 key_types[(reg->key & CSRTYPE_MASK)>>6],
464 reg->key & CSRKEY_MASK, reg->val,
470 #define DUMP_FORMAT "%08x %08x %08x %08x %08x %08x %08x %08x\n"
473 dump_crom(u_int32_t *p)
477 for (i = 0; i < len/(4*8); i ++) {
479 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
485 load_crom(char *filename, u_int32_t *p)
490 if ((file = fopen(filename, "r")) == NULL)
492 for (i = 0; i < len/(4*8); i ++) {
493 fscanf(file, DUMP_FORMAT,
494 p, p+1, p+2, p+3, p+4, p+5, p+6, p+7);
500 show_topology_map(int fd)
502 struct fw_topology_map *tmap;
503 union fw_self_id sid;
505 static const char *port_status[] = {" ", "-", "P", "C"};
506 static const char *pwr_class[] = {" 0W", "15W", "30W", "45W",
507 "-1W", "-2W", "-5W", "-9W"};
508 static const char *speed[] = {"S100", "S200", "S400", "S800"};
509 tmap = malloc(sizeof(struct fw_topology_map));
511 err(EX_SOFTWARE, "%s:tmap malloc", __func__);
512 if (ioctl(fd, FW_GTPMAP, tmap) < 0) {
513 err(EX_IOERR, "%s: ioctl", __func__);
515 printf("crc_len: %d generation:%d node_count:%d sid_count:%d\n",
516 tmap->crc_len, tmap->generation,
517 tmap->node_count, tmap->self_id_count);
518 printf("id link gap_cnt speed delay cIRM power port0 port1 port2"
520 for (i = 0; i < tmap->crc_len - 2; i++) {
521 sid = tmap->self_id[i];
523 printf("%02d sequel packet\n", sid.p0.phy_id);
526 printf("%02d %2d %2d %4s %d %d %3s"
531 speed[sid.p0.phy_speed],
534 pwr_class[sid.p0.power_class],
535 port_status[sid.p0.port0],
536 port_status[sid.p0.port1],
537 port_status[sid.p0.port2],
538 sid.p0.initiated_reset,
546 read_phy_registers(int fd, u_int8_t *buf, int offset, int len)
548 struct fw_reg_req_t reg;
551 for (i = 0; i < len; i++) {
552 reg.addr = offset + i;
553 if (ioctl(fd, FWOHCI_RDPHYREG, ®) < 0)
554 err(EX_IOERR, "%s: ioctl", __func__);
555 buf[i] = (u_int8_t) reg.data;
556 printf("0x%02x ", reg.data);
562 read_phy_page(int fd, u_int8_t *buf, int page, int port)
564 struct fw_reg_req_t reg;
567 reg.data = ((page & 7) << 5) | (port & 0xf);
568 if (ioctl(fd, FWOHCI_WRPHYREG, ®) < 0)
569 err(EX_IOERR, "%s: ioctl", __func__);
570 read_phy_registers(fd, buf, 8, 8);
574 dump_phy_registers(int fd)
576 struct phyreg_base b;
577 struct phyreg_page0 p;
578 struct phyreg_page1 v;
581 printf("=== base register ===\n");
582 read_phy_registers(fd, (u_int8_t *)&b, 0, 8);
584 "Physical_ID:%d R:%d CPS:%d\n"
585 "RHB:%d IBR:%d Gap_Count:%d\n"
586 "Extended:%d Num_Ports:%d\n"
587 "PHY_Speed:%d Delay:%d\n"
588 "LCtrl:%d C:%d Jitter:%d Pwr_Class:%d\n"
589 "WDIE:%d ISBR:%d CTOI:%d CPSI:%d STOI:%d PEI:%d EAA:%d EMC:%d\n"
590 "Max_Legacy_SPD:%d BLINK:%d Bridge:%d\n"
591 "Page_Select:%d Port_Select%d\n",
592 b.phy_id, b.r, b.cps,
593 b.rhb, b.ibr, b.gap_count,
594 b.extended, b.num_ports,
595 b.phy_speed, b.delay,
596 b.lctrl, b.c, b.jitter, b.pwr_class,
597 b.wdie, b.isbr, b.ctoi, b.cpsi, b.stoi, b.pei, b.eaa, b.emc,
598 b.legacy_spd, b.blink, b.bridge,
599 b.page_select, b.port_select
602 for (i = 0; i < b.num_ports; i ++) {
603 printf("\n=== page 0 port %d ===\n", i);
604 read_phy_page(fd, (u_int8_t *)&p, 0, i);
606 "Astat:%d BStat:%d Ch:%d Con:%d RXOK:%d Dis:%d\n"
607 "Negotiated_speed:%d PIE:%d Fault:%d Stanby_fault:%d Disscrm:%d B_Only:%d\n"
608 "DC_connected:%d Max_port_speed:%d LPP:%d Cable_speed:%d\n"
609 "Connection_unreliable:%d Beta_mode:%d\n"
611 "Loop_disable:%d In_standby:%d Hard_disable:%d\n",
612 p.astat, p.bstat, p.ch, p.con, p.rxok, p.dis,
613 p.negotiated_speed, p.pie, p.fault, p.stanby_fault, p.disscrm, p.b_only,
614 p.dc_connected, p.max_port_speed, p.lpp, p.cable_speed,
615 p.connection_unreliable, p.beta_mode,
617 p.loop_disable, p.in_standby, p.hard_disable
620 printf("\n=== page 1 ===\n");
621 read_phy_page(fd, (u_int8_t *)&v, 1, 0);
625 "Product_ID:0x%06x\n",
627 (v.vendor_id[0] << 16) | (v.vendor_id[1] << 8) | v.vendor_id[2],
628 (v.product_id[0] << 16) | (v.product_id[1] << 8) | v.product_id[2]
633 open_dev(int *fd, char *devname)
636 *fd = open(devname, O_RDWR);
645 sysctl_set_int(const char *name, int val)
647 if (sysctlbyname(name, NULL, NULL, &val, sizeof(int)) < 0)
648 err(1, "sysctl %s failed.", name);
652 detect_recv_fn(int fd, char ich)
655 struct fw_isochreq isoreq;
656 struct fw_isobufreq bufreq;
661 #define RECV_NUM_PACKET 16
662 #define RECV_PACKET_SZ 1024
664 bufreq.rx.nchunk = 8;
665 bufreq.rx.npacket = RECV_NUM_PACKET;
666 bufreq.rx.psize = RECV_PACKET_SZ;
667 bufreq.tx.nchunk = 0;
668 bufreq.tx.npacket = 0;
671 if (ioctl(fd, FW_SSTBUF, &bufreq) < 0)
672 err(EX_IOERR, "%s: ioctl FW_SSTBUF", __func__);
674 isoreq.ch = ich & 0x3f;
675 isoreq.tag = (ich >> 6) & 3;
677 if (ioctl(fd, FW_SRSTREAM, &isoreq) < 0)
678 err(EX_IOERR, "%s: ioctl FW_SRSTREAM", __func__);
680 buf = (char *)malloc(RECV_NUM_PACKET * RECV_PACKET_SZ);
682 err(EX_SOFTWARE, "%s:buf malloc", __func__);
684 * fwdev.c seems to return EIO on error and
685 * the return value of the last uiomove
686 * on success. For now, checking that the
687 * return is not less than zero should be
688 * sufficient. fwdev.c::fw_read() should
689 * return the total length read, not the value
690 * of the last uiomove().
692 len = read(fd, buf, RECV_NUM_PACKET * RECV_PACKET_SZ);
694 err(EX_IOERR, "%s: error reading from device\n", __func__);
695 ptr = (u_int32_t *) buf;
696 ciph = (struct ciphdr *)(ptr + 1);
700 fprintf(stderr, "Detected DV format on input.\n");
704 fprintf(stderr, "Detected MPEG TS format on input.\n");
708 errx(1, "Unsupported format for receiving: fmt=0x%x", ciph->fmt);
715 main(int argc, char **argv)
717 #define MAX_BOARDS 10
718 u_int32_t crom_buf[1024/4];
719 u_int32_t crom_buf_hex[1024/4];
721 const char *device_string = "/dev/fw";
722 int fd = -1, ch, len=1024;
723 int32_t current_board = 0;
725 * If !command_set, then -u will display the nodes for the board.
726 * This emulates the previous behavior when -u is passed by itself
728 bool command_set = false;
729 bool open_needed = false;
733 fwmethod *recvfn = NULL;
735 * Holders for which functions
738 bool display_board_only = false;
739 bool display_crom = false;
740 bool send_bus_reset = false;
741 bool display_crom_hex = false;
742 bool load_crom_from_file = false;
743 bool set_fwmem_target = false;
744 bool dump_topology = false;
745 bool dump_phy_reg = false;
747 int32_t priority_budget = -1;
748 int32_t set_root_node = -1;
749 int32_t set_gap_count = -1;
750 int32_t send_link_on = -1;
751 int32_t send_reset_start = -1;
753 char *crom_string = NULL;
754 char *crom_string_hex = NULL;
755 char *recv_data = NULL;
756 char *send_data = NULL;
759 for (current_board = 0; current_board < MAX_BOARDS; current_board++) {
760 snprintf(devbase, sizeof(devbase), "%s%d", device_string, current_board);
761 if (open_dev(&fd, devbase) < 0) {
762 if (current_board == 0) {
773 * Parse all command line options, then execute requested operations.
775 while ((ch = getopt(argc, argv, "M:f:g:m:o:s:b:prtc:d:l:u:R:S:")) != -1) {
778 priority_budget = strtol(optarg, NULL, 0);
779 if (priority_budget < 0 || priority_budget > INT32_MAX)
780 errx(EX_USAGE, "%s: invalid number: %s", __func__, optarg);
783 display_board_only = false;
786 crom_string = malloc(strlen(optarg)+1);
787 if (crom_string == NULL)
788 err(EX_SOFTWARE, "%s:crom_string malloc", __func__);
789 if ( (strtol(crom_string, NULL, 0) < 0) || strtol(crom_string, NULL, 0) > MAX_BOARDS)
790 err(EX_USAGE, "%s:Invalid value for node", __func__);
791 strcpy(crom_string, optarg);
795 display_board_only = false;
798 crom_string_hex = malloc(strlen(optarg)+1);
799 if (crom_string_hex == NULL)
800 err(EX_SOFTWARE, "%s:crom_string_hex malloc", __func__);
801 strcpy(crom_string_hex, optarg);
802 display_crom_hex = 1;
805 display_board_only = false;
808 #define MAX_PHY_CONFIG 0x3f
809 set_root_node = strtol(optarg, NULL, 0);
810 if ( (set_root_node < 0) || (set_root_node > MAX_PHY_CONFIG) )
811 err(EX_USAGE, "%s:set_root_node out of range", __func__);
814 display_board_only = false;
817 set_gap_count = strtol(optarg, NULL, 0);
818 if ( (set_gap_count < 0) || (set_gap_count > MAX_PHY_CONFIG) )
819 err(EX_USAGE, "%s:set_gap_count out of range", __func__);
822 display_board_only = false;
825 load_crom_from_file = 1;
826 load_crom(optarg, crom_buf);
828 display_board_only = false;
831 set_fwmem_target = 1;
834 display_board_only = false;
835 if (eui64_hostton(optarg, &target) != 0 &&
836 eui64_aton(optarg, &target) != 0)
837 err(EX_USAGE, "%s: invalid target: %s", __func__, optarg);
840 send_link_on = str2node(fd, optarg);
841 if ( (send_link_on < 0) || (send_link_on > INT32_MAX) )
842 err(EX_USAGE, "%s: node out of range: %s\n",__func__, optarg);
845 display_board_only = false;
851 display_board_only = false;
857 display_board_only = false;
860 send_reset_start = str2node(fd, optarg);
861 if ( (send_reset_start < 0) || (send_reset_start > INT32_MAX) )
862 err(EX_USAGE, "%s: node out of range: %s\n", __func__, optarg);
865 display_board_only = false;
871 display_board_only = false;
875 display_board_only = true;
876 current_board = strtol(optarg, NULL, 0);
888 errx(EX_USAGE, "unrecognized method: %s",
892 display_board_only = false;
895 recv_data = malloc(strlen(optarg)+1);
896 if (recv_data == NULL)
897 err(EX_SOFTWARE, "%s:recv_data malloc", __func__);
898 strcpy(recv_data, optarg);
901 display_board_only = false;
904 send_data = malloc(strlen(optarg)+1);
905 if (send_data == NULL)
906 err(EX_SOFTWARE, "%s:send_data malloc", __func__);
907 strcpy(send_data, optarg);
910 display_board_only = false;
919 * If -u <bus_number> is passed, execute
920 * command for that card only.
922 * If -u <bus_number> is not passed, execute
923 * command for card 0 only.
927 snprintf(devbase, sizeof(devbase), "%s%d", device_string, current_board);
928 if (open_dev(&fd, devbase) < 0) {
929 errx(EX_IOERR, "%s: Error opening board #%d\n", __func__, current_board);
933 * display the nodes on this board "-u"
936 if (display_board_only)
943 dump_phy_registers(fd);
946 * send a BUS_RESET Event "-r"
948 if (send_bus_reset) {
949 if(ioctl(fd, FW_IBUSRST, &tmp) < 0)
950 err(EX_IOERR, "%s: ioctl", __func__);
953 * Print out the CROM for this node "-c"
956 tmp = str2node(fd, crom_string);
957 get_crom(fd, tmp, crom_buf, len);
962 * Hex Dump the CROM for this node "-d"
964 if (display_crom_hex) {
965 tmp = str2node(fd, crom_string_hex);
966 get_crom(fd, tmp, crom_buf_hex, len);
967 dump_crom(crom_buf_hex);
968 free(crom_string_hex);
971 * Set Priority Budget to value for this node "-b"
973 if (priority_budget >= 0)
974 set_pri_req(fd, priority_budget);
977 * Explicitly set the root node of this bus to value "-f"
979 if (set_root_node >= 0)
980 send_phy_config(fd, set_root_node, -1);
983 * Set the gap count for this card/bus "-g"
985 if (set_gap_count >= 0)
986 send_phy_config(fd, -1, set_gap_count);
989 * Load a CROM from a file "-l"
991 if (load_crom_from_file)
994 * Set the fwmem target for a node to argument "-m"
996 if (set_fwmem_target) {
997 eui.hi = ntohl(*(u_int32_t*)&(target.octet[0]));
998 eui.lo = ntohl(*(u_int32_t*)&(target.octet[4]));
999 sysctl_set_int("hw.firewire.fwmem.eui64_hi", eui.hi);
1000 sysctl_set_int("hw.firewire.fwmem.eui64_lo", eui.lo);
1004 * Send a link on to this board/bus "-o"
1006 if (send_link_on >= 0)
1007 link_on(fd, send_link_on);
1010 * Send a reset start to this board/bus "-s"
1012 if (send_reset_start >= 0)
1013 reset_start(fd, send_reset_start);
1016 * Dump the node topology for this board/bus "-t"
1019 show_topology_map(fd);
1022 * Recieve data file from node "-R"
1026 if (recv_data != NULL){
1027 if (recvfn == NULL) { /* guess... */
1028 recvfn = detect_recv_fn(fd, TAG | CHANNEL);
1031 snprintf(devbase, sizeof(devbase), "%s%d", device_string, current_board);
1032 if (open_dev(&fd, devbase) < 0)
1033 errx(EX_IOERR, "%s: Error opening board #%d in recv_data\n", __func__, current_board);
1034 (*recvfn)(fd, recv_data, TAG | CHANNEL, -1);
1039 * Send data file to node "-S"
1041 if (send_data != NULL){
1042 dvsend(fd, send_data, TAG | CHANNEL, -1);