Subject: bin/21207: add fibre channel wwn information to scsictl
To: None <gnats-bugs@gnats.netbsd.org>
From: Eric Schnoebelen <eric@egsnore.cirr.com>
List: netbsd-bugs
Date: 04/16/2003 17:18:41
>Number:         21207
>Category:       bin
>Synopsis:       add fibre channel wwn information gathering to scsictl
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 16 22:19:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Eric Schnoebelen
>Release:        NetBSD 1.6
>Organization:
Eric Schnoebelen	eric@cirr.com			http://www.cirr.com
>Environment:
System: NetBSD egsnore.cirr.com 1.6 NetBSD 1.6 (GENERIC) #0: Sun Sep 8 19:43:40 UTC 2002 autobuild@tgm.daemon.org:/autobuild/i386/OBJ/autobuild/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
	I've added a subcommand to scsictl(8) to allow it to retrieve
	(and display) WWN information for attached fibre channel drives.

	The source base is -current as of 12 April, 2003.
>How-To-Repeat:
	enhancement request:  try to gather the wwn's from fc devices
	    from the NetBSD userland.
>Fix:
cvs server: Diffing .
Index: scsictl.c
===================================================================
RCS file: /cvsroot/src/sbin/scsictl/scsictl.c,v
retrieving revision 1.19
diff -b -u -w -r1.19 scsictl.c
--- scsictl.c	2002/09/26 06:15:38	1.19
+++ scsictl.c	2003/04/16 22:18:00
@@ -58,6 +58,8 @@
 #include <dev/scsipi/scsi_disk.h>
 #include <dev/scsipi/scsipiconf.h>
 
+#include <dev/ic/isp_ioctl.h>
+
 #include "extern.h"
 
 struct command {
@@ -108,11 +110,13 @@
 void	bus_reset __P((int, char *[]));
 void	bus_scan __P((int, char *[]));
 void	bus_detach __P((int, char *[]));
+void	bus_getwwn __P((int, char *[]));
 
 struct command bus_commands[] = {
 	{ "reset",	"",			bus_reset },
 	{ "scan",	"target lun",		bus_scan },
 	{ "detach",	"target lun",		bus_detach },
+	{ "getwwn",	"target",		bus_getwwn },
 	{ NULL,		NULL,				NULL },
 };
 
@@ -870,6 +874,65 @@
 
 	if (ioctl(fd, SCBUSIODETACH, &args) != 0)
 		err(1, "SCBUSIODETACH");
+
+	return;
+}
+
+/*
+ * scsictl_getwwn_info
+ *
+ *	query individual fc device to get (and print) the 
+ *	port/node wwn information
+ */
+
+scsictl_getwwn_info(loopid)
+	int loopid;
+{
+	struct isp_fc_device args;
+	int rc;
+
+	args.loopid = loopid;
+	if ((rc = ioctl(fd, ISP_FC_GETDINFO, &args)) == 0) {
+	    printf( "%s: loopid: %d portid: %d\n",
+		    dvname,
+		    args.loopid, args.portid);
+	    printf( "%s: node wwn: %llx port wwn: %llx\n",
+		    dvname, 
+		    args.node_wwn, args.port_wwn);
+	}
+	return rc;
+}
+
+/*
+ * bus_getwwn:
+ *
+ *	query the fc bus to get port and node wwn information
+ */
+void
+bus_getwwn(argc, argv)
+	int argc;
+	char *argv[];
+{
+	char *cp;
+	int loopid;
+
+	/* Must have two args: loopid */
+	if (argc != 1)
+		usage();
+
+	if (strcmp(argv[0], "any") == 0 || strcmp(argv[0], "all") == 0)
+		for  (loopid = 0; loopid <= 255; loopid++) {
+		    scsictl_getwwn_info(loopid);
+		}
+	else {
+		loopid = strtol(argv[0], &cp, 10);
+		if (*cp != '\0' || loopid < 0 || loopid > 255)
+			errx(1, "invalid target: %s", argv[0]);
+
+		if (scsictl_getwwn_info(loopid) != 0)
+			err(1, "ISP_FC_GETDINFO");
+	}
+
 
 	return;
 }
>Release-Note:
>Audit-Trail:
>Unformatted: