Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Jun 2008 15:12:58 -0700
From:      Sean Bruno <sbruno@miralink.com>
To:        freebsd-firewire@freebsd.org, Hidetoshi Shimokawa <simokawa@FreeBSD.ORG>
Subject:   This is where I'm going with fwcontrol
Message-ID:  <48695A6A.1030701@miralink.com>
In-Reply-To: <48668196.6080602@miralink.com>
References:  <486680D5.9070106@miralink.com> <48668196.6080602@miralink.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------000801080501060205070102
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Take a look at what I'm doing with fwcontrol if you have time.

I'm modifying it such that it can find nodes on different "buses" or 
cards and allowing it to parse all arguments before execution begins.  
It's in the primitive stages right now and I'd really like to know what 
you think.

Here is a current diff against RELENG_7 which seems to be the same as 
-CURRENT.

Sean

--------------000801080501060205070102
Content-Type: text/x-patch;
 name="fwcontrol.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="fwcontrol.diff"

Only in RELENG_7/src/usr.sbin/fwcontrol/: .fwcontrol.c.swp
diff -u reference_RELENG_7/src/usr.sbin/fwcontrol/fwcontrol.c RELENG_7/src/usr.sbin/fwcontrol/fwcontrol.c
--- reference_RELENG_7/src/usr.sbin/fwcontrol/fwcontrol.c	2008-05-01 23:15:58.000000000 -0700
+++ RELENG_7/src/usr.sbin/fwcontrol/fwcontrol.c	2008-06-30 09:05:21.000000000 -0700
@@ -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);
 }
@@ -590,22 +591,20 @@
 	);
 }
 
-static void
+static int
 open_dev(int *fd, char *devbase)
 {
 	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;
-		}
+		snprintf(name, sizeof(name), "%s.%d", devbase, i);
+		*fd = open(name, O_RDWR);
 		if (*fd < 0)
-			err(1, "open");
+			return(-1);
 
 	}
+	return(0);
 }
 
 static void
@@ -666,57 +665,107 @@
 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 dev_counter = 0;
+	int num_boards = 0;
+	int current_board = 0;
+	int open_needed = 0;
 	long tmp;
 	struct fw_eui64 eui;
 	struct eui64 target;
 	fwmethod *recvfn = NULL;
-
-	fd = -1;
-
-	if (argc < 2) {
-		open_dev(&fd, devbase);
-		list_dev(fd);
-	}
-
-	while ((ch = getopt(argc, argv, "M:f:g:m:o:s:b:prtc:d:l:u:R:S:")) != -1)
+/*
+ * Holders for which functions
+ * to iterate through
+ */
+	int priority_budget = 0;
+	int display_crom = 0;
+	char *crom_string = NULL;
+	char *crom_string_hex = NULL;
+	int display_crom_hex = 0;
+	int display_bus = MAX_BOARDS;
+	int adjust_gap_count = 0;
+	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;
+	int send_link_on = 0;
+	int send_bus_reset = 0;
+	int send_reset_start = 0;
+	int recv_data = 0;
+	int send_data = 0;
+
+	if (argc < 2)
+		open_needed = 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);
+			open_needed = 1;
+			display_bus = -1;
+# if 0
+                        open_dev(&fd, devbase);
+                        set_pri_req(fd, tmp);
+#endif
 			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;
+			display_bus = -1;
 			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;
+			display_bus = -1;
 			break;
 		case 'f':
+			adjust_gap_count = 1;
+			open_needed = 1;
+			display_bus = -1;
+#if 0
 			tmp = strtol(optarg, NULL, 0);
 			open_dev(&fd, devbase);
 			send_phy_config(fd, tmp, -1);
+#endif
 			break;
 		case 'g':
+			reset_gap_count = 1;
+			open_needed = 1;
+			display_bus = -1;
+#if 0
 			tmp = strtol(optarg, NULL, 0);
 			open_dev(&fd, devbase);
 			send_phy_config(fd, -1, tmp);
+#endif
 			break;
 		case 'l':
+			load_crom_from_file = 1;
+			open_needed = 1;
+			display_bus = -1;
+#if 0
 			load_crom(optarg, crom_buf);
 			show_crom(crom_buf);
+#endif
 			break;
 		case 'm':
+			set_fwmem_target = 1;
+			display_bus = -1;
+#if 0
 		       if (eui64_hostton(optarg, &target) != 0 &&
 			   eui64_aton(optarg, &target) != 0)
 				errx(EX_USAGE, "invalid target: %s", optarg);
@@ -724,41 +773,49 @@
 			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);
+#endif
 			break;
 		case 'o':
+			send_link_on = 1;
+			open_needed = 1;
+			display_bus = -1;
+#if 0
 			open_dev(&fd, devbase);
 			tmp = str2node(fd, optarg);
 			send_link_on(fd, tmp);
+#endif
 			break;
 		case 'p':
-			open_dev(&fd, devbase);
-			dump_phy_registers(fd);
+			dump_phy_reg = 1;
+			open_needed = 1;
+			display_bus = -1;
 			break;
 		case 'r':
-			open_dev(&fd, devbase);
-			if(ioctl(fd, FW_IBUSRST, &tmp) < 0)
-                       		err(1, "ioctl");
+			send_bus_reset = 1;
+			open_needed = 1;
+			display_bus = -1;
 			break;
 		case 's':
+			send_reset_start  = str2node(fd, optarg);
+			open_needed = 1;
+			display_bus = -1;
+#if 0
 			open_dev(&fd, devbase);
-			tmp = str2node(fd, optarg);
 			reset_start(fd, tmp);
+#endif
 			break;
 		case 't':
+			dump_topology = 1;
+			open_needed = 1;
+			display_bus = -1;
+#if 0
 			open_dev(&fd, devbase);
 			show_topology_map(fd);
+#endif
 			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);
-			}
+			display_bus = strtol(optarg, NULL, 0);
+			open_needed = 1;
 			break;
 #define TAG	(1<<6)
 #define CHANNEL	63
@@ -774,8 +831,13 @@
 				errx(EX_USAGE, "unrecognized method: %s",
 				    optarg);
 			}
+			display_bus = -1;
 			break;
 		case 'R':
+			recv_data = 1;
+			open_needed = 1;
+			display_bus = -1;
+#if 0
 			open_dev(&fd, devbase);
 			if (recvfn == NULL) /* guess... */
 				recvfn = detect_recv_fn(fd, TAG | CHANNEL);
@@ -783,13 +845,126 @@
 			fd = -1;
 			open_dev(&fd, devbase);
 			(*recvfn)(fd, optarg, TAG | CHANNEL, -1);
+#endif
 			break;
 		case 'S':
+			send_data = 1;
+			open_needed = 1;
+			display_bus = -1;
+#if 0
 			open_dev(&fd, devbase);
 			dvsend(fd, optarg, TAG | CHANNEL, -1);
+#endif
 			break;
 		default:
 			usage();
+			return 0;
 		}
+	}
+       /*
+	* Iterate over the boards and display the 
+	* node configuration if no other arguments
+	* are passed, eg "sudo fwcontrol"
+	*
+	* If any arguments are passed, assume board
+	* 0 for compatiblity reasons.
+
+	* If command is set and this card is the bus
+	* we wish to execute the command for, then do it.
+	* 
+	*/
+	for (current_board = 0; current_board < MAX_BOARDS; current_board++) {
+		if(open_needed){
+			snprintf(devbase, sizeof(devbase), "%s%d", device_string, current_board);
+			if (open_dev(&fd, devbase) < 0)
+				return(EIO);
+		}
+		if (current_board == display_bus ||
+		    display_bus == MAX_BOARDS) {
+			list_dev(fd);
+		}
+		/*
+		 * dump_phy_reg "-p" 
+		 */
+		if (dump_phy_reg) {
+			if (display_bus == -1) {
+				if (current_board == 0) { /* This mimics the old behavior */
+					dump_phy_registers(fd);
+				} else {
+					errx(EX_USAGE, "Displaying PHY registers requires -u <bus number>\n");
+					usage();
+				}
+			} else if (current_board == display_bus)
+				dump_phy_registers(fd);
+		}
+				
+		/*
+		 * send a BUS_RESET Event "-r"
+		 */
+		if (send_bus_reset) {
+			if (display_bus == -1) {
+				if (current_board == 0) { /* This mimics the old behavior */
+					if(ioctl(fd, FW_IBUSRST, &tmp) < 0)
+                       				err(1, "ioctl");
+				} else {
+					errx(EX_USAGE, "Sending a BUS Reset requires -u <bus_number>\n");
+					usage();
+				}
+			} else if (current_board == display_bus) {
+					if(ioctl(fd, FW_IBUSRST, &tmp) < 0)
+                       				err(1, "ioctl");
+			}
+		}
+		/*
+		 * Print out the CROM for this node "-c"
+		 */
+		if (display_crom) {
+			if (display_bus == -1) {
+				if (current_board == 0) { /* This mimics the old behavior */
+					tmp = str2node(fd, crom_string);
+					get_crom(fd, tmp, crom_buf, len);
+					show_crom(crom_buf);
+					free(crom_string);
+				} else {
+					if(crom_string != NULL)
+						free(crom_string);
+					errx(EX_USAGE, "Displaying the CROM for a node requires -u <bus number>\n");
+					usage();
+				}
+			} else if (current_board == display_bus) {
+					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) {
+			if (display_bus == -1) {
+				if (current_board == 0) { /* This mimics the old behavior */
+					tmp = str2node(fd, crom_string_hex);
+					get_crom(fd, tmp, crom_buf, len);
+					dump_crom(crom_buf);
+					free(crom_string_hex);
+				} else {
+					if(crom_string != NULL)
+						free(crom_string);
+					errx(EX_USAGE, "Dumping the CROM for a node requires -u <bus number>\n");
+					usage();
+				}
+			} else if (current_board == display_bus) {
+					tmp = str2node(fd, crom_string_hex);
+					get_crom(fd, tmp, crom_buf, len);
+					dump_crom(crom_buf);
+					free(crom_string_hex);
+			}
+		}
+		if (fd > 0) {
+			close(fd);
+			fd = -1;
+		}
+	}
 	return 0;
 }

--------------000801080501060205070102--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?48695A6A.1030701>