From owner-freebsd-firewire@FreeBSD.ORG Mon Aug 4 11:06:54 2008 Return-Path: Delivered-To: freebsd-firewire@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7CF521065675 for ; Mon, 4 Aug 2008 11:06:54 +0000 (UTC) (envelope-from owner-bugmaster@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 5387E8FC16 for ; Mon, 4 Aug 2008 11:06:54 +0000 (UTC) (envelope-from owner-bugmaster@FreeBSD.org) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m74B6sTk082042 for ; Mon, 4 Aug 2008 11:06:54 GMT (envelope-from owner-bugmaster@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m74B6rpc082038 for freebsd-firewire@FreeBSD.org; Mon, 4 Aug 2008 11:06:53 GMT (envelope-from owner-bugmaster@FreeBSD.org) Date: Mon, 4 Aug 2008 11:06:53 GMT Message-Id: <200808041106.m74B6rpc082038@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: gnats set sender to owner-bugmaster@FreeBSD.org using -f From: FreeBSD bugmaster To: freebsd-firewire@FreeBSD.org Cc: Subject: Current problem reports assigned to freebsd-firewire@FreeBSD.org X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Aug 2008 11:06:54 -0000 Current FreeBSD problem reports Critical problems Serious problems S Tracker Resp. Description -------------------------------------------------------------------------------- o kern/74238 firewire [firewire] fw_rcv: unknown response; firewire ad-hoc w 1 problem total. Non-critical problems S Tracker Resp. Description -------------------------------------------------------------------------------- o kern/113785 firewire [firewire] dropouts when playing DV on firewire 1 problem total. From owner-freebsd-firewire@FreeBSD.ORG Wed Aug 6 01:24:52 2008 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 665C11065691; Wed, 6 Aug 2008 01:24:52 +0000 (UTC) (envelope-from freebsd@sopwith.solgatos.com) Received: from parsely.rain.com (parsely.rain.com [199.26.172.196]) by mx1.freebsd.org (Postfix) with ESMTP id C0B348FC1F; Wed, 6 Aug 2008 01:24:51 +0000 (UTC) (envelope-from freebsd@sopwith.solgatos.com) Received: from sopwith.solgatos.com (uucp@localhost) by parsely.rain.com (8.11.4/8.11.4) with UUCP id m761Ol313954; Tue, 5 Aug 2008 18:24:47 -0700 (PDT) (envelope-from freebsd@sopwith.solgatos.com) Received: from localhost by sopwith.solgatos.com (8.8.8/6.24) id BAA03303; Wed, 6 Aug 2008 01:23:49 GMT Message-Id: <200808060123.BAA03303@sopwith.solgatos.com> To: Sean Bruno , freebsd-firewire@freebsd.org, Hidetoshi Shimokawa Date: Tue, 05 Aug 2008 18:23:49 +0100 From: Dieter Cc: Subject: Re: This is where I'm going with fwcontrol X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Aug 2008 01:24:52 -0000 > fwcontrol.c: In function 'main': > fwcontrol.c:726: warning: comparison is always false due to limited range of data type > > I changed priority_budget from int to long, is this the correct fix? I suspect that gcc will still complain on ILP32 machines. From owner-freebsd-firewire@FreeBSD.ORG Wed Aug 6 01:38:20 2008 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0407B106566B; Wed, 6 Aug 2008 01:38:20 +0000 (UTC) (envelope-from freebsd@sopwith.solgatos.com) Received: from parsely.rain.com (parsely.rain.com [199.26.172.196]) by mx1.freebsd.org (Postfix) with ESMTP id 62BFE8FC0A; Wed, 6 Aug 2008 01:38:19 +0000 (UTC) (envelope-from freebsd@sopwith.solgatos.com) Received: from sopwith.solgatos.com (uucp@localhost) by parsely.rain.com (8.11.4/8.11.4) with UUCP id m7610Uv13916; Tue, 5 Aug 2008 18:00:30 -0700 (PDT) (envelope-from freebsd@sopwith.solgatos.com) Received: from localhost by sopwith.solgatos.com (8.8.8/6.24) id AAA24024; Wed, 6 Aug 2008 00:59:23 GMT Message-Id: <200808060059.AAA24024@sopwith.solgatos.com> To: Sean Bruno In-reply-to: Your message of "Tue, 01 Jul 2008 17:26:27 PDT." <486ACB33.50204@miralink.com> Date: Tue, 05 Aug 2008 17:59:23 +0100 From: Dieter Cc: freebsd-firewire@freebsd.org Subject: Re: This is where I'm going with fwcontrol X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Aug 2008 01:38:20 -0000 In message <486ACB33.50204@miralink.com>, Sean Bruno writes: > > Here is a current diff against RELENG_7 which seems to be the same as > > -CURRENT. fwcontrol.c: In function 'main': fwcontrol.c:726: warning: comparison is always false due to limited range of data type I changed priority_budget from int to long, is this the correct fix? BUG: + if (adjust_gap_count) + send_phy_config(fd, adjust_gap_count, -1); Since I need to set this to 0 (see PR 113785), the if() fails and doesn't execute the send_phy_config(). I fixed this by adding a seperate flag, need_to_send_adjust_gap_count. Please feel free to think up a better name for the flag. :-) NOTE: some of the other options have the same problem, if the argument can be 0. The patch below only fixes -f. I did add some error checking, mostly for malloc. With the patch below, -f, -r, -u, -S work for me. FreeBSD 7.0 on AMD64, with the NEC fw controller. I haven't tested -R yet, I suspect the VIA fw controller still doesn't work. =================================================================== RCS file: RCS/fwcontrol.c,v retrieving revision 1.3 diff -u -r1.3 fwcontrol.c --- fwcontrol.c 2008/08/05 23:16:45 1.3 +++ fwcontrol.c 2008/08/06 00:33:25 @@ -97,7 +97,7 @@ get_dev(int fd, struct fw_devlstreq *data) { if (data == NULL) - err(1, "malloc"); + err(1, "arg data is NULL"); /* probably due to failure of malloc in calling function */ if( ioctl(fd, FW_GDEVLST, data) < 0) { err(1, "ioctl"); } @@ -188,6 +188,8 @@ u_int32_t *qld, res; asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16); + if (asyreq == NULL) + err(1, "malloc"); asyreq->req.len = 16; #if 0 asyreq->req.type = FWASREQNODE; @@ -226,6 +228,8 @@ struct fw_asyreq *asyreq; asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12); + if (asyreq == NULL) + err(1, "malloc"); asyreq->req.len = 12; asyreq->req.type = FWASREQNODE; asyreq->pkt.mode.ld[0] = 0; @@ -251,6 +255,8 @@ struct fw_asyreq *asyreq; asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12); + if (asyreq == NULL) + err(1, "malloc"); asyreq->req.len = 12; asyreq->req.type = FWASREQNODE; asyreq->pkt.mode.common.tcode = FWTCODE_PHY; @@ -268,6 +274,8 @@ struct fw_asyreq *asyreq; asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16); + if (asyreq == NULL) + err(1, "malloc"); asyreq->req.len = 16; asyreq->req.type = FWASREQNODE; asyreq->pkt.mode.wreqq.dst = FWLOCALBUS | (node & 0x3f); @@ -643,7 +651,11 @@ err(1, "ioctl FW_SRSTREAM"); buf = (char *)malloc(1024*16); + if (buf == NULL) + err(1, "malloc"); len = read(fd, buf, 1024*16); + if (len == -1) + err(1, "read"); ptr = (u_int32_t *) buf; ciph = (struct ciphdr *)(ptr + 1); @@ -688,12 +700,13 @@ * to iterate through */ int display_board_only = 0; - int priority_budget = 0; + long priority_budget = 0; int display_crom = 0; char *crom_string = NULL; char *crom_string_hex = NULL; int display_crom_hex = 0; int adjust_gap_count = 0; + int need_to_send_adjust_gap_count = 0; int reset_gap_count = 0; int load_crom_from_file = 0; int set_fwmem_target = 0; @@ -731,6 +744,8 @@ break; case 'c': crom_string = malloc(strlen(optarg)+1); + if (crom_string == NULL) + err(1, "malloc"); strcpy(crom_string, optarg); display_crom = 1; open_needed = 1; @@ -739,6 +754,8 @@ break; case 'd': crom_string_hex = malloc(strlen(optarg)+1); + if (crom_string == NULL) + err(1, "malloc"); strcpy(crom_string_hex, optarg); display_crom_hex = 1; open_needed = 1; @@ -747,6 +764,7 @@ break; case 'f': adjust_gap_count = strtol(optarg, NULL, 0); + need_to_send_adjust_gap_count = 1; open_needed = 1; command_set = 1; display_board_only = 0; @@ -827,6 +845,8 @@ break; case 'R': recv_data = malloc(strlen(optarg)+1); + if (recv_data == NULL) + err(1, "malloc"); strcpy(recv_data, optarg); open_needed = 1; command_set = 1; @@ -834,6 +854,8 @@ break; case 'S': send_data = malloc(strlen(optarg)+1); + if (send_data == NULL) + err(1, "malloc"); strcpy(send_data, optarg); open_needed = 1; display_board_only = 0; @@ -904,8 +926,10 @@ /* * Adjust the gap count for this card/bus to value "-f" */ - if (adjust_gap_count) + if (need_to_send_adjust_gap_count) + { send_phy_config(fd, adjust_gap_count, -1); + } /* * Reset the gap count for this card/bus "-g" From owner-freebsd-firewire@FreeBSD.ORG Sat Aug 9 20:12:30 2008 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 42847106564A; Sat, 9 Aug 2008 20:12:30 +0000 (UTC) (envelope-from sbruno@miralink.com) Received: from plato.miralink.com (mail.miralink.com [70.103.185.20]) by mx1.freebsd.org (Postfix) with ESMTP id 18D198FC0C; Sat, 9 Aug 2008 20:12:30 +0000 (UTC) (envelope-from sbruno@miralink.com) Received: from localhost (localhost.localdomain [127.0.0.1]) by plato.miralink.com (Postfix) with ESMTP id D823B1A90DA; Sat, 9 Aug 2008 13:06:58 -0700 (PDT) X-Virus-Scanned: amavisd-new at X-Spam-Flag: NO X-Spam-Score: -4.399 X-Spam-Level: X-Spam-Status: No, score=-4.399 tagged_above=-10 required=6.6 tests=[ALL_TRUSTED=-1.8, AWL=0.000, BAYES_00=-2.599] Received: from plato.miralink.com ([127.0.0.1]) by localhost (plato.miralink.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id koHc5fq-VK6d; Sat, 9 Aug 2008 13:06:58 -0700 (PDT) Received: from [10.47.1.6] (vpn.office.miralink.com [10.0.0.5]) by plato.miralink.com (Postfix) with ESMTP id 2F21C1A8EF0; Sat, 9 Aug 2008 13:06:58 -0700 (PDT) Message-ID: <489DFA2C.4080407@miralink.com> Date: Sat, 09 Aug 2008 13:12:28 -0700 From: Sean Bruno User-Agent: Thunderbird 2.0.0.16 (X11/20080723) MIME-Version: 1.0 To: Dieter References: <200808060123.BAA03303@sopwith.solgatos.com> In-Reply-To: <200808060123.BAA03303@sopwith.solgatos.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Scott Long , freebsd-firewire@freebsd.org Subject: Re: This is where I'm going with fwcontrol X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Aug 2008 20:12:30 -0000 Dieter wrote: >> fwcontrol.c: In function 'main': >> fwcontrol.c:726: warning: comparison is always false due to limited range of data type >> >> I changed priority_budget from int to long, is this the correct fix? >> > > I suspect that gcc will still complain on ILP32 machines. > Sorry for the delay...See the attached patch and test it on unpatched 6/7/8 as fwcontrol is the same on all platforms. I implemented your fix for priority_budget, i.e. I should have been paying attention to the conditional test and the assignment from strtol()! Also, I changed some of the variable to check for >= 0 and set their default values to -1. This should have the same effect as adding a new variable as you did in your fix. Let me know what you think! -- Sean Bruno MiraLink Corporation 6015 NE 80th Ave, Ste 100 Portland, OR 97218 Cell 503-358-6832 Phone 503-621-5143 Fax 503-621-5199 MSN: sbruno@miralink.com Google: seanwbruno@gmail.com From owner-freebsd-firewire@FreeBSD.ORG Sat Aug 9 20:14:00 2008 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4BB0A1065676; Sat, 9 Aug 2008 20:14:00 +0000 (UTC) (envelope-from sbruno@miralink.com) Received: from plato.miralink.com (mail.miralink.com [70.103.185.20]) by mx1.freebsd.org (Postfix) with ESMTP id 137A58FC15; Sat, 9 Aug 2008 20:14:00 +0000 (UTC) (envelope-from sbruno@miralink.com) Received: from localhost (localhost.localdomain [127.0.0.1]) by plato.miralink.com (Postfix) with ESMTP id D95E61A90DA; Sat, 9 Aug 2008 13:08:28 -0700 (PDT) X-Virus-Scanned: amavisd-new at X-Spam-Flag: NO X-Spam-Score: -4.399 X-Spam-Level: X-Spam-Status: No, score=-4.399 tagged_above=-10 required=6.6 tests=[ALL_TRUSTED=-1.8, AWL=0.000, BAYES_00=-2.599] Received: from plato.miralink.com ([127.0.0.1]) by localhost (plato.miralink.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MT9JRG2JmqhK; Sat, 9 Aug 2008 13:08:28 -0700 (PDT) Received: from [10.47.1.6] (vpn.office.miralink.com [10.0.0.5]) by plato.miralink.com (Postfix) with ESMTP id 9041D1A8EF0; Sat, 9 Aug 2008 13:08:27 -0700 (PDT) Message-ID: <489DFA86.4010507@miralink.com> Date: Sat, 09 Aug 2008 13:13:58 -0700 From: Sean Bruno User-Agent: Thunderbird 2.0.0.16 (X11/20080723) MIME-Version: 1.0 To: Dieter References: <200808060123.BAA03303@sopwith.solgatos.com> In-Reply-To: <200808060123.BAA03303@sopwith.solgatos.com> Content-Type: multipart/mixed; boundary="------------080306080803050709040006" Cc: Scott Long , freebsd-firewire@freebsd.org Subject: Re: This is where I'm going with fwcontrol(now with actual patch) X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Aug 2008 20:14:00 -0000 This is a multi-part message in MIME format. --------------080306080803050709040006 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Dieter wrote: >> fwcontrol.c: In function 'main': >> fwcontrol.c:726: warning: comparison is always false due to limited range of data type >> >> I changed priority_budget from int to long, is this the correct fix? >> > > I suspect that gcc will still complain on ILP32 machines. > Sorry for the delay...See the attached patch and test it on unpatched 6/7/8 as fwcontrol is the same on all platforms. I implemented your fix for priority_budget, i.e. I should have been paying attention to the conditional test and the assignment from strtol()! Also, I changed some of the variable to check for >= 0 and set their default values to -1. This should have the same effect as adding a new variable as you did in your fix. Let me know what you think! -- Sean Bruno MiraLink Corporation 6015 NE 80th Ave, Ste 100 Portland, OR 97218 Cell 503-358-6832 Phone 503-621-5143 Fax 503-621-5199 MSN: sbruno@miralink.com Google: seanwbruno@gmail.com --------------080306080803050709040006 Content-Type: text/x-patch; name="fwcontrol.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="fwcontrol.diff" Index: fwcontrol.8 =================================================================== --- fwcontrol.8 (revision 181478) +++ fwcontrol.8 (working copy) @@ -59,7 +59,7 @@ The following options are available: .Bl -tag -width indent .It Fl u Ar bus_num -Specify the FireWire bus number to be operated on. +Specify the FireWire bus number to be operated on. Default is bus 0. .It Fl r Initiate bus reset. .It Fl t Index: fwcontrol.c =================================================================== --- fwcontrol.c (revision 181478) +++ fwcontrol.c (working copy) @@ -81,6 +81,7 @@ "\t-l: load and parse hex dump file of configuration ROM\n" "\t-R: Receive DV or MPEG TS stream\n" "\t-S: Send DV stream\n" + "\t-p: Display current PHY register settings\n" "\t-m: set fwmem target\n"); exit(EX_USAGE); } @@ -92,18 +93,14 @@ *(u_int32_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 = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); if (data == NULL) err(1, "malloc"); if( ioctl(fd, FW_GDEVLST, data) < 0) { err(1, "ioctl"); } - return data; } static int @@ -130,17 +127,23 @@ if (eui64_hostton(nodestr, &eui) != 0 && eui64_aton(nodestr, &eui) != 0) return (-1); - data = get_dev(fd); + data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); + 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) + if (i >= data->info_len) { + if (data != NULL) + free(data); return (-1); + } gotnode: if (node < 0 || node > 63) @@ -158,7 +161,8 @@ char addr[EUI64_SIZ], hostname[40]; int i; - data = get_dev(fd); + data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); + get_dev(fd, data); printf("%d devices (info_len=%d)\n", data->n, data->info_len); printf("node EUI64 status hostname\n"); for (i = 0; i < data->info_len; i++) { @@ -242,7 +246,7 @@ } static void -send_link_on(int fd, int node) +link_on(int fd, int node) { struct fw_asyreq *asyreq; @@ -290,7 +294,8 @@ u_int32_t max, reg, old; int i; - data = get_dev(fd); + data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); + get_dev(fd, data); #define BUGET_REG 0xf0000218 for (i = 0; i < data->info_len; i++) { devinfo = &data->dev[i]; @@ -344,7 +349,8 @@ int i, error; struct fw_devlstreq *data; - data = get_dev(fd); + data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); + get_dev(fd, data); for (i = 0; i < data->info_len; i++) { if (data->dev[i].dst == node && data->dev[i].eui.lo != 0) @@ -590,22 +596,16 @@ ); } -static void -open_dev(int *fd, char *devbase) +static int +open_dev(int *fd, char *devname) { - char name[256]; - int i; - if (*fd < 0) { - for (i = 0; i < 4; i++) { - snprintf(name, sizeof(name), "%s.%d", devbase, i); - if ((*fd = open(name, O_RDWR)) >= 0) - break; - } + *fd = open(devname, O_RDWR); if (*fd < 0) - err(1, "open"); + return(-1); } + return(0); } static void @@ -666,99 +666,147 @@ int main(int argc, char **argv) { +#define MAX_BOARDS 10 u_int32_t crom_buf[1024/4]; - char devbase[1024] = "/dev/fw0"; - int fd, ch, len=1024; + u_int32_t crom_buf_hex[1024/4]; + char devbase[64]; + const char *device_string = "/dev/fw"; + int fd = -1, ch, len=1024; + int 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 + */ + int command_set = 0; + int open_needed = 0; long tmp; struct fw_eui64 eui; struct eui64 target; fwmethod *recvfn = NULL; +/* + * Holders for which functions + * to iterate through + */ + int display_board_only = 0; + long priority_budget = -1; + int display_crom = 0; + char *crom_string = NULL; + char *crom_string_hex = NULL; + int display_crom_hex = 0; + int adjust_gap_count = -1; + int reset_gap_count = 0; + int load_crom_from_file = 0; + int set_fwmem_target = 0; + long dump_phy_reg = 0; + int dump_topology = 0; + long send_link_on = 0; + int send_bus_reset = 0; + long send_reset_start = 0; + char *recv_data = NULL; + char *send_data = NULL; - fd = -1; - if (argc < 2) { - open_dev(&fd, devbase); - list_dev(fd); + for (current_board = 0; current_board < MAX_BOARDS; current_board++) { + snprintf(devbase, sizeof(devbase), "%s%d", device_string, current_board); + if (open_dev(&fd, devbase) < 0) { + return(0); + } + list_dev(fd); + close(fd); + fd = -1; + } } - - while ((ch = getopt(argc, argv, "M:f:g:m:o:s:b:prtc:d:l:u:R:S:")) != -1) + /* + * 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) { switch(ch) { case 'b': - tmp = strtol(optarg, NULL, 0); - if (tmp < 0 || tmp > (long)0xffffffff) + priority_budget = strtol(optarg, NULL, 0); + if (priority_budget < 0 || priority_budget > (long)0xffffffff) errx(EX_USAGE, "invalid number: %s", optarg); - open_dev(&fd, devbase); - set_pri_req(fd, tmp); + command_set = 1; + open_needed = 1; + display_board_only = 0; break; case 'c': - open_dev(&fd, devbase); - tmp = str2node(fd, optarg); - get_crom(fd, tmp, crom_buf, len); - show_crom(crom_buf); + crom_string = malloc(strlen(optarg)+1); + strcpy(crom_string, optarg); + display_crom = 1; + open_needed = 1; + command_set = 1; + display_board_only = 0; break; case 'd': - open_dev(&fd, devbase); - tmp = str2node(fd, optarg); - get_crom(fd, tmp, crom_buf, len); - dump_crom(crom_buf); + crom_string_hex = malloc(strlen(optarg)+1); + strcpy(crom_string_hex, optarg); + display_crom_hex = 1; + open_needed = 1; + command_set = 1; + display_board_only = 0; break; case 'f': - tmp = strtol(optarg, NULL, 0); - open_dev(&fd, devbase); - send_phy_config(fd, tmp, -1); + adjust_gap_count = strtol(optarg, NULL, 0); + open_needed = 1; + command_set = 1; + display_board_only = 0; break; case 'g': - tmp = strtol(optarg, NULL, 0); - open_dev(&fd, devbase); - send_phy_config(fd, -1, tmp); + reset_gap_count = strtol(optarg, NULL, 0); + open_needed = 1; + command_set = 1; + display_board_only = 0; break; case 'l': + load_crom_from_file = 1; load_crom(optarg, crom_buf); - show_crom(crom_buf); + command_set = 1; + display_board_only = 0; break; case 'm': - if (eui64_hostton(optarg, &target) != 0 && - eui64_aton(optarg, &target) != 0) + set_fwmem_target = 1; + open_needed = 0; + command_set = 1; + display_board_only = 0; + if (eui64_hostton(optarg, &target) != 0 && + eui64_aton(optarg, &target) != 0) errx(EX_USAGE, "invalid target: %s", optarg); - eui.hi = ntohl(*(u_int32_t*)&(target.octet[0])); - eui.lo = ntohl(*(u_int32_t*)&(target.octet[4])); - sysctl_set_int("hw.firewire.fwmem.eui64_hi", eui.hi); - sysctl_set_int("hw.firewire.fwmem.eui64_lo", eui.lo); break; case 'o': - open_dev(&fd, devbase); - tmp = str2node(fd, optarg); - send_link_on(fd, tmp); + send_link_on = str2node(fd, optarg); + open_needed = 1; + command_set = 1; + display_board_only = 0; break; case 'p': - open_dev(&fd, devbase); - dump_phy_registers(fd); + dump_phy_reg = 1; + open_needed = 1; + command_set = 1; + display_board_only = 0; break; case 'r': - open_dev(&fd, devbase); - if(ioctl(fd, FW_IBUSRST, &tmp) < 0) - err(1, "ioctl"); + send_bus_reset = 1; + open_needed = 1; + command_set = 1; + display_board_only = 0; break; case 's': - open_dev(&fd, devbase); - tmp = str2node(fd, optarg); - reset_start(fd, tmp); + send_reset_start = str2node(fd, optarg); + open_needed = 1; + command_set = 1; + display_board_only = 0; break; case 't': - open_dev(&fd, devbase); - show_topology_map(fd); + dump_topology = 1; + open_needed = 1; + command_set = 1; + display_board_only = 0; break; case 'u': - tmp = strtol(optarg, NULL, 0); - snprintf(devbase, sizeof(devbase), "/dev/fw%ld", tmp); - if (fd > 0) { - close(fd); - fd = -1; - } - if (argc == optind) { - open_dev(&fd, devbase); - list_dev(fd); - } + if(!command_set) + display_board_only = 1; + current_board = strtol(optarg, NULL, 0); + open_needed = 1; break; #define TAG (1<<6) #define CHANNEL 63 @@ -774,22 +822,151 @@ errx(EX_USAGE, "unrecognized method: %s", optarg); } + command_set = 1; + display_board_only = 0; break; case 'R': - open_dev(&fd, devbase); - if (recvfn == NULL) /* guess... */ - recvfn = detect_recv_fn(fd, TAG | CHANNEL); - close(fd); - fd = -1; - open_dev(&fd, devbase); - (*recvfn)(fd, optarg, TAG | CHANNEL, -1); + recv_data = malloc(strlen(optarg)+1); + strcpy(recv_data, optarg); + open_needed = 1; + command_set = 1; + display_board_only = 0; break; case 'S': - open_dev(&fd, devbase); - dvsend(fd, optarg, TAG | CHANNEL, -1); + send_data = malloc(strlen(optarg)+1); + strcpy(send_data, optarg); + open_needed = 1; + display_board_only = 0; break; default: usage(); + return 0; } + } /* end while */ + + /* + * If -u is passed, execute + * command for that card only. + * + * If -u is not passed, execute + * command for card 0 only. + * + */ + if(open_needed){ + snprintf(devbase, sizeof(devbase), "%s%d", device_string, current_board); + if (open_dev(&fd, devbase) < 0) + return(EIO); + } + /* + * 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) + err(1, "ioctl"); + } + /* + * 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); + + /* + * Adjust the gap count for this card/bus to value "-f" + */ + if (adjust_gap_count >= 0) + send_phy_config(fd, adjust_gap_count, -1); + + /* + * Reset the gap count for this card/bus "-g" + */ + if (reset_gap_count) + send_phy_config(fd, -1, tmp); + + /* + * 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])); + sysctl_set_int("hw.firewire.fwmem.eui64_hi", eui.hi); + sysctl_set_int("hw.firewire.fwmem.eui64_lo", eui.lo); + } + + /* + * Send a link on to this board/bus "-o" + */ + if (send_link_on) + link_on(fd, send_link_on); + + /* + * Send a reset start to this board/bus "-s" + */ + if (send_reset_start) + reset_start(fd, send_reset_start); + + /* + * Dump the node topology for this board/bus "-t" + */ + if (dump_topology) + show_topology_map(fd); + + /* + * Recieve data file from node "-R" + */ + if (recv_data != NULL){ + if (recvfn == NULL) /* guess... */ + recvfn = detect_recv_fn(fd, TAG | CHANNEL); + (*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; + } return 0; } --------------080306080803050709040006--