Home | History | Annotate | Line # | Download | only in iopctl
iopctl.c revision 1.11.2.2
      1  1.11.2.2  he /*	$NetBSD: iopctl.c,v 1.11.2.2 2001/12/09 18:38:09 he Exp $	*/
      2  1.11.2.2  he 
      3  1.11.2.2  he /*-
      4  1.11.2.2  he  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  1.11.2.2  he  * All rights reserved.
      6  1.11.2.2  he  *
      7  1.11.2.2  he  * This code is derived from software contributed to The NetBSD Foundation
      8  1.11.2.2  he  * by Andrew Doran.
      9  1.11.2.2  he  *
     10  1.11.2.2  he  * Redistribution and use in source and binary forms, with or without
     11  1.11.2.2  he  * modification, are permitted provided that the following conditions
     12  1.11.2.2  he  * are met:
     13  1.11.2.2  he  * 1. Redistributions of source code must retain the above copyright
     14  1.11.2.2  he  *    notice, this list of conditions and the following disclaimer.
     15  1.11.2.2  he  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.11.2.2  he  *    notice, this list of conditions and the following disclaimer in the
     17  1.11.2.2  he  *    documentation and/or other materials provided with the distribution.
     18  1.11.2.2  he  * 3. All advertising materials mentioning features or use of this software
     19  1.11.2.2  he  *    must display the following acknowledgement:
     20  1.11.2.2  he  *	This product includes software developed by the NetBSD
     21  1.11.2.2  he  *	Foundation, Inc. and its contributors.
     22  1.11.2.2  he  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.11.2.2  he  *    contributors may be used to endorse or promote products derived
     24  1.11.2.2  he  *    from this software without specific prior written permission.
     25  1.11.2.2  he  *
     26  1.11.2.2  he  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.11.2.2  he  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.11.2.2  he  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.11.2.2  he  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.11.2.2  he  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.11.2.2  he  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.11.2.2  he  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.11.2.2  he  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.11.2.2  he  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.11.2.2  he  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.11.2.2  he  * POSSIBILITY OF SUCH DAMAGE.
     37  1.11.2.2  he  */
     38  1.11.2.2  he 
     39  1.11.2.2  he #ifndef lint
     40  1.11.2.2  he #include <sys/cdefs.h>
     41  1.11.2.2  he __RCSID("$NetBSD: iopctl.c,v 1.11.2.2 2001/12/09 18:38:09 he Exp $");
     42  1.11.2.2  he #endif /* not lint */
     43  1.11.2.2  he 
     44  1.11.2.2  he #include <sys/param.h>
     45  1.11.2.2  he #include <sys/ioctl.h>
     46  1.11.2.2  he #include <sys/uio.h>
     47  1.11.2.2  he #include <sys/device.h>
     48  1.11.2.2  he 
     49  1.11.2.2  he #include <err.h>
     50  1.11.2.2  he #include <errno.h>
     51  1.11.2.2  he #include <fcntl.h>
     52  1.11.2.2  he #include <stdio.h>
     53  1.11.2.2  he #include <stdlib.h>
     54  1.11.2.2  he #include <stdarg.h>
     55  1.11.2.2  he #include <string.h>
     56  1.11.2.2  he #include <unistd.h>
     57  1.11.2.2  he #include <util.h>
     58  1.11.2.2  he #include <getopt.h>
     59  1.11.2.2  he 
     60  1.11.2.2  he #include <dev/i2o/i2o.h>
     61  1.11.2.2  he #include <dev/i2o/iopio.h>
     62  1.11.2.2  he 
     63  1.11.2.2  he const char	*class2str(int);
     64  1.11.2.2  he void	getparam(int, int, void *, int);
     65  1.11.2.2  he int	gettid(char **);
     66  1.11.2.2  he int	main(int, char **);
     67  1.11.2.2  he int	show(const char *, const char *, ...);
     68  1.11.2.2  he void	i2ostrvis(const char *, int, char *, int);
     69  1.11.2.2  he void	usage(void);
     70  1.11.2.2  he 
     71  1.11.2.2  he void	reconfig(char **);
     72  1.11.2.2  he void	showdevid(char **);
     73  1.11.2.2  he void	showddmid(char **);
     74  1.11.2.2  he void	showlct(char **);
     75  1.11.2.2  he void	showstatus(char **);
     76  1.11.2.2  he void	showtidmap(char **);
     77  1.11.2.2  he 
     78  1.11.2.2  he struct {
     79  1.11.2.2  he 	int	class;
     80  1.11.2.2  he 	const char	*caption;
     81  1.11.2.2  he } const i2oclass[] = {
     82  1.11.2.2  he 	{ I2O_CLASS_EXECUTIVE, "executive" },
     83  1.11.2.2  he 	{ I2O_CLASS_DDM, "device driver module" },
     84  1.11.2.2  he 	{ I2O_CLASS_RANDOM_BLOCK_STORAGE, "random block storage" },
     85  1.11.2.2  he 	{ I2O_CLASS_SEQUENTIAL_STORAGE,	"sequential storage" },
     86  1.11.2.2  he 	{ I2O_CLASS_LAN, "LAN port" },
     87  1.11.2.2  he 	{ I2O_CLASS_WAN, "WAN port" },
     88  1.11.2.2  he 	{ I2O_CLASS_FIBRE_CHANNEL_PORT,	"fibrechannel port" },
     89  1.11.2.2  he 	{ I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL, "fibrechannel peripheral" },
     90  1.11.2.2  he  	{ I2O_CLASS_SCSI_PERIPHERAL, "SCSI peripheral" },
     91  1.11.2.2  he 	{ I2O_CLASS_ATE_PORT, "ATE port" },
     92  1.11.2.2  he 	{ I2O_CLASS_ATE_PERIPHERAL, "ATE peripheral" },
     93  1.11.2.2  he 	{ I2O_CLASS_FLOPPY_CONTROLLER, "floppy controller" },
     94  1.11.2.2  he 	{ I2O_CLASS_FLOPPY_DEVICE, "floppy device" },
     95  1.11.2.2  he 	{ I2O_CLASS_BUS_ADAPTER_PORT, "bus adapter port" },
     96  1.11.2.2  he };
     97  1.11.2.2  he 
     98  1.11.2.2  he struct {
     99  1.11.2.2  he 	const char	*label;
    100  1.11.2.2  he 	int	takesargs;
    101  1.11.2.2  he 	void	(*func)(char **);
    102  1.11.2.2  he } const cmdtab[] = {
    103  1.11.2.2  he 	{ "reconfig", 0, reconfig },
    104  1.11.2.2  he 	{ "showddmid", 1, showddmid },
    105  1.11.2.2  he 	{ "showdevid", 1, showdevid },
    106  1.11.2.2  he 	{ "showlct", 0, showlct },
    107  1.11.2.2  he 	{ "showstatus",	0, showstatus },
    108  1.11.2.2  he 	{ "showtidmap",	0, showtidmap },
    109  1.11.2.2  he };
    110  1.11.2.2  he 
    111  1.11.2.2  he int	fd;
    112  1.11.2.2  he char	buf[32768];
    113  1.11.2.2  he struct	i2o_status status;
    114  1.11.2.2  he 
    115  1.11.2.2  he int
    116  1.11.2.2  he main(int argc, char **argv)
    117  1.11.2.2  he {
    118  1.11.2.2  he 	int ch, i;
    119  1.11.2.2  he 	const char *dv;
    120  1.11.2.2  he 	struct iovec iov;
    121  1.11.2.2  he 
    122  1.11.2.2  he 	dv = "/dev/iop0";
    123  1.11.2.2  he 
    124  1.11.2.2  he 	while ((ch = getopt(argc, argv, "f:")) != -1) {
    125  1.11.2.2  he 		switch (ch) {
    126  1.11.2.2  he 		case 'f':
    127  1.11.2.2  he 			dv = optarg;
    128  1.11.2.2  he 			break;
    129  1.11.2.2  he 		default:
    130  1.11.2.2  he 			usage();
    131  1.11.2.2  he 			/* NOTREACHED */
    132  1.11.2.2  he 		}
    133  1.11.2.2  he 	}
    134  1.11.2.2  he 
    135  1.11.2.2  he 	if (argv[optind] == NULL)
    136  1.11.2.2  he 		usage();
    137  1.11.2.2  he 
    138  1.11.2.2  he 	if ((fd = open(dv, O_RDWR)) < 0)
    139  1.11.2.2  he 		err(EXIT_FAILURE, "%s", dv);
    140  1.11.2.2  he 
    141  1.11.2.2  he 	iov.iov_base = &status;
    142  1.11.2.2  he 	iov.iov_len = sizeof(status);
    143  1.11.2.2  he 	if (ioctl(fd, IOPIOCGSTATUS, &iov) < 0)
    144  1.11.2.2  he 		err(EXIT_FAILURE, "IOPIOCGSTATUS");
    145  1.11.2.2  he 
    146  1.11.2.2  he 	for (i = 0; i < sizeof(cmdtab) / sizeof(cmdtab[0]); i++)
    147  1.11.2.2  he 		if (strcmp(argv[optind], cmdtab[i].label) == 0) {
    148  1.11.2.2  he 			if (cmdtab[i].takesargs == 0 &&
    149  1.11.2.2  he 			    argv[optind + 1] != NULL)
    150  1.11.2.2  he 			    	usage();
    151  1.11.2.2  he 			(*cmdtab[i].func)(argv + optind + 1);
    152  1.11.2.2  he 			break;
    153  1.11.2.2  he 		}
    154  1.11.2.2  he 
    155  1.11.2.2  he 	if (i == sizeof(cmdtab) / sizeof(cmdtab[0]))
    156  1.11.2.2  he 		errx(EXIT_FAILURE, "unknown command ``%s''", argv[optind]);
    157  1.11.2.2  he 
    158  1.11.2.2  he 	close(fd);
    159  1.11.2.2  he 	exit(EXIT_SUCCESS);
    160  1.11.2.2  he 	/* NOTREACHED */
    161  1.11.2.2  he }
    162  1.11.2.2  he 
    163  1.11.2.2  he void
    164  1.11.2.2  he usage(void)
    165  1.11.2.2  he {
    166  1.11.2.2  he 	extern char *__progname;
    167  1.11.2.2  he 
    168  1.11.2.2  he 	(void)fprintf(stderr, "usage: %s [-f dev] <command> [target]\n",
    169  1.11.2.2  he 	    __progname);
    170  1.11.2.2  he 	exit(EXIT_FAILURE);
    171  1.11.2.2  he 	/* NOTREACHED */
    172  1.11.2.2  he }
    173  1.11.2.2  he 
    174  1.11.2.2  he int
    175  1.11.2.2  he show(const char *hdr, const char *fmt, ...)
    176  1.11.2.2  he {
    177  1.11.2.2  he 	int i;
    178  1.11.2.2  he 	va_list va;
    179  1.11.2.2  he 
    180  1.11.2.2  he 	for (i = printf("%s", hdr); i < 25; i++)
    181  1.11.2.2  he 		putchar(' ');
    182  1.11.2.2  he 	va_start(va, fmt);
    183  1.11.2.2  he 	i += vprintf(fmt, va);
    184  1.11.2.2  he 	va_end(va);
    185  1.11.2.2  he 	putchar('\n');
    186  1.11.2.2  he 	return (i);
    187  1.11.2.2  he }
    188  1.11.2.2  he 
    189  1.11.2.2  he const char *
    190  1.11.2.2  he class2str(int class)
    191  1.11.2.2  he {
    192  1.11.2.2  he 	int i;
    193  1.11.2.2  he 
    194  1.11.2.2  he 	for (i = 0; i < sizeof(i2oclass) / sizeof(i2oclass[0]); i++)
    195  1.11.2.2  he 		if (class == i2oclass[i].class)
    196  1.11.2.2  he 			return (i2oclass[i].caption);
    197  1.11.2.2  he 
    198  1.11.2.2  he 	return ("unknown");
    199  1.11.2.2  he }
    200  1.11.2.2  he 
    201  1.11.2.2  he void
    202  1.11.2.2  he getparam(int tid, int group, void *pbuf, int pbufsize)
    203  1.11.2.2  he {
    204  1.11.2.2  he 	struct ioppt pt;
    205  1.11.2.2  he 	struct i2o_util_params_op mb;
    206  1.11.2.2  he 	struct i2o_reply *rf;
    207  1.11.2.2  he 	struct {
    208  1.11.2.2  he 		struct	i2o_param_op_list_header olh;
    209  1.11.2.2  he 		struct	i2o_param_op_all_template oat;
    210  1.11.2.2  he 	} __attribute__ ((__packed__)) req;
    211  1.11.2.2  he 
    212  1.11.2.2  he 	mb.msgflags = I2O_MSGFLAGS(i2o_util_params_op);
    213  1.11.2.2  he 	mb.msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_GET);
    214  1.11.2.2  he 	mb.flags = 0;
    215  1.11.2.2  he 
    216  1.11.2.2  he 	req.olh.count = htole16(1);
    217  1.11.2.2  he 	req.olh.reserved = htole16(0);
    218  1.11.2.2  he 	req.oat.operation = htole16(I2O_PARAMS_OP_FIELD_GET);
    219  1.11.2.2  he 	req.oat.fieldcount = htole16(0xffff);
    220  1.11.2.2  he 	req.oat.group = htole16(group);
    221  1.11.2.2  he 
    222  1.11.2.2  he 	pt.pt_msg = &mb;
    223  1.11.2.2  he 	pt.pt_msglen = sizeof(mb);
    224  1.11.2.2  he 	pt.pt_reply = buf;
    225  1.11.2.2  he 	pt.pt_replylen = sizeof(buf);
    226  1.11.2.2  he 	pt.pt_timo = 10000;
    227  1.11.2.2  he 	pt.pt_nbufs = 2;
    228  1.11.2.2  he 
    229  1.11.2.2  he 	pt.pt_bufs[0].ptb_data = &req;
    230  1.11.2.2  he 	pt.pt_bufs[0].ptb_datalen = sizeof(req);
    231  1.11.2.2  he 	pt.pt_bufs[0].ptb_out = 1;
    232  1.11.2.2  he 
    233  1.11.2.2  he 	pt.pt_bufs[1].ptb_data = pbuf;
    234  1.11.2.2  he 	pt.pt_bufs[1].ptb_datalen = pbufsize;
    235  1.11.2.2  he 	pt.pt_bufs[1].ptb_out = 0;
    236  1.11.2.2  he 
    237  1.11.2.2  he 	if (ioctl(fd, IOPIOCPT, &pt) < 0)
    238  1.11.2.2  he 		err(EXIT_FAILURE, "IOPIOCPT");
    239  1.11.2.2  he 
    240  1.11.2.2  he 	rf = (struct i2o_reply *)buf;
    241  1.11.2.2  he 	if ((rf->msgflags & I2O_MSGFLAGS_FAIL) != 0)
    242  1.11.2.2  he 		errx(EXIT_FAILURE, "I2O_UTIL_PARAMS_GET failed (FAIL)");
    243  1.11.2.2  he 	if (rf->reqstatus != 0)
    244  1.11.2.2  he 		errx(EXIT_FAILURE, "I2O_UTIL_PARAMS_GET failed (%d)",
    245  1.11.2.2  he 		    ((struct i2o_reply *)buf)->reqstatus);
    246  1.11.2.2  he }
    247  1.11.2.2  he 
    248  1.11.2.2  he void
    249  1.11.2.2  he showlct(char **argv)
    250  1.11.2.2  he {
    251  1.11.2.2  he 	struct iovec iov;
    252  1.11.2.2  he 	struct i2o_lct *lct;
    253  1.11.2.2  he 	struct i2o_lct_entry *ent;
    254  1.11.2.2  he 	u_int32_t classid, usertid;
    255  1.11.2.2  he 	int i, nent;
    256  1.11.2.2  he 	char ident[sizeof(ent->identitytag) * 4 + 1];
    257  1.11.2.2  he 
    258  1.11.2.2  he 	iov.iov_base = buf;
    259  1.11.2.2  he 	iov.iov_len = sizeof(buf);
    260  1.11.2.2  he 
    261  1.11.2.2  he 	if (ioctl(fd, IOPIOCGLCT, &iov) < 0)
    262  1.11.2.2  he 		err(EXIT_FAILURE, "IOPIOCGLCT");
    263  1.11.2.2  he 
    264  1.11.2.2  he 	lct = (struct i2o_lct *)buf;
    265  1.11.2.2  he 	ent = lct->entry;
    266  1.11.2.2  he 	nent = ((le16toh(lct->tablesize) << 2) -
    267  1.11.2.2  he 	    sizeof(struct i2o_lct) + sizeof(struct i2o_lct_entry)) /
    268  1.11.2.2  he 	    sizeof(struct i2o_lct_entry);
    269  1.11.2.2  he 
    270  1.11.2.2  he 	for (i = 0; i < nent; i++, ent++) {
    271  1.11.2.2  he 		classid = le32toh(ent->classid);
    272  1.11.2.2  he 		usertid = le32toh(ent->usertid);
    273  1.11.2.2  he 
    274  1.11.2.2  he 		show("lct entry", "%d", i);
    275  1.11.2.2  he 		show("entry size", "%d bytes", le16toh(ent->entrysize) << 2);
    276  1.11.2.2  he 		show("local tid", "%d", le16toh(ent->localtid) & 4095);
    277  1.11.2.2  he 		show("change indicator", "%d", le32toh(ent->changeindicator));
    278  1.11.2.2  he 		show("flags", "%x", le32toh(ent->deviceflags));
    279  1.11.2.2  he 		show("class id", "%x (%s)", classid & 4095,
    280  1.11.2.2  he 		    class2str(classid & 4095));
    281  1.11.2.2  he 		show("version", "%x", (classid >> 12) & 15);
    282  1.11.2.2  he 		show("organisation id", "%x", classid >> 16);
    283  1.11.2.2  he 		show("subclass info", "%x", le32toh(ent->subclassinfo));
    284  1.11.2.2  he 		show("user tid", "%d", usertid & 4095);
    285  1.11.2.2  he 		show("parent tid", "%d", (usertid >> 12) & 4095);
    286  1.11.2.2  he 		show("bios info", "%d", (usertid >> 24) & 255);
    287  1.11.2.2  he 		i2ostrvis(ent->identitytag, sizeof(ent->identitytag), ident,
    288  1.11.2.2  he 		    sizeof(ident));
    289  1.11.2.2  he 		show("identity tag", "<%s>", ident);
    290  1.11.2.2  he 		show("event caps", "%x", le32toh(ent->eventcaps));
    291  1.11.2.2  he 
    292  1.11.2.2  he 		if (i != nent - 1)
    293  1.11.2.2  he 			printf("\n");
    294  1.11.2.2  he 	}
    295  1.11.2.2  he }
    296  1.11.2.2  he 
    297  1.11.2.2  he void
    298  1.11.2.2  he showstatus(char **argv)
    299  1.11.2.2  he {
    300  1.11.2.2  he 	char ident[sizeof(status.productid) + 1];
    301  1.11.2.2  he 	u_int32_t segnumber;
    302  1.11.2.2  he 
    303  1.11.2.2  he 	i2ostrvis(status.productid, sizeof(status.productid),
    304  1.11.2.2  he 	    ident, sizeof(ident));
    305  1.11.2.2  he 
    306  1.11.2.2  he 	segnumber = le32toh(status.segnumber);
    307  1.11.2.2  he 	show("organization id", "%d", le16toh(status.orgid));
    308  1.11.2.2  he 	show("iop id", "%d", le32toh(status.iopid) & 4095);
    309  1.11.2.2  he 	show("host unit id", "%d", (le32toh(status.iopid) >> 16));
    310  1.11.2.2  he 	show("segment number", "%d", segnumber & 4095);
    311  1.11.2.2  he 	show("i2o version", "%d", (segnumber >> 12) & 15);
    312  1.11.2.2  he 	show("iop state", "%d", (segnumber >> 16) & 255);
    313  1.11.2.2  he 	show("messenger type", "%d", segnumber >> 24);
    314  1.11.2.2  he 	show("inbound frame sz", "%d", le32toh(status.inboundmframesize));
    315  1.11.2.2  he 	show("init code", "%d", status.initcode);
    316  1.11.2.2  he 	show("max inbound queue depth", "%d",
    317  1.11.2.2  he 	    le32toh(status.maxinboundmframes));
    318  1.11.2.2  he 	show("inbound queue depth", "%d",
    319  1.11.2.2  he 	    le32toh(status.currentinboundmframes));
    320  1.11.2.2  he 	show("max outbound queue depth", "%d",
    321  1.11.2.2  he 	    le32toh(status.maxoutboundmframes));
    322  1.11.2.2  he 	show("product id string", "<%s>", ident);
    323  1.11.2.2  he 	show("expected lct size", "%d", le32toh(status.expectedlctsize));
    324  1.11.2.2  he 	show("iop capabilities", "0x%08x", le32toh(status.iopcaps));
    325  1.11.2.2  he 	show("desired priv mem sz", "0x%08x",
    326  1.11.2.2  he 	    le32toh(status.desiredprivmemsize));
    327  1.11.2.2  he 	show("current priv mem sz", "0x%08x",
    328  1.11.2.2  he 	    le32toh(status.currentprivmemsize));
    329  1.11.2.2  he 	show("current priv mem base", "0x%08x",
    330  1.11.2.2  he 	    le32toh(status.currentprivmembase));
    331  1.11.2.2  he 	show("desired priv io sz", "0x%08x",
    332  1.11.2.2  he 	    le32toh(status.desiredpriviosize));
    333  1.11.2.2  he 	show("current priv io sz", "0x%08x",
    334  1.11.2.2  he 	    le32toh(status.currentpriviosize));
    335  1.11.2.2  he 	show("current priv io base", "0x%08x",
    336  1.11.2.2  he 	    le32toh(status.currentpriviobase));
    337  1.11.2.2  he }
    338  1.11.2.2  he 
    339  1.11.2.2  he void
    340  1.11.2.2  he showddmid(char **argv)
    341  1.11.2.2  he {
    342  1.11.2.2  he 	struct {
    343  1.11.2.2  he 		struct	i2o_param_op_results pr;
    344  1.11.2.2  he 		struct	i2o_param_read_results prr;
    345  1.11.2.2  he 		struct	i2o_param_ddm_identity di;
    346  1.11.2.2  he 		char padding[128];
    347  1.11.2.2  he 	} __attribute__ ((__packed__)) p;
    348  1.11.2.2  he 	char ident[128];
    349  1.11.2.2  he 
    350  1.11.2.2  he 	getparam(gettid(argv), I2O_PARAM_DDM_IDENTITY, &p, sizeof(p));
    351  1.11.2.2  he 
    352  1.11.2.2  he 	show("ddm tid", "%d", le16toh(p.di.ddmtid) & 4095);
    353  1.11.2.2  he 	i2ostrvis(p.di.name, sizeof(p.di.name), ident, sizeof(ident));
    354  1.11.2.2  he 	show("module name", "%s", ident);
    355  1.11.2.2  he 	i2ostrvis(p.di.revlevel, sizeof(p.di.revlevel), ident, sizeof(ident));
    356  1.11.2.2  he 	show("module revision", "%s", ident);
    357  1.11.2.2  he 	show("serial # format", "%d", p.di.snformat);
    358  1.11.2.2  he 	show("serial #", "%08x%08x%08x", *(u_int32_t *)&p.di.serialnumber[0],
    359  1.11.2.2  he 	    *(u_int32_t *)&p.di.serialnumber[4],
    360  1.11.2.2  he 	    *(u_int32_t *)&p.di.serialnumber[8]);
    361  1.11.2.2  he }
    362  1.11.2.2  he 
    363  1.11.2.2  he void
    364  1.11.2.2  he showdevid(char **argv)
    365  1.11.2.2  he {
    366  1.11.2.2  he 	struct {
    367  1.11.2.2  he 		struct	i2o_param_op_results pr;
    368  1.11.2.2  he 		struct	i2o_param_read_results prr;
    369  1.11.2.2  he 		struct	i2o_param_device_identity di;
    370  1.11.2.2  he 		char padding[128];
    371  1.11.2.2  he 	} __attribute__ ((__packed__)) p;
    372  1.11.2.2  he 	char ident[128];
    373  1.11.2.2  he 
    374  1.11.2.2  he 	getparam(gettid(argv), I2O_PARAM_DEVICE_IDENTITY, &p, sizeof(p));
    375  1.11.2.2  he 
    376  1.11.2.2  he 	show("class id", "%d (%s)", le32toh(p.di.classid) & 4095,
    377  1.11.2.2  he 	    class2str(le32toh(p.di.classid) & 4095));
    378  1.11.2.2  he 	show("owner tid", "%d", le32toh(p.di.ownertid) & 4095);
    379  1.11.2.2  he 	show("parent tid", "%d", le32toh(p.di.parenttid) & 4095);
    380  1.11.2.2  he 
    381  1.11.2.2  he 	i2ostrvis(p.di.vendorinfo, sizeof(p.di.vendorinfo), ident,
    382  1.11.2.2  he 	    sizeof(ident));
    383  1.11.2.2  he 	show("vendor", "<%s>", ident);
    384  1.11.2.2  he 
    385  1.11.2.2  he 	i2ostrvis(p.di.productinfo, sizeof(p.di.productinfo), ident,
    386  1.11.2.2  he 	    sizeof(ident));
    387  1.11.2.2  he 	show("product", "<%s>", ident);
    388  1.11.2.2  he 
    389  1.11.2.2  he 	i2ostrvis(p.di.description, sizeof(p.di.description), ident,
    390  1.11.2.2  he 	    sizeof(ident));
    391  1.11.2.2  he 	show("description", "<%s>", ident);
    392  1.11.2.2  he 
    393  1.11.2.2  he 	i2ostrvis(p.di.revlevel, sizeof(p.di.revlevel), ident, sizeof(ident));
    394  1.11.2.2  he 	show("revision level", "<%s>", ident);
    395  1.11.2.2  he }
    396  1.11.2.2  he 
    397  1.11.2.2  he void
    398  1.11.2.2  he reconfig(char **argv)
    399  1.11.2.2  he {
    400  1.11.2.2  he 
    401  1.11.2.2  he 	if (ioctl(fd, IOPIOCRECONFIG))
    402  1.11.2.2  he 		err(EXIT_FAILURE, "IOPIOCRECONFIG");
    403  1.11.2.2  he }
    404  1.11.2.2  he 
    405  1.11.2.2  he void
    406  1.11.2.2  he showtidmap(char **argv)
    407  1.11.2.2  he {
    408  1.11.2.2  he 	struct iovec iov;
    409  1.11.2.2  he 	struct iop_tidmap *it;
    410  1.11.2.2  he 	int nent;
    411  1.11.2.2  he 
    412  1.11.2.2  he 	iov.iov_base = buf;
    413  1.11.2.2  he 	iov.iov_len = sizeof(buf);
    414  1.11.2.2  he 
    415  1.11.2.2  he 	if (ioctl(fd, IOPIOCGTIDMAP, &iov) < 0)
    416  1.11.2.2  he 		err(EXIT_FAILURE, "IOPIOCGTIDMAP");
    417  1.11.2.2  he 
    418  1.11.2.2  he 	nent = iov.iov_len / sizeof(*it);
    419  1.11.2.2  he 	it = (struct iop_tidmap *)buf;
    420  1.11.2.2  he 
    421  1.11.2.2  he 	for (; nent-- != 0; it++)
    422  1.11.2.2  he 		if ((it->it_flags & IT_CONFIGURED) != 0)
    423  1.11.2.2  he 			printf("%s\ttid %d\n", it->it_dvname, it->it_tid);
    424  1.11.2.2  he }
    425  1.11.2.2  he 
    426  1.11.2.2  he void
    427  1.11.2.2  he i2ostrvis(const char *src, int slen, char *dst, int dlen)
    428  1.11.2.2  he {
    429  1.11.2.2  he 	int hc, lc, i, nit;
    430  1.11.2.2  he 
    431  1.11.2.2  he 	dlen--;
    432  1.11.2.2  he 	lc = 0;
    433  1.11.2.2  he 	hc = 0;
    434  1.11.2.2  he 	i = 0;
    435  1.11.2.2  he 
    436  1.11.2.2  he 	/*
    437  1.11.2.2  he 	 * DPT use NUL as a space, whereas AMI use it as a terminator.  The
    438  1.11.2.2  he 	 * spec has nothing to say about it.  Since AMI fields are usually
    439  1.11.2.2  he 	 * filled with junk after the terminator, ...
    440  1.11.2.2  he 	 */
    441  1.11.2.2  he 	nit = (le16toh(status.orgid) != I2O_ORG_DPT);
    442  1.11.2.2  he 
    443  1.11.2.2  he 	while (slen-- != 0 && dlen-- != 0) {
    444  1.11.2.2  he 		if (nit && *src == '\0')
    445  1.11.2.2  he 			break;
    446  1.11.2.2  he 		else if (*src <= 0x20 || *src >= 0x7f) {
    447  1.11.2.2  he 			if (hc)
    448  1.11.2.2  he 				dst[i++] = ' ';
    449  1.11.2.2  he 		} else {
    450  1.11.2.2  he 			hc = 1;
    451  1.11.2.2  he 			dst[i++] = *src;
    452  1.11.2.2  he 			lc = i;
    453  1.11.2.2  he 		}
    454  1.11.2.2  he 		src++;
    455  1.11.2.2  he 	}
    456  1.11.2.2  he 
    457  1.11.2.2  he 	dst[lc] = '\0';
    458  1.11.2.2  he }
    459  1.11.2.2  he 
    460  1.11.2.2  he int
    461  1.11.2.2  he gettid(char **argv)
    462  1.11.2.2  he {
    463  1.11.2.2  he 	char *argp;
    464  1.11.2.2  he 	int tid;
    465  1.11.2.2  he 
    466  1.11.2.2  he 	if (argv[1] != NULL)
    467  1.11.2.2  he 		usage();
    468  1.11.2.2  he 
    469  1.11.2.2  he 	tid = (int)strtol(argv[0], &argp, 0);
    470  1.11.2.2  he 	if (*argp != '\0')
    471  1.11.2.2  he 		usage();
    472  1.11.2.2  he 
    473  1.11.2.2  he 	return (tid);
    474  1.11.2.2  he }
    475