Pre-2.0 release: Sync with HAMMER 64 - NFS and cross-device link fixes.
[dragonfly.git] / usr.sbin / dpt / dpt_softc / dpt_softc.c
blob0f3e22298abf741036b49485005c593d027f97fb
1 /*
2 * Copyright (c) 1997 by Simon Shapiro
3 * All Rights Reserved
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * $FreeBSD: src/usr.sbin/dpt/dpt_softc/dpt_softc.c,v 1.3.2.1 2001/07/24 09:49:45 dd Exp $
30 * $DragonFly: src/usr.sbin/dpt/dpt_softc/dpt_softc.c,v 1.3 2004/12/18 22:48:03 swildner Exp $
33 /* dpt_softc.c: Dunp a DPT control structure */
35 #include <stdlib.h>
36 #include <fcntl.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <errno.h>
40 #include <sys/time.h>
41 #include <sys/stat.h>
42 #include <sys/queue.h>
43 #include <sys/ioctl.h>
44 #include <scsi/scsi_all.h>
45 #include <scsi/scsi_message.h>
46 #include <scsi/scsiconf.h>
49 * The following two defines alter the size and composition of dpt_softc_t.
50 * If useland does not match the kenel, disaster will ensue.
51 * Since we do not know how to pick up kernel options from here,
52 * and since we always use these options, we will enable them here.
54 * If you build a kernel without these options, edit here and recompile.
56 #define DPT_MEASURE_PERFORMANCE
58 #include <sys/dpt.h>
60 static char i2bin_bitmap[48]; /* Used for binary dump of registers */
62 char *
63 i2bin(unsigned int no, int length)
65 int ndx, rind;
67 for (ndx = 0, rind = 0; ndx < 32; ndx++, rind++) {
68 i2bin_bitmap[rind] = (((no << ndx) & 0x80000000) ? '1' : '0');
70 if (((ndx % 4) == 3))
71 i2bin_bitmap[++rind] = ' ';
74 if ((ndx % 4) == 3)
75 i2bin_bitmap[rind - 1] = '\0';
76 else
77 i2bin_bitmap[rind] = '\0';
79 switch (length) {
80 case 8:
81 return (i2bin_bitmap + 30);
82 break;
83 case 16:
84 return (i2bin_bitmap + 20);
85 break;
86 case 24:
87 return (i2bin_bitmap + 10);
88 break;
89 case 32:
90 return (i2bin_bitmap);
91 default:
92 return ("i2bin: Invalid length Specs");
93 break;
96 int
97 main(int argc, char **argv, char **argp)
99 dpt_user_softc_t udpt;
100 int result;
101 int fd;
103 if ( (fd = open(argv[1], O_RDWR, S_IRUSR | S_IWUSR)) == -1 ) {
104 fprintf(stderr, "%s ERROR: Failed to open \"%s\" - %s\n",
105 argv[0], argv[1], strerror(errno));
106 exit(1);
109 if ( (result = ioctl(fd, DPT_IOCTL_SOFTC, &udpt)) != 0 ) {
110 fprintf(stderr, "%s ERROR: Failed to send IOCTL %lx - %s\n",
111 argv[0], DPT_IOCTL_SOFTC,
112 strerror(errno));
113 exit(2);
116 printf(stdout, "Counters:%d:%d:%d:%d:%d:%d:%d\n",
117 udpt.total_ccbs_count,
118 udpt.free_ccbs_count,
119 udpt.waiting_ccbs_count,
120 udpt.submitted_ccbs_count,
121 udpt.completed_ccbs_count,
122 udpt.commands_processed,
123 udpt.lost_interrupts);
125 fprintf(stdout, "Queue Status:%s\n",
126 i2bin(udpt.queue_status, sizeof(udpt.queue_status) * 8));
128 fprintf(stdout, "Free lock:%s\n",
129 i2bin(udpt.free_lock, sizeof(udpt.free_lock) * 8));
131 fprintf(stdout, "Waiting lock:%s\n",
132 i2bin(udpt.waiting_lock, sizeof(udpt.waiting_lock) * 8));
134 fprintf(stdout, "Submitted lock:%s\n",
135 i2bin(udpt.submitted_lock, sizeof(udpt.submitted_lock) * 8));
137 fprintf(stdout, "Completed lock:%s\n",
138 i2bin(udpt.completed_lock, sizeof(udpt.completed_lock) * 8));
140 fprintf(stdout, "Configuration:%s:%d:%d:%d:%x:%d:%d\n",
141 udpt.handle_interrupts ? "Yes" : "No",
142 udpt.max_id,
143 udpt.max_lun,
144 udpt.channels,
145 udpt.io_base,
146 udpt.irq,
147 udpt.dma_channel);
149 fprintf(stdout, "ID:%x:%x:%s:%s:%s:%s:%x\n",
150 udpt.board_data.deviceType,
151 udpt.board_data.rm_dtq,
152 udpt.board_data.vendor,
153 udpt.board_data.modelNum,
154 udpt.board_data.firmware,
155 udpt.board_data.protocol,
156 udpt.EATA_revision);
158 fprintf(stdout,"Capabilities:%x:%d:%s:%s:%s:%s:%s\n",
159 udpt.bustype,
160 udpt.channels,
161 i2bin((u_int32_t)udpt.state, sizeof(udpt.state) * 8),
162 udpt.primary ? "Yes" : "No",
163 udpt.more_support ? "Yes" : "No",
164 udpt.immediate_support ? "Yes" : "No",
165 udpt.broken_INQUIRY ? "Yes" : "No");
167 fprintf(stdout,"More Config:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d\n",
168 udpt.resetlevel[0],
169 udpt.resetlevel[1],
170 udpt.resetlevel[2],
171 udpt.cplen,
172 udpt.cppadlen,
173 udpt.queuesize,
174 udpt.sgsize,
175 udpt.hostid[0],
176 udpt.hostid[1],
177 udpt.hostid[2]);
179 fprintf(stdout,"Cache:%s:%d\n",
180 (udpt.cache_type == DPT_NO_CACHE)
181 ? "None"
182 : (udpt.cache_type == DPT_CACHE_WRITETHROUGH)
183 ? "Write-Through" : "Write-Back",
184 udpt.cache_size);
186 return(0);